summaryrefslogtreecommitdiff
path: root/lib/blkid
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2005-05-07 17:06:27 -0400
committerTheodore Ts'o <tytso@mit.edu>2005-05-07 17:06:27 -0400
commited6acfa337ca74912079b85196cf1263f6daf1a2 (patch)
tree4aeae5bd667c95cfb58abc19915fe7bcc1d34d17 /lib/blkid
parent12b3c8ec1d314b8775fc7d9cefd6bfff551f1de0 (diff)
downloade2fsprogs-ed6acfa337ca74912079b85196cf1263f6daf1a2.tar.gz
Add a new option to the blkid program, -l, which will more efficiently search
for a single device. Add a new function to the blkid library, blkid_probe_all_new(). Optimize blkid_find_dev_with_tag() so that extraneous device validation are skipped. (Makes a difference for system with a large number of disks).
Diffstat (limited to 'lib/blkid')
-rw-r--r--lib/blkid/ChangeLog9
-rw-r--r--lib/blkid/blkid.h1
-rw-r--r--lib/blkid/devname.c52
-rw-r--r--lib/blkid/tag.c11
4 files changed, 57 insertions, 16 deletions
diff --git a/lib/blkid/ChangeLog b/lib/blkid/ChangeLog
index 40c7d122..d84c9037 100644
--- a/lib/blkid/ChangeLog
+++ b/lib/blkid/ChangeLog
@@ -1,5 +1,14 @@
2005-05-07 Theodore Ts'o <tytso@mit.edu>
+ * tag.c (blkid_find_dev_with_tag): If a device can't be found with
+ the specified search arguments, probe all new devices
+ before trying to verify existing devices, as a speed
+ optimization.
+
+ * devname.c (blkid_probe_all_new): New function which only probes
+ devices are not known in the blkid cache. This takes
+ much less time than a full probe of all devices.
+
* cache.c, dev.c, devno.c, probe.c, probe.h: Fix gcc -Wall nits.
* blkidP.h, cache.c, dev.c, read.c, tag.c: Clean up the debugging
diff --git a/lib/blkid/blkid.h b/lib/blkid/blkid.h
index 84be589f..892b7980 100644
--- a/lib/blkid/blkid.h
+++ b/lib/blkid/blkid.h
@@ -65,6 +65,7 @@ extern char *blkid_devno_to_devname(dev_t devno);
/* devname.c */
extern int blkid_probe_all(blkid_cache cache);
+extern int blkid_probe_all_new(blkid_cache cache);
extern blkid_dev blkid_get_dev(blkid_cache cache, const char *devname,
int flags);
diff --git a/lib/blkid/devname.c b/lib/blkid/devname.c
index 87d5cbef..3b1ad89b 100644
--- a/lib/blkid/devname.c
+++ b/lib/blkid/devname.c
@@ -79,7 +79,7 @@ blkid_dev blkid_get_dev(blkid_cache cache, const char *devname, int flags)
* Probe a single block device to add to the device cache.
*/
static void probe_one(blkid_cache cache, const char *ptname,
- dev_t devno, int pri)
+ dev_t devno, int pri, int only_if_new)
{
blkid_dev dev = NULL;
struct list_head *p;
@@ -91,6 +91,8 @@ static void probe_one(blkid_cache cache, const char *ptname,
blkid_dev tmp = list_entry(p, struct blkid_struct_dev,
bid_devs);
if (tmp->bid_devno == devno) {
+ if (only_if_new)
+ return;
dev = blkid_verify(cache, tmp);
break;
}
@@ -171,7 +173,7 @@ static dev_t lvm_get_devno(const char *lvm_device)
return ret;
}
-static void lvm_probe_all(blkid_cache cache)
+static void lvm_probe_all(blkid_cache cache, int only_if_new)
{
DIR *vg_list;
struct dirent *vg_iter;
@@ -222,7 +224,8 @@ static void lvm_probe_all(blkid_cache cache)
DBG(DEBUG_DEVNAME, printf("LVM dev %s: devno 0x%04X\n",
lvm_device,
(unsigned int) dev));
- probe_one(cache, lvm_device, dev, BLKID_PRI_LVM);
+ probe_one(cache, lvm_device, dev, BLKID_PRI_LVM,
+ only_if_new);
free(lvm_device);
}
closedir(lv_list);
@@ -235,7 +238,7 @@ exit:
#define PROC_EVMS_VOLUMES "/proc/evms/volumes"
static int
-evms_probe_all(blkid_cache cache)
+evms_probe_all(blkid_cache cache, int only_if_new)
{
char line[100];
int ma, mi, sz, num = 0;
@@ -253,7 +256,8 @@ evms_probe_all(blkid_cache cache)
DBG(DEBUG_DEVNAME, printf("Checking partition %s (%d, %d)\n",
device, ma, mi));
- probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS);
+ probe_one(cache, device, makedev(ma, mi), BLKID_PRI_EVMS,
+ only_if_new);
num++;
}
fclose(procpt);
@@ -263,7 +267,7 @@ evms_probe_all(blkid_cache cache)
/*
* Read the device data for all available block devices in the system.
*/
-int blkid_probe_all(blkid_cache cache)
+static int probe_all(blkid_cache cache, int only_if_new)
{
FILE *proc;
char line[1024];
@@ -286,9 +290,9 @@ int blkid_probe_all(blkid_cache cache)
return 0;
blkid_read_cache(cache);
- evms_probe_all(cache);
+ evms_probe_all(cache, only_if_new);
#ifdef VG_DIR
- lvm_probe_all(cache);
+ lvm_probe_all(cache, only_if_new);
#endif
proc = fopen(PROC_PARTITIONS, "r");
@@ -325,7 +329,8 @@ int blkid_probe_all(blkid_cache cache)
ptname, (unsigned int) devs[which]));
if (sz > 1)
- probe_one(cache, ptname, devs[which], 0);
+ probe_one(cache, ptname, devs[which], 0,
+ only_if_new);
lens[which] = 0;
lens[last] = 0;
} else if (lens[last] && strncmp(ptnames[last], ptname,
@@ -333,23 +338,44 @@ int blkid_probe_all(blkid_cache cache)
DBG(DEBUG_DEVNAME,
printf("whole dev %s, devno 0x%04X\n",
ptnames[last], (unsigned int) devs[last]));
- probe_one(cache, ptnames[last], devs[last], 0);
+ probe_one(cache, ptnames[last], devs[last], 0,
+ only_if_new);
lens[last] = 0;
}
}
/* Handle the last device if it wasn't partitioned */
if (lens[which])
- probe_one(cache, ptname, devs[which], 0);
+ probe_one(cache, ptname, devs[which], 0, only_if_new);
fclose(proc);
+ blkid_flush_cache(cache);
+ return 0;
+}
+int blkid_probe_all(blkid_cache cache)
+{
+ int ret;
+
+ DBG(DEBUG_PROBE, printf("Begin blkid_probe_all()\n"));
+ ret = probe_all(cache, 0);
cache->bic_time = time(0);
cache->bic_flags |= BLKID_BIC_FL_PROBED;
- blkid_flush_cache(cache);
- return 0;
+ DBG(DEBUG_PROBE, printf("End blkid_probe_all()\n"));
+ return ret;
}
+int blkid_probe_all_new(blkid_cache cache)
+{
+ int ret;
+
+ DBG(DEBUG_PROBE, printf("Begin blkid_probe_all_new()\n"));
+ ret = probe_all(cache, 1);
+ DBG(DEBUG_PROBE, printf("End blkid_probe_all_new()\n"));
+ return ret;
+}
+
+
#ifdef TEST_PROGRAM
int main(int argc, char **argv)
{
diff --git a/lib/blkid/tag.c b/lib/blkid/tag.c
index 9470ac01..9bca2c6a 100644
--- a/lib/blkid/tag.c
+++ b/lib/blkid/tag.c
@@ -316,9 +316,6 @@ extern void blkid_tag_iterate_end(blkid_tag_iterate iter)
* type/value pair. If there is more than one device that matches the
* search specification, it returns the one with the highest priority
* value. This allows us to give preference to EVMS or LVM devices.
- *
- * XXX there should also be an interface which uses an iterator so we
- * can get all of the devices which match a type/value search parameter.
*/
extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
const char *type,
@@ -328,6 +325,7 @@ extern blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
blkid_dev dev;
int pri;
struct list_head *p;
+ int probe_new = 0;
if (!cache || !type || !value)
return NULL;
@@ -359,6 +357,13 @@ try_again:
goto try_again;
}
+ if (!dev && !probe_new) {
+ if (blkid_probe_all_new(cache) < 0)
+ return NULL;
+ probe_new++;
+ goto try_again;
+ }
+
if (!dev && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
if (blkid_probe_all(cache) < 0)
return NULL;