[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
From: Goffredo Baroncelli 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 Reviewed-by: Daniel Kiper --- grub-core/fs/btrfs.c | 60 +++- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 965888da4..7c316fd33 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+"); @@ -701,11 +702,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; grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); @@ -776,6 +802,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 RAID 6: total %" PRIuGRUB_UINT64_T + ", missing %" PRIuGRUB_UINT64_T "\n", + nstripes, failed_devices); + ret = GRUB_ERR_READ_ERROR; + goto cleanup; +} else grub_dprintf ("btrfs", "enough disks for RAID 5: total %" @@ -786,7 +821,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); ret = GRUB_ERR_NONE; cleanup: @@ -876,9 +911,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) { @@ -1027,6 +1064,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, */ grub_divmod64 (high + stripen, nstripes, &stripen); + /* + * parities_pos is equal to "(high - nparities) % nstripes" + * (see the diagram above). + * However "high - nparities" can be negative, eg. when high + * == 0 leading to an incorrect computation. + * "high + nstripes - nparities" is always positive and in + * modulo nstripes is equal to "(high - nparities) % nstripes" + */ + grub_divmod64 (high + nstripes - nparities, nstripes, +&parities_pos); + stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1067,7 +1115,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } else for (i = 0; i < redundancy; i++) -- 2.19.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
From: Goffredo Baroncelli 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 Reviewed-by: Daniel Kiper --- grub-core/fs/btrfs.c | 60 +++- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index b277f2904..9419d313d 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+"); @@ -701,11 +702,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; grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); @@ -778,6 +804,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 RAID 6: total %" PRIuGRUB_UINT64_T + ", missing %" PRIuGRUB_UINT64_T "\n", + nstripes, failed_devices); + ret = GRUB_ERR_READ_ERROR; + goto cleanup; +} else grub_dprintf ("btrfs", "enough disks for RAID 5: total %" @@ -788,7 +823,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); ret = GRUB_ERR_NONE; cleanup: @@ -878,9 +913,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) { @@ -1029,6 +1066,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, */ grub_divmod64 (high + stripen, nstripes, &stripen); + /* + * parities_pos is equal to "(high - nparities) % nstripes" + * (see the diagram above). + * However "high - nparities" can be negative, eg. when high + * == 0 leading to an incorrect computation. + * "high + nstripes - nparities" is always positive and in + * modulo nstripes is equal to "(high - nparities) % nstripes" + */ + grub_divmod64 (high + nstripes - nparities, nstripes, +&parities_pos); + stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1069,7 +1117,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } else for (i = 0; i < redundancy; i++) -- 2.19.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On Thu, Oct 11, 2018 at 08:51:03PM +0200, Goffredo Baroncelli wrote: > From: Goffredo Baroncelli > > 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 > Reviewed-by: Daniel Kiper > --- > grub-core/fs/btrfs.c | 60 +++- > 1 file changed, 54 insertions(+), 6 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index d066d54cc..d20ee09e4 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+"); > > @@ -702,11 +703,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; >grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); > @@ -779,6 +805,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 s/not enough disks for raid6/not enough disks for RAID 6/ You are using "RAID 5" in earlier patch, so, please be consistent and use "RAID 6" here. > + ", missing %" PRIuGRUB_UINT64_T "\n", > + nstripes, failed_devices); > + ret = GRUB_ERR_READ_ERROR; > + goto cleanup; > +} >else > grub_dprintf ("btrfs", > "enough disks for RAID 5 rebuilding: total %" > @@ -789,7 +824,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); > >ret = GRUB_ERR_NONE; > cleanup: > @@ -879,9 +914,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) > { > @@ -1030,6 +1067,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, > */ > grub_divmod64 (high + stripen, nstripes, &stripen); > > + /* > +* parities_pos is equal to "(high - nparities) % nstripes" > +* (see the diagram above). > +* However "high - nparities" might be negative (eg when high > +* == 0) leading to an incorrect computation. However, "high - nparities" can be negative, eg. when high == 0, leading to an incorrect results. > +* Instead "high + nstripes - nparities" is always positive and > +* in modulo nstripes is equal to "(high - nparities) % nstripes" "high + nstripes - nparities" is always positive and modulo nstripes is equal to "(high - nparities) % nstripes". If you change above mentioned things you can retain my Reviewed-by: Daniel Kiper Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
From: Goffredo Baroncelli 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 Reviewed-by: Daniel Kiper --- grub-core/fs/btrfs.c | 60 +++- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index d066d54cc..d20ee09e4 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+"); @@ -702,11 +703,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; grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); @@ -779,6 +805,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", "enough disks for RAID 5 rebuilding: total %" @@ -789,7 +824,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); ret = GRUB_ERR_NONE; cleanup: @@ -879,9 +914,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) { @@ -1030,6 +1067,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, */ grub_divmod64 (high + stripen, nstripes, &stripen); + /* + * parities_pos is equal to "(high - nparities) % nstripes" + * (see the diagram above). + * However "high - nparities" might be negative (eg when high + * == 0) leading to an incorrect computation. + * Instead "high + nstripes - nparities" is always positive and + * in modulo nstripes is equal to "(high - nparities) % nstripes" + */ + grub_divmod64 (high + nstripes - nparities, nstripes, +&parities_pos); + stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1081,7 +1129,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } if (!err) break; -- 2.19.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On Thu, Sep 27, 2018 at 08:35:04PM +0200, Goffredo Baroncelli wrote: > From: Goffredo Baroncelli > > 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 Reviewed-by: Daniel Kiper Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
From: Goffredo Baroncelli 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 | 63 +++- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index db8df0eea..b49f714ef 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+"); @@ -702,11 +703,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; grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); @@ -777,6 +803,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", "enough disks for RAID 5 rebuilding: total %" @@ -787,7 +822,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); ret = GRUB_ERR_NONE; cleanup: @@ -877,9 +912,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) { @@ -1011,6 +1048,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, *size if the latter is smaller. * - nparities is the number of parities (1 for RAID5, 2 for *RAID6); used only in RAID5/6 code. + *size if the latter is smaller. + * - parities_pos is the position of the parity in a row ( + *2 for P1, 3 for P2...) */ stripe_nr = grub_divmod64 (off, chunk_stripe_length, &low); @@ -1029,6 +1069,17 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, */ grub_divmod64 (high + stripen, nstripes, &stripen); + /* + * parities_pos is equal to "(high - nparities) % nstripes" + * (see the diagram above). + * However "high - nparities" might be negative (eg when high + * == 0) leading to an incorrect computation. + * Instead "high + nstripes - nparities" is always positive and + * in modulo nstripes is equal to "(high - nparities) % nstripes" + */ + grub_divmod64 (high + nstripes - nparities, nstripes, +&parities_pos); + stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1080,7 +1131,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, gr
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On Wed, Sep 26, 2018 at 09:56:07PM +0200, Goffredo Baroncelli wrote: > On 25/09/2018 21.20, Daniel Kiper wrote: > > On Wed, Sep 19, 2018 at 08:40:40PM +0200, Goffredo Baroncelli wrote: > >> From: Goffredo Baroncelli > >> > [] > >> * - stripe_offset is the disk offset, > >> * - csize is the "potential" data to read. It will be reduced to > >> *size if the latter is smaller. > >> + * - parities_pos is the position of the parity inside a row ( > > > > s/inside/in/> > >> + *2 for P1, 3 for P2...) > > + * - nparities is the number of parities (1 for RAID5, 2 for > RAID6); > + *used only in RAID5/6 code. > > >> */ > >> block_nr = grub_divmod64 (off, chunk_stripe_length, &low); > >> > >> @@ -1030,6 +1069,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data > >> *data, grub_disk_addr_t addr, > >> */ > >> grub_divmod64 (high + stripen, nstripes, &stripen); > >> > >> +grub_divmod64 (high + nstripes - nparities, nstripes, > >> + &parities_pos); > > > > I think that this math requires a bit of explanation in the comment > > before grub_divmod64(). Especially I am interested in why high + > > nstripes - nparities works as expected. > > > What about > > /* > * parities_pos is equal to "(high - nparities) % nstripes" (see the diagram > above). > * However "high - nparities" might be negative (eg when high == 0) leading > to an > * incorrect computation. > * Instead "high + nstripes - nparities" is always positive and in modulo > nstripes is > * equal to "(high - nparities) % nstripes > */ LGTM. Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On 25/09/2018 21.20, Daniel Kiper wrote: > On Wed, Sep 19, 2018 at 08:40:40PM +0200, Goffredo Baroncelli wrote: >> From: Goffredo Baroncelli >> [] >> * - stripe_offset is the disk offset, >> * - csize is the "potential" data to read. It will be reduced to >> *size if the latter is smaller. >> + * - parities_pos is the position of the parity inside a row ( > > s/inside/in/> >> + *2 for P1, 3 for P2...) + * - nparities is the number of parities (1 for RAID5, 2 for RAID6); + *used only in RAID5/6 code. >> */ >>block_nr = grub_divmod64 (off, chunk_stripe_length, &low); >> >> @@ -1030,6 +1069,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, >> grub_disk_addr_t addr, >> */ >>grub_divmod64 (high + stripen, nstripes, &stripen); >> >> + grub_divmod64 (high + nstripes - nparities, nstripes, >> + &parities_pos); > > I think that this math requires a bit of explanation in the comment > before grub_divmod64(). Especially I am interested in why high + > nstripes - nparities works as expected. What about /* * parities_pos is equal to "(high - nparities) % nstripes" (see the diagram above). * However "high - nparities" might be negative (eg when high == 0) leading to an * incorrect computation. * Instead "high + nstripes - nparities" is always positive and in modulo nstripes is * equal to "(high - nparities) % nstripes */ > > Daniel > BR G.Baroncelli -- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On Wed, Sep 19, 2018 at 08:40:40PM +0200, Goffredo Baroncelli wrote: > From: Goffredo Baroncelli > > 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 | 54 +++- > 1 file changed, 48 insertions(+), 6 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index 55a7eeffc..400cd56b6 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; >grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); > @@ -787,6 +813,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", > "enough disks for RAID 5 rebuilding: total %" > @@ -797,7 +832,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) > @@ -886,9 +921,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) > { > @@ -1015,6 +1052,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, > * - stripe_offset is the disk offset, > * - csize is the "potential" data to read. It will be reduced to > *size if the latter is smaller. > +* - parities_pos is the position of the parity inside a row ( s/inside/in/ > +*2 for P1, 3 for P2...) > */ > block_nr = grub_divmod64 (off, chunk_stripe_length, &low); > > @@ -1030,6 +1069,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, > */ > grub_divmod64 (high + stripen, nstripes, &stripen); > > + grub_divmod64 (high + nstripes - nparities, nstripes, > + &parities_pos); I think that this math requires a bit of explanation in the comment before grub_divmod64(). Especially I am interested in why high + nstripes - nparities works as expected. Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
From: Goffredo Baroncelli 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 | 54 +++- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 55a7eeffc..400cd56b6 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; grub_uint64_t nstripes = grub_le_to_cpu16 (chunk->nstripes); @@ -787,6 +813,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", "enough disks for RAID 5 rebuilding: total %" @@ -797,7 +832,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) @@ -886,9 +921,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) { @@ -1015,6 +1052,8 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, * - stripe_offset is the disk offset, * - csize is the "potential" data to read. It will be reduced to *size if the latter is smaller. + * - parities_pos is the position of the parity inside a row ( + *2 for P1, 3 for P2...) */ block_nr = grub_divmod64 (off, chunk_stripe_length, &low); @@ -1030,6 +1069,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, */ grub_divmod64 (high + stripen, nstripes, &stripen); + grub_divmod64 (high + nstripes - nparities, nstripes, +&parities_pos); + stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1081,7 +1123,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err != GRUB_ERR_NONE) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } if (err == GRUB_ERR_NONE) break; -- 2.19.0 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-d
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
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 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
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); stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1093,7 +1132,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err != GRUB_ERR_NONE) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } if (err == GRUB_ERR_NONE) break; -- 2.18.0.rc2 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
On Sun, Jun 03, 2018 at 08:53:48PM +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 | 50 ++-- > 1 file changed, 44 insertions(+), 6 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index c8f034641..0b6557ce3 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+"); > > @@ -706,11 +707,35 @@ 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; > + > +grub_memcpy(dest, buffers[disk_nr].buf, size); > + > +grub_errno = buffers[disk_nr].data_is_valid ? GRUB_ERR_NONE : > + GRUB_ERR_READ_ERROR; > +return grub_errno; if (!buffers[disk_nr].data_is_valid) return GRUB_ERR_READ_ERROR; grub_memcpy(dest, buffers[disk_nr].buf, size); return GRUB_ERR_NONE; Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: Add RAID 6 recovery for a btrfs filesystem.
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 | 50 ++-- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index c8f034641..0b6557ce3 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+"); @@ -706,11 +707,35 @@ 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; + +grub_memcpy(dest, buffers[disk_nr].buf, size); + +grub_errno = buffers[disk_nr].data_is_valid ? GRUB_ERR_NONE : +GRUB_ERR_READ_ERROR; +return grub_errno; +} + +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; @@ -791,6 +816,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", @@ -803,7 +837,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: @@ -896,9 +930,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) { @@ -1043,6 +1079,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); stripe_offset = low + chunk_stripe_length * high; csize = chunk_stripe_length - low; @@ -1097,7 +1135,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, grub_errno = GRUB_ERR_NONE; if (err != GRUB_ERR_NONE) err = raid56_read_retry (data, chunk, stripe_offset, - csize, buf); + stripen, csize, buf, parities_pos); } if (err == GRUB_ERR_NONE) break; -- 2.17.1 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 9/9] btrfs: add RAID 6 recovery for a btrfs filesystem.
On 05/30/2018 02:15 PM, Daniel Kiper wrote: > On Wed, May 16, 2018 at 08:48:19PM +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 old md RAID 6 code already > > s/the old md/the md/ ok >> present in grub. >> >> Signed-off-by: Goffredo Baroncelli >> --- >> grub-core/fs/btrfs.c | 45 +++- >> 1 file changed, 40 insertions(+), 5 deletions(-) >> >> diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c >> index 5fcaad86f..3d71b954e 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+"); >> >> @@ -695,11 +696,35 @@ rebuild_raid5 (struct raid56_buffer *buffers, >> grub_uint64_t nstripes, >> csize); >> } >> >> +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; >> + >> +grub_memcpy(dest, buffers[disk_nr].buf, size); > > Could we avoid this grub_memcpy() call somehow? I would like; however this would mean that the handling of the raid 5 and raid 6 rebuilding code would be totally different. This has a big impact on the patches set and the related tests performed until now. Are you sure that this effort will be really needed ? > >> +grub_errno = buffers[disk_nr].data_is_valid ? GRUB_ERR_NONE : >> + GRUB_ERR_READ_ERROR; >> +return grub_errno; >> +} >> + >> +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, raid6_recover_read_buffer, 0); >> +} >> + >> 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 stripen, >> - grub_uint64_t csize, void *buf) >> + grub_uint64_t csize, void *buf, grub_uint64_t parities_pos) >> { >> >>struct raid56_buffer *buffers = NULL; >> @@ -780,6 +805,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", >> @@ -796,7 +830,7 @@ raid56_read_retry (struct grub_btrfs_data *data, >> } >>else >> { >> - grub_dprintf ("btrfs", "called rebuild_raid6(), NOT IMPLEMENTED\n"); >> + rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen); >> } >> >> cleanup: >> @@ -891,8 +925,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, >> grub_disk_addr_t addr, >> 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| > > Space before "|" please? OK > >> +GRUB_BTRFS_CHUNK_TYPE_RAID6)); >> >> if (grub_le_to_cpu64 (chunk->size) <= off) >>{ >> @@ -1089,7 +1124,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, >> grub_disk_addr_t addr, >> csize, buf); >> if (err != GRUB_ERR_NONE) >>err = raid56_read_retry (data, chunk, stripe_offset, >> - stripen, csize, buf); >> + stripen, csize, buf, parities_pos); > > I am not sure what is parities_pos and where it is initialized. > If it is a part of earlier patch but it is not used then I think > that it should be a part of this patch. You are right > > Daniel > I think that I implemented all your requests in the next patches set. The only exception is the removing the memcpy in the raid6 recovery path. Now I am starting the test. when I will completed the test phase, I will resend the patches. BR G.Baroncelli -- gpg @keyserver.linux.it: Goffredo Baroncelli Key fingerprint BBF5 1610 0B64 DAC6 5F7D 17B2 0EDA 9B37 8B82 E0B5 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.o
Re: [PATCH 9/9] btrfs: add RAID 6 recovery for a btrfs filesystem.
On Wed, May 16, 2018 at 08:48:19PM +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 old md RAID 6 code already s/the old md/the md/ > present in grub. > > Signed-off-by: Goffredo Baroncelli > --- > grub-core/fs/btrfs.c | 45 +++- > 1 file changed, 40 insertions(+), 5 deletions(-) > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > index 5fcaad86f..3d71b954e 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+"); > > @@ -695,11 +696,35 @@ rebuild_raid5 (struct raid56_buffer *buffers, > grub_uint64_t nstripes, > csize); > } > > +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; > + > +grub_memcpy(dest, buffers[disk_nr].buf, size); Could we avoid this grub_memcpy() call somehow? > +grub_errno = buffers[disk_nr].data_is_valid ? GRUB_ERR_NONE : > + GRUB_ERR_READ_ERROR; > +return grub_errno; > +} > + > +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, raid6_recover_read_buffer, 0); > +} > + > 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 stripen, > -grub_uint64_t csize, void *buf) > +grub_uint64_t csize, void *buf, grub_uint64_t parities_pos) > { > >struct raid56_buffer *buffers = NULL; > @@ -780,6 +805,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", > @@ -796,7 +830,7 @@ raid56_read_retry (struct grub_btrfs_data *data, > } >else > { > - grub_dprintf ("btrfs", "called rebuild_raid6(), NOT IMPLEMENTED\n"); > + rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen); > } > > cleanup: > @@ -891,8 +925,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, > 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| Space before "|" please? > + GRUB_BTRFS_CHUNK_TYPE_RAID6)); > > if (grub_le_to_cpu64 (chunk->size) <= off) > { > @@ -1089,7 +1124,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, > grub_disk_addr_t addr, >csize, buf); > if (err != GRUB_ERR_NONE) > err = raid56_read_retry (data, chunk, stripe_offset, > -stripen, csize, buf); > +stripen, csize, buf, parities_pos); I am not sure what is parities_pos and where it is initialized. If it is a part of earlier patch but it is not used then I think that it should be a part of this patch. Daniel ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
[PATCH 9/9] btrfs: add RAID 6 recovery for a btrfs filesystem.
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 old md RAID 6 code already present in grub. Signed-off-by: Goffredo Baroncelli --- grub-core/fs/btrfs.c | 45 +++- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index 5fcaad86f..3d71b954e 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+"); @@ -695,11 +696,35 @@ rebuild_raid5 (struct raid56_buffer *buffers, grub_uint64_t nstripes, csize); } +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; + +grub_memcpy(dest, buffers[disk_nr].buf, size); + +grub_errno = buffers[disk_nr].data_is_valid ? GRUB_ERR_NONE : +GRUB_ERR_READ_ERROR; +return grub_errno; +} + +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, raid6_recover_read_buffer, 0); +} + 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 stripen, - grub_uint64_t csize, void *buf) + grub_uint64_t csize, void *buf, grub_uint64_t parities_pos) { struct raid56_buffer *buffers = NULL; @@ -780,6 +805,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", @@ -796,7 +830,7 @@ raid56_read_retry (struct grub_btrfs_data *data, } else { - grub_dprintf ("btrfs", "called rebuild_raid6(), NOT IMPLEMENTED\n"); + rebuild_raid6 (buffers, nstripes, csize, parities_pos, buf, stripen); } cleanup: @@ -891,8 +925,9 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, 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) { @@ -1089,7 +1124,7 @@ grub_btrfs_read_logical (struct grub_btrfs_data *data, grub_disk_addr_t addr, csize, buf); if (err != GRUB_ERR_NONE) err = raid56_read_retry (data, chunk, stripe_offset, - stripen, csize, buf); + stripen, csize, buf, parities_pos); } if (err == GRUB_ERR_NONE) -- 2.17.0 ___ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel