1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include <linux/module.h>
51 #include <obd_class.h>
52 #include <lustre_ver.h>
53 #include <obd_support.h>
55 #include <lprocfs_status.h>
56 #include <lustre_mds.h>
57 #include <lustre_fid.h>
58 #include <lustre/lustre_idl.h>
60 #include "mdd_internal.h"
62 static int mdd_notify(struct obd_device *host, struct obd_device *watched,
63 enum obd_notify_event ev, void *owner)
65 struct mdd_device *mdd = owner;
69 LASSERT(owner != NULL);
72 case OBD_NOTIFY_ACTIVE:
74 case OBD_NOTIFY_SYNC_NONBLOCK:
75 rc = md_do_upcall(NULL, &mdd->mdd_md_dev, MD_LOV_SYNC);
77 case OBD_NOTIFY_CONFIG:
78 rc = md_do_upcall(NULL, &mdd->mdd_md_dev, MD_LOV_CONFIG);
81 CDEBUG(D_INFO, "Unhandled notification %#x\n", ev);
87 /* The obd is created for handling data stack for mdd */
88 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
89 struct lustre_cfg *cfg)
91 char *dev = lustre_cfg_string(cfg, 0);
92 int rc, name_size, uuid_size;
95 struct lustre_cfg_bufs *bufs;
96 struct lustre_cfg *lcfg;
97 struct obd_device *obd;
100 mds_id = mdd2lu_dev(mdd)->ld_site->ls_node_id;
101 name_size = strlen(MDD_OBD_NAME) + 35;
102 uuid_size = strlen(MDD_OBD_UUID) + 35;
104 OBD_ALLOC(name, name_size);
105 OBD_ALLOC(uuid, uuid_size);
106 if (name == NULL || uuid == NULL)
107 GOTO(cleanup_mem, rc = -ENOMEM);
111 GOTO(cleanup_mem, rc = -ENOMEM);
113 snprintf(name, strlen(MDD_OBD_NAME) + 35, "%s-%s-%d",
114 MDD_OBD_NAME, dev, mds_id);
116 snprintf(uuid, strlen(MDD_OBD_UUID) + 35, "%s-%s-%d",
117 MDD_OBD_UUID, dev, mds_id);
119 lustre_cfg_bufs_reset(bufs, name);
120 lustre_cfg_bufs_set_string(bufs, 1, MDD_OBD_TYPE);
121 lustre_cfg_bufs_set_string(bufs, 2, uuid);
122 lustre_cfg_bufs_set_string(bufs, 3, (char*)dev/* MDD_OBD_PROFILE */);
123 lustre_cfg_bufs_set_string(bufs, 4, (char*)dev);
125 lcfg = lustre_cfg_new(LCFG_ATTACH, bufs);
128 GOTO(cleanup_mem, rc = -ENOMEM);
130 rc = class_attach(lcfg);
132 GOTO(lcfg_cleanup, rc);
134 obd = class_name2obd(name);
136 CERROR("Can not find obd %s\n", MDD_OBD_NAME);
140 obd->obd_recovering = 1;
141 obd->u.mds.mds_id = mds_id;
142 rc = class_setup(obd, lcfg);
144 GOTO(class_detach, rc);
147 * Add here for obd notify mechanism, when adding a new ost, the mds
148 * will notify this mdd.
150 obd->obd_upcall.onu_upcall = mdd_notify;
151 obd->obd_upcall.onu_owner = mdd;
152 mdd->mdd_obd_dev = obd;
157 class_detach(obd, lcfg);
159 lustre_cfg_free(lcfg);
162 OBD_FREE(name, name_size);
164 OBD_FREE(uuid, uuid_size);
168 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
169 struct lustre_cfg *lcfg)
171 struct obd_device *obd;
175 obd = mdd2obd_dev(mdd);
178 rc = class_cleanup(obd, lcfg);
180 GOTO(lcfg_cleanup, rc);
182 obd->obd_upcall.onu_upcall = NULL;
183 obd->obd_upcall.onu_owner = NULL;
184 rc = class_detach(obd, lcfg);
186 GOTO(lcfg_cleanup, rc);
187 mdd->mdd_obd_dev = NULL;
194 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
195 void *md, int *md_size, const char *name)
200 rc = mdo_xattr_get(env, obj, mdd_buf_get(env, md, *md_size), name,
201 mdd_object_capa(env, obj));
203 * XXX: Handling of -ENODATA, the right way is to have ->do_md_get()
204 * exported by dt layer.
206 if (rc == 0 || rc == -ENODATA) {
210 CERROR("Error %d reading eadata \n", rc);
212 /* XXX: Convert lov EA but fixed after verification test. */
219 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
220 void *md, int *md_size, const char *name)
223 mdd_read_lock(env, obj, MOR_TGT_CHILD);
224 rc = mdd_get_md(env, obj, md, md_size, name);
225 mdd_read_unlock(env, obj);
229 static int mdd_lov_set_stripe_md(const struct lu_env *env,
230 struct mdd_object *obj, struct lu_buf *buf,
231 struct thandle *handle)
233 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
234 struct obd_device *obd = mdd2obd_dev(mdd);
235 struct obd_export *lov_exp = obd->u.mds.mds_osc_exp;
236 struct lov_stripe_md *lsm = NULL;
240 LASSERT(S_ISDIR(mdd_object_type(obj)) || S_ISREG(mdd_object_type(obj)));
241 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, lov_exp, 0,
245 obd_free_memmd(lov_exp, &lsm);
247 rc = mdd_xattr_set_txn(env, obj, buf, MDS_LOV_MD_NAME, 0, handle);
249 CDEBUG(D_INFO, "set lov ea of "DFID" rc %d \n", PFID(mdo2fid(obj)), rc);
254 * Permission check is done before call it,
255 * no need check again.
257 static int mdd_lov_set_dir_md(const struct lu_env *env,
258 struct mdd_object *obj, struct lu_buf *buf,
259 struct thandle *handle)
261 struct lov_user_md *lum = NULL;
265 LASSERT(S_ISDIR(mdd_object_type(obj)));
266 lum = (struct lov_user_md*)buf->lb_buf;
268 /* if { size, offset, count } = { 0, -1, 0 } and no pool (i.e. all default
269 * values specified) then delete default striping from dir. */
270 if (lum->lmm_stripe_size == 0 && lum->lmm_stripe_count == 0 &&
271 lum->lmm_stripe_offset == (typeof(lum->lmm_stripe_offset))(-1) &&
272 lum->lmm_magic != LOV_USER_MAGIC_V3) {
273 rc = mdd_xattr_set_txn(env, obj, &LU_BUF_NULL,
274 MDS_LOV_MD_NAME, 0, handle);
277 CDEBUG(D_INFO, "delete lov ea of "DFID" rc %d \n",
278 PFID(mdo2fid(obj)), rc);
280 rc = mdd_lov_set_stripe_md(env, obj, buf, handle);
285 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj)
287 struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
288 struct md_ucred *uc = md_ucred(env);
292 rc = mdd_la_get(env, obj, tmp_la, BYPASS_CAPA);
296 if ((uc->mu_fsuid != tmp_la->la_uid) &&
297 !mdd_capable(uc, CFS_CAP_FOWNER))
298 rc = mdd_permission_internal_locked(env, obj, tmp_la,
299 MAY_WRITE, MOR_TGT_CHILD);
304 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
305 struct mdd_object *child, struct lov_mds_md *lmmp,
306 int lmm_size, struct thandle *handle, int set_stripe)
313 buf = mdd_buf_get(env, lmmp, lmm_size);
314 mode = mdd_object_type(child);
315 if (S_ISREG(mode) && lmm_size > 0) {
317 rc = mdd_lov_set_stripe_md(env, child, buf, handle);
319 rc = mdd_xattr_set_txn(env, child, buf,
320 MDS_LOV_MD_NAME, 0, handle);
322 } else if (S_ISDIR(mode)) {
323 if (lmmp == NULL && lmm_size == 0) {
324 struct mdd_device *mdd = mdd_obj2mdd_dev(child);
325 struct lov_mds_md *lmm = mdd_max_lmm_get(env, mdd);
326 int size = sizeof(struct lov_mds_md_v3);
328 /* Get parent dir stripe and set */
330 rc = mdd_get_md_locked(env, pobj, lmm, &size,
333 buf = mdd_buf_get(env, lmm, size);
334 rc = mdd_xattr_set_txn(env, child, buf,
335 MDS_LOV_MD_NAME, 0, handle);
337 CERROR("error on copy stripe info: rc "
341 LASSERT(lmmp != NULL && lmm_size > 0);
342 rc = mdd_lov_set_dir_md(env, child, buf, handle);
345 CDEBUG(D_INFO, "Set lov md %p size %d for fid "DFID" rc %d\n",
346 lmmp, lmm_size, PFID(mdo2fid(child)), rc);
351 * XXX: this is for create lsm object id, which should identify the lsm object
352 * unique in the whole mds, as I see. But it seems, we still not need it
353 * now. Right? So just borrow the ll_fid_build_ino().
355 static obd_id mdd_lov_create_id(const struct lu_fid *fid)
357 return fid_flatten(fid);
360 static void mdd_lov_update_objids(struct obd_device *obd, struct lov_mds_md *lmm)
362 struct mds_obd *mds = &obd->u.mds;
364 struct lov_ost_data_v1 *lmm_objects;
367 /* if we create file without objects - lmm is NULL */
371 if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V3)
372 lmm_objects = ((struct lov_mds_md_v3 *)lmm)->lmm_objects;
374 lmm_objects = lmm->lmm_objects;
376 for (j = 0; j < le32_to_cpu(lmm->lmm_stripe_count); j++) {
377 int i = le32_to_cpu(lmm_objects[j].l_ost_idx);
378 obd_id id = le64_to_cpu(lmm_objects[j].l_object_id);
379 int page = i / OBJID_PER_PAGE();
380 int idx = i % OBJID_PER_PAGE();
381 obd_id *data = mds->mds_lov_page_array[page];
383 CDEBUG(D_INODE,"update last object for ost %d - new %llu"
384 " old %llu\n", i, id, data[idx]);
385 if (id > data[idx]) {
387 cfs_bitmap_set(mds->mds_lov_page_dirty, page);
393 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm)
395 mdd_lov_update_objids(mdd->mdd_obd_dev, lmm);
398 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
399 struct lov_mds_md *lmm, int lmm_size,
400 const struct md_op_spec *spec)
402 if (lmm && !spec->u.sp_ea.no_lov_create)
403 OBD_FREE(lmm, lmm_size);
406 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
407 struct mdd_object *parent, struct mdd_object *child,
408 struct lov_mds_md **lmm, int *lmm_size,
409 const struct md_op_spec *spec, struct lu_attr *la)
411 struct obd_device *obd = mdd2obd_dev(mdd);
412 struct obd_export *lov_exp = obd->u.mds.mds_osc_exp;
414 struct lov_stripe_md *lsm = NULL;
415 const void *eadata = spec->u.sp_ea.eadata;
416 __u32 create_flags = spec->sp_cr_flags;
417 struct obd_trans_info *oti = &mdd_env_info(env)->mti_oti;
421 if (!md_should_create(create_flags))
426 /* replay case, has objects already, only get lov from eadata */
427 if (spec->u.sp_ea.no_lov_create != 0) {
428 *lmm = (struct lov_mds_md *)spec->u.sp_ea.eadata;
429 *lmm_size = spec->u.sp_ea.eadatalen;
433 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO))
434 GOTO(out_ids, rc = -ENOMEM);
436 LASSERT(lov_exp != NULL);
437 oa = &mdd_env_info(env)->mti_oa;
439 oa->o_uid = 0; /* must have 0 uid / gid on OST */
441 oa->o_gr = FILTER_GROUP_MDS0 + mdd2lu_dev(mdd)->ld_site->ls_node_id;
442 oa->o_mode = S_IFREG | 0600;
443 oa->o_id = mdd_lov_create_id(mdd_object_fid(child));
444 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLFLAGS |
445 OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLGROUP;
448 if (!(create_flags & MDS_OPEN_HAS_OBJS)) {
449 if (create_flags & MDS_OPEN_HAS_EA) {
450 LASSERT(eadata != NULL);
451 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, lov_exp,
452 0, &lsm, (void*)eadata);
455 lsm->lsm_object_id = oa->o_id;
456 lsm->lsm_object_gr = oa->o_gr;
457 } else if (parent != NULL) {
458 /* get lov ea from parent and set to lov */
459 struct lov_mds_md *_lmm;
462 _lmm_size = mdd_lov_mdsize(env, mdd);
463 _lmm = mdd_max_lmm_get(env, mdd);
466 GOTO(out_oti, rc = -ENOMEM);
468 rc = mdd_get_md_locked(env, parent, _lmm,
472 rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE,
473 lov_exp, 0, &lsm, _lmm);
478 rc = obd_create(lov_exp, oa, &lsm, oti);
481 CERROR("Create error for "DFID": %d\n",
482 PFID(mdo2fid(child)), rc);
487 LASSERT(lsm->lsm_object_gr >= FILTER_GROUP_MDS0);
489 LASSERT(eadata != NULL);
490 rc = obd_iocontrol(OBD_IOC_LOV_SETEA, lov_exp, 0, &lsm,
494 lsm->lsm_object_id = oa->o_id;
495 lsm->lsm_object_gr = oa->o_gr;
499 * Sometimes, we may truncate some object(without lsm) then open it
500 * (with write flags), so creating lsm above. The Nonzero(truncated)
501 * size should tell ost, since size attr is in charge by OST.
503 if (la->la_size && la->la_valid & LA_SIZE) {
504 struct obd_info *oinfo = &mdd_env_info(env)->mti_oi;
506 memset(oinfo, 0, sizeof(*oinfo));
508 /* When setting attr to ost, FLBKSZ is not needed. */
509 oa->o_valid &= ~OBD_MD_FLBLKSZ;
510 obdo_from_la(oa, la, OBD_MD_FLTYPE | OBD_MD_FLATIME |
511 OBD_MD_FLMTIME | OBD_MD_FLCTIME | OBD_MD_FLSIZE);
514 * XXX: Pack lustre id to OST, in OST, it will be packed by
515 * filter_fid, but can not see what is the usages. So just pack
516 * o_seq o_ver here, maybe fix it after this cycle.
518 oa->o_fid = fid_seq(mdd_object_fid(child));
519 oa->o_generation = fid_oid(mdd_object_fid(child));
520 oa->o_valid |= OBD_MD_FLFID | OBD_MD_FLGENER;
523 oinfo->oi_capa = mdo_capa_get(env, child, NULL,
524 CAPA_OPC_MDS_DEFAULT);
525 oinfo->oi_policy.l_extent.start = la->la_size;
526 oinfo->oi_policy.l_extent.end = OBD_OBJECT_EOF;
528 if (IS_ERR(oinfo->oi_capa))
529 oinfo->oi_capa = NULL;
531 rc = obd_punch_rqset(lov_exp, oinfo, oti);
532 capa_put(oinfo->oi_capa);
534 CERROR("Error setting attrs for "DFID": rc %d\n",
535 PFID(mdo2fid(child)), rc);
537 CERROR("obd_setattr for "DFID" rc %d\n",
538 PFID(mdo2fid(child)), rc);
545 /* blksize should be changed after create data object */
546 la->la_valid |= LA_BLKSIZE;
547 la->la_blksize = oa->o_blksize;
549 rc = obd_packmd(lov_exp, lmm, lsm);
551 CERROR("Cannot pack lsm, err = %d\n", rc);
558 oti_free_cookies(oti);
561 obd_free_memmd(lov_exp, &lsm);
567 * used when destroying orphans and from mds_reint_unlink() when MDS wants to
568 * destroy objects on OSS.
571 int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
572 struct mdd_object *obj, struct lu_attr *la,
573 struct lov_mds_md *lmm, int lmm_size,
574 struct llog_cookie *logcookies,
577 struct obd_device *obd = mdd2obd_dev(mdd);
578 struct obd_export *lov_exp = obd->u.mds.mds_osc_exp;
579 struct lov_stripe_md *lsm = NULL;
580 struct obd_trans_info *oti = &mdd_env_info(env)->mti_oti;
581 struct obdo *oa = &mdd_env_info(env)->mti_oa;
588 rc = obd_unpackmd(lov_exp, &lsm, lmm, lmm_size);
590 CERROR("Error unpack md %p\n", lmm);
593 LASSERT(rc >= sizeof(*lsm));
597 oa->o_id = lsm->lsm_object_id;
598 oa->o_gr = FILTER_GROUP_MDS0 + mdd2lu_dev(mdd)->ld_site->ls_node_id;
599 oa->o_mode = la->la_mode & S_IFMT;
600 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
603 if (log_unlink && logcookies) {
604 oa->o_valid |= OBD_MD_FLCOOKIE;
605 oti->oti_logcookies = logcookies;
608 CDEBUG(D_INFO, "destroying OSS object %d/%d\n",
609 (int)oa->o_id, (int)oa->o_gr);
611 rc = obd_destroy(lov_exp, oa, lsm, oti, NULL);
613 obd_free_memmd(lov_exp, &lsm);
619 * called with obj not locked.
621 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
622 struct mdd_object *obj, struct lu_attr *la)
624 struct md_attr *ma = &mdd_env_info(env)->mti_ma;
628 if (unlikely(la->la_nlink != 0)) {
629 CWARN("Attempt to destroy OSS object when nlink == %d\n",
634 ma->ma_lmm_size = mdd_lov_mdsize(env, mdd);
635 ma->ma_lmm = mdd_max_lmm_get(env, mdd);
636 ma->ma_cookie_size = mdd_lov_cookiesize(env, mdd);
637 ma->ma_cookie = mdd_max_cookie_get(env, mdd);
638 if (ma->ma_lmm == NULL || ma->ma_cookie == NULL)
639 RETURN(rc = -ENOMEM);
642 rc = mdd_get_md_locked(env, obj, ma->ma_lmm, &ma->ma_lmm_size,
645 CWARN("Get lov ea failed for "DFID"\n", PFID(mdo2fid(obj)));
648 ma->ma_valid = MA_LOV;
650 rc = mdd_unlink_log(env, mdd, obj, ma);
652 CWARN("mds unlink log for "DFID" failed: %d\n",
653 PFID(mdo2fid(obj)), rc);
656 if (ma->ma_valid | MA_COOKIE)
657 rc = mdd_lovobj_unlink(env, mdd, obj, la,
658 ma->ma_lmm, ma->ma_lmm_size,
663 int mdd_log_op_unlink(struct obd_device *obd,
664 struct lov_mds_md *lmm, int lmm_size,
665 struct llog_cookie *logcookies, int cookies_size)
667 struct mds_obd *mds = &obd->u.mds;
668 struct lov_stripe_md *lsm = NULL;
669 struct llog_unlink_rec *lur;
670 struct llog_ctxt *ctxt;
674 if (IS_ERR(mds->mds_osc_obd))
675 RETURN(PTR_ERR(mds->mds_osc_obd));
677 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
680 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
683 /* first prepare unlink log record */
684 OBD_ALLOC(lur, sizeof(*lur));
686 GOTO(out, rc = -ENOMEM);
687 lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
688 lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
690 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
691 rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookies,
692 cookies_size / sizeof(struct llog_cookie));
695 OBD_FREE(lur, sizeof(*lur));
697 obd_free_memmd(mds->mds_osc_exp, &lsm);
701 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
702 struct mdd_object *mdd_cobj, struct md_attr *ma)
704 struct obd_device *obd = mdd2obd_dev(mdd);
706 LASSERT(ma->ma_valid & MA_LOV);
708 if ((ma->ma_cookie_size > 0) &&
709 (mdd_log_op_unlink(obd, ma->ma_lmm, ma->ma_lmm_size,
710 ma->ma_cookie, ma->ma_cookie_size) > 0)) {
711 ma->ma_valid |= MA_COOKIE;
716 int mdd_log_op_setattr(struct obd_device *obd, __u32 uid, __u32 gid,
717 struct lov_mds_md *lmm, int lmm_size,
718 struct llog_cookie *logcookies, int cookies_size)
720 struct mds_obd *mds = &obd->u.mds;
721 struct lov_stripe_md *lsm = NULL;
722 struct llog_setattr_rec *lsr;
723 struct llog_ctxt *ctxt;
727 if (IS_ERR(mds->mds_osc_obd))
728 RETURN(PTR_ERR(mds->mds_osc_obd));
730 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
734 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
738 OBD_ALLOC(lsr, sizeof(*lsr));
740 GOTO(out, rc = -ENOMEM);
742 /* prepare setattr log record */
743 lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
744 lsr->lsr_hdr.lrh_type = MDS_SETATTR_REC;
748 /* write setattr log */
749 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
750 rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
751 cookies_size / sizeof(struct llog_cookie));
755 OBD_FREE(lsr, sizeof(*lsr));
757 obd_free_memmd(mds->mds_osc_exp, &lsm);
761 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
762 const struct md_attr *ma,
763 struct lov_mds_md *lmm, int lmm_size,
764 struct llog_cookie *logcookies, int cookies_size)
766 struct obd_device *obd = mdd2obd_dev(mdd);
768 /* journal chown/chgrp in llog, just like unlink */
770 CDEBUG(D_INFO, "setattr llog for uid/gid=%lu/%lu\n",
771 (unsigned long)ma->ma_attr.la_uid,
772 (unsigned long)ma->ma_attr.la_gid);
773 return mdd_log_op_setattr(obd, ma->ma_attr.la_uid,
774 ma->ma_attr.la_gid, lmm,
775 lmm_size, logcookies,
781 static int mdd_osc_setattr_async(struct obd_device *obd, __u32 uid, __u32 gid,
782 struct lov_mds_md *lmm, int lmm_size,
783 struct llog_cookie *logcookies, __u64 id, __u32 gen,
786 struct mds_obd *mds = &obd->u.mds;
787 struct obd_trans_info oti = { 0 };
788 struct obd_info oinfo = { { { 0 } } };
792 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OST_SETATTR))
795 /* first get memory EA */
796 OBDO_ALLOC(oinfo.oi_oa);
802 rc = obd_unpackmd(mds->mds_osc_exp, &oinfo.oi_md, lmm, lmm_size);
804 CERROR("Error unpack md %p for inode "LPU64"\n", lmm, id);
808 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, oinfo.oi_md);
810 CERROR("Error revalidate lsm %p \n", oinfo.oi_md);
815 oinfo.oi_oa->o_uid = uid;
816 oinfo.oi_oa->o_gid = gid;
817 oinfo.oi_oa->o_id = oinfo.oi_md->lsm_object_id;
818 oinfo.oi_oa->o_gr = oinfo.oi_md->lsm_object_gr;
819 oinfo.oi_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP |
820 OBD_MD_FLUID | OBD_MD_FLGID;
822 oinfo.oi_oa->o_valid |= OBD_MD_FLCOOKIE;
823 oti.oti_logcookies = logcookies;
826 oinfo.oi_oa->o_fid = id;
827 oinfo.oi_oa->o_generation = gen;
828 oinfo.oi_oa->o_valid |= OBD_MD_FLFID | OBD_MD_FLGENER;
831 /* do async setattr from mds to ost not waiting for responses. */
832 rc = obd_setattr_async(mds->mds_osc_exp, &oinfo, &oti, NULL);
834 CDEBUG(D_INODE, "mds to ost setattr objid 0x"LPX64
835 " on ost error %d\n", oinfo.oi_md->lsm_object_id, rc);
838 obd_free_memmd(mds->mds_osc_exp, &oinfo.oi_md);
839 OBDO_FREE(oinfo.oi_oa);
843 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
844 struct lov_mds_md *lmm, int lmm_size,
845 struct llog_cookie *logcookies)
847 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
848 struct obd_device *obd = mdd2obd_dev(mdd);
849 struct lu_attr *tmp_la = &mdd_env_info(env)->mti_la;
850 const struct lu_fid *fid = mdd_object_fid(obj);
855 mdd_read_lock(env, obj, MOR_TGT_CHILD);
856 rc = mdo_attr_get(env, obj, tmp_la, mdd_object_capa(env, obj));
857 mdd_read_unlock(env, obj);
861 oc = mdo_capa_get(env, obj, NULL, CAPA_OPC_MDS_DEFAULT);
865 rc = mdd_osc_setattr_async(obd, tmp_la->la_uid, tmp_la->la_gid, lmm,
866 lmm_size, logcookies, fid_seq(fid),