Received: from list by lists.gnu.org with archive (Exim 4.71) id 1fdct5-0007oB-Iz for mharc-grub-devel@gnu.org; Thu, 12 Jul 2018 10:48:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fdct2-0007nh-JW for grub-devel@gnu.org; Thu, 12 Jul 2018 10:48:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fdcsx-00022V-NF for grub-devel@gnu.org; Thu, 12 Jul 2018 10:48:04 -0400 Received: from boksu.net-space.pl ([185.15.1.105]:55101) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.71) (envelope-from ) id 1fdcsx-0001zP-Bh for grub-devel@gnu.org; Thu, 12 Jul 2018 10:47:59 -0400 Received: (from localhost user: 'dkiper' uid#4000 fake: STDIN (dkiper@boksu.net-space.pl)) by router-fw-old.local.net-space.pl id S1851158AbeGLOr5 (ORCPT ); Thu, 12 Jul 2018 16:47:57 +0200 Date: Thu, 12 Jul 2018 16:47:57 +0200 From: Daniel Kiper To: The development of GNU GRUB Cc: Goffredo Baroncelli Subject: Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem. Message-ID: <20180712144757.GI7005@router-fw-old.local.net-space.pl> References: <20180619173956.7356-1-kreijack@inwind.it> <20180619173956.7356-10-kreijack@inwind.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180619173956.7356-10-kreijack@inwind.it> User-Agent: Mutt/1.3.28i X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 185.15.1.105 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: Thu, 12 Jul 2018 14:48:05 -0000 On Tue, Jun 19, 2018 at 07:39:56PM +0200, Goffredo Baroncelli wrote: > Add the RAID 6 recovery, in order to use a RAID 6 filesystem even if some > disks (up to two) are missing. This code use the md RAID 6 code already > present in grub. > > Signed-off-by: Goffredo Baroncelli > --- > grub-core/fs/btrfs.c | 51 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 45 insertions(+), 6 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index 7f01e447a..13777c868 100644 > --- a/grub-core/fs/btrfs.c > +++ b/grub-core/fs/btrfs.c > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > > GRUB_MOD_LICENSE ("GPLv3+"); > > @@ -705,11 +706,36 @@ rebuild_raid5 (char *dest, struct raid56_buffer *buffers, > } > } > > +static grub_err_t > +raid6_recover_read_buffer (void *data, int disk_nr, > + grub_uint64_t addr __attribute__ ((unused)), > + void *dest, grub_size_t size) > +{ > + struct raid56_buffer *buffers = data; > + > + if (!buffers[disk_nr].data_is_valid) > + return grub_errno = GRUB_ERR_READ_ERROR; > + > + grub_memcpy(dest, buffers[disk_nr].buf, size); > + > + return grub_errno = GRUB_ERR_NONE; > +} > + > +static void > +rebuild_raid6 (struct raid56_buffer *buffers, grub_uint64_t nstripes, > + grub_uint64_t csize, grub_uint64_t parities_pos, void *dest, > + grub_uint64_t stripen) > + > +{ > + grub_raid6_recover_gen (buffers, nstripes, stripen, parities_pos, > + dest, 0, csize, 0, raid6_recover_read_buffer); > +} > + > static grub_err_t > raid56_read_retry (struct grub_btrfs_data *data, > struct grub_btrfs_chunk_item *chunk, > - grub_uint64_t stripe_offset, > - grub_uint64_t csize, void *buf) > + grub_uint64_t stripe_offset, grub_uint64_t stripen, > + grub_uint64_t csize, void *buf, grub_uint64_t parities_pos) > { > struct raid56_buffer *buffers = NULL; > grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); > @@ -788,6 +814,15 @@ raid56_read_retry (struct grub_btrfs_data *data, > ret = GRUB_ERR_READ_ERROR; > goto cleanup; > } > + else if (failed_devices > 2 && (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID6)) > + { > + grub_dprintf ("btrfs", > + "not enough disks for raid6: total %" PRIuGRUB_UINT64_T > + ", missing %" PRIuGRUB_UINT64_T "\n", > + nstripes, failed_devices); > + ret = GRUB_ERR_READ_ERROR; > + goto cleanup; > + } > else > { > grub_dprintf ("btrfs", > @@ -800,7 +835,7 @@ raid56_read_retry (struct grub_btrfs_data *data, > if (chunk_type & GRUB_BTRFS_CHUNK_TYPE_RAID5) > rebuild_raid5 (buf, buffers, nstripes, csize); > else > - grub_dprintf ("btrfs", "called rebuild_raid6(), NOT IMPLEMENTED\n"); > + rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen); > > cleanup: > if (buffers) > @@ -892,9 +927,11 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, > unsigned redundancy = 1; > unsigned i, j; > int is_raid56; > + grub_uint64_t parities_pos = 0; > > - is_raid56 = !!(grub_le_to_cpu64 (chunk->type) & > - GRUB_BTRFS_CHUNK_TYPE_RAID5); > + is_raid56 = !!(grub_le_to_cpu64 (chunk->type) & > + (GRUB_BTRFS_CHUNK_TYPE_RAID5 | > + GRUB_BTRFS_CHUNK_TYPE_RAID6)); > > if (grub_le_to_cpu64 (chunk->size) <= off) > { > @@ -1039,6 +1076,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, > * 2 for A3....). The math is performed modulo number of disks. > */ > grub_divmod64 (high + stripen, nstripes, &stripen); > + grub_divmod64 (high + nstripes - nparities, nstripes, > + &parities_pos); This change suggest that this line does not belong to patch #1. And you have to add parities_pos to the comment above too. Daniel