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.
---
src/vz/vz_sdk.c | 33 +++++++++++++++++++++++++++++----
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 89c9e89..865cabe 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2096,12 +2096,14 @@ 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;
+ PRL_VM_DEV_EMULATION_TYPE emul;
int ret = -1;
pret = PrlVmCfg_SetVNCMode(sdkdom, PRD_DISABLED);
@@ -2117,6 +2119,18 @@ 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);
+
+ pret = PrlVmDev_GetEmulatedType(dev, &emul);
+ prlsdkCheckRetGoto(pret, cleanup);
+
+ if (devType == PDE_HARD_DISK) {
+ PrlHandle_Free(dev);
+ continue;
+ }
+ }
pret = PrlVmDev_Remove(dev);
PrlHandle_Free(dev);
}
@@ -3465,6 +3479,7 @@ prlsdkDoApplyConfig(virConnectPtr conn,
char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
bool needBoot = true;
char *mask = NULL;
+ bool skipdisk = false;
if (prlsdkCheckUnsupportedParams(sdkdom, def) < 0)
return -1;
@@ -3514,7 +3529,11 @@ prlsdkDoApplyConfig(virConnectPtr conn,
}
prlsdkCheckRetGoto(pret, error);
- if (prlsdkClearDevices(sdkdom) < 0)
+ if (def->nfss == 1 &&
+ def->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
+ skipdisk = true;
+
+ if (prlsdkClearDevices(sdkdom, skipdisk) < 0)
goto error;
if (prlsdkRemoveBootDevices(sdkdom) < 0)
@@ -3544,6 +3563,8 @@ prlsdkDoApplyConfig(virConnectPtr conn,
for (i = 0; i < def->nfss; i++) {
if (STREQ(def->fss[i]->dst, "/"))
needBoot = false;
+ if (def->fss[i]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
+ continue;
if (prlsdkAddFS(sdkdom, def->fss[i]) < 0)
goto error;
}
@@ -3655,6 +3676,7 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
int ret = -1;
int useTemplate = 0;
size_t i;
+ PRL_UINT32 flags = 0;
if (def->nfss > 1) {
/* Check all filesystems */
@@ -3696,8 +3718,11 @@ prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def)
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