Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

btrfs: implement shutdown ioctl

The shutdown ioctl should follow the XFS one, which use magic number 'X',
and ioctl number 125, with a uint32 as flags.

For now btrfs don't distinguish DEFAULT and LOGFLUSH flags (just like
f2fs), both will freeze the fs first (implies committing the current
transaction), setting the SHUTDOWN flag and finally thaw the fs.

For NOLOGFLUSH flag, the freeze/thaw part is skipped thus the current
transaction is aborted.

The new shutdown ioctl is hidden behind experimental features for more
testing.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Anand Jain <asj@kernel.org>
Tested-by: Anand Jain <asj@kernel.org>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>

authored by

Qu Wenruo and committed by
David Sterba
6b1ac78d 9b283945

+50
+41
fs/btrfs/ioctl.c
··· 5223 5223 return 0; 5224 5224 } 5225 5225 5226 + #ifdef CONFIG_BTRFS_EXPERIMENTAL 5227 + static int btrfs_ioctl_shutdown(struct btrfs_fs_info *fs_info, unsigned long arg) 5228 + { 5229 + int ret = 0; 5230 + u32 flags; 5231 + 5232 + if (!capable(CAP_SYS_ADMIN)) 5233 + return -EPERM; 5234 + 5235 + if (get_user(flags, (u32 __user *)arg)) 5236 + return -EFAULT; 5237 + 5238 + if (flags >= BTRFS_SHUTDOWN_FLAGS_LAST) 5239 + return -EINVAL; 5240 + 5241 + if (btrfs_is_shutdown(fs_info)) 5242 + return 0; 5243 + 5244 + switch (flags) { 5245 + case BTRFS_SHUTDOWN_FLAGS_LOGFLUSH: 5246 + case BTRFS_SHUTDOWN_FLAGS_DEFAULT: 5247 + ret = freeze_super(fs_info->sb, FREEZE_HOLDER_KERNEL, NULL); 5248 + if (ret) 5249 + return ret; 5250 + btrfs_force_shutdown(fs_info); 5251 + ret = thaw_super(fs_info->sb, FREEZE_HOLDER_KERNEL, NULL); 5252 + if (ret) 5253 + return ret; 5254 + break; 5255 + case BTRFS_SHUTDOWN_FLAGS_NOLOGFLUSH: 5256 + btrfs_force_shutdown(fs_info); 5257 + break; 5258 + } 5259 + return ret; 5260 + } 5261 + #endif 5262 + 5226 5263 long btrfs_ioctl(struct file *file, unsigned int 5227 5264 cmd, unsigned long arg) 5228 5265 { ··· 5415 5378 #endif 5416 5379 case BTRFS_IOC_SUBVOL_SYNC_WAIT: 5417 5380 return btrfs_ioctl_subvol_sync(fs_info, argp); 5381 + #ifdef CONFIG_BTRFS_EXPERIMENTAL 5382 + case BTRFS_IOC_SHUTDOWN: 5383 + return btrfs_ioctl_shutdown(fs_info, arg); 5384 + #endif 5418 5385 } 5419 5386 5420 5387 return -ENOTTY;
+9
include/uapi/linux/btrfs.h
··· 1099 1099 BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, 1100 1100 }; 1101 1101 1102 + /* Flags for IOC_SHUTDOWN, must match XFS_FSOP_GOING_FLAGS_* flags. */ 1103 + #define BTRFS_SHUTDOWN_FLAGS_DEFAULT 0x0 1104 + #define BTRFS_SHUTDOWN_FLAGS_LOGFLUSH 0x1 1105 + #define BTRFS_SHUTDOWN_FLAGS_NOLOGFLUSH 0x2 1106 + #define BTRFS_SHUTDOWN_FLAGS_LAST 0x3 1107 + 1102 1108 #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ 1103 1109 struct btrfs_ioctl_vol_args) 1104 1110 #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ ··· 1225 1219 struct btrfs_ioctl_encoded_io_args) 1226 1220 #define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \ 1227 1221 struct btrfs_ioctl_subvol_wait) 1222 + 1223 + /* Shutdown ioctl should follow XFS's interfaces, thus not using btrfs magic. */ 1224 + #define BTRFS_IOC_SHUTDOWN _IOR('X', 125, __u32) 1228 1225 1229 1226 #ifdef __cplusplus 1230 1227 }