Skip to content

Commit 01edea1

Browse files
committed
Pull filesystem visibility ioctls series from Kent Overstreet: This patch series adds a few new ioctls to standardize a few interfaces to get and set filesystem uuid and retrieving the sysfs path. The get UUID ioctls are lifted versions of the ext4 ioctls with one difference, killing the flexible array member - we'll never have UUIDs more than 16 bytes, and getting rid of the flexible array member makes them easier to use. FS_IOC_GETFSSYSFSPATH is new, but it addresses something that we've been doing in fs specific code for awhile - "given a path on a mounted filesystem, tell me where it lives in sysfs". * series "filesystem visibility ioctls" of https://lore.kernel.org/r/20240207025624.1019754-1-kent.overstreet@linux.dev: (6 commits) xfs: add support for FS_IOC_GETFSSYSFSPATH fs: add FS_IOC_GETFSSYSFSPATH fat: Hook up sb->s_uuid fs: FS_IOC_GETUUID ovl: convert to super_set_uuid() fs: super_set_uuid() Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents 6613476 + 231e872 commit 01edea1

File tree

14 files changed

+141
-17
lines changed

14 files changed

+141
-17
lines changed

Documentation/userspace-api/ioctl/ioctl-number.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ Code Seq# Include File Comments
8282
0x10 00-0F drivers/char/s390/vmcp.h
8383
0x10 10-1F arch/s390/include/uapi/sclp_ctl.h
8484
0x10 20-2F arch/s390/include/uapi/asm/hypfs.h
85-
0x12 all linux/fs.h
85+
0x12 all linux/fs.h BLK* ioctls
8686
linux/blkpg.h
87+
0x15 all linux/fs.h FS_IOC_* ioctls
8788
0x1b all InfiniBand Subsystem
8889
<http://infiniband.sourceforge.net/>
8990
0x20 all drivers/cdrom/cm206.h

fs/ext4/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5346,7 +5346,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
53465346
sb->s_qcop = &ext4_qctl_operations;
53475347
sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
53485348
#endif
5349-
memcpy(&sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
5349+
super_set_uuid(sb, es->s_uuid, sizeof(es->s_uuid));
53505350

53515351
INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
53525352
mutex_init(&sbi->s_orphan_lock);

fs/f2fs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4496,7 +4496,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
44964496
sb->s_time_gran = 1;
44974497
sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
44984498
(test_opt(sbi, POSIX_ACL) ? SB_POSIXACL : 0);
4499-
memcpy(&sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
4499+
super_set_uuid(sb, (void *) raw_super->uuid, sizeof(raw_super->uuid));
45004500
sb->s_iflags |= SB_I_CGROUPWB;
45014501

45024502
/* init f2fs-specific super block info */

fs/fat/inode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,9 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat,
17621762
else /* fat 16 or 12 */
17631763
sbi->vol_id = bpb.fat16_vol_id;
17641764

1765+
__le32 vol_id_le = cpu_to_le32(sbi->vol_id);
1766+
super_set_uuid(sb, (void *) &vol_id_le, sizeof(vol_id_le));
1767+
17651768
sbi->dir_per_block = sb->s_blocksize / sizeof(struct msdos_dir_entry);
17661769
sbi->dir_per_block_bits = ffs(sbi->dir_per_block) - 1;
17671770

fs/gfs2/ops_fstype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void gfs2_sb_in(struct gfs2_sbd *sdp, const void *buf)
214214

215215
memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
216216
memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
217-
memcpy(&s->s_uuid, str->sb_uuid, 16);
217+
super_set_uuid(s, str->sb_uuid, 16);
218218
}
219219

220220
/**

fs/ioctl.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,33 @@ static int ioctl_fssetxattr(struct file *file, void __user *argp)
763763
return err;
764764
}
765765

766+
static int ioctl_getfsuuid(struct file *file, void __user *argp)
767+
{
768+
struct super_block *sb = file_inode(file)->i_sb;
769+
struct fsuuid2 u = { .len = sb->s_uuid_len, };
770+
771+
if (!sb->s_uuid_len)
772+
return -ENOIOCTLCMD;
773+
774+
memcpy(&u.uuid[0], &sb->s_uuid, sb->s_uuid_len);
775+
776+
return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
777+
}
778+
779+
static int ioctl_get_fs_sysfs_path(struct file *file, void __user *argp)
780+
{
781+
struct super_block *sb = file_inode(file)->i_sb;
782+
783+
if (!strlen(sb->s_sysfs_name))
784+
return -ENOIOCTLCMD;
785+
786+
struct fs_sysfs_path u = {};
787+
788+
u.len = scnprintf(u.name, sizeof(u.name), "%s/%s", sb->s_type->name, sb->s_sysfs_name);
789+
790+
return copy_to_user(argp, &u, sizeof(u)) ? -EFAULT : 0;
791+
}
792+
766793
/*
767794
* do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
768795
* It's just a simple helper for sys_ioctl and compat_sys_ioctl.
@@ -845,6 +872,12 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
845872
case FS_IOC_FSSETXATTR:
846873
return ioctl_fssetxattr(filp, argp);
847874

875+
case FS_IOC_GETFSUUID:
876+
return ioctl_getfsuuid(filp, argp);
877+
878+
case FS_IOC_GETFSSYSFSPATH:
879+
return ioctl_get_fs_sysfs_path(filp, argp);
880+
848881
default:
849882
if (S_ISREG(inode->i_mode))
850883
return file_ioctl(filp, cmd, argp);

fs/kernfs/mount.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,9 @@ int kernfs_get_tree(struct fs_context *fc)
358358
}
359359
sb->s_flags |= SB_ACTIVE;
360360

361-
uuid_gen(&sb->s_uuid);
361+
uuid_t uuid;
362+
uuid_gen(&uuid);
363+
super_set_uuid(sb, uuid.b, sizeof(uuid));
362364

363365
down_write(&root->kernfs_supers_rwsem);
364366
list_add(&info->node, &info->root->supers);

fs/ocfs2/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,8 +2027,8 @@ static int ocfs2_initialize_super(struct super_block *sb,
20272027
cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
20282028
bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
20292029
sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
2030-
memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
2031-
sizeof(di->id2.i_super.s_uuid));
2030+
super_set_uuid(sb, di->id2.i_super.s_uuid,
2031+
sizeof(di->id2.i_super.s_uuid));
20322032

20332033
osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
20342034

fs/overlayfs/util.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,14 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
760760
const struct path *upperpath)
761761
{
762762
bool set = false;
763+
uuid_t uuid;
763764
int res;
764765

765766
/* Try to load existing persistent uuid */
766-
res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_UUID, sb->s_uuid.b,
767+
res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_UUID, uuid.b,
767768
UUID_SIZE);
768769
if (res == UUID_SIZE)
769-
return true;
770+
goto set_uuid;
770771

771772
if (res != -ENODATA)
772773
goto fail;
@@ -794,17 +795,20 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
794795
}
795796

796797
/* Generate overlay instance uuid */
797-
uuid_gen(&sb->s_uuid);
798+
uuid_gen(&uuid);
798799

799800
/* Try to store persistent uuid */
800801
set = true;
801-
res = ovl_setxattr(ofs, upperpath->dentry, OVL_XATTR_UUID, sb->s_uuid.b,
802+
res = ovl_setxattr(ofs, upperpath->dentry, OVL_XATTR_UUID, uuid.b,
802803
UUID_SIZE);
803-
if (res == 0)
804-
return true;
804+
if (res)
805+
goto fail;
806+
807+
set_uuid:
808+
super_set_uuid(sb, uuid.b, sizeof(uuid));
809+
return true;
805810

806811
fail:
807-
memset(sb->s_uuid.b, 0, UUID_SIZE);
808812
ofs->config.uuid = OVL_UUID_NULL;
809813
pr_warn("failed to %s uuid (%pd2, err=%i); falling back to uuid=null.\n",
810814
set ? "set" : "get", upperpath->dentry, res);

fs/ubifs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
22452245
goto out_umount;
22462246
}
22472247

2248-
import_uuid(&sb->s_uuid, c->uuid);
2248+
super_set_uuid(sb, c->uuid, sizeof(c->uuid));
22492249

22502250
mutex_unlock(&c->umount_mutex);
22512251
return 0;

0 commit comments

Comments
 (0)