From 165f65a7aa07d55d284d419cdaa04eed2d96ade3 Mon Sep 17 00:00:00 2001 From: Li Wei Date: Mon, 1 Dec 2014 15:05:56 +0800 Subject: [PATCH] LU-6027 mdt: Allow user EAs with empty values 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 Reviewed-on: http://review.whamcloud.com/12900 Tested-by: Jenkins Reviewed-by: Fan Yong Tested-by: Maloo Reviewed-by: Johann Lombardi Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_xattr.c | 75 +++++++++++++++++++++++--------------------------- lustre/tests/sanity.sh | 8 ++++++ 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index e699d52e..7d7e15d 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -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 */ diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index c70457c..d564937 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 -- 1.8.3.1