Whamcloud - gitweb
b=17740
[fs/lustre-release.git] / lustre / mdd / mdd_lov.c
index 687137a..1659902 100644 (file)
@@ -1,31 +1,46 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  lustre/mdd/mdd_lov.c
- *  Lustre Metadata Server (mds) handling of striped file data
+ * GPL HEADER START
  *
- *  Copyright (C) 2001-2006 Cluster File Systems, Inc.
- *   Author: Peter Braam <braam@clusterfs.com>
- *           wangdi <wangdi@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
  */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/mdd/mdd_lov.c
+ *
+ * Lustre Metadata Server (mds) handling of striped file data
+ *
+ * Author: Peter Braam <braam@clusterfs.com>
+ * Author: wangdi <wangdi@clusterfs.com>
+ */
+
 #ifndef EXPORT_SYMTAB
 # define EXPORT_SYMTAB
 #endif
@@ -82,7 +97,7 @@ int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
         struct obd_device      *obd;
         ENTRY;
 
-        mds_id = mdd2lu_dev(mdd)->ld_site->ls_node_id;
+        mds_id = lu_site2md(mdd2lu_dev(mdd)->ld_site)->ms_node_id;
         name_size = strlen(MDD_OBD_NAME) + 35;
         uuid_size = strlen(MDD_OBD_UUID) + 35;
 
@@ -130,12 +145,11 @@ int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
 
         /*
          * Add here for obd notify mechanism, when adding a new ost, the mds
-         * will notify this mdd.
+         * will notify this mdd. The mds will be used for quota also.
          */
         obd->obd_upcall.onu_upcall = mdd_notify;
         obd->obd_upcall.onu_owner = mdd;
         mdd->mdd_obd_dev = obd;
-
         EXIT;
 class_detach:
         if (rc)
@@ -170,7 +184,7 @@ int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
         if (rc)
                 GOTO(lcfg_cleanup, rc);
         mdd->mdd_obd_dev = NULL;
-        
+
         EXIT;
 lcfg_cleanup:
         return rc;
@@ -205,7 +219,7 @@ int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
                       void *md, int *md_size, const char *name)
 {
         int rc = 0;
-        mdd_read_lock(env, obj);
+        mdd_read_lock(env, obj, MOR_TGT_CHILD);
         rc = mdd_get_md(env, obj, md, md_size, name);
         mdd_read_unlock(env, obj);
         return rc;
@@ -250,12 +264,11 @@ static int mdd_lov_set_dir_md(const struct lu_env *env,
         LASSERT(S_ISDIR(mdd_object_type(obj)));
         lum = (struct lov_user_md*)buf->lb_buf;
 
-        /* if { size, offset, count } = { 0, -1, 0 } (i.e. all default
+        /* if { size, offset, count } = { 0, -1, 0 } and no pool (i.e. all default
          * values specified) then delete default striping from dir. */
-        if ((lum->lmm_stripe_size == 0 && lum->lmm_stripe_count == 0 &&
-             lum->lmm_stripe_offset == (typeof(lum->lmm_stripe_offset))(-1)) ||
-             /* lmm_stripe_size == -1 is deprecated in 1.4.6 */
-             lum->lmm_stripe_size == (typeof(lum->lmm_stripe_size))(-1)){
+        if (lum->lmm_stripe_size == 0 && lum->lmm_stripe_count == 0 &&
+            lum->lmm_stripe_offset == (typeof(lum->lmm_stripe_offset))(-1) &&
+            lum->lmm_magic != LOV_USER_MAGIC_V3) {
                 rc = mdd_xattr_set_txn(env, obj, &LU_BUF_NULL,
                                        MDS_LOV_MD_NAME, 0, handle);
                 if (rc == -ENODATA)
@@ -279,9 +292,10 @@ int mdd_lsm_sanity_check(const struct lu_env *env,  struct mdd_object *obj)
         if (rc)
                 RETURN(rc);
 
-        if ((uc->mu_fsuid != tmp_la->la_uid) && !mdd_capable(uc, CAP_FOWNER))
+        if ((uc->mu_fsuid != tmp_la->la_uid) &&
+            !mdd_capable(uc, CFS_CAP_FOWNER))
                 rc = mdd_permission_internal_locked(env, obj, tmp_la,
-                                                    MAY_WRITE);
+                                                    MAY_WRITE, MOR_TGT_CHILD);
 
         RETURN(rc);
 }
@@ -308,7 +322,7 @@ int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
                 if (lmmp == NULL && lmm_size == 0) {
                         struct mdd_device *mdd = mdd_obj2mdd_dev(child);
                         struct lov_mds_md *lmm = mdd_max_lmm_get(env, mdd);
-                        int size = sizeof(*lmm);
+                        int size = sizeof(struct lov_mds_md_v3);
 
                         /* Get parent dir stripe and set */
                         if (pobj != NULL)
@@ -342,56 +356,50 @@ static obd_id mdd_lov_create_id(const struct lu_fid *fid)
         return fid_flatten(fid);
 }
 
-static int mdd_lov_objid_alloc(const struct lu_env *env,
-                               struct mdd_device *mdd)
-{
-        struct mdd_thread_info *info = mdd_env_info(env);
-        struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds;
-
-        OBD_ALLOC(info->mti_oti.oti_objid,
-                  mds->mds_lov_desc.ld_tgt_count * sizeof(obd_id));
-        return (info->mti_oti.oti_objid == NULL ? -ENOMEM : 0);
-}
-
-void mdd_lov_objid_update(const struct lu_env *env, struct mdd_device *mdd)
+static void mdd_lov_update_objids(struct obd_device *obd, struct lov_mds_md *lmm)
 {
-        struct mdd_thread_info *info = mdd_env_info(env);
-        if (info->mti_oti.oti_objid != NULL)
-                mds_lov_update_objids(mdd->mdd_obd_dev,
-                                      info->mti_oti.oti_objid);
-}
+        struct mds_obd *mds = &obd->u.mds;
+        int j;
+        struct lov_ost_data_v1 *lmm_objects;
+        ENTRY;
 
-static void mdd_lov_objid_from_lmm(const struct lu_env *env,
-                                   struct mdd_device *mdd,
-                                   struct lov_mds_md *lmm)
-{
-        struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds;
-        struct mdd_thread_info *info = mdd_env_info(env);
-        mds_objids_from_lmm(info->mti_oti.oti_objid, lmm, &mds->mds_lov_desc);
+        /* if we create file without objects - lmm is NULL */
+        if (lmm == NULL)
+                return;
+
+        if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V3)
+                lmm_objects = ((struct lov_mds_md_v3 *)lmm)->lmm_objects;
+        else
+                lmm_objects = lmm->lmm_objects;
+
+        for (j = 0; j < le32_to_cpu(lmm->lmm_stripe_count); j++) {
+                int i = le32_to_cpu(lmm_objects[j].l_ost_idx);
+                obd_id id = le64_to_cpu(lmm_objects[j].l_object_id);
+                int page = i / OBJID_PER_PAGE();
+                int idx = i % OBJID_PER_PAGE();
+                obd_id *data = mds->mds_lov_page_array[page];
+
+                CDEBUG(D_INODE,"update last object for ost %d - new %llu"
+                               " old %llu\n", i, id, data[idx]);
+                if (id > data[idx]) {
+                        data[idx] = id;
+                        cfs_bitmap_set(mds->mds_lov_page_dirty, page);
+                }
+        }
+        EXIT;
 }
 
-static void mdd_lov_objid_free(const struct lu_env *env,
-                               struct mdd_device *mdd)
+void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm)
 {
-        struct mdd_thread_info *info = mdd_env_info(env);
-        struct mds_obd *mds = &mdd->mdd_obd_dev->u.mds;
-
-        OBD_FREE(info->mti_oti.oti_objid,
-                 mds->mds_lov_desc.ld_tgt_count * sizeof(obd_id));
-        info->mti_oti.oti_objid = NULL;
+        mdd_lov_update_objids(mdd->mdd_obd_dev, lmm);
 }
 
 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
                            struct lov_mds_md *lmm, int lmm_size,
                            const struct md_op_spec *spec)
 {
-        struct mdd_thread_info *info = mdd_env_info(env);
-
         if (lmm && !spec->u.sp_ea.no_lov_create)
                 OBD_FREE(lmm, lmm_size);
-
-        if (info->mti_oti.oti_objid != NULL)
-                mdd_lov_objid_free(env, mdd);
 }
 
 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
@@ -401,6 +409,7 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
 {
         struct obd_device     *obd = mdd2obd_dev(mdd);
         struct obd_export     *lov_exp = obd->u.mds.mds_osc_exp;
+        struct lu_site        *site = mdd2lu_dev(mdd)->ld_site;
         struct obdo           *oa;
         struct lov_stripe_md  *lsm = NULL;
         const void            *eadata = spec->u.sp_ea.eadata;
@@ -413,19 +422,15 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
                 RETURN(0);
 
         oti_init(oti, NULL);
-        rc = mdd_lov_objid_alloc(env, mdd);
-        if (rc != 0)
-                RETURN(rc);
 
         /* replay case, has objects already, only get lov from eadata */
         if (spec->u.sp_ea.no_lov_create != 0) {
                 *lmm = (struct lov_mds_md *)spec->u.sp_ea.eadata;
                 *lmm_size = spec->u.sp_ea.eadatalen;
-                mdd_lov_objid_from_lmm(env, mdd, *lmm);
                 RETURN(0);
         }
 
-        if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_ALLOC_OBDO))
+        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOC_OBDO))
                 GOTO(out_ids, rc = -ENOMEM);
 
         LASSERT(lov_exp != NULL);
@@ -433,7 +438,7 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
 
         oa->o_uid = 0; /* must have 0 uid / gid on OST */
         oa->o_gid = 0;
-        oa->o_gr = FILTER_GROUP_MDS0 + mdd2lu_dev(mdd)->ld_site->ls_node_id;
+        oa->o_gr = mdt_to_obd_objgrp(lu_site2md(site)->ms_node_id);
         oa->o_mode = S_IFREG | 0600;
         oa->o_id = mdd_lov_create_id(mdd_object_fid(child));
         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLFLAGS |
@@ -479,7 +484,7 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
                         }
                         GOTO(out_oti, rc);
                 }
-                LASSERT(lsm->lsm_object_gr >= FILTER_GROUP_MDS0);
+                LASSERT_MDS_GROUP(lsm->lsm_object_gr);
         } else {
                 LASSERT(eadata != NULL);
                 rc = obd_iocontrol(OBD_IOC_LOV_SETEA, lov_exp, 0, &lsm,
@@ -500,8 +505,6 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
 
                 memset(oinfo, 0, sizeof(*oinfo));
 
-                oa->o_size = la->la_size;
-
                 /* When setting attr to ost, FLBKSZ is not needed. */
                 oa->o_valid &= ~OBD_MD_FLBLKSZ;
                 obdo_from_la(oa, la, OBD_MD_FLTYPE | OBD_MD_FLATIME |
@@ -517,13 +520,11 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
                 oa->o_valid |= OBD_MD_FLFID | OBD_MD_FLGENER;
                 oinfo->oi_oa = oa;
                 oinfo->oi_md = lsm;
-                oinfo->oi_capa = mdo_capa_get(env, child, NULL,
-                                              CAPA_OPC_MDS_DEFAULT);
-                if (IS_ERR(oinfo->oi_capa))
-                        oinfo->oi_capa = NULL;
+                oinfo->oi_capa = NULL;
+                oinfo->oi_policy.l_extent.start = la->la_size;
+                oinfo->oi_policy.l_extent.end = OBD_OBJECT_EOF;
 
-                rc = obd_setattr(lov_exp, oinfo, oti);
-                capa_put(oinfo->oi_capa);
+                rc = obd_punch_rqset(lov_exp, oinfo, oti);
                 if (rc) {
                         CERROR("Error setting attrs for "DFID": rc %d\n",
                                PFID(mdo2fid(child)), rc);
@@ -553,13 +554,10 @@ out_oti:
 out_ids:
         if (lsm)
                 obd_free_memmd(lov_exp, &lsm);
-        if (rc != 0)
-                mdd_lov_objid_free(env, mdd);
 
         return rc;
 }
 
-
 /*
  * used when destroying orphans and from mds_reint_unlink() when MDS wants to
  * destroy objects on OSS.
@@ -576,6 +574,7 @@ int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
         struct lov_stripe_md  *lsm = NULL;
         struct obd_trans_info *oti = &mdd_env_info(env)->mti_oti;
         struct obdo           *oa = &mdd_env_info(env)->mti_oa;
+        struct lu_site        *site = mdd2lu_dev(mdd)->ld_site;
         int rc;
         ENTRY;
 
@@ -592,7 +591,7 @@ int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
         }
 
         oa->o_id = lsm->lsm_object_id;
-        oa->o_gr = FILTER_GROUP_MDS0 + mdd2lu_dev(mdd)->ld_site->ls_node_id;
+        oa->o_gr = mdt_to_obd_objgrp(lu_site2md(site)->ms_node_id);
         oa->o_mode = la->la_mode & S_IFMT;
         oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
 
@@ -605,16 +604,16 @@ int mdd_lovobj_unlink(const struct lu_env *env, struct mdd_device *mdd,
         CDEBUG(D_INFO, "destroying OSS object %d/%d\n",
                         (int)oa->o_id, (int)oa->o_gr);
 
-        rc = obd_destroy(lov_exp, oa, lsm, oti, NULL);
+        rc = obd_destroy(lov_exp, oa, lsm, oti, NULL, NULL);
 
         obd_free_memmd(lov_exp, &lsm);
         RETURN(rc);
 }
 
-
 /*
  * called with obj not locked. 
  */
+
 int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
                     struct mdd_object *obj, struct lu_attr *la)
 {
@@ -636,12 +635,18 @@ int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
                 RETURN(rc = -ENOMEM);
 
         /* get lov ea */
+
         rc = mdd_get_md_locked(env, obj, ma->ma_lmm, &ma->ma_lmm_size,
                                MDS_LOV_MD_NAME);
-        if (rc) {
-                CWARN("Get lov ea failed for "DFID"\n", PFID(mdo2fid(obj)));
+
+        if (rc <= 0) {
+                CWARN("Get lov ea failed for "DFID" rc = %d\n",
+                         PFID(mdo2fid(obj)), rc);
+                if (rc == 0)
+                        rc = -ENOENT;
                 RETURN(rc);
         }
+
         ma->ma_valid = MA_LOV;
         
         rc = mdd_unlink_log(env, mdd, obj, ma);
@@ -650,13 +655,52 @@ int mdd_lov_destroy(const struct lu_env *env, struct mdd_device *mdd,
                        PFID(mdo2fid(obj)), rc);
                 RETURN(rc);
         }
-        if (ma->ma_valid | MA_COOKIE)
-                rc = mdd_lovobj_unlink(env, mdd, obj, la, 
+
+        if (ma->ma_valid & MA_COOKIE)
+                rc = mdd_lovobj_unlink(env, mdd, obj, la,
                                        ma->ma_lmm, ma->ma_lmm_size,
                                        ma->ma_cookie, 1);
         RETURN(rc);
 }
 
+int mdd_log_op_unlink(struct obd_device *obd,
+                      struct lov_mds_md *lmm, int lmm_size,
+                      struct llog_cookie *logcookies, int cookies_size)
+{
+        struct mds_obd *mds = &obd->u.mds;
+        struct lov_stripe_md *lsm = NULL;
+        struct llog_unlink_rec *lur;
+        struct llog_ctxt *ctxt;
+        int rc;
+        ENTRY;
+
+        if (IS_ERR(mds->mds_osc_obd))
+                RETURN(PTR_ERR(mds->mds_osc_obd));
+
+        rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
+        if (rc < 0)
+                RETURN(rc);
+        rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
+        if (rc)
+                GOTO(out, rc);
+        /* first prepare unlink log record */
+        OBD_ALLOC(lur, sizeof(*lur));
+        if (!lur)
+                GOTO(out, rc = -ENOMEM);
+        lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
+        lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
+
+        ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
+        rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookies,
+                      cookies_size / sizeof(struct llog_cookie));
+        llog_ctxt_put(ctxt);
+
+        OBD_FREE(lur, sizeof(*lur));
+        GOTO(out, rc);
+out:
+        obd_free_memmd(mds->mds_osc_exp, &lsm);
+        return rc;
+}
 
 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
                    struct mdd_object *mdd_cobj, struct md_attr *ma)
@@ -666,13 +710,58 @@ int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
         LASSERT(ma->ma_valid & MA_LOV);
 
         if ((ma->ma_cookie_size > 0) &&
-            (mds_log_op_unlink(obd, ma->ma_lmm, ma->ma_lmm_size,
+            (mdd_log_op_unlink(obd, ma->ma_lmm, ma->ma_lmm_size,
                                ma->ma_cookie, ma->ma_cookie_size) > 0)) {
                 ma->ma_valid |= MA_COOKIE;
         }
         return 0;
 }
 
+int mdd_log_op_setattr(struct obd_device *obd, __u32 uid, __u32 gid,
+                      struct lov_mds_md *lmm, int lmm_size,
+                      struct llog_cookie *logcookies, int cookies_size)
+{
+        struct mds_obd *mds = &obd->u.mds;
+        struct lov_stripe_md *lsm = NULL;
+        struct llog_setattr64_rec *lsr;
+        struct llog_ctxt *ctxt;
+        int rc;
+        ENTRY;
+
+        if (IS_ERR(mds->mds_osc_obd))
+                RETURN(PTR_ERR(mds->mds_osc_obd));
+
+        rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
+        if (rc < 0)
+                RETURN(rc);
+
+        rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
+        if (rc)
+                GOTO(out, rc);
+
+        OBD_ALLOC(lsr, sizeof(*lsr));
+        if (!lsr)
+                GOTO(out, rc = -ENOMEM);
+
+        /* prepare setattr log record */
+        lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
+        lsr->lsr_hdr.lrh_type = MDS_SETATTR64_REC;
+        lsr->lsr_uid = uid;
+        lsr->lsr_gid = gid;
+
+        /* write setattr log */
+        ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
+        rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
+                      cookies_size / sizeof(struct llog_cookie));
+
+        llog_ctxt_put(ctxt);
+
+        OBD_FREE(lsr, sizeof(*lsr));
+ out:
+        obd_free_memmd(mds->mds_osc_exp, &lsm);
+        RETURN(rc);
+}
+
 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
                     const struct md_attr *ma,
                     struct lov_mds_md *lmm, int lmm_size,
@@ -683,44 +772,97 @@ int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
         /* journal chown/chgrp in llog, just like unlink */
         if (lmm_size > 0) {
                 CDEBUG(D_INFO, "setattr llog for uid/gid=%lu/%lu\n",
-                        (unsigned long)ma->ma_attr.la_uid, 
+                        (unsigned long)ma->ma_attr.la_uid,
                         (unsigned long)ma->ma_attr.la_gid);
-                return mds_log_op_setattr(obd, ma->ma_attr.la_uid, 
-                                          ma->ma_attr.la_gid, lmm, 
+                return mdd_log_op_setattr(obd, ma->ma_attr.la_uid,
+                                          ma->ma_attr.la_gid, lmm,
                                           lmm_size, logcookies,
                                           cookies_size);
         } else
                 return 0;
 }
 
+static int mdd_osc_setattr_async(struct obd_device *obd, __u32 uid, __u32 gid,
+                          struct lov_mds_md *lmm, int lmm_size,
+                          struct llog_cookie *logcookies, __u64 id, __u32 gen,
+                          struct obd_capa *oc)
+{
+        struct mds_obd *mds = &obd->u.mds;
+        struct obd_trans_info oti = { 0 };
+        struct obd_info oinfo = { { { 0 } } };
+        int rc;
+        ENTRY;
+
+        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_OST_SETATTR))
+                RETURN(0);
+
+        /* first get memory EA */
+        OBDO_ALLOC(oinfo.oi_oa);
+        if (!oinfo.oi_oa)
+                RETURN(-ENOMEM);
+
+        LASSERT(lmm);
+
+        rc = obd_unpackmd(mds->mds_osc_exp, &oinfo.oi_md, lmm, lmm_size);
+        if (rc < 0) {
+                CERROR("Error unpack md %p for inode "LPU64"\n", lmm, id);
+                GOTO(out, rc);
+        }
+
+        rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, oinfo.oi_md);
+        if (rc) {
+                CERROR("Error revalidate lsm %p \n", oinfo.oi_md);
+                GOTO(out, rc);
+        }
+
+        /* then fill oa */
+        oinfo.oi_oa->o_uid = uid;
+        oinfo.oi_oa->o_gid = gid;
+        oinfo.oi_oa->o_id = oinfo.oi_md->lsm_object_id;
+        oinfo.oi_oa->o_gr = oinfo.oi_md->lsm_object_gr;
+        oinfo.oi_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP |
+                                OBD_MD_FLUID | OBD_MD_FLGID;
+        if (logcookies) {
+                oinfo.oi_oa->o_valid |= OBD_MD_FLCOOKIE;
+                oti.oti_logcookies = logcookies;
+        }
+
+        oinfo.oi_oa->o_fid = id;
+        oinfo.oi_oa->o_generation = gen;
+        oinfo.oi_oa->o_valid |= OBD_MD_FLFID | OBD_MD_FLGENER;
+        oinfo.oi_capa = oc;
+
+        /* do async setattr from mds to ost not waiting for responses. */
+        rc = obd_setattr_async(mds->mds_osc_exp, &oinfo, &oti, NULL);
+        if (rc)
+                CDEBUG(D_INODE, "mds to ost setattr objid 0x"LPX64
+                       " on ost error %d\n", oinfo.oi_md->lsm_object_id, rc);
+out:
+        if (oinfo.oi_md)
+                obd_free_memmd(mds->mds_osc_exp, &oinfo.oi_md);
+        OBDO_FREE(oinfo.oi_oa);
+        RETURN(rc);
+}
+
 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
-                          struct lov_mds_md *lmm, int lmm_size, 
+                          struct lov_mds_md *lmm, int lmm_size,
                           struct llog_cookie *logcookies)
 {
         struct mdd_device   *mdd = mdo2mdd(&obj->mod_obj);
         struct obd_device   *obd = mdd2obd_dev(mdd);
         struct lu_attr      *tmp_la = &mdd_env_info(env)->mti_la;
         const struct lu_fid *fid = mdd_object_fid(obj);
-        struct obd_capa     *oc;
         int rc = 0;
         ENTRY;
 
-        mdd_read_lock(env, obj);
+        mdd_read_lock(env, obj, MOR_TGT_CHILD);
         rc = mdo_attr_get(env, obj, tmp_la, mdd_object_capa(env, obj));
         mdd_read_unlock(env, obj);
         if (rc)
                 RETURN(rc);
 
-        oc = mdo_capa_get(env, obj, NULL, CAPA_OPC_MDS_DEFAULT);
-        if (IS_ERR(oc))
-                oc = NULL;
-
-        rc = mds_osc_setattr_async(obd, tmp_la->la_uid, tmp_la->la_gid, lmm,
+        rc = mdd_osc_setattr_async(obd, tmp_la->la_uid, tmp_la->la_gid, lmm,
                                    lmm_size, logcookies, fid_seq(fid),
-                                   fid_oid(fid), oc);
-
-        capa_put(oc);
-
+                                   fid_oid(fid), NULL);
         RETURN(rc);
 }
-