]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Don't do wait loops from VolLookupByPath
authorCole Robinson <crobinso@redhat.com>
Sun, 21 Oct 2012 16:53:20 +0000 (12:53 -0400)
committerCole Robinson <crobinso@redhat.com>
Sat, 27 Oct 2012 19:14:00 +0000 (15:14 -0400)
virStorageVolLookupByPath is an API call that virt-manager uses
quite a bit when dealing with storage. This call use BackendStablePath
which has several usleep() heuristics that can be tripped up
and hang virt-manager for a while.

Current example: an empty mpath pool pointing to /dev/mapper makes
_any_ calls to virStorageVolLookupByPath take 5 seconds.

The sleep heuristics are actually only needed in certain cases
when we are waiting for new storage to appear, so let's skip the
timeout steps when calling from LookupByPath.
(cherry picked from commit 77eff5eeb2d2aada3c670d325d04a35b54428988)

src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_disk.c
src/storage/storage_backend_scsi.c
src/storage/storage_driver.c

index aea70e2561a84a47fb5d7b43263d393681e092ca..85b8287e30d62267905762ced7af69b7e8448df6 100644 (file)
@@ -1338,10 +1338,14 @@ virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
  *
  * Typically target.path is one of the /dev/disk/by-XXX dirs
  * with stable paths.
+ *
+ * If 'wait' is true, we use a timeout loop to give dynamic paths
+ * a change to appear.
  */
 char *
 virStorageBackendStablePath(virStoragePoolObjPtr pool,
-                            const char *devpath)
+                            const char *devpath,
+                            bool wait)
 {
     DIR *dh;
     struct dirent *dent;
@@ -1372,7 +1376,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
  reopen:
     if ((dh = opendir(pool->def->target.path)) == NULL) {
         opentries++;
-        if (errno == ENOENT && opentries < 50) {
+        if (wait && errno == ENOENT && opentries < 50) {
             usleep(100 * 1000);
             goto reopen;
         }
@@ -1387,7 +1391,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
      * the target directory and figure out which one points
      * to this device node.
      *
-     * And it might need some time till the stabe path shows
+     * And it might need some time till the stable path shows
      * up, so add timeout to retry here.
      */
  retry:
@@ -1411,7 +1415,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
         VIR_FREE(stablepath);
     }
 
-    if (++retry < 100) {
+    if (wait && ++retry < 100) {
         usleep(100 * 1000);
         goto retry;
     }
index a67eeb7ddfb7d231ee2a4177dffee99ff84bcde9..71935a76073de5826673c0828f10bc81cd1bedde 100644 (file)
@@ -130,7 +130,8 @@ virStorageBackendDetectBlockVolFormatFD(virStorageVolTargetPtr target,
                                         int fd);
 
 char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
-                                  const char *devpath);
+                                  const char *devpath,
+                                  bool wait);
 
 typedef int (*virStorageBackendListVolRegexFunc)(virStoragePoolObjPtr pool,
                                                  char **const groups,
index ceceab06f90f80703d53c3f30145913c129c3272..b7bceea0c47fc8be1d9795dc204fd5ec8415b6fc 100644 (file)
@@ -83,7 +83,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
          * dir every time its run. Should figure out a more efficient
          * way of doing this...
          */
-        vol->target.path = virStorageBackendStablePath(pool, devpath);
+        vol->target.path = virStorageBackendStablePath(pool, devpath, true);
         VIR_FREE(devpath);
         if (vol->target.path == NULL)
             return -1;
index 27dcbb67eaccb71d083bae7e61e59b4345633f09..4e832eb6564733cbce6e1107be03cffdeced6a3a 100644 (file)
@@ -246,7 +246,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
      * way of doing this...
      */
     if ((vol->target.path = virStorageBackendStablePath(pool,
-                                                        devpath)) == NULL) {
+                                                        devpath,
+                                                        true)) == NULL) {
         retval = -1;
         goto free_vol;
     }
index 28829d3800e45d4e7287b3330d1c21a80f6e3517..4fbc0c015d6d6a29720bd5444d7369007c65154b 100644 (file)
@@ -1318,7 +1318,8 @@ storageVolumeLookupByPath(virConnectPtr conn,
             const char *stable_path;
 
             stable_path = virStorageBackendStablePath(driver->pools.objs[i],
-                                                      cleanpath);
+                                                      cleanpath,
+                                                      false);
             if (stable_path == NULL) {
                 /* Don't break the whole lookup process if it fails on
                  * getting the stable path for some of the pools.