提交 3f131ebf 编写于 作者: P Peter Krempa

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.
上级 62046c12
...@@ -814,62 +814,43 @@ qemuGetSharedDeviceKey(const char *device_path) ...@@ -814,62 +814,43 @@ 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) {
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) if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
return 0; return 0;
} else {
return 0;
}
src = virDomainDiskGetSource(disk);
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(src, NULL))) {
ret = -1;
goto cleanup;
}
/* It can't be conflict if unpriv_sgio is not supported if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src->path, NULL)))
* by kernel.
*/
if (!virFileExists(sysfs_path))
goto cleanup; goto cleanup;
if (!(key = qemuGetSharedDeviceKey(src))) { /* It can't be conflict if unpriv_sgio is not supported by kernel. */
ret = -1; if (!virFileExists(sysfs_path)) {
ret = 0;
goto cleanup; goto cleanup;
} }
/* It can't be conflict if no other domain is if (!(key = qemuGetSharedDeviceKey(disk->src->path)))
* is sharing it.
*/
if (!(virHashLookup(sharedDevices, key)))
goto cleanup; goto cleanup;
if (virGetDeviceUnprivSGIO(src, NULL, &val) < 0) { /* It can't be conflict if no other domain is sharing it. */
ret = -1; if (!(virHashLookup(sharedDevices, key))) {
ret = 0;
goto cleanup; goto cleanup;
} }
if ((val == 0 && if (virGetDeviceUnprivSGIO(disk->src->path, NULL, &val) < 0)
goto cleanup;
if (!((val == 0 &&
(disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED || (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) || disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
(val == 1 && (val == 1 &&
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED)) disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
goto cleanup;
if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) { if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
...@@ -880,16 +861,21 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices, ...@@ -880,16 +861,21 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
} else { } else {
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
_("sgio of shared disk '%s' conflicts with other " _("sgio of shared disk '%s' conflicts with other "
"active domains"), src); "active domains"), disk->src->path);
} }
ret = -1; goto cleanup;
}
ret = 0;
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, ...@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册