]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: use virDirRead API
authorEric Blake <eblake@redhat.com>
Thu, 24 Apr 2014 21:48:55 +0000 (15:48 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 28 Apr 2014 23:52:46 +0000 (17:52 -0600)
More instances of failure to report (unlikely) readdir errors.
In one case, I chose to ignore them, given that a readdir error
would be no different than timing out on the loop, where the
fallback path behaves correctly either way.

* src/storage/storage_backend.c (virStorageBackendStablePath):
Ignore readdir errors.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemRefresh): Report readdir errors.
* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIGetHostNumber): Likewise.
* src/storage/storage_backend_scsi.c (getNewStyleBlockDevice)
(getBlockDevice, virStorageBackendSCSIFindLUs): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/storage/storage_backend.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_iscsi.c
src/storage/storage_backend_scsi.c

index 946196b0bf6113f413258cbc2e9edfbaf5b36546..58468b3735bee73eb1169463b5f289026822392f 100644 (file)
@@ -1564,6 +1564,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
     char *stablepath;
     int opentries = 0;
     int retry = 0;
+    int direrr;
 
     /* Short circuit if pool has no target, or if its /dev */
     if (pool->def->target.path == NULL ||
@@ -1604,10 +1605,11 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
      * to this device node.
      *
      * And it might need some time till the stable path shows
-     * up, so add timeout to retry here.
+     * up, so add timeout to retry here.  Ignore readdir failures,
+     * since we have a fallback.
      */
  retry:
-    while ((dent = readdir(dh)) != NULL) {
+    while ((direrr = virDirRead(dh, &dent, NULL)) > 0) {
         if (dent->d_name[0] == '.')
             continue;
 
@@ -1626,7 +1628,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
         VIR_FREE(stablepath);
     }
 
-    if (loop && ++retry < 100) {
+    if (!direrr && loop && ++retry < 100) {
         usleep(100 * 1000);
         goto retry;
     }
index 3e3d55fd157b4615c927129638d9d088ef22b521..0f98853a26e80aafb74a26747aa1549e34eafc9e 100644 (file)
@@ -854,6 +854,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
     struct dirent *ent;
     struct statvfs sb;
     virStorageVolDefPtr vol = NULL;
+    int direrr;
 
     if (!(dir = opendir(pool->def->target.path))) {
         virReportSystemError(errno,
@@ -862,7 +863,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto cleanup;
     }
 
-    while ((ent = readdir(dir)) != NULL) {
+    while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
         int ret;
         char *backingStore;
         int backingStoreFormat;
@@ -924,9 +925,10 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
             goto cleanup;
     }
+    if (direrr < 0)
+        goto cleanup;
     closedir(dir);
 
-
     if (statvfs(pool->def->target.path, &sb) < 0) {
         virReportSystemError(errno,
                              _("cannot statvfs path '%s'"),
index 881159b3054e4f11041d3159f569416b317131f2..aa6980caea0ab2dd54151f32f15f05231cf76157 100644 (file)
@@ -93,6 +93,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
     int retval = 0;
     DIR *sysdir = NULL;
     struct dirent *dirent = NULL;
+    int direrr;
 
     VIR_DEBUG("Finding host number from '%s'", sysfs_path);
 
@@ -107,7 +108,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
         goto out;
     }
 
-    while ((dirent = readdir(sysdir))) {
+    while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) {
         if (STREQLEN(dirent->d_name, "target", strlen("target"))) {
             if (sscanf(dirent->d_name,
                        "target%u:", host) != 1) {
@@ -117,6 +118,8 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
             }
         }
     }
+    if (direrr < 0)
+        retval = -1;
 
     closedir(sysdir);
  out:
index c448d7fc44b7231ee5489ccc952487d762b2ab4b..d037f4688375183975030d44d87b80bbb8b00493 100644 (file)
@@ -237,6 +237,7 @@ getNewStyleBlockDevice(const char *lun_path,
     DIR *block_dir = NULL;
     struct dirent *block_dirent = NULL;
     int retval = 0;
+    int direrr;
 
     if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
         goto out;
@@ -252,7 +253,7 @@ getNewStyleBlockDevice(const char *lun_path,
         goto out;
     }
 
-    while ((block_dirent = readdir(block_dir))) {
+    while ((direrr = virDirRead(block_dir, &block_dirent, block_path)) > 0) {
 
         if (STREQLEN(block_dirent->d_name, ".", 1)) {
             continue;
@@ -268,6 +269,8 @@ getNewStyleBlockDevice(const char *lun_path,
 
         break;
     }
+    if (direrr < 0)
+        retval = -1;
 
     closedir(block_dir);
 
@@ -319,6 +322,7 @@ getBlockDevice(uint32_t host,
     DIR *lun_dir = NULL;
     struct dirent *lun_dirent = NULL;
     int retval = 0;
+    int direrr;
 
     if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
                     host, bus, target, lun) < 0)
@@ -333,7 +337,7 @@ getBlockDevice(uint32_t host,
         goto out;
     }
 
-    while ((lun_dirent = readdir(lun_dir))) {
+    while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
         if (STREQLEN(lun_dirent->d_name, "block", 5)) {
             if (strlen(lun_dirent->d_name) == 5) {
                 retval = getNewStyleBlockDevice(lun_path,
@@ -442,7 +446,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
 
     snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
 
-    while ((lun_dirent = readdir(devicedir))) {
+    while ((retval = virDirRead(devicedir, &lun_dirent, device_path)) > 0) {
         if (sscanf(lun_dirent->d_name, devicepattern,
                    &bus, &target, &lun) != 3) {
             continue;