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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_lov.c
38 * Lustre Metadata Server (mds) handling of striped file data
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: wangdi <wangdi@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_MDS
46 #include <linux/module.h>
48 #include <obd_class.h>
49 #include <lustre_ver.h>
50 #include <obd_support.h>
52 #include <lprocfs_status.h>
53 #include <lustre_mds.h>
54 #include <lustre_fid.h>
55 #include <lustre/lustre_idl.h>
57 #include "mdd_internal.h"
59 static int mdd_notify(struct obd_device *host, struct obd_device *watched,
60 enum obd_notify_event ev, void *owner, void *data)
62 struct mdd_device *mdd = owner;
66 LASSERT(owner != NULL);
69 case OBD_NOTIFY_ACTIVE:
71 case OBD_NOTIFY_SYNC_NONBLOCK:
72 rc = md_do_upcall(NULL, &mdd->mdd_md_dev,
75 case OBD_NOTIFY_CONFIG:
76 rc = md_do_upcall(NULL, &mdd->mdd_md_dev,
80 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
86 /* The obd is created for handling data stack for mdd */
87 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
88 struct lustre_cfg *cfg)
90 char *dev = lustre_cfg_string(cfg, 0);
91 int rc, name_size, uuid_size;
94 struct lustre_cfg_bufs *bufs;
95 struct lustre_cfg *lcfg;
96 struct obd_device *obd;
99 mds_id = lu_site2md(mdd2lu_dev(mdd)->ld_site)->ms_node_id;
100 name_size = strlen(MDD_OBD_NAME) + 35;
101 uuid_size = strlen(MDD_OBD_UUID) + 35;
103 OBD_ALLOC(name, name_size);
104 OBD_ALLOC(uuid, uuid_size);
105 if (name == NULL || uuid == NULL)
106 GOTO(cleanup_mem, rc = -ENOMEM);
110 GOTO(cleanup_mem, rc = -ENOMEM);
112 snprintf(name, strlen(MDD_OBD_NAME) + 35, "%s-%s",
115 snprintf(uuid, strlen(MDD_OBD_UUID) + 35, "%s-%s",
118 lustre_cfg_bufs_reset(bufs, name);
119 lustre_cfg_bufs_set_string(bufs, 1, MDD_OBD_TYPE);
120 lustre_cfg_bufs_set_string(bufs, 2, uuid);
121 lustre_cfg_bufs_set_string(bufs, 3, (char*)dev/* MDD_OBD_PROFILE */);
122 lustre_cfg_bufs_set_string(bufs, 4, (char*)dev);
124 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
127 GOTO(cleanup_mem, rc = -ENOMEM);
129 rc = class_attach(lcfg);
131 GOTO(lcfg_cleanup, rc);
133 obd = class_name2obd(name);
135 CERROR("Can not find obd %s\n", MDD_OBD_NAME);
139 cfs_spin_lock(&obd->obd_dev_lock);
140 obd->obd_recovering = 1;
141 cfs_spin_unlock(&obd->obd_dev_lock);
142 obd->u.mds.mds_id = mds_id;
143 obd->u.obt.obt_osd_properties.osd_max_ea_size =
144 mdd->mdd_dt_conf.ddp_max_ea_size;
146 rc = class_setup(obd, lcfg);
148 GOTO(class_detach, rc);
151 * Add here for obd notify mechanism, when adding a new ost, the mds
152 * will notify this mdd.
154 obd->obd_upcall.onu_upcall = mdd_notify;
155 obd->obd_upcall.onu_owner = mdd;
156 mdd->mdd_obd_dev = obd;
161 class_detach(obd, lcfg);
163 lustre_cfg_free(lcfg);
166 OBD_FREE(name, name_size);
168 OBD_FREE(uuid, uuid_size);
172 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
173 struct lustre_cfg *lcfg)
175 struct obd_device *obd;
179 obd = mdd2obd_dev(mdd);
182 rc = class_cleanup(obd, lcfg);
184 GOTO(lcfg_cleanup, rc);
186 obd->obd_upcall.onu_upcall = NULL;
187 obd->obd_upcall.onu_owner = NULL;
188 rc = class_detach(obd, lcfg);
190 GOTO(lcfg_cleanup, rc);
191 mdd->mdd_obd_dev = NULL;
198 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
199 void *md, int *md_size, const char *name)
204 rc = mdo_xattr_get(env, obj, mdd_buf_get(env, md, *md_size), name,
205 mdd_object_capa(env, obj));
207 * XXX: Handling of -ENODATA, the right way is to have ->do_md_get()
208 * exported by dt layer.
210 if (rc == 0 || rc == -ENODATA) {
214 CDEBUG(D_OTHER, "Error %d reading eadata - %d\n",
217 /* XXX: Convert lov EA but fixed after verification test. */
224 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
225 void *md, int *md_size, const char *name)
228 mdd_read_lock(env, obj, MOR_TGT_CHILD);
229 rc = mdd_get_md(env, obj, md, md_size, name);
230 mdd_read_unlock(env, obj);
234 static int mdd_lov_set_stripe_md(const struct lu_env *env,
235 struct mdd_object *obj, struct lu_buf *buf,
236 struct thandle *handle)
238 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
239 struct obd_device *obd = mdd2obd_dev(mdd);
240 struct obd_export *lov_exp = obd->u.mds.mds_lov_exp;
241 struct lov_stripe_md *lsm = NULL;
245 LASSERT(S_ISDIR(mdd_object_type(obj)) || S_ISREG(mdd_object_type(obj)));
246 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, lov_exp, 0,
250 obd_free_memmd(lov_exp, &lsm);
252 rc = mdd_xattr_set_txn(env, obj, buf, XATTR_NAME_LOV, 0, handle);
254 CDEBUG(D_INFO, "set lov ea of "DFID" rc %d \n", PFID(mdo2fid(obj)), rc);
259 * Permission check is done before call it,
260 * no need check again.
262 static int mdd_lov_set_dir_md(const struct lu_env *env,
263 struct mdd_object *obj, struct lu_buf *buf,
264 struct thandle *handle)
266 struct lov_user_md *lum = NULL;
270 LASSERT(S_ISDIR(mdd_object_type(obj)));
271 lum = (struct lov_user_md*)buf->lb_buf;
273 /* if { size, offset, count } = { 0, -1, 0 } and no pool
274 * (i.e. all default values specified) then delete default
275 * striping from dir. */
276 if (LOVEA_DELETE_VALUES(lum->lmm_stripe_size, lum->lmm_stripe_count,
277 lum->lmm_stripe_offset) &&
278 lum->lmm_magic != LOV_USER_MAGIC_V3) {
279 rc = mdd_xattr_set_txn(env, obj, &LU_BUF_NULL,
280 XATTR_NAME_LOV, 0, handle);
283 CDEBUG(D_INFO, "delete lov ea of "DFID" rc %d \n",
284 PFID(mdo2fid(obj)), rc);
286 rc = mdd_lov_set_stripe_md(env, obj, buf, handle);
291 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj)
293 struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
294 struct md_ucred *uc = md_ucred(env);
298 rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA);
302 if ((uc->mu_fsuid != tmp_la->la_uid) &&
303 !mdd_capable(uc, CFS_CAP_FOWNER))
304 rc = mdd_permission_internal_locked(env, obj, tmp_la,
305 MAY_WRITE, MOR_TGT_CHILD);
310 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
311 struct mdd_object *child, struct lov_mds_md *lmmp,
312 int lmm_size, struct thandle *handle, int set_stripe)
319 buf = mdd_buf_get(env, lmmp, lmm_size);
320 mode = mdd_object_type(child);
321 if (S_ISREG(mode) && lmm_size > 0) {
323 rc = mdd_lov_set_stripe_md(env, child, buf, handle);
325 rc = mdd_xattr_set_txn(env, child, buf,
326 XATTR_NAME_LOV, 0, handle);
328 } else if (S_ISDIR(mode)) {
329 if (lmmp == NULL && lmm_size == 0) {
330 struct mdd_device *mdd = mdd_obj2mdd_dev(child);
331 struct lov_mds_md *lmm = mdd_max_lmm_get(env, mdd);
332 int size = sizeof(struct lov_mds_md_v3);
334 /* Get parent dir stripe and set */
336 rc = mdd_get_md_locked(env, pobj, lmm, &size,
339 buf = mdd_buf_get(env, lmm, size);
340 rc = mdd_xattr_set_txn(env, child, buf,
344 CERROR("error on copy stripe info: rc "
348 LASSERT(lmmp != NULL && lmm_size > 0);
349 rc = mdd_lov_set_dir_md(env, child, buf, handle);
352 CDEBUG(D_INFO, "Set lov md %p size %d for fid "DFID" rc %d\n",
353 lmmp, lmm_size, PFID(mdo2fid(child)), rc);
357 int mdd_lov_objid_prepare(struct mdd_device *mdd, struct lov_mds_md *lmm)
359 /* copy mds_lov code is using wrong layer */
360 return mds_lov_prepare_objids(mdd->mdd_obd_dev, lmm);
363 int mdd_declare_lov_objid_update(const struct lu_env *env,
364 struct mdd_device *mdd,
365 struct thandle *handle)
367 struct obd_device *obd = mdd2obd_dev(mdd);
370 /* in prepare we create local files */
371 if (unlikely(mdd->mdd_capa == NULL))
374 /* XXX: this is a temporary solution to declare llog changes
375 * will be fixed in 2.3 with new llog implementation */
377 size = obd->u.mds.mds_lov_desc.ld_tgt_count * sizeof(obd_id);
378 return dt_declare_record_write(env, mdd->mdd_capa, size, 0, handle);
381 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm)
383 /* copy mds_lov code is using wrong layer */
384 mds_lov_update_objids(mdd->mdd_obd_dev, lmm);
387 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
388 struct lov_mds_md *lmm, int lmm_size,
389 const struct md_op_spec *spec)
391 if (lmm && !spec->no_create)
392 OBD_FREE_LARGE(lmm, lmm_size);
395 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
396 struct mdd_object *parent, struct mdd_object *child,
397 struct lov_mds_md **lmm, int *lmm_size,
398 const struct md_op_spec *spec, struct md_attr *ma)
400 struct obd_device *obd = mdd2obd_dev(mdd);
401 struct obd_export *lov_exp = obd->u.mds.mds_lov_exp;
402 struct lu_site *site = mdd2lu_dev(mdd)->ld_site;
404 struct lov_stripe_md *lsm = NULL;
405 const void *eadata = spec->u.sp_ea.eadata;
406 __u64 create_flags = spec->sp_cr_flags;
407 struct obd_trans_info *oti = &mdd_env_info(env)->mti_oti;
408 struct lu_attr *la = &ma->ma_attr;
412 if (!md_should_create(create_flags)) {
418 /* replay case, has objects already, only get lov from eadata */
419 if (spec->no_create != 0) {
420 *lmm = (struct lov_mds_md *)spec->u.sp_ea.eadata;
421 *lmm_size = spec->u.sp_ea.eadatalen;
422 if (*lmm_size == lov_mds_md_size((*lmm)->lmm_stripe_count,
423 (*lmm)->lmm_magic)) {
426 CERROR("incorrect lsm received during recovery\n");
431 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO))
432 GOTO(out_ids, rc = -ENOMEM);
434 LASSERT(lov_exp != NULL);
435 oa = &mdd_env_info(env)->mti_oa;
437 oa->o_uid = 0; /* must have 0 uid / gid on OST */
439 oa->o_seq = mdt_to_obd_objseq(lu_site2md(site)->ms_node_id);
440 oa->o_mode = S_IFREG | 0600;
441 oa->o_id = fid_ver_oid(mdd_object_fid(child));
442 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLFLAGS |
443 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLGROUP;
446 if (!(create_flags & MDS_OPEN_HAS_OBJS)) {
447 if (create_flags & MDS_OPEN_HAS_EA) {
448 LASSERT(eadata != NULL);
449 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, lov_exp,
450 0, &lsm, (void*)eadata);
454 /* get lov ea from parent and set to lov */
455 struct lov_mds_md *_lmm;
456 int _lmm_size = mdd_lov_mdsize(env, mdd);
458 LASSERT(parent != NULL);
461 * can not create child's lov_mds_md by access it
464 if (mdd_object_obf(parent))
465 GOTO(out_oti, rc = -EBADFD);
467 _lmm = mdd_max_lmm_get(env, mdd);
469 GOTO(out_oti, rc = -ENOMEM);
471 rc = mdd_get_md_locked(env, parent, _lmm,
475 _lmm_size = mdd_lov_mdsize(env, mdd);
476 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE,
484 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_OPEN_WAIT_CREATE, 10);
485 rc = obd_create(env, lov_exp, oa, &lsm, oti);
488 CERROR("Create error for "DFID": %d\n",
489 PFID(mdo2fid(child)), rc);
495 if (ma->ma_valid & MA_LAY_GEN)
496 /* If we already have a lsm, the file is not new and we
497 * are about to change the layout, so we have to bump
498 * the generation. It is worth noting that old versions
499 * will be confused by a non-zero gen, that's why
500 * OBD_INCOMPAT_LMM_VER has been introduced */
501 lsm->lsm_layout_gen = ma->ma_layout_gen + 1;
503 /* Start with a null generation for backward
504 * compatiblity with old versions */
505 lsm->lsm_layout_gen = 0;
507 LASSERT_SEQ_IS_MDT(lsm->lsm_object_seq);
509 LASSERT(eadata != NULL);
510 rc = obd_iocontrol(OBD_IOC_LOV_SETEA, lov_exp, 0, &lsm,
515 if (ma->ma_valid & MA_LAY_GEN)
516 lsm->lsm_layout_gen = ma->ma_layout_gen;
518 lsm->lsm_layout_gen = 0;
521 lsm->lsm_object_id = fid_ver_oid(mdd_object_fid(child));
522 lsm->lsm_object_seq = fid_seq(mdd_object_fid(child));
524 * Sometimes, we may truncate some object(without lsm) then open it
525 * (with write flags), so creating lsm above. The Nonzero(truncated)
526 * size should tell ost, since size attr is in charge by OST.
528 if (la->la_size && la->la_valid & LA_SIZE) {
529 struct obd_info *oinfo = &mdd_env_info(env)->mti_oi;
531 memset(oinfo, 0, sizeof(*oinfo));
533 /* When setting attr to ost, FLBKSZ is not needed. */
534 oa->o_valid &= ~OBD_MD_FLBLKSZ;
535 obdo_from_la(oa, la, LA_TYPE | LA_ATIME | LA_MTIME |
538 * XXX: Pack lustre id to OST, in OST, it will be packed by
539 * filter_fid, but can not see what is the usages. So just pack
540 * o_seq o_ver here, maybe fix it after this cycle.
542 obdo_set_parent_fid(oa, mdd_object_fid(child));
545 oinfo->oi_capa = NULL;
546 oinfo->oi_policy.l_extent.start = la->la_size;
547 oinfo->oi_policy.l_extent.end = OBD_OBJECT_EOF;
549 rc = obd_punch_rqset(lov_exp, oinfo, oti);
551 CERROR("Error setting attrs for "DFID": rc %d\n",
552 PFID(mdo2fid(child)), rc);
554 CERROR("obd_setattr for "DFID" rc %d\n",
555 PFID(mdo2fid(child)), rc);
561 /* blksize should be changed after create data object */
562 la->la_valid |= LA_BLKSIZE;
563 la->la_blksize = oa->o_blksize;
565 rc = obd_packmd(lov_exp, lmm, lsm);
567 CERROR("Cannot pack lsm, err = %d\n", rc);
570 if (mdd_lov_objid_prepare(mdd, *lmm) != 0) {
571 CERROR("Not have memory for update objid\n");
574 GOTO(out_oti, rc = -ENOMEM);
580 oti_free_cookies(oti);
583 obd_free_memmd(lov_exp, &lsm);
589 * used when destroying orphans and from mds_reint_unlink() when MDS wants to
590 * destroy objects on OSS.
592 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
593 struct mdd_object *obj, struct lu_attr *la,
594 struct md_attr *ma, int log_unlink)
596 struct obd_device *obd = mdd2obd_dev(mdd);
597 struct obd_export *lov_exp = obd->u.mds.mds_lov_exp;
598 struct lov_stripe_md *lsm = NULL;
599 struct obd_trans_info *oti = &mdd_env_info(env)->mti_oti;
600 struct obdo *oa = &mdd_env_info(env)->mti_oa;
601 struct lu_site *site = mdd2lu_dev(mdd)->ld_site;
602 struct lov_mds_md *lmm = ma->ma_lmm;
603 int lmm_size = ma->ma_lmm_size;
604 struct llog_cookie *logcookies = ma->ma_cookie;
611 rc = obd_unpackmd(lov_exp, &lsm, lmm, lmm_size);
613 CERROR("Error unpack md %p\n", lmm);
616 LASSERT(rc >= sizeof(*lsm));
620 oa->o_id = lsm->lsm_object_id;
621 oa->o_seq = mdt_to_obd_objseq(lu_site2md(site)->ms_node_id);
622 oa->o_mode = la->la_mode & S_IFMT;
623 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
626 if (log_unlink && logcookies) {
627 oa->o_valid |= OBD_MD_FLCOOKIE;
628 oti->oti_logcookies = logcookies;
631 if (!(ma->ma_attr_flags & MDS_UNLINK_DESTROY))
632 oa->o_flags = OBD_FL_DELORPHAN;
634 CDEBUG(D_INFO, "destroying OSS object "LPU64":"LPU64"\n", oa->o_seq,
637 rc = obd_destroy(env, lov_exp, oa, lsm, oti, NULL, NULL);
639 obd_free_memmd(lov_exp, &lsm);
644 * called with obj locked.
646 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
647 struct mdd_object *obj, struct lu_attr *la)
649 struct md_attr *ma = &mdd_env_info(env)->mti_ma;
653 LASSERT(mdd_write_locked(env, obj) != 0);
655 if (unlikely(!S_ISREG(mdd_object_type(obj))))
658 if (unlikely(la->la_nlink != 0)) {
659 CWARN("Attempt to destroy OSS object when nlink == %d\n",
664 ma->ma_lmm_size = mdd_lov_mdsize(env, mdd);
665 ma->ma_lmm = mdd_max_lmm_get(env, mdd);
666 ma->ma_cookie_size = mdd_lov_cookiesize(env, mdd);
667 ma->ma_cookie = mdd_max_cookie_get(env, mdd);
668 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
669 RETURN(rc = -ENOMEM);
673 rc = mdd_get_md(env, obj, ma->ma_lmm, &ma->ma_lmm_size,
677 CWARN("Get lov ea failed for "DFID" rc = %d\n",
678 PFID(mdo2fid(obj)), rc);
684 ma->ma_valid = MA_LOV;
686 rc = mdd_unlink_log(env, mdd, obj, ma);
688 CWARN("mds unlink log for "DFID" failed: %d\n",
689 PFID(mdo2fid(obj)), rc);
693 if (ma->ma_valid & MA_COOKIE)
694 rc = mdd_lovobj_unlink(env, mdd, obj, la, ma, 1);
699 int mdd_declare_unlink_log(const struct lu_env *env, struct mdd_object *obj,
700 struct md_attr *ma, struct thandle *handle)
702 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
709 if (!S_ISREG(lu_object_attr(&obj->mod_obj.mo_lu)))
712 rc = mdd_lmm_get_locked(env, obj, ma);
713 if (rc || !(ma->ma_valid & MA_LOV))
717 if (le32_to_cpu(ma->ma_lmm->lmm_magic) != LOV_MAGIC_V1 &&
718 le32_to_cpu(ma->ma_lmm->lmm_magic) != LOV_MAGIC_V3) {
719 CERROR("%s: invalid LOV_MAGIC %08x on object "DFID"\n",
720 mdd->mdd_obd_dev->obd_name,
721 le32_to_cpu(ma->ma_lmm->lmm_magic),
722 PFID(lu_object_fid(&obj->mod_obj.mo_lu)));
726 stripe = le16_to_cpu(ma->ma_lmm->lmm_stripe_count);
727 if (stripe == LOV_ALL_STRIPES);
728 stripe = mdd2obd_dev(mdd)->u.mds.mds_lov_desc.ld_tgt_count;
730 for (i = 0; i < stripe; i++) {
731 rc = mdd_declare_llog_record(env, mdd,
732 sizeof(struct llog_unlink_rec),
741 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
742 struct mdd_object *mdd_cobj, struct md_attr *ma)
744 LASSERT(ma->ma_valid & MA_LOV);
746 if ((ma->ma_cookie_size > 0) &&
747 (mds_log_op_unlink(mdd2obd_dev(mdd), ma->ma_lmm, ma->ma_lmm_size,
748 ma->ma_cookie, ma->ma_cookie_size) > 0)) {
749 CDEBUG(D_HA, "DEBUG: unlink log is added for object "DFID"\n",
750 PFID(mdd_object_fid(mdd_cobj)));
751 ma->ma_valid |= MA_COOKIE;
756 int mdd_log_op_setattr(struct obd_device *obd, __u32 uid, __u32 gid,
757 struct lov_mds_md *lmm, int lmm_size,
758 struct llog_cookie *logcookies, int cookies_size)
760 struct mds_obd *mds = &obd->u.mds;
761 struct lov_stripe_md *lsm = NULL;
762 struct llog_setattr64_rec *lsr;
763 struct llog_ctxt *ctxt;
767 if (IS_ERR(mds->mds_lov_obd))
768 RETURN(PTR_ERR(mds->mds_lov_obd));
770 rc = obd_unpackmd(mds->mds_lov_exp, &lsm, lmm, lmm_size);
774 OBD_ALLOC(lsr, sizeof(*lsr));
776 GOTO(out, rc = -ENOMEM);
778 /* prepare setattr log record */
779 lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
780 lsr->lsr_hdr.lrh_type = MDS_SETATTR64_REC;
784 /* write setattr log */
785 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
786 rc = llog_obd_add(NULL, ctxt, &lsr->lsr_hdr, lsm, logcookies,
787 cookies_size / sizeof(struct llog_cookie));
791 OBD_FREE(lsr, sizeof(*lsr));
793 obd_free_memmd(mds->mds_lov_exp, &lsm);
797 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
798 const struct md_attr *ma,
799 struct lov_mds_md *lmm, int lmm_size,
800 struct llog_cookie *logcookies, int cookies_size)
802 struct obd_device *obd = mdd2obd_dev(mdd);
804 /* journal chown/chgrp in llog, just like unlink */
806 CDEBUG(D_INFO, "setattr llog for uid/gid=%lu/%lu\n",
807 (unsigned long)ma->ma_attr.la_uid,
808 (unsigned long)ma->ma_attr.la_gid);
809 return mdd_log_op_setattr(obd, ma->ma_attr.la_uid,
810 ma->ma_attr.la_gid, lmm,
811 lmm_size, logcookies,
817 static int mdd_osc_setattr_async(struct obd_device *obd, __u32 uid, __u32 gid,
818 struct lov_mds_md *lmm, int lmm_size,
819 struct llog_cookie *logcookies, const struct lu_fid *parent,
822 struct mds_obd *mds = &obd->u.mds;
823 struct obd_trans_info oti = { 0 };
824 struct obd_info oinfo = { { { 0 } } };
828 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OST_SETATTR))
831 /* first get memory EA */
832 OBDO_ALLOC(oinfo.oi_oa);
838 rc = obd_unpackmd(mds->mds_lov_exp, &oinfo.oi_md, lmm, lmm_size);
840 CERROR("Error unpack md %p for obj "DFID"\n", lmm,
846 oinfo.oi_oa->o_uid = uid;
847 oinfo.oi_oa->o_gid = gid;
848 oinfo.oi_oa->o_id = oinfo.oi_md->lsm_object_id;
849 oinfo.oi_oa->o_seq = oinfo.oi_md->lsm_object_seq;
850 oinfo.oi_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP |
851 OBD_MD_FLUID | OBD_MD_FLGID;
853 oinfo.oi_oa->o_valid |= OBD_MD_FLCOOKIE;
854 oti.oti_logcookies = logcookies;
857 obdo_set_parent_fid(oinfo.oi_oa, parent);
860 /* do async setattr from mds to ost not waiting for responses. */
861 rc = obd_setattr_async(mds->mds_lov_exp, &oinfo, &oti, NULL);
863 CDEBUG(D_INODE, "mds to ost setattr objid 0x"LPX64
864 " on ost error %d\n", oinfo.oi_md->lsm_object_id, rc);
867 obd_free_memmd(mds->mds_lov_exp, &oinfo.oi_md);
868 OBDO_FREE(oinfo.oi_oa);
872 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
873 struct lov_mds_md *lmm, int lmm_size,
874 struct llog_cookie *logcookies)
876 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
877 struct obd_device *obd = mdd2obd_dev(mdd);
878 struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
879 const struct lu_fid *fid = mdd_object_fid(obj);
883 mdd_read_lock(env, obj, MOR_TGT_CHILD);
884 rc = mdo_attr_get(env, obj, tmp_la, mdd_object_capa(env, obj));
885 mdd_read_unlock(env, obj);
889 rc = mdd_osc_setattr_async(obd, tmp_la->la_uid, tmp_la->la_gid, lmm,
890 lmm_size, logcookies, fid, NULL);