|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v4 5/7] libxl: allow creation of domains with a specified or random domid
Paul Durrant writes ("[PATCH v4 5/7] libxl: allow creation of domains with a
specified or random domid"):
> This patch adds a 'domid' field to libxl_domain_create_info and then
> modifies libxl__domain_make() to have Xen use that value if it is valid.
> If the domid value is invalid then Xen will choose the domid, as before,
> unless the value is the new special RANDOM_DOMID value added to the API.
> This value instructs libxl__domain_make() to choose a random domid value
> for Xen to use.
>
> If Xen determines that a domid specified to or chosen by
> libxl__domain_make() co-incides with an existing domain then the create
> operation will fail. In this case, if RANDOM_DOMID was specified to
> libxl__domain_make() then a new random value will be chosen and the create
> operation will be re-tried, otherwise libxl__domain_make() will fail.
>
> After Xen has successfully created a new domain, libxl__domain_make() will
> check whether its domid matches any recently used domid values. If it does
> then the domain will be destroyed. If the domid used in creation was
> specified to libxl__domain_make() then it will fail at this point,
> otherwise the create operation will be re-tried with either a new random
> or Xen-selected domid value.
...
> - ret = xc_domain_create(ctx->xch, domid, &create);
> + if (libxl_domid_valid_guest(info->domid))
> + *domid = info->domid;
> +
> + again:
> + for (;;) {
> + if (info->domid == RANDOM_DOMID) {
> + uint16_t v;
> +
> + ret = libxl__random_bytes(gc, (void *)&v, sizeof(v));
> + if (ret < 0)
> + break;
> +
> + v &= DOMID_MASK;
> + if (!libxl_domid_valid_guest(v))
> + continue;
> +
> + *domid = v;
> + }
> +
> + ret = xc_domain_create(ctx->xch, domid, &create);
> + if (ret == 0 || errno != EEXIST || info->domid != RANDOM_DOMID)
> + break;
> + }
> +
> if (ret < 0) {
> LOGED(ERROR, *domid, "domain creation fail");
> + *domid = INVALID_DOMID;
> + rc = ERROR_FAIL;
> + goto out;
> + }
> +
> + if (libxl__is_domid_recent(gc, *domid)) {
> + if (*domid == info->domid) /* domid was specified */
> + LOGED(ERROR, *domid, "domain id recently used");
> +
> + ret = xc_domain_destroy(ctx->xch, *domid);
> + if (!ret) {
> + *domid = INVALID_DOMID;
> +
> + /* If the domid was not specified then have another go */
> + if (!libxl_domid_valid_guest(info->domid))
> + goto again;
> + }
You have written this as two nested loops, one of which is implemented
as a goto, but actually logically this is surely only one loop ?
Please could you reorganise this and then I'll read it again...
Thanks,
Ian.
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |