basically s/data->/data.common->/ Because the data member of hypervObject is a union, get the data via the "common" member everywhere - existing driver does not require special handling for v1 vs v2 separately. --- src/hyperv/hyperv_driver.c | 76 +++++++++++++++++++++++----------------------- src/hyperv/hyperv_wmi.c | 21 ++++++++----- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index b642a02..5d01c1f 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -240,7 +240,7 @@ hypervConnectGetHostname(virConnectPtr conn) goto cleanup; } - ignore_value(VIR_STRDUP(hostname, computerSystem->data->DNSHostName)); + ignore_value(VIR_STRDUP(hostname, computerSystem->data.common->DNSHostName)); cleanup: hypervFreeObject(priv, (hypervObject *)computerSystem); @@ -282,7 +282,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) "{Win32_ComputerSystem.Name=\"%s\"} " "where AssocClass = Win32_ComputerSystemProcessor " "ResultClass = Win32_Processor", - computerSystem->data->Name); + computerSystem->data.common->Name); if (hypervGetWin32ProcessorList(priv, &query, &processorList) < 0) goto cleanup; @@ -295,7 +295,7 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) } /* Strip the string to fit more relevant information in 32 chars */ - tmp = processorList->data->Name; + tmp = processorList->data.common->Name; while (*tmp != '\0') { if (STRPREFIX(tmp, " ")) { @@ -313,16 +313,16 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) } /* Fill struct */ - if (virStrncpy(info->model, processorList->data->Name, + if (virStrncpy(info->model, processorList->data.common->Name, sizeof(info->model) - 1, sizeof(info->model)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("CPU model %s too long for destination"), - processorList->data->Name); + processorList->data.common->Name); goto cleanup; } - info->memory = computerSystem->data->TotalPhysicalMemory / 1024; /* byte to kilobyte */ - info->mhz = processorList->data->MaxClockSpeed; + info->memory = computerSystem->data.common->TotalPhysicalMemory / 1024; /* byte to kilobyte */ + info->mhz = processorList->data.common->MaxClockSpeed; info->nodes = 1; info->sockets = 0; @@ -331,8 +331,8 @@ hypervNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) ++info->sockets; } - info->cores = processorList->data->NumberOfCores; - info->threads = info->cores / processorList->data->NumberOfLogicalProcessors; + info->cores = processorList->data.common->NumberOfCores; + info->threads = info->cores / processorList->data.common->NumberOfLogicalProcessors; info->cpus = info->sockets * info->cores; result = 0; @@ -372,7 +372,7 @@ hypervConnectListDomains(virConnectPtr conn, int *ids, int maxids) for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem->next) { - ids[count++] = computerSystem->data->ProcessID; + ids[count++] = computerSystem->data.common->ProcessID; if (count >= maxids) break; @@ -532,7 +532,7 @@ hypervDomainSuspend(virDomainPtr domain) if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - if (computerSystem->data->EnabledState != + if (computerSystem->data.common->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_ENABLED) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not active")); @@ -560,7 +560,7 @@ hypervDomainResume(virDomainPtr domain) if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - if (computerSystem->data->EnabledState != + if (computerSystem->data.common->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_PAUSED) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain is not paused")); @@ -666,7 +666,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_VirtualSystemSettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } @@ -676,7 +676,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) "{Msvm_VirtualSystemSettingData.InstanceID=\"%s\"} " "where AssocClass = Msvm_VirtualSystemSettingDataComponent " "ResultClass = Msvm_ProcessorSettingData", - virtualSystemSettingData->data->InstanceID); + virtualSystemSettingData->data.common->InstanceID); if (hypervGetMsvmProcessorSettingDataList(priv, &query, &processorSettingData) < 0) { @@ -687,7 +687,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_ProcessorSettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } @@ -697,7 +697,7 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) "{Msvm_VirtualSystemSettingData.InstanceID=\"%s\"} " "where AssocClass = Msvm_VirtualSystemSettingDataComponent " "ResultClass = Msvm_MemorySettingData", - virtualSystemSettingData->data->InstanceID); + virtualSystemSettingData->data.common->InstanceID); if (hypervGetMsvmMemorySettingDataList(priv, &query, &memorySettingData) < 0) { @@ -709,15 +709,15 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_MemorySettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } /* Fill struct */ info->state = hypervMsvmComputerSystemEnabledStateToDomainState(computerSystem); - info->maxMem = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ - info->memory = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */ - info->nrVirtCpu = processorSettingData->data->VirtualQuantity; + info->maxMem = memorySettingData->data.common->Limit * 1024; /* megabyte to kilobyte */ + info->memory = memorySettingData->data.common->VirtualQuantity * 1024; /* megabyte to kilobyte */ + info->nrVirtCpu = processorSettingData->data.common->VirtualQuantity; info->cpuTime = 0; result = 0; @@ -803,7 +803,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_VirtualSystemSettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } @@ -813,7 +813,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) "{Msvm_VirtualSystemSettingData.InstanceID=\"%s\"} " "where AssocClass = Msvm_VirtualSystemSettingDataComponent " "ResultClass = Msvm_ProcessorSettingData", - virtualSystemSettingData->data->InstanceID); + virtualSystemSettingData->data.common->InstanceID); if (hypervGetMsvmProcessorSettingDataList(priv, &query, &processorSettingData) < 0) { @@ -824,7 +824,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_ProcessorSettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } @@ -834,7 +834,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) "{Msvm_VirtualSystemSettingData.InstanceID=\"%s\"} " "where AssocClass = Msvm_VirtualSystemSettingDataComponent " "ResultClass = Msvm_MemorySettingData", - virtualSystemSettingData->data->InstanceID); + virtualSystemSettingData->data.common->InstanceID); if (hypervGetMsvmMemorySettingDataList(priv, &query, &memorySettingData) < 0) { @@ -846,7 +846,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not lookup %s for domain %s"), "Msvm_MemorySettingData", - computerSystem->data->ElementName); + computerSystem->data.common->ElementName); goto cleanup; } @@ -854,34 +854,34 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def->virtType = VIR_DOMAIN_VIRT_HYPERV; if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) { - def->id = computerSystem->data->ProcessID; + def->id = computerSystem->data.common->ProcessID; } else { def->id = -1; } - if (virUUIDParse(computerSystem->data->Name, def->uuid) < 0) { + if (virUUIDParse(computerSystem->data.common->Name, def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse UUID from string '%s'"), - computerSystem->data->Name); + computerSystem->data.common->Name); return NULL; } - if (VIR_STRDUP(def->name, computerSystem->data->ElementName) < 0) + if (VIR_STRDUP(def->name, computerSystem->data.common->ElementName) < 0) goto cleanup; - if (VIR_STRDUP(def->description, virtualSystemSettingData->data->Notes) < 0) + if (VIR_STRDUP(def->description, virtualSystemSettingData->data.common->Notes) < 0) goto cleanup; - virDomainDefSetMemoryTotal(def, memorySettingData->data->Limit * 1024); /* megabyte to kilobyte */ - def->mem.cur_balloon = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */ + virDomainDefSetMemoryTotal(def, memorySettingData->data.common->Limit * 1024); /* megabyte to kilobyte */ + def->mem.cur_balloon = memorySettingData->data.common->VirtualQuantity * 1024; /* megabyte to kilobyte */ if (virDomainDefSetVcpusMax(def, - processorSettingData->data->VirtualQuantity, + processorSettingData->data.common->VirtualQuantity, NULL) < 0) goto cleanup; if (virDomainDefSetVcpus(def, - processorSettingData->data->VirtualQuantity) < 0) + processorSettingData->data.common->VirtualQuantity) < 0) goto cleanup; def->os.type = VIR_DOMAIN_OSTYPE_HVM; @@ -930,7 +930,7 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem->next) { - if (VIR_STRDUP(names[count], computerSystem->data->ElementName) < 0) + if (VIR_STRDUP(names[count], computerSystem->data.common->ElementName) < 0) goto cleanup; ++count; @@ -1154,7 +1154,7 @@ hypervDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags) if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - result = computerSystem->data->EnabledState == + result = computerSystem->data.common->EnabledState == MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED ? 1 : 0; cleanup: @@ -1177,7 +1177,7 @@ hypervDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags) if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0) goto cleanup; - if (computerSystem->data->EnabledState != + if (computerSystem->data.common->EnabledState != MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("Domain has no managed save image")); @@ -1280,7 +1280,7 @@ hypervConnectListAllDomains(virConnectPtr conn, /* managed save filter */ if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE)) { - bool mansave = computerSystem->data->EnabledState == + bool mansave = computerSystem->data.common->EnabledState == MSVM_COMPUTERSYSTEM_ENABLEDSTATE_SUSPENDED; if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) && mansave) || diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 9e62f57..7a9aa52 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -439,6 +439,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, virBuffer query = VIR_BUFFER_INITIALIZER; Msvm_ConcreteJob *concreteJob = NULL; bool completed = false; + const char *resourceUri = MSVM_COMPUTERSYSTEM_V2_RESOURCE_URI; + virUUIDFormat(domain->uuid, uuid_string); @@ -447,6 +449,9 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, virAsprintf(&properties, "RequestedState=%d", requestedState) < 0) goto cleanup; + if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) + resourceUri = MSVM_COMPUTERSYSTEM_V2_RESOURCE_URI; + options = wsmc_options_init(); if (options == NULL) { @@ -459,7 +464,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, wsmc_add_prop_from_str(options, properties); /* Invoke method */ - response = wsmc_action_invoke(priv->client, MSVM_COMPUTERSYSTEM_RESOURCE_URI, + response = wsmc_action_invoke(priv->client, resourceUri, options, "RequestStateChange", NULL); if (hypervVerifyResponse(priv->client, response, "invocation") < 0) @@ -508,7 +513,7 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain, goto cleanup; } - switch (concreteJob->data->JobState) { + switch (concreteJob->data.common->JobState) { case MSVM_CONCRETEJOB_JOBSTATE_NEW: case MSVM_CONCRETEJOB_JOBSTATE_STARTING: case MSVM_CONCRETEJOB_JOBSTATE_RUNNING: @@ -567,7 +572,7 @@ int hypervMsvmComputerSystemEnabledStateToDomainState (Msvm_ComputerSystem *computerSystem) { - switch (computerSystem->data->EnabledState) { + switch (computerSystem->data.common->EnabledState) { case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_UNKNOWN: return VIR_DOMAIN_NOSTATE; @@ -607,7 +612,7 @@ hypervIsMsvmComputerSystemActive(Msvm_ComputerSystem *computerSystem, if (in_transition != NULL) *in_transition = false; - switch (computerSystem->data->EnabledState) { + switch (computerSystem->data.common->EnabledState) { case MSVM_COMPUTERSYSTEM_ENABLEDSTATE_UNKNOWN: return false; @@ -651,20 +656,20 @@ hypervMsvmComputerSystemToDomain(virConnectPtr conn, return -1; } - if (virUUIDParse(computerSystem->data->Name, uuid) < 0) { + if (virUUIDParse(computerSystem->data.common->Name, uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse UUID from string '%s'"), - computerSystem->data->Name); + computerSystem->data.common->Name); return -1; } - *domain = virGetDomain(conn, computerSystem->data->ElementName, uuid); + *domain = virGetDomain(conn, computerSystem->data.common->ElementName, uuid); if (*domain == NULL) return -1; if (hypervIsMsvmComputerSystemActive(computerSystem, NULL)) { - (*domain)->id = computerSystem->data->ProcessID; + (*domain)->id = computerSystem->data.common->ProcessID; } else { (*domain)->id = -1; } -- 2.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list