在 2025/7/4 15:55, Johannes Thumshirn 写道:
On 04.07.25 01:43, Qu Wenruo wrote:
long btrfs_ioctl(struct file *file, unsigned int
cmd, unsigned long arg)
{
@@ -5201,6 +5231,8 @@ long btrfs_ioctl(struct file *file, unsigned int
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
struct btrfs_root *root = BTRFS_I(inode)->root;
void __user *argp = (void __user *)arg;
+ /* If @arg is just an unsigned long value. */
+ unsigned long flags;
switch (cmd) {
case FS_IOC_GETVERSION:
@@ -5349,6 +5381,14 @@ long btrfs_ioctl(struct file *file, unsigned int
#endif
case BTRFS_IOC_SUBVOL_SYNC_WAIT:
return btrfs_ioctl_subvol_sync(fs_info, argp);
+#ifdef CONFIG_BTRFS_EXPERIMENTAL
+ case BTRFS_IOC_SHUTDOWN:
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+ if (get_user(flags, (__u32 __user *)arg))
+ return -EFAULT;
+ return btrfs_emergency_shutdown(fs_info, flags);
+#endif
With that you'll get buildbot complaints if CONFIG_BTRFS_EXPERIMENTAL=n
because flags is unused.
I'd probably put the get_user(flags, ...) into
btrfs_emergency_shutdown() to silence the compiler.
That sounds a lot better than all my alternatives (a dedicated {} block
to put @flags into, get_user() at the beginning of btrfs_ioctl())
Will go your path when merging the patches.
Thanks,
Qu