diff mbox series

[05/10] btrfs-progs: tune: check for missing device

Message ID aebc04bcbbfc24298969e986eab5f27b002cebdd.1690985783.git.anand.jain@oracle.com (mailing list archive)
State New, archived
Headers show
Series fixes and preparatory related to metadata_uuid | expand

Commit Message

Anand Jain Aug. 2, 2023, 11:29 p.m. UTC
If btrfstune is executed on a filesystem that contains a missing device,
the command will now fail.

It is ok fail when any of the options supported by btrfstune are used.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: adds comment

 tune/main.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff mbox series

Patch

diff --git a/tune/main.c b/tune/main.c
index 73d09c34a897..8febd0d6479c 100644
--- a/tune/main.c
+++ b/tune/main.c
@@ -287,6 +287,23 @@  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 sb 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) {
+		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");