]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: recognize array property as distinct type.
authorDawid Zamirski <dzamirski@datto.com>
Tue, 18 Apr 2017 14:56:20 +0000 (10:56 -0400)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 18 Apr 2017 21:19:38 +0000 (23:19 +0200)
When hyperv code generator for WMI classes identifies common
properties, it needs to take into account array type as a distinct
type, i.e string != string[]. This is the case where v1 of the
Msvm_VirtualSystemSettingData has Notes property as string whereas v2
uses Notes[], therefore they have to be treated as different fields and
cannot be placed in the "common" struct.

src/hyperv/hyperv_driver.c
src/hyperv/hyperv_wmi_generator.py

index 090ea243ba5d30d7ee7d2955d5fcd89980b95802..0ca59717b1b5a3e591c4474e08d279fab7e47fc7 100644 (file)
@@ -894,8 +894,31 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     if (VIR_STRDUP(def->name, computerSystem->data.common->ElementName) < 0)
         goto cleanup;
 
-    if (VIR_STRDUP(def->description, virtualSystemSettingData->data.common->Notes) < 0)
-        goto cleanup;
+    if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
+        if (VIR_STRDUP(def->description,
+                       virtualSystemSettingData->data.v1->Notes) < 0)
+            goto cleanup;
+    } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2 &&
+               virtualSystemSettingData->data.v2->Notes.data != NULL) {
+        char **notes = (char **)virtualSystemSettingData->data.v2->Notes.data;
+        virBuffer buf = VIR_BUFFER_INITIALIZER;
+        size_t i = 0;
+
+        /* in practice Notes has 1 element */
+        for (i = 0; i < virtualSystemSettingData->data.v2->Notes.count; i++) {
+            /* but if there's more than 1, separate by double new line */
+            if (virBufferUse(&buf) > 0)
+                virBufferAddLit(&buf, "\n\n");
+
+            virBufferAdd(&buf, *notes, -1);
+            notes++;
+        }
+
+        if (virBufferCheckError(&buf))
+            goto cleanup;
+
+        def->description = virBufferContentAndReset(&buf);
+    }
 
     virDomainDefSetMemoryTotal(def, memorySettingData->data.common->Limit * 1024); /* megabyte to kilobyte */
     def->mem.cur_balloon = memorySettingData->data.common->VirtualQuantity * 1024; /* megabyte to kilobyte */
index c15d97adc5b70be12f8db2240ac05268b5e869d5..9aee0b9bf377e9fbcccd1237baf4e92bdf714dcc 100755 (executable)
@@ -251,7 +251,7 @@ class WmiClass:
         for cls in self.versions:
             for prop in cls.properties:
                 # consdered same if matches by name AND type
-                key = "%s_%s" % (prop.name, prop.type)
+                key = "%s_%s_%s" % (prop.name, prop.type, prop.is_array)
 
                 if key in property_info:
                     property_info[key][1] += 1