Re: [PATCH v2 9/9] pvs: implement VM creation

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

 



On 04/18/2012 02:07 PM, Dmitry Guryanov wrote:
To create a new VM in PVS we should issue "prlctl create" command,
and give path to the directory, where VM should be created. VM's
storage will be in that directory later. So in this first version
find out location of first VM's hard disk and create VM there.


[...]
+static int
+pvsCreateVm(virConnectPtr conn, virDomainDefPtr def)
+{
+    pvsConnPtr privconn = conn->privateData;
+    int i;
+    virStorageVolDefPtr privvol = NULL;
+    virStoragePoolObjPtr pool = NULL;
+    virStorageVolPtr vol = NULL;
+	char uuidstr[VIR_UUID_STRING_BUFLEN];
+

Spacing.

+    for (i = 0; i<  def->ndisks; i++) {
+        if (def->disks[i]->device != VIR_DOMAIN_DISK_DEVICE_DISK)
+            continue;
+
+        vol = pvsStorageVolumeLookupByPathLocked(conn, def->disks[i]->src);
+        if (!vol) {
+            pvsError(VIR_ERR_INVALID_ARG,
+                     _("Can't find volume with path '%s'"),
+                     def->disks[i]->src);
+            return -1;
+        }
+        break;
+    }
+
+    if (!vol) {
+        pvsError(VIR_ERR_INVALID_ARG,
+                 _("Can't create VM without hard disks"));
+        return -1;
+    }
+
+    pool = virStoragePoolObjFindByName(&privconn->pools, vol->pool);
+    if (!pool) {
+        pvsError(VIR_ERR_INVALID_ARG,
+                 _("Can't find storage pool with name '%s'"),
+                 vol->pool);
+        goto error;
+    }
+
+    privvol = virStorageVolDefFindByPath(pool, def->disks[i]->src);
+    if (!privvol) {
+        pvsError(VIR_ERR_INVALID_ARG,
+                 _("Can't find storage volume definition for path '%s'"),
+                 def->disks[i]->src);
+        goto error2;
+    }
+
+	virUUIDFormat(def->uuid, uuidstr);
+

Spacing.

+    if (pvsCmdRun(PRLCTL, "create", def->name, "--dst",
+                  pool->def->target.path, "--no-hdd", "--uuid", uuidstr, NULL))
+        goto error2;

Nit: Check for '< 0' ?

+
+    if (pvsCmdRun(PRLCTL, "set", def->name, "--vnc-mode", "auto", NULL))
+        goto error2;
+
+    virStoragePoolObjUnlock(pool);
+    virUnrefStorageVol(vol);
+
+    return 0;
+
+  error2:
+    virStoragePoolObjUnlock(pool);
+  error:
+    virUnrefStorageVol(vol);
+    return -1;
+}
+
  static virDomainPtr
  pvsDomainDefineXML(virConnectPtr conn, const char *xml)
  {
@@ -1122,8 +1189,16 @@ pvsDomainDefineXML(virConnectPtr conn, const char *xml)

          def = NULL;
      } else {
-        pvsError(VIR_ERR_NO_SUPPORT, _("Not implemented yet"));
+        if (pvsCreateVm(conn, def))
              goto cleanup;


Nit: Check for < 0.

+        if (pvsLoadDomains(privconn, def->name))
+            goto cleanup;

Probably here too.


So, I guess I found a lot of 'easy' stuff, but otherwise it looks ok to me also.

    Stefan

--
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]