From: Wei Liu <wei.liu2@citrix.com>
To: xen-devel@lists.xen.org
Cc: Wei Liu <wei.liu2@citrix.com>,
ian.jackson@eu.citrix.com, ian.campbell@citrix.com
Subject: [PATCH v4 for 4.5 3/8] libxl: make libxl_cd_insert "eject" + "insert"
Date: Tue, 16 Sep 2014 11:01:13 +0100 [thread overview]
Message-ID: <1410861678-31428-4-git-send-email-wei.liu2@citrix.com> (raw)
In-Reply-To: <1410861678-31428-1-git-send-email-wei.liu2@citrix.com>
We introduce an intermediate empty state when inserting media into
CDROM. The scheme works like this:
lock json config
write empty state to xenstore
for (;;) {
write user supplied disk to JSON
write disk information to xenstore
}
unlock json config
Bear in mind that all steps can fail. With the proposed scheme, we now
know, if xenstore is empty, then CDROM should be considered empty;
otherwise we should use JSON version of CDROM configuration.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
tools/libxl/libxl.c | 119 ++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 98 insertions(+), 21 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index e5d4891..89f4ce0 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2664,14 +2664,26 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
{
AO_CREATE(ctx, domid, ao_how);
int num = 0, i;
- libxl_device_disk *disks = NULL;
+ libxl_device_disk *disks = NULL, disk_saved, disk_empty;
+ libxl_domain_config d_config;
int rc, dm_ver;
-
libxl__device device;
const char * path;
char * tmp;
+ libxl__domain_userdata_lock *lock = NULL;
+ xs_transaction_t t = XBT_NULL;
+ flexarray_t *insert = NULL, *empty = NULL;
- flexarray_t *insert = NULL;
+ libxl_domain_config_init(&d_config);
+ libxl_device_disk_init(&disk_empty);
+ libxl_device_disk_init(&disk_saved);
+ libxl_device_disk_copy(ctx, &disk_saved, disk);
+
+ disk_empty.format = LIBXL_DISK_FORMAT_EMPTY;
+ disk_empty.vdev = libxl__strdup(NOGC, disk->vdev);
+ disk_empty.pdev_path = libxl__strdup(NOGC, "");
+ disk_empty.is_cdrom = 1;
+ libxl__device_disk_setdefault(gc, &disk_empty);
libxl_domain_type type = libxl__domain_type(gc, domid);
if (type == LIBXL_DOMAIN_TYPE_INVALID) {
@@ -2723,24 +2735,8 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
rc = libxl__device_from_disk(gc, domid, disk, &device);
if (rc) goto out;
- if (dm_ver == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
- rc = libxl__qmp_insert_cdrom(gc, domid, disk);
- if (rc) goto out;
- }
-
path = libxl__device_backend_path(gc, &device);
- /* Sanity check: make sure the backend exists before writing here */
- tmp = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/frontend", path));
- if (!tmp)
- {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
- libxl__sprintf(gc, "%s/frontend", path));
- rc = ERROR_FAIL;
- goto out;
- }
-
-
insert = flexarray_make(gc, 4, 1);
flexarray_append_pair(insert, "type",
@@ -2753,19 +2749,100 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk,
else
flexarray_append_pair(insert, "params", "");
- rc = libxl__xs_writev_atonce(gc, path,
- libxl__xs_kvs_of_flexarray(gc, insert, insert->count));
+ empty = flexarray_make(gc, 4, 1);
+ flexarray_append_pair(empty, "type",
+ libxl__device_disk_string_of_backend(disk->backend));
+ flexarray_append_pair(empty, "params", "");
+
+ /* Note: CTX lock is already held at this point so lock hierarchy
+ * is maintained.
+ */
+ lock = libxl__lock_domain_userdata(gc, domid);
+ if (!lock) {
+ rc = ERROR_LOCK_FAIL;
+ goto out;
+ }
+
+ /* We need to eject the original image first. This is implemented
+ * by inserting empty media. JSON is not updated.
+ */
+ if (dm_ver == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+ rc = libxl__qmp_insert_cdrom(gc, domid, &disk_empty);
+ if (rc) goto out;
+ }
+
+ for (;;) {
+ rc = libxl__xs_transaction_start(gc, &t);
+ if (rc) goto out;
+ /* Sanity check: make sure the backend exists before writing here */
+ tmp = libxl__xs_read(gc, t, libxl__sprintf(gc, "%s/frontend", path));
+ if (!tmp)
+ {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
+ libxl__sprintf(gc, "%s/frontend", path));
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ rc = libxl__xs_writev(gc, t, path,
+ libxl__xs_kvs_of_flexarray(gc, empty, empty->count));
+ if (rc) goto out;
+
+ rc = libxl__xs_transaction_commit(gc, &t);
+ if (!rc) break;
+ if (rc < 0) goto out;
+ }
+
+ rc = libxl__get_domain_configuration(gc, domid, &d_config);
if (rc) goto out;
+ DEVICE_ADD(disk, disks, domid, &disk_saved, COMPARE_DISK, &d_config);
+
+ if (dm_ver == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+ rc = libxl__qmp_insert_cdrom(gc, domid, disk);
+ if (rc) goto out;
+ }
+
+ for (;;) {
+ rc = libxl__xs_transaction_start(gc, &t);
+ if (rc) goto out;
+ /* Sanity check: make sure the backend exists before writing here */
+ tmp = libxl__xs_read(gc, t, libxl__sprintf(gc, "%s/frontend", path));
+ if (!tmp)
+ {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Internal error: %s does not exist",
+ libxl__sprintf(gc, "%s/frontend", path));
+ rc = ERROR_FAIL;
+ goto out;
+ }
+
+ rc = libxl__set_domain_configuration(gc, domid, &d_config);
+ if (rc) goto out;
+
+ rc = libxl__xs_writev(gc, t, path,
+ libxl__xs_kvs_of_flexarray(gc, insert, insert->count));
+ if (rc) goto out;
+
+ rc = libxl__xs_transaction_commit(gc, &t);
+ if (!rc) break;
+ if (rc < 0) goto out;
+ }
+
/* success, no actual async */
libxl__ao_complete(egc, ao, 0);
rc = 0;
out:
+ libxl__xs_transaction_abort(gc, &t);
for (i = 0; i < num; i++)
libxl_device_disk_dispose(&disks[i]);
free(disks);
+ libxl_device_disk_dispose(&disk_empty);
+ libxl_device_disk_dispose(&disk_saved);
+ libxl_domain_config_dispose(&d_config);
+
+ if (lock) libxl__unlock_domain_userdata(lock);
if (rc) return AO_ABORT(rc);
return AO_INPROGRESS;
--
1.7.10.4
next prev parent reply other threads:[~2014-09-16 10:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 10:01 [PATCH v4 for 4.5 0/8] libxl: synchronise domain configuration Wei Liu
2014-09-16 10:01 ` [PATCH v4 for 4.5 1/8] libxl: rework domain userdata file lock Wei Liu
2014-09-16 18:50 ` Ian Campbell
2014-09-16 21:02 ` Wei Liu
2014-09-16 10:01 ` [PATCH v4 for 4.5 2/8] libxl: synchronise configuration when we hotplug a device Wei Liu
2014-09-16 18:52 ` Ian Campbell
2014-09-16 10:01 ` Wei Liu [this message]
2014-09-16 18:57 ` [PATCH v4 for 4.5 3/8] libxl: make libxl_cd_insert "eject" + "insert" Ian Campbell
2014-09-16 10:01 ` [PATCH v4 for 4.5 4/8] libxl: refactor libxl_get_memory_target Wei Liu
2014-09-16 19:02 ` Ian Campbell
2014-09-16 10:01 ` [PATCH v4 for 4.5 5/8] libxl: introduce libxl_retrieve_domain_configuration Wei Liu
2014-09-16 19:14 ` Ian Campbell
2014-09-16 10:01 ` [PATCH v4 for 4.5 6/8] libxl: introduce libxl_userdata_unlink Wei Liu
2014-09-16 10:01 ` [PATCH v4 for 4.5 7/8] xl: use libxl_retrieve_domain_configuration and JSON format Wei Liu
2014-09-16 10:01 ` [PATCH v4 for 4.5 8/8] xl: long output of "list" command now contains Dom0 information Wei Liu
2014-09-17 19:16 ` [PATCH v4 for 4.5 0/8] libxl: synchronise domain configuration Ian Campbell
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=1410861678-31428-4-git-send-email-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xen.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).