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