Couple changes for Linux raid metadata 1.x support
Strange timing. I ran into needing support for 1.2 metadata a few days
ago. Wrote the code yesterday and when I pulled to check for conflicts before I submitted someone else had also just written the code.
Here are a few changes I had that are not in the tree:
- Don't use disks with outdated superblocks
- Don't use disks that are being rebuilt/transfomed
- Check superblock checksums
- Check superblock is in the correct location
- Update the recovery code to use the start_sector
Doug
=== modified file 'disk/dmraid_nvidia.c'
dmraid_nvidia.c +1 -0
@@ -137,6 +137,7 @@ array->number =0 ; array->total_devs = sb.array.total_volumes; array->chunk_size = sb.array.stripe_block_size; + array->freshness =0 ; array->index = sb.unit_number; array->uuid_len =sizeof (sb.array.signature); array->uuid =grub_malloc (sizeof (sb.array.signature));
=== modified file 'disk/mdraid_linux.c'
mdraid_linux.c +49 -0
85 lines not on this page · raw message
=== modified file 'disk/raid.c'
raid.c +31 -4
@@ -130,8 +130,8 @@ disk->id = array->number; disk->data = array; -grub_dprintf ("raid" ,"%s: total_devs=%d, disk_size=%lld\n" , name, - array->total_devs, (unsigned long long ) array->disk_size); +grub_dprintf ("raid" ,"%s: total_devs=%d, nr_devs=%d, disk_size=%lld\n" , name, + array->total_devs, array->nr_devs, (unsigned long long ) array->disk_size);switch (array->level) {
@@ -495,21 +495,48 @@/* FIXME: Check whether the update time of the superblocks are the same. */ +if (new_array->freshness < array->freshness) + { +/* This disk is outdated. Don't add it to the array. */ +grub_dprintf ("raid" ,"member '%s' is not fresh: disk: %llu, array: %llu\n" , + disk->name, new_array->freshness, array->freshness); +return grub_error (GRUB_ERR_OUT_OF_RANGE ,"disk not fresh" ); + } +if (array->total_devs == array->nr_devs)/* We found more members of the array than the array actually has according to its superblock. This shouldn't happen normally. */ -grub_dprintf ("raid" ,"array->nr_devs > array->total_devs (%d)?!?" , +grub_dprintf ("raid" ,"array->nr_devs > array->total_devs (%d)?!?\n" , array->total_devs);if (array->device[new_array->index] !=NULL )/* We found multiple devices with the same number. Again, this shouldn't happen. */ -grub_dprintf ("raid" ,"Found two disks with the number %d?!?" , +grub_dprintf ("raid" ,"Found two disks with the number %d?!?\n" , new_array->number);if (new_array->disk_size < array->disk_size) array->disk_size = new_array->disk_size; + +if (new_array->freshness > array->freshness) + { +int i; + +/* Kick out all already found array members that are outdated */ +for (i =0 ; i <GRUB_RAID_MAX_DEVICES ; i++) +if (array->device[i]) + { +grub_dprintf ("raid" ,"member '%s' is not fresh: disk: %llu, array: %llu\n" , + array->device[i]->name, array->freshness, new_array->freshness); +grub_disk_close (array->device[i]); + array->device[i] =0 ; + array->nr_devs--; + } + + array->freshness = new_array->freshness; + } +break ; }
=== modified file 'disk/raid5_recover.c'
raid5_recover.c +2 -1
@@ -45,7 +45,8 @@if (i == disknr)continue ; - err =grub_disk_read (array->device[i], sector,0 , size, buf2); + err =grub_disk_read (array->device[i], + array->start_sector[i] + sector,0 , size, buf2);if (err) {
=== modified file 'disk/raid6_recover.c'
raid6_recover.c +11 -5
@@ -119,7 +119,9 @@else {if ((array->device[pos]) && - (!grub_disk_read (array->device[pos], sector,0 , size, buf))) + (!grub_disk_read (array->device[pos], + array->start_sector[pos] + sector, +0 , size, buf))) {grub_raid_block_xor (pbuf, buf, size);grub_raid_block_mul (raid6_table2[i][i], buf, size);
@@ -149,7 +151,8 @@ {/* One bad device */ if ((array->device[p]) && - (!grub_disk_read (array->device[p], sector,0 , size, buf))) + (!grub_disk_read (array->device[p], + array->start_sector[p] + sector,0 , size, buf))) {grub_raid_block_xor (buf, pbuf, size); goto quit;
@@ -162,7 +165,8 @@ } grub_errno =GRUB_ERR_NONE ; -if (grub_disk_read (array->device[q], sector,0 , size, buf)) +if (grub_disk_read (array->device[q], array->start_sector[q] + sector, +0 , size, buf)) goto quit;grub_raid_block_xor (buf, qbuf, size);
@@ -180,12 +184,14 @@ goto quit; } -if (grub_disk_read (array->device[p], sector,0 , size, buf)) +if (grub_disk_read (array->device[p], array->start_sector[p] + sector, +0 , size, buf)) goto quit;grub_raid_block_xor (pbuf, buf, size); -if (grub_disk_read (array->device[q], sector,0 , size, buf)) +if (grub_disk_read (array->device[q], array->start_sector[q] + sector, +0 , size, buf)) goto quit;grub_raid_block_xor (qbuf, buf, size);
=== modified file 'include/grub/raid.h'
grub/raid.h +2 -0
@@ -43,6 +43,8 @@grub_size_t chunk_size;/* The size of a chunk, in 512 byte sectors. */ grub_uint64_t disk_size;/* Size of an individual disk, in 512 byte sectors. */ +grub_uint64_t freshness;/* Indicator of freshness of disk. All valid +devices will have the same highest number */ int index;/* Index of current device. */ int uuid_len;/* The length of uuid. */ char *uuid;/* The UUID of the device. */