xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
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 v8 02/11] libxl: libxl__device_disk_local_attach return a new libxl_device_disk
Date: Tue, 29 May 2012 11:39:07 +0100	[thread overview]
Message-ID: <1338287956-24691-2-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1205281439080.26786@kaball-desktop>

Introduce a new libxl_device_disk* parameter to
libxl__device_disk_local_attach, the parameter is allocated by the
caller. libxl__device_disk_local_attach is going to fill the new disk
with informations about the new locally attached disk.  The new
libxl_device_disk should be passed to libxl_device_disk_local_detach
afterwards.

Changes in v8:
- free pdev_path and script in local_detach;
- use libxl__strdup instead of strdup.

Changes in v7:
- rename tmpdisk to localdisk;
- add a comment in libxl__bootloader_state about localdisk.

Changes in v6:
- return error in case pdev_path is NULL;
- libxl__device_disk_local_attach update the new disk, the caller
allocates it;
- remove \n from logs.

Changes in v5:
- rename disk to in_disk;
- rename tmpdisk to disk;
- copy disk to new_disk only on success;
- remove check on libxl__zalloc success.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 tools/libxl/libxl.c            |   18 +++++++++++++++---
 tools/libxl/libxl_bootloader.c |    4 ++--
 tools/libxl/libxl_internal.h   |   10 +++++++++-
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index cd870c4..762e72a 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1735,13 +1735,24 @@ out:
     return ret;
 }
 
-char * libxl__device_disk_local_attach(libxl__gc *gc, libxl_device_disk *disk)
+char * libxl__device_disk_local_attach(libxl__gc *gc,
+        const libxl_device_disk *in_disk,
+        libxl_device_disk *disk)
 {
     libxl_ctx *ctx = gc->owner;
     char *dev = NULL;
     char *ret = NULL;
     int rc;
 
+    if (in_disk->pdev_path == NULL)
+        return NULL;
+
+    memcpy(disk, in_disk, sizeof(libxl_device_disk));
+    disk->pdev_path = libxl__strdup(NULL, in_disk->pdev_path);
+    if (in_disk->script != NULL)
+        disk->script = libxl__strdup(NULL, in_disk->script);
+    disk->vdev = NULL;
+
     rc = libxl__device_disk_setdefault(gc, disk);
     if (rc) goto out;
 
@@ -1779,8 +1790,7 @@ char * libxl__device_disk_local_attach(libxl__gc *gc, libxl_device_disk *disk)
                            " 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);
+            LOG(DEBUG, "locally attaching qdisk %s", in_disk->pdev_path);
             dev = disk->pdev_path;
             break;
         default:
@@ -1804,6 +1814,8 @@ int libxl__device_disk_local_detach(libxl__gc *gc, libxl_device_disk *disk)
      * needed by the soon to be started domain and do nothing.
      */
 
+    free(disk->pdev_path);
+    free(disk->script);
     return 0;
 }
 
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index e8950b1..82371f1 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -228,7 +228,7 @@ static void bootloader_cleanup(libxl__egc *egc, libxl__bootloader_state *bl)
     if (bl->outputdir) libxl__remove_directory(gc, bl->outputdir);
 
     if (bl->diskpath) {
-        libxl__device_disk_local_detach(gc, bl->disk);
+        libxl__device_disk_local_detach(gc, &bl->localdisk);
         free(bl->diskpath);
         bl->diskpath = 0;
     }
@@ -330,7 +330,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)
         goto out;
     }
 
-    bl->diskpath = libxl__device_disk_local_attach(gc, bl->disk);
+    bl->diskpath = libxl__device_disk_local_attach(gc, bl->disk, &bl->localdisk);
     if (!bl->diskpath) {
         rc = ERROR_FAIL;
         goto out;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index d34e561..21b8b54 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1265,7 +1265,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 *in_disk,
+        libxl_device_disk *new_disk);
 _hidden int libxl__device_disk_local_detach(libxl__gc *gc,
         libxl_device_disk *disk);
 
@@ -1803,6 +1804,13 @@ struct libxl__bootloader_state {
     libxl__bootloader_console_callback *console_available;
     libxl_domain_build_info *info; /* u.pv.{kernel,ramdisk,cmdline} updated */
     libxl_device_disk *disk;
+    /* Should be zeroed by caller on entry.  Will be filled in by
+     * bootloader machinery; represents the local attachment of the
+     * disk for the benefit of the bootloader.  Must be detached by
+     * the caller using libxl__device_disk_local_detach, but only
+     * after the domain's kernel and initramfs have been loaded into
+     * memory and the file references disposed of. */
+    libxl_device_disk localdisk;
     uint32_t domid;
     /* private to libxl__run_bootloader */
     char *outputpath, *outputdir, *logfile;
-- 
1.7.2.5

  parent reply	other threads:[~2012-05-29 10:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 10:38 [PATCH v8 0/11] qdisk local attach Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 01/11] libxl: make libxl_device_disk_local_attach/detach internal functions Stefano Stabellini
2012-05-29 10:39 ` Stefano Stabellini [this message]
2012-05-29 14:10   ` [PATCH v8 02/11] libxl: libxl__device_disk_local_attach return a new libxl_device_disk Ian Campbell
2012-05-29 14:29     ` Stefano Stabellini
2012-05-29 14:48       ` Stefano Stabellini
2012-05-29 15:03         ` Ian Campbell
2012-05-29 15:10           ` Stefano Stabellini
2012-05-29 15:23         ` Ian Jackson
2012-05-29 15:25         ` Ian Jackson
2012-05-29 15:32           ` Ian Campbell
2012-05-29 10:39 ` [PATCH v8 03/11] libxl: add a transaction parameter to libxl__device_generic_add Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 04/11] libxl: export libxl__device_from_disk Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 05/11] libxl: introduce libxl__device_disk_add Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 06/11] xl/libxl: add a blkdev_start parameter Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 07/11] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 08/11] xl/libxl: implement QDISK libxl_device_disk_local_attach Stefano Stabellini
2012-06-07 17:56   ` Roger Pau Monne
2012-06-07 18:27     ` Ian Jackson
2012-05-29 10:39 ` [PATCH v8 09/11] libxl__device_disk_local_attach: wait for state "connected" Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 10/11] libxl_string_to_backend: add qdisk Stefano Stabellini
2012-05-29 10:39 ` [PATCH v8 11/11] main_blockdetach: destroy the disk on successful removal Stefano Stabellini
2012-05-29 15:37 ` [PATCH v8 0/11] qdisk local attach 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=1338287956-24691-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).