Whamcloud - gitweb
LU-1518 mdd: Fixup mdd_{obf,dot_lustre}_obj_ops.
authorJohn L. Hammond <jhammond@tacc.utexas.edu>
Wed, 13 Jun 2012 16:20:12 +0000 (11:20 -0500)
committerOleg Drokin <green@whamcloud.com>
Fri, 31 Aug 2012 20:44:25 +0000 (16:44 -0400)
Define several missing md_object ops for .lustre/fid.  Unify
attribute handling for .lustre with that of normal md_objects.

Fixed several defects:
- use parent ops instead of child ops in mdo_create();
- skip version get for obf in mdt_obj_version_get();
- disable non-normal fid lookup in obf_lookup();

Signed-off-by: John L. Hammond <jhammond@tacc.utexas.edu>
Signed-off-by: Bob Glossman <bogl@whamcloud.com>
Signed-off-by: Niu Yawei <niu@whamcloud.com>
Change-Id: I89c5b37c822680b0ad1e23372e3e2be464f6a3d8
Reviewed-on: http://review.whamcloud.com/3726
Tested-by: Hudson
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/md_object.h
lustre/mdd/mdd_device.c
lustre/mdd/mdd_internal.h
lustre/mdd/mdd_object.c
lustre/mdt/mdt_reint.c
lustre/tests/sanity.sh

index 42bf7b7..973c050 100644 (file)
@@ -805,8 +805,8 @@ static inline int mdo_create(const struct lu_env *env,
                              struct md_op_spec *spc,
                              struct md_attr *at)
 {
                              struct md_op_spec *spc,
                              struct md_attr *at)
 {
-        LASSERT(c->mo_dir_ops->mdo_create);
-        return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
+       LASSERT(p->mo_dir_ops->mdo_create);
+       return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
 }
 
 static inline int mdo_create_data(const struct lu_env *env,
 }
 
 static inline int mdo_create_data(const struct lu_env *env,
index 47eab65..45ed842 100644 (file)
@@ -487,21 +487,6 @@ static int dot_lustre_mdd_permission(const struct lu_env *env,
                 return 0;
 }
 
                 return 0;
 }
 
-static int dot_lustre_mdd_attr_get(const struct lu_env *env,
-                                   struct md_object *obj, struct md_attr *ma)
-{
-        struct mdd_object *mdd_obj = md2mdd_obj(obj);
-
-        return mdd_attr_get_internal_locked(env, mdd_obj, ma);
-}
-
-static int dot_lustre_mdd_attr_set(const struct lu_env *env,
-                                   struct md_object *obj,
-                                   const struct md_attr *ma)
-{
-        return -EPERM;
-}
-
 static int dot_lustre_mdd_xattr_get(const struct lu_env *env,
                                     struct md_object *obj, struct lu_buf *buf,
                                     const char *name)
 static int dot_lustre_mdd_xattr_get(const struct lu_env *env,
                                     struct md_object *obj, struct lu_buf *buf,
                                     const char *name)
@@ -609,8 +594,8 @@ static int dot_file_unlock(const struct lu_env *env, struct md_object *obj,
 
 static struct md_object_operations mdd_dot_lustre_obj_ops = {
         .moo_permission    = dot_lustre_mdd_permission,
 
 static struct md_object_operations mdd_dot_lustre_obj_ops = {
         .moo_permission    = dot_lustre_mdd_permission,
-        .moo_attr_get      = dot_lustre_mdd_attr_get,
-        .moo_attr_set      = dot_lustre_mdd_attr_set,
+       .moo_attr_get      = mdd_attr_get,
+       .moo_attr_set      = mdd_attr_set,
         .moo_xattr_get     = dot_lustre_mdd_xattr_get,
         .moo_xattr_list    = dot_lustre_mdd_xattr_list,
         .moo_xattr_set     = dot_lustre_mdd_xattr_set,
         .moo_xattr_get     = dot_lustre_mdd_xattr_get,
         .moo_xattr_list    = dot_lustre_mdd_xattr_list,
         .moo_xattr_set     = dot_lustre_mdd_xattr_set,
@@ -751,8 +736,7 @@ static int obf_attr_get(const struct lu_env *env, struct md_object *obj,
                 /* "fid" is a virtual object and hence does not have any "real"
                  * attributes. So we reuse attributes of .lustre for "fid" dir */
                 ma->ma_need |= MA_INODE;
                 /* "fid" is a virtual object and hence does not have any "real"
                  * attributes. So we reuse attributes of .lustre for "fid" dir */
                 ma->ma_need |= MA_INODE;
-                rc = dot_lustre_mdd_attr_get(env, &mdd->mdd_dot_lustre->mod_obj,
-                                             ma);
+               rc = mdd_attr_get(env, &mdd->mdd_dot_lustre->mod_obj, ma);
                 if (rc)
                         return rc;
                 ma->ma_valid |= MA_INODE;
                 if (rc)
                         return rc;
                 ma->ma_valid |= MA_INODE;
@@ -788,6 +772,12 @@ static int obf_attr_set(const struct lu_env *env, struct md_object *obj,
         return -EPERM;
 }
 
         return -EPERM;
 }
 
+static int obf_xattr_list(const struct lu_env *env,
+                         struct md_object *obj, struct lu_buf *buf)
+{
+       return 0;
+}
+
 static int obf_xattr_get(const struct lu_env *env,
                          struct md_object *obj, struct lu_buf *buf,
                          const char *name)
 static int obf_xattr_get(const struct lu_env *env,
                          struct md_object *obj, struct lu_buf *buf,
                          const char *name)
@@ -795,6 +785,21 @@ static int obf_xattr_get(const struct lu_env *env,
         return 0;
 }
 
         return 0;
 }
 
+static int obf_xattr_set(const struct lu_env *env,
+                        struct md_object *obj,
+                        const struct lu_buf *buf, const char *name,
+                        int fl)
+{
+       return -EPERM;
+}
+
+static int obf_xattr_del(const struct lu_env *env,
+                        struct md_object *obj,
+                        const char *name)
+{
+       return -EPERM;
+}
+
 static int obf_mdd_open(const struct lu_env *env, struct md_object *obj,
                         int flags)
 {
 static int obf_mdd_open(const struct lu_env *env, struct md_object *obj,
                         int flags)
 {
@@ -833,13 +838,16 @@ static int obf_path(const struct lu_env *env, struct md_object *obj,
 }
 
 static struct md_object_operations mdd_obf_obj_ops = {
 }
 
 static struct md_object_operations mdd_obf_obj_ops = {
-        .moo_attr_get   = obf_attr_get,
-        .moo_attr_set   = obf_attr_set,
-        .moo_xattr_get  = obf_xattr_get,
-        .moo_open       = obf_mdd_open,
-        .moo_close      = obf_mdd_close,
-        .moo_readpage   = obf_mdd_readpage,
-        .moo_path       = obf_path
+       .moo_attr_get    = obf_attr_get,
+       .moo_attr_set    = obf_attr_set,
+       .moo_xattr_list  = obf_xattr_list,
+       .moo_xattr_get   = obf_xattr_get,
+       .moo_xattr_set   = obf_xattr_set,
+       .moo_xattr_del   = obf_xattr_del,
+       .moo_open        = obf_mdd_open,
+       .moo_close       = obf_mdd_close,
+       .moo_readpage    = obf_mdd_readpage,
+       .moo_path        = obf_path
 };
 
 /**
 };
 
 /**
@@ -860,11 +868,19 @@ static int obf_lookup(const struct lu_env *env, struct md_object *p,
 
         sscanf(name, SFID, RFID(f));
         if (!fid_is_sane(f)) {
 
         sscanf(name, SFID, RFID(f));
         if (!fid_is_sane(f)) {
-                CWARN("bad FID format [%s], should be "DFID"\n", lname->ln_name,
-                      (__u64)1, 2, 0);
+               CWARN("%s: bad FID format [%s], should be "DFID"\n",
+                     mdd->mdd_obd_dev->obd_name, lname->ln_name,
+                     (__u64)FID_SEQ_NORMAL, 1, 0);
                 GOTO(out, rc = -EINVAL);
         }
 
                 GOTO(out, rc = -EINVAL);
         }
 
+       if (!fid_is_norm(f)) {
+               CWARN("%s: "DFID" is invalid, sequence should be "
+                     ">= "LPX64"\n", mdd->mdd_obd_dev->obd_name, PFID(f),
+                     (__u64)FID_SEQ_NORMAL);
+               GOTO(out, rc = -EINVAL);
+       }
+
         /* Check if object with this fid exists */
         child = mdd_object_find(env, mdd, f);
         if (child == NULL)
         /* Check if object with this fid exists */
         child = mdd_object_find(env, mdd, f);
         if (child == NULL)
index 79f6de2..96181ba 100644 (file)
@@ -248,6 +248,10 @@ int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
                struct lu_attr *la, struct lustre_capa *capa);
 int mdd_data_get(const struct lu_env *env, struct mdd_object *obj, void **data);
 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
                struct lu_attr *la, struct lustre_capa *capa);
+int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
+                struct md_attr *ma);
+int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
+                const struct md_attr *ma);
 int mdd_attr_set_internal(const struct lu_env *env,
                           struct mdd_object *obj,
                           struct lu_attr *attr,
 int mdd_attr_set_internal(const struct lu_env *env,
                           struct mdd_object *obj,
                           struct lu_attr *attr,
index ccea39b..0cc62fa 100644 (file)
@@ -851,8 +851,8 @@ int mdd_attr_get_internal_locked(const struct lu_env *env,
 /*
  * No permission check is needed.
  */
 /*
  * No permission check is needed.
  */
-static int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
-                        struct md_attr *ma)
+int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
+                struct md_attr *ma)
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
         int                rc;
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
         int                rc;
@@ -1633,8 +1633,8 @@ static int mdd_declare_attr_set(const struct lu_env *env,
 }
 
 /* set attr and LOV EA at once, return updated attr */
 }
 
 /* set attr and LOV EA at once, return updated attr */
-static int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
-                        const struct md_attr *ma)
+int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
+                const struct md_attr *ma)
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
         struct mdd_device *mdd = mdo2mdd(obj);
 {
         struct mdd_object *mdd_obj = md2mdd_obj(obj);
         struct mdd_device *mdd = mdo2mdd(obj);
index 60730a8..682b348 100644 (file)
@@ -103,7 +103,7 @@ static void mdt_obj_version_get(struct mdt_thread_info *info,
 {
         LASSERT(o);
         LASSERT(mdt_object_exists(o) >= 0);
 {
         LASSERT(o);
         LASSERT(mdt_object_exists(o) >= 0);
-        if (mdt_object_exists(o) > 0)
+       if (mdt_object_exists(o) > 0 && !mdt_object_obf(o))
                 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
         else
                 *version = ENOENT_VERSION;
                 *version = dt_version_get(info->mti_env, mdt_obj2dt(o));
         else
                 *version = ENOENT_VERSION;
@@ -492,6 +492,9 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
         if (IS_ERR(mo))
                 GOTO(out, rc = PTR_ERR(mo));
 
         if (IS_ERR(mo))
                 GOTO(out, rc = PTR_ERR(mo));
 
+       if (mdt_object_obf(mo))
+               GOTO(out_put, rc = -EPERM);
+
         /* start a log jounal handle if needed */
         if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
                 if ((ma->ma_attr.la_valid & LA_SIZE) ||
         /* start a log jounal handle if needed */
         if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
                 if ((ma->ma_attr.la_valid & LA_SIZE) ||
@@ -1222,6 +1225,11 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
         if (IS_ERR(mold))
                 GOTO(out_unlock_target, rc = PTR_ERR(mold));
 
         if (IS_ERR(mold))
                 GOTO(out_unlock_target, rc = PTR_ERR(mold));
 
+       if (mdt_object_obf(mold)) {
+               mdt_object_put(info->mti_env, mold);
+               GOTO(out_unlock_target, rc = -EPERM);
+       }
+
         lh_oldp = &info->mti_lh[MDT_LH_OLD];
         mdt_lock_reg_init(lh_oldp, LCK_EX);
         rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP,
         lh_oldp = &info->mti_lh[MDT_LH_OLD];
         mdt_lock_reg_init(lh_oldp, LCK_EX);
         rc = mdt_object_lock(info, mold, lh_oldp, MDS_INODELOCK_LOOKUP,
@@ -1256,6 +1264,11 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                 if (IS_ERR(mnew))
                         GOTO(out_unlock_old, rc = PTR_ERR(mnew));
 
                 if (IS_ERR(mnew))
                         GOTO(out_unlock_old, rc = PTR_ERR(mnew));
 
+               if (mdt_object_obf(mnew)) {
+                       mdt_object_put(info->mti_env, mnew);
+                       GOTO(out_unlock_old, rc = -EPERM);
+               }
+
                 rc = mdt_object_lock(info, mnew, lh_newp,
                                      MDS_INODELOCK_FULL, MDT_CROSS_LOCK);
                 if (rc != 0) {
                 rc = mdt_object_lock(info, mnew, lh_newp,
                                      MDS_INODELOCK_FULL, MDT_CROSS_LOCK);
                 if (rc != 0) {
index e37c7f3..f434a8e 100644 (file)
@@ -7864,6 +7864,35 @@ test_154() {
        touch $DIR/.lustre/fid/$tfile && \
                error "touch $DIR/.lustre/fid/$tfile should fail."
 
        touch $DIR/.lustre/fid/$tfile && \
                error "touch $DIR/.lustre/fid/$tfile should fail."
 
+       echo "setxattr to $DIR/.lustre/fid"
+       setfattr -n trusted.name1 -v value1 $DIR/.lustre/fid &&
+               error "setxattr should fail."
+
+       echo "listxattr for $DIR/.lustre/fid"
+       getfattr -d -m "^trusted" $DIR/.lustre/fid &&
+               error "listxattr should fail."
+
+       echo "delxattr from $DIR/.lustre/fid"
+       setfattr -x trusted.name1 $DIR/.lustre/fid &&
+               error "delxattr should fail."
+
+       echo "touch invalid fid: $DIR/.lustre/fid/[0x200000400:0x2:0x3]"
+       touch $DIR/.lustre/fid/[0x200000400:0x2:0x3] &&
+               error "touch invalid fid should fail."
+
+       echo "touch non-normal fid: $DIR/.lustre/fid/[0x1:0x2:0x0]"
+       touch $DIR/.lustre/fid/[0x1:0x2:0x0] &&
+               error "touch non-normal fid should fail."
+
+       echo "rename $tdir to $DIR/.lustre/fid"
+       mrename $DIR/$tdir $DIR/.lustre/fid &&
+               error "rename to $DIR/.lustre/fid should fail."
+
+       echo "rename .lustre to itself"
+       fid=$($LFS path2fid $DIR)
+       mrename $DIR/.lustre $DIR/.lustre/fid/$fid/.lustre &&
+               error "rename .lustre to itself should fail."
+
        echo "Open-by-FID succeeded"
 }
 run_test 154 "Open-by-FID"
        echo "Open-by-FID succeeded"
 }
 run_test 154 "Open-by-FID"