mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 14:57:42 +00:00
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:
parent
ddcf4730ce
commit
56a03233ab
@ -1564,6 +1564,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
|||||||
char *stablepath;
|
char *stablepath;
|
||||||
int opentries = 0;
|
int opentries = 0;
|
||||||
int retry = 0;
|
int retry = 0;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
/* Short circuit if pool has no target, or if its /dev */
|
/* Short circuit if pool has no target, or if its /dev */
|
||||||
if (pool->def->target.path == NULL ||
|
if (pool->def->target.path == NULL ||
|
||||||
@ -1604,10 +1605,11 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
|||||||
* to this device node.
|
* to this device node.
|
||||||
*
|
*
|
||||||
* And it might need some time till the stable path shows
|
* 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:
|
retry:
|
||||||
while ((dent = readdir(dh)) != NULL) {
|
while ((direrr = virDirRead(dh, &dent, NULL)) > 0) {
|
||||||
if (dent->d_name[0] == '.')
|
if (dent->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -1626,7 +1628,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
|||||||
VIR_FREE(stablepath);
|
VIR_FREE(stablepath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loop && ++retry < 100) {
|
if (!direrr && loop && ++retry < 100) {
|
||||||
usleep(100 * 1000);
|
usleep(100 * 1000);
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
@ -854,6 +854,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
struct dirent *ent;
|
struct dirent *ent;
|
||||||
struct statvfs sb;
|
struct statvfs sb;
|
||||||
virStorageVolDefPtr vol = NULL;
|
virStorageVolDefPtr vol = NULL;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
if (!(dir = opendir(pool->def->target.path))) {
|
if (!(dir = opendir(pool->def->target.path))) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -862,7 +863,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((ent = readdir(dir)) != NULL) {
|
while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
|
||||||
int ret;
|
int ret;
|
||||||
char *backingStore;
|
char *backingStore;
|
||||||
int backingStoreFormat;
|
int backingStoreFormat;
|
||||||
@ -924,9 +925,10 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
|
if (VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
if (direrr < 0)
|
||||||
|
goto cleanup;
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
|
||||||
|
|
||||||
if (statvfs(pool->def->target.path, &sb) < 0) {
|
if (statvfs(pool->def->target.path, &sb) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("cannot statvfs path '%s'"),
|
_("cannot statvfs path '%s'"),
|
||||||
|
@ -93,6 +93,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
|
|||||||
int retval = 0;
|
int retval = 0;
|
||||||
DIR *sysdir = NULL;
|
DIR *sysdir = NULL;
|
||||||
struct dirent *dirent = NULL;
|
struct dirent *dirent = NULL;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
VIR_DEBUG("Finding host number from '%s'", sysfs_path);
|
VIR_DEBUG("Finding host number from '%s'", sysfs_path);
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((dirent = readdir(sysdir))) {
|
while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) {
|
||||||
if (STREQLEN(dirent->d_name, "target", strlen("target"))) {
|
if (STREQLEN(dirent->d_name, "target", strlen("target"))) {
|
||||||
if (sscanf(dirent->d_name,
|
if (sscanf(dirent->d_name,
|
||||||
"target%u:", host) != 1) {
|
"target%u:", host) != 1) {
|
||||||
@ -117,6 +118,8 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (direrr < 0)
|
||||||
|
retval = -1;
|
||||||
|
|
||||||
closedir(sysdir);
|
closedir(sysdir);
|
||||||
out:
|
out:
|
||||||
|
@ -237,6 +237,7 @@ getNewStyleBlockDevice(const char *lun_path,
|
|||||||
DIR *block_dir = NULL;
|
DIR *block_dir = NULL;
|
||||||
struct dirent *block_dirent = NULL;
|
struct dirent *block_dirent = NULL;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
|
if (virAsprintf(&block_path, "%s/block", lun_path) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
@ -252,7 +253,7 @@ getNewStyleBlockDevice(const char *lun_path,
|
|||||||
goto out;
|
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)) {
|
if (STREQLEN(block_dirent->d_name, ".", 1)) {
|
||||||
continue;
|
continue;
|
||||||
@ -268,6 +269,8 @@ getNewStyleBlockDevice(const char *lun_path,
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (direrr < 0)
|
||||||
|
retval = -1;
|
||||||
|
|
||||||
closedir(block_dir);
|
closedir(block_dir);
|
||||||
|
|
||||||
@ -319,6 +322,7 @@ getBlockDevice(uint32_t host,
|
|||||||
DIR *lun_dir = NULL;
|
DIR *lun_dir = NULL;
|
||||||
struct dirent *lun_dirent = NULL;
|
struct dirent *lun_dirent = NULL;
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
int direrr;
|
||||||
|
|
||||||
if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
|
if (virAsprintf(&lun_path, "/sys/bus/scsi/devices/%u:%u:%u:%u",
|
||||||
host, bus, target, lun) < 0)
|
host, bus, target, lun) < 0)
|
||||||
@ -333,7 +337,7 @@ getBlockDevice(uint32_t host,
|
|||||||
goto out;
|
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 (STREQLEN(lun_dirent->d_name, "block", 5)) {
|
||||||
if (strlen(lun_dirent->d_name) == 5) {
|
if (strlen(lun_dirent->d_name) == 5) {
|
||||||
retval = getNewStyleBlockDevice(lun_path,
|
retval = getNewStyleBlockDevice(lun_path,
|
||||||
@ -442,7 +446,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
|
|||||||
|
|
||||||
snprintf(devicepattern, sizeof(devicepattern), "%u:%%u:%%u:%%u\n", scanhost);
|
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,
|
if (sscanf(lun_dirent->d_name, devicepattern,
|
||||||
&bus, &target, &lun) != 3) {
|
&bus, &target, &lun) != 3) {
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user