From: Ian Jackson <ian.jackson@citrix.com>
To: Paul Durrant <pdurrant@amazon.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Andrew Cooper <Andrew.Cooper3@citrix.com>,
Jason Andryuk <jandryuk@gmail.com>,
George Dunlap <George.Dunlap@citrix.com>,
Anthony Perard <anthony.perard@citrix.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [Xen-devel] [PATCH v4 5/7] libxl: allow creation of domains with a specified or random domid
Date: Thu, 30 Jan 2020 17:25:55 +0000 [thread overview]
Message-ID: <24115.4515.335032.366833@mariner.uk.xensource.com> (raw)
In-Reply-To: <20200122144446.919-6-pdurrant@amazon.com>
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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-01-30 17:26 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 14:44 [Xen-devel] [PATCH v4 0/7] xl/libxl: domid allocation/preservation changes Paul Durrant
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 1/7] libxl: add definition of INVALID_DOMID to the API Paul Durrant
2020-01-22 14:52 ` Roger Pau Monné
2020-01-31 10:31 ` Durrant, Paul
2020-01-31 11:06 ` Roger Pau Monné
2020-01-31 11:10 ` Durrant, Paul
2020-01-31 12:07 ` Andrew Cooper
2020-01-31 12:11 ` Durrant, Paul
2020-01-30 17:31 ` Ian Jackson
2020-01-30 17:35 ` Durrant, Paul
2020-01-30 17:51 ` Ian Jackson
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 2/7] libxl_create: make 'soft reset' explicit Paul Durrant
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 3/7] libxl: generalise libxl__domain_userdata_lock() Paul Durrant
2020-01-30 17:04 ` Ian Jackson
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 4/7] libxl: add infrastructure to track and query 'recent' domids Paul Durrant
2020-01-30 17:23 ` Ian Jackson
2020-01-31 10:55 ` Anthony PERARD
2020-01-31 10:57 ` Durrant, Paul
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 5/7] libxl: allow creation of domains with a specified or random domid Paul Durrant
2020-01-30 17:25 ` Ian Jackson [this message]
2020-01-30 17:32 ` Durrant, Paul
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 6/7] xl.conf: introduce 'domid_policy' Paul Durrant
2020-01-22 14:44 ` [Xen-devel] [PATCH v4 7/7] xl: allow domid to be preserved on save/restore or migrate Paul Durrant
2020-01-30 17:28 ` Ian Jackson
2020-01-30 17:42 ` Durrant, Paul
2020-01-30 18:20 ` Andrew Cooper
2020-01-31 16:07 ` Wei Liu
2020-02-01 11:56 ` Durrant, Paul
2020-02-21 11:58 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=24115.4515.335032.366833@mariner.uk.xensource.com \
--to=ian.jackson@citrix.com \
--cc=Andrew.Cooper3@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=jandryuk@gmail.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=pdurrant@amazon.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).