From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/3] btrfs: volumes: Add btrfs_fs_devices::missing_list to collect missing devices
Date: Thu, 7 Nov 2019 14:27:09 +0800 [thread overview]
Message-ID: <20191107062710.67964-3-wqu@suse.com> (raw)
In-Reply-To: <20191107062710.67964-1-wqu@suse.com>
This enables btrfs to iterate missing devices separately, without
iterating all fs_devices.
This provides the basis for later degraded chunk enhancement.
The change includes:
- Add missing devices to btrfs_fs_devices::missing_list
This happens at add_missing_dev() and other locations where
missing_devices get increased.
- Remove missing devices from btrfs_fs_devices::missing_list
This needs to cover all locations where missing_devices get decreased.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/volumes.c | 27 +++++++++++++++++++++------
fs/btrfs/volumes.h | 6 ++++++
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index eee5fc1d11f0..a462d8de5d2a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -324,6 +324,7 @@ static struct btrfs_fs_devices *alloc_fs_devices(const u8 *fsid,
INIT_LIST_HEAD(&fs_devs->devices);
INIT_LIST_HEAD(&fs_devs->alloc_list);
+ INIT_LIST_HEAD(&fs_devs->missing_list);
INIT_LIST_HEAD(&fs_devs->fs_list);
if (fsid)
memcpy(fs_devs->fsid, fsid, BTRFS_FSID_SIZE);
@@ -1089,6 +1090,7 @@ static noinline struct btrfs_device *device_list_add(const char *path,
if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) {
fs_devices->missing_devices--;
clear_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state);
+ list_del_init(&device->dev_alloc_list);
}
}
@@ -1250,11 +1252,10 @@ static void btrfs_close_one_device(struct btrfs_device *device)
if (device->bdev)
fs_devices->open_devices--;
+ list_del_init(&device->dev_alloc_list);
if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
- device->devid != BTRFS_DEV_REPLACE_DEVID) {
- list_del_init(&device->dev_alloc_list);
+ device->devid != BTRFS_DEV_REPLACE_DEVID)
fs_devices->rw_devices--;
- }
if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
fs_devices->missing_devices--;
@@ -2140,6 +2141,12 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
device->fs_devices->rw_devices--;
mutex_unlock(&fs_info->chunk_mutex);
}
+ if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) {
+ mutex_lock(&fs_info->chunk_mutex);
+ list_del_init(&device->dev_alloc_list);
+ device->fs_devices->missing_devices--;
+ mutex_unlock(&fs_info->chunk_mutex);
+ }
mutex_unlock(&uuid_mutex);
ret = btrfs_shrink_device(device, 0);
@@ -2184,9 +2191,6 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
if (cur_devices != fs_devices)
fs_devices->total_devices--;
- if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state))
- cur_devices->missing_devices--;
-
btrfs_assign_next_active_device(device, NULL);
if (device->bdev) {
@@ -2236,6 +2240,13 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const char *device_path,
device->fs_devices->rw_devices++;
mutex_unlock(&fs_info->chunk_mutex);
}
+ if (test_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state)) {
+ mutex_lock(&fs_info->chunk_mutex);
+ list_add(&device->dev_alloc_list,
+ &fs_devices->missing_list);
+ device->fs_devices->missing_devices++;
+ mutex_unlock(&fs_info->chunk_mutex);
+ }
goto out;
}
@@ -2438,6 +2449,7 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
seed_devices->opened = 1;
INIT_LIST_HEAD(&seed_devices->devices);
INIT_LIST_HEAD(&seed_devices->alloc_list);
+ INIT_LIST_HEAD(&seed_devices->missing_list);
mutex_init(&seed_devices->device_list_mutex);
mutex_lock(&fs_devices->device_list_mutex);
@@ -6640,6 +6652,7 @@ static struct btrfs_device *add_missing_dev(struct btrfs_fs_devices *fs_devices,
fs_devices->num_devices++;
set_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state);
+ list_add(&device->dev_alloc_list, &fs_devices->missing_list);
fs_devices->missing_devices++;
return device;
@@ -6979,6 +6992,7 @@ static int read_one_dev(struct extent_buffer *leaf,
*/
device->fs_devices->missing_devices++;
set_bit(BTRFS_DEV_STATE_MISSING, &device->dev_state);
+ list_add(&device->dev_alloc_list, &fs_devices->missing_list);
}
/* Move the device to its own fs_devices */
@@ -6992,6 +7006,7 @@ static int read_one_dev(struct extent_buffer *leaf,
device->fs_devices->missing_devices--;
fs_devices->missing_devices++;
+ list_move(&device->dev_alloc_list, &fs_devices->missing_list);
device->fs_devices = fs_devices;
}
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index a7da1f3e3627..9cef4dc4b5be 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -253,6 +253,12 @@ struct btrfs_fs_devices {
*/
struct list_head alloc_list;
+ /*
+ * Devices which can't be found. Projected by chunk_mutex.
+ * This acts as a fallback allocation list for certain degraded mount.
+ */
+ struct list_head missing_list;
+
struct btrfs_fs_devices *seed;
int seeding;
--
2.24.0
next prev parent reply other threads:[~2019-11-07 6:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-07 6:27 [PATCH 0/3] btrfs: More intelligent degraded chunk allocator Qu Wenruo
2019-11-07 6:27 ` [PATCH 1/3] btrfs: volumes: Refactor device holes gathering into a separate function Qu Wenruo
2019-11-07 9:20 ` Johannes Thumshirn
2019-11-07 9:33 ` Qu Wenruo
2019-11-07 9:45 ` Johannes Thumshirn
2019-11-07 6:27 ` Qu Wenruo [this message]
2019-11-07 9:31 ` [PATCH 2/3] btrfs: volumes: Add btrfs_fs_devices::missing_list to collect missing devices Johannes Thumshirn
2019-11-19 10:03 ` Anand Jain
2019-11-19 10:29 ` Qu Wenruo
2019-11-27 19:36 ` David Sterba
2019-11-07 6:27 ` [PATCH 3/3] btrfs: volumes: Allocate degraded chunks if rw devices can't fullfil a chunk Qu Wenruo
2019-11-19 10:05 ` Anand Jain
2019-11-19 10:41 ` Qu Wenruo
2019-11-27 19:23 ` David Sterba
2019-11-27 23:36 ` Qu Wenruo
2019-11-28 11:24 ` David Sterba
2019-11-28 12:29 ` Qu Wenruo
2019-11-28 12:30 ` Qu WenRuo
2019-11-28 12:39 ` Qu Wenruo
2019-11-18 20:18 ` [PATCH 0/3] btrfs: More intelligent degraded chunk allocator David Sterba
2019-11-18 23:32 ` Qu Wenruo
2019-11-19 5:18 ` Alberto Bursi
2019-11-27 19:26 ` David Sterba
2019-12-02 3:22 ` Zygo Blaxell
2019-12-02 4:41 ` Qu Wenruo
2019-12-02 19:27 ` Zygo Blaxell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191107062710.67964-3-wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).