We shouldn't delete disk from default config if we create container based on template, because we don't have the new disk from XML, only template name. And don't add template section from XML as new filesystem, we use PrlVmCfg_SetOsTemplate function to set template name. Do not set PRNVM_PRESERVE_DISK flag in PrlVm_RegEx() call, because this will cause an error during CT startup. --- diff from v1: Remove unusable variable (PRL_VM_DEV_EMULATION_TYPE emul) Add parameter useCtTemplateFs in prlsdkDoApplyConfig() function Allow only one fs with "template" type and only for CT creation Move this commit to patch series src/vz/vz_sdk.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 2b031c9..c5f8edd 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -2107,12 +2107,13 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, virDomainDefPtr def) return 0; } -static int prlsdkClearDevices(PRL_HANDLE sdkdom) +static int prlsdkClearDevices(PRL_HANDLE sdkdom, bool skipdisk) { PRL_RESULT pret; PRL_UINT32 n, i; PRL_HANDLE devList; PRL_HANDLE dev; + PRL_DEVICE_TYPE devType; int ret = -1; pret = PrlVmCfg_SetVNCMode(sdkdom, PRD_DISABLED); @@ -2128,6 +2129,15 @@ static int prlsdkClearDevices(PRL_HANDLE sdkdom) pret = PrlHndlList_GetItem(devList, i, &dev); prlsdkCheckRetGoto(pret, cleanup); + if (skipdisk) { + pret = PrlVmDev_GetType(dev, &devType); + prlsdkCheckRetGoto(pret, cleanup); + + if (devType == PDE_HARD_DISK) { + PrlHandle_Free(dev); + continue; + } + } pret = PrlVmDev_Remove(dev); PrlHandle_Free(dev); } @@ -3470,7 +3480,8 @@ static int prlsdkDoApplyConfig(virConnectPtr conn, PRL_HANDLE sdkdom, virDomainDefPtr def, - virDomainDefPtr olddef) + virDomainDefPtr olddef, + bool useCtTemplateFs) { PRL_RESULT pret; size_t i; @@ -3526,7 +3537,7 @@ prlsdkDoApplyConfig(virConnectPtr conn, } prlsdkCheckRetGoto(pret, error); - if (prlsdkClearDevices(sdkdom) < 0) + if (prlsdkClearDevices(sdkdom, useCtTemplateFs) < 0) goto error; if (prlsdkRemoveBootDevices(sdkdom) < 0) @@ -3554,6 +3565,12 @@ prlsdkDoApplyConfig(virConnectPtr conn, } for (i = 0; i < def->nfss; i++) { + if (def->fss[i]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) { + if(useCtTemplateFs) + continue; + else + goto error; + } if (STREQ(def->fss[i]->dst, "/")) needBoot = false; if (prlsdkAddFS(sdkdom, def->fss[i]) < 0) @@ -3602,7 +3619,7 @@ prlsdkApplyConfig(virConnectPtr conn, if (PRL_FAILED(waitJob(job))) return -1; - ret = prlsdkDoApplyConfig(conn, sdkdom, new, dom->def); + ret = prlsdkDoApplyConfig(conn, sdkdom, new, dom->def, false); if (ret == 0) { job = PrlVm_CommitEx(sdkdom, PVCF_DETACH_HDD_BUNDLE); @@ -3642,7 +3659,7 @@ prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def) pret = PrlVmCfg_SetOfflineManagementEnabled(sdkdom, 0); prlsdkCheckRetGoto(pret, cleanup); - ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL); + ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL, false); if (ret) goto cleanup; @@ -3665,8 +3682,9 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) PRL_HANDLE result = PRL_INVALID_HANDLE; PRL_RESULT pret; int ret = -1; - int useTemplate = 0; + bool useTemplate = false; size_t i; + PRL_UINT32 flags = 0; if (def->nfss > 1) { /* Check all filesystems */ @@ -3679,7 +3697,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) } } else if (def->nfss == 1) { if (def->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) { - useTemplate = 1; + useTemplate = true; } else if (def->fss[0]->type != VIR_DOMAIN_FS_TYPE_FILE) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Unsupported filesystem type.")); @@ -3704,12 +3722,15 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def) } - ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL); + ret = prlsdkDoApplyConfig(conn, sdkdom, def, NULL, useTemplate); if (ret) goto cleanup; - job = PrlVm_RegEx(sdkdom, "", - PACF_NON_INTERACTIVE_MODE | PRNVM_PRESERVE_DISK); + flags = PACF_NON_INTERACTIVE_MODE; + if (!useTemplate) + flags = flags | PRNVM_PRESERVE_DISK; + + job = PrlVm_RegEx(sdkdom, "", flags); if (PRL_FAILED(waitJob(job))) ret = -1; -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list