1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

qemu: conf: rename qemuCheckSharedDevice to qemuCheckSharedDisk

The qemuCheckSharedDevice function is operating only on disk devices.
Rename it and change the arguments to reflect that and refactor some
logic for more readability.
This commit is contained in:
Peter Krempa 2014-08-07 14:56:30 +02:00
parent 62046c1267
commit 3f131ebf62

View File

@ -814,82 +814,68 @@ qemuGetSharedDeviceKey(const char *device_path)
* Returns 0 if no conflicts, otherwise returns -1. * Returns 0 if no conflicts, otherwise returns -1.
*/ */
static int static int
qemuCheckSharedDevice(virHashTablePtr sharedDevices, qemuCheckSharedDisk(virHashTablePtr sharedDevices,
virDomainDeviceDefPtr dev) virDomainDiskDefPtr disk)
{ {
virDomainDiskDefPtr disk = NULL;
char *sysfs_path = NULL; char *sysfs_path = NULL;
char *key = NULL; char *key = NULL;
int val; int val;
int ret = 0; int ret = -1;
const char *src;
if (dev->type == VIR_DOMAIN_DEVICE_DISK) { if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
disk = dev->data.disk;
/* The only conflicts between shared disk we care about now
* is sgio setting, which is only valid for device='lun'.
*/
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
return 0;
} else {
return 0; return 0;
}
src = virDomainDiskGetSource(disk); if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src->path, NULL)))
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(src, NULL))) { goto cleanup;
ret = -1;
/* It can't be conflict if unpriv_sgio is not supported by kernel. */
if (!virFileExists(sysfs_path)) {
ret = 0;
goto cleanup; goto cleanup;
} }
/* It can't be conflict if unpriv_sgio is not supported if (!(key = qemuGetSharedDeviceKey(disk->src->path)))
* by kernel.
*/
if (!virFileExists(sysfs_path))
goto cleanup; goto cleanup;
if (!(key = qemuGetSharedDeviceKey(src))) { /* It can't be conflict if no other domain is sharing it. */
ret = -1; if (!(virHashLookup(sharedDevices, key))) {
ret = 0;
goto cleanup; goto cleanup;
} }
/* It can't be conflict if no other domain is if (virGetDeviceUnprivSGIO(disk->src->path, NULL, &val) < 0)
* is sharing it.
*/
if (!(virHashLookup(sharedDevices, key)))
goto cleanup; goto cleanup;
if (virGetDeviceUnprivSGIO(src, NULL, &val) < 0) { if (!((val == 0 &&
ret = -1; (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
(val == 1 &&
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
"with other active domains"),
disk->src->srcpool->pool,
disk->src->srcpool->volume);
} else {
virReportError(VIR_ERR_OPERATION_INVALID,
_("sgio of shared disk '%s' conflicts with other "
"active domains"), disk->src->path);
}
goto cleanup; goto cleanup;
} }
if ((val == 0 && ret = 0;
(disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
(val == 1 &&
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
goto cleanup;
if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
"with other active domains"),
disk->src->srcpool->pool,
disk->src->srcpool->volume);
} else {
virReportError(VIR_ERR_OPERATION_INVALID,
_("sgio of shared disk '%s' conflicts with other "
"active domains"), src);
}
ret = -1;
cleanup: cleanup:
VIR_FREE(sysfs_path); VIR_FREE(sysfs_path);
VIR_FREE(key); VIR_FREE(key);
return ret; return ret;
} }
bool bool
qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry, qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name, const char *name,
@ -1007,10 +993,11 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
} }
qemuDriverLock(driver); qemuDriverLock(driver);
if (qemuCheckSharedDevice(driver->sharedDevices, dev) < 0)
goto cleanup;
if (dev->type == VIR_DOMAIN_DEVICE_DISK) { if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0)
goto cleanup;
if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk)))) if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
goto cleanup; goto cleanup;
} else { } else {