Skip to content

Commit 0f1a876

Browse files
committed
Merge tag 'vfs-6.9.uuid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
Pull vfs uuid updates from Christian Brauner: "This adds two new ioctl()s for getting the filesystem uuid and retrieving the sysfs path based on the path of a mounted filesystem. Getting the filesystem uuid has been implemented in filesystem specific code for a while it's now lifted as a generic ioctl" * tag 'vfs-6.9.uuid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: 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()
2 parents 910202f + 01edea1 commit 0f1a876

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
@@ -774,13 +774,14 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
774774
const struct path *upperpath)
775775
{
776776
bool set = false;
777+
uuid_t uuid;
777778
int res;
778779

779780
/* Try to load existing persistent uuid */
780-
res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_UUID, sb->s_uuid.b,
781+
res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_UUID, uuid.b,
781782
UUID_SIZE);
782783
if (res == UUID_SIZE)
783-
return true;
784+
goto set_uuid;
784785

785786
if (res != -ENODATA)
786787
goto fail;
@@ -808,17 +809,20 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
808809
}
809810

810811
/* Generate overlay instance uuid */
811-
uuid_gen(&sb->s_uuid);
812+
uuid_gen(&uuid);
812813

813814
/* Try to store persistent uuid */
814815
set = true;
815-
res = ovl_setxattr(ofs, upperpath->dentry, OVL_XATTR_UUID, sb->s_uuid.b,
816+
res = ovl_setxattr(ofs, upperpath->dentry, OVL_XATTR_UUID, uuid.b,
816817
UUID_SIZE);
817-
if (res == 0)
818-
return true;
818+
if (res)
819+
goto fail;
820+
821+
set_uuid:
822+
super_set_uuid(sb, uuid.b, sizeof(uuid));
823+
return true;
819824

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

fs/ubifs/super.c

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

2249-
import_uuid(&sb->s_uuid, c->uuid);
2249+
super_set_uuid(sb, c->uuid, sizeof(c->uuid));
22502250

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

0 commit comments

Comments
 (0)