Whamcloud - gitweb
LU-6027 mdt: Allow user EAs with empty values 00/12900/9
authorLi Wei <wei.g.li@intel.com>
Mon, 1 Dec 2014 07:05:56 +0000 (15:05 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 19 Jan 2015 23:44:29 +0000 (23:44 +0000)
Setting a user EA with an empty value is a valid case, according to
attr(5) and some experiments with ext4.  Doing so with Lustre
currently results in what appears to be a no-op---the EA name won't be
added or updated (if an EA with the same name already existed).

Change-Id: Ic8950963baeceada99c4607631ecd2a6510ae3ed
Signed-off-by: Li Wei <wei.g.li@intel.com>
Reviewed-on: http://review.whamcloud.com/12900
Tested-by: Jenkins
Reviewed-by: Fan Yong <fan.yong@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Johann Lombardi <johann.lombardi@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_xattr.c
lustre/tests/sanity.sh

index e699d52..7d7e15d 100644 (file)
@@ -378,7 +378,8 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
        __u32                    perm;
        ENTRY;
 
-        CDEBUG(D_INODE, "setxattr for "DFID"\n", PFID(rr->rr_fid1));
+       CDEBUG(D_INODE, "setxattr for "DFID": %s %s\n", PFID(rr->rr_fid1),
+              valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
 
        if (info->mti_dlm_req)
                ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
@@ -386,9 +387,6 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SETXATTR))
                 RETURN(err_serious(-ENOMEM));
 
-        CDEBUG(D_INODE, "%s xattr %s\n",
-               valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
-
        rc = mdt_init_ucred_reint(info);
         if (rc != 0)
                 RETURN(rc);
@@ -486,43 +484,38 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
        attr->la_valid = LA_CTIME;
        child = mdt_object_child(obj);
        if (valid & OBD_MD_FLXATTR) {
-               char *xattr = rr->rr_eadata;
-
-                if (xattr_len > 0) {
-                        int flags = 0;
-
-                        if (valid & OBD_MD_FLRMTLSETFACL) {
-                                if (unlikely(!remote))
-                                        GOTO(out_unlock, rc = -EINVAL);
-
-                                xattr_len = mdt_rmtlsetfacl(info, child,
-                                                xattr_name,
-                                                (ext_acl_xattr_header *)xattr,
-                                                &new_xattr);
-                                if (xattr_len < 0)
-                                        GOTO(out_unlock, rc = xattr_len);
-
-                                xattr = (char *)new_xattr;
-                        }
-
-                        if (attr->la_flags & XATTR_REPLACE)
-                                flags |= LU_XATTR_REPLACE;
-
-                        if (attr->la_flags & XATTR_CREATE)
-                                flags |= LU_XATTR_CREATE;
-
-                        mdt_fail_write(env, info->mti_mdt->mdt_bottom,
-                                       OBD_FAIL_MDS_SETXATTR_WRITE);
-
-                        buf->lb_buf = xattr;
-                        buf->lb_len = xattr_len;
-                        rc = mo_xattr_set(env, child, buf, xattr_name, flags);
-                        /* update ctime after xattr changed */
-                        if (rc == 0) {
-                                ma->ma_attr_flags |= MDS_PERM_BYPASS;
-                                mo_attr_set(env, child, ma);
-                        }
-                }
+               void   *xattr = rr->rr_eadata;
+               int     flags = 0;
+
+               if (valid & OBD_MD_FLRMTLSETFACL) {
+                       if (unlikely(!remote))
+                               GOTO(out_unlock, rc = -EINVAL);
+
+                       xattr_len = mdt_rmtlsetfacl(info, child, xattr_name,
+                                                   xattr, &new_xattr);
+                       if (xattr_len < 0)
+                               GOTO(out_unlock, rc = xattr_len);
+
+                       xattr = new_xattr;
+               }
+
+               if (attr->la_flags & XATTR_REPLACE)
+                       flags |= LU_XATTR_REPLACE;
+
+               if (attr->la_flags & XATTR_CREATE)
+                       flags |= LU_XATTR_CREATE;
+
+               mdt_fail_write(env, info->mti_mdt->mdt_bottom,
+                              OBD_FAIL_MDS_SETXATTR_WRITE);
+
+               buf->lb_buf = xattr;
+               buf->lb_len = xattr_len;
+               rc = mo_xattr_set(env, child, buf, xattr_name, flags);
+               /* update ctime after xattr changed */
+               if (rc == 0) {
+                       ma->ma_attr_flags |= MDS_PERM_BYPASS;
+                       mo_attr_set(env, child, ma);
+               }
         } else if (valid & OBD_MD_FLXATTRRM) {
                 rc = mo_xattr_del(env, child, xattr_name);
                 /* update ctime after xattr changed */
index c70457c..d564937 100644 (file)
@@ -6903,6 +6903,14 @@ test_102q() {
 }
 run_test 102q "flistxattr should not return trusted.link EAs for orphans"
 
+test_102r() {
+       touch $DIR/$tfile || error "touch"
+       setfattr -n user.$(basename $tfile) $DIR/$tfile || error "setfattr"
+       getfattr -n user.$(basename $tfile) $DIR/$tfile || error "getfattr"
+       rm $DIR/$tfile || error "rm"
+}
+run_test 102r "set EAs with empty values"
+
 run_acl_subtest()
 {
     $LUSTRE/tests/acl/run $LUSTRE/tests/acl/$1.test