Skip to contentSkip to conversation

minor cleanups for device close and free functions

PATCH In review Anand Jain 2 participants 6 messages Apr 4, 2023 – Apr 6, 2023 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover minor cleanups for device close and free functions

This patch series includes fixes for minor issues identified in the btrfs_close_one_device() and btrfs_free_device() functions.

Anand Jain (2):
btrfs: warn for any missed cleanup at btrfs_close_one_device
btrfs: remove redundant release of alloc_state

 fs/btrfs/volumes.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
2.39.2
author
#1 lore raw

PATCH 1/2 btrfs: warn for any missed cleanup at btrfs_close_one_device

During my recent search for the root cause of a reported bug, I realized that it's a good idea to issue a warning for missed cleanup instead of using debug-only assertions. Since most installations run with debug off, missed cleanups and premature calls to close could go unnoticed. However, these issues are serious enough to warrant reporting and fixing.

---
 fs/btrfs/volumes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +4 -4
index eead4a1f53b7..0e3677650a78 100644
@@ -1150,10 +1150,10 @@ static void btrfs_close_one_device(struct btrfs_device *device)
 	device->last_flush_error = 0;
 
 	/* Verify the device is back in a pristine state  */
-	ASSERT(!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
-	ASSERT(!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
-	ASSERT(list_empty(&device->dev_alloc_list));
-	ASSERT(list_empty(&device->post_commit_list));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
+	WARN_ON(!list_empty(&device->dev_alloc_list));
+	WARN_ON(!list_empty(&device->post_commit_list));
 }
 
 static void close_fs_devices(struct btrfs_fs_devices *fs_devices)
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/2] btrfs: warn for any missed cleanup at btrfs_close_one_device

Quoted 5 lines · Anand Jain

During my recent search for the root cause of a reported bug, I realized that it's a good idea to issue a warning for missed cleanup instead of using debug-only assertions. Since most installations run with debug off, missed cleanups and premature calls to close could go unnoticed. However, these issues are serious enough to warrant reporting and fixing.

There are other WARN_ONs checking for device state so it should be ok to add some more.

Quoted 11 lines
---
 fs/btrfs/volumes.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +0 -0
index eead4a1f53b7..0e3677650a78 100644
@@ -1150,10 +1150,10 @@ static void btrfs_close_one_device(struct btrfs_device *device)
 	device->last_flush_error = 0;

fs/btrfs/volumes.c static void btrfs_close_one_device(struct btrfs_device *device) · line 1156

Quoted 10 lines
fs/btrfs/volumes.c +4 -4
 
 	/* Verify the device is back in a pristine state  */
-	ASSERT(!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
-	ASSERT(!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
-	ASSERT(list_empty(&device->dev_alloc_list));
-	ASSERT(list_empty(&device->post_commit_list));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
+	WARN_ON(!list_empty(&device->dev_alloc_list));
+	WARN_ON(!list_empty(&device->post_commit_list));

I'm thinking if we can reset some of the values to a safe state too, not keeping it until the next time the device is opened, because not everything is reset at device open time.

author
#3 lore raw

Re: [PATCH 1/2] btrfs: warn for any missed cleanup at btrfs_close_one_device

Quoted 22 lines · David Sterba
Quoted 5 lines · Anand Jain

During my recent search for the root cause of a reported bug, I realized that it's a good idea to issue a warning for missed cleanup instead of using debug-only assertions. Since most installations run with debug off, missed cleanups and premature calls to close could go unnoticed. However, these issues are serious enough to warrant reporting and fixing.

There are other WARN_ONs checking for device state so it should be ok to add some more.

Quoted 12 lines
---
  fs/btrfs/volumes.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +0 -0
index eead4a1f53b7..0e3677650a78 100644
@@ -1150,10 +1150,10 @@ static void btrfs_close_one_device(struct btrfs_device *device)
  	device->last_flush_error = 0;
 
Quoted 13 lines

fs/btrfs/volumes.c static void btrfs_close_one_device(struct btrfs_device *device) · line 1156

Quoted 9 lines
fs/btrfs/volumes.c +4 -4
  	/* Verify the device is back in a pristine state  */
-	ASSERT(!test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
-	ASSERT(!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
-	ASSERT(list_empty(&device->dev_alloc_list));
-	ASSERT(list_empty(&device->post_commit_list));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_FLUSH_SENT, &device->dev_state));
+	WARN_ON(test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state));
+	WARN_ON(!list_empty(&device->dev_alloc_list));
+	WARN_ON(!list_empty(&device->post_commit_list));

I'm thinking if we can reset some of the values to a safe state too, not keeping it until the next time the device is opened, because not everything is reset at device open time.

Good idea. We need some cleanup around these code lines. I will send patches.

Thanks, Anand

author
#4 lore raw

PATCH 2/2 btrfs: remove redundant release of alloc_state

In reply to Anand Jain

Commit 321f69f86a0f ("btrfs: reset device back to allocation state when removing") included adding extent_io_tree_release(&device->alloc_state) to btrfs_close_one_device(), which had already been called in btrfs_free_device().

The alloc_state tree (IO_TREE_DEVICE_ALLOC_STATE), is created in btrfs_alloc_device() and released in btrfs_close_one_device(). Therefore, the additional call to extent_io_tree_release(&device->alloc_state) in btrfs_free_device() is unnecessary and can be removed.

---
 fs/btrfs/volumes.c | 1 -
 1 file changed, 1 deletion(-)
fs/btrfs/volumes.c +0 -1
index 0e3677650a78..c201d72f798e 100644
@@ -395,7 +395,6 @@ void btrfs_free_device(struct btrfs_device *device)
 {
 	WARN_ON(!list_empty(&device->post_commit_list));
 	rcu_string_free(device->name);
-	extent_io_tree_release(&device->alloc_state);
 	btrfs_destroy_dev_zone_info(device);
 	kfree(device);
 }
Signature · 1 line
2.39.2
#5 lore raw
In reply to Anand Jain
Quoted 6 lines · Anand Jain

This patch series includes fixes for minor issues identified in the btrfs_close_one_device() and btrfs_free_device() functions.

Anand Jain (2):
btrfs: warn for any missed cleanup at btrfs_close_one_device
btrfs: remove redundant release of alloc_state

Added to misc-next, thanks.