From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 6/6] libxl: prevent creation of domains with duplicate names
Date: Thu, 27 Jan 2011 17:41:04 +0000 [thread overview]
Message-ID: <1296150064-31991-7-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1296150064-31991-6-git-send-email-ian.jackson@eu.citrix.com>
libxl_domain_rename is where domain names are assigned. Therefore
this is where we check that no two domains have the same name. As a
special exception, domains whose name is "" are not considered to
clash.
We also take special care not to mind if we try to rename a domain to
the name it already has.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
tools/libxl/libxl.c | 22 ++++++++++++++++++++++
tools/libxl/libxl_create.c | 1 +
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index ccbc842..a88623a 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -141,6 +141,28 @@ int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
}
}
+ if (new_name[0]) {
+ /* nonempty names must be unique */
+ uint32_t domid_e;
+ rc = libxl_name_to_domid(ctx, new_name, &domid_e);
+ if (rc == ERROR_INVAL) {
+ /* no such domain, good */
+ } else if (rc != 0) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unexpected error"
+ "checking for existing domain");
+ goto x_rc;
+ } else if (domid_e == domid) {
+ /* domain already has this name, ok (but we do still
+ * need the rest of the code as we may need to check
+ * old_name, for example). */
+ } else {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "domain with name \"%s\""
+ " already exists.", new_name);
+ rc = ERROR_INVAL;
+ goto x_rc;
+ }
+ }
+
if (old_name) {
got_old_name = xs_read(ctx->xsh, trans, name_path, &got_old_len);
if (!got_old_name) {
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 8aabc3c..f5a5cc4 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -350,6 +350,7 @@ int libxl__domain_make(libxl_ctx *ctx, libxl_domain_create_info *info,
retry_transaction:
t = xs_transaction_start(ctx->xsh);
+
xs_rm(ctx->xsh, t, dom_path);
xs_mkdir(ctx->xsh, t, dom_path);
xs_set_permissions(ctx->xsh, t, dom_path, roperm, ARRAY_SIZE(roperm));
--
1.5.6.5
next prev parent reply other threads:[~2011-01-27 17:41 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-27 17:40 [PATCH 0/6] libxl, xl: fix domain name uniqueness check Ian Jackson
2011-01-27 17:40 ` [PATCH 1/6] xl: Revert "xl: avoid creating domains with duplicate names" Ian Jackson
2011-01-27 17:41 ` [PATCH 2/6] libxl: fix error handling (xenstore transaction leak) in libxl__domain_make Ian Jackson
2011-01-27 17:41 ` [PATCH 3/6] libxl, xl: fixes to domain creation cleanup logic (domid values) Ian Jackson
2011-01-27 17:41 ` [PATCH 4/6] libxl: internals: document the error behaviour of various libxl__xs_* functions Ian Jackson
2011-01-27 17:41 ` [PATCH 5/6] libxl: during domain destruction, do not complain if no devices dir to destroy Ian Jackson
2011-01-27 17:41 ` Ian Jackson [this message]
2011-01-27 18:33 ` [PATCH 3/6] libxl, xl: fixes to domain creation cleanup logic (domid values) Stefano Stabellini
2011-01-27 18:59 ` Ian Jackson
2011-01-27 20:01 ` Ian Jackson
2011-01-27 20:13 ` Gianni Tedesco
2011-01-28 12:22 ` Stefano Stabellini
2011-01-28 12:28 ` Ian Jackson
2011-01-28 13:27 ` Stefano Stabellini
2011-01-28 17:38 ` Ian Jackson
2011-01-28 17:52 ` Stefano Stabellini
2011-01-28 18:39 ` Ian Jackson
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=1296150064-31991-7-git-send-email-ian.jackson@eu.citrix.com \
--to=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.