Re: [PATCH v2] vz: fix building capabilities

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/06/2015 03:45 PM, Maxim Nestratov wrote:
03.07.2015 20:26, Dmitry Guryanov пишет:
There should be at least one domain for each guest
in cababilities. And in current code we don't add
domain for this guest for example.

     if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
                                          VIR_ARCH_X86_64,
                                          "vz",
                                          NULL, 0, NULL)) == NULL)

Anyway, with two virt types it looks a litte messy, so let's
move adding guest and domain to a separate function.

Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx>
---
src/vz/vz_driver.c | 92 ++++++++++++++++++++++--------------------------------
  1 file changed, 38 insertions(+), 54 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 47c5023..8c3c818 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -78,14 +78,45 @@ vzDriverUnlock(vzConnPtr driver)
      virMutexUnlock(&driver->lock);
  }
  +static int
+vzCapsAddGuestDomain(virCapsPtr caps,
+                     virDomainOSType ostype,
+                     virArch arch,
+                     const char * emulator,
+                     virDomainVirtType virt_type)
+{
+    virCapsGuestPtr guest;
+
+    if ((guest = virCapabilitiesAddGuest(caps, ostype, arch, emulator,
+                                         NULL, 0, NULL)) == NULL)
+        return -1;
+
+
+    if (virCapabilitiesAddGuestDomain(guest, virt_type,
+                                      NULL, NULL, 0, NULL) == NULL)
+        return -1;
+
+    return 0;
+}
+
  static virCapsPtr
  vzBuildCapabilities(void)
  {
      virCapsPtr caps = NULL;
      virCPUDefPtr cpu = NULL;
      virCPUDataPtr data = NULL;
-    virCapsGuestPtr guest;
      virNodeInfo nodeinfo;
+    virDomainOSType ostypes[] = {
+        VIR_DOMAIN_OSTYPE_HVM,
+        VIR_DOMAIN_OSTYPE_EXE
+    };
+    virArch archs[] = { VIR_ARCH_I686, VIR_ARCH_X86_64 };
+    const char *const emulators[] = { "parallels", "vz" };
+    virDomainVirtType virt_types[] = {
+        VIR_DOMAIN_VIRT_PARALLELS,
+        VIR_DOMAIN_VIRT_VZ
+    };
+    size_t i, j, k;
        if ((caps = virCapabilitiesNew(virArchFromHost(),
                                     false, false)) == NULL)
@@ -94,59 +125,12 @@ vzBuildCapabilities(void)
      if (nodeCapsInitNUMA(caps) < 0)
          goto error;
  -    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
-                                         VIR_ARCH_X86_64,
-                                         "parallels",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
-                                         VIR_ARCH_I686,
-                                         "parallels",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-
-    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_PARALLELS,
-                                      NULL, NULL, 0, NULL) == NULL)
-        goto error;
-
-    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
-                                         VIR_ARCH_X86_64,
-                                         "parallels",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_PARALLELS,
-                                      NULL, NULL, 0, NULL) == NULL)
-        goto error;
-
-    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
-                                         VIR_ARCH_X86_64,
-                                         "vz",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
-                                         VIR_ARCH_I686,
-                                         "vz",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-
-    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VZ,
-                                      NULL, NULL, 0, NULL) == NULL)
-        goto error;
-
-    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_EXE,
-                                         VIR_ARCH_X86_64,
-                                         "vz",
-                                         NULL, 0, NULL)) == NULL)
-        goto error;
-
-    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_VZ,
-                                      NULL, NULL, 0, NULL) == NULL)
-        goto error;
+    for (i = 0; i < 2; i++)
+        for (j = 0; j < 2; j++)
+            for (k = 0; k < 2; k++)
+                if (vzCapsAddGuestDomain(caps, ostypes[i], archs[j],
+ emulators[k], virt_types[k]) < 0)
+                    goto error;
        if (nodeGetInfo(&nodeinfo))
          goto error;
ACK. Looks good.

Thanks, pushed.

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]