Skip to contentSkip to conversation

Detect if we actually have partitions and print raid info in "ls -l"

PATCH Doug Nazar 2 participants 3 messages Jul 29, 2010

lore
Share & tools
lore

Doug Nazar

author
#0 lore raw

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

=== modified file 'include/grub/partition.h'

grub/partition.h +1 -0
@@ -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'

disk.c +4 -0
@@ -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'

partition.c +29 -0
@@ -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)
 {

=== modified file 'disk/dmraid_nvidia.c'

dmraid_nvidia.c +1 -0
@@ -156,6 +156,7 @@
 {
   .name = "dmraid_nv",
   .detect = grub_dmraid_nv_detect,
+  .uuid = 0,
   .next = 0
 };
 

=== modified file 'disk/mdraid_linux.c'

mdraid_linux.c +23 -0
@@ -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'

raid.c +34 -0
@@ -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'

grub/raid.h +3 -0
@@ -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'

misc.c +25 -6
@@ -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)

=== modified file 'disk/ieee1275/ofdisk.c'

ieee1275/ofdisk.c +5 -5
@@ -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;
 }
author
#1 lore raw
Quoted 6 lines · Doug Nazar

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'

common.rmk +1 -1
@@ -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'

raid.c +3 -1
@@ -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 @@
 
 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'

grub/raid.h +4 -1
@@ -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'

device.c +5 -0
@@ -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'

misc.c +5 -3
@@ -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);
#2 lore raw
Quoted 108 lines · Doug Nazar
Quoted 11 lines · Doug Nazar

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'

common.rmk +1 -1
@@ -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'

raid.c +3 -1
@@ -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 @@
 
 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'

grub/raid.h +4 -1
@@ -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'

device.c +5 -0
@@ -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'

misc.c +1 -1
@@ -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;

misc.c line 66

Quoted 10 lines
misc.c +4 -2
       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.

Signature · 1 line
Len Sorensen