@@ -3538,6 +3538,23 @@ static int write_dev_flush(struct btrfs_device *device, int wait)
return 0;
}
+static int check_barrier_error(struct btrfs_fs_devices *fsdevs)
+{
+ int dropouts = 0;
+ struct btrfs_device *dev;
+
+ list_for_each_entry_rcu(dev, &fsdevs->devices, dev_list) {
+ if (!dev->bdev || dev->last_flush_error)
+ dropouts++;
+ }
+
+ if (dropouts >
+ fsdevs->fs_info->num_tolerated_disk_barrier_failures)
+ return -EIO;
+
+ return 0;
+}
+
/*
* send an empty flush down to each device in parallel,
* then wait for them
@@ -3575,8 +3592,19 @@ static int barrier_all_devices(struct btrfs_fs_info *info)
if (write_dev_flush(dev, 1))
dropouts++;
}
- if (dropouts > info->num_tolerated_disk_barrier_failures)
- return -EIO;
+
+ /*
+ * A slight optimization, we check for dropouts here which avoids
+ * a dev list loop when disks are healthy.
+ */
+ if (dropouts) {
+ /*
+ * As we need holistic view of the failed disks, so
+ * error checking is pushed to a separate loop.
+ */
+ return check_barrier_error(info->fs_devices);
+ }
+
return 0;
}
The objective of this patch is to cleanup barrier_all_devices() so that the error checking is in a separate loop independent of of the loop which submits and waits on the device flush requests. By doing this it helps to further develop patches which would tune the error-actions as needed. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- v2: Address Qu review comments viz.. Add meaningful names, like cp_list (for checkpoint_list head). (And actually it does not need a new struct type just to hold the head pointer, list node is already named as device_checkpoint). Check return value of add_device_checkpoint() Check if the device is already added at add_device_checkpoint() Rename fini_devices_checkpoint() to rel_devices_checkpoint() v3: (resent with the correct version (that is 3 not 2) of the patch). Dropped for idea of using the BTRFS_DEV_STAT_FLUSH_ERRS, though its the right way, but it needs a better infracture to handle that. Now the flush error return is saved and checked instead of the checkpoint of the dev_stat method earlier. v4: no change fs/btrfs/disk-io.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)