Whamcloud - gitweb
LU-1303 mds: integration lod/osp into the stack
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index ba8d76a..1fb0ffd 100644 (file)
@@ -912,7 +912,7 @@ int mdd_declare_finish_unlink(const struct lu_env *env,
         if (rc)
                 return rc;
 
-        return mdd_declare_object_kill(env, obj, ma, handle);
+       return mdo_declare_destroy(env, obj, handle);
 }
 
 /* caller should take a lock before calling */
@@ -921,7 +921,6 @@ int mdd_finish_unlink(const struct lu_env *env,
                       struct thandle *th)
 {
        int rc = 0;
-        int reset = 1;
         int is_dir = S_ISDIR(ma->ma_attr.la_mode);
         ENTRY;
 
@@ -945,13 +944,9 @@ int mdd_finish_unlink(const struct lu_env *env,
                                         PFID(mdd_object_fid(obj)),
                                         obj->mod_count);
                 } else {
-                        rc = mdd_object_kill(env, obj, ma, th);
-                        if (rc == 0)
-                                reset = 0;
+                       rc = mdo_destroy(env, obj, th);
                 }
         }
-        if (reset)
-                ma->ma_valid &= ~(MA_LOV | MA_COOKIE);
 
         RETURN(rc);
 }
@@ -1140,15 +1135,6 @@ cleanup:
 
 stop:
         mdd_trans_stop(env, mdd, rc, handle);
-#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 3, 55, 0)
-       if (rc == 0 && ma->ma_valid & MA_COOKIE && ma->ma_valid & MA_LOV &&
-           ma->ma_valid & MA_FLAGS && ma->ma_attr_flags & MDS_UNLINK_DESTROY)
-               /* Since echo client is incapable of destorying ost object,
-                * it will destory the object here. */
-               rc = mdd_lovobj_unlink(env, mdd, mdd_cobj, la, ma, 1);
-#else
-#warning "please remove this after 2.4 (LOD/OSP)."
-#endif
 
         return rc;
 }
@@ -1169,27 +1155,6 @@ static int mdd_cd_sanity_check(const struct lu_env *env,
 
 }
 
-static int mdd_declare_create_data(const struct lu_env *env,
-                                   struct mdd_device *mdd,
-                                   struct mdd_object *obj,
-                                   int lmm_size,
-                                   struct thandle *handle)
-{
-        struct lu_buf *buf = &mdd_env_info(env)->mti_buf;
-        int            rc;
-
-        buf->lb_buf = NULL;
-        buf->lb_len = lmm_size;
-        rc = mdo_declare_xattr_set(env, obj, buf, XATTR_NAME_LOV,
-                                   0, handle);
-        if (rc)
-                return rc;
-
-        rc = mdd_declare_lov_objid_update(env, mdd, handle);
-
-        return rc;
-}
-
 static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
                            struct md_object *cobj, const struct md_op_spec *spec,
                            struct md_attr *ma)
@@ -1197,25 +1162,30 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
         struct mdd_device *mdd = mdo2mdd(cobj);
         struct mdd_object *mdd_pobj = md2mdd_obj(pobj);
         struct mdd_object *son = md2mdd_obj(cobj);
-        struct lov_mds_md *lmm = NULL;
-        int                lmm_size = 0;
         struct thandle    *handle;
-       struct lu_attr    *attr = &mdd_env_info(env)->mti_la_for_fix;
+       const struct lu_buf *buf;
+       struct lu_attr    *attr = &mdd_env_info(env)->mti_cattr;
         int                rc;
         ENTRY;
 
+       /* do not let users to create stripes via .lustre/
+        * mdd_obf_setup() sets IMMUTE_OBJ on this directory */
+       if (pobj && mdd_pobj->mod_flags & IMMUTE_OBJ)
+               RETURN(-ENOENT);
+
         rc = mdd_cd_sanity_check(env, son);
         if (rc)
                 RETURN(rc);
 
         if (!md_should_create(spec->sp_cr_flags))
                 RETURN(0);
-        lmm_size = ma->ma_lmm_size;
-
-        rc = mdd_lov_create(env, mdd, mdd_pobj, son, &lmm, &lmm_size, spec, ma);
-        if (rc)
-                RETURN(rc);
 
+       /*
+        * there are following use cases for this function:
+        * 1) late striping - file was created with MDS_OPEN_DELAY_CREATE
+        *    striping can be specified or not
+        * 2) CMD?
+        */
        rc = mdd_la_get(env, son, attr, mdd_object_capa(env, son));
        if (rc)
                RETURN(rc);
@@ -1227,44 +1197,46 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
         if (IS_ERR(handle))
                 GOTO(out_free, rc = PTR_ERR(handle));
 
-        rc = mdd_declare_create_data(env, mdd, son, lmm_size, handle);
-        if (rc)
-                GOTO(stop, rc);
-
-        rc = mdd_trans_start(env, mdd, handle);
-        if (rc)
-                GOTO(stop, rc);
-
         /*
          * XXX: Setting the lov ea is not locked but setting the attr is locked?
          * Should this be fixed?
          */
+       CDEBUG(D_OTHER, "ea %p/%u, cr_flags %Lo, no_create %u\n",
+              spec->u.sp_ea.eadata, spec->u.sp_ea.eadatalen,
+              spec->sp_cr_flags, spec->no_create);
+
+       if (spec->no_create) {
+               /* replay case */
+               buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
+                                       spec->u.sp_ea.eadatalen);
+       } else  if (!(spec->sp_cr_flags & MDS_OPEN_HAS_OBJS)) {
+               if (spec->sp_cr_flags & MDS_OPEN_HAS_EA) {
+                       /* lfs setstripe */
+                       buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
+                                               spec->u.sp_ea.eadatalen);
+               } else {
+                       buf = &LU_BUF_NULL;
+               }
+       } else {
+               /* MDS_OPEN_HAS_OBJS is not used anymore ? */
+               LBUG();
+       }
 
-        /* Replay creates has objects already */
-#if 0
-        if (spec->no_create) {
-                CDEBUG(D_INFO, "we already have lov ea\n");
-                rc = mdd_lov_set_md(env, mdd_pobj, son,
-                                    (struct lov_mds_md *)spec->u.sp_ea.eadata,
-                                    spec->u.sp_ea.eadatalen, handle, 0);
-        } else
-#endif
-                /* No need mdd_lsm_sanity_check here */
-                rc = mdd_lov_set_md(env, mdd_pobj, son, lmm,
-                                    lmm_size, handle, 0);
+       rc = dt_declare_xattr_set(env, mdd_object_child(son), buf,
+                                 XATTR_NAME_LOV, 0, handle);
+       if (rc)
+               GOTO(stop, rc);
 
-        /* update lov_objid data, must be before transaction stop! */
-        if (rc == 0)
-                mdd_lov_objid_update(mdd, lmm);
+       rc = mdd_trans_start(env, mdd, handle);
+       if (rc)
+               GOTO(stop, rc);
 
+       rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
+                         0, handle, mdd_object_capa(env, son));
 stop:
-        mdd_trans_stop(env, mdd, rc, handle);
+       mdd_trans_stop(env, mdd, rc, handle);
 out_free:
-        /* Finish mdd_lov_create() stuff. */
-        /* if no_create == 0 (not replay), we free lmm allocated by
-         * mdd_lov_create() */
-        mdd_lov_create_finish(env, mdd, lmm, lmm_size, spec);
-        RETURN(rc);
+       RETURN(rc);
 }
 
 /* Get fid from name and parent */
@@ -1459,13 +1431,12 @@ static int mdd_create_sanity_check(const struct lu_env *env,
 static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
                              struct mdd_object *p, struct mdd_object *c,
                              const struct lu_name *name,
-                             struct lu_attr *attr, int lmm_size,
+                             struct lu_attr *attr,
                              int got_def_acl,
                              struct thandle *handle,
                              const struct md_op_spec *spec)
 {
        struct mdd_thread_info *info = mdd_env_info(env);
-        struct lu_buf *buf = &mdd_env_info(env)->mti_buf;
         int            rc = 0;
 
        rc = mdd_declare_object_create_internal(env, p, c, attr, handle, spec);
@@ -1512,10 +1483,17 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
         if (rc)
                 GOTO(out, rc);
 
-        rc = mdo_declare_xattr_set(env, c, buf, XATTR_NAME_LOV,
-                                   0, handle);
-        if (rc)
-                GOTO(out, rc);
+       /* replay case, create LOV EA from client data */
+       if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA)) {
+               const struct lu_buf *buf;
+
+               buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
+                                       spec->u.sp_ea.eadatalen);
+               rc = mdo_declare_xattr_set(env, c, buf, XATTR_NAME_LOV,
+                                          0, handle);
+               if (rc)
+                       GOTO(out, rc);
+       }
 
        if (S_ISLNK(attr->la_mode)) {
                 rc = dt_declare_record_write(env, mdd_object_child(c),
@@ -1533,8 +1511,6 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
         if (rc)
                 return rc;
 
-        rc = mdd_declare_lov_objid_update(env, mdd, handle);
-
 out:
         return rc;
 }
@@ -1553,12 +1529,11 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
         struct mdd_object      *son = md2mdd_obj(child);
         struct mdd_device      *mdd = mdo2mdd(pobj);
         struct lu_attr         *attr = &ma->ma_attr;
-        struct lov_mds_md      *lmm = NULL;
         struct thandle         *handle;
        struct lu_attr         *pattr = &info->mti_pattr;
         struct dynlock_handle  *dlh;
         const char             *name = lname->ln_name;
-        int rc, created = 0, initialized = 0, inserted = 0, lmm_size = 0;
+       int rc, created = 0, initialized = 0, inserted = 0;
         int got_def_acl = 0;
         ENTRY;
 
@@ -1608,19 +1583,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
                 RETURN(rc);
 
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_DQACQ_NET))
-                GOTO(out_pending, rc = -EINPROGRESS);
-
-        /*
-         * No RPC inside the transaction, so OST objects should be created at
-         * first.
-         */
-        if (S_ISREG(attr->la_mode)) {
-                lmm_size = ma->ma_lmm_size;
-                rc = mdd_lov_create(env, mdd, mdd_pobj, son, &lmm, &lmm_size,
-                                    spec, ma);
-                if (rc)
-                        GOTO(out_pending, rc);
-        }
+               GOTO(out_free, rc = -EINPROGRESS);
 
         if (!S_ISLNK(attr->la_mode)) {
                struct lu_buf *acl_buf;
@@ -1644,7 +1607,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
                 GOTO(out_free, rc = PTR_ERR(handle));
 
        rc = mdd_declare_create(env, mdd, mdd_pobj, son, lname, attr,
-                               got_def_acl, lmm_size, handle, spec);
+                               got_def_acl, handle, spec);
         if (rc)
                 GOTO(out_stop, rc);
 
@@ -1680,6 +1643,22 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
 
         rc = mdd_object_initialize(env, mdo2fid(mdd_pobj), lname,
                                   son, attr, handle, spec);
+
+       /*
+        * in case of replay we just set LOVEA provided by the client
+        * XXX: I think it would be interesting to try "old" way where
+        *      MDT calls this xattr_set(LOV) in a different transaction.
+        *      probably this way we code can be made better.
+        */
+       if (rc == 0 &&
+                       (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA))) {
+               const struct lu_buf *buf;
+
+               buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
+                               spec->u.sp_ea.eadatalen);
+               rc = mdo_xattr_set(env, son, buf, XATTR_NAME_LOV, 0, handle,
+                               BYPASS_CAPA);
+       }
         mdd_write_unlock(env, son);
         if (rc)
                 /*
@@ -1698,13 +1677,6 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
 
         inserted = 1;
 
-        /* No need mdd_lsm_sanity_check here */
-        rc = mdd_lov_set_md(env, mdd_pobj, son, lmm, lmm_size, handle, 0);
-        if (rc) {
-                CERROR("error on stripe info copy %d \n", rc);
-                GOTO(cleanup, rc);
-        }
-
         if (S_ISLNK(attr->la_mode)) {
                 struct md_ucred  *uc = md_ucred(env);
                 struct dt_object *dt = mdd_object_child(son);
@@ -1765,10 +1737,6 @@ cleanup:
                mdd_write_unlock(env, son);
         }
 
-        /* update lov_objid data, must be before transaction stop! */
-        if (rc == 0)
-                mdd_lov_objid_update(mdd, lmm);
-
         mdd_pdo_write_unlock(env, mdd_pobj, dlh);
 out_trans:
         if (rc == 0)
@@ -1780,9 +1748,6 @@ out_trans:
 out_stop:
         mdd_trans_stop(env, mdd, rc, handle);
 out_free:
-        /* finish lov_create stuff, free all temporary data */
-        mdd_lov_create_finish(env, mdd, lmm, lmm_size, spec);
-out_pending:
         /* The child object shouldn't be cached anymore */
         if (rc)
                 cfs_set_bit(LU_OBJECT_HEARD_BANSHEE,