diff options
author | Eric Sandeen <sandeen@redhat.com> | 2009-04-22 22:51:51 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2009-04-22 22:52:40 -0400 |
commit | 4e60e06847c781efffc8c43342b7756bbe5cff45 (patch) | |
tree | 6d50cc96f77a6e4de6ad3482242dd0d2956dccbc /lib | |
parent | de7a86e23c6113f386dc3500304cd8a37b91bfa8 (diff) | |
download | e2fsprogs-4e60e06847c781efffc8c43342b7756bbe5cff45.tar.gz |
blkid: remove whole-disk entries from cache when partitions are found
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>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/blkid/devname.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c index e338c950..8553e9f3 100644 --- a/lib/blkid/devname.c +++ b/lib/blkid/devname.c @@ -365,6 +365,7 @@ static int probe_all(blkid_cache cache, int only_if_new) 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 +426,29 @@ static int probe_all(blkid_cache cache, int only_if_new) } /* + * 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. |