Whamcloud - gitweb
LU-15548 osd-ldiskfs: hide virtual projid xattr
authorLi Dongyang <dongyangli@ddn.com>
Wed, 23 Mar 2022 09:42:51 +0000 (20:42 +1100)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 4 Aug 2022 18:53:58 +0000 (18:53 +0000)
Add tunable enable_projid_xattr to hide the virtual
project ID xattr by default.

Lustre-change: https://review.whamcloud.com/46900
Lustre-commit: ef826db1f43b2849af26491028f4cfc25595faf6

Fixes: 665383d3a1f4 ("LU-12056 ldiskfs: add trusted.projid virtual xattr")
Change-Id: I21263d91599f9e2d5850cb9d94a8b6df90c8443c
Test-Parameters: trivial testlist=conf-sanity env=ONLY=131
Test-Parameters: testlist=sanity env=ONLY=904
Signed-off-by: Li Dongyang <dongyangli@ddn.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/47989
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/osd-ldiskfs/osd_handler.c
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_lproc.c
lustre/tests/sanity.sh

index 135f081..d304c4d 100644 (file)
@@ -4901,9 +4901,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;
@@ -4914,7 +4916,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,
@@ -8152,6 +8178,7 @@ static int osd_device_init0(const struct lu_env *env,
 
        o->od_read_cache_enable = 1;
        o->od_writethrough_cache_enable = 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;
index 0455bbe..068dd6c 100644 (file)
@@ -288,7 +288,8 @@ struct osd_device {
                                  od_writethrough_cache_enable:1,
                                  od_writethrough_cache_enable_set:1,
                                  od_nonrotational:1,
-                                 od_nonrotational_set:1;
+                                 od_nonrotational_set:1,
+                                 od_enable_projid_xattr:1;
 
        __s64                     od_auto_scrub_interval;
        __u32                     od_dirent_journal;
index d600856..fb3b355 100644 (file)
@@ -333,6 +333,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)
@@ -879,6 +918,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,
index 344deaf..52c9758 100755 (executable)
@@ -27683,9 +27683,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"
@@ -27708,6 +27721,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" ] ||