Whamcloud - gitweb
LU-15548 osd-ldiskfs: hide virtual projid xattr 00/46900/3
authorLi Dongyang <dongyangli@ddn.com>
Wed, 23 Mar 2022 09:42:51 +0000 (20:42 +1100)
committerOleg Drokin <green@whamcloud.com>
Wed, 30 Mar 2022 06:15:50 +0000 (06:15 +0000)
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 <dongyangli@ddn.com>
Reviewed-on: https://review.whamcloud.com/46900
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@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 0577ba9..daf2efe 100644 (file)
@@ -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;
index 0ce9cce..b77ade7 100644 (file)
@@ -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;
index 01d5982..b93881b 100644 (file)
@@ -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,
index a437b57..62e0899 100755 (executable)
@@ -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" ] ||