summaryrefslogtreecommitdiff
path: root/fs/btrfs/raid56.c
diff options
context:
space:
mode:
authorQu Wenruo <wqu@suse.com>2022-11-01 19:16:06 +0800
committerDavid Sterba <dsterba@suse.com>2022-12-05 18:00:49 +0100
commit509c27aa2fb69b4475d05d0ac5c5c4206e28d5d6 (patch)
tree39a3a586256f5f00374bd81721b28e4c329fe68a /fs/btrfs/raid56.c
parentd817ce35d24a53c6736ac68e759ed83135ff7c3b (diff)
btrfs: raid56: extract the rmw bio list build code into a helper
The helper will later be used to refactor the whole RMW path. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/raid56.c')
-rw-r--r--fs/btrfs/raid56.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 2dd87ceda9db..88e2204c9f28 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1595,28 +1595,16 @@ static void raid56_rmw_end_io_work(struct work_struct *work)
validate_rbio_for_rmw(rbio);
}
-/*
- * the stripe must be locked by the caller. It will
- * unlock after all the writes are done
- */
-static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
+static int rmw_assemble_read_bios(struct btrfs_raid_bio *rbio,
+ struct bio_list *bio_list)
{
- int bios_to_read = 0;
- struct bio_list bio_list;
const int nr_data_sectors = rbio->stripe_nsectors * rbio->nr_data;
- int ret;
- int total_sector_nr;
struct bio *bio;
+ int total_sector_nr;
+ int ret = 0;
- bio_list_init(&bio_list);
-
- ret = alloc_rbio_pages(rbio);
- if (ret)
- goto cleanup;
-
- index_rbio_pages(rbio);
+ ASSERT(bio_list_size(bio_list) == 0);
- atomic_set(&rbio->error, 0);
/* Build a list of bios to read all the missing data sectors. */
for (total_sector_nr = 0; total_sector_nr < nr_data_sectors;
total_sector_nr++) {
@@ -1641,11 +1629,43 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
if (sector->uptodate)
continue;
- ret = rbio_add_io_sector(rbio, &bio_list, sector,
+ ret = rbio_add_io_sector(rbio, bio_list, sector,
stripe, sectornr, REQ_OP_READ);
if (ret)
goto cleanup;
}
+ return 0;
+
+cleanup:
+ while ((bio = bio_list_pop(bio_list)))
+ bio_put(bio);
+ return ret;
+}
+
+/*
+ * the stripe must be locked by the caller. It will
+ * unlock after all the writes are done
+ */
+static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
+{
+ int bios_to_read = 0;
+ struct bio_list bio_list;
+ int ret;
+ struct bio *bio;
+
+ bio_list_init(&bio_list);
+
+ ret = alloc_rbio_pages(rbio);
+ if (ret)
+ goto cleanup;
+
+ index_rbio_pages(rbio);
+
+ atomic_set(&rbio->error, 0);
+
+ ret = rmw_assemble_read_bios(rbio, &bio_list);
+ if (ret < 0)
+ goto cleanup;
bios_to_read = bio_list_size(&bio_list);
if (!bios_to_read) {