[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/9] btrfs: refactor the code that read from disk
From: |
Goffredo Baroncelli |
Subject: |
[PATCH 6/9] btrfs: refactor the code that read from disk |
Date: |
Wed, 16 May 2018 20:48:16 +0200 |
This is a preparatory patch, to help the adding of the RAID 5/6 recovery
code. In case of availability of all disks, this code is good for all the
RAID profiles. However in case of failure, the error handling is quite
different. Refactoring this code increases the general readability.
Signed-off-by: Goffredo Baroncelli <address@hidden>
---
grub-core/fs/btrfs.c | 85 +++++++++++++++++++++++++-------------------
1 file changed, 49 insertions(+), 36 deletions(-)
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 51f300829..63651928b 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -625,6 +625,47 @@ find_device (struct grub_btrfs_data *data, grub_uint64_t
id)
return ctx.dev_found;
}
+static grub_err_t
+btrfs_read_from_chunk (struct grub_btrfs_data *data,
+ struct grub_btrfs_chunk_item *chunk,
+ grub_uint64_t stripen, grub_uint64_t stripe_offset,
+ int redundancy, grub_uint64_t csize,
+ void *buf)
+{
+
+ struct grub_btrfs_chunk_stripe *stripe;
+ grub_disk_addr_t paddr;
+ grub_device_t dev;
+ grub_err_t err;
+
+ stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1);
+ /* Right now the redundancy handling is easy.
+ With RAID5-like it will be more difficult. */
+ stripe += stripen + redundancy;
+
+ paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset;
+
+ grub_dprintf ("btrfs", "stripe %" PRIxGRUB_UINT64_T
+ " maps to 0x%" PRIxGRUB_UINT64_T "\n",
+ stripen, stripe->offset);
+ grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T "\n", paddr);
+
+ dev = find_device (data, stripe->device_id);
+ if (!dev)
+ {
+ grub_dprintf ("btrfs",
+ "couldn't find a necessary member device "
+ "of multi-device filesystem\n");
+ grub_errno = GRUB_ERR_NONE;
+ return GRUB_ERR_READ_ERROR;
+ }
+
+ err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS,
+ paddr & (GRUB_DISK_SECTOR_SIZE - 1),
+ csize, buf);
+ return err;
+}
+
static grub_err_t
grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
void *buf, grub_size_t size, int recursion_depth)
@@ -638,7 +679,6 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
grub_disk_addr_t addr,
grub_err_t err = 0;
struct grub_btrfs_key key_out;
int challoc = 0;
- grub_device_t dev;
struct grub_btrfs_key key_in;
grub_size_t chsize;
grub_disk_addr_t chaddr;
@@ -879,42 +919,15 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data,
grub_disk_addr_t addr,
for (i = 0; i < redundancy; i++)
{
- struct grub_btrfs_chunk_stripe *stripe;
- grub_disk_addr_t paddr;
-
- stripe = (struct grub_btrfs_chunk_stripe *) (chunk + 1);
- /* Right now the redundancy handling is easy.
- With RAID5-like it will be more difficult. */
- stripe += stripen + i;
-
- paddr = grub_le_to_cpu64 (stripe->offset) + stripe_offset;
-
- grub_dprintf ("btrfs", "stripe %" PRIxGRUB_UINT64_T
- " maps to 0x%" PRIxGRUB_UINT64_T "\n",
- stripen, stripe->offset);
- grub_dprintf ("btrfs", "reading paddr 0x%" PRIxGRUB_UINT64_T
- "\n", paddr);
-
- dev = find_device (data, stripe->device_id);
- if (!dev)
- {
- grub_dprintf ("btrfs",
- "couldn't find a necessary member device "
- "of multi-device filesystem\n");
- err = grub_errno;
- grub_errno = GRUB_ERR_NONE;
- continue;
- }
-
- err = grub_disk_read (dev->disk, paddr >> GRUB_DISK_SECTOR_BITS,
- paddr & (GRUB_DISK_SECTOR_SIZE - 1),
- csize, buf);
- if (!err)
- break;
- grub_errno = GRUB_ERR_NONE;
+ err = btrfs_read_from_chunk (data, chunk, stripen,
+ stripe_offset,
+ i, /* redundancy */
+ csize, buf);
+ if (err == GRUB_ERR_NONE)
+ break;
}
- if (i != redundancy)
- break;
+ if (err == GRUB_ERR_NONE)
+ break;
}
if (err)
return grub_errno = err;
--
2.17.0
- [PATCH V4] Add support for BTRFS raid5/6 to GRUB, Goffredo Baroncelli, 2018/05/16
- [PATCH 1/9] btrfs: add support for reading a filesystem with a RAID 5 or RAID 6 profile., Goffredo Baroncelli, 2018/05/16
- [PATCH 2/9] btrfs: add helper to check the btrfs header., Goffredo Baroncelli, 2018/05/16
- [PATCH 5/9] btrfs: move logging code in grub_btrfs_read_logical(), Goffredo Baroncelli, 2018/05/16
- [PATCH 6/9] btrfs: refactor the code that read from disk,
Goffredo Baroncelli <=
- [PATCH 3/9] btrfs: move the error logging from find_device() to its callee., Goffredo Baroncelli, 2018/05/16
- [PATCH 4/9] btrfs: avoiding a rescan for a device which was already not founded., Goffredo Baroncelli, 2018/05/16
- [PATCH 7/9] btrfs: add support for recovery for a RAID 5 btrfs profiles., Goffredo Baroncelli, 2018/05/16
- [PATCH 8/9] btrfs: make more generic the code for RAID 6 rebuilding, Goffredo Baroncelli, 2018/05/16
- [PATCH 9/9] btrfs: add RAID 6 recovery for a btrfs filesystem., Goffredo Baroncelli, 2018/05/16