[PATCH] lvm: Fix error recovery by only adding objects when we cannot fail

Guillem Jover guillem.jover at nokia.com
Mon Oct 27 21:22:06 UTC 2008


The error unwinding code was keeping objects referenced in the lists
even when those were being unfreed. Delay the addition of those objects
to the lists until the code is not going to be able to fail, so that
that part does not need to be unwound.
---
 disk/lvm.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/disk/lvm.c b/disk/lvm.c
index df8c99b..2ee1f7f 100644
--- a/disk/lvm.c
+++ b/disk/lvm.c
@@ -345,8 +345,6 @@ grub_lvm_scan_device (const char *name)
 
       vg->lvs = NULL;
       vg->pvs = NULL;
-      vg->next = vg_list;
-      vg_list = vg;
 
       p = grub_strstr (p, "physical_volumes {");
       if (p)
@@ -384,14 +382,15 @@ grub_lvm_scan_device (const char *name)
 	      pv->start = grub_lvm_getvalue (&p, "pe_start = ");
 	      if (p == NULL)
 		goto pvs_fail;
-	      pv->disk = NULL;
-	      pv->next = vg->pvs;
-	      vg->pvs = pv;
 	      
 	      p = grub_strchr (p, '}');
 	      if (p == NULL)
 		goto pvs_fail;
 	      p++;
+
+	      pv->disk = NULL;
+	      pv->next = vg->pvs;
+	      vg->pvs = pv;
 	      
 	      continue;
 	    pvs_fail:
@@ -520,16 +519,16 @@ grub_lvm_scan_device (const char *name)
 		  goto fail4;
 		}
 
-	      lv->number = lv_count++;
-	      lv->vg = vg;
-	      lv->next = vg->lvs;
-	      vg->lvs = lv;
-	      
 	      p = grub_strchr (p, '}');
 	      if (p == NULL)
 		goto lvs_fail;
 	      p += 3;
 	      
+	      lv->number = lv_count++;
+	      lv->vg = vg;
+	      lv->next = vg->lvs;
+	      vg->lvs = lv;
+
 	      continue;
 	    lvs_fail:
 	      grub_free (lv->name);
@@ -537,6 +536,9 @@ grub_lvm_scan_device (const char *name)
 	      goto fail4;
 	    }
 	}
+
+	vg->next = vg_list;
+	vg_list = vg;
     }
   else
     {
-- 
1.6.0.2


--+QahgC5+KEYLbs62--





More information about the Pkg-grub-devel mailing list