* Detect if we actually have partitions and print raid info in "ls -l"
@ 2010-07-29 4:06 Doug Nazar
2010-07-29 8:14 ` Doug Nazar
0 siblings, 1 reply; 3+ messages in thread
From: Doug Nazar @ 2010-07-29 4:06 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]
Here are a couple more patches to cleanup the raid user interface a
little.
The first detects if there are actually partitions on the disk. Only
kicks in if we open the whole disk and the underlying subsystem says
there might be partitions. Slight semantic change is that has_partitions
now really means it has partitions rather then might have partitions.
This cleans up the tab completion of devices that may have partitions
but we're using the full disk (i.e. usually raid devices, lvms, etc.)
The second expands the 'ls -l' output to include raid information.
Previously depending on the raid metadata layout, it was possible to
detect the filesystem on the underlying raid partition. So now it checks
for raid devices first and if detected prints out the raid info. This
probably requires the previous patches for raid that have been posted in
the last few days. Holler if you want a roll-up patch.
Partition ide1,apple9: RAID6, md/1 - Disk 2/4, UUID
5c991134-a98c-2396-7204-9d6b077d2840
The last patch fixes a small error I had in the calculation of ofdisk
sizes and also prints the device with the seek/read error.
Doug
[-- Attachment #2: grub-detect-if-we-really-have-partitions.diff --]
[-- Type: text/plain, Size: 1794 bytes --]
=== modified file 'include/grub/partition.h'
--- include/grub/partition.h 2010-07-14 09:26:17 +0000
+++ include/grub/partition.h 2010-07-29 01:03:11 +0000
@@ -72,6 +72,7 @@
int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
int (*hook) (struct grub_disk *disk,
const grub_partition_t partition));
+int EXPORT_FUNC(grub_partition_detect) (struct grub_disk *disk);
char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
=== modified file 'kern/disk.c'
--- kern/disk.c 2010-02-07 00:48:38 +0000
+++ kern/disk.c 2010-07-29 01:13:07 +0000
@@ -298,6 +298,10 @@
goto fail;
}
}
+ else if (disk->has_partitions)
+ {
+ disk->has_partitions = grub_partition_detect(disk);
+ }
/* The cache will be invalidated about 2 seconds after a device was
closed. */
=== modified file 'kern/partition.c'
--- kern/partition.c 2010-07-16 23:55:01 +0000
+++ kern/partition.c 2010-07-29 01:07:42 +0000
@@ -219,6 +219,35 @@
return ret;
}
+int
+grub_partition_detect (struct grub_disk *disk)
+{
+ const struct grub_partition_map *partmap;
+ int found = 0;
+
+ auto int part_iterate (grub_disk_t dsk, const grub_partition_t p);
+
+ int part_iterate (grub_disk_t dsk __attribute((unused)),
+ const grub_partition_t partition __attribute((unused)))
+ {
+ found = 1;
+ /* It's not really an error, just want to short-circut the interation */
+ return grub_error(GRUB_ERR_TEST_FAILURE, "Partition found");
+ }
+
+ FOR_PARTITION_MAPS(partmap)
+ {
+ grub_err_t err;
+ err = partmap->iterate (disk, part_iterate);
+ if (err)
+ grub_errno = GRUB_ERR_NONE;
+ if (found)
+ break;
+ }
+
+ return found;
+}
+
char *
grub_partition_get_name (const grub_partition_t partition)
{
[-- Attachment #3: grub-print-raid-info-in-ls.diff --]
[-- Type: text/plain, Size: 3980 bytes --]
=== modified file 'disk/dmraid_nvidia.c'
--- disk/dmraid_nvidia.c 2010-07-23 05:25:00 +0000
+++ disk/dmraid_nvidia.c 2010-07-29 02:36:07 +0000
@@ -156,6 +156,7 @@
{
.name = "dmraid_nv",
.detect = grub_dmraid_nv_detect,
+ .uuid = 0,
.next = 0
};
=== modified file 'disk/mdraid_linux.c'
--- disk/mdraid_linux.c 2010-07-28 03:18:33 +0000
+++ disk/mdraid_linux.c 2010-07-29 02:38:44 +0000
@@ -475,9 +475,32 @@
return grub_error (GRUB_ERR_OUT_OF_RANGE, "not raid");
}
+static char *
+grub_mdraid_uuid (struct grub_raid_array *array)
+{
+ char *uuid;
+ grub_uint16_t *data;
+
+ if (!array || !array->uuid_len || !array->uuid)
+ return 0;
+
+ data = (grub_uint16_t *)array->uuid;
+ uuid = grub_xasprintf ("%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
+ grub_be_to_cpu16 (data[0]),
+ grub_be_to_cpu16 (data[1]),
+ grub_be_to_cpu16 (data[2]),
+ grub_be_to_cpu16 (data[3]),
+ grub_be_to_cpu16 (data[4]),
+ grub_be_to_cpu16 (data[5]),
+ grub_be_to_cpu16 (data[6]),
+ grub_be_to_cpu16 (data[7]));
+ return uuid;
+}
+
static struct grub_raid grub_mdraid_dev = {
.name = "mdraid",
.detect = grub_mdraid_detect,
+ .uuid = grub_mdraid_uuid,
.next = 0
};
=== modified file 'disk/raid.c'
--- disk/raid.c 2010-07-28 07:55:56 +0000
+++ disk/raid.c 2010-07-29 02:20:47 +0000
@@ -726,6 +726,40 @@
}
}
+struct grub_raid_array *
+grub_raid_probe(grub_device_t dev, int *index, char **uuid)
+{
+ struct grub_raid *p;
+
+ if (!dev->disk)
+ return 0;
+
+ for (p = grub_raid_list; p; p = p->next)
+ {
+ struct grub_raid_array array;
+
+ if (p->detect && !p->detect(dev->disk, &array, 0))
+ {
+ struct grub_raid_array *a;
+
+ for (a = array_list; a != NULL; a = a->next)
+ if ((a->uuid_len == array.uuid_len) &&
+ (! grub_memcmp (a->uuid, array.uuid, a->uuid_len)))
+ {
+ if (index)
+ *index = array.index;
+ if (uuid && p->uuid)
+ *uuid = p->uuid(a);
+ return a;
+ }
+ }
+
+ grub_errno = 0;
+ }
+
+ return 0;
+}
+
static struct grub_disk_dev grub_raid_dev =
{
.name = "raid",
=== modified file 'include/grub/raid.h'
--- include/grub/raid.h 2010-07-23 05:25:00 +0000
+++ include/grub/raid.h 2010-07-29 02:17:04 +0000
@@ -64,6 +64,7 @@
grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array,
grub_disk_addr_t *start_sector);
+ char * (*uuid) (struct grub_raid_array *array);
struct grub_raid *next;
};
@@ -74,6 +75,8 @@
void grub_raid_block_xor (char *buf1, const char *buf2, int size);
+struct grub_raid_array * grub_raid_probe(grub_device_t dev, int *index, char **uuid);
+
typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
int disknr, char *buf,
grub_disk_addr_t sector,
=== modified file 'normal/misc.c'
--- normal/misc.c 2010-03-15 10:49:27 +0000
+++ normal/misc.c 2010-07-29 02:37:44 +0000
@@ -26,6 +26,7 @@
#include <grub/datetime.h>
#include <grub/term.h>
#include <grub/i18n.h>
+#include <grub/raid.h>
/* Print the information on the device NAME. */
grub_err_t
@@ -53,12 +54,30 @@
else if (dev->disk)
{
grub_fs_t fs;
-
- fs = grub_fs_probe (dev);
- /* Ignore all errors. */
- grub_errno = 0;
-
- if (fs)
+ struct grub_raid_array *array;
+ int disk_index;
+ char *array_uuid = 0;
+
+ array = grub_raid_probe(dev, &disk_index, &array_uuid);
+ if (!array)
+ {
+ fs = grub_fs_probe (dev);
+ /* Ignore all errors. */
+ grub_errno = 0;
+ }
+
+ if (array)
+ {
+ grub_printf ("RAID%u %s - Disk %u/%u",
+ array->level, array->name,
+ disk_index, array->total_devs);
+ if (array_uuid)
+ {
+ grub_printf (", UUID %s", array_uuid);
+ grub_free (array_uuid);
+ }
+ }
+ else if (fs)
{
grub_printf_ (N_("Filesystem type %s"), fs->name);
if (fs->label)
[-- Attachment #4: grub-fix-error-in-ofdisk-size-calc.diff --]
[-- Type: text/plain, Size: 1029 bytes --]
=== modified file 'disk/ieee1275/ofdisk.c'
--- disk/ieee1275/ofdisk.c 2010-07-28 07:55:56 +0000
+++ disk/ieee1275/ofdisk.c 2010-07-29 03:58:16 +0000
@@ -264,7 +264,7 @@
}
- if (size > 1024)
+ if (curr > 1024 && size == 512)
disk->total_sectors = curr / 512;
op->size = disk->total_sectors;
}
@@ -303,13 +303,13 @@
pos, &status);
if (status < 0)
return grub_error (GRUB_ERR_READ_ERROR,
- "seek error, can't seek block %llu",
- (long long) sector);
+ "seek error, can't seek on '%s' at block %llu",
+ disk->name, (long long) sector);
grub_ieee1275_read ((grub_ieee1275_ihandle_t) (unsigned long) disk->data,
buf, size * 512UL, &actual);
if (actual != (grub_ssize_t) (size * 512UL))
- return grub_error (GRUB_ERR_READ_ERROR, "read error on block: %llu",
- (long long) sector);
+ return grub_error (GRUB_ERR_READ_ERROR, "read error on '%s' at block: %llu",
+ disk->name, (long long) sector);
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Detect if we actually have partitions and print raid info in "ls -l"
2010-07-29 4:06 Detect if we actually have partitions and print raid info in "ls -l" Doug Nazar
@ 2010-07-29 8:14 ` Doug Nazar
2010-07-29 15:37 ` Lennart Sorensen
0 siblings, 1 reply; 3+ messages in thread
From: Doug Nazar @ 2010-07-29 8:14 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
On 2010-07-29 12:06 AM, Doug Nazar wrote:
>
> The second expands the 'ls -l' output to include raid information.
> Previously depending on the raid metadata layout, it was possible to
> detect the filesystem on the underlying raid partition. So now it
> checks for raid devices first and if detected prints out the raid
> info. This probably requires the previous patches for raid that have
> been posted in the last few days. Holler if you want a roll-up patch.
>
> Partition ide1,apple9: RAID6, md/1 - Disk 2/4, UUID
> 5c991134-a98c-2396-7204-9d6b077d2840
>
Realized I'd added a dependency on the raid module. This patch cleans
that up.
Doug
[-- Attachment #2: grub-print-raid-info-remove-dependency.diff --]
[-- Type: text/plain, Size: 2983 bytes --]
=== modified file 'conf/common.rmk'
--- conf/common.rmk 2010-07-06 18:27:55 +0000
+++ conf/common.rmk 2010-07-29 08:01:45 +0000
@@ -104,7 +104,7 @@
kernel_img_HEADERS += boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
- list.h command.h i18n.h env_private.h libgcc.h
+ list.h command.h i18n.h env_private.h libgcc.h raid.h
ifneq ($(platform), emu)
kernel_img_HEADERS += machine/memory.h machine/loader.h
=== modified file 'disk/raid.c'
--- disk/raid.c 2010-07-29 04:26:32 +0000
+++ disk/raid.c 2010-07-29 07:42:28 +0000
@@ -724,7 +724,7 @@
}
}
-struct grub_raid_array *
+static struct grub_raid_array *
grub_raid_probe(grub_device_t dev, int *index, char **uuid)
{
struct grub_raid *p;
@@ -776,11 +776,13 @@
\f
GRUB_MOD_INIT(raid)
{
+ grub_raid_probe_func = grub_raid_probe;
grub_disk_dev_register (&grub_raid_dev);
}
GRUB_MOD_FINI(raid)
{
grub_disk_dev_unregister (&grub_raid_dev);
+ grub_raid_probe_func = 0;
free_array ();
}
=== modified file 'include/grub/raid.h'
--- include/grub/raid.h 2010-07-29 02:47:49 +0000
+++ include/grub/raid.h 2010-07-29 08:08:27 +0000
@@ -75,7 +75,9 @@
void grub_raid_block_xor (char *buf1, const char *buf2, int size);
-struct grub_raid_array * grub_raid_probe(grub_device_t dev, int *index, char **uuid);
+typedef struct grub_raid_array * (*grub_raid_probe_func_t) (grub_device_t dev,
+ int *index,
+ char **uuid);
typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
int disknr, char *buf,
@@ -89,5 +91,6 @@
extern grub_raid5_recover_func_t grub_raid5_recover_func;
extern grub_raid6_recover_func_t grub_raid6_recover_func;
+extern grub_raid_probe_func_t EXPORT_VAR(grub_raid_probe_func);
#endif /* ! GRUB_RAID_H */
=== modified file 'kern/device.c'
--- kern/device.c 2010-03-31 20:03:48 +0000
+++ kern/device.c 2010-07-29 07:47:45 +0000
@@ -25,6 +25,11 @@
#include <grub/misc.h>
#include <grub/env.h>
#include <grub/partition.h>
+#include <grub/raid.h>
+
+/* Toss it here for now. Perhaps in the future expand it to a
+ generic helper function that checks raid, lvm, etc. */
+grub_raid_probe_func_t grub_raid_probe_func;
grub_device_t
grub_device_open (const char *name)
=== modified file 'normal/misc.c'
--- normal/misc.c 2010-07-29 02:47:49 +0000
+++ normal/misc.c 2010-07-29 07:44:38 +0000
@@ -54,11 +54,13 @@
else if (dev->disk)
{
grub_fs_t fs;
- struct grub_raid_array *array;
+ struct grub_raid_array *array = 0;
int disk_index;
char *array_uuid = 0;
-
- array = grub_raid_probe(dev, &disk_index, &array_uuid);
+
+ if (grub_raid_probe_func)
+ array = (*grub_raid_probe_func)(dev, &disk_index, &array_uuid);
+
if (!array)
{
fs = grub_fs_probe (dev);
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Detect if we actually have partitions and print raid info in "ls -l"
2010-07-29 8:14 ` Doug Nazar
@ 2010-07-29 15:37 ` Lennart Sorensen
0 siblings, 0 replies; 3+ messages in thread
From: Lennart Sorensen @ 2010-07-29 15:37 UTC (permalink / raw)
To: The development of GNU GRUB
On Thu, Jul 29, 2010 at 04:14:00AM -0400, Doug Nazar wrote:
> On 2010-07-29 12:06 AM, Doug Nazar wrote:
>>
>> The second expands the 'ls -l' output to include raid information.
>> Previously depending on the raid metadata layout, it was possible to
>> detect the filesystem on the underlying raid partition. So now it
>> checks for raid devices first and if detected prints out the raid
>> info. This probably requires the previous patches for raid that have
>> been posted in the last few days. Holler if you want a roll-up patch.
>>
>> Partition ide1,apple9: RAID6, md/1 - Disk 2/4, UUID
>> 5c991134-a98c-2396-7204-9d6b077d2840
>>
>
> Realized I'd added a dependency on the raid module. This patch cleans
> that up.
>
> Doug
>
> === modified file 'conf/common.rmk'
> --- conf/common.rmk 2010-07-06 18:27:55 +0000
> +++ conf/common.rmk 2010-07-29 08:01:45 +0000
> @@ -104,7 +104,7 @@
> kernel_img_HEADERS += boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
> env.h err.h file.h fs.h kernel.h loader.h misc.h mm.h net.h parser.h \
> partition.h msdos_partition.h reader.h symbol.h term.h time.h types.h \
> - list.h command.h i18n.h env_private.h libgcc.h
> + list.h command.h i18n.h env_private.h libgcc.h raid.h
>
> ifneq ($(platform), emu)
> kernel_img_HEADERS += machine/memory.h machine/loader.h
>
> === modified file 'disk/raid.c'
> --- disk/raid.c 2010-07-29 04:26:32 +0000
> +++ disk/raid.c 2010-07-29 07:42:28 +0000
> @@ -724,7 +724,7 @@
> }
> }
>
> -struct grub_raid_array *
> +static struct grub_raid_array *
> grub_raid_probe(grub_device_t dev, int *index, char **uuid)
> {
> struct grub_raid *p;
> @@ -776,11 +776,13 @@
> \f
> GRUB_MOD_INIT(raid)
> {
> + grub_raid_probe_func = grub_raid_probe;
> grub_disk_dev_register (&grub_raid_dev);
> }
>
> GRUB_MOD_FINI(raid)
> {
> grub_disk_dev_unregister (&grub_raid_dev);
> + grub_raid_probe_func = 0;
> free_array ();
> }
>
> === modified file 'include/grub/raid.h'
> --- include/grub/raid.h 2010-07-29 02:47:49 +0000
> +++ include/grub/raid.h 2010-07-29 08:08:27 +0000
> @@ -75,7 +75,9 @@
>
> void grub_raid_block_xor (char *buf1, const char *buf2, int size);
>
> -struct grub_raid_array * grub_raid_probe(grub_device_t dev, int *index, char **uuid);
> +typedef struct grub_raid_array * (*grub_raid_probe_func_t) (grub_device_t dev,
> + int *index,
> + char **uuid);
>
> typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
> int disknr, char *buf,
> @@ -89,5 +91,6 @@
>
> extern grub_raid5_recover_func_t grub_raid5_recover_func;
> extern grub_raid6_recover_func_t grub_raid6_recover_func;
> +extern grub_raid_probe_func_t EXPORT_VAR(grub_raid_probe_func);
>
> #endif /* ! GRUB_RAID_H */
>
> === modified file 'kern/device.c'
> --- kern/device.c 2010-03-31 20:03:48 +0000
> +++ kern/device.c 2010-07-29 07:47:45 +0000
> @@ -25,6 +25,11 @@
> #include <grub/misc.h>
> #include <grub/env.h>
> #include <grub/partition.h>
> +#include <grub/raid.h>
> +
> +/* Toss it here for now. Perhaps in the future expand it to a
> + generic helper function that checks raid, lvm, etc. */
> +grub_raid_probe_func_t grub_raid_probe_func;
>
> grub_device_t
> grub_device_open (const char *name)
>
> === modified file 'normal/misc.c'
> --- normal/misc.c 2010-07-29 02:47:49 +0000
> +++ normal/misc.c 2010-07-29 07:44:38 +0000
> @@ -54,11 +54,13 @@
> else if (dev->disk)
> {
> grub_fs_t fs;
> - struct grub_raid_array *array;
> + struct grub_raid_array *array = 0;
> int disk_index;
> char *array_uuid = 0;
> -
> - array = grub_raid_probe(dev, &disk_index, &array_uuid);
> +
> + if (grub_raid_probe_func)
> + array = (*grub_raid_probe_func)(dev, &disk_index, &array_uuid);
> +
> if (!array)
> {
> fs = grub_fs_probe (dev);
>
OK, I added your last 5 or so patches, and yes the tab completion works
great now on the md raid devices without partitions.
Booting without devaliases on the other hand not so much. See comment
on the patch in that thread.
--
Len Sorensen
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-29 15:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-29 4:06 Detect if we actually have partitions and print raid info in "ls -l" Doug Nazar
2010-07-29 8:14 ` Doug Nazar
2010-07-29 15:37 ` Lennart Sorensen
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.