From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v3 1/7] libxl: libxl__device_disk_local_attach return a new libxl_device_disk
Date: Mon, 16 Apr 2012 19:33:04 +0100 [thread overview]
Message-ID: <1334601190-14187-1-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1204161848030.26786@kaball-desktop>
- make libxl_device_disk_local_attach/detach two internal functions;
- pass a gc rather than a ctx to them;
- introduce a new libxl_device_disk** parameter to
libxl__device_disk_local_attach, the parameter is allocated on the gc by
libxl__device_disk_local_attach. It is going to fill it with
informations about the new locally attached disk. The new
libxl_device_disk should be passed to libxl_device_disk_local_detach
afterwards.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
tools/libxl/libxl.c | 73 -----------------------------------
tools/libxl/libxl.h | 7 ---
tools/libxl/libxl_bootloader.c | 9 ++--
tools/libxl/libxl_internal.c | 82 ++++++++++++++++++++++++++++++++++++++++
tools/libxl/libxl_internal.h | 11 +++++
5 files changed, 97 insertions(+), 85 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 60dbfdc..e645d2a 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1664,79 +1664,6 @@ out:
return ret;
}
-char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk)
-{
- GC_INIT(ctx);
- char *dev = NULL;
- char *ret = NULL;
- int rc;
-
- rc = libxl__device_disk_setdefault(gc, disk);
- if (rc) goto out;
-
- switch (disk->backend) {
- case LIBXL_DISK_BACKEND_PHY:
- LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
- disk->pdev_path);
- dev = disk->pdev_path;
- break;
- case LIBXL_DISK_BACKEND_TAP:
- switch (disk->format) {
- case LIBXL_DISK_FORMAT_RAW:
- /* optimise away the early tapdisk attach in this case */
- LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching"
- " tap disk %s directly (ie without using blktap)",
- disk->pdev_path);
- dev = disk->pdev_path;
- break;
- case LIBXL_DISK_FORMAT_VHD:
- dev = libxl__blktap_devpath(gc, disk->pdev_path,
- disk->format);
- break;
- case LIBXL_DISK_FORMAT_QCOW:
- case LIBXL_DISK_FORMAT_QCOW2:
- abort(); /* prevented by libxl__device_disk_set_backend */
- default:
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
- "unrecognized disk format: %d", disk->format);
- break;
- }
- break;
- case LIBXL_DISK_BACKEND_QDISK:
- if (disk->format != LIBXL_DISK_FORMAT_RAW) {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally"
- " attach a qdisk image if the format is not raw");
- break;
- }
- LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching qdisk %s\n",
- disk->pdev_path);
- dev = disk->pdev_path;
- break;
- default:
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend "
- "type: %d", disk->backend);
- break;
- }
-
- out:
- if (dev != NULL)
- ret = strdup(dev);
- GC_FREE;
- return ret;
-}
-
-int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk)
-{
- /* Nothing to do for PHYSTYPE_PHY. */
-
- /*
- * For other device types assume that the blktap2 process is
- * needed by the soon to be started domain and do nothing.
- */
-
- return 0;
-}
-
/******************************************************************************/
int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index edbca53..779c8dd 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -618,13 +618,6 @@ int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid,
*/
int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
-/*
- * Make a disk available in this (the control) domain. Returns path to
- * a device.
- */
-char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
-int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
-
/* Network Interfaces */
int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index 2774062..429253d 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -330,6 +330,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
char *fifo = NULL;
char *diskpath = NULL;
char **args = NULL;
+ libxl_device_disk *tmpdisk = NULL;
char tempdir_template[] = "/var/run/libxl/bl.XXXXXX";
char *tempdir;
@@ -386,7 +387,7 @@ int libxl_run_bootloader(libxl_ctx *ctx,
goto out_close;
}
- diskpath = libxl_device_disk_local_attach(ctx, disk);
+ diskpath = libxl__device_disk_local_attach(gc, disk, &tmpdisk);
if (!diskpath) {
goto out_close;
}
@@ -452,10 +453,8 @@ int libxl_run_bootloader(libxl_ctx *ctx,
rc = 0;
out_close:
- if (diskpath) {
- libxl_device_disk_local_detach(ctx, disk);
- free(diskpath);
- }
+ if (tmpdisk)
+ libxl__device_disk_local_detach(gc, tmpdisk);
if (fifo_fd > -1)
close(fifo_fd);
if (bootloader_fd > -1)
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index b89aef7..95fb918 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -323,6 +323,88 @@ out:
return rc;
}
+_hidden char * libxl__device_disk_local_attach(libxl__gc *gc,
+ const libxl_device_disk *disk,
+ libxl_device_disk **new_disk)
+{
+ libxl_ctx *ctx = gc->owner;
+ char *dev = NULL;
+ int rc;
+ libxl_device_disk *tmpdisk = libxl__zalloc(gc, sizeof(libxl_device_disk));
+ if (tmpdisk == NULL) goto out;
+
+ *new_disk = tmpdisk;
+ memcpy(tmpdisk, disk, sizeof(libxl_device_disk));
+ if (disk->pdev_path != NULL)
+ tmpdisk->pdev_path = libxl__strdup(gc, disk->pdev_path);
+ if (disk->script != NULL)
+ tmpdisk->script = libxl__strdup(gc, disk->script);
+ tmpdisk->vdev = NULL;
+
+ rc = libxl__device_disk_setdefault(gc, tmpdisk);
+ if (rc) goto out;
+
+ switch (tmpdisk->backend) {
+ case LIBXL_DISK_BACKEND_PHY:
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
+ tmpdisk->pdev_path);
+ dev = tmpdisk->pdev_path;
+ break;
+ case LIBXL_DISK_BACKEND_TAP:
+ switch (tmpdisk->format) {
+ case LIBXL_DISK_FORMAT_RAW:
+ /* optimise away the early tapdisk attach in this case */
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching"
+ " tap disk %s directly (ie without using blktap)",
+ tmpdisk->pdev_path);
+ dev = tmpdisk->pdev_path;
+ break;
+ case LIBXL_DISK_FORMAT_VHD:
+ dev = libxl__blktap_devpath(gc, tmpdisk->pdev_path,
+ tmpdisk->format);
+ break;
+ case LIBXL_DISK_FORMAT_QCOW:
+ case LIBXL_DISK_FORMAT_QCOW2:
+ abort(); /* prevented by libxl__device_disk_set_backend */
+ default:
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "unrecognized disk format: %d", tmpdisk->format);
+ break;
+ }
+ break;
+ case LIBXL_DISK_BACKEND_QDISK:
+ if (tmpdisk->format != LIBXL_DISK_FORMAT_RAW) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally"
+ " attach a qdisk image if the format is not raw");
+ break;
+ }
+ LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching qdisk %s\n",
+ disk->pdev_path);
+ dev = tmpdisk->pdev_path;
+ break;
+ default:
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend "
+ "type: %d", tmpdisk->backend);
+ break;
+ }
+
+ out:
+ return dev;
+}
+
+_hidden int libxl__device_disk_local_detach(libxl__gc *gc,
+ libxl_device_disk *disk)
+{
+ /* Nothing to do for PHYSTYPE_PHY. */
+
+ /*
+ * For other device types assume that the blktap2 process is
+ * needed by the soon to be started domain and do nothing.
+ */
+
+ return 0;
+}
+
libxl_device_model_version libxl__device_model_version_running(libxl__gc *gc,
uint32_t domid)
{
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index a4b933b..4e0d203 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1001,6 +1001,17 @@ _hidden char *libxl__blktap_devpath(libxl__gc *gc,
*/
_hidden void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path);
+/*
+ * Make a disk available in this (the control) domain. Returns path to
+ * a device.
+ */
+_hidden char * libxl__device_disk_local_attach(libxl__gc *gc,
+ const libxl_device_disk *disk,
+ libxl_device_disk **new_disk);
+_hidden int libxl__device_disk_local_detach(libxl__gc *gc,
+ libxl_device_disk *disk);
+
+
_hidden char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid);
struct libxl__xen_console_reader {
--
1.7.2.5
next prev parent reply other threads:[~2012-04-16 18:33 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-16 18:32 [PATCH v3 0/7] qdisk local attach Stefano Stabellini
2012-04-16 18:33 ` Stefano Stabellini [this message]
2012-04-17 17:25 ` [PATCH v3 1/7] libxl: libxl__device_disk_local_attach return a new libxl_device_disk Ian Jackson
2012-04-18 8:34 ` Ian Campbell
2012-04-20 13:58 ` Stefano Stabellini
2012-04-16 18:33 ` [PATCH v3 2/7] libxl: add a transaction parameter to libxl__device_generic_add Stefano Stabellini
2012-04-17 17:27 ` Ian Jackson
2012-04-18 8:41 ` Ian Campbell
2012-04-20 15:13 ` Stefano Stabellini
2012-04-16 18:33 ` [PATCH v3 3/7] libxl: introduce libxl__device_disk_add_t Stefano Stabellini
2012-04-17 17:37 ` Ian Jackson
2012-04-20 14:00 ` Stefano Stabellini
2012-04-16 18:33 ` [PATCH v3 4/7] xl/libxl: add a blkdev_start parameter Stefano Stabellini
2012-04-17 17:47 ` Ian Jackson
2012-04-20 14:04 ` Stefano Stabellini
2012-04-20 14:08 ` Ian Campbell
2012-04-23 17:40 ` Stefano Stabellini
2012-04-24 9:20 ` Ian Campbell
2012-04-20 14:22 ` Ian Jackson
2012-04-16 18:33 ` [PATCH v3 5/7] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-04-17 17:53 ` Ian Jackson
2012-04-20 14:14 ` Stefano Stabellini
2012-04-20 14:28 ` Ian Jackson
2012-04-23 17:40 ` Stefano Stabellini
2012-04-16 18:33 ` [PATCH v3 6/7] xl/libxl: implement QDISK libxl_device_disk_local_attach Stefano Stabellini
2012-04-17 17:58 ` Ian Jackson
2012-04-20 14:24 ` Stefano Stabellini
2012-04-20 14:37 ` Ian Jackson
2012-04-23 17:40 ` Stefano Stabellini
2012-04-16 18:33 ` [PATCH v3 7/7] libxl__device_disk_local_attach: wait for state "connected" Stefano Stabellini
2012-04-17 18:01 ` Ian Jackson
2012-04-20 14:35 ` Stefano Stabellini
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=1334601190-14187-1-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=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 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).