mirror of https://gitee.com/openkylin/libvirt.git
hyperv: reduce duplicate code for Msvm_ComputerSystem lookups
Signed-off-by: Matt Coleman <matt@datto.com> Reviewed-by: Neal Gompa <ngompa13@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
855af506d3
commit
f1c406a9aa
|
@ -172,30 +172,6 @@ hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
hypervGetVirtualSystemByUUID(hypervPrivate *priv, const char *uuid,
|
||||
Msvm_ComputerSystem **computerSystemList)
|
||||
{
|
||||
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
|
||||
virBufferEscapeSQL(&query,
|
||||
MSVM_COMPUTERSYSTEM_WQL_SELECT
|
||||
"WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
|
||||
"AND Name = '%s'",
|
||||
uuid);
|
||||
|
||||
if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0)
|
||||
return -1;
|
||||
|
||||
if (*computerSystemList == NULL) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("No domain with UUID %s"), uuid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
hypervGetVirtualSystemByName(hypervPrivate *priv, const char *name,
|
||||
Msvm_ComputerSystem **computerSystemList)
|
||||
|
@ -806,7 +782,7 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|||
|
||||
virUUIDFormat(uuid, uuid_string);
|
||||
|
||||
if (hypervGetVirtualSystemByUUID(priv, uuid_string, &computerSystem) < 0)
|
||||
if (hypervMsvmComputerSystemFromUUID(priv, uuid_string, &computerSystem) < 0)
|
||||
goto cleanup;
|
||||
|
||||
hypervMsvmComputerSystemToDomain(conn, computerSystem, &domain);
|
||||
|
|
|
@ -1508,32 +1508,27 @@ hypervMsvmComputerSystemToDomain(virConnectPtr conn,
|
|||
|
||||
|
||||
int
|
||||
hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
|
||||
Msvm_ComputerSystem **computerSystem)
|
||||
hypervMsvmComputerSystemFromUUID(hypervPrivate *priv, const char *uuid,
|
||||
Msvm_ComputerSystem **computerSystem)
|
||||
{
|
||||
hypervPrivate *priv = domain->conn->privateData;
|
||||
char uuid_string[VIR_UUID_STRING_BUFLEN];
|
||||
g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (computerSystem == NULL || *computerSystem != NULL) {
|
||||
if (!computerSystem || *computerSystem) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
virUUIDFormat(domain->uuid, uuid_string);
|
||||
|
||||
virBufferAsprintf(&query,
|
||||
MSVM_COMPUTERSYSTEM_WQL_SELECT
|
||||
"WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
|
||||
"AND Name = '%s'", uuid_string);
|
||||
virBufferEscapeSQL(&query,
|
||||
MSVM_COMPUTERSYSTEM_WQL_SELECT
|
||||
"WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
|
||||
"AND Name = '%s'", uuid);
|
||||
|
||||
if (hypervGetWmiClassList(priv, Msvm_ComputerSystem_WmiInfo, &query,
|
||||
(hypervObject **)computerSystem) < 0)
|
||||
return -1;
|
||||
|
||||
if (*computerSystem == NULL) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN,
|
||||
_("No domain with UUID %s"), uuid_string);
|
||||
if (!*computerSystem) {
|
||||
virReportError(VIR_ERR_NO_DOMAIN, _("No domain with UUID %s"), uuid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1541,6 +1536,19 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
|
|||
}
|
||||
|
||||
|
||||
int
|
||||
hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
|
||||
Msvm_ComputerSystem **computerSystem)
|
||||
{
|
||||
hypervPrivate *priv = domain->conn->privateData;
|
||||
char uuidString[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
virUUIDFormat(domain->uuid, uuidString);
|
||||
|
||||
return hypervMsvmComputerSystemFromUUID(priv, uuidString, computerSystem);
|
||||
}
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Msvm_VirtualSystemSettingData
|
||||
*/
|
||||
|
|
|
@ -233,5 +233,9 @@ int hypervMsvmComputerSystemToDomain(virConnectPtr conn,
|
|||
Msvm_ComputerSystem *computerSystem,
|
||||
virDomainPtr *domain);
|
||||
|
||||
int
|
||||
hypervMsvmComputerSystemFromUUID(hypervPrivate *priv, const char *uuid,
|
||||
Msvm_ComputerSystem **computerSystem);
|
||||
|
||||
int hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
|
||||
Msvm_ComputerSystem **computerSystem);
|
||||
|
|
Loading…
Reference in New Issue