storage: use virDirRead API

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>
This commit is contained in:
Eric Blake 2014-04-24 15:48:55 -06:00
parent ddcf4730ce
commit 56a03233ab
4 changed files with 20 additions and 9 deletions

View 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;
}

View 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'"),

View 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:

View 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;