From 19c337ad9a5b5a6f9312497799af7ea974473bb2 Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Thu, 3 Aug 2023 07:29:41 +0800 Subject: [PATCH] btrfs-progs: btrfstune: check for missing devices If btrfstune is executed on a filesystem that contains a missing device, the command will now fail. It is ok to fail when any of the options supported by btrfstune are used, the filesystem devices should be all available. Signed-off-by: Anand Jain Signed-off-by: David Sterba --- tune/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tune/main.c b/tune/main.c index 73d09c34..df652907 100644 --- a/tune/main.c +++ b/tune/main.c @@ -287,6 +287,25 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) return 1; } + /* + * As we increment the generation number here, it is unlikely that the + * missing device will have a higher generation number, and the kernel + * won't use its super block for any further commits, even if it is not + * missing during mount. + * + * So, we allow all operations except for -m, -M, -u, and -U, as these + * operations also change the fsid/metadata_uuid, which are key + * parameters for assembling the devices and need to be consistent on + * all the partner devices. + */ + if ((change_metadata_uuid || random_fsid || new_fsid_str) && + root->fs_info->fs_devices->missing_devices > 0) { + error("missing %lld device(s), failing the command", + root->fs_info->fs_devices->missing_devices); + ret = 1; + goto out; + } + if (to_bg_tree) { if (to_extent_tree) { error("option --convert-to-block-group-tree conflicts with --convert-from-block-group-tree");