tags 487758 +pending
thanks

This will be fixed in the next release of e2fsprogs.

                                                - Ted

>From 772b89d34212e4b36c2025c80304e166bc25a2f3 Mon Sep 17 00:00:00 2001
From: Eric Sandeen <[EMAIL PROTECTED]>
Date: Fri, 20 Jun 2008 22:32:49 -0500
Subject: [PATCH] blkid: use list_for_each_safe in garbage collection

We need to use list_for_each_safe in case a device gets removed from
the list during garbage collection.

Also make the manpage slightly more informative about
what the -g garbage collection option does.

Addresses-Debian-Bug: #487758, #487783

Signed-off-by: Eric Sandeen <[EMAIL PROTECTED]>
Signed-off-by: Theodore Ts'o <[EMAIL PROTECTED]>
---
 lib/blkid/cache.c |    4 ++--
 misc/blkid.8.in   |    3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/blkid/cache.c b/lib/blkid/cache.c
index 1508d0f..efd4656 100644
--- a/lib/blkid/cache.c
+++ b/lib/blkid/cache.c
@@ -154,13 +154,13 @@ void blkid_put_cache(blkid_cache cache)
 
 void blkid_gc_cache(blkid_cache cache)
 {
-	struct list_head *p;
+	struct list_head *p, *pnext;
 	struct stat st;
 
 	if (!cache)
 		return;
 
-	list_for_each(p, &cache->bic_devs) {
+	list_for_each_safe(p, pnext, &cache->bic_devs) {
 		blkid_dev dev = list_entry(p, struct blkid_struct_dev, bid_devs);
 		if (!p)
 			break;
diff --git a/misc/blkid.8.in b/misc/blkid.8.in
index 42ad0d7..8a4e971 100644
--- a/misc/blkid.8.in
+++ b/misc/blkid.8.in
@@ -61,7 +61,8 @@ scanned but not necessarily available at this time), specify
 .IR /dev/null.
 .TP
 .B \-g
-Perform a garbage collection pass on the blkid cache.
+Perform a garbage collection pass on the blkid cache to remove
+devices which no longer exist.
 .TP
 .B \-h
 Display a usage message and exit.
-- 
1.5.6.rc3.1.g36b7.dirty

>From b697f9d01c5f07842426f7d8e918bf3110028662 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <[EMAIL PROTECTED]>
Date: Sat, 28 Jun 2008 21:02:01 -0400
Subject: [PATCH] blkid: Make sure a device returned by blkid_find_dev_with_tag exists

There could be stale entries in blkid file, so if the device does not
exist, skip it.

Addresses-Debian-Bug: #487758, #487783

Signed-off-by: "Theodore Ts'o" <[EMAIL PROTECTED]>
---
 lib/blkid/tag.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/blkid/tag.c b/lib/blkid/tag.c
index 44dd86d..8a8ac99 100644
--- a/lib/blkid/tag.c
+++ b/lib/blkid/tag.c
@@ -10,6 +10,7 @@
  * %End-Header%
  */
 
+#include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -355,7 +356,8 @@ try_again:
 						   bit_names);
 
 			if (!strcmp(tmp->bit_val, value) &&
-			    tmp->bit_dev->bid_pri > pri) {
+			    (tmp->bit_dev->bid_pri > pri) &&
+			    !access(tmp->bit_dev->bid_name, F_OK)) {
 				dev = tmp->bit_dev;
 				pri = dev->bid_pri;
 			}
@@ -363,7 +365,7 @@ try_again:
 	}
 	if (dev && !(dev->bid_flags & BLKID_BID_FL_VERIFIED)) {
 		dev = blkid_verify(cache, dev);
-		if (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED))
+		if (!dev || (dev && (dev->bid_flags & BLKID_BID_FL_VERIFIED)))
 			goto try_again;
 	}
 
-- 
1.5.6.rc3.1.g36b7.dirty

>From bf58e3d1c68be63d673d232154bde5854e031afc Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <[EMAIL PROTECTED]>
Date: Sat, 28 Jun 2008 22:09:43 -0400
Subject: [PATCH] blkid: Eliminate stale entries that duplicate a verified device

Addresses-Debian-Bug: #487758, #487783

Signed-off-by: "Theodore Ts'o" <[EMAIL PROTECTED]>
---
 lib/blkid/devname.c |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 29cde8e..df96859 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -51,7 +51,7 @@
 blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
 {
 	blkid_dev dev = NULL, tmp;
-	struct list_head *p;
+	struct list_head *p, *pnext;
 
 	if (!cache || !devname)
 		return NULL;
@@ -78,8 +78,42 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
 		cache->bic_flags |= BLKID_BIC_FL_CHANGED;
 	}
 
-	if (flags & BLKID_DEV_VERIFY)
+	if (flags & BLKID_DEV_VERIFY) {
 		dev = blkid_verify(cache, dev);
+		if (!dev || !(dev->bid_flags & BLKID_BID_FL_VERIFIED))
+			return dev;
+		/* 
+		 * If the device is verified, then search the blkid
+		 * cache for any entries that match on the type, uuid,
+		 * and label, and verify them; if a cache entry can
+		 * not be verified, then it's stale and so we remove
+		 * it.
+		 */
+		list_for_each_safe(p, pnext, &cache->bic_devs) {
+			blkid_dev dev2;
+			if (!p)
+				break;
+			dev2 = list_entry(p, struct blkid_struct_dev, bid_devs);
+			if (dev2->bid_flags & BLKID_BID_FL_VERIFIED)
+				continue;
+			if (strcmp(dev->bid_type, dev2->bid_type))
+				continue;
+			if (dev->bid_label && dev2->bid_label &&
+			    strcmp(dev->bid_label, dev2->bid_label))
+				continue;
+			if (dev->bid_uuid && dev2->bid_uuid &&
+			    strcmp(dev->bid_uuid, dev2->bid_uuid))
+				continue;
+			if ((dev->bid_label && !dev2->bid_label) ||
+			    (!dev->bid_label && dev2->bid_label) ||
+			    (dev->bid_uuid && !dev2->bid_uuid) ||
+			    (!dev->bid_uuid && dev2->bid_uuid))
+				continue;
+			dev2 = blkid_verify(cache, dev2);
+			if (dev2 && !(dev2->bid_flags & BLKID_BID_FL_VERIFIED))
+				blkid_free_dev(dev2);
+		}
+	}
 	return dev;
 }
 
-- 
1.5.6.rc3.1.g36b7.dirty

Reply via email to