From: Liu Bo <bo.li.liu@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 4/4] Btrfs: change how we set In_sync
Date: Wed, 1 Nov 2017 18:54:05 -0600 [thread overview]
Message-ID: <20171102005405.20420-5-bo.li.liu@oracle.com> (raw)
In-Reply-To: <20171102005405.20420-1-bo.li.liu@oracle.com>
The current method sometimes can report In_sync status wrongly if the
out-of-sync device happens to be the first one we check, and since it
will be the only one, it'll be set In_sync, but later if a newer
device is found, we then change it to !In_sync, but it's not reported
in kernel log.
This changes it to set In_sync flag after iterating all devices, at
this point we have the latest device so we can report out-of-sync
device precisely.
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
fs/btrfs/volumes.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b83b7c8..43f03a6 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1010,26 +1010,9 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
device->generation =
btrfs_stack_device_generation(&disk_super->dev_item);
- /* no lock is required during the initial stage. */
- if (!latest_dev) {
- set_bit(In_sync, &device->flags);
- latest_dev = device;
- } else {
- if (device->generation > latest_dev->generation) {
- set_bit(In_sync, &device->flags);
- clear_bit(In_sync, &latest_dev->flags);
- latest_dev = device;
- } else if (device->generation == latest_dev->generation) {
- set_bit(In_sync, &device->flags);
- }
- /*
- * if (device->generation < latest_dev->generation)
- * # don't set In_sync
- */
- }
-
- if (!test_bit(In_sync, &device->flags))
- pr_info("dev %s gen %llu is not In_sync\n", device->name->str, device->generation);
+ if (!latest_dev ||
+ device->generation > latest_dev->generation)
+ latest_dev = device;
if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_SEEDING) {
device->writeable = 0;
@@ -1063,6 +1046,21 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
blkdev_put(bdev, flags);
continue;
}
+
+ /* set In_sync flag */
+ list_for_each_entry(device, head, dev_list) {
+ ASSERT(device->generation <= latest_dev->generation);
+ if (device->generation == latest_dev->generation) {
+ set_bit(In_sync, &device->flags);
+ pr_debug("btrfs: dev %s gen %llu is In_sync\n",
+ device->name->str, device->generation);
+ } else {
+ clear_bit(In_sync, &device->flags);
+ pr_info("btrfs: dev %s gen %llu is not In_sync\n",
+ device->name->str, device->generation);
+ }
+ }
+
if (fs_devices->open_devices == 0) {
ret = -EINVAL;
goto out;
--
2.9.4
prev parent reply other threads:[~2017-11-02 1:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-02 0:54 [PATCH 0/4] Fix raid6 reconstruction bug Liu Bo
2017-11-02 0:54 ` [PATCH 1/4] Btrfs: introduce device flags Liu Bo
2017-11-06 16:40 ` David Sterba
2017-11-08 19:46 ` Liu Bo
2017-11-13 17:13 ` David Sterba
2017-11-07 9:30 ` Anand Jain
2017-11-02 0:54 ` [PATCH 2/4] Btrfs: fix data corruption in raid6 Liu Bo
2017-11-07 8:32 ` Anand Jain
2017-11-08 19:53 ` Liu Bo
2017-11-09 9:29 ` Anand Jain
2017-11-09 9:59 ` Qu Wenruo
2017-11-10 0:12 ` Liu Bo
2017-11-10 0:54 ` Qu Wenruo
2017-11-10 10:15 ` Qu Wenruo
2017-11-02 0:54 ` [PATCH 3/4] Btrfs: make raid1 and raid10 be aware of device flag In_sync Liu Bo
2017-11-02 0:54 ` Liu Bo [this message]
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=20171102005405.20420-5-bo.li.liu@oracle.com \
--to=bo.li.liu@oracle.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).