btrfs: go fs_holder_ops and add shutdown_bdev() callback
Subsystems (2)
cover btrfs: go fs_holder_ops and add shutdown_bdev() callback
This series is relying on another series here:
https://lore.kernel.org/linux-btrfs/[email protected]/
That above series prepare btrfs to use fs_holder_ops, and the first patch in this series is exactly making btrfs use that fs_holder_ops.
Then patch 2~4 implements the shutdown ioctl for btrfs.
For now the shutdown ioctl has no proper sync yet.
Patch 5 is the one affecting the generic fs_holder_ops and super_operations, that we need a shutdown_bdev() variant, which passes the bdev to the fs and let the fs to determine if they can continue operation or needs to shutdown.
AKA, the shutdown_bdev() variant is for multi-devices filesystems like btrfs and bcachefs.
And finally implement the shutdown_bdev() for btrfs, so that eventually generic/730 can properly pass.
Reason for RFC:
There are still test failures for shutdown group, mostly due to the fact that btrfs is not implementing the proper flags handling (e.g. currently the shutdown never sync the fs no matter what).
But I want to get some feedback about the new super_operations::shutdown_bdev() call back before committing too much.
Qu Wenruo (6):
btrfs: introduce a new fs state, EMERGENCY_SHUTDOWN
btrfs: reject file operations if in shutdown state
btrfs: reject delalloc ranges if the fs is shutdown
btrfs: implement shutdown ioctl
fs: introduce a shutdown_bdev super block operation
btrfs: implement shutdown_bdev super operation callback
fs/btrfs/file.c | 25 ++++++++++++++++++++++++- fs/btrfs/fs.h | 18 ++++++++++++++++++ fs/btrfs/inode.c | 14 +++++++++++++- fs/btrfs/ioctl.c | 21 +++++++++++++++++++++ fs/btrfs/messages.c | 1 + fs/btrfs/reflink.c | 3 +++ fs/btrfs/super.c | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 2 ++ fs/btrfs/volumes.h | 5 +++++ fs/super.c | 4 +++- include/linux/fs.h | 10 ++++++++++ include/uapi/linux/btrfs.h | 9 +++++++++ 12 files changed, 143 insertions(+), 3 deletions(-)
Signature · 1 line
2.49.0
RFC PATCH 1/6 btrfs: introduce a new fs state, EMERGENCY_SHUTDOWN
This is btrfs' equivalent of XFS_IOC_GOINGDOWN or EXT4_IOC_SHUTDOWN, after entering the emergency shutdown state, all operations will return error (-EIO), and can not be bring back to normal state until unmount.
We reuse the existing btrfs_handle_fs_error() function, which will mark the fs read-only and output an error message.
This allows us to handle put_super() callback as usual, as the fs is already marked as error and RO, thus we need no special handling.
The only extra thing is to set the EMERGENCY_SHUTDOWN flag to reject future operations with -EIO.
--- fs/btrfs/fs.h | 18 ++++++++++++++++++ fs/btrfs/messages.c | 1 + 2 files changed, 19 insertions(+)
fs/btrfs/fs.h +18 -0
@@ -29,6 +29,7 @@#include "extent-io-tree.h" #include "async-thread.h" #include "block-rsv.h" +#include "messages.h" struct inode ;struct super_block ;
@@ -120,6 +121,12 @@ enum {/* No more delayed iput can be queued. */ BTRFS_FS_STATE_NO_DELAYED_IPUT , +/* +* Emergency shutdown, a step further than trans aborted by rejecting +* all operations. +*/ +BTRFS_FS_STATE_EMERGENCY_SHUTDOWN , + BTRFS_FS_STATE_COUNT };
@@ -1100,6 +1107,17 @@ static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info) (unlikely (test_bit (BTRFS_FS_STATE_LOG_CLEANUP_ERROR , \ &(fs_info)->fs_state))) +static inline bool btrfs_is_shutdown (struct btrfs_fs_info *fs_info) +{ +return test_bit (BTRFS_FS_STATE_EMERGENCY_SHUTDOWN , &fs_info->fs_state); +} + +static inline void btrfs_shutdown (struct btrfs_fs_info *fs_info) +{ +btrfs_handle_fs_error (fs_info, -EIO ,"filesystem emergency shutdown" ); +set_bit (BTRFS_FS_STATE_EMERGENCY_SHUTDOWN , &fs_info->fs_state); +} +/* * We use folio flag owner_2 to indicate there is an ordered extent with * unfinished IO.
fs/btrfs/messages.c +1 -0
@@ -23,6 +23,7 @@ static const char fs_state_chars[] = { [BTRFS_FS_STATE_NO_DATA_CSUMS] = 'C', [BTRFS_FS_STATE_SKIP_META_CSUMS] = 'S', [BTRFS_FS_STATE_LOG_CLEANUP_ERROR] = 'L', + [BTRFS_FS_STATE_EMERGENCY_SHUTDOWN] = 'E', };static void btrfs_state_to_string (const struct btrfs_fs_info *info,char *buf)
Signature · 1 line
2.49.0
RFC PATCH 2/6 btrfs: reject file operations if in shutdown state
In reply to Qu WenruoThis includes the following callbacks of file_operations:
- read_iter()
- write_iter()
- mmap()
- open()
- remap_file_range()
- uring_cmd()
- splice_read()
This requires a small wrapper to do the extra shutdown check, then call the regular filemap_splice_read() function
This should reject most of the file operations on a shutdown btrfs.
The callback ioctl() is intentionally skipped, as ext4 doesn't do the shutdown check on ioctl() either, thus I believe there is some special require for ioctl() callback even if the fs is fully shutdown.
--- fs/btrfs/file.c | 25 ++++++++++++++++++++++++- fs/btrfs/ioctl.c | 3 +++ fs/btrfs/reflink.c | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-)
fs/btrfs/file.c +24 -1
@@ -1420,6 +1420,8 @@ ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,struct btrfs_inode *inode =BTRFS_I (file_inode (file));ssize_t num_written, num_sync; +if (unlikely (btrfs_is_shutdown (inode->root->fs_info))) +return -EIO ;/* * If the fs flips readonly due to some impossible error, although we * have opened a file as writable, we have to stop this write operation
@@ -1982,6 +1984,8 @@ static int btrfs_file_mmap(struct file *filp, struct vm_area_struct *vma) {struct address_space *mapping = filp->f_mapping; +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (file_inode (filp))))) +return -EIO ;if (!mapping->a_ops->read_folio)return -ENOEXEC ;
@@ -3041,6 +3045,9 @@ static long btrfs_fallocate(struct file *file, int mode,int blocksize =BTRFS_I (inode)->root->fs_info->sectorsize;int ret; +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (inode)))) +return -EIO ; +/* Do not allow fallocate in ZONED mode */ if (btrfs_is_zoned (inode_to_fs_info (inode)))return -EOPNOTSUPP ;
@@ -3732,6 +3739,9 @@ static int btrfs_file_open(struct inode *inode, struct file *filp) {int ret; +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (inode)))) +return -EIO ; + filp->f_mode |=FMODE_NOWAIT |FMODE_CAN_ODIRECT ; ret =fsverity_file_open (inode, filp);
@@ -3744,6 +3754,9 @@ static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to) {ssize_t ret =0 ; +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (file_inode (iocb->ki_filp))))) +return -EIO ; +if (iocb->ki_flags &IOCB_DIRECT ) { ret =btrfs_direct_read (iocb, to); if (ret < 0 || !iov_iter_count(to) ||
@@ -3754,10 +3767,20 @@ static ssize_t btrfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return filemap_read (iocb, to, ret); } +static ssize_t btrfs_file_splice_read (struct file *in,loff_t *ppos, +struct pipe_inode_info *pipe, +size_t len,unsigned int flags) +{ +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (file_inode (in))))) +return -EIO ; + +return filemap_splice_read (in, ppos, pipe, len, flags); +} +const struct file_operations btrfs_file_operations = { .llseek = btrfs_file_llseek, .read_iter = btrfs_file_read_iter, - .splice_read = filemap_splice_read, + .splice_read = btrfs_file_splice_read, .write_iter = btrfs_file_write_iter, .splice_write = iter_file_splice_write, .mmap = btrfs_file_mmap,
fs/btrfs/ioctl.c +3 -0
@@ -5067,6 +5067,9 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issuint btrfs_uring_cmd (struct io_uring_cmd *cmd,unsigned int issue_flags) { +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (file_inode (cmd->file))))) +return -EIO ; +switch (cmd->cmd_op) {case BTRFS_IOC_ENCODED_READ :#if defined(CONFIG_64BIT ) && defined(CONFIG_COMPAT )
fs/btrfs/reflink.c +3 -0
@@ -869,6 +869,9 @@ loff_t btrfs_remap_file_range(struct file *src_file, loff_t off,bool same_inode = dst_inode == src_inode;int ret; +if (unlikely (btrfs_is_shutdown (inode_to_fs_info (file_inode (src_file))))) +return -EIO ; +if (remap_flags & ~(REMAP_FILE_DEDUP |REMAP_FILE_ADVISORY ))return -EINVAL ;
Signature · 1 line
2.49.0
RFC PATCH 3/6 btrfs: reject delalloc ranges if the fs is shutdown
In reply to Qu WenruoIf the filesystem has dirty pages before the fs is shutdown, we should no longer write them back, instead should treat them as writeback error.
Handle such situation by marking all those delalloc range as error and let error handling path to clean them up.
For ranges that already have ordered extent created, let them continue the writeback, and at ordered io finish time the file extent item update will be rejected as the fs is already marked error.
--- fs/btrfs/inode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
fs/btrfs/inode.c +13 -1
@@ -862,6 +862,9 @@ static void compress_file_range(struct btrfs_work *work)int compress_type = fs_info->compress_type;int compress_level = fs_info->compress_level; +if (unlikely (btrfs_is_shutdown (fs_info))) + goto cleanup_and_bail_uncompressed; +inode_should_defrag (inode, start, end, end - start +1 ,SZ_16K );/*
@@ -1277,6 +1280,11 @@ static noinline int cow_file_range(struct btrfs_inode *inode,unsigned long page_ops;int ret =0 ; +if (unlikely (btrfs_is_shutdown (fs_info))) { + ret = -EIO ; + goto out_unlock; + } +if (btrfs_is_free_space_inode (inode)) { ret = -EINVAL ; goto out_unlock;
@@ -2027,7 +2035,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, {struct btrfs_fs_info *fs_info = inode->root->fs_info;struct btrfs_root *root = inode->root; -struct btrfs_path *path; +struct btrfs_path *path =NULL ;u64 cow_start = (u64)-1 ;/* * If not 0, represents the inclusive end of the last fallback_to_cow()
@@ -2047,6 +2055,10 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,*/ ASSERT (!btrfs_is_zoned (fs_info) ||btrfs_is_data_reloc_root (root)); +if (unlikely (btrfs_is_shutdown (fs_info))) { + ret = -EIO ; + goto error; + } path =btrfs_alloc_path ();if (!path) { ret = -ENOMEM ;
Signature · 1 line
2.49.0
RFC PATCH 4/6 btrfs: implement shutdown ioctl
In reply to Qu WenruoThe shutdown interface should all follow the XFS one, which use magic 'X', and ioctl number 125, with a u32 as flags.
For now btrfs doesn't follow the flags, as there is no traditional journal in btrfs (the log tree is to mostly speed up fsync).
--- fs/btrfs/ioctl.c | 18 ++++++++++++++++++ include/uapi/linux/btrfs.h | 9 +++++++++ 2 files changed, 27 insertions(+)
fs/btrfs/ioctl.c +18 -0
@@ -5213,6 +5213,16 @@ static int btrfs_ioctl_subvol_sync(struct btrfs_fs_info *fs_info, void __user *areturn 0 ; } +static int btrfs_emergency_shutdown (struct btrfs_fs_info *fs_info,u32 flags) +{ +if (flags >=BTRFS_SHUTDOWN_FLAGS_LAST ) +return -EINVAL ; + +/* For now, btrfs do not distinguish the different flags. */ +btrfs_shutdown (fs_info); +return 0 ; +} +long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -5368,6 +5378,14 @@ long btrfs_ioctl(struct file *file, unsigned int#endif case BTRFS_IOC_SUBVOL_SYNC_WAIT :return btrfs_ioctl_subvol_sync (fs_info, argp); +case BTRFS_IOC_SHUTDOWN : +u32 flags; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; +if (get_user (flags, (__u32 __user *)arg)) +return -EFAULT ; +return btrfs_emergency_shutdown (fs_info, flags); }return -ENOTTY ;
include/uapi/linux/btrfs.h +9 -0
@@ -1096,6 +1096,12 @@ enum btrfs_err_code { BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, }; +/* Flags for IOC_SHUTDOWN, should match XFS' flags. */ +#define BTRFS_SHUTDOWN_FLAGS_DEFAULT 0x0 +#define BTRFS_SHUTDOWN_FLAGS_LOGFLUSH 0x1 +#define BTRFS_SHUTDOWN_FLAGS_NOLOGFLUSH 0x2 +#define BTRFS_SHUTDOWN_FLAGS_LAST 0x3 +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -1217,6 +1223,9 @@ enum btrfs_err_code {#define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \ struct btrfs_ioctl_subvol_wait) +/* Shutdown ioctl should follow XFS's interfaces, thus not using btrfs magic. */ +#define BTRFS_IOC_SHUTDOWN _IOR('X', 125, __u32) + #ifdef __cplusplus }#endif
Signature · 1 line
2.49.0
kernel test robot
build botRe: [PATCH RFC 4/6] btrfs: implement shutdown ioctl
kernel test robot noticed the following build errors:
Hi Qu,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on kdave/for-next]
[also build test ERROR on brauner-vfs/vfs.all linus/master v6.16-rc2 next-20250620] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Qu-Wenruo/btrfs-introduce-a-new-fs-state-EMERGENCY_SHUTDOWN/20250620-134942 base: https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next patch link: https://lore.kernel.org/r/33a2119f23fd6ced841c619d5467e2e2e4d96cdc.1750397889.git.wqu%40suse.com patch subject: [PATCH RFC 4/6] btrfs: implement shutdown ioctl config: arc-randconfig-001-20250621 (https://download.01.org/0day-ci/archive/20250621/[email protected]/config) compiler: arc-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250621/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/btrfs/ioctl.c: In function 'btrfs_ioctl':
>> fs/btrfs/ioctl.c:5382:3: error: a label can only be part of a statement and a declaration is not a statement
u32 flags;
^~~vim +5382 fs/btrfs/ioctl.c
5225
5226 long btrfs_ioctl(struct file *file, unsigned int
5227 cmd, unsigned long arg)
5228 {
5229 struct inode *inode = file_inode(file);
5230 struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
5231 struct btrfs_root *root = BTRFS_I(inode)->root;
5232 void __user *argp = (void __user *)arg;
5233
5234 switch (cmd) {
5235 case FS_IOC_GETVERSION:
5236 return btrfs_ioctl_getversion(inode, argp);
5237 case FS_IOC_GETFSLABEL:
5238 return btrfs_ioctl_get_fslabel(fs_info, argp);
5239 case FS_IOC_SETFSLABEL:
5240 return btrfs_ioctl_set_fslabel(file, argp);
5241 case FITRIM:
5242 return btrfs_ioctl_fitrim(fs_info, argp);
5243 case BTRFS_IOC_SNAP_CREATE:
5244 return btrfs_ioctl_snap_create(file, argp, 0);
5245 case BTRFS_IOC_SNAP_CREATE_V2:
5246 return btrfs_ioctl_snap_create_v2(file, argp, 0);
5247 case BTRFS_IOC_SUBVOL_CREATE:
5248 return btrfs_ioctl_snap_create(file, argp, 1);
5249 case BTRFS_IOC_SUBVOL_CREATE_V2:
5250 return btrfs_ioctl_snap_create_v2(file, argp, 1);
5251 case BTRFS_IOC_SNAP_DESTROY:
5252 return btrfs_ioctl_snap_destroy(file, argp, false);
5253 case BTRFS_IOC_SNAP_DESTROY_V2:
5254 return btrfs_ioctl_snap_destroy(file, argp, true);
5255 case BTRFS_IOC_SUBVOL_GETFLAGS:
5256 return btrfs_ioctl_subvol_getflags(BTRFS_I(inode), argp);
5257 case BTRFS_IOC_SUBVOL_SETFLAGS:
5258 return btrfs_ioctl_subvol_setflags(file, argp);
5259 case BTRFS_IOC_DEFAULT_SUBVOL:
5260 return btrfs_ioctl_default_subvol(file, argp);
5261 case BTRFS_IOC_DEFRAG:
5262 return btrfs_ioctl_defrag(file, NULL);
5263 case BTRFS_IOC_DEFRAG_RANGE:
5264 return btrfs_ioctl_defrag(file, argp);
5265 case BTRFS_IOC_RESIZE:
5266 return btrfs_ioctl_resize(file, argp);
5267 case BTRFS_IOC_ADD_DEV:
5268 return btrfs_ioctl_add_dev(fs_info, argp);
5269 case BTRFS_IOC_RM_DEV:
5270 return btrfs_ioctl_rm_dev(file, argp);
5271 case BTRFS_IOC_RM_DEV_V2:
5272 return btrfs_ioctl_rm_dev_v2(file, argp);
5273 case BTRFS_IOC_FS_INFO:
5274 return btrfs_ioctl_fs_info(fs_info, argp);
5275 case BTRFS_IOC_DEV_INFO:
5276 return btrfs_ioctl_dev_info(fs_info, argp);
5277 case BTRFS_IOC_TREE_SEARCH:
5278 return btrfs_ioctl_tree_search(root, argp);
5279 case BTRFS_IOC_TREE_SEARCH_V2:
5280 return btrfs_ioctl_tree_search_v2(root, argp);
5281 case BTRFS_IOC_INO_LOOKUP:
5282 return btrfs_ioctl_ino_lookup(root, argp);
5283 case BTRFS_IOC_INO_PATHS:
5284 return btrfs_ioctl_ino_to_path(root, argp);
5285 case BTRFS_IOC_LOGICAL_INO:
5286 return btrfs_ioctl_logical_to_ino(fs_info, argp, 1);
5287 case BTRFS_IOC_LOGICAL_INO_V2:
5288 return btrfs_ioctl_logical_to_ino(fs_info, argp, 2);
5289 case BTRFS_IOC_SPACE_INFO:
5290 return btrfs_ioctl_space_info(fs_info, argp);
5291 case BTRFS_IOC_SYNC: {
5292 int ret;
5293
5294 ret = btrfs_start_delalloc_roots(fs_info, LONG_MAX, false);
5295 if (ret)
5296 return ret;
5297 ret = btrfs_sync_fs(inode->i_sb, 1);
5298 /*
5299 * There may be work for the cleaner kthread to do (subvolume
5300 * deletion, delayed iputs, defrag inodes, etc), so wake it up.
5301 */
5302 wake_up_process(fs_info->cleaner_kthread);
5303 return ret;
5304 }
5305 case BTRFS_IOC_START_SYNC:
5306 return btrfs_ioctl_start_sync(root, argp);
5307 case BTRFS_IOC_WAIT_SYNC:
5308 return btrfs_ioctl_wait_sync(fs_info, argp);
5309 case BTRFS_IOC_SCRUB:
5310 return btrfs_ioctl_scrub(file, argp);
5311 case BTRFS_IOC_SCRUB_CANCEL:
5312 return btrfs_ioctl_scrub_cancel(fs_info);
5313 case BTRFS_IOC_SCRUB_PROGRESS:
5314 return btrfs_ioctl_scrub_progress(fs_info, argp);
5315 case BTRFS_IOC_BALANCE_V2:
5316 return btrfs_ioctl_balance(file, argp);
5317 case BTRFS_IOC_BALANCE_CTL:
5318 return btrfs_ioctl_balance_ctl(fs_info, arg);
5319 case BTRFS_IOC_BALANCE_PROGRESS:
5320 return btrfs_ioctl_balance_progress(fs_info, argp);
5321 case BTRFS_IOC_SET_RECEIVED_SUBVOL:
5322 return btrfs_ioctl_set_received_subvol(file, argp);
5323 #ifdef CONFIG_64BIT
5324 case BTRFS_IOC_SET_RECEIVED_SUBVOL_32:
5325 return btrfs_ioctl_set_received_subvol_32(file, argp);
5326 #endif
5327 case BTRFS_IOC_SEND:
5328 return _btrfs_ioctl_send(root, argp, false);
5329 #if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
5330 case BTRFS_IOC_SEND_32:
5331 return _btrfs_ioctl_send(root, argp, true);
5332 #endif
5333 case BTRFS_IOC_GET_DEV_STATS:
5334 return btrfs_ioctl_get_dev_stats(fs_info, argp);
5335 case BTRFS_IOC_QUOTA_CTL:
5336 return btrfs_ioctl_quota_ctl(file, argp);
5337 case BTRFS_IOC_QGROUP_ASSIGN:
5338 return btrfs_ioctl_qgroup_assign(file, argp);
5339 case BTRFS_IOC_QGROUP_CREATE:
5340 return btrfs_ioctl_qgroup_create(file, argp);
5341 case BTRFS_IOC_QGROUP_LIMIT:
5342 return btrfs_ioctl_qgroup_limit(file, argp);
5343 case BTRFS_IOC_QUOTA_RESCAN:
5344 return btrfs_ioctl_quota_rescan(file, argp);
5345 case BTRFS_IOC_QUOTA_RESCAN_STATUS:
5346 return btrfs_ioctl_quota_rescan_status(fs_info, argp);
5347 case BTRFS_IOC_QUOTA_RESCAN_WAIT:
5348 return btrfs_ioctl_quota_rescan_wait(fs_info);
5349 case BTRFS_IOC_DEV_REPLACE:
5350 return btrfs_ioctl_dev_replace(fs_info, argp);
5351 case BTRFS_IOC_GET_SUPPORTED_FEATURES:
5352 return btrfs_ioctl_get_supported_features(argp);
5353 case BTRFS_IOC_GET_FEATURES:
5354 return btrfs_ioctl_get_features(fs_info, argp);
5355 case BTRFS_IOC_SET_FEATURES:
5356 return btrfs_ioctl_set_features(file, argp);
5357 case BTRFS_IOC_GET_SUBVOL_INFO:
5358 return btrfs_ioctl_get_subvol_info(inode, argp);
5359 case BTRFS_IOC_GET_SUBVOL_ROOTREF:
5360 return btrfs_ioctl_get_subvol_rootref(root, argp);
5361 case BTRFS_IOC_INO_LOOKUP_USER:
5362 return btrfs_ioctl_ino_lookup_user(file, argp);
5363 case FS_IOC_ENABLE_VERITY:
5364 return fsverity_ioctl_enable(file, (const void __user *)argp);
5365 case FS_IOC_MEASURE_VERITY:
5366 return fsverity_ioctl_measure(file, argp);
5367 case FS_IOC_READ_VERITY_METADATA:
5368 return fsverity_ioctl_read_metadata(file, argp);
5369 case BTRFS_IOC_ENCODED_READ:
5370 return btrfs_ioctl_encoded_read(file, argp, false);
5371 case BTRFS_IOC_ENCODED_WRITE:
5372 return btrfs_ioctl_encoded_write(file, argp, false);
5373 #if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
5374 case BTRFS_IOC_ENCODED_READ_32:
5375 return btrfs_ioctl_encoded_read(file, argp, true);
5376 case BTRFS_IOC_ENCODED_WRITE_32:
5377 return btrfs_ioctl_encoded_write(file, argp, true);
5378 #endif
5379 case BTRFS_IOC_SUBVOL_SYNC_WAIT:
5380 return btrfs_ioctl_subvol_sync(fs_info, argp);
5381 case BTRFS_IOC_SHUTDOWN:
> 5382 u32 flags;
5383
5384 if (!capable(CAP_SYS_ADMIN))
5385 return -EPERM;
5386 if (get_user(flags, (__u32 __user *)arg))
5387 return -EFAULT;
5388 return btrfs_emergency_shutdown(fs_info, flags);
5389 }
5390
5391 return -ENOTTY;
5392 }
5393
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH 5/6 fs: introduce a shutdown_bdev super block operation
In reply to Qu WenruoCurrently we already have the super_operations::shutdown() callback, which is called when the block device of a filesystem is marked dead.
However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new super_operation::shutdown_bdev() callback, for mutli-device filesystems like btrfs and bcachefs.
For now the only user is fs_holder_ops::mark_dead(), which will call shutdown_bdev() if supported.
If not supported then fallback to the original shutdown() callback.
Btrfs is going to add the usage of shutdown_bdev() soon.
--- fs/super.c | 4 +++- include/linux/fs.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
fs/super.c +3 -1
@@ -1461,7 +1461,9 @@ static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)sync_filesystem (sb);shrink_dcache_sb (sb);evict_inodes (sb); -if (sb->s_op->shutdown) +if (sb->s_op->shutdown_bdev) + sb->s_op->shutdown_bdev (sb, bdev); +else if (sb->s_op->shutdown) sb->s_op->shutdown (sb);super_unlock_shared (sb);
include/linux/fs.h +10 -0
@@ -2363,7 +2363,17 @@ struct super_operations { struct shrink_control *);long (*free_cached_objects)(struct super_block *,struct shrink_control *); +/* +* For single-device filesystems. Called when the only block device is +* marked dead. +*/ void (*shutdown)(struct super_block *sb); + +/* +* For multi-device filesystems. Called when any of its block device is +* marked dead. +*/ +void (*shutdown_bdev)(struct super_block *sb,struct block_device *bdev); };/*
Signature · 1 line
2.49.0
Jan Kara
reviewerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 11 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.
Quoted 7 lines
For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.Btrfs is going to add the usage of
shutdown_bdev()soon.Signed-off-by Qu Wenruo <[email protected]>
Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
Honza
Quoted 45 lines
--- fs/super.c | 4 +++- include/linux/fs.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)fs/super.c +3
-1@@ -1461,7 +1461,9 @@ static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)sync_filesystem (sb);shrink_dcache_sb (sb);evict_inodes (sb); -if (sb->s_op->shutdown) +if (sb->s_op->shutdown_bdev) + sb->s_op->shutdown_bdev (sb, bdev); +else if (sb->s_op->shutdown) sb->s_op->shutdown (sb);super_unlock_shared (sb);include/linux/fs.h +10
-0@@ -2363,7 +2363,17 @@ struct super_operations { struct shrink_control *);long (*free_cached_objects)(struct super_block *,struct shrink_control *); +/* +* For single-device filesystems. Called when the only block device is +* marked dead. +*/ void (*shutdown)(struct super_block *sb); + +/* +* For multi-device filesystems. Called when any of its block device is +* marked dead. +*/ +void (*shutdown_bdev)(struct super_block *sb,struct block_device *bdev); };/* Signature · 1 line
2.49.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 18 lines · Jan Kara
Quoted 17 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.Btrfs is going to add the usage of
shutdown_bdev()soon.
Quoted 7 lines
Quoted 1 line
Signed-off-by Qu Wenruo <[email protected]>Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
Honza
That makes sense.
Will add the new bdev parameters instead.
Thanks,
Qu
Quoted 46 lines
Quoted 46 lines
--- fs/super.c | 4 +++- include/linux/fs.h | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)fs/super.c +3
-1@@ -1461,7 +1461,9 @@ static void fs_bdev_mark_dead(struct block_device *bdev, bool surprise)sync_filesystem (sb);shrink_dcache_sb (sb);evict_inodes (sb); -if (sb->s_op->shutdown) +if (sb->s_op->shutdown_bdev) + sb->s_op->shutdown_bdev (sb, bdev); +else if (sb->s_op->shutdown) sb->s_op->shutdown (sb);super_unlock_shared (sb);include/linux/fs.h +10
-0@@ -2363,7 +2363,17 @@ struct super_operations { struct shrink_control *);long (*free_cached_objects)(struct super_block *,struct shrink_control *); +/* +* For single-device filesystems. Called when the only block device is +* marked dead. +*/ void (*shutdown)(struct super_block *sb); + +/* +* For multi-device filesystems. Called when any of its block device is +* marked dead. +*/ +void (*shutdown_bdev)(struct super_block *sb,struct block_device *bdev); };/* Signature · 1 line
2.49.0
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
In reply to Jan KaraQuoted 16 lines · Jan Kara
Quoted 15 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.
Quoted 7 lines
Quoted 3 lines
Btrfs is going to add the usage of
shutdown_bdev()soon.Signed-off-by Qu Wenruo <[email protected]>Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
I don't really think that's a good idea as-is. The current ->shutdown callback is called ->shutdown because it is expected to shut the file system down. That's why I suggested to Qu to add a new devloss callback, to describe that a device is lost. In a file system with built-in redundancy that is not a shutdown. So Qu, please add a devloss callback. And maybe if we have no other good use for the shutdown callback we can remove it in favor of the devloss one. But having something named shutdown take the block device and not always shutting the file system down is highly confusing.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 25 lines · Christoph Hellwig
Quoted 16 lines · Jan Kara
Quoted 15 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.Quoted 7 lines
Quoted 3 lines
Btrfs is going to add the usage of
shutdown_bdev()soon.Signed-off-by Qu Wenruo <[email protected]>Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
Quoted 9 lines
I don't really think that's a good idea as-is. The current ->shutdown callback is called ->shutdown because it is expected to shut the file system down. That's why I suggested to Qu to add a new devloss callback, to describe that a device is lost. In a file system with built-in redundancy that is not a shutdown. So Qu, please add a devloss callback. And maybe if we have no other good use for the shutdown callback we can remove it in favor of the devloss one. But having something named shutdown take the block device and not always shutting the file system down is highly confusing.
OK, I got the point of the name "devloss" now, didn't notice the naming itself is important at that timing.
And in fact a new callback is much easier on me, no need to modify the code of other fses.
@Jan, would this be acceptable for a new devloss() callback instead?
Thanks,
Qu
Jan Kara
reviewerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 36 lines · Qu Wenruo
Quoted 25 lines · Christoph Hellwig
Quoted 16 lines · Jan Kara
Quoted 15 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.Quoted 7 lines
Quoted 3 lines
Btrfs is going to add the usage of
shutdown_bdev()soon.Signed-off-by Qu Wenruo <[email protected]>Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
Quoted 9 lines
I don't really think that's a good idea as-is. The current ->shutdown callback is called ->shutdown because it is expected to shut the file system down. That's why I suggested to Qu to add a new devloss callback, to describe that a device is lost. In a file system with built-in redundancy that is not a shutdown. So Qu, please add a devloss callback. And maybe if we have no other good use for the shutdown callback we can remove it in favor of the devloss one. But having something named shutdown take the block device and not always shutting the file system down is highly confusing.
Quoted 7 lines
OK, I got the point of the name "devloss" now, didn't notice the naming itself is important at that timing.
And in fact a new callback is much easier on me, no need to modify the code of other fses.
@Jan, would this be acceptable for a new
devloss()callback instead?
OK, now I understand the rationale better as well. Yes, devloss() callback makes sense to me. It just looked weird to have two types shutdown callback. And yes, eventually we might provide a generic handler for devloss callback that will just shut the filesystem down and then we can remove the shutdown callback but that can happen later.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
In reply to Christoph HellwigQuoted 25 lines · Christoph Hellwig
Quoted 16 lines · Jan Kara
Quoted 15 lines · Qu Wenruo
Currently we already have the
super_operations::shutdown()callback, which is called when the block device of a filesystem is marked dead.However this is mostly for single(ish) block device filesystems.
For multi-device filesystems, they may afford a missing device, thus may continue work without fully shutdown the filesystem.
So add a new
super_operation::shutdown_bdev()callback, for mutli-device filesystems like btrfs and bcachefs.For now the only user is
fs_holder_ops::mark_dead(), which will callshutdown_bdev()if supported.
If not supported then fallback to the originalshutdown()callback.Quoted 7 lines
Quoted 3 lines
Btrfs is going to add the usage of
shutdown_bdev()soon.Signed-off-by Qu Wenruo <[email protected]>Thanks for the patch. I think that we could actually add 'bdev' that triggered shutdown among arguments ->shutdown takes instead of introducing a new handler.
Quoted 9 lines
I don't really think that's a good idea as-is. The current ->shutdown callback is called ->shutdown because it is expected to shut the file system down. That's why I suggested to Qu to add a new devloss callback, to describe that a device is lost. In a file system with built-in redundancy that is not a shutdown. So Qu, please add a devloss callback. And maybe if we have no other good use for the shutdown callback we can remove it in favor of the devloss one. But having something named shutdown take the block device and not always shutting the file system down is highly confusing.
I think we should add:
include/linux/fs.h +1 -0
@@ -2368,6 +2368,7 @@ struct super_operations {long (*free_cached_objects)(struct super_block *,struct shrink_control *);void (*shutdown)(struct super_block *sb); +void (*drop_bdev)(struct super_block *sb,struct block_device *bdev/* , unsigned int flags/reason maybe too ? */ ); };
You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 6 lines · Christian Brauner
void (*shutdown)(struct super_block *sb);+ void (*drop_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);
};You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Drop is weird word for what is happening here, and if it wasn't for the context in this thread I'd expect it to be about refcounting in Linux.
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 8 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
void (*shutdown)(struct super_block *sb);+ void (*drop_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);
};You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Quoted 6 lines
Drop is weird word for what is happening here, and if it wasn't for the context in this thread I'd expect it to be about refcounting in Linux.
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
What about a more common used term, mark_dead()?
It's already used in blk_holder_ops, and I'd say it's more straighforward to me, compared to shutdown()/goingdown().
Thanks,
Qu
Christian Brauner
maintainerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 14 lines · Qu Wenruo
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
void (*shutdown)(struct super_block *sb);+ void (*drop_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);
};You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Drop is weird word for what is happening here, and if it wasn't for the context in this thread I'd expect it to be about refcounting in Linux.
Quoted 8 lines
Quoted 3 lines
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
What about a more common used term,
mark_dead()?It's already used in
blk_holder_ops, and I'd say it's more straighforward to me, compared to shutdown()/goingdown().
But it's not about the superblock going down necessarily. It's about the device going away for whatever reason:
void (*yank_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */); void (*pull_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */); void (*unplug_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */); void (*remove_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */);
On a single device superblock unplugging that device would obviously cause an actual shutdown. On multi-device superblocks it doesn't always.
(That brings me to another thought. Is there a use-case for knowing in advance whether removing a device would shut down the superblock? Because then the ability to probe whether a device can be safely removed or an option to only remove the device if it can be removed without killing the superblock would be a natural extension.)
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 24 lines · Christian Brauner
Quoted 14 lines · Qu Wenruo
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
void (*shutdown)(struct super_block *sb); + void (*drop_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */); };You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Drop is weird word for what is happening here, and if it wasn't for the context in this thread I'd expect it to be about refcounting in Linux.
Quoted 8 lines
Quoted 3 lines
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
What about a more common used term,
mark_dead()?It's already used in
blk_holder_ops, and I'd say it's more straighforward to me, compared to shutdown()/goingdown().
Quoted 7 lines
But it's not about the superblock going down necessarily. It's about the device going away for whatever reason:
void (*yank_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*pull_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*unplug_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*remove_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);
All sound good to me, although the last one sounds better.
Quoted 6 lines
On a single device superblock unplugging that device would obviously cause an actual shutdown. On multi-device superblocks it doesn't always.
(That brings me to another thought. Is there a use-case for knowing in advance whether removing a device would shut down the superblock?
Maybe another interface like can_remove_bdev()?
It's not hard for btrfs to provide it, we already have a check function btrfs_check_rw_degradable() to do that.
Although I'd say, that will be something way down the road.
We even don't have a proper way to let end user configure the device loss behavior. E.g. some end users may prefer a full shutdown to be extra cautious, other than continue degraded.
Thanks,
Qu
Quoted 3 lines
Because then the ability to probe whether a device can be safely removed or an option to only remove the device if it can be removed without killing the superblock would be a natural extension.)
Christian Brauner
maintainerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 44 lines · Qu Wenruo
Quoted 24 lines · Christian Brauner
Quoted 14 lines · Qu Wenruo
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Christian Brauner
void (*shutdown)(struct super_block *sb); + void (*drop_bdev)(struct super_block *sb, struct block_device *bdev /* , unsigned int flags/reason maybe too ? */); };You might want to drop a block device independent of whether the device was somehow lost. So I find that a bit more flexible.
Drop is weird word for what is happening here, and if it wasn't for the context in this thread I'd expect it to be about refcounting in Linux.
Quoted 8 lines
Quoted 3 lines
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
What about a more common used term,
mark_dead()?It's already used in
blk_holder_ops, and I'd say it's more straighforward to me, compared to shutdown()/goingdown().Quoted 7 lines
But it's not about the superblock going down necessarily. It's about the device going away for whatever reason:
void (*yank_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*pull_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*unplug_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*remove_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);All sound good to me, although the last one sounds better.
Quoted 6 lines
On a single device superblock unplugging that device would obviously cause an actual shutdown. On multi-device superblocks it doesn't always.
(That brings me to another thought. Is there a use-case for knowing in advance whether removing a device would shut down the superblock?
Quoted 6 lines
Maybe another interface like
can_remove_bdev()?It's not hard for btrfs to provide it, we already have a check function
btrfs_check_rw_degradable()to do that.Although I'd say, that will be something way down the road.
Yes, for sure. I think long-term we should hoist at least the bare infrastructure for multi-device filesystem management into the VFS. Or we should at least explore whether that's feasible and if it's overall advantageous to maintenance and standardization. We've already done a bit of that and imho it's now a lot easier to reason about the basics already.
Quoted 5 lines
We even don't have a proper way to let end user configure the device loss behavior.
E.g. some end users may prefer a full shutdown to be extra cautious, other than continue degraded.
Right.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
在 2025/6/24 18:43, Christian Brauner 写道:
[...]
Quoted 7 lines
Quoted 4 lines
It's not hard for btrfs to provide it, we already have a check function
btrfs_check_rw_degradable()to do that.Although I'd say, that will be something way down the road.
Yes, for sure. I think long-term we should hoist at least the bare infrastructure for multi-device filesystem management into the VFS.
Just want to mention that, "multi-device filesystem" already includes fses with external journal.
Thus the new callback may be a good chance for those mature fses to explore some corner case availability improvement, e.g. the loss of the external journal device while there is no live journal on it. (I have to admin it's super niche, and live-migration to internal journal may be way more complex than my uneducated guess)
Thanks,
Qu
Quoted 12 lines
Or we should at least explore whether that's feasible and if it's overall advantageous to maintenance and standardization. We've already done a bit of that and imho it's now a lot easier to reason about the basics already.
Quoted 5 lines
We even don't have a proper way to let end user configure the device loss behavior.
E.g. some end users may prefer a full shutdown to be extra cautious, other than continue degraded.Right.
Christian Brauner
maintainerRe: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 7 lines · Qu Wenruo
在 2025/6/24 18:43, Christian Brauner 写道:
[...]Quoted 3 lines
Quoted 3 lines
It's not hard for btrfs to provide it, we already have a check function
btrfs_check_rw_degradable()to do that.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Although I'd say, that will be something way down the road.
Yes, for sure. I think long-term we should hoist at least the bare infrastructure for multi-device filesystem management into the VFS.
Just want to mention that, "multi-device filesystem" already includes fses with external journal.
Yes, that's what I meant below by "We've already done a bit of that". It's now possible to actually reach all devices associted with a filesystem from the block layer. It works for xfs and ext4 with journal fileystems. So for example, you can freeze the log device and the main device as the block layer is now able to find both and the fs stays frozen until both have been unfrozen. This wasn't possible before the rework we did.
Now follows a tiny rant not targeted at you specifically but something that still bugs me in general:
We had worked on extending this to btrfs so that it's all integrated properly with the block layer. And we heard long promises of how you would make that switch happen but refused us to let us make that switch. So now it's 2 years later and zero happend in that area.
That also means block device freezing on btrfs is broken. If you freeze a block device used by btrfs via the dm (even though unlikely) layer you freeze the block device without btrfs being informed about that.
It also means that block device removal is likely a bit yanky because btrfs won't be notified when any device other than the main device is suddenly yanked. You probably have logic there but the block layer can easily inform the filesystem about such an event nowadays and let it take appropriate action.
And fwiw, you also don't restrict writing to mounted block devices. That's another thing you blocked us from implementing even though we sent the changes for that already and so we disabled that in ead622674df5 ("btrfs: Do not restrict writes to btrfs devices"). So you're also still vulnerable to that stuff.
Quoted 4 lines
Thus the new callback may be a good chance for those mature fses to explore some corner case availability improvement, e.g. the loss of the external journal device while there is no live journal on it.
Already handled for xfs and ext4 cleanly since our rework iiuc.
Quoted 19 lines
(I have to admin it's super niche, and live-migration to internal journal may be way more complex than my uneducated guess)
Thanks,
QuQuoted 12 lines
Or we should at least explore whether that's feasible and if it's overall advantageous to maintenance and standardization. We've already done a bit of that and imho it's now a lot easier to reason about the basics already.
Quoted 5 lines
We even don't have a proper way to let end user configure the device loss behavior.
E.g. some end users may prefer a full shutdown to be extra cautious, other than continue degraded.Right.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
Quoted 24 lines · Christian Brauner
Quoted 7 lines · Qu Wenruo
在 2025/6/24 18:43, Christian Brauner 写道:
[...]Quoted 3 lines
Quoted 3 lines
It's not hard for btrfs to provide it, we already have a check function
btrfs_check_rw_degradable()to do that.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Although I'd say, that will be something way down the road.
Yes, for sure. I think long-term we should hoist at least the bare infrastructure for multi-device filesystem management into the VFS.
Just want to mention that, "multi-device filesystem" already includes fses with external journal.
Yes, that's what I meant below by "We've already done a bit of that". It's now possible to actually reach all devices associted with a filesystem from the block layer. It works for xfs and ext4 with journal fileystems. So for example, you can freeze the log device and the main device as the block layer is now able to find both and the fs stays frozen until both have been unfrozen. This wasn't possible before the rework we did.
Quoted 7 lines
Now follows a tiny rant not targeted at you specifically but something that still bugs me in general:
We had worked on extending this to btrfs so that it's all integrated properly with the block layer. And we heard long promises of how you would make that switch happen but refused us to let us make that switch. So now it's 2 years later and zero happend in that area.
I believe we (the btrfs community) are not intentionally rejecting this, bad luck and lack of review bandwidth is involved, as at that time we're focusing on migrating to the new fsconfig mount interface.
That delayed review of the original patchset from Christoph, then the old series no longer applies due to the fsconfig change, until Johannes revived the series for the first time.
Then even more (minor) conflicts with recent mount ro/rw mount fixes, and although Johannes tried his best to refresh the series, those conflicts eventually resulted test failures.
And I wasn't even following all those updates, until one day I'm eventually freed from btrfs large folio support, and had time to attack the long failure generic/730 due to lack of shutdown support.
Then I was dragged into the rabbit hole and finally we're here.
Also I have to admit, at least me do not have much experience in the block/VFS field, and sometimes we still assume the existing infrastructure is still mostly targeting single-ish block device filesystems, but it's not true anymore.
We're improving this, and got quite some help from Christoph, e.g. he contributed the btrfs bio layer to do all the bio split/chain inside btrfs.
I hope this remove_bdev() call back can be a good start point to bridge the btrfs and block community closer.
Quoted 4 lines
That also means block device freezing on btrfs is broken. If you freeze a block device used by btrfs via the dm (even though unlikely) layer you freeze the block device without btrfs being informed about that.
Yes, you're totally right and I also believe that may be the reason of btrfs corruption after hibernation/suspension.
Quoted 6 lines
It also means that block device removal is likely a bit yanky because btrfs won't be notified when any device other than the main device is suddenly yanked. You probably have logic there but the block layer can easily inform the filesystem about such an event nowadays and let it take appropriate action.
Yep, btrfs doesn't handling removal of devices at runtime at all, but still tries to do IO on that device, only saved by the extra mirrors.
Meaning unless a user is monitoring the dmesg, one won't notice the problem, which a huge degradation of availability happening silently.
Quoted 6 lines
And fwiw, you also don't restrict writing to mounted block devices. That's another thing you blocked us from implementing even though we sent the changes for that already and so we disabled that in
ead622674df5("btrfs: Do not restrict writes to btrfs devices"). So you're also still vulnerable to that stuff.
Oh, that's something new and let me explore this after all the remove_bdev() callback thing.
Thanks,
Qu
Quoted 28 lines
Quoted 5 lines
Thus the new callback may be a good chance for those mature fses to explore some corner case availability improvement, e.g. the loss of the external journal device while there is no live journal on it.
Already handled for xfs and ext4 cleanly since our rework iiuc.
Quoted 19 lines
(I have to admin it's super niche, and live-migration to internal journal may be way more complex than my uneducated guess)
Thanks,
QuQuoted 12 lines
Or we should at least explore whether that's feasible and if it's overall advantageous to maintenance and standardization. We've already done a bit of that and imho it's now a lot easier to reason about the basics already.
Quoted 5 lines
We even don't have a proper way to let end user configure the device loss behavior.
E.g. some end users may prefer a full shutdown to be extra cautious, other than continue degraded.Right.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
In reply to Qu WenruoQuoted 5 lines · Qu Wenruo
Thus the new callback may be a good chance for those mature fses to explore some corner case availability improvement, e.g. the loss of the external journal device while there is no live journal on it.
(I have to admin it's super niche, and live-migration to internal journal may be way more complex than my uneducated guess)
I don't know know of a file system that has a log/journal where is isn't integral part of the metadata write architecture.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
void (*yank_bdev)(struct
super_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*pull_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*unplug_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */); void (*remove_bdev)(structsuper_block*sb, structblock_device*bdev /* , unsigned int flags/reason maybe too ? */);
Out of these remove_bdev is the most sane.
Quoted 5 lines
(That brings me to another thought. Is there a use-case for knowing in advance whether removing a device would shut down the superblock? Because then the ability to probe whether a device can be safely removed or an option to only remove the device if it can be removed without killing the superblock would be a natural extension.)
I don't think there is a use for it at this (holder_ops) level. If the device driver notifies about a device going to away we're already committed. It makes some sense at the file system administration level, but you want to tie that much deepter into the file system, i.e. you'd actually usually want to migrate all data off the device first.
Re: [PATCH RFC 5/6] fs: introduce a shutdown_bdev super block operation
In reply to Qu WenruoQuoted 5 lines · Qu Wenruo
Quoted 3 lines
When the VFS/libfs does an upcall into the file system to notify it that a device is gone that's pretty much a device loss. I'm not married to the exact name, but drop seems like a pretty bad choice.
What about a more common used term,
mark_dead()?
That's even less generic than devloss.
RFC PATCH 6/6 btrfs: implement shutdown_bdev super operation callback
In reply to Qu WenruoFor this callback, btrfs will:
- Go degraded if the fs can still maintain RW operations
- Shutdown if the fs can not maintain RW operations
I know the shutdown can be a little overkilled, if one has a RAID1 metadata and RAID0 data, in that case one can still read data with 50% rate to got some good data.
But it can also be as bad as the only device went missing for a single device btrfs.
So here we go safe other than sorry when handling missing device.
--- fs/btrfs/super.c | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.c | 2 ++ fs/btrfs/volumes.h | 5 +++++ 3 files changed, 41 insertions(+)
fs/btrfs/super.c +34 -0
@@ -2397,6 +2397,39 @@ static long btrfs_free_cached_objects(struct super_block *sb, struct shrink_contreturn 0 ; } +static void btrfs_shutdown_bdev (struct super_block *sb,struct block_device *bdev) +{ +struct btrfs_fs_info *fs_info =btrfs_sb (sb); +struct btrfs_device *device; +struct btrfs_dev_lookup_args lookup_args = { .devt = bdev->bd_dev }; + +mutex_lock (&fs_info->fs_devices->device_list_mutex); + device =btrfs_find_device (fs_info->fs_devices, &lookup_args); +mutex_unlock (&fs_info->fs_devices->device_list_mutex); +if (!device) { +btrfs_warn (fs_info,"unable to find btrfs device for block device '%pg'" , + bdev); +return ; + } +set_bit (BTRFS_DEV_STATE_MISSING , &device->dev_state); + device->fs_devices->missing_devices++; +if (test_and_clear_bit (BTRFS_DEV_STATE_WRITEABLE , &device->dev_state)) { +list_del_init (&device->dev_alloc_list); + device->fs_devices->rw_devices--; + } +if (!btrfs_check_rw_degradable (fs_info, device)) { +btrfs_warn_in_rcu (fs_info, +"btrfs device id %llu path %s has gone missing, can not maintain read-write" , + device->devid,btrfs_dev_name (device)); +btrfs_shutdown (fs_info); +return ; + } +btrfs_warn_in_rcu (fs_info, +"btrfs device id %llu path %s has gone missing, continue degraded" , + device->devid,btrfs_dev_name (device)); +btrfs_set_opt (fs_info->mount_opt,DEGRADED ); +} +static const struct super_operations btrfs_super_ops = { .drop_inode = btrfs_drop_inode, .evict_inode = btrfs_evict_inode,
@@ -2412,6 +2445,7 @@ static const struct super_operations btrfs_super_ops = { .unfreeze_fs = btrfs_unfreeze, .nr_cached_objects = btrfs_nr_cached_objects, .free_cached_objects = btrfs_free_cached_objects, + .shutdown_bdev = btrfs_shutdown_bdev, };static const struct file_operations btrfs_ctl_fops = {
fs/btrfs/volumes.c +2 -0
@@ -6792,6 +6792,8 @@ static bool dev_args_match_fs_devices(const struct btrfs_dev_lookup_args *args,static bool dev_args_match_device (const struct btrfs_dev_lookup_args *args,const struct btrfs_device *device) { +if (args->devt) +return device->devt == args->devt;if (args->missing) {if (test_bit (BTRFS_DEV_STATE_IN_FS_METADATA , &device->dev_state) && !device->bdev)
fs/btrfs/volumes.h +5 -0
@@ -652,6 +652,11 @@ struct btrfs_dev_lookup_args {u64 devid;u8 *uuid;u8 *fsid; +/* +* If devt is specified, all other members will be ignored as it is +* enough to uniquely locate a device. +*/ +dev_t devt;bool missing; };
Signature · 1 line
2.49.0