Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g2hL8-000838-Lk for mharc-grub-devel@gnu.org; Wed, 19 Sep 2018 14:36:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2hL6-000831-C4 for grub-devel@gnu.org; Wed, 19 Sep 2018 14:36:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2hL2-0002SJ-1s for grub-devel@gnu.org; Wed, 19 Sep 2018 14:36:40 -0400 Received: from smtp-33-i6.italiaonline.it ([213.209.14.33]:56340 helo=libero.it) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2hL1-0002P0-NJ for grub-devel@gnu.org; Wed, 19 Sep 2018 14:36:35 -0400 Received: from venice.bhome ([94.38.18.13]) by smtp-33.iol.local with ESMTPA id 2hKygfwlcQGOz2hKzgVYWe; Wed, 19 Sep 2018 20:36:33 +0200 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2014; t=1537382193; bh=h+MVSqnRlAlWQ/7Bhq7lFOLE/v0DWeOjkU0L6qMnQq0=; h=From:To:Cc:Subject:Date; b=KTlx2UJhO3r1HJjXN1VNBnOQHlbc7dS7mLof4y/b+HhoR8WImlWnU59h2S+nFWNwT astbIqhgOULWeA7z6HFvNN2uj8OB9WrouAd2aDUbCF0f/4uqyB8jmtNxiyflyR7gdG 7nEiwDF5PzHrhiJ/JVwO20KtWTX3fIxRVayBQO4SidbYECCrCP0NeiNc0Oup61RkBk lHVCzm5HiBUQ0odY+GZH7wR1S42HSvRgG+A7tlz+W+uvCrByzPP9HO61FuPVHVHPXH 4e5uY5Nh/hT6vzRyg0Vf+QC4UCzNDLH/RZCZuOtVp/WKKzXLjcFahUR8qh1Kj7TBvv Mtbb0HfnuA+Aw== X-CNFS-Analysis: v=2.3 cv=OvCeNB3t c=1 sm=1 tr=0 a=y+pHRDKYf/eurU+tzaSv/w==:117 a=y+pHRDKYf/eurU+tzaSv/w==:17 a=aN2EQwbrEeMS1mtm6tgA:9 a=0HxuzKx6jGqXImNv:21 a=1lWlG15CL-aWOs4E:21 From: Goffredo Baroncelli To: grub-devel@gnu.org Cc: Goffredo Baroncelli Subject: [PATCH 1/9] btrfs: Add support for reading a filesystem with a RAID 5 or RAID 6 profile. Date: Wed, 19 Sep 2018 20:36:20 +0200 Message-Id: <20180919183628.3696-2-kreijack@libero.it> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfO0Fr84o7ZDO7u5MEOELbyLqjQNODpixiuZz5kAdxot34eauymkmb3cndDjKyiI2JajR5PVX/xBZgXjjDmnBam3FonJAy7k+YXznPBpk9LISiTQ5irTG xP8sgaV2C6WbLq2VMBEmumKH/ahuIZwYyONtTakefSRvA+BdTIz8ng+1xVF1J8L0Tnu2uQbUr84OSg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 213.209.14.33 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 18:36:41 -0000 From: Goffredo Baroncelli Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index be195448d..56c42746d 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -119,6 +119,8 @@ struct grub_btrfs_chunk_item #define GRUB_BTRFS_CHUNK_TYPE_RAID1 0x10 #define GRUB_BTRFS_CHUNK_TYPE_DUPLICATED 0x20 #define GRUB_BTRFS_CHUNK_TYPE_RAID10 0x40 +#define GRUB_BTRFS_CHUNK_TYPE_RAID5 0x80 +#define GRUB_BTRFS_CHUNK_TYPE_RAID6 0x100 grub_uint8_t dummy2[0xc]; grub_uint16_t nstripes; grub_uint16_t nsubstripes; @@ -764,6 +766,70 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; + break; + } + case GRUB_BTRFS_CHUNK_TYPE_RAID5: + case GRUB_BTRFS_CHUNK_TYPE_RAID6: + { + grub_uint64_t nparities, block_nr, high, low; + + redundancy = 1; /* no redundancy for now */ + + if (grub_le_to_cpu64 (chunk->type) & GRUB_BTRFS_CHUNK_TYPE_RAID5) + { + grub_dprintf ("btrfs", "RAID5\n"); + nparities = 1; + } + else + { + grub_dprintf ("btrfs", "RAID6\n"); + nparities = 2; + } + + /* + * A RAID 6 layout consists of several blocks spread on the disks. + * The raid terminology is used to call all the blocks of a row + * "stripe". Unfortunately the BTRFS terminology confuses block + * and stripe. + * + * Disk0 Disk1 Disk2 Disk3 + * + * A1 B1 P1 Q1 + * Q2 A2 B2 P2 + * P3 Q3 A3 B3 + * [...] + * + * Note that the placement of the parities depends on row index. + * In the code below: + * - block_nr is the block number without the parities + * (A1 = 0, B1 = 1, A2 = 2, B2 = 3, ...), + * - high is the row number (0 for A1...Q1, 1 for Q2...P2, ...), + * - stripen is the disk number (0 for A1,Q2,P3, 1 for B1...), + * - off is the logical address to read + * - chunk_stripe_length is the size of a block (typically 64k), + * - nstripes is the number of disks, + * - low is the offset of the data inside a stripe, + * - stripe_offset is the disk offset, + * - csize is the "potential" data to read. It will be reduced to + * size if the latter is smaller. + */ + block_nr = grub_divmod64 (off, chunk_stripe_length, &low); + + /* + * stripen is computed without the parities (0 for A1, A2, A3... + * 1 for B1, B2...). + */ + high = grub_divmod64 (block_nr, nstripes - nparities, &stripen); + + /* + * stripen is recomputed considering the parities (0 for A1, 1 for + * A2, 2 for A3....). + */ + grub_divmod64 (high + stripen, nstripes, &stripen); + + stripe_offset = low + chunk_stripe_length * high; + csize = chunk_stripe_length - low; + break; } default: -- 2.19.0