* grub-core/disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Remove useless

grub_errors.
	* grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Simplify by
	not reloading whole superblock but only the part which is really needed.
	Remove useless grub_errors.
	* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Remove useless
	grub_errors.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-02-26 23:36:12 +01:00
parent e2a833958e
commit b2582b84f2
4 changed files with 79 additions and 114 deletions

View file

@ -1,3 +1,13 @@
2012-02-26 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/disk/dmraid_nvidia.c (grub_dmraid_nv_detect): Remove useless
grub_errors.
* grub-core/disk/mdraid1x_linux.c (grub_mdraid_detect): Simplify by
not reloading whole superblock but only the part which is really needed.
Remove useless grub_errors.
* grub-core/disk/mdraid_linux.c (grub_mdraid_detect): Remove useless
grub_errors.
2012-02-26 Vladimir Serbinenko <phcoder@gmail.com> 2012-02-26 Vladimir Serbinenko <phcoder@gmail.com>
Don't export grub_get_rtc. Don't export grub_get_rtc.

View file

@ -103,26 +103,20 @@ grub_dmraid_nv_detect (grub_disk_t disk,
char *uuid; char *uuid;
if (disk->partition) if (disk->partition)
{ /* Skip partition. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "skip partition");
return NULL; return NULL;
}
sector = grub_disk_get_size (disk); sector = grub_disk_get_size (disk);
if (sector == GRUB_DISK_SIZE_UNKNOWN) if (sector == GRUB_DISK_SIZE_UNKNOWN)
{ /* Not raid. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
return NULL; return NULL;
}
sector -= 2; sector -= 2;
if (grub_disk_read (disk, sector, 0, sizeof (sb), &sb)) if (grub_disk_read (disk, sector, 0, sizeof (sb), &sb))
return NULL; return NULL;
if (grub_memcmp (sb.vendor, NV_ID_STRING, 6)) if (grub_memcmp (sb.vendor, NV_ID_STRING, 6))
{ /* Not raid. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
return NULL; return NULL;
}
if (sb.version != NV_VERSION) if (sb.version != NV_VERSION)
{ {

View file

@ -108,9 +108,7 @@ grub_mdraid_detect (grub_disk_t disk,
struct grub_diskfilter_pv_id *id, struct grub_diskfilter_pv_id *id,
grub_disk_addr_t *start_sector) grub_disk_addr_t *start_sector)
{ {
grub_disk_addr_t sector = 0;
grub_uint64_t size; grub_uint64_t size;
struct grub_raid_super_1x sb;
grub_uint8_t minor_version; grub_uint8_t minor_version;
size = grub_disk_get_size (disk); size = grub_disk_get_size (disk);
@ -125,6 +123,13 @@ grub_mdraid_detect (grub_disk_t disk,
for (minor_version = 0; minor_version < 3; ++minor_version) for (minor_version = 0; minor_version < 3; ++minor_version)
{ {
grub_disk_addr_t sector = 0;
struct grub_raid_super_1x sb;
grub_uint16_t role;
grub_uint32_t level;
struct grub_diskfilter_vg *array;
char *uuid;
if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0) if (size == GRUB_DISK_SIZE_UNKNOWN && minor_version == 0)
continue; continue;
@ -145,22 +150,13 @@ grub_mdraid_detect (grub_disk_t disk,
&sb)) &sb))
return NULL; return NULL;
if (grub_le_to_cpu32 (sb.magic) != SB_MAGIC if (sb.magic != grub_cpu_to_le32_compile_time (SB_MAGIC)
|| grub_le_to_cpu64 (sb.super_offset) != sector) || grub_le_to_cpu64 (sb.super_offset) != sector)
continue; continue;
{ if (sb.major_version != grub_cpu_to_le32_compile_time (1))
grub_uint64_t sb_size; /* Unsupported version. */
struct grub_raid_super_1x *real_sb;
grub_uint32_t level;
if (grub_le_to_cpu32 (sb.major_version) != 1)
{
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"Unsupported RAID version: %d",
grub_le_to_cpu32 (sb.major_version));
return NULL; return NULL;
}
level = grub_le_to_cpu32 (sb.level); level = grub_le_to_cpu32 (sb.level);
@ -176,70 +172,47 @@ grub_mdraid_detect (grub_disk_t disk,
return NULL; return NULL;
} }
/* 1.x superblocks don't have a fixed size on disk. So we have to if (grub_le_to_cpu32 (sb.dev_number) >=
read it again now that we now the max device count. */ grub_le_to_cpu32 (sb.max_dev))
sb_size = sizeof (struct grub_raid_super_1x) /* Spares aren't implemented. */
+ 2 * grub_le_to_cpu32 (sb.max_dev);
real_sb = grub_malloc (sb_size);
if (! real_sb)
return NULL; return NULL;
if (grub_disk_read (disk, sector, 0, sb_size, real_sb)) if (grub_le_to_cpu32 (sb.dev_number)
{ >= grub_le_to_cpu32 (sb.raid_disks))
grub_free (real_sb); /* Spares aren't implemented. */
return NULL; return NULL;
}
struct grub_diskfilter_vg *array; if (grub_disk_read (disk, sector,
char *uuid; (char *) &sb.dev_roles[sb.dev_number]
- (char *) &sb,
if (grub_le_to_cpu32 (real_sb->dev_number) >= sizeof (role), &role))
grub_le_to_cpu32 (real_sb->max_dev))
{
grub_error (GRUB_ERR_OUT_OF_RANGE,
"spares aren't implemented");
return NULL; return NULL;
}
id->uuidlen = 0; id->uuidlen = 0;
id->id = grub_le_to_cpu16 id->id = grub_le_to_cpu16 (role);
(real_sb->dev_roles[grub_le_to_cpu32 (real_sb->dev_number)]);
uuid = grub_malloc (16); uuid = grub_malloc (16);
if (!uuid) if (!uuid)
{
grub_free (real_sb);
return NULL; return NULL;
}
grub_memcpy (uuid, real_sb->set_uuid, 16); grub_memcpy (uuid, sb.set_uuid, 16);
*start_sector = grub_le_to_cpu64 (real_sb->data_offset); *start_sector = grub_le_to_cpu64 (sb.data_offset);
if (grub_le_to_cpu32 (real_sb->dev_number)
>= grub_le_to_cpu32 (real_sb->raid_disks))
{
grub_error (GRUB_ERR_OUT_OF_RANGE,
"spares aren't implemented");
return NULL;
}
array = grub_diskfilter_make_raid (16, uuid, array = grub_diskfilter_make_raid (16, uuid,
grub_le_to_cpu32 (real_sb->raid_disks), grub_le_to_cpu32 (sb.raid_disks),
real_sb->set_name, sb.set_name,
(real_sb->size) (sb.size)
? grub_le_to_cpu64 (real_sb->size) ? grub_le_to_cpu64 (sb.size)
: grub_le_to_cpu64 (real_sb->data_size), : grub_le_to_cpu64 (sb.data_size),
grub_le_to_cpu32 (real_sb->chunksize), grub_le_to_cpu32 (sb.chunksize),
grub_le_to_cpu32 (real_sb->layout), grub_le_to_cpu32 (sb.layout),
grub_le_to_cpu32 (real_sb->level)); grub_le_to_cpu32 (sb.level));
grub_free (real_sb);
return array; return array;
} }
}
grub_error (GRUB_ERR_OUT_OF_RANGE, "not 1.x raid"); /* not 1.x raid. */
return NULL; return NULL;
} }

View file

@ -175,31 +175,22 @@ grub_mdraid_detect (grub_disk_t disk,
/* The sector where the mdraid 0.90 superblock is stored, if available. */ /* The sector where the mdraid 0.90 superblock is stored, if available. */
size = grub_disk_get_size (disk); size = grub_disk_get_size (disk);
if (size == GRUB_DISK_SIZE_UNKNOWN) if (size == GRUB_DISK_SIZE_UNKNOWN)
{ /* not 0.9x raid. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
return NULL; return NULL;
}
sector = NEW_SIZE_SECTORS (size); sector = NEW_SIZE_SECTORS (size);
if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb)) if (grub_disk_read (disk, sector, 0, SB_BYTES, &sb))
return NULL; return NULL;
/* Look whether there is a mdraid 0.90 superblock. */ /* Look whether there is a mdraid 0.90 superblock. */
if (grub_le_to_cpu32 (sb.md_magic) != SB_MAGIC) if (sb.md_magic != grub_cpu_to_le32_compile_time (SB_MAGIC))
{ /* not 0.9x raid. */
grub_error (GRUB_ERR_OUT_OF_RANGE, "not 0.9x raid");
return NULL; return NULL;
}
if (grub_le_to_cpu32 (sb.major_version) != 0 if (sb.major_version != grub_cpu_to_le32_compile_time (0)
|| grub_le_to_cpu32 (sb.minor_version) != 90) || sb.minor_version != grub_cpu_to_le32_compile_time (90))
{ /* Unsupported version. */
grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"unsupported RAID version: %d.%d",
grub_le_to_cpu32 (sb.major_version),
grub_le_to_cpu32 (sb.minor_version));
return NULL; return NULL;
}
/* FIXME: Check the checksum. */ /* FIXME: Check the checksum. */
@ -217,11 +208,8 @@ grub_mdraid_detect (grub_disk_t disk,
} }
if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff if (grub_le_to_cpu32 (sb.this_disk.number) == 0xffff
|| grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe) || grub_le_to_cpu32 (sb.this_disk.number) == 0xfffe)
{ /* Spares aren't implemented. */
grub_error (GRUB_ERR_OUT_OF_RANGE,
"spares aren't implemented");
return NULL; return NULL;
}
uuid = grub_malloc (16); uuid = grub_malloc (16);
if (!uuid) if (!uuid)