From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] remove whole-disk entries from cache when partitions are found
Date: Mon, 23 Mar 2009 11:51:51 -0500 [thread overview]
Message-ID: <49C7BE27.2090702@redhat.com> (raw)
We can get into a situation in blkid where whole disks remain
in the cache, even though partitions are found. For labels
such as sun disklabels which may have the first partition
beginning at sector 0, this is even somewhat likely.
1) create a sun disklabel w/partitions
2) mkfs the first partition (at sector 0)
3) remove the partition table
4) run blkid - this finds the fs on the whole disk, places in cache
5) recreate the partition table
6) run blkid - this finds the partition, places in cache
And now we have both /dev/sda and /dev/sda1 in cache.
There are heuristics in probe_all to avoid putting the whole disk
in cache if it has partitions, but there is nothing to remove the
whole-disk entry in the above case. I think the below patch
suffices, although I haven't quite convinced myself that setting
the lens[which]=0; is the right logic for that bit of state...
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
Index: e2fsprogs/lib/blkid/devname.c
===================================================================
--- e2fsprogs.orig/lib/blkid/devname.c
+++ e2fsprogs/lib/blkid/devname.c
@@ -365,6 +365,7 @@ static int probe_all(blkid_cache cache,
unsigned long long sz;
int lens[2] = { 0, 0 };
int which = 0, last = 0;
+ struct list_head *p, *pnext;
ptnames[0] = ptname0;
ptnames[1] = ptname1;
@@ -425,6 +428,29 @@ static int probe_all(blkid_cache cache,
}
/*
+ * If last was a whole disk and we just found a partition
+ * on it, remove the whole-disk dev from the cache if
+ * it exists.
+ */
+ if (lens[last] && !strncmp(ptnames[last], ptname, lens[last])) {
+ list_for_each_safe(p, pnext, &cache->bic_devs) {
+ blkid_dev tmp;
+
+ /* find blkid dev for the whole-disk devno */
+ tmp = list_entry(p, struct blkid_struct_dev,
+ bid_devs);
+ if (tmp->bid_devno == devs[last]) {
+ DBG(DEBUG_DEVNAME,
+ printf("freeing %s\n",
+ tmp->bid_name));
+ blkid_free_dev(tmp);
+ cache->bic_flags |= BLKID_BIC_FL_CHANGED;
+ break;
+ }
+ }
+ lens[last] = 0;
+ }
+ /*
* If last was not checked because it looked like a whole-disk
* dev, and the device's base name has changed,
* check last as well.
next reply other threads:[~2009-03-23 16:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-23 16:51 Eric Sandeen [this message]
2009-04-23 2:53 ` [PATCH] remove whole-disk entries from cache when partitions are found Theodore Tso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49C7BE27.2090702@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).