Skip to contentSkip to conversation

btrfs: Move missing device handling in a dedicate function

PATCH In review Nikolay Borisov 3 participants 3 messages Jan 11, 2022 – Jan 12, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Move missing device handling in a dedicate function

This simplifies the code flow in read_one_chunk and makes error handling when handling missing devices a bit simipler by reducing it to a single check if something went wrong. No functional changes.

---
 fs/btrfs/volumes.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
fs/btrfs/volumes.c +25 -14
index b07d382d53a8..7518ac5c28dc 100644
@@ -7060,6 +7060,27 @@ static void warn_32bit_meta_chunk(struct btrfs_fs_info *fs_info,
 }
 #endif
 
+static struct btrfs_device *handle_missing_device(struct btrfs_fs_info *fs_info,
+						  u64 devid, u8 *uuid)
+{
+	struct btrfs_device *dev;
+
+	if (!btrfs_test_opt(fs_info, DEGRADED)) {
+		btrfs_report_missing_device(fs_info, devid, uuid, true);
+		return ERR_PTR(-ENOENT);
+	}
+
+	dev = add_missing_dev(fs_info->fs_devices, devid, uuid);
+	if (IS_ERR(dev)) {
+		btrfs_err(fs_info, "failed to init missing dev %llu: %ld",
+			  devid, PTR_ERR(dev));
+		return dev;
+	}
+	btrfs_report_missing_device(fs_info, devid, uuid, false);
+
+	return dev;
+}
+
 static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
 			  struct btrfs_chunk *chunk)
 {
@@ -7147,28 +7168,18 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
 				   BTRFS_UUID_SIZE);
 		args.uuid = uuid;
 		map->stripes[i].dev = btrfs_find_device(fs_info->fs_devices, &args);
-		if (!map->stripes[i].dev &&
-		    !btrfs_test_opt(fs_info, DEGRADED)) {
-			free_extent_map(em);
-			btrfs_report_missing_device(fs_info, devid, uuid, true);
-			return -ENOENT;
-		}
 		if (!map->stripes[i].dev) {
-			map->stripes[i].dev =
-				add_missing_dev(fs_info->fs_devices, devid,
-						uuid);
+			map->stripes[i].dev = handle_missing_device(fs_info,
+								    devid, uuid);
 			if (IS_ERR(map->stripes[i].dev)) {
 				free_extent_map(em);
-				btrfs_err(fs_info,
-					"failed to init missing dev %llu: %ld",
-					devid, PTR_ERR(map->stripes[i].dev));
 				return PTR_ERR(map->stripes[i].dev);
+
 			}
-			btrfs_report_missing_device(fs_info, devid, uuid, false);
 		}
+
 		set_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
 				&(map->stripes[i].dev->dev_state));
-
 	}
 
 	write_lock(&map_tree->lock);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 70 lines · Nikolay Borisov

This simplifies the code flow in read_one_chunk and makes error handling when handling missing devices a bit simipler by reducing it to a single check if something went wrong. No functional changes.

---
 fs/btrfs/volumes.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)
fs/btrfs/volumes.c +7 -0
index b07d382d53a8..7518ac5c28dc 100644
@@ -7060,6 +7060,27 @@ static void warn_32bit_meta_chunk(struct 
 btrfs_fs_info *fs_info,
 }
 #endif
 
+static struct btrfs_device *handle_missing_device(struct 
 btrfs_fs_info *fs_info,
+						  u64 devid, u8 
 *uuid)
+{
+	struct btrfs_device *dev;
+
+	if (!btrfs_test_opt(fs_info, DEGRADED)) {
+		btrfs_report_missing_device(fs_info, devid, uuid, 

true);

fs/btrfs/volumes.c +6 -0
+		return ERR_PTR(-ENOENT);
+	}
+
+	dev = add_missing_dev(fs_info->fs_devices, devid, uuid);
+	if (IS_ERR(dev)) {
+		btrfs_err(fs_info, "failed to init missing dev 

%llu: %ld",

fs/btrfs/volumes.c +10 -9
+			  devid, PTR_ERR(dev));
+		return dev;
+	}
+	btrfs_report_missing_device(fs_info, devid, uuid, false);
+
+	return dev;
+}
+
 static int read_one_chunk(struct btrfs_key *key, struct 
 extent_buffer *leaf,
 			  struct btrfs_chunk *chunk)
 {
@@ -7147,28 +7168,18 @@ static int read_one_chunk(struct 
 btrfs_key *key, struct extent_buffer *leaf,
 				   BTRFS_UUID_SIZE);
 		args.uuid = uuid;
 		map->stripes[i].dev = 
 btrfs_find_device(fs_info->fs_devices, &args);
-		if (!map->stripes[i].dev &&
-		    !btrfs_test_opt(fs_info, DEGRADED)) {
-			free_extent_map(em);
-			btrfs_report_missing_device(fs_info, 
 devid, uuid, true);
-			return -ENOENT;
-		}
 		if (!map->stripes[i].dev) {
-			map->stripes[i].dev =
- 
 add_missing_dev(fs_info->fs_devices, devid,
-						uuid);
+			map->stripes[i].dev = 
 handle_missing_device(fs_info,
+ 
 devid, uuid);

fs/btrfs/volumes.c static int read_one_chunk(struct

Quoted 10 lines
fs/btrfs/volumes.c +1 -3
 			if (IS_ERR(map->stripes[i].dev)) {
 				free_extent_map(em);
-				btrfs_err(fs_info,
-					"failed to init missing 
 dev %llu: %ld",
-					devid, 
 PTR_ERR(map->stripes[i].dev));
 				return 
 PTR_ERR(map->stripes[i].dev);
+

No need for the blank line, I think.

--
Su

Quoted 11 lines
fs/btrfs/volumes.c +0 -1
 			}
-			btrfs_report_missing_device(fs_info, 

devid, uuid, false);

fs/btrfs/volumes.c +1 -1
 		}
+
 		set_bit(BTRFS_DEV_STATE_IN_FS_METADATA,
 				&(map->stripes[i].dev->dev_state));
-
 	}
 
 	write_lock(&map_tree->lock);