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;
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,
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;
/* 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;
}
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)
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,
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"
#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" ] ||