Skip to contentSkip to conversation

btrfs: Add comments on locking of several device-related fields

PATCH Superseded Nikolay Borisov 2 participants 6 messages May 7, 2019 – May 10, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Add comments on locking of several device-related fields

---
 fs/btrfs/volumes.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +8 -3
index 3b97e8092ba7..514799362244 100644
@@ -52,8 +52,8 @@ struct btrfs_io_geometry {
 #define BTRFS_DEV_STATE_FLUSH_SENT	(4)
 
 struct btrfs_device {
-	struct list_head dev_list;
-	struct list_head dev_alloc_list;
+	struct list_head dev_list; /* device_list_mutex */
+	struct list_head dev_alloc_list; /* chunk mutex */
 	struct list_head post_commit_list; /* chunk mutex */
 	struct btrfs_fs_devices *fs_devices;
 	struct btrfs_fs_info *fs_info;
@@ -238,9 +238,14 @@ struct btrfs_fs_devices {
 	 * this mutex lock.
 	 */
 	struct mutex device_list_mutex;
+
+	/* List of all devices, protected by device_list_mutex */
 	struct list_head devices;
 
-	/* devices not currently being allocated */
+	/*
+	 * Devices which can satisfy space allocation. Protected by
+	 * chunk_mutex
+	 */
 	struct list_head alloc_list;
 
 	struct btrfs_fs_devices *seed;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Nikolay Borisov
---
 fs/btrfs/volumes.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +0 -0
index 3b97e8092ba7..514799362244 100644

fs/btrfs/volumes.h struct btrfs_io_geometry { · line 57

Quoted 8 lines
fs/btrfs/volumes.h +2 -2
@@ -52,8 +52,8 @@ struct btrfs_io_geometry {
 #define BTRFS_DEV_STATE_FLUSH_SENT	(4)
 
 struct btrfs_device {
-	struct list_head dev_list;
-	struct list_head dev_alloc_list;
+	struct list_head dev_list; /* device_list_mutex */
+	struct list_head dev_alloc_list; /* chunk mutex */
 	struct list_head post_commit_list; /* chunk mutex */

Please update the documentation in the comment 'Device locking' in volumes.c

#2 lore raw
Quoted 13 lines · David Sterba
Quoted 12 lines · Nikolay Borisov
---
 fs/btrfs/volumes.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +0 -0
index 3b97e8092ba7..514799362244 100644
@@ -52,8 +52,8 @@ struct btrfs_io_geometry {
 #define BTRFS_DEV_STATE_FLUSH_SENT	(4)
 
Quoted 10 lines

fs/btrfs/volumes.h struct btrfs_io_geometry { · line 57

Quoted 6 lines
fs/btrfs/volumes.h +2 -2
 struct btrfs_device {
-	struct list_head dev_list;
-	struct list_head dev_alloc_list;
+	struct list_head dev_list; /* device_list_mutex */
+	struct list_head dev_alloc_list; /* chunk mutex */
 	struct list_head post_commit_list; /* chunk mutex */

Please update the documentation in the comment 'Device locking' in volumes.c

Right the only thing that is missing from the Device Locking comment is the mention of post_commit_list. However, dev_list and dev_alloc_list are essentially "the other side" of btrfs_fs_devices::alloc_list hence I've added them as inline comments. I think it makes more sense to those small comments next to the variables at least as a remainder.

#3 lore raw
Quoted 26 lines · Nikolay Borisov
Quoted 13 lines · David Sterba
Quoted 12 lines · Nikolay Borisov
---
 fs/btrfs/volumes.h | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/volumes.h +0 -0
index 3b97e8092ba7..514799362244 100644
@@ -52,8 +52,8 @@ struct btrfs_io_geometry {
 #define BTRFS_DEV_STATE_FLUSH_SENT	(4)
 
Quoted 9 lines

fs/btrfs/volumes.h struct btrfs_io_geometry { · line 57

Quoted 6 lines
fs/btrfs/volumes.h +2 -2
 struct btrfs_device {
-	struct list_head dev_list;
-	struct list_head dev_alloc_list;
+	struct list_head dev_list; /* device_list_mutex */
+	struct list_head dev_alloc_list; /* chunk mutex */
 	struct list_head post_commit_list; /* chunk mutex */

Please update the documentation in the comment 'Device locking' in volumes.c

Quoted 5 lines

Right the only thing that is missing from the Device Locking comment is the mention of post_commit_list. However, dev_list and dev_alloc_list are essentially "the other side" of btrfs_fs_devices::alloc_list hence I've added them as inline comments. I think it makes more sense to those small comments next to the variables at least as a remainder.

Ok.

#4 lore raw

PATCH v2 1/1 btrfs: Add comments on locking of several device-related fields

In reply to David Sterba

---

V2:
* Document post_commit_list is protected by chunk_mutex in the "Device Locking" section.

 fs/btrfs/volumes.c |  4 +++-
 fs/btrfs/volumes.h | 11 ++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +3 -1
index b85ff32f851c..83603be86891 100644
@@ -237,7 +237,9 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
  * chunk_mutex
  * -----------
  * protects chunks, adding or removing during allocation, trim or when a new
- * device is added/removed
+ * device is added/removed. Additionally it also protects post_commit_list of
+ * individual devices, since they can be added to the transaction's
+ * post_commit_list only with chunk_mutex held.
  *
  * cleaner_mutex
  * -------------
fs/btrfs/volumes.h +8 -3
index 3b97e8092ba7..514799362244 100644
@@ -52,8 +52,8 @@ struct btrfs_io_geometry {
 #define BTRFS_DEV_STATE_FLUSH_SENT	(4)
 
 struct btrfs_device {
-	struct list_head dev_list;
-	struct list_head dev_alloc_list;
+	struct list_head dev_list; /* device_list_mutex */
+	struct list_head dev_alloc_list; /* chunk mutex */
 	struct list_head post_commit_list; /* chunk mutex */
 	struct btrfs_fs_devices *fs_devices;
 	struct btrfs_fs_info *fs_info;
@@ -238,9 +238,14 @@ struct btrfs_fs_devices {
 	 * this mutex lock.
 	 */
 	struct mutex device_list_mutex;
+
+	/* List of all devices, protected by device_list_mutex */
 	struct list_head devices;
 
-	/* devices not currently being allocated */
+	/*
+	 * Devices which can satisfy space allocation. Protected by
+	 * chunk_mutex
+	 */
 	struct list_head alloc_list;
 
 	struct btrfs_fs_devices *seed;
Signature · 1 line
2.17.1