Re: [PATCH] vz: Allow to create container based on template

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

 



On Thu, 2015-11-19 at 14:44 +0300, Mikhail Feoktistov wrote:
> 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);

Where do you use this 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;
>  

I think we should make this logic more robust. There is only one case,
when VIR_DOMAIN_FS_TYPE_TEMPLATE fs is allowed - when we create new container.
So I'd add a parameter to prlsdkDoApplyConfig, something like useCtTemplateFs,
which means that we should have only one fs of type template and no disks.

>      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 fs with index different from 0 is VIR_DOMAIN_FS_TYPE_TEMPLATE - it's an
error, also if we are not creating new ct - it's also error.

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

Why do you need to remove this flag to create ct from template? As I remember
it's needed to keep disk images, which you've remove from config.


> +
> +    job = PrlVm_RegEx(sdkdom, "", flags);
>      if (PRL_FAILED(waitJob(job)))
>          ret = -1;
>  
-- 
Dmitry Guryanov

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