Whamcloud - gitweb
LU-4609 ofd: auto resume LFSCK after the recovery
[fs/lustre-release.git] / lustre / ofd / ofd_objects.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ofd/ofd_objects.c
37  *
38  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
39  * Author: Mikhail Pershin <tappro@whamcloud.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_FILTER
43
44 #include <dt_object.h>
45 #include <lustre/lustre_idl.h>
46 #include <lustre_lfsck.h>
47
48 #include "ofd_internal.h"
49
50 int ofd_version_get_check(struct ofd_thread_info *info,
51                           struct ofd_object *fo)
52 {
53         dt_obj_version_t curr_version;
54
55         LASSERT(ofd_object_exists(fo));
56
57         if (info->fti_exp)
58                 RETURN(0);
59
60         curr_version = dt_version_get(info->fti_env, ofd_object_child(fo));
61         if ((__s64)curr_version == -EOPNOTSUPP)
62                 RETURN(0);
63         /* VBR: version is checked always because costs nothing */
64         if (info->fti_pre_version != 0 &&
65             info->fti_pre_version != curr_version) {
66                 CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n",
67                        info->fti_pre_version, curr_version);
68                 spin_lock(&info->fti_exp->exp_lock);
69                 info->fti_exp->exp_vbr_failed = 1;
70                 spin_unlock(&info->fti_exp->exp_lock);
71                 RETURN (-EOVERFLOW);
72         }
73         info->fti_pre_version = curr_version;
74         RETURN(0);
75 }
76
77 struct ofd_object *ofd_object_find(const struct lu_env *env,
78                                    struct ofd_device *ofd,
79                                    const struct lu_fid *fid)
80 {
81         struct ofd_object *fo;
82         struct lu_object  *o;
83
84         ENTRY;
85
86         o = lu_object_find(env, &ofd->ofd_dt_dev.dd_lu_dev, fid, NULL);
87         if (likely(!IS_ERR(o)))
88                 fo = ofd_obj(o);
89         else
90                 fo = ERR_CAST(o); /* return error */
91
92         RETURN(fo);
93 }
94
95 int ofd_object_ff_load(const struct lu_env *env, struct ofd_object *fo)
96 {
97         struct ofd_thread_info  *info = ofd_info(env);
98         struct filter_fid_old   *ff   = &info->fti_mds_fid_old;
99         struct lu_buf           *buf  = &info->fti_buf;
100         struct lu_fid           *pfid = &fo->ofo_pfid;
101         int                      rc   = 0;
102
103         if (fid_is_sane(pfid))
104                 return 0;
105
106         buf->lb_buf = ff;
107         buf->lb_len = sizeof(*ff);
108         rc = dt_xattr_get(env, ofd_object_child(fo), buf, XATTR_NAME_FID,
109                           BYPASS_CAPA);
110         if (rc < 0)
111                 return rc;
112
113         if (rc < sizeof(struct lu_fid)) {
114                 fid_zero(pfid);
115
116                 return -ENODATA;
117         }
118
119         pfid->f_seq = le64_to_cpu(ff->ff_parent.f_seq);
120         pfid->f_oid = le32_to_cpu(ff->ff_parent.f_oid);
121         /* Currently, the filter_fid::ff_parent::f_ver is not the real parent
122          * MDT-object's FID::f_ver, instead it is the OST-object index in its
123          * parent MDT-object's layout EA. */
124         pfid->f_stripe_idx = le32_to_cpu(ff->ff_parent.f_stripe_idx);
125
126         return 0;
127 }
128
129 void ofd_object_put(const struct lu_env *env, struct ofd_object *fo)
130 {
131         lu_object_put(env, &fo->ofo_obj.do_lu);
132 }
133
134 int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
135                           obd_id id, struct ofd_seq *oseq, int nr, int sync)
136 {
137         struct ofd_thread_info  *info = ofd_info(env);
138         struct ofd_object       *fo = NULL;
139         struct dt_object        *next;
140         struct thandle          *th;
141         struct ofd_object       **batch;
142         struct lu_fid           *fid = &info->fti_fid;
143         obd_id                   tmp;
144         int                      rc;
145         int                      i;
146         int                      objects = 0;
147         int                      nr_saved = nr;
148
149         ENTRY;
150
151         /* Don't create objects beyond the valid range for this SEQ */
152         if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
153                      (id + nr) >= IDIF_MAX_OID)) {
154                 CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n",
155                        ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
156                 RETURN(rc = -ENOSPC);
157         } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
158                             (id + nr) >= OBIF_MAX_OID)) {
159                 CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n",
160                        ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
161                 RETURN(rc = -ENOSPC);
162         }
163
164         OBD_ALLOC(batch, nr_saved * sizeof(struct ofd_object *));
165         if (batch == NULL)
166                 RETURN(-ENOMEM);
167
168         info->fti_attr.la_valid = LA_TYPE | LA_MODE;
169         /*
170          * We mark object SUID+SGID to flag it for accepting UID+GID from
171          * client on first write.  Currently the permission bits on the OST are
172          * never used, so this is OK.
173          */
174         info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | 0666;
175         info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
176
177         /* Initialize a/c/m time so any client timestamp will always
178          * be newer and update the inode. ctime = 0 is also handled
179          * specially in osd_inode_setattr(). See LU-221, LU-1042 */
180         info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME;
181         info->fti_attr.la_atime = 0;
182         info->fti_attr.la_mtime = 0;
183         info->fti_attr.la_ctime = 0;
184
185         LASSERT(id != 0);
186
187         /* prepare objects */
188         *fid = *lu_object_fid(&oseq->os_lastid_obj->do_lu);
189         for (i = 0; i < nr; i++) {
190                 rc = fid_set_id(fid, id + i);
191                 if (rc != 0) {
192                         if (i == 0)
193                                 GOTO(out, rc);
194
195                         nr = i;
196                         break;
197                 }
198
199                 fo = ofd_object_find(env, ofd, fid);
200                 if (IS_ERR(fo)) {
201                         if (i == 0)
202                                 GOTO(out, rc = PTR_ERR(fo));
203
204                         nr = i;
205                         break;
206                 }
207
208                 ofd_write_lock(env, fo);
209                 batch[i] = fo;
210         }
211         info->fti_buf.lb_buf = &tmp;
212         info->fti_buf.lb_len = sizeof(tmp);
213         info->fti_off = 0;
214
215         th = ofd_trans_create(env, ofd);
216         if (IS_ERR(th))
217                 GOTO(out, rc = PTR_ERR(th));
218
219         th->th_sync |= sync;
220
221         rc = dt_declare_record_write(env, oseq->os_lastid_obj, &info->fti_buf,
222                                      info->fti_off, th);
223         if (rc)
224                 GOTO(trans_stop, rc);
225
226         for (i = 0; i < nr; i++) {
227                 fo = batch[i];
228                 LASSERT(fo);
229
230                 if (unlikely(ofd_object_exists(fo))) {
231                         /* object may exist being re-created by write replay */
232                         CDEBUG(D_INODE, "object "LPX64"/"LPX64" exists: "
233                                DFID"\n", ostid_seq(&oseq->os_oi), id,
234                                PFID(lu_object_fid(&fo->ofo_obj.do_lu)));
235                         continue;
236                 }
237
238                 next = ofd_object_child(fo);
239                 LASSERT(next != NULL);
240
241                 rc = dt_declare_create(env, next, &info->fti_attr, NULL,
242                                        &info->fti_dof, th);
243                 if (rc) {
244                         nr = i;
245                         break;
246                 }
247         }
248
249         rc = dt_trans_start_local(env, ofd->ofd_osd, th);
250         if (rc)
251                 GOTO(trans_stop, rc);
252
253         CDEBUG(D_OTHER, "%s: create new object "DFID" nr %d\n",
254                ofd_name(ofd), PFID(fid), nr);
255
256         LASSERT(nr > 0);
257
258          /* When the LFSCK scanning the whole device to verify the LAST_ID file
259           * consistency, it will load the last_id into RAM firstly, and compare
260           * the last_id with each OST-object's ID. If the later one is larger,
261           * then it will regard the LAST_ID file crashed. But during the LFSCK
262           * scanning, the OFD may continue to create new OST-objects. Those new
263           * created OST-objects will have larger IDs than the LFSCK known ones.
264           * So from the LFSCK view, it needs to re-load the last_id from disk
265           * file, and if the latest last_id is still smaller than the object's
266           * ID, then the LAST_ID file is real crashed.
267           *
268           * To make above mechanism to work, before OFD pre-create OST-objects,
269           * it needs to update the LAST_ID file firstly, otherwise, the LFSCK
270           * may cannot get latest last_id although new OST-object created. */
271         if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_SKIP_LASTID)) {
272                 tmp = cpu_to_le64(id + nr - 1);
273                 dt_write_lock(env, oseq->os_lastid_obj, 0);
274                 rc = dt_record_write(env, oseq->os_lastid_obj,
275                                      &info->fti_buf, &info->fti_off, th);
276                 dt_write_unlock(env, oseq->os_lastid_obj);
277                 if (rc != 0)
278                         GOTO(trans_stop, rc);
279         }
280
281         for (i = 0; i < nr; i++) {
282                 fo = batch[i];
283                 LASSERT(fo);
284
285                 /* Only the new created objects need to be recorded. */
286                 if (ofd->ofd_osd->dd_record_fid_accessed) {
287                         lfsck_pack_rfa(&ofd_info(env)->fti_lr,
288                                        lu_object_fid(&fo->ofo_obj.do_lu));
289                         lfsck_in_notify(env, ofd->ofd_osd,
290                                         &ofd_info(env)->fti_lr);
291                 }
292
293                 if (likely(!ofd_object_exists(fo) &&
294                            !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING))) {
295                         next = ofd_object_child(fo);
296                         LASSERT(next != NULL);
297
298                         rc = dt_create(env, next, &info->fti_attr, NULL,
299                                        &info->fti_dof, th);
300                         if (rc)
301                                 break;
302                         LASSERT(ofd_object_exists(fo));
303                 }
304                 ofd_seq_last_oid_set(oseq, id + i);
305         }
306
307         objects = i;
308         /* NOT all the wanted objects have been created,
309          * set the LAST_ID as the real created. */
310         if (unlikely(objects < nr)) {
311                 int rc1;
312
313                 info->fti_off = 0;
314                 tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
315                 dt_write_lock(env, oseq->os_lastid_obj, 0);
316                 rc1 = dt_record_write(env, oseq->os_lastid_obj,
317                                       &info->fti_buf, &info->fti_off, th);
318                 dt_write_unlock(env, oseq->os_lastid_obj);
319                 if (rc1 != 0)
320                         CERROR("%s: fail to reset the LAST_ID for seq ("LPX64
321                                ") from "LPU64" to "LPU64"\n", ofd_name(ofd),
322                                ostid_seq(&oseq->os_oi), id + nr - 1,
323                                ofd_seq_last_oid(oseq));
324         }
325
326 trans_stop:
327         ofd_trans_stop(env, ofd, th, rc);
328 out:
329         for (i = 0; i < nr_saved; i++) {
330                 fo = batch[i];
331                 if (fo) {
332                         ofd_write_unlock(env, fo);
333                         ofd_object_put(env, fo);
334                 }
335         }
336         OBD_FREE(batch, nr_saved * sizeof(struct ofd_object *));
337
338         CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER,
339                "created %d/%d objects: %d\n", objects, nr_saved, rc);
340
341         LASSERT(ergo(objects == 0, rc < 0));
342         RETURN(objects > 0 ? objects : rc);
343 }
344
345 /*
346  * If the object still has SUID+SGID bits set (see ofd_precreate_object()) then
347  * we will accept the UID+GID if sent by the client for initializing the
348  * ownership of this object.  We only allow this to happen once (so clear these
349  * bits) and later only allow setattr.
350  */
351 int ofd_attr_handle_ugid(const struct lu_env *env, struct ofd_object *fo,
352                          struct lu_attr *la, int is_setattr)
353 {
354         struct ofd_thread_info  *info = ofd_info(env);
355         struct lu_attr          *ln = &info->fti_attr2;
356         __u32                    mask = 0;
357         int                      rc;
358
359         ENTRY;
360
361         if (!(la->la_valid & LA_UID) && !(la->la_valid & LA_GID))
362                 RETURN(0);
363
364         rc = dt_attr_get(env, ofd_object_child(fo), ln, BYPASS_CAPA);
365         if (rc != 0)
366                 RETURN(rc);
367
368         LASSERT(ln->la_valid & LA_MODE);
369
370         if (!is_setattr) {
371                 if (!(ln->la_mode & S_ISUID))
372                         la->la_valid &= ~LA_UID;
373                 if (!(ln->la_mode & S_ISGID))
374                         la->la_valid &= ~LA_GID;
375         }
376
377         if ((la->la_valid & LA_UID) && (ln->la_mode & S_ISUID))
378                 mask |= S_ISUID;
379         if ((la->la_valid & LA_GID) && (ln->la_mode & S_ISGID))
380                 mask |= S_ISGID;
381         if (mask != 0) {
382                 if (!(la->la_valid & LA_MODE) || !is_setattr) {
383                         la->la_mode = ln->la_mode;
384                         la->la_valid |= LA_MODE;
385                 }
386                 la->la_mode &= ~mask;
387         }
388
389         RETURN(0);
390 }
391
392 int ofd_attr_set(const struct lu_env *env, struct ofd_object *fo,
393                  struct lu_attr *la, struct filter_fid *ff)
394 {
395         struct ofd_thread_info  *info = ofd_info(env);
396         struct ofd_device       *ofd = ofd_obj2dev(fo);
397         struct thandle          *th;
398         struct ofd_mod_data     *fmd;
399         int                      ff_needed = 0;
400         int                      rc;
401         ENTRY;
402
403         ofd_write_lock(env, fo);
404         if (!ofd_object_exists(fo))
405                 GOTO(unlock, rc = -ENOENT);
406
407         if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME)) {
408                 fmd = ofd_fmd_get(info->fti_exp, &fo->ofo_header.loh_fid);
409                 if (fmd && fmd->fmd_mactime_xid < info->fti_xid)
410                         fmd->fmd_mactime_xid = info->fti_xid;
411                 ofd_fmd_put(info->fti_exp, fmd);
412         }
413
414         /* VBR: version recovery check */
415         rc = ofd_version_get_check(info, fo);
416         if (rc)
417                 GOTO(unlock, rc);
418
419         rc = ofd_attr_handle_ugid(env, fo, la, 1 /* is_setattr */);
420         if (rc != 0)
421                 GOTO(unlock, rc);
422
423         if (ff != NULL) {
424                 rc = ofd_object_ff_load(env, fo);
425                 if (rc == -ENODATA)
426                         ff_needed = 1;
427                 else if (rc < 0)
428                         GOTO(unlock, rc);
429         }
430
431         th = ofd_trans_create(env, ofd);
432         if (IS_ERR(th))
433                 GOTO(unlock, rc = PTR_ERR(th));
434
435         rc = dt_declare_attr_set(env, ofd_object_child(fo), la, th);
436         if (rc)
437                 GOTO(stop, rc);
438
439         if (ff_needed) {
440                 info->fti_buf.lb_buf = ff;
441                 info->fti_buf.lb_len = sizeof(*ff);
442                 rc = dt_declare_xattr_set(env, ofd_object_child(fo),
443                                           &info->fti_buf, XATTR_NAME_FID, 0,
444                                           th);
445                 if (rc)
446                         GOTO(stop, rc);
447         }
448
449         rc = ofd_trans_start(env, ofd, la->la_valid & LA_SIZE ? fo : NULL, th);
450         if (rc)
451                 GOTO(stop, rc);
452
453         rc = dt_attr_set(env, ofd_object_child(fo), la, th,
454                          ofd_object_capa(env, fo));
455         if (rc)
456                 GOTO(stop, rc);
457
458         if (ff_needed) {
459                 rc = dt_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
460                                   XATTR_NAME_FID, 0, th, BYPASS_CAPA);
461                 if (rc == 0) {
462                         fo->ofo_pfid.f_seq = le64_to_cpu(ff->ff_parent.f_seq);
463                         fo->ofo_pfid.f_oid = le32_to_cpu(ff->ff_parent.f_oid);
464                         /* Currently, the filter_fid::ff_parent::f_ver is not
465                          * the real parent MDT-object's FID::f_ver, instead it
466                          * is the OST-object index in its parent MDT-object's
467                          * layout EA. */
468                         fo->ofo_pfid.f_stripe_idx =
469                                         le32_to_cpu(ff->ff_parent.f_stripe_idx);
470                 }
471         }
472
473         GOTO(stop, rc);
474
475 stop:
476         ofd_trans_stop(env, ofd, th, rc);
477 unlock:
478         ofd_write_unlock(env, fo);
479
480         return rc;
481 }
482
483 int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo,
484                      __u64 start, __u64 end, struct lu_attr *la,
485                      struct filter_fid *ff, struct obdo *oa)
486 {
487         struct ofd_thread_info  *info = ofd_info(env);
488         struct ofd_device       *ofd = ofd_obj2dev(fo);
489         struct ofd_mod_data     *fmd;
490         struct dt_object        *dob = ofd_object_child(fo);
491         struct thandle          *th;
492         int                      ff_needed = 0;
493         int                      rc;
494
495         ENTRY;
496
497         /* we support truncate, not punch yet */
498         LASSERT(end == OBD_OBJECT_EOF);
499
500         fmd = ofd_fmd_get(info->fti_exp, &fo->ofo_header.loh_fid);
501         if (fmd && fmd->fmd_mactime_xid < info->fti_xid)
502                 fmd->fmd_mactime_xid = info->fti_xid;
503         ofd_fmd_put(info->fti_exp, fmd);
504
505         ofd_write_lock(env, fo);
506         if (!ofd_object_exists(fo))
507                 GOTO(unlock, rc = -ENOENT);
508
509         if (ofd->ofd_lfsck_verify_pfid && oa->o_valid & OBD_MD_FLFID) {
510                 rc = ofd_verify_ff(env, fo, oa);
511                 if (rc != 0)
512                         GOTO(unlock, rc);
513         }
514
515         /* VBR: version recovery check */
516         rc = ofd_version_get_check(info, fo);
517         if (rc)
518                 GOTO(unlock, rc);
519
520         rc = ofd_attr_handle_ugid(env, fo, la, 0 /* !is_setattr */);
521         if (rc != 0)
522                 GOTO(unlock, rc);
523
524         if (ff != NULL) {
525                 rc = ofd_object_ff_load(env, fo);
526                 if (rc == -ENODATA)
527                         ff_needed = 1;
528                 else if (rc < 0)
529                         GOTO(unlock, rc);
530         }
531
532         th = ofd_trans_create(env, ofd);
533         if (IS_ERR(th))
534                 GOTO(unlock, rc = PTR_ERR(th));
535
536         rc = dt_declare_attr_set(env, dob, la, th);
537         if (rc)
538                 GOTO(stop, rc);
539
540         rc = dt_declare_punch(env, dob, start, OBD_OBJECT_EOF, th);
541         if (rc)
542                 GOTO(stop, rc);
543
544         if (ff_needed) {
545                 info->fti_buf.lb_buf = ff;
546                 info->fti_buf.lb_len = sizeof(*ff);
547                 rc = dt_declare_xattr_set(env, ofd_object_child(fo),
548                                           &info->fti_buf, XATTR_NAME_FID, 0,
549                                           th);
550                 if (rc)
551                         GOTO(stop, rc);
552         }
553
554         rc = ofd_trans_start(env, ofd, fo, th);
555         if (rc)
556                 GOTO(stop, rc);
557
558         rc = dt_punch(env, dob, start, OBD_OBJECT_EOF, th,
559                       ofd_object_capa(env, fo));
560         if (rc)
561                 GOTO(stop, rc);
562
563         rc = dt_attr_set(env, dob, la, th, ofd_object_capa(env, fo));
564         if (rc)
565                 GOTO(stop, rc);
566
567         if (ff_needed) {
568                 rc = dt_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
569                                   XATTR_NAME_FID, 0, th, BYPASS_CAPA);
570                 if (rc == 0) {
571                         fo->ofo_pfid.f_seq = le64_to_cpu(ff->ff_parent.f_seq);
572                         fo->ofo_pfid.f_oid = le32_to_cpu(ff->ff_parent.f_oid);
573                         /* Currently, the filter_fid::ff_parent::f_ver is not
574                          * the real parent MDT-object's FID::f_ver, instead it
575                          * is the OST-object index in its parent MDT-object's
576                          * layout EA. */
577                         fo->ofo_pfid.f_stripe_idx =
578                                         le32_to_cpu(ff->ff_parent.f_stripe_idx);
579                 }
580         }
581
582         GOTO(stop, rc);
583
584 stop:
585         ofd_trans_stop(env, ofd, th, rc);
586 unlock:
587         ofd_write_unlock(env, fo);
588
589         return rc;
590 }
591
592 int ofd_object_destroy(const struct lu_env *env, struct ofd_object *fo,
593                        int orphan)
594 {
595         struct ofd_device       *ofd = ofd_obj2dev(fo);
596         struct thandle          *th;
597         int                      rc = 0;
598
599         ENTRY;
600
601         ofd_write_lock(env, fo);
602         if (!ofd_object_exists(fo))
603                 GOTO(unlock, rc = -ENOENT);
604
605         th = ofd_trans_create(env, ofd);
606         if (IS_ERR(th))
607                 GOTO(unlock, rc = PTR_ERR(th));
608
609         dt_declare_ref_del(env, ofd_object_child(fo), th);
610         dt_declare_destroy(env, ofd_object_child(fo), th);
611         if (orphan)
612                 rc = dt_trans_start_local(env, ofd->ofd_osd, th);
613         else
614                 rc = ofd_trans_start(env, ofd, NULL, th);
615         if (rc)
616                 GOTO(stop, rc);
617
618         ofd_fmd_drop(ofd_info(env)->fti_exp, &fo->ofo_header.loh_fid);
619
620         dt_ref_del(env, ofd_object_child(fo), th);
621         dt_destroy(env, ofd_object_child(fo), th);
622 stop:
623         ofd_trans_stop(env, ofd, th, rc);
624 unlock:
625         ofd_write_unlock(env, fo);
626         RETURN(rc);
627 }
628
629 int ofd_attr_get(const struct lu_env *env, struct ofd_object *fo,
630                  struct lu_attr *la)
631 {
632         int rc = 0;
633
634         ENTRY;
635
636         if (ofd_object_exists(fo)) {
637                 rc = dt_attr_get(env, ofd_object_child(fo), la,
638                                  ofd_object_capa(env, fo));
639
640 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
641                 /* Try to correct for a bug in 2.1.0 (LU-221) that caused
642                  * negative timestamps to appear to be in the far future,
643                  * due old timestamp being stored on disk as an unsigned value.
644                  * This fixes up any bad values stored on disk before
645                  * returning them to the client, and ensures any timestamp
646                  * updates are correct.  LU-1042 */
647                 if (unlikely(la->la_atime == LU221_BAD_TIME))
648                         la->la_atime = 0;
649                 if (unlikely(la->la_mtime == LU221_BAD_TIME))
650                         la->la_mtime = 0;
651                 if (unlikely(la->la_ctime == LU221_BAD_TIME))
652                         la->la_ctime = 0;
653 #else
654 #warning "remove old LU-221/LU-1042 workaround code"
655 #endif
656         } else {
657                 rc = -ENOENT;
658         }
659         RETURN(rc);
660 }