From ef826db1f43b2849af26491028f4cfc25595faf6 Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Wed, 23 Mar 2022 20:42:51 +1100 Subject: [PATCH] LU-15548 osd-ldiskfs: hide virtual projid xattr Add tunable enable_projid_xattr to hide the virtual project ID xattr by default. Change-Id: I21263d91599f9e2d5850cb9d94a8b6df90c8443c Test-Parameters: trivial testlist=conf-sanity env=ONLY=131 Test-Parameters: testlist=sanity env=ONLY=904 Signed-off-by: Li Dongyang Reviewed-on: https://review.whamcloud.com/46900 Tested-by: jenkins Reviewed-by: Li Xi Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/osd-ldiskfs/osd_handler.c | 29 +++++++++++++++++++++++++++- lustre/osd-ldiskfs/osd_internal.h | 3 ++- lustre/osd-ldiskfs/osd_lproc.c | 40 +++++++++++++++++++++++++++++++++++++++ lustre/tests/sanity.sh | 15 +++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index 0577ba9..daf2efe 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -4908,9 +4908,11 @@ static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt, const struct lu_buf *buf) { struct osd_object *obj = osd_dt_obj(dt); + struct osd_device *dev = osd_obj2dev(obj); struct inode *inode = obj->oo_inode; struct osd_thread_info *info = osd_oti_get(env); struct dentry *dentry = &info->oti_obj_dentry; + int rc; if (!dt_object_exists(dt)) return -ENOENT; @@ -4921,7 +4923,31 @@ static int osd_xattr_list(const struct lu_env *env, struct dt_object *dt, dentry->d_inode = inode; dentry->d_sb = inode->i_sb; - return inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len); + rc = inode->i_op->listxattr(dentry, buf->lb_buf, buf->lb_len); + + if (rc < 0 || buf->lb_buf == NULL) + return rc; + + /* Hide virtual project ID xattr from list if disabled */ + if (!dev->od_enable_projid_xattr) { + char *end = (char *)buf->lb_buf + rc; + char *p = buf->lb_buf; + + while (p < end) { + char *next = p + strlen(p) + 1; + + if (strcmp(p, XATTR_NAME_PROJID) == 0) { + if (end - next > 0) + memmove(p, next, end - next); + rc -= next - p; + break; + } + + p = next; + } + } + + return rc; } static int osd_declare_xattr_del(const struct lu_env *env, @@ -8163,6 +8189,7 @@ static int osd_device_init0(const struct lu_env *env, o->od_read_cache = 1; o->od_writethrough_cache = 1; + o->od_enable_projid_xattr = 0; o->od_readcache_max_filesize = OSD_MAX_CACHE_SIZE; o->od_readcache_max_iosize = OSD_READCACHE_MAX_IO_MB << 20; o->od_writethrough_max_iosize = OSD_WRITECACHE_MAX_IO_MB << 20; diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index 0ce9cce..b77ade7 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -278,7 +278,8 @@ struct osd_device { /* Other flags */ od_read_cache:1, od_writethrough_cache:1, - od_nonrotational:1; + od_nonrotational:1, + od_enable_projid_xattr:1; __u32 od_dirent_journal; diff --git a/lustre/osd-ldiskfs/osd_lproc.c b/lustre/osd-ldiskfs/osd_lproc.c index 01d5982..b93881b 100644 --- a/lustre/osd-ldiskfs/osd_lproc.c +++ b/lustre/osd-ldiskfs/osd_lproc.c @@ -218,6 +218,45 @@ static ssize_t writethrough_cache_enable_store(struct kobject *kobj, } LUSTRE_RW_ATTR(writethrough_cache_enable); +static ssize_t enable_projid_xattr_show(struct kobject *kobj, + struct attribute *attr, + char *buf) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct osd_device *osd = osd_dt_dev(dt); + + LASSERT(osd); + if (unlikely(!osd->od_mnt)) + return -EINPROGRESS; + + return snprintf(buf, PAGE_SIZE, "%u\n", osd->od_enable_projid_xattr); +} + +static ssize_t enable_projid_xattr_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, + size_t count) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, + dd_kobj); + struct osd_device *osd = osd_dt_dev(dt); + bool val; + int rc; + + LASSERT(osd); + if (unlikely(!osd->od_mnt)) + return -EINPROGRESS; + + rc = kstrtobool(buffer, &val); + if (rc) + return rc; + + osd->od_enable_projid_xattr = !!val; + return count; +} +LUSTRE_RW_ATTR(enable_projid_xattr); + static ssize_t fallocate_zero_blocks_show(struct kobject *kobj, struct attribute *attr, char *buf) @@ -762,6 +801,7 @@ struct ldebugfs_vars ldebugfs_osd_obd_vars[] = { static struct attribute *ldiskfs_attrs[] = { &lustre_attr_read_cache_enable.attr, &lustre_attr_writethrough_cache_enable.attr, + &lustre_attr_enable_projid_xattr.attr, &lustre_attr_fstype.attr, &lustre_attr_mntdev.attr, &lustre_attr_fallocate_zero_blocks.attr, diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index a437b57..62e0899 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -28160,9 +28160,22 @@ test_904() { local testfile="$DIR/$tdir/$tfile" local xattr="trusted.projid" local projid + local mdts=$(comma_list $(mdts_nodes)) + local saved=$(do_facet mds1 $LCTL get_param -n \ + osd-ldiskfs.*MDT0000.enable_projid_xattr) + + do_nodes $mdts $LCTL set_param osd-ldiskfs.*MDT*.enable_projid_xattr=0 + stack_trap "do_nodes $mdts $LCTL set_param \ + osd-ldiskfs.*MDT*.enable_projid_xattr=$saved" mkdir -p $DIR/$tdir touch $testfile + #hide projid xattr on server + $LFS project -p 1 $testfile || + error "set $testfile project id failed" + getfattr -m - $testfile | grep $xattr && + error "do not show trusted.projid when disabled on server" + do_nodes $mdts $LCTL set_param osd-ldiskfs.*MDT*.enable_projid_xattr=1 #should be hidden when projid is 0 $LFS project -p 0 $testfile || error "set $testfile project id failed" @@ -28185,6 +28198,8 @@ test_904() { #check the new projid via getxattr $LFS project -p 1001 $testfile || error "set $testfile project id failed" + getfattr -m - $testfile | grep $xattr || + error "should show trusted.projid when project ID != 0" projid=$(getfattr -n $xattr $testfile | sed -n 's/^trusted\.projid="\(.*\)"/\1/p') [ $projid == "1001" ] || -- 1.8.3.1