On Tuesday 25 November 2014 15:52:54 Maxim Nestratov wrote: > 18.11.2014 16:17, Dmitry Guryanov пишет: > > This patch replaces code, which creates domains by > > running prlctl command. > > > > prlsdkCreateVm/Ct will do prlsdkApplyConfig, because > > we send request to the server only once in this case. > > > > But prlsdkApplyConfig will be called also from > > parallelsDomainDefineXML function. There is no problem with > > it, parallelsDomainDefineXML will be refactored later. > > > > Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx> > > --- > > > > src/parallels/parallels_driver.c | 45 +--------------------- > > src/parallels/parallels_sdk.c | 83 > > +++++++++++++++++++++++++++++++++++++++- src/parallels/parallels_sdk.h > > | 2 + > > 3 files changed, 86 insertions(+), 44 deletions(-) > > > > diff --git a/src/parallels/parallels_driver.c > > b/src/parallels/parallels_driver.c index 55ee003..582ffdb 100644 > > --- a/src/parallels/parallels_driver.c > > +++ b/src/parallels/parallels_driver.c > > @@ -657,47 +657,6 @@ parallelsDomainGetAutostart(virDomainPtr domain, int > > *autostart)> > > return ret; > > > > } > > > > -static int > > -parallelsCreateVm(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainDefPtr > > def) -{ > > - char uuidstr[VIR_UUID_STRING_BUFLEN]; > > - > > - virUUIDFormat(def->uuid, uuidstr); > > - > > - if (parallelsCmdRun(PRLCTL, "create", def->name, "--no-hdd", > > - "--uuid", uuidstr, NULL) < 0) > > - return -1; > > - > > - return 0; > > -} > > - > > -static int > > -parallelsCreateCt(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainDefPtr > > def) -{ > > - char uuidstr[VIR_UUID_STRING_BUFLEN]; > > - > > - virUUIDFormat(def->uuid, uuidstr); > > - > > - if (def->nfss != 1 || > > - def->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE) { > > - > > - virReportError(VIR_ERR_INVALID_ARG, "%s", > > - _("There must be only 1 template FS for " > > - "container creation")); > > - goto error; > > - } > > - > > - if (parallelsCmdRun(PRLCTL, "create", def->name, "--vmtype", "ct", > > - "--uuid", uuidstr, > > - "--ostemplate", def->fss[0]->src, NULL) < 0) > > - goto error; > > - > > - return 0; > > - > > - error: > > - return -1; > > -} > > - > > > > static virDomainPtr > > parallelsDomainDefineXML(virConnectPtr conn, const char *xml) > > { > > > > @@ -720,10 +679,10 @@ parallelsDomainDefineXML(virConnectPtr conn, const > > char *xml)> > > if (olddom == NULL) { > > > > virResetLastError(); > > if (STREQ(def->os.type, "hvm")) { > > > > - if (parallelsCreateVm(conn, def)) > > + if (prlsdkCreateVm(conn, def)) > > > > goto cleanup; > > > > } else if (STREQ(def->os.type, "exe")) { > > > > - if (parallelsCreateCt(conn, def)) > > + if (prlsdkCreateCt(conn, def)) > > > > goto cleanup; > > > > } else { > > > > virReportError(VIR_ERR_INVALID_ARG, > > > > diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c > > index bccb2d7..a943f4b 100644 > > --- a/src/parallels/parallels_sdk.c > > +++ b/src/parallels/parallels_sdk.c > > @@ -2506,7 +2506,6 @@ prlsdkDoApplyConfig(PRL_HANDLE sdkdom, > > > > error: > > return -1; > > > > - > > > > } > > > > int > > > > @@ -2538,3 +2537,85 @@ prlsdkApplyConfig(virConnectPtr conn, > > > > return ret; > > > > } > > > > + > > +int > > +prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) > > +{ > > + parallelsConnPtr privconn = conn->privateData; > > + PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; > > + PRL_HANDLE job = PRL_INVALID_HANDLE; > > + PRL_HANDLE result = PRL_INVALID_HANDLE; > > + PRL_HANDLE srvconf = PRL_INVALID_HANDLE; > > + PRL_RESULT pret; > > + int ret = -1; > > + > > + pret = PrlSrv_CreateVm(privconn->server, &sdkdom); > > + prlsdkCheckRetGoto(pret, cleanup); > > + > > + job = PrlSrv_GetSrvConfig(privconn->server); > > + if (!(result = getJobResult(job, privconn->jobTimeout))) > > + goto cleanup; > > + > > + pret = PrlResult_GetParamByIndex(result, 0, &srvconf); > > + prlsdkCheckRetGoto(pret, cleanup); > > + > > + pret = PrlVmCfg_SetDefaultConfig(sdkdom, srvconf, > > PVS_GUEST_VER_LIN_REDHAT, 0); + prlsdkCheckRetGoto(pret, cleanup); > > + > > + ret = prlsdkDoApplyConfig(sdkdom, def); > > + if (ret) > > + goto cleanup; > > + > > + job = PrlVm_Reg(sdkdom, "", 1); > > + ret = waitJob(job, privconn->jobTimeout); > > + > > + cleanup: > > + PrlHandle_Free(sdkdom); > > + return ret; > > +} > > + > > +int > > +prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) > > +{ > > + parallelsConnPtr privconn = conn->privateData; > > + PRL_HANDLE sdkdom = PRL_INVALID_HANDLE; > > + PRL_GET_VM_CONFIG_PARAM_DATA confParam; > > + PRL_HANDLE job = PRL_INVALID_HANDLE; > > + PRL_HANDLE result = PRL_INVALID_HANDLE; > > + PRL_RESULT pret; > > + int ret = -1; > > + > > + if (def->nfss != 1 || > > + def->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE) { > > + > > + virReportError(VIR_ERR_INVALID_ARG, "%s", > > + _("There must be only 1 template FS for " > > + "container creation")); > > + return -1; > > + } > > I'm not sure this is a mandatory parameter in case container is created > with loop device. > OK > > + > > + confParam.nVmType = PVT_CT; > > + confParam.sConfigSample = "vswap.1024MB"; > > + confParam.nOsVersion = 0; > > + > > PrlVmCfg_SetVmType(sdkdom, PVT_CT) should be called here type already specified in confParam, so we don't need to call this function. > > > + job = PrlSrv_GetDefaultVmConfig(privconn->server, &confParam, 0); > > + if (!(result = getJobResult(job, privconn->jobTimeout))) > > + goto cleanup; > > + > > + pret = PrlResult_GetParamByIndex(result, 0, &sdkdom); > > + prlsdkCheckRetGoto(pret, cleanup); > > + > > + > > we have to skip this in case it is absent > > > pret = PrlVmCfg_SetOsTemplate(sdkdom, def->fss[0]->src); > > > > + prlsdkCheckRetGoto(pret, cleanup); > > + > > + ret = prlsdkDoApplyConfig(sdkdom, def); > > + if (ret) > > + goto cleanup; > > + > > + job = PrlVm_Reg(sdkdom, "", 1); > > + ret = waitJob(job, privconn->jobTimeout); > > It is better to specify explicitly e.g. > > PrlVm_RegEx(sdkdom, "", PACF_NON_INTERACTIVE_MODE); > > > + > > + cleanup: > > + PrlHandle_Free(sdkdom); > > + return ret; > > +} > > diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h > > index 8de077c..b654c2a 100644 > > --- a/src/parallels/parallels_sdk.h > > +++ b/src/parallels/parallels_sdk.h > > @@ -48,3 +48,5 @@ int > > > > prlsdkApplyConfig(virConnectPtr conn, > > > > virDomainObjPtr dom, > > virDomainDefPtr new); > > > > +int prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def); > > +int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def); -- Dmitry Guryanov -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list