|
|
d18179 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
d18179 |
From: Goffredo Baroncelli <kreijack@inwind.it>
|
|
|
d18179 |
Date: Mon, 22 Oct 2018 19:29:31 +0200
|
|
|
d18179 |
Subject: [PATCH] btrfs: Add support for reading a filesystem with a RAID 5 or
|
|
|
d18179 |
RAID 6 profile
|
|
|
d18179 |
|
|
|
d18179 |
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
|
|
|
d18179 |
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
d18179 |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
d18179 |
(cherry picked from commit 81e2673fb60a200a33bb064fbffe9e3956f37974)
|
|
|
d18179 |
---
|
|
|
d18179 |
grub-core/fs/btrfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
d18179 |
1 file changed, 73 insertions(+)
|
|
|
d18179 |
|
|
|
d18179 |
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
|
|
|
d18179 |
index a401374690..6f17f5d0eb 100644
|
|
|
d18179 |
--- a/grub-core/fs/btrfs.c
|
|
|
d18179 |
+++ b/grub-core/fs/btrfs.c
|
|
|
d18179 |
@@ -120,6 +120,8 @@ struct grub_btrfs_chunk_item
|
|
|
d18179 |
#define GRUB_BTRFS_CHUNK_TYPE_RAID1 0x10
|
|
|
d18179 |
#define GRUB_BTRFS_CHUNK_TYPE_DUPLICATED 0x20
|
|
|
d18179 |
#define GRUB_BTRFS_CHUNK_TYPE_RAID10 0x40
|
|
|
d18179 |
+#define GRUB_BTRFS_CHUNK_TYPE_RAID5 0x80
|
|
|
d18179 |
+#define GRUB_BTRFS_CHUNK_TYPE_RAID6 0x100
|
|
|
d18179 |
grub_uint8_t dummy2[0xc];
|
|
|
d18179 |
grub_uint16_t nstripes;
|
|
|
d18179 |
grub_uint16_t nsubstripes;
|
|
|
d18179 |
@@ -785,6 +787,77 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr,
|
|
|
d18179 |
stripe_offset = low + chunk_stripe_length
|
|
|
d18179 |
* high;
|
|
|
d18179 |
csize = chunk_stripe_length - low;
|
|
|
d18179 |
+ break;
|
|
|
d18179 |
+ }
|
|
|
d18179 |
+ case GRUB_BTRFS_CHUNK_TYPE_RAID5:
|
|
|
d18179 |
+ case GRUB_BTRFS_CHUNK_TYPE_RAID6:
|
|
|
d18179 |
+ {
|
|
|
d18179 |
+ grub_uint64_t nparities, stripe_nr, high, low;
|
|
|
d18179 |
+
|
|
|
d18179 |
+ redundancy = 1; /* no redundancy for now */
|
|
|
d18179 |
+
|
|
|
d18179 |
+ if (grub_le_to_cpu64 (chunk->type) & GRUB_BTRFS_CHUNK_TYPE_RAID5)
|
|
|
d18179 |
+ {
|
|
|
d18179 |
+ grub_dprintf ("btrfs", "RAID5\n");
|
|
|
d18179 |
+ nparities = 1;
|
|
|
d18179 |
+ }
|
|
|
d18179 |
+ else
|
|
|
d18179 |
+ {
|
|
|
d18179 |
+ grub_dprintf ("btrfs", "RAID6\n");
|
|
|
d18179 |
+ nparities = 2;
|
|
|
d18179 |
+ }
|
|
|
d18179 |
+
|
|
|
d18179 |
+ /*
|
|
|
d18179 |
+ * RAID 6 layout consists of several stripes spread over
|
|
|
d18179 |
+ * the disks, e.g.:
|
|
|
d18179 |
+ *
|
|
|
d18179 |
+ * Disk_0 Disk_1 Disk_2 Disk_3
|
|
|
d18179 |
+ * A0 B0 P0 Q0
|
|
|
d18179 |
+ * Q1 A1 B1 P1
|
|
|
d18179 |
+ * P2 Q2 A2 B2
|
|
|
d18179 |
+ *
|
|
|
d18179 |
+ * Note: placement of the parities depend on row number.
|
|
|
d18179 |
+ *
|
|
|
d18179 |
+ * Pay attention that the btrfs terminology may differ from
|
|
|
d18179 |
+ * terminology used in other RAID implementations, e.g. LVM,
|
|
|
d18179 |
+ * dm or md. The main difference is that btrfs calls contiguous
|
|
|
d18179 |
+ * block of data on a given disk, e.g. A0, stripe instead of chunk.
|
|
|
d18179 |
+ *
|
|
|
d18179 |
+ * The variables listed below have following meaning:
|
|
|
d18179 |
+ * - stripe_nr is the stripe number excluding the parities
|
|
|
d18179 |
+ * (A0 = 0, B0 = 1, A1 = 2, B1 = 3, etc.),
|
|
|
d18179 |
+ * - high is the row number (0 for A0...Q0, 1 for Q1...P1, etc.),
|
|
|
d18179 |
+ * - stripen is the disk number in a row (0 for A0, Q1, P2,
|
|
|
d18179 |
+ * 1 for B0, A1, Q2, etc.),
|
|
|
d18179 |
+ * - off is the logical address to read,
|
|
|
d18179 |
+ * - chunk_stripe_length is the size of a stripe (typically 64 KiB),
|
|
|
d18179 |
+ * - nstripes is the number of disks in a row,
|
|
|
d18179 |
+ * - low is the offset of the data inside a stripe,
|
|
|
d18179 |
+ * - stripe_offset is the data offset in an array,
|
|
|
d18179 |
+ * - csize is the "potential" data to read; it will be reduced
|
|
|
d18179 |
+ * to size if the latter is smaller,
|
|
|
d18179 |
+ * - nparities is the number of parities (1 for RAID 5, 2 for
|
|
|
d18179 |
+ * RAID 6); used only in RAID 5/6 code.
|
|
|
d18179 |
+ */
|
|
|
d18179 |
+ stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low);
|
|
|
d18179 |
+
|
|
|
d18179 |
+ /*
|
|
|
d18179 |
+ * stripen is computed without the parities
|
|
|
d18179 |
+ * (0 for A0, A1, A2, 1 for B0, B1, B2, etc.).
|
|
|
d18179 |
+ */
|
|
|
d18179 |
+ high = grub_divmod64 (stripe_nr, nstripes - nparities, &stripen);
|
|
|
d18179 |
+
|
|
|
d18179 |
+ /*
|
|
|
d18179 |
+ * The stripes are spread over the disks. Every each row their
|
|
|
d18179 |
+ * positions are shifted by 1 place. So, the real disks number
|
|
|
d18179 |
+ * change. Hence, we have to take into account current row number
|
|
|
d18179 |
+ * modulo nstripes (0 for A0, 1 for A1, 2 for A2, etc.).
|
|
|
d18179 |
+ */
|
|
|
d18179 |
+ grub_divmod64 (high + stripen, nstripes, &stripen);
|
|
|
d18179 |
+
|
|
|
d18179 |
+ stripe_offset = chunk_stripe_length * high + low;
|
|
|
d18179 |
+ csize = chunk_stripe_length - low;
|
|
|
d18179 |
+
|
|
|
d18179 |
break;
|
|
|
d18179 |
}
|
|
|
d18179 |
default:
|