]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: don't mark cache as "probed" if /sys not available
authorKarel Zak <kzak@redhat.com>
Fri, 19 Nov 2021 13:19:03 +0000 (14:19 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 19 Nov 2021 13:19:03 +0000 (14:19 +0100)
For "mount --all" we need to read the cache more than once in a short
time. The library checks the delay between probes, and if the delay is
too short, it does not read devices. This is a problem on boot when there
are no /sys, and the cache is empty. In this case, we need to check
for /sys until it's available constantly.

https://github.com/util-linux/util-linux/issues/1492
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/devname.c
libblkid/src/resolve.c
libblkid/src/tag.c

index 90a8245fc9cdb9c0430315c6cd6a69a168355bf4..9a173e3489ab8d6611f5e2fbdcd65f16552d0ac5 100644 (file)
@@ -429,6 +429,8 @@ sysfs_probe_all(blkid_cache cache, int only_if_new, int only_removable)
        if (!sysfs)
                return -BLKID_ERR_SYSFS;
 
+       DBG(DEVNAME, ul_debug(" probe /sys/block"));
+
        /* scan /sys/block */
        while ((dev = xreaddir(sysfs))) {
                DIR *dir = NULL;
@@ -533,14 +535,18 @@ sysfs_probe_all(blkid_cache cache, int only_if_new, int only_removable)
 /*
  * Read the device data for all available block devices in the system.
  */
-static int probe_all(blkid_cache cache, int only_if_new)
+static int probe_all(blkid_cache cache, int only_if_new, int update_interval)
 {
+       int rc;
+
        if (!cache)
                return -BLKID_ERR_PARAM;
 
        if (cache->bic_flags & BLKID_BIC_FL_PROBED &&
-           time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL)
+           time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL) {
+               DBG(PROBE, ul_debug("don't re-probe [delay < %d]", BLKID_PROBE_INTERVAL));
                return 0;
+       }
 
        blkid_read_cache(cache);
 #ifdef VG_DIR
@@ -548,7 +554,13 @@ static int probe_all(blkid_cache cache, int only_if_new)
 #endif
        ubi_probe_all(cache, only_if_new);
 
-       sysfs_probe_all(cache, only_if_new, 0);
+       rc = sysfs_probe_all(cache, only_if_new, 0);
+
+       /* Don't mark the change as "probed" if /sys not avalable */
+       if (update_interval && rc == 0) {
+               cache->bic_time = time(NULL);
+               cache->bic_flags |= BLKID_BIC_FL_PROBED;
+       }
 
        blkid_flush_cache(cache);
        return 0;
@@ -567,11 +579,7 @@ int blkid_probe_all(blkid_cache cache)
        int ret;
 
        DBG(PROBE, ul_debug("Begin blkid_probe_all()"));
-       ret = probe_all(cache, 0);
-       if (ret == 0) {
-               cache->bic_time = time(NULL);
-               cache->bic_flags |= BLKID_BIC_FL_PROBED;
-       }
+       ret = probe_all(cache, 0, 1);
        DBG(PROBE, ul_debug("End blkid_probe_all() [rc=%d]", ret));
        return ret;
 }
@@ -589,7 +597,7 @@ int blkid_probe_all_new(blkid_cache cache)
        int ret;
 
        DBG(PROBE, ul_debug("Begin blkid_probe_all_new()"));
-       ret = probe_all(cache, 1);
+       ret = probe_all(cache, 1, 0);
        DBG(PROBE, ul_debug("End blkid_probe_all_new() [rc=%d]", ret));
        return ret;
 }
index 641b02286081331d1a4023783ec5df5961a08d95..16653fa8e1d7b1afa3c703d516eb66764cfa5239 100644 (file)
@@ -32,7 +32,7 @@ char *blkid_get_tag_value(blkid_cache cache, const char *tagname,
        blkid_cache c = cache;
        char *ret = NULL;
 
-       DBG(TAG, ul_debug("looking for %s on %s", tagname, devname));
+       DBG(TAG, ul_debug("looking for tag %s on %s device", tagname, devname));
 
        if (!devname)
                return NULL;
index 390a648648133bca4407c0086e413c734acf71d2..178336505fd6b7df2f4aacbb51212ad43f70fe40 100644 (file)
@@ -326,14 +326,14 @@ blkid_dev blkid_find_dev_with_tag(blkid_cache cache,
        blkid_dev       dev;
        int             pri;
        struct list_head *p;
-       int             probe_new = 0;
+       int             probe_new = 0, probe_all = 0;
 
        if (!cache || !type || !value)
                return NULL;
 
        blkid_read_cache(cache);
 
-       DBG(TAG, ul_debug("looking for %s=%s in cache", type, value));
+       DBG(TAG, ul_debug("looking for tag %s=%s in cache", type, value));
 
 try_again:
        pri = -1;
@@ -366,9 +366,11 @@ try_again:
                goto try_again;
        }
 
-       if (!dev && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
+       if (!dev && !probe_all
+           && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) {
                if (blkid_probe_all(cache) < 0)
                        return NULL;
+               probe_all++;
                goto try_again;
        }
        return dev;