提交 f6a5cbbf 编写于 作者: J John Ferlan

qemu: Refactor qemuCheckSharedDisk to create qemuCheckUnprivSGIO

Split out the current function in order to share the code with hostdev
in a future patch. Failure to match the expected sgio value against what
is stored will cause an error which the caller would need to handle since
only the caller has the disk (or eventually hostdev) specific data in
order to uniquely identify the disk in an error message.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 e9c27344
...@@ -1018,26 +1018,28 @@ qemuGetSharedDeviceKey(const char *device_path) ...@@ -1018,26 +1018,28 @@ qemuGetSharedDeviceKey(const char *device_path)
return key; return key;
} }
/* Check if a shared device's setting conflicts with the conf /*
* used by other domain(s). Currently only checks the sgio * Make necessary checks for the need to check and for the current setting
* setting. Note that this should only be called for disk with * of the 'unpriv_sgio' value for the device_path passed.
* block source if the device type is disk.
* *
* Returns 0 if no conflicts, otherwise returns -1. * Returns:
* 0 - Success
* -1 - Some failure which would already have been messaged
* -2 - Mismatch with the "shared" sgio setting - needs to be messaged
* by caller since it has context of which type of disk resource is
* being used and in the future the hostdev information.
*/ */
static int static int
qemuCheckSharedDisk(virHashTablePtr sharedDevices, qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
virDomainDiskDefPtr disk) const char *device_path,
int sgio)
{ {
char *sysfs_path = NULL; char *sysfs_path = NULL;
char *key = NULL; char *key = NULL;
int val; int val;
int ret = -1; int ret = -1;
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN) if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
return 0;
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src->path, NULL)))
goto cleanup; goto cleanup;
/* It can't be conflict if unpriv_sgio is not supported by kernel. */ /* It can't be conflict if unpriv_sgio is not supported by kernel. */
...@@ -1046,7 +1048,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices, ...@@ -1046,7 +1048,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices,
goto cleanup; goto cleanup;
} }
if (!(key = qemuGetSharedDeviceKey(disk->src->path))) if (!(key = qemuGetSharedDeviceKey(device_path)))
goto cleanup; goto cleanup;
/* It can't be conflict if no other domain is sharing it. */ /* It can't be conflict if no other domain is sharing it. */
...@@ -1055,27 +1057,18 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices, ...@@ -1055,27 +1057,18 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices,
goto cleanup; goto cleanup;
} }
if (virGetDeviceUnprivSGIO(disk->src->path, NULL, &val) < 0) if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
goto cleanup; goto cleanup;
/* Error message on failure needs to be handled in caller
* since there is more specific knowledge of device
*/
if (!((val == 0 && if (!((val == 0 &&
(disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED || (sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) || sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
(val == 1 && (val == 1 &&
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) { sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
ret = -2;
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;
} }
...@@ -1088,6 +1081,45 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices, ...@@ -1088,6 +1081,45 @@ qemuCheckSharedDisk(virHashTablePtr sharedDevices,
} }
/* Check if a shared device's setting conflicts with the conf
* used by other domain(s). Currently only checks the sgio
* setting. Note that this should only be called for disk with
* block source if the device type is disk.
*
* Returns 0 if no conflicts, otherwise returns -1.
*/
static int
qemuCheckSharedDisk(virHashTablePtr sharedDevices,
virDomainDiskDefPtr disk)
{
int ret;
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
return 0;
if ((ret = qemuCheckUnprivSGIO(sharedDevices, disk->src->path,
disk->sgio)) < 0) {
if (ret == -2) {
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);
}
}
return -1;
}
return 0;
}
bool bool
qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry, qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name, const char *name,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册