mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
scsi: Adjust return status from getBlockDevice
https://bugzilla.redhat.com/show_bug.cgi?id=1224233 Currently it's not possible to determine the difference between a fatal memory allocation or failure to open/read the directory error with a perhaps less fatal, I didn't find the "block" device in the directory (which may be a disk entry without a block device). In the case of the latter, we shouldn't cause failure to continue searching in the caller (virStorageBackendSCSIFindLUs), rather we should allow trying reading the next directory entry. Signed-off-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
a4e92f9e14
commit
5c9fc1c11f
@ -324,6 +324,15 @@ getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Search a device entry for the "block" file
|
||||||
|
*
|
||||||
|
* Returns
|
||||||
|
*
|
||||||
|
* 0 => Found it
|
||||||
|
* -1 => Fatal error
|
||||||
|
* -2 => Didn't find in lun_path directory
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
getBlockDevice(uint32_t host,
|
getBlockDevice(uint32_t host,
|
||||||
uint32_t bus,
|
uint32_t bus,
|
||||||
@ -337,36 +346,47 @@ getBlockDevice(uint32_t host,
|
|||||||
int retval = -1;
|
int retval = -1;
|
||||||
int direrr;
|
int direrr;
|
||||||
|
|
||||||
|
*block_device = NULL;
|
||||||
|
|
||||||
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)
|
||||||
goto out;
|
goto cleanup;
|
||||||
|
|
||||||
lun_dir = opendir(lun_path);
|
if (!(lun_dir = opendir(lun_path))) {
|
||||||
if (lun_dir == NULL) {
|
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to opendir sysfs path '%s'"),
|
_("Failed to opendir sysfs path '%s'"),
|
||||||
lun_path);
|
lun_path);
|
||||||
goto out;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((direrr = virDirRead(lun_dir, &lun_dirent, lun_path)) > 0) {
|
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,
|
if (getNewStyleBlockDevice(lun_path,
|
||||||
lun_dirent->d_name,
|
lun_dirent->d_name,
|
||||||
block_device);
|
block_device) < 0)
|
||||||
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
retval = getOldStyleBlockDevice(lun_path,
|
if (getOldStyleBlockDevice(lun_path,
|
||||||
lun_dirent->d_name,
|
lun_dirent->d_name,
|
||||||
block_device);
|
block_device) < 0)
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (direrr < 0)
|
||||||
|
goto cleanup;
|
||||||
|
if (!*block_device) {
|
||||||
|
retval = -2;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
retval = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (lun_dir)
|
||||||
closedir(lun_dir);
|
closedir(lun_dir);
|
||||||
|
|
||||||
out:
|
|
||||||
VIR_FREE(lun_path);
|
VIR_FREE(lun_path);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@ -412,9 +432,9 @@ processLU(virStoragePoolObjPtr pool,
|
|||||||
VIR_DEBUG("%u:%u:%u:%u is a Direct-Access LUN",
|
VIR_DEBUG("%u:%u:%u:%u is a Direct-Access LUN",
|
||||||
host, bus, target, lun);
|
host, bus, target, lun);
|
||||||
|
|
||||||
if (getBlockDevice(host, bus, target, lun, &block_device) < 0) {
|
if ((retval = getBlockDevice(host, bus, target, lun, &block_device)) < 0) {
|
||||||
VIR_DEBUG("Failed to find block device for this LUN");
|
VIR_DEBUG("Failed to find block device for this LUN");
|
||||||
return -1;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = virStorageBackendSCSINewLun(pool, host, bus, target, lun,
|
retval = virStorageBackendSCSINewLun(pool, host, bus, target, lun,
|
||||||
|
Loading…
Reference in New Issue
Block a user