From: Sean Finney Date: Thu, 1 Jul 2010 21:19:11 +0000 (+0200) Subject: * disk/lvm.c (grub_lvm_scan_device): Skip snapshots. X-Git-Tag: 1.99~778 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5944958c61a4b8aa11162d01ea61462d02db7ac4;p=thirdparty%2Fgrub.git * disk/lvm.c (grub_lvm_scan_device): Skip snapshots. 2010-07-01 Vladimir Serbinenko * disk/lvm.c (grub_lvm_checkvalue): New function. (grub_lvm_check_flag): Likewise. Also-By: Vladimir Serbinenko --- diff --git a/ChangeLog b/ChangeLog index f21d94425..341e122f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-07-01 Sean Finney + + * disk/lvm.c (grub_lvm_scan_device): Skip snapshots. + +2010-07-01 Vladimir Serbinenko + + * disk/lvm.c (grub_lvm_checkvalue): New function. + (grub_lvm_check_flag): Likewise. + 2010-07-01 Robert Millan * kern/emu/hostdisk.c (convert_system_partition_to_system_disk): diff --git a/disk/lvm.c b/disk/lvm.c index 7dde40920..71860e853 100644 --- a/disk/lvm.c +++ b/disk/lvm.c @@ -45,6 +45,52 @@ grub_lvm_getvalue (char **p, char *str) return grub_strtoul (*p, NULL, 10); } +static int +grub_lvm_checkvalue (char **p, char *str, char *tmpl) +{ + int tmpllen = grub_strlen (tmpl); + *p = grub_strstr (*p, str); + if (! *p) + return 0; + *p += grub_strlen (str); + if (**p != '"') + return 0; + return (grub_memcmp (*p + 1, tmpl, tmpllen) == 0 && (*p)[tmpllen + 1] == '"'); +} + +static int +grub_lvm_check_flag (char *p, char *str, char *flag) +{ + int len_str = grub_strlen (str), len_flag = grub_strlen (flag); + while (1) + { + char *q; + p = grub_strstr (p, str); + if (! p) + return 0; + p += len_str; + if (grub_memcmp (p, " = [", sizeof (" = [") - 1) != 0) + continue; + q = p + sizeof (" = [") - 1; + while (1) + { + while (grub_isspace (*q)) + q++; + if (*q != '"') + return 0; + q++; + if (grub_memcmp (q, flag, len_flag) == 0 && q[len_flag] == '"') + return 1; + while (*q != '"') + q++; + q++; + if (*q == ']') + return 0; + q++; + } + } +} + static int grub_lvm_iterate (int (*hook) (const char *name)) { @@ -421,6 +467,7 @@ grub_lvm_scan_device (const char *name) while (1) { int s; + int skip_lv = 0; struct grub_lvm_lv *lv; struct grub_lvm_segment *seg; @@ -445,6 +492,12 @@ grub_lvm_scan_device (const char *name) lv->size = 0; + if (!grub_lvm_check_flag (p, "status", "VISIBLE")) + { + skip_lv = 1; + goto lv_parsed; + } + lv->segment_count = grub_lvm_getvalue (&p, "segment_count = "); if (p == NULL) goto lvs_fail; @@ -465,6 +518,14 @@ grub_lvm_scan_device (const char *name) seg->extent_count = grub_lvm_getvalue (&p, "extent_count = "); if (p == NULL) goto lvs_segment_fail; + + if (grub_lvm_checkvalue (&p, "type = ", "snapshot")) + { + /* Found a snapshot, give up and move on. */ + skip_lv = 1; + break; + } + seg->stripe_count = grub_lvm_getvalue (&p, "stripe_count = "); if (p == NULL) goto lvs_segment_fail; @@ -531,12 +592,20 @@ grub_lvm_scan_device (const char *name) goto fail4; } + lv_parsed: if (p != NULL) p = grub_strchr (p, '}'); if (p == NULL) goto lvs_fail; p += 3; + if (skip_lv) + { + grub_free (lv->name); + grub_free (lv); + continue; + } + lv->number = lv_count++; lv->vg = vg; lv->next = vg->lvs;