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 v4 2/8] libxl: libxl__device_disk_local_attach return a new libxl_device_disk
Date: Tue, 24 Apr 2012 11:45:52 +0100 [thread overview]
Message-ID: <1335264358-20182-2-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1204231810140.26786@kaball-desktop>
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_bootloader.c | 10 ++++----
tools/libxl/libxl_internal.c | 47 +++++++++++++++++++++++----------------
tools/libxl/libxl_internal.h | 3 +-
3 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index 977c6d3..83cac78 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,8 +387,9 @@ int libxl_run_bootloader(libxl_ctx *ctx,
goto out_close;
}
- diskpath = libxl__device_disk_local_attach(gc, disk);
+ diskpath = libxl__device_disk_local_attach(gc, disk, &tmpdisk);
if (!diskpath) {
+ rc = ERROR_FAIL;
goto out_close;
}
@@ -452,10 +454,8 @@ int libxl_run_bootloader(libxl_ctx *ctx,
rc = 0;
out_close:
- if (diskpath) {
- libxl__device_disk_local_detach(gc, 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 1f428b2..3af77e7 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -323,64 +323,73 @@ out:
return rc;
}
-_hidden char * libxl__device_disk_local_attach(libxl__gc *gc, libxl_device_disk *disk)
+_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;
- char *ret = NULL;
int rc;
-
- rc = libxl__device_disk_setdefault(gc, disk);
+ 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 (disk->backend) {
+ switch (tmpdisk->backend) {
case LIBXL_DISK_BACKEND_PHY:
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
- disk->pdev_path);
- dev = disk->pdev_path;
+ tmpdisk->pdev_path);
+ dev = tmpdisk->pdev_path;
break;
case LIBXL_DISK_BACKEND_TAP:
- switch (disk->format) {
+ 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)",
- disk->pdev_path);
- dev = disk->pdev_path;
+ tmpdisk->pdev_path);
+ dev = tmpdisk->pdev_path;
break;
case LIBXL_DISK_FORMAT_VHD:
- dev = libxl__blktap_devpath(gc, disk->pdev_path,
- disk->format);
+ 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", disk->format);
+ "unrecognized disk format: %d", tmpdisk->format);
break;
}
break;
case LIBXL_DISK_BACKEND_QDISK:
- if (disk->format != LIBXL_DISK_FORMAT_RAW) {
+ 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 = disk->pdev_path;
+ dev = tmpdisk->pdev_path;
break;
default:
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend "
- "type: %d", disk->backend);
+ "type: %d", tmpdisk->backend);
break;
}
out:
- if (dev != NULL)
- ret = strdup(dev);
- return ret;
+ return dev;
}
_hidden int libxl__device_disk_local_detach(libxl__gc *gc, libxl_device_disk *disk)
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 6927aef..2f1cf0f 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1006,7 +1006,8 @@ _hidden void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path);
* a device.
*/
_hidden char * libxl__device_disk_local_attach(libxl__gc *gc,
- libxl_device_disk *disk);
+ const libxl_device_disk *disk,
+ libxl_device_disk **new_disk);
_hidden int libxl__device_disk_local_detach(libxl__gc *gc,
libxl_device_disk *disk);
--
1.7.2.5
next prev parent reply other threads:[~2012-04-24 10:45 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-04 11:12 [PATCH v5 0/8] qdisk local attach Stefano Stabellini
2012-05-04 11:13 ` [PATCH v5 1/8] libxl: make libxl_device_disk_local_attach/detach internal functions Stefano Stabellini
2012-05-04 11:13 ` [PATCH v5 2/8] libxl: libxl__device_disk_local_attach return a new libxl_device_disk Stefano Stabellini
2012-05-04 14:40 ` Ian Campbell
2012-05-04 16:27 ` Ian Jackson
2012-05-14 13:04 ` Stefano Stabellini
2012-05-14 13:06 ` Ian Campbell
2012-05-14 14:15 ` Ian Jackson
2012-05-04 11:13 ` [PATCH v5 3/8] libxl: add a transaction parameter to libxl__device_generic_add Stefano Stabellini
2012-05-04 14:41 ` Ian Campbell
2012-05-04 11:13 ` [PATCH v5 4/8] libxl: introduce libxl__device_disk_add Stefano Stabellini
2012-04-24 10:45 ` [PATCH v4 0/8] qdisk local attach Stefano Stabellini
2012-04-24 10:45 ` [PATCH v4 1/8] libxl: make libxl_device_disk_local_attach/detach internal functions Stefano Stabellini
2012-04-24 15:16 ` Ian Campbell
2012-04-24 10:45 ` Stefano Stabellini [this message]
2012-04-24 15:02 ` [PATCH v4 2/8] libxl: libxl__device_disk_local_attach return a new libxl_device_disk Ian Jackson
2012-04-24 15:25 ` Ian Campbell
2012-04-24 10:45 ` [PATCH v4 3/8] libxl: add a transaction parameter to libxl__device_generic_add Stefano Stabellini
2012-04-24 15:34 ` Ian Jackson
2012-04-24 10:45 ` [PATCH v4 4/8] libxl: introduce libxl__device_disk_add_t Stefano Stabellini
2012-04-24 15:42 ` Ian Jackson
2012-04-24 16:02 ` Ian Jackson
2012-05-04 16:30 ` [PATCH v4 4/8] libxl: introduce libxl__device_disk_add_t [and 1 more messages] Ian Jackson
2012-04-24 10:45 ` [PATCH v4 5/8] xl/libxl: add a blkdev_start parameter Stefano Stabellini
2012-04-24 14:52 ` Ian Jackson
2012-04-24 10:45 ` [PATCH v4 6/8] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-04-24 14:58 ` Ian Jackson
2012-04-24 15:04 ` Ian Campbell
2012-04-24 15:16 ` Ian Jackson
2012-04-24 10:45 ` [PATCH v4 7/8] xl/libxl: implement QDISK libxl_device_disk_local_attach Stefano Stabellini
2012-04-24 15:39 ` Ian Jackson
2012-04-24 10:45 ` [PATCH v4 8/8] libxl__device_disk_local_attach: wait for state "connected" Stefano Stabellini
2012-04-24 15:18 ` Ian Jackson
2012-05-04 14:49 ` [PATCH v5 4/8] libxl: introduce libxl__device_disk_add Ian Campbell
2012-05-04 11:13 ` [PATCH v5 5/8] xl/libxl: add a blkdev_start parameter Stefano Stabellini
2012-05-04 14:54 ` Ian Campbell
2012-05-04 16:32 ` Ian Jackson
2012-05-04 11:13 ` [PATCH v5 6/8] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-05-04 14:59 ` Ian Campbell
2012-05-04 16:46 ` Ian Jackson
2012-05-04 17:08 ` Ian Campbell
2012-05-04 17:16 ` Ian Jackson
2012-05-04 17:20 ` Ian Campbell
2012-05-14 13:48 ` Stefano Stabellini
2012-05-14 13:56 ` Ian Campbell
2012-05-04 16:39 ` Ian Jackson
2012-05-14 14:10 ` Stefano Stabellini
2012-05-14 14:22 ` Ian Jackson
2012-05-14 14:43 ` Stefano Stabellini
2012-05-04 11:13 ` [PATCH v5 7/8] xl/libxl: implement QDISK libxl_device_disk_local_attach Stefano Stabellini
2012-05-04 15:11 ` Ian Campbell
2012-05-04 16:42 ` Ian Jackson
2012-05-14 14:13 ` Stefano Stabellini
2012-05-14 14:23 ` Ian Jackson
2012-05-14 14:45 ` Stefano Stabellini
2012-05-14 14:46 ` Ian Jackson
2012-05-14 14:52 ` Stefano Stabellini
2012-05-04 11:13 ` [PATCH v5 8/8] libxl__device_disk_local_attach: wait for state "connected" Stefano Stabellini
2012-05-04 15:13 ` Ian Campbell
2012-05-14 14:16 ` Stefano Stabellini
2012-05-10 13:07 ` [PATCH v5 0/8] qdisk local attach Jan Beulich
2012-05-11 15:57 ` 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=1335264358-20182-2-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).