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

Re: [Xen-devel] [PATCH 5/6] libxl: allow creation of domains with specified or random domid



On Tue, Dec 24, 2019 at 8:06 AM Paul Durrant <pdurrant@xxxxxxxxxx> wrote:
>
> This patch modifies do_domain_create() to use the value of domid that is
> passed in. A new 'special value' - RANDOM_DOMID - is added into the API
> and this, INVALID_DOMID or any valid domid is passed unmodified to
> libxl__domain_make(). Any other invalid domid value will cause an error.
>
> If RANDOM_DOMID is passed in then libxl__domain_make() will use
> libxl__random_bytes() to choose a domid. If the chosen value is not a
> valid domid then this step will be repeated. Once a valid value is chosen
> it will be passed to xc_domain_create() but if this fails with an errno
> value of EEXIST, a new random value will be chosen and the operation will
> be retried.
>
> If a valid domid is passed in and xc_domain_create() fails with errno
> set to EEXIST then this will result in a new error value of
> ERROR_DEVICE_EXISTS being returned from libxl__domain_make(). This is
> done so that domcreate_complete() can be adjusted so as not to tear down
> the existing domain that the attempted creation happened to collide with.
>
> NOTE: libxl__logv() is also modified to only log valid domid values in
>       messages rather than any domid, valid or otherwise, that is not
>       INVALID_DOMID.
>
> Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
> ---
> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> Cc: Wei Liu <wl@xxxxxxx>
> Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>
> ---

<snip>

> --- a/tools/libxl/libxl_create.c
> +++ b/tools/libxl/libxl_create.c

<snip>

> @@ -571,6 +569,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_config 
> *d_config,
>              .max_grant_frames = b_info->max_grant_frames,
>              .max_maptrack_frames = b_info->max_maptrack_frames,
>          };
> +        uint32_t in_domid = *domid;
>
>          if (info->type != LIBXL_DOMAIN_TYPE_PV) {
>              create.flags |= XEN_DOMCTL_CDF_hvm;
> @@ -600,10 +599,24 @@ int libxl__domain_make(libxl__gc *gc, 
> libxl_domain_config *d_config,
>              goto out;
>          }
>
> -        ret = xc_domain_create(ctx->xch, domid, &create);
> +        for (;;) {
> +            if (in_domid == RANDOM_DOMID) {
> +                ret = libxl__random_bytes(gc, (void *)domid, sizeof(*domid));

Since valid domids are ~0-2^15, you may want to used a temporary
uint16_t instead of the uint32_t domid to tighten up the range.

Regards,
Jason

> +                if (ret < 0)
> +                    break;
> +
> +                if (!libxl_domid_valid_guest(*domid))
> +                    continue;
> +            }
> +
> +            ret = xc_domain_create(ctx->xch, domid, &create);
> +            if (ret == 0 || errno != EEXIST || in_domid != RANDOM_DOMID)
> +                break;
> +        }
> +

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.