From ba7c99a5b18535305d3ae3b1687116c1fff5b4a8 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Fri, 27 Jun 2014 00:20:46 +0800 Subject: [PATCH] LU-3660 acl: support mount option "noacl" for zfs zfs parse mount option in zpl layer, but osd-zfs calls dmu directly, since ldiskfs parse "noacl" at mount time, osd-zfs should do the same in osd_mount(). Similar to ldiskfs, osd-zfs should check whether ACL is enabled for ACL operations, if not -EOPNOTSUPP is returned. add sanity test 103b for "noacl" mount option. Signed-off-by: Lai Siyao Change-Id: I11075a9de8759fde956e7ae8b715840a56d0428e Reviewed-on: http://review.whamcloud.com/11157 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Li Wei Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_xattr.c | 13 +++++++------ lustre/osd-zfs/osd_handler.c | 25 ++++++++++++++++++------- lustre/osd-zfs/osd_internal.h | 3 ++- lustre/osd-zfs/osd_xattr.c | 32 +++++++++++++++++++++++++++++++- lustre/tests/sanity.sh | 40 ++++++++++++++++++++++++++++++++++++++-- 5 files changed, 96 insertions(+), 17 deletions(-) diff --git a/lustre/mdt/mdt_xattr.c b/lustre/mdt/mdt_xattr.c index 6c5616f..c8ced24 100644 --- a/lustre/mdt/mdt_xattr.c +++ b/lustre/mdt/mdt_xattr.c @@ -95,12 +95,13 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info) RETURN(-EINVAL); } - if (size == -ENODATA) { - size = 0; - } else if (size < 0) { - CERROR("Error geting EA size: %d\n", size); - RETURN(size); - } + if (size == -ENODATA) { + size = 0; + } else if (size < 0) { + if (size != -EOPNOTSUPP) + CERROR("Error geting EA size: %d\n", size); + RETURN(size); + } req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER, info->mti_body->mbo_eadatasize == 0 ? 0 : size); diff --git a/lustre/osd-zfs/osd_handler.c b/lustre/osd-zfs/osd_handler.c index 66efdc9..bb42023 100644 --- a/lustre/osd-zfs/osd_handler.c +++ b/lustre/osd-zfs/osd_handler.c @@ -336,19 +336,23 @@ static void osd_conf_get(const struct lu_env *env, const struct dt_device *dev, struct dt_device_param *param) { + struct osd_device *osd = osd_dt_dev(dev); + /* * XXX should be taken from not-yet-existing fs abstraction layer. */ - param->ddp_max_name_len = MAXNAMELEN; - param->ddp_max_nlink = 1 << 31; /* it's 8byte on a disk */ - param->ddp_block_shift = 12; /* XXX */ - param->ddp_mount_type = LDD_MT_ZFS; + param->ddp_max_name_len = MAXNAMELEN; + param->ddp_max_nlink = 1 << 31; /* it's 8byte on a disk */ + param->ddp_block_shift = 12; /* XXX */ + param->ddp_mount_type = LDD_MT_ZFS; - param->ddp_mntopts = MNTOPT_USERXATTR | MNTOPT_ACL; - param->ddp_max_ea_size = DXATTR_MAX_ENTRY_SIZE; + param->ddp_mntopts = MNTOPT_USERXATTR; + if (osd->od_posix_acl) + param->ddp_mntopts |= MNTOPT_ACL; + param->ddp_max_ea_size = DXATTR_MAX_ENTRY_SIZE; /* for maxbytes, report same value as ZPL */ - param->ddp_maxbytes = MAX_LFS_FILESIZE; + param->ddp_maxbytes = MAX_LFS_FILESIZE; /* Default reserved fraction of the available space that should be kept * for error margin. Unfortunately, there are many factors that can @@ -520,6 +524,7 @@ static int osd_mount(const struct lu_env *env, char *svname = lustre_cfg_string(cfg, 4); dmu_buf_t *rootdb; dsl_pool_t *dp; + const char *opts; int rc; ENTRY; @@ -604,6 +609,12 @@ static int osd_mount(const struct lu_env *env, o->od_quota_slave = NULL; GOTO(err, rc); } + + /* parse mount option "noacl", and enable ACL by default */ + opts = lustre_cfg_string(cfg, 3); + if (opts == NULL || strstr(opts, "noacl") == NULL) + o->od_posix_acl = 1; + err: RETURN(rc); } diff --git a/lustre/osd-zfs/osd_internal.h b/lustre/osd-zfs/osd_internal.h index 3df1af1..16e7633 100644 --- a/lustre/osd-zfs/osd_internal.h +++ b/lustre/osd-zfs/osd_internal.h @@ -256,7 +256,8 @@ struct osd_device { unsigned int od_rdonly:1, od_xattr_in_sa:1, od_quota_iused_est:1, - od_is_ost:1; + od_is_ost:1, + od_posix_acl:1; char od_mntdev[128]; char od_svname[128]; diff --git a/lustre/osd-zfs/osd_xattr.c b/lustre/osd-zfs/osd_xattr.c index 2900fb6..bc45582 100644 --- a/lustre/osd-zfs/osd_xattr.c +++ b/lustre/osd-zfs/osd_xattr.c @@ -68,6 +68,7 @@ #include #include +#include /* * Copy an extended attribute into the buffer provided, or compute the @@ -245,6 +246,11 @@ int osd_xattr_get(const struct lu_env *env, struct dt_object *dt, LASSERT(osd_invariant(obj)); LASSERT(dt_object_exists(dt)); + if (!osd_obj2dev(obj)->od_posix_acl && + (!strcmp(name, POSIX_ACL_XATTR_ACCESS) || + !strcmp(name, POSIX_ACL_XATTR_DEFAULT))) + RETURN(-EOPNOTSUPP); + down(&obj->oo_guard); rc = __osd_xattr_get(env, obj, buf, name, &size); up(&obj->oo_guard); @@ -589,6 +595,11 @@ int osd_xattr_set(const struct lu_env *env, struct dt_object *dt, LASSERT(dt_object_exists(dt)); LASSERT(obj->oo_db); + if (!osd_obj2dev(obj)->od_posix_acl && + (!strcmp(name, POSIX_ACL_XATTR_ACCESS) || + !strcmp(name, POSIX_ACL_XATTR_DEFAULT))) + RETURN(-EOPNOTSUPP); + oh = container_of0(handle, struct osd_thandle, ot_super); down(&obj->oo_guard); @@ -727,6 +738,11 @@ int osd_xattr_del(const struct lu_env *env, struct dt_object *dt, oh = container_of0(handle, struct osd_thandle, ot_super); LASSERT(oh->ot_tx != NULL); + if (!osd_obj2dev(obj)->od_posix_acl && + (!strcmp(name, POSIX_ACL_XATTR_ACCESS) || + !strcmp(name, POSIX_ACL_XATTR_DEFAULT))) + RETURN(-EOPNOTSUPP); + down(&obj->oo_guard); rc = __osd_xattr_del(env, obj, name, oh); up(&obj->oo_guard); @@ -751,12 +767,19 @@ osd_sa_xattr_list(const struct lu_env *env, struct osd_object *obj, LASSERT(obj->oo_sa_xattr); while ((nvp = nvlist_next_nvpair(obj->oo_sa_xattr, nvp)) != NULL) { + const char *name = nvpair_name(nvp); + + if (!osd_obj2dev(obj)->od_posix_acl && + (!strcmp(name, POSIX_ACL_XATTR_ACCESS) || + !strcmp(name, POSIX_ACL_XATTR_DEFAULT))) + continue; + len = strlen(nvpair_name(nvp)); if (lb->lb_buf != NULL) { if (len + 1 > remain) return -ERANGE; - memcpy(lb->lb_buf, nvpair_name(nvp), len); + memcpy(lb->lb_buf, name, len); lb->lb_buf += len; *((char *)lb->lb_buf) = '\0'; lb->lb_buf++; @@ -800,6 +823,13 @@ int osd_xattr_list(const struct lu_env *env, struct dt_object *dt, while ((rc = -udmu_zap_cursor_retrieve_key(env, zc, oti->oti_key, MAXNAMELEN)) == 0) { + if (!osd_obj2dev(obj)->od_posix_acl && + (!strcmp(oti->oti_key, POSIX_ACL_XATTR_ACCESS) || + !strcmp(oti->oti_key, POSIX_ACL_XATTR_DEFAULT))) { + zap_cursor_advance(zc); + continue; + } + rc = strlen(oti->oti_key); if (lb->lb_buf != NULL) { if (rc + 1 > remain) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index cb99d07..d2c7a48 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -6840,7 +6840,7 @@ run_acl_subtest() return $? } -test_103 () { +test_103a() { [ "$UID" != 0 ] && skip_env "must run as root" && return [ -z "$(lctl get_param -n mdc.*-mdc-*.connect_flags | grep acl)" ] && skip "must have acl enabled" && return @@ -6901,7 +6901,43 @@ test_103 () { fi done } -run_test 103 "acl test =========================================" +run_test 103a "acl test =========================================" + +test_103b() { + local noacl=false + local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/}) + local mountopts=$MDS_MOUNT_OPTS + + if [[ "$MDS_MOUNT_OPTS" =~ "noacl" ]]; then + noacl=true + else + # stop the MDT + stop $SINGLEMDS || error "failed to stop MDT." + # remount the MDT + if [ -z "$MDS_MOUNT_OPTS" ]; then + MDS_MOUNT_OPTS="-o noacl" + else + MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl" + fi + start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || + error "failed to start MDT." + MDS_MOUNT_OPTS=$mountopts + fi + + touch $DIR/$tfile + setfacl -m u:bin:rw $DIR/$tfile && error "setfacl should fail" + + if ! $noacl; then + # stop the MDT + stop $SINGLEMDS || error "failed to stop MDT." + # remount the MDT + start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || + error "failed to start MDT." + fi + + rm -f $DIR/$tfile +} +run_test 103b "MDS mount option \"noacl\" =======================" test_104a() { [ $PARALLEL == "yes" ] && skip "skip parallel run" && return -- 1.8.3.1