4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ofd/ofd_objects.c
34 * This file contains OSD API methods related to OBD Filter Device (OFD)
37 * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
38 * Author: Mikhail Pershin <mike.pershin@intel.com>
41 #define DEBUG_SUBSYSTEM S_FILTER
43 #include <dt_object.h>
44 #include <lustre_lfsck.h>
46 #include "ofd_internal.h"
49 * Get object version from disk and check it.
51 * This function checks object version from disk with
52 * ofd_thread_info::fti_pre_version filled from incoming RPC. This is part of
53 * VBR (Version-Based Recovery) and ensures that object has the same version
54 * upon replay as it has during original modification.
56 * \param[in] info execution thread OFD private data
57 * \param[in] fo OFD object
59 * \retval 0 if version matches
60 * \retval -EOVERFLOW on version mismatch
62 static int ofd_version_get_check(struct ofd_thread_info *info,
63 struct ofd_object *fo)
65 dt_obj_version_t curr_version;
67 LASSERT(ofd_object_exists(fo));
69 if (info->fti_exp == NULL)
72 curr_version = dt_version_get(info->fti_env, ofd_object_child(fo));
73 if ((__s64)curr_version == -EOPNOTSUPP)
75 /* VBR: version is checked always because costs nothing */
76 if (info->fti_pre_version != 0 &&
77 info->fti_pre_version != curr_version) {
78 CDEBUG(D_INODE, "Version mismatch %#llx != %#llx\n",
79 info->fti_pre_version, curr_version);
80 spin_lock(&info->fti_exp->exp_lock);
81 info->fti_exp->exp_vbr_failed = 1;
82 spin_unlock(&info->fti_exp->exp_lock);
85 info->fti_pre_version = curr_version;
90 * Get OFD object by FID.
92 * This function finds OFD slice of compound object with the given FID.
94 * \param[in] env execution environment
95 * \param[in] ofd OFD device
96 * \param[in] fid FID of the object
98 * \retval pointer to the found ofd_object
99 * \retval ERR_PTR(errno) in case of error
101 struct ofd_object *ofd_object_find(const struct lu_env *env,
102 struct ofd_device *ofd,
103 const struct lu_fid *fid)
105 struct ofd_object *fo;
110 o = lu_object_find(env, &ofd->ofd_dt_dev.dd_lu_dev, fid, NULL);
111 if (likely(!IS_ERR(o)))
114 fo = ERR_CAST(o); /* return error */
120 * Get FID of parent MDT object.
122 * This function reads extended attribute XATTR_NAME_FID of OFD object which
123 * contains the MDT parent object FID and saves it in ofd_object::ofo_ff.
125 * The filter_fid::ff_parent::f_ver field currently holds
126 * the OST-object index in the parent MDT-object's layout EA,
127 * not the actual FID::f_ver of the parent. We therefore access
128 * it via the macro f_stripe_idx.
130 * \param[in] env execution environment
131 * \param[in] fo OFD object
133 * \retval 0 if successful
134 * \retval -ENODATA if there is no such xattr
135 * \retval negative value on error
137 int ofd_object_ff_load(const struct lu_env *env, struct ofd_object *fo)
139 struct ofd_thread_info *info = ofd_info(env);
140 struct filter_fid *ff = &fo->ofo_ff;
141 struct lu_buf *buf = &info->fti_buf;
144 if (fid_is_sane(&ff->ff_parent))
148 buf->lb_len = sizeof(*ff);
149 rc = dt_xattr_get(env, ofd_object_child(fo), buf, XATTR_NAME_FID);
153 if (unlikely(rc < sizeof(struct lu_fid))) {
154 fid_zero(&ff->ff_parent);
158 filter_fid_le_to_cpu(ff, ff, rc);
163 struct ofd_precreate_cb {
164 struct dt_txn_commit_cb opc_cb;
165 struct ofd_seq *opc_oseq;
169 static void ofd_cb_precreate(struct lu_env *env, struct thandle *th,
170 struct dt_txn_commit_cb *cb, int err)
172 struct ofd_precreate_cb *opc;
173 struct ofd_seq *oseq;
175 opc = container_of(cb, struct ofd_precreate_cb, opc_cb);
176 oseq = opc->opc_oseq;
178 CDEBUG(D_OTHER, "Sub %d from %d for "DFID", th_sync %d\n",
179 opc->opc_objects, atomic_read(&oseq->os_precreate_in_progress),
180 PFID(&oseq->os_oi.oi_fid), th->th_sync);
181 atomic_sub(opc->opc_objects, &oseq->os_precreate_in_progress);
182 ofd_seq_put(env, opc->opc_oseq);
186 static int ofd_precreate_cb_add(const struct lu_env *env, struct thandle *th,
187 struct ofd_seq *oseq, int objects)
189 struct ofd_precreate_cb *opc;
190 struct dt_txn_commit_cb *dcb;
197 precreate = atomic_read(&oseq->os_precreate_in_progress);
198 atomic_inc(&oseq->os_refc);
199 opc->opc_oseq = oseq;
200 opc->opc_objects = objects;
201 CDEBUG(D_OTHER, "Add %d to %d for "DFID", th_sync %d\n",
202 opc->opc_objects, precreate,
203 PFID(&oseq->os_oi.oi_fid), th->th_sync);
205 if ((precreate + objects) >= (5 * OST_MAX_PRECREATE))
209 dcb->dcb_func = ofd_cb_precreate;
210 INIT_LIST_HEAD(&dcb->dcb_linkage);
211 strlcpy(dcb->dcb_name, "ofd_cb_precreate", sizeof(dcb->dcb_name));
213 rc = dt_trans_cb_add(th, dcb);
215 ofd_seq_put(env, oseq);
220 atomic_add(objects, &oseq->os_precreate_in_progress);
226 * Precreate the given number \a nr of objects in the given sequence \a oseq.
228 * This function precreates new OST objects in the given sequence.
229 * The precreation starts from \a id and creates \a nr objects sequentially.
232 * This function may create fewer objects than requested.
234 * We mark object SUID+SGID to flag it for accepting UID+GID from client on
235 * first write. Currently the permission bits on the OST are never used,
238 * Initialize a/c/m time so any client timestamp will always be newer and
239 * update the inode. The ctime = 0 case is also handled specially in
240 * osd_inode_setattr(). See LU-221, LU-1042 for details.
242 * \param[in] env execution environment
243 * \param[in] ofd OFD device
244 * \param[in] id object ID to start precreation from
245 * \param[in] oseq object sequence
246 * \param[in] nr number of objects to precreate
247 * \param[in] sync synchronous precreation flag
249 * \retval 0 if successful
250 * \retval negative value on error
252 int ofd_precreate_objects(const struct lu_env *env, struct ofd_device *ofd,
253 u64 id, struct ofd_seq *oseq, int nr, int sync)
255 struct ofd_thread_info *info = ofd_info(env);
256 struct ofd_object *fo = NULL;
257 struct dt_object *next;
259 struct ofd_object **batch;
260 struct lu_fid *fid = &info->fti_fid;
270 /* Don't create objects beyond the valid range for this SEQ */
271 if (unlikely(fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
272 (id + nr) > IDIF_MAX_OID)) {
273 CERROR("%s:"DOSTID" hit the IDIF_MAX_OID (1<<48)!\n",
274 ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
275 RETURN(rc = -ENOSPC);
276 } else if (unlikely(!fid_seq_is_mdt0(ostid_seq(&oseq->os_oi)) &&
277 (id + nr) > OBIF_MAX_OID)) {
278 CERROR("%s:"DOSTID" hit the OBIF_MAX_OID (1<<32)!\n",
279 ofd_name(ofd), id, ostid_seq(&oseq->os_oi));
280 RETURN(rc = -ENOSPC);
283 OBD_ALLOC_PTR_ARRAY(batch, nr_saved);
287 info->fti_attr.la_valid = LA_TYPE | LA_MODE;
288 info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | S_ISVTX | 0666;
289 info->fti_dof.dof_type = dt_mode_to_dft(S_IFREG);
291 info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME;
292 info->fti_attr.la_atime = 0;
293 info->fti_attr.la_mtime = 0;
294 info->fti_attr.la_ctime = 0;
298 /* prepare objects */
299 *fid = *lu_object_fid(&oseq->os_lastid_obj->do_lu);
300 for (i = 0; i < nr; i++) {
301 rc = fid_set_id(fid, id + i);
310 fo = ofd_object_find(env, ofd, fid);
313 GOTO(out, rc = PTR_ERR(fo));
321 info->fti_buf.lb_buf = &tmp;
322 info->fti_buf.lb_len = sizeof(tmp);
325 th = ofd_trans_create(env, ofd);
327 GOTO(out, rc = PTR_ERR(th));
331 rc = dt_declare_record_write(env, oseq->os_lastid_obj, &info->fti_buf,
334 GOTO(trans_stop, rc);
336 for (i = 0; i < nr; i++) {
340 if (unlikely(ofd_object_exists(fo))) {
341 /* object may exist being re-created by write replay */
342 CDEBUG(D_INODE, "object %#llx/%#llx exists: "
343 DFID"\n", ostid_seq(&oseq->os_oi), id,
344 PFID(lu_object_fid(&fo->ofo_obj.do_lu)));
348 next = ofd_object_child(fo);
349 LASSERT(next != NULL);
351 rc = dt_declare_create(env, next, &info->fti_attr, NULL,
355 GOTO(trans_stop, rc);
362 rc = dt_trans_start_local(env, ofd->ofd_osd, th);
364 GOTO(trans_stop, rc);
366 CDEBUG(D_OTHER, "%s: create new object "DFID" nr %d\n",
367 ofd_name(ofd), PFID(fid), nr);
369 /* When the LFSCK scanning the whole device to verify the LAST_ID file
370 * consistency, it will load the last_id into RAM firstly, and compare
371 * the last_id with each OST-object's ID. If the later one is larger,
372 * then it will regard the LAST_ID file crashed. But during the LFSCK
373 * scanning, the OFD may continue to create new OST-objects. Those new
374 * created OST-objects will have larger IDs than the LFSCK known ones.
375 * So from the LFSCK view, it needs to re-load the last_id from disk
376 * file, and if the latest last_id is still smaller than the object's
377 * ID, then the LAST_ID file is real crashed.
379 * To make above mechanism to work, before OFD pre-create OST-objects,
380 * it needs to update the LAST_ID file firstly, otherwise, the LFSCK
381 * may cannot get latest last_id although new OST-object created. */
382 if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_SKIP_LASTID)) {
383 tmp = cpu_to_le64(id + nr - 1);
384 dt_write_lock(env, oseq->os_lastid_obj, DT_LASTID);
385 rc = dt_record_write(env, oseq->os_lastid_obj,
386 &info->fti_buf, &info->fti_off, th);
387 dt_write_unlock(env, oseq->os_lastid_obj);
389 GOTO(trans_stop, rc);
392 for (i = 0; i < nr; i++) {
396 ofd_write_lock(env, fo);
398 /* Only the new created objects need to be recorded. */
399 if (ofd->ofd_osd->dd_record_fid_accessed) {
400 struct lfsck_req_local *lrl = &ofd_info(env)->fti_lrl;
402 lfsck_pack_rfa(lrl, lu_object_fid(&fo->ofo_obj.do_lu),
403 LEL_FID_ACCESSED, LFSCK_TYPE_LAYOUT);
404 lfsck_in_notify_local(env, ofd->ofd_osd, lrl, NULL);
407 if (likely(!ofd_object_exists(fo) &&
408 !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING))) {
409 next = ofd_object_child(fo);
410 LASSERT(next != NULL);
412 rc = dt_create(env, next, &info->fti_attr, NULL,
414 ofd_write_unlock(env, fo);
417 GOTO(trans_stop, rc);
422 LASSERT(ofd_object_exists(fo));
424 ofd_write_unlock(env, fo);
427 ofd_seq_last_oid_set(oseq, id + i);
431 /* NOT all the wanted objects have been created,
432 * set the LAST_ID as the real created. */
433 if (unlikely(objects < nr)) {
437 tmp = cpu_to_le64(ofd_seq_last_oid(oseq));
438 dt_write_lock(env, oseq->os_lastid_obj, DT_LASTID);
439 rc1 = dt_record_write(env, oseq->os_lastid_obj,
440 &info->fti_buf, &info->fti_off, th);
441 dt_write_unlock(env, oseq->os_lastid_obj);
443 CERROR("%s: fail to reset the LAST_ID for seq (%#llx"
444 ") from %llu to %llu\n", ofd_name(ofd),
445 ostid_seq(&oseq->os_oi), id + nr - 1,
446 ofd_seq_last_oid(oseq));
450 ofd_precreate_cb_add(env, th, oseq, objects);
452 rc2 = ofd_trans_stop(env, ofd, th, rc);
454 CERROR("%s: failed to stop transaction: rc = %d\n",
459 for (i = 0; i < nr_saved; i++) {
463 ofd_object_put(env, fo);
465 OBD_FREE_PTR_ARRAY(batch, nr_saved);
467 CDEBUG((objects == 0 && rc == 0) ? D_ERROR : D_OTHER,
468 "created %d/%d objects: %d\n", objects, nr_saved, rc);
470 LASSERT(ergo(objects == 0, rc < 0));
471 RETURN(objects > 0 ? objects : rc);
475 * Fix the OFD object ownership.
477 * If the object still has SUID+SGID bits set, meaning that it was precreated
478 * by the MDT before it was assigned to any file, (see ofd_precreate_objects())
479 * then we will accept the UID/GID/PROJID if sent by the client for initializing
480 * the ownership of this object. We only allow this to happen once (so clear
481 * these bits) and later only allow setattr.
483 * \param[in] env execution environment
484 * \param[in] fo OFD object
485 * \param[in] la object attributes
486 * \param[in] is_setattr was this function called from setattr or not
488 * \retval 0 if successful
489 * \retval negative value on error
491 int ofd_attr_handle_id(const struct lu_env *env, struct ofd_object *fo,
492 struct lu_attr *la, int is_setattr)
494 struct ofd_thread_info *info = ofd_info(env);
495 struct lu_attr *ln = &info->fti_attr2;
501 if (!(la->la_valid & LA_UID) && !(la->la_valid & LA_GID) &&
502 !(la->la_valid & LA_PROJID))
505 rc = dt_attr_get(env, ofd_object_child(fo), ln);
509 LASSERT(ln->la_valid & LA_MODE);
512 * Only allow setattr to change UID/GID/PROJID, if
513 * SUID+SGID is not set which means this is not
514 * initialization of this objects.
517 if (!(ln->la_mode & S_ISUID))
518 la->la_valid &= ~LA_UID;
519 if (!(ln->la_mode & S_ISGID))
520 la->la_valid &= ~LA_GID;
521 if (!(ln->la_mode & S_ISVTX))
522 la->la_valid &= ~LA_PROJID;
525 /* Initialize ownership of this object, clear SUID+SGID bits*/
526 if ((la->la_valid & LA_UID) && (ln->la_mode & S_ISUID))
528 if ((la->la_valid & LA_GID) && (ln->la_mode & S_ISGID))
530 if ((la->la_valid & LA_PROJID) && (ln->la_mode & S_ISVTX))
533 if (!(la->la_valid & LA_MODE) || !is_setattr) {
534 la->la_mode = ln->la_mode;
535 la->la_valid |= LA_MODE;
537 la->la_mode &= ~mask;
544 * Check if it needs to update filter_fid by the value of @oa.
547 * \param[in] fo ofd object
548 * \param[in] oa obdo from client or MDT
549 * \param[out] ff if filter_fid needs updating, this field is used to
550 * return the new buffer
552 * \retval < 0 error occurred
553 * \retval 0 doesn't need to update filter_fid
554 * \retval FL_XATTR_{CREATE,REPLACE} flag for xattr update
556 int ofd_object_ff_update(const struct lu_env *env, struct ofd_object *fo,
557 const struct obdo *oa, struct filter_fid *ff)
563 (OBD_MD_FLFID | OBD_MD_FLOSTLAYOUT | OBD_MD_LAYOUT_VERSION)))
566 rc = ofd_object_ff_load(env, fo);
567 if (rc < 0 && rc != -ENODATA)
570 LASSERT(ff != &fo->ofo_ff);
571 if (rc == -ENODATA) {
572 rc = LU_XATTR_CREATE;
573 memset(ff, 0, sizeof(*ff));
575 rc = LU_XATTR_REPLACE;
576 memcpy(ff, &fo->ofo_ff, sizeof(*ff));
579 if (oa->o_valid & OBD_MD_FLFID) {
580 /* packing fid and converting it to LE for storing into EA.
581 * Here ->o_stripe_idx should be filled by LOV and rest of
582 * fields - by client. */
583 ff->ff_parent.f_seq = oa->o_parent_seq;
584 ff->ff_parent.f_oid = oa->o_parent_oid;
585 /* XXX: we are ignoring o_parent_ver here, since this should
586 * be the same for all objects in this fileset. */
587 ff->ff_parent.f_ver = oa->o_stripe_idx;
589 if (oa->o_valid & OBD_MD_FLOSTLAYOUT)
590 ff->ff_layout = oa->o_layout;
592 if (oa->o_valid & OBD_MD_LAYOUT_VERSION) {
593 CDEBUG(D_INODE, DFID": OST("DFID") layout version %u -> %u\n",
594 PFID(&fo->ofo_ff.ff_parent),
595 PFID(lu_object_fid(&fo->ofo_obj.do_lu)),
596 ff->ff_layout_version, oa->o_layout_version);
598 /* only the MDS has the authority to update layout version */
599 if (!(exp_connect_flags(ofd_info(env)->fti_exp) &
601 CERROR(DFID": update layout version from client\n",
602 PFID(&fo->ofo_ff.ff_parent));
607 if (ff->ff_layout_version & LU_LAYOUT_RESYNC) {
608 /* this opens a new era of writing */
609 ff->ff_layout_version = 0;
613 /* it's not allowed to change it to a smaller value */
614 if (oa->o_layout_version < ff->ff_layout_version)
617 if (ff->ff_layout_version == 0 ||
618 oa->o_layout_version & LU_LAYOUT_RESYNC) {
619 /* if LU_LAYOUT_RESYNC is set, it closes the era of
620 * writing. Only mirror I/O can write this object. */
621 ff->ff_layout_version = oa->o_layout_version;
623 } else if (oa->o_layout_version > ff->ff_layout_version) {
624 ff->ff_range = max_t(__u32, ff->ff_range,
625 oa->o_layout_version -
626 ff->ff_layout_version);
630 if (memcmp(ff, &fo->ofo_ff, sizeof(*ff)))
631 filter_fid_cpu_to_le(ff, ff, sizeof(*ff));
639 * Set OFD object attributes.
641 * This function sets OFD object attributes taken from incoming request.
642 * It sets not only regular attributes but also XATTR_NAME_FID extended
643 * attribute if needed. The "fid" xattr allows the object's MDT parent inode
644 * to be found and verified by LFSCK and other tools in case of inconsistency.
646 * \param[in] env execution environment
647 * \param[in] fo OFD object
648 * \param[in] la object attributes
649 * \param[in] oa obdo carries fid, ost_layout, layout version
651 * \retval 0 if successful
652 * \retval negative value on error
654 int ofd_attr_set(const struct lu_env *env, struct ofd_object *fo,
655 struct lu_attr *la, struct obdo *oa)
657 struct ofd_thread_info *info = ofd_info(env);
658 struct ofd_device *ofd = ofd_obj2dev(fo);
659 struct filter_fid *ff = &info->fti_mds_fid;
665 if (!ofd_object_exists(fo))
666 GOTO(out, rc = -ENOENT);
668 /* VBR: version recovery check */
669 rc = ofd_version_get_check(info, fo);
673 rc = ofd_attr_handle_id(env, fo, la, 1 /* is_setattr */);
677 th = ofd_trans_create(env, ofd);
679 GOTO(out, rc = PTR_ERR(th));
681 rc = dt_declare_attr_set(env, ofd_object_child(fo), la, th);
685 info->fti_buf.lb_buf = ff;
686 info->fti_buf.lb_len = sizeof(*ff);
687 rc = dt_declare_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
688 XATTR_NAME_FID, 0, th);
692 rc = ofd_trans_start(env, ofd, la->la_valid & LA_SIZE ? fo : NULL, th);
696 ofd_write_lock(env, fo);
697 if (!ofd_object_exists(fo))
698 GOTO(unlock, rc = -ENOENT);
700 /* serialize vs ofd_commitrw_write() */
701 if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME))
702 tgt_fmd_update(info->fti_exp, &fo->ofo_header.loh_fid,
705 rc = dt_attr_set(env, ofd_object_child(fo), la, th);
709 fl = ofd_object_ff_update(env, fo, oa, ff);
711 GOTO(unlock, rc = fl);
714 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR1))
715 ff->ff_parent.f_oid = cpu_to_le32(1UL << 31);
716 else if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR2))
717 le32_add_cpu(&ff->ff_parent.f_oid, -1);
718 else if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NOPFID))
721 info->fti_buf.lb_buf = ff;
722 info->fti_buf.lb_len = sizeof(*ff);
723 rc = dt_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
724 XATTR_NAME_FID, fl, th);
726 filter_fid_le_to_cpu(&fo->ofo_ff, ff, sizeof(*ff));
732 ofd_write_unlock(env, fo);
734 rc2 = ofd_trans_stop(env, ofd, th, rc);
736 CERROR("%s: failed to stop transaction: rc = %d\n",
745 * Truncate/punch OFD object.
747 * This function frees all of the allocated object's space from the \a start
748 * offset to the \a end offset. For truncate() operations the \a end offset
749 * is OBD_OBJECT_EOF. The functionality to punch holes in an object via
750 * fallocate(FALLOC_FL_PUNCH_HOLE) is not yet implemented (see LU-3606).
752 * \param[in] env execution environment
753 * \param[in] fo OFD object
754 * \param[in] start start offset to punch from
755 * \param[in] end end of punch
756 * \param[in] la object attributes
757 * \param[in] oa obdo struct from incoming request
759 * \retval 0 if successful
760 * \retval negative value on error
762 int ofd_object_punch(const struct lu_env *env, struct ofd_object *fo,
763 __u64 start, __u64 end, struct lu_attr *la,
766 struct ofd_thread_info *info = ofd_info(env);
767 struct ofd_device *ofd = ofd_obj2dev(fo);
768 struct dt_object *dob = ofd_object_child(fo);
769 struct filter_fid *ff = &info->fti_mds_fid;
775 /* we support truncate, not punch yet */
776 LASSERT(end == OBD_OBJECT_EOF);
778 if (!ofd_object_exists(fo))
779 GOTO(out, rc = -ENOENT);
781 if (ofd->ofd_lfsck_verify_pfid && oa->o_valid & OBD_MD_FLFID) {
782 rc = ofd_verify_ff(env, fo, oa);
787 /* VBR: version recovery check */
788 rc = ofd_version_get_check(info, fo);
792 rc = ofd_attr_handle_id(env, fo, la, 0 /* !is_setattr */);
796 th = ofd_trans_create(env, ofd);
798 GOTO(out, rc = PTR_ERR(th));
800 rc = dt_declare_attr_set(env, dob, la, th);
804 rc = dt_declare_punch(env, dob, start, OBD_OBJECT_EOF, th);
808 info->fti_buf.lb_buf = ff;
809 info->fti_buf.lb_len = sizeof(*ff);
810 rc = dt_declare_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
811 XATTR_NAME_FID, 0, th);
815 rc = ofd_trans_start(env, ofd, fo, th);
819 ofd_write_lock(env, fo);
821 if (la->la_valid & (LA_ATIME | LA_MTIME | LA_CTIME))
822 tgt_fmd_update(info->fti_exp, &fo->ofo_header.loh_fid,
825 if (!ofd_object_exists(fo))
826 GOTO(unlock, rc = -ENOENT);
828 /* need to verify layout version */
829 if (oa->o_valid & OBD_MD_LAYOUT_VERSION) {
830 rc = ofd_verify_layout_version(env, fo, oa);
834 oa->o_valid &= ~OBD_MD_LAYOUT_VERSION;
837 rc = dt_punch(env, dob, start, OBD_OBJECT_EOF, th);
841 fl = ofd_object_ff_update(env, fo, oa, ff);
843 GOTO(unlock, rc = fl);
845 rc = dt_attr_set(env, dob, la, th);
850 if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR1))
851 ff->ff_parent.f_oid = cpu_to_le32(1UL << 31);
852 else if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_UNMATCHED_PAIR2))
853 le32_add_cpu(&ff->ff_parent.f_oid, -1);
854 else if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NOPFID))
857 info->fti_buf.lb_buf = ff;
858 info->fti_buf.lb_len = sizeof(*ff);
859 rc = dt_xattr_set(env, ofd_object_child(fo), &info->fti_buf,
860 XATTR_NAME_FID, fl, th);
862 filter_fid_le_to_cpu(&fo->ofo_ff, ff, sizeof(*ff));
868 ofd_write_unlock(env, fo);
870 rc2 = ofd_trans_stop(env, ofd, th, rc);
872 CERROR("%s: failed to stop transaction: rc = %d\n",
881 * Destroy OFD object.
883 * This function destroys OFD object. If object wasn't used at all (orphan)
884 * then local transaction is used, which means the transaction data is not
885 * returned back in reply.
887 * \param[in] env execution environment
888 * \param[in] fo OFD object
889 * \param[in] orphan flag to indicate that object is orphaned
891 * \retval 0 if successful
892 * \retval negative value on error
894 int ofd_destroy(const struct lu_env *env, struct ofd_object *fo,
897 struct ofd_device *ofd = ofd_obj2dev(fo);
904 if (!ofd_object_exists(fo))
905 GOTO(out, rc = -ENOENT);
907 th = ofd_trans_create(env, ofd);
909 GOTO(out, rc = PTR_ERR(th));
911 rc = dt_declare_ref_del(env, ofd_object_child(fo), th);
915 rc = dt_declare_destroy(env, ofd_object_child(fo), th);
920 rc = dt_trans_start_local(env, ofd->ofd_osd, th);
922 rc = ofd_trans_start(env, ofd, NULL, th);
926 ofd_write_lock(env, fo);
927 if (!ofd_object_exists(fo))
928 GOTO(stop, rc = -ENOENT);
930 tgt_fmd_drop(ofd_info(env)->fti_exp, &fo->ofo_header.loh_fid);
932 dt_ref_del(env, ofd_object_child(fo), th);
933 dt_destroy(env, ofd_object_child(fo), th);
934 ofd_write_unlock(env, fo);
937 rc2 = ofd_trans_stop(env, ofd, th, rc);
939 CERROR("%s failed to stop transaction: %d\n",
948 * Get OFD object attributes.
950 * This function gets OFD object regular attributes. It is used to serve
951 * incoming request as well as for local OFD purposes.
953 * \param[in] env execution environment
954 * \param[in] fo OFD object
955 * \param[in] la object attributes
957 * \retval 0 if successful
958 * \retval negative value on error
960 int ofd_attr_get(const struct lu_env *env, struct ofd_object *fo,
967 if (ofd_object_exists(fo)) {
968 rc = dt_attr_get(env, ofd_object_child(fo), la);