Skip to contentSkip to conversation

Bug fix for LVM

PATCH In review Bean 6 participants 28 messages Jul 18, 2009 – Aug 6, 2009

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 Bug fix for LVM

Hi,

This patch fixes a few bug in lvm.

There can be multiple copies of meta data, it's not an error, ignore the extra copy instead of quit.

In case of LVM on RAID, the raid device and first disk would have the same lvm header ! The raid device would be found first, so we don't replace pv->disk if it has been set.

grub-probe doesn't work in LVM on RAID, as it only assume one layer of abstraction, the fix is not to rely on os, but uses grub to get the correct abstraction information.

Fix grub-fstest to support lvm.

Signature · 1 line
Bean
disk/lvm.c +6 -9
index 6707a40..126b494 100644
@@ -271,15 +271,9 @@ grub_lvm_scan_device (const char *name)
   dlocn++;
   mda_offset = grub_le_to_cpu64 (dlocn->offset);
   mda_size = grub_le_to_cpu64 (dlocn->size);
-  dlocn++;
 
-  if (dlocn->offset)
-    {
-      grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-		  "We don't support multiple LVM metadata areas");
-
-      goto fail;
-    }
+  /* It's possible to have multiple copies of metadata areas, we just use the
+     first one.  */
 
   /* Allocate buffer space for the circular worst-case scenario. */
   metadatabuf = grub_malloc (2 * mda_size);
@@ -564,7 +558,10 @@ grub_lvm_scan_device (const char *name)
       {
 	if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN))
 	  {
-	    pv->disk = grub_disk_open (name);
+	    /* This could happen to LVM on RAID, pv->disk points to the
+	       raid device, we shouldn't change it.  */
+	    if (! pv->disk)
+	      pv->disk = grub_disk_open (name);
 	    break;
 	  }
       }
util/grub-fstest.c +2 -0
index 4722269..c39529a 100644
@@ -294,6 +294,8 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
     }
 
   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();
   switch (cmd)
     {
     case CMD_LS:
util/grub-probe.c +34 -25

85 lines not on this page · raw message

#1 lore raw

util/grub-fstest.c fstest (char **images, int num_disks, int cmd, int n, char **args) · line 298

Quoted 5 lines · Bean
     }
   grub_raid_rescan ();
util/grub-fstest.c +2 -0
+  grub_lvm_fini ();
+  grub_lvm_init ();

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function. It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc. It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init(). Could you fix this while at it?

util/grub-probe.c probe (const char *path, char *device_name) · line 120

Quoted 9 lines

#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
if (! grub_util_check_char_device (device_name))

util/grub-probe.c +2 -2
-        grub_util_error ("%s is not a character device.\n", device_name);
+	grub_util_error ("%s is not a character device.\n", device_name);
 #else
       if (! grub_util_check_block_device (device_name))
-        grub_util_error ("%s is not a block device.\n", device_name);
+	grub_util_error ("%s is not a block device.\n", device_name);
 #endif

Looks like this slipped in.

util/grub-probe.c probe (const char *path, char *device_name) · line 151

Quoted 3 lines
util/grub-probe.c +3 -0
+  if (print == PRINT_ABSTRACTION)
+    {
+      char buf[30];

This is a buffer overflow waiting to happen. Please use asprintf(), this will help you avoid the "&buf[1]" hack.

util/grub-probe.c probe (const char *path, char *device_name) · line 154

Quoted 3 lines
util/grub-probe.c +3 -0
+      grub_disk_memberlist_t list = NULL, tmp;
+      int is_lvm = 0;
+      int is_raid = 0;

I think you can add const qualifier in the is_lvm one.

util/grub-probe.c probe (const char *path, char *device_name) · line 157

Quoted 2 lines
util/grub-probe.c +2 -0
+      is_lvm = (dev->disk->dev->id == GRUB_DISK_DEVICE_LVM_ID);
+      is_raid |= (dev->disk->dev->id == GRUB_DISK_DEVICE_RAID_ID);

No need for logic OR here.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#2 lore raw
Quoted 7 lines · Robert Millan
Quoted 5 lines · Bean

     }

   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();

Quoted 6 lines

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function.  It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc.  It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init().  Could you fix this while at it?

This is required. As raid and lvm scan device in init function, but grub-fstest uses loopback device, which hasn't been setup in grub_init_all. This code rescan raid and lvm, otherwise there won't be available.

Quoted 11 lines
Quoted 3 lines

+  if (print == PRINT_ABSTRACTION)
+    {
+      char buf[30];

This is a buffer overflow waiting to happen.  Please use asprintf(), this will help you avoid the "&buf[1]" hack.

Quoted 3 lines

+      grub_disk_memberlist_t list = NULL, tmp;
+      int is_lvm = 0;
+      int is_raid = 0;

Quoted 6 lines

I think you can add const qualifier in the is_lvm one.

Quoted 2 lines

+      is_lvm = (dev->disk->dev->id == GRUB_DISK_DEVICE_LVM_ID);
+      is_raid |= (dev->disk->dev->id == GRUB_DISK_DEVICE_RAID_ID);

No need for logic OR here.

Ok.

Signature · 1 line
Bean
#3 lore raw
Quoted 15 lines · Bean
Quoted 7 lines · Robert Millan
Quoted 5 lines · Bean

     }

   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();

Quoted 6 lines

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function.  It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc.  It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init().  Could you fix this while at it?

Quoted 4 lines

This is required. As raid and lvm scan device in init function, but grub-fstest uses loopback device, which hasn't been setup in grub_init_all. This code rescan raid and lvm, otherwise there won't be available.

Ok, then please could you ifdef it for GRUB_UTIL ?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw
In reply to Bean
Quoted 15 lines · Bean
Quoted 7 lines · Robert Millan
Quoted 5 lines · Bean

     }

   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();

Quoted 6 lines

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function.  It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc.  It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init().  Could you fix this while at it?

Quoted 5 lines

This is required. As raid and lvm scan device in init function, but grub-fstest uses loopback device, which hasn't been setup in grub_init_all. This code rescan raid and lvm, otherwise there won't be available.

This situation isn't strictly speaking restricted to grub-fstest then. One would sensibly want to loopmount lvm image in grub shell. Is there a way to do it cleanly?

Quoted 29 lines
Quoted 11 lines
Quoted 3 lines

+  if (print == PRINT_ABSTRACTION)
+    {
+      char buf[30];

This is a buffer overflow waiting to happen.  Please use asprintf(), this will help you avoid the "&buf[1]" hack.

Quoted 3 lines

+      grub_disk_memberlist_t list = NULL, tmp;
+      int is_lvm = 0;
+      int is_raid = 0;

Quoted 6 lines

I think you can add const qualifier in the is_lvm one.

Quoted 2 lines

+      is_lvm = (dev->disk->dev->id == GRUB_DISK_DEVICE_LVM_ID);
+      is_raid |= (dev->disk->dev->id == GRUB_DISK_DEVICE_RAID_ID);

No need for logic OR here.

Ok.

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 4 lines
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
#5 lore raw
Quoted 16 lines · Vladimir 'phcoder' Serbinenko
Quoted 15 lines · Bean
Quoted 13 lines · Robert Millan
Quoted 5 lines · Bean

     }

   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function.  It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc.  It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init().  Could you fix this while at it?

Quoted 8 lines
Quoted 5 lines

This is required. As raid and lvm scan device in init function, but grub-fstest uses loopback device, which hasn't been setup in grub_init_all. This code rescan raid and lvm, otherwise there won't be available.

This situation isn't strictly speaking restricted to grub-fstest then. One would sensibly want to loopmount lvm image in grub shell. Is there a way to do it cleanly?

I think a good long-term solution is to move the scan function from grub_raid_init() to wheereever appropiate to make the scan happen dynamically everytime e.g. the iterate() function is called. However, doing this efficiently needs some work.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#6 lore raw
Quoted 22 lines · Robert Millan
Quoted 21 lines · Vladimir 'phcoder' Serbinenko
Quoted 20 lines · Bean
Quoted 7 lines · Robert Millan
Quoted 5 lines · Bean

     }

   grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_lvm_init ();

Quoted 6 lines

This is aside from this patch, but I don't see the purpose of this grub_raid_rescan() function.  It's in raid.mod but only used by grub-fstest, so at least it should be #ifdef'ed out, but looking at what it does, it seems very ad-hoc.  It basically amounts to the same you're doing with grub_lvm_fini() and grub_lvm_init().  Could you fix this while at it?

This is required. As raid and lvm scan device in init function, but grub-fstest uses loopback device, which hasn't been setup in grub_init_all. This code rescan raid and lvm, otherwise there won't be available.

Quoted 8 lines
Quoted 3 lines

This situation isn't strictly speaking restricted to grub-fstest then. One would sensibly want to loopmount lvm image in grub shell. Is there a way to do it cleanly?

I think a good long-term solution is to move the scan function from grub_raid_init() to wheereever appropiate to make the scan happen dynamically everytime e.g. the iterate() function is called.  However, doing this efficiently needs some work.

Hi,

I've come up an alternative solution to grub_raid_rescan, we can use the same trick as lvm, call fini and then init function, this would have the same effect of rescanning. Now that grub_raid_rescan is gone, I can simply raid.c further by moving grub_raid_scan_device into grub_raid_register.

As for dynamically scanning, I think it's not common to mount lvm/raid in loopback files, we could just ignore it for now.

Signature · 1 line
Bean
disk/lvm.c +6 -9
index 6707a40..126b494 100644
@@ -271,15 +271,9 @@ grub_lvm_scan_device (const char *name)
   dlocn++;
   mda_offset = grub_le_to_cpu64 (dlocn->offset);
   mda_size = grub_le_to_cpu64 (dlocn->size);
-  dlocn++;
 
-  if (dlocn->offset)
-    {
-      grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-		  "We don't support multiple LVM metadata areas");
-
-      goto fail;
-    }
+  /* It's possible to have multiple copies of metadata areas, we just use the
+     first one.  */
 
   /* Allocate buffer space for the circular worst-case scenario. */
   metadatabuf = grub_malloc (2 * mda_size);
@@ -564,7 +558,10 @@ grub_lvm_scan_device (const char *name)
       {
 	if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN))
 	  {
-	    pv->disk = grub_disk_open (name);
+	    /* This could happen to LVM on RAID, pv->disk points to the
+	       raid device, we shouldn't change it.  */
+	    if (! pv->disk)
+	      pv->disk = grub_disk_open (name);
 	    break;
 	  }
       }
disk/raid.c +30 -58

108 lines not on this page · raw message

include/grub/raid.h +0 -1
index 595ced1..8fa4c38 100644
@@ -67,7 +67,6 @@ typedef struct grub_raid *grub_raid_t;
 void grub_raid_register (grub_raid_t raid);
 void grub_raid_unregister (grub_raid_t raid);
 
-void grub_raid_rescan (void);
 void grub_raid_block_xor (char *buf1, const char *buf2, int size);
 
 typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
util/grub-fstest.c +7 -2
index 4722269..a4de2ae 100644
@@ -28,7 +28,6 @@
 #include <grub/env.h>
 #include <grub/term.h>
 #include <grub/mm.h>
-#include <grub/raid.h>
 #include <grub/lib/hexdump.h>
 #include <grub/lib/crc.h>
 #include <grub/command.h>
@@ -293,7 +292,13 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
         grub_util_error ("loopback command fails.");
     }
 
-  grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_mdraid_fini ();
+  grub_raid_fini ();  
+  grub_raid_init ();
+  grub_mdraid_init ();
+  grub_lvm_init ();
+
   switch (cmd)
     {
     case CMD_LS:
util/grub-probe.c +27 -23

68 lines not on this page · raw message

#7 lore raw
Quoted 8 lines · Bean

Hi,

I've come up an alternative solution to grub_raid_rescan, we can use the same trick as lvm, call fini and then init function, this would have the same effect of rescanning. Now that grub_raid_rescan is gone, I can simply raid.c further by moving grub_raid_scan_device into grub_raid_register.

Good idea. I was certain this could be simplified :-)

Quoted 2 lines

As for dynamically scanning, I think it's not common to mount lvm/raid in loopback files, we could just ignore it for now.

Sure. Just an idea we can discuss sometime.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#8 lore raw
In reply to Bean

util/grub-probe.c probe (const char *path, char *device_name) · line 169

Quoted 5 lines · Bean
util/grub-probe.c +5 -0
+      if (is_raid)
+	printf ("raid mdraid");
+
+      if (is_lvm)
+	printf ((is_raid) ? " lvm" : "lvm");

Is there a better way to handle this? Perhaps we could make the list newline separated instead of space separated and avoid the problem altogether.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#9 lore raw
Quoted 10 lines · Robert Millan
Quoted 5 lines · Bean

+      if (is_raid)
+     printf ("raid mdraid");
+
+      if (is_lvm)
+     printf ((is_raid) ? " lvm" : "lvm");

Is there a better way to handle this?  Perhaps we could make the list newline separated instead of space separated and avoid the problem altogether.

Hi,

Actually, if we allows an extra space at the end of line, it can be written like this:

if (is_raid)

     printf ("raid mdraid ");

if (is_lvm)

     printf ("lvm ");

The space is not visible, and ignored by grub-install anyway.

Signature · 1 line
Bean
#10 lore raw
Quoted 17 lines · Bean
Quoted 10 lines · Robert Millan
Quoted 5 lines · Bean

+      if (is_raid)
+     printf ("raid mdraid");
+
+      if (is_lvm)
+     printf ((is_raid) ? " lvm" : "lvm");

Is there a better way to handle this?  Perhaps we could make the list newline separated instead of space separated and avoid the problem altogether.

Hi,

Actually, if we allows an extra space at the end of line, it can be written like this:

Quoted 7 lines

if (is_raid)

     printf ("raid mdraid ");

if (is_lvm)

     printf ("lvm ");

The space is not visible, and ignored by grub-install anyway.

Ok. I'd prefer a newline, but it can always be changed later on.

Your patch seems fine to me.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#11 lore raw
In reply to Bean

Bean, should Grub2 with this patch work if the boot partition is LVM volume and LVM is placed on top of RAID 5 arrays?

Thanks,

Patrik

Quoted 26 lines · Bean

Hi,

This patch fixes a few bug in lvm.

There can be multiple copies of meta data, it's not an error, ignore the extra copy instead of quit.

In case of LVM on RAID, the raid device and first disk would have the same lvm header ! The raid device would be found first, so we don't replace pv->disk if it has been set.

grub-probe doesn't work in LVM on RAID, as it only assume one layer of abstraction, the fix is not to rely on os, but uses grub to get the correct abstraction information.

Fix grub-fstest to support lvm.

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

author
#12 lore raw
Quoted 2 lines · Patrik Horník

Bean, should Grub2 with this patch work if the boot partition is LVM volume and LVM is placed on top of RAID 5 arrays?

Hi,

Yeah, it should work, please try it out.

Signature · 1 line
Bean
#13 lore raw

Am Montag, den 20.07.2009, 03:34 +0800 schrieb Bean:

Quoted 8 lines · Patrik Horník
Quoted 2 lines

Bean, should Grub2 with this patch work if the boot partition is LVM volume and LVM is placed on top of RAID 5 arrays?

Hi,

Yeah, it should work, please try it out.

I just tried it out with a RAID 5 over 3 partitions on one disk. grub-probe -t abstraction shows `raid mdraid lvm', but if I boot from the disk ls doestn't (md0) nor (vg-lvol0)
If I insmod raid; insmod mdraid; insmod lvm from a normal grub both devices get shown.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#14 lore raw
In reply to Bean

Hello Bean,

it still does not work, I've tested your patch today against revision 2448 from SVN.

- grub-probe works and detects ex2 filesystem on LVM volume on RAID5 arrays.

- However grub on boot still does not detect filesystem on root/boot volume. It knows root LVM volume according ls command from grub rescue, but still goes to rescue mode with error "unknown filesystem".

- grub-install also does not work, it creates core.img without some of needed modules. It seems that raid modules are missing, because ls in grub rescue shows only native partitions. I've created core.img manually to test your patch, with modules "ext2 chain pc biosdisk lvm raid mdraid".

Patrik Horník

Quoted 17 lines · Bean
Quoted 2 lines · Patrik Horník

Bean, should Grub2 with this patch work if the boot partition is LVM volume and LVM is placed on top of RAID 5 arrays?

Hi,

Yeah, it should work, please try it out.

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

author
#15 lore raw
Quoted 11 lines · Patrik Horník

Hello Bean,

it still does not work, I've tested your patch today against revision 2448 from SVN.

- grub-probe works and detects ex2 filesystem on LVM volume on RAID5 arrays.

- However grub on boot still does not detect filesystem on root/boot volume. It knows root LVM volume according ls command from grub rescue, but still goes to rescue mode with error "unknown filesystem".

Quoted 5 lines

- grub-install also does not work, it creates core.img without some of needed modules. It seems that raid modules are missing, because ls in grub rescue shows only native partitions. I've created core.img manually to test your patch, with modules "ext2 chain pc biosdisk lvm raid mdraid".

Hi,

Perhaps the install script still has problem to determine the correct modules, maybe you can try to this list manually:

"ext2 chain pc biosdisk raid mdraid lvm".

The order is important, lvm must be loaded after raid and mdraid.

Signature · 1 line
Bean
author
#16 lore raw

Hi,

Oh, I've found the problem. The abstraction is ok, but now partmap is wrong. The original code assumes at most one level of abstraction when detecting partmap, and it doesn't work on two level abstraction like LVM on RAID. If you add module minicmd, you can use lsmod and see pc module is missing.

I also make some improvement to the patch. Now it also detect the raid level, and add raid5rec or raid6rec accordingly.

Signature · 1 line
Bean
disk/lvm.c +6 -9
index 6707a40..126b494 100644
@@ -271,15 +271,9 @@ grub_lvm_scan_device (const char *name)
   dlocn++;
   mda_offset = grub_le_to_cpu64 (dlocn->offset);
   mda_size = grub_le_to_cpu64 (dlocn->size);
-  dlocn++;
 
-  if (dlocn->offset)
-    {
-      grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-		  "We don't support multiple LVM metadata areas");
-
-      goto fail;
-    }
+  /* It's possible to have multiple copies of metadata areas, we just use the
+     first one.  */
 
   /* Allocate buffer space for the circular worst-case scenario. */
   metadatabuf = grub_malloc (2 * mda_size);
@@ -564,7 +558,10 @@ grub_lvm_scan_device (const char *name)
       {
 	if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN))
 	  {
-	    pv->disk = grub_disk_open (name);
+	    /* This could happen to LVM on RAID, pv->disk points to the
+	       raid device, we shouldn't change it.  */
+	    if (! pv->disk)
+	      pv->disk = grub_disk_open (name);
 	    break;
 	  }
       }
disk/raid.c +30 -58

108 lines not on this page · raw message

include/grub/raid.h +0 -1
index 595ced1..8fa4c38 100644
@@ -67,7 +67,6 @@ typedef struct grub_raid *grub_raid_t;
 void grub_raid_register (grub_raid_t raid);
 void grub_raid_unregister (grub_raid_t raid);
 
-void grub_raid_rescan (void);
 void grub_raid_block_xor (char *buf1, const char *buf2, int size);
 
 typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
util/grub-fstest.c +7 -2
index 4722269..a4de2ae 100644
@@ -28,7 +28,6 @@
 #include <grub/env.h>
 #include <grub/term.h>
 #include <grub/mm.h>
-#include <grub/raid.h>
 #include <grub/lib/hexdump.h>
 #include <grub/lib/crc.h>
 #include <grub/command.h>
@@ -293,7 +292,13 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
         grub_util_error ("loopback command fails.");
     }
 
-  grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_mdraid_fini ();
+  grub_raid_fini ();
+  grub_raid_init ();
+  grub_mdraid_init ();
+  grub_lvm_init ();
+
   switch (cmd)
     {
     case CMD_LS:
util/grub-probe.c +74 -23

133 lines not on this page · raw message

author
#17 lore raw

Hi,

BTW, I found a regression on r2421 that cause raid5rec to fail:

http://svn.savannah.gnu.org/viewvc/trunk/grub2/disk/raid6_recover.c?root=grub&r1=2197&r2=2421

buf and buf2 are two different variable.

This new patch include the revert raid5_recover.c to r1828.

Quoted 14 lines · Bean

Hi,

Oh, I've found the problem. The abstraction is ok, but now partmap is wrong. The original code assumes at most one level of abstraction when detecting partmap, and it doesn't work on two level abstraction like LVM on RAID. If you add module minicmd, you can use lsmod and see pc module is missing.

I also make some improvement to the patch. Now it also detect the raid level, and add raid5rec or raid6rec accordingly.

--
Bean

Signature · 1 line
Bean
disk/lvm.c +6 -9
index 6707a40..126b494 100644
@@ -271,15 +271,9 @@ grub_lvm_scan_device (const char *name)
   dlocn++;
   mda_offset = grub_le_to_cpu64 (dlocn->offset);
   mda_size = grub_le_to_cpu64 (dlocn->size);
-  dlocn++;
 
-  if (dlocn->offset)
-    {
-      grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
-		  "We don't support multiple LVM metadata areas");
-
-      goto fail;
-    }
+  /* It's possible to have multiple copies of metadata areas, we just use the
+     first one.  */
 
   /* Allocate buffer space for the circular worst-case scenario. */
   metadatabuf = grub_malloc (2 * mda_size);
@@ -564,7 +558,10 @@ grub_lvm_scan_device (const char *name)
       {
 	if (! grub_memcmp (pv->id, pv_id, GRUB_LVM_ID_STRLEN))
 	  {
-	    pv->disk = grub_disk_open (name);
+	    /* This could happen to LVM on RAID, pv->disk points to the
+	       raid device, we shouldn't change it.  */
+	    if (! pv->disk)
+	      pv->disk = grub_disk_open (name);
 	    break;
 	  }
       }
disk/raid.c +30 -58

108 lines not on this page · raw message

disk/raid5_recover.c +3 -1
index a280be1..31cef88 100644
@@ -32,10 +32,12 @@ grub_raid5_recover (struct grub_raid_array *array, int disknr,
   int i;
 
   size <<= GRUB_DISK_SECTOR_BITS;
-  buf2 = grub_zalloc (size);
+  buf2 = grub_malloc (size);
   if (!buf2)
     return grub_errno;
 
+  grub_memset (buf, 0, size);
+
   for (i = 0; i < (int) array->total_devs; i++)
     {
       grub_err_t err;
include/grub/raid.h +0 -1
index 595ced1..8fa4c38 100644
@@ -67,7 +67,6 @@ typedef struct grub_raid *grub_raid_t;
 void grub_raid_register (grub_raid_t raid);
 void grub_raid_unregister (grub_raid_t raid);
 
-void grub_raid_rescan (void);
 void grub_raid_block_xor (char *buf1, const char *buf2, int size);
 
 typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
util/grub-fstest.c +7 -2
index 4722269..1bb3706 100644
@@ -28,7 +28,6 @@
 #include <grub/env.h>
 #include <grub/term.h>
 #include <grub/mm.h>
-#include <grub/raid.h>
 #include <grub/lib/hexdump.h>
 #include <grub/lib/crc.h>
 #include <grub/command.h>
@@ -293,7 +292,13 @@ fstest (char **images, int num_disks, int cmd, int n, char **args)
         grub_util_error ("loopback command fails.");
     }
 
-  grub_raid_rescan ();
+  grub_lvm_fini ();
+  grub_mdraid_fini ();
+  grub_raid_fini ();
+  grub_raid_init ();
+  grub_mdraid_init ();
+  grub_lvm_init ();
+
   switch (cmd)
     {
     case CMD_LS:
util/grub-probe.c +74 -23

133 lines not on this page · raw message

author
#18 lore raw

Hi,

Oh, the link should be:

http://svn.savannah.gnu.org/viewvc/trunk/grub2/disk/raid5_recover.c?root=grub&r1=2197&r2=2421

Quoted 31 lines · Bean

Hi,

BTW, I found a regression on r2421 that cause raid5rec to fail:

http://svn.savannah.gnu.org/viewvc/trunk/grub2/disk/raid6_recover.c?root=grub&r1=2197&r2=2421

buf and buf2 are two different variable.

This new patch include the revert raid5_recover.c to r1828.

Quoted 8 lines · Bean

Hi,

Oh, I've found the problem. The abstraction is ok, but now partmap is wrong. The original code assumes at most one level of abstraction when detecting partmap, and it doesn't work on two level abstraction like LVM on RAID. If you add module minicmd, you can use lsmod and see pc module is missing.

Quoted 6 lines

I also make some improvement to the patch. Now it also detect the raid level, and add raid5rec or raid6rec accordingly.

--
Bean

--
Bean

Signature · 1 line
Bean
#19 lore raw
In reply to Bean

disk/raid5_recover.c grub_raid5_recover (struct grub_raid_array *array, int disknr, · line 39

Quoted 6 lines · Bean
disk/raid5_recover.c +2 -1
-  buf2 = grub_zalloc (size);
+  buf2 = grub_malloc (size);
   if (!buf2)
     return grub_errno;
 
+  grub_memset (buf, 0, size);

We just received 'buf' as parameter. Why do we have to zero it here?

util/grub-probe.c probe_partmap (grub_disk_t disk) · line 111

Quoted 8 lines
util/grub-probe.c +8 -0
+static int
+probe_raid_level (grub_disk_t disk)
+{
+  if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID)
+    return -1;
+
+  return ((struct grub_raid_array *) disk->data)->level;
+}

Since this an ad-hoc function, could you put it in the same block that needs it? If 'static' qualifier is present, it won't result in nested function AFAICT.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#20 lore raw

Am Dienstag, den 28.07.2009, 19:42 +0200 schrieb Robert Millan:

Quoted 15 lines · Bean

util/grub-probe.c probe_partmap (grub_disk_t disk) · line 111

Quoted 9 lines
util/grub-probe.c +8 -0
+static int
+probe_raid_level (grub_disk_t disk)
+{
+  if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID)
+    return -1;
+
+  return ((struct grub_raid_array *) disk->data)->level;
+}

Since this an ad-hoc function, could you put it in the same block that needs it? If 'static' qualifier is present, it won't result in nested function AFAICT.

GCC manual [0] says:

A nested function always has no linkage. Declaring one with extern or static is erroneous.

[0]
http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Nested-Functions.html#Nested-Functions

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
author
#21 lore raw
In reply to Robert Millan
Quoted 9 lines · Robert Millan
Quoted 6 lines · Bean

-  buf2 = grub_zalloc (size);
+  buf2 = grub_malloc (size);
   if (!buf2)
     return grub_errno;

+  grub_memset (buf, 0, size);

We just received 'buf' as parameter.  Why do we have to zero it here?

Hi,

Because we are in a recovery function, the original content may not be correct, we need to clear it out before continue.

Quoted 13 lines

util/grub-probe.c probe_partmap (grub_disk_t disk) · line 111

Quoted 9 lines
util/grub-probe.c +8 -0
+static int
+probe_raid_level (grub_disk_t disk)
+{
+  if (disk->dev->id != GRUB_DISK_DEVICE_RAID_ID)
+    return -1;
+
+  return ((struct grub_raid_array *) disk->data)->level;
+}

Since this an ad-hoc function, could you put it in the same block that needs it?  If 'static' qualifier is present, it won't result in nested function AFAICT.

It's used by the next function probe, so unless we use nested function, it can't be placed closer.

Signature · 1 line
Bean
#22 lore raw
Quoted 7 lines · Bean
Quoted 6 lines · Robert Millan
Quoted 5 lines · Bean

-  buf2 = grub_zalloc (size);
+  buf2 = grub_malloc (size);
   if (!buf2)
     return grub_errno;

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+  grub_memset (buf, 0, size);

We just received 'buf' as parameter.  Why do we have to zero it here?

Hi,

Because we are in a recovery function, the original content may not be correct, we need to clear it out before continue.

Alright. I think a comment would help, it's not obvious why it's done this way.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#23 lore raw
In reply to Bean

Hello Bean,

great, it is working now.

However, "grub-probe -t abstraction" separates different modules with newline character, so grub-mkconfig generates incorrect grub.cfg.

Patrik Horník

Quoted 37 lines · Bean

Hi,

BTW, I found a regression on r2421 that cause raid5rec to fail:

http://svn.savannah.gnu.org/viewvc/trunk/grub2/disk/raid6_recover.c?root=grub&r1=2197&r2=2421

buf and buf2 are two different variable.

This new patch include the revert raid5_recover.c to r1828.

Quoted 8 lines · Bean

Hi,

Oh, I've found the problem. The abstraction is ok, but now partmap is wrong. The original code assumes at most one level of abstraction when detecting partmap, and it doesn't work on two level abstraction like LVM on RAID. If you add module minicmd, you can use lsmod and see pc module is missing.

Quoted 6 lines

I also make some improvement to the patch. Now it also detect the raid level, and add raid5rec or raid6rec accordingly.

--
Bean

--
Bean

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

#24 lore raw
In reply to Bean
Quoted 9 lines · Bean

Hi,

BTW, I found a regression on r2421 that cause raid5rec to fail:

http://svn.savannah.gnu.org/viewvc/trunk/grub2/disk/raid6_recover.c?root=grub&r1=2197&r2=2421

buf and buf2 are two different variable.

This new patch include the revert raid5_recover.c to r1828.

Sorry for that! I have reverted that part of the patch, and I'm reviewing the whole commit for possible other errors of that kind.

There is no need to combine reverts with other patches. An obvious mistake can be reverted separately.

Signature · 2 lines
Regards,
Pavel Roskin
author
#25 lore raw

Hi,

Committed, grub-probe now now uses space as separator instead of newline.

Signature · 1 line
Bean
#26 lore raw

Am Freitag, den 31.07.2009, 22:28 +0800 schrieb Bean:

Quoted 4 lines

Hi,

Committed, grub-probe now now uses space as separator instead of newline.

grub-mkconfig is still broken with it even though you use now spaces instead of newlines.
insmod doestn't support multiple modules at once.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer
#27 lore raw

Am Freitag, den 31.07.2009, 20:30 +0200 schrieb Felix Zielcke:

Quoted 10 lines

Am Freitag, den 31.07.2009, 22:28 +0800 schrieb Bean:

Quoted 4 lines

Hi,

Committed, grub-probe now now uses space as separator instead of newline.

grub-mkconfig is still broken with it even though you use now spaces instead of newlines.
insmod doestn't support multiple modules at once.

I just fixed it now. Now grub-mkconfig prints multiple insmod lines for them.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer