Allow qemu to provide emulated disks for devices with hotplug scripts
cover Allow qemu to provide emulated disks for devices with hotplug scripts
Qemu in dom0 can only provide emulated disks when the qemu process has access to an image of the file. At the moment, this only includes plain files or physical devices in dom0; it does not include anything to do with a hotplug script.
However, hotplug scripts run from dom0 generally do, as a necessary side effect of their activity, create a block device which could be passed to domain 0; this block device can be passed to a qemu device running in dom0 to provide emulated disk support.
This series allows qemu to gain access to that block device, giving it full parity with PV guests for all disks whose backend is in domain 0.
It also takes steps towards generalizing the "local attach" funcitonality which is used by pygrub to access non-local disks, so that in the future qemu can access emulated disks by attaching them to dom0.
RFC because I haven't tested it since forward-porting it.
George Dunlap (4):
libxl: Move check for local access to a funciton
libxl: Share logic for finding path between qemuu and pygrub tools/hotplug: Add a "dummy" hotplug script for testing
libxl: Allow local access for block devices with hotplug scripts
tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-common.sh | 5 +- tools/hotplug/Linux/block-dummy | 107 +++++++++++++++++++++++++++++++++ tools/libxl/libxl.c | 115 +++++++++++++++++++++++++++++------- tools/libxl/libxl_bootloader.c | 1 + tools/libxl/libxl_dm.c | 66 ++++++++++++++------- tools/libxl/libxl_internal.h | 12 +++- 7 files changed, 262 insertions(+), 45 deletions(-) create mode 100644 tools/hotplug/Linux/block-dummy
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
RFC PATCH 1/4 libxl: Move check for local access to a funciton
From: George Dunlap <[email protected]>
Move pygrub checks for local access ability into a separate function.
Also reorganize libxl__device_disk_local_initiate_attach so that we don't initialize dls->disk unless we actually end up doing a local attach.
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monne <[email protected]>
--- tools/libxl/libxl.c | 66 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 20 deletions(-)
tools/libxl/libxl.c +46 -20
@@ -3016,13 +3016,38 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user,/* Callbacks */ +static char *libxl__device_disk_find_local_path (libxl__gc *gc, +const libxl_device_disk *disk) { +char *path =NULL ; + +/* No local paths for driver domains */ +if (disk->backend_domname !=NULL ) { +LOG (DEBUG ,"Non-local backend, can't access locally.\n" ); + goto out; + } + +/* +* If this is in raw format, and we're not using a script or a +* driver domain, we can access the target path directly. +*/ +if (disk->format ==LIBXL_DISK_FORMAT_RAW + && disk->script ==NULL + && disk->pdev_path) { + path =libxl__strdup (gc, disk->pdev_path); +LOG (DEBUG ,"Directly accessing local RAW disk %s" , path); + goto out; + } + + out: +return path; +} +static void local_device_attach_cb (libxl__egc *egc,libxl__ao_device *aodev);void libxl__device_disk_local_initiate_attach (libxl__egc *egc,libxl__disk_local_state *dls) {STATE_AO_GC (dls->ao); -char *dev =NULL ;int rc;const libxl_device_disk *in_disk = dls->in_disk;libxl_device_disk *disk = &dls->disk;
@@ -3030,34 +3055,35 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,assert (in_disk->pdev_path); -memcpy (disk, in_disk,sizeof (libxl_device_disk)); - disk->pdev_path =libxl__strdup (gc, in_disk->pdev_path); -if (in_disk->script !=NULL ) - disk->script =libxl__strdup (gc, in_disk->script); disk->vdev =NULL ; - rc =libxl__device_disk_setdefault (gc, disk); -if (rc) goto out; +if (dls->diskpath) +LOG (DEBUG ,"Strange, dls->diskpath already set: %s" , dls->diskpath); -/* If this is in a driver domain, or it's not a raw format, or it involves -* running a script, we have to do a local attach. */ -if (disk->backend_domname !=NULL - || disk->format !=LIBXL_DISK_FORMAT_RAW - || disk->script !=NULL ) { +LOG (DEBUG ,"Trying to find local path" ); + +if ((dls->diskpath =libxl__device_disk_find_local_path (gc, in_disk))) { +LOG (DEBUG ,"Local path found, executing callback." ); + dls->callback (egc, dls,0 ); + }else { +LOG (DEBUG ,"Local path not found, initiating attach." ); + +memcpy (disk, in_disk,sizeof (libxl_device_disk)); + disk->pdev_path =libxl__strdup (gc, in_disk->pdev_path); +if (in_disk->script !=NULL ) + disk->script =libxl__strdup (gc, in_disk->script); + disk->vdev =NULL ; + + rc =libxl__device_disk_setdefault (gc, disk); +if (rc) goto out; + +/* If we can't find a local path, attach it */ libxl__prepare_ao_device (ao, &dls->aodev); dls->aodev.callback = local_device_attach_cb;device_disk_add (egc,LIBXL_TOOLSTACK_DOMID , disk, &dls->aodev, libxl__alloc_vdev, (void *) blkdev_start); -return ; } -LOG (DEBUG ,"locally attaching RAW disk %s" , disk->pdev_path); - dev = disk->pdev_path; - -if (dev !=NULL ) - dls->diskpath =libxl__strdup (gc, dev); - - dls->callback (egc, dls,0 );return ; out:
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
RFC PATCH 2/4 libxl: Share logic for finding path between qemuu and pygrub
In reply to George DunlapFrom: George Dunlap <[email protected]>
qemu can also access disks which will be provided with a qdisk backend directly; add a flag to libxl__device_disk_find_local_path to indicate whether to check for qdisk direct access.
Reorganize the qemuu disk argument code to make a clean separation between finding a file to use (if any), and constructing the parameters.
Only use qemu_disk_format_string() in circumstances where qemu may be interpreting the disk (i.e., backend==QDISK). In all other cases, it should use RAW.
Share as much as possible between the is_cdrom path and the normal path.
Call libxl__device_disk_find_local_path() for most paths. If we can't find a local path, print an error and skip the disk, rather than using a bogus path.
This should fix two bugs:
* In the case of a block script, or a non-dom0 backend, qemuu will now print a warning and skip the disk, rather than adding bogus parameters that will cause qemuu to error out.
* You should now be able to use any backend for a cdrom that you can use for a normal disk. (Before it was limited to RAW files or things that qemu could handle directly.)
I left the libxl__blktap_devpath in the qemuu-specific code rather than sharing it with the pyrgub code because:
1) When the pygrub path runs the guest disks have not yet been set up
2) libxl__blktap_devpath() will give you the existing devpath if it already exists, but will set one up for you if you don't. So on the pygrub path, this would end up setting up a new tap device.
3) There is no TAP-specific teardown code on the pygrub path, and I don't want to add any (particularly since I'm hoping to remove tapdisk altogether soon).
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Anthony Perard <[email protected]>
CC: Roger Pau Monne <[email protected]>
--- tools/libxl/libxl.c | 17 ++++++++++-- tools/libxl/libxl_dm.c | 66 +++++++++++++++++++++++++++++--------------- tools/libxl/libxl_internal.h | 8 ++++++ 3 files changed, 66 insertions(+), 25 deletions(-)
tools/libxl/libxl.c +14 -3
@@ -3016,8 +3016,9 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user,/* Callbacks */ -static char *libxl__device_disk_find_local_path (libxl__gc *gc, -const libxl_device_disk *disk) { +char *libxl__device_disk_find_local_path (libxl__gc *gc, +const libxl_device_disk *disk, +bool qdisk_direct) {char *path =NULL ;/* No local paths for driver domains */
@@ -3038,6 +3039,16 @@ static char * libxl__device_disk_find_local_path(libxl__gc *gc, goto out; } +/* +* If we're being called for a qemu path, we can pass the target +* string directly as well +*/ +if (qdisk_direct && disk->backend ==LIBXL_DISK_BACKEND_QDISK ) { + path =libxl__strdup (gc, disk->pdev_path); +LOG (DEBUG ,"Directly accessing local QDISK target %s" , path); + goto out; + } + out:return path; }
@@ -3062,7 +3073,7 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,LOG (DEBUG ,"Trying to find local path" ); -if ((dls->diskpath =libxl__device_disk_find_local_path (gc, in_disk))) { +if ((dls->diskpath =libxl__device_disk_find_local_path (gc, in_disk, false))) {LOG (DEBUG ,"Local path found, executing callback." ); dls->callback (egc, dls,0 ); }else {
tools/libxl/libxl_dm.c +44 -22
110 lines not on this page · raw message
tools/libxl/libxl_internal.h +8 -0
@@ -2670,6 +2670,14 @@ static inline void libxl__device_disk_local_init(libxl__disk_local_state *dls) dls->rc =0 ; } +/* +* See if we can find a way to access a disk locally +*/ +_hidden char * libxl__device_disk_find_local_path(libxl__gc *gc, +const libxl_device_disk *disk, +bool qdisk_direct); + +/* Make a disk available in this (the control) domain. Always calls * dls->callback when finished. * State Idle -> Attaching
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
RFC PATCH 3/4 tools/hotplug: Add a "dummy" hotplug script for testing
In reply to George DunlapFrom: George Dunlap <[email protected]>
Testing the hotplug external script path at the moment involves actually setting up one of the alternate datapaths (blktap, iscsi, &c). Simplify testing by making a script which does a simple loopback, but still has a target that can't be used directly.
To use:
script=block-dummy,vdev=xvda,target=dummy:<file>
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monne <[email protected]>
--- tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-dummy | 107 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+)
tools/hotplug/Linux/Makefile +1 -0
@@ -27,6 +27,7 @@ XEN_SCRIPTS += vscsi XEN_SCRIPTS += block-iscsi XEN_SCRIPTS += block-tap XEN_SCRIPTS += block-drbd-probe +XEN_SCRIPTS += block-dummy XEN_SCRIPTS += $(XEN_SCRIPTS-y) SUBDIRS-$(CONFIG_SYSTEMD) += systemd
tools/hotplug/Linux/block-dummy new file +107 -0
107 lines not on this page · raw message
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
RFC PATCH 4/4 libxl: Allow local access for block devices with hotplug scripts
In reply to George DunlapFrom: George Dunlap <[email protected]>
pygrub and qemuu need to be able to access a VM's disks locally in order to be able to pull out the kernel and provide emulated disk access, respectively. This can be done either by accessing the local disk directly, or by plugging the target disk into dom0 to allow access.
Unfortunately, while the plugging machinery works for pygrub, it does not yet work for qemuu; meaning that disk hotplug scripts cannot be used with HVM domains.
Fortunately, disks using hotplug scripts created in dom0 do create a block device as part of set-up, which can be accessed locally.
First, modify the write_dev function in block-common to add an extra
parameter: "physical-device-path", the path to the physical device which is passed to blkback. All hotplug scripts that use write_dev will automatically gain the new functionality.
Second, modify libxl__device_disk_setdefault() to be able to fish this path out of xenstore and pass it back.
We need the target domid to find the appropriate xenstore node, so add that to libxl__disk_local_state.
This allows qemuu to boot with block devices created with hotplug scripts.
Unfortunately it does not allow pygrub to access a device locally without having to plug it in, because when pygrub runs the guests' disks have not yet been set up.
---
CC: Ian Campbell <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monne <[email protected]>
--- tools/hotplug/Linux/block-common.sh | 5 ++++- tools/libxl/libxl.c | 42 ++++++++++++++++++++++++++++++++++--- tools/libxl/libxl_bootloader.c | 1 + tools/libxl/libxl_dm.c | 2 +- tools/libxl/libxl_internal.h | 4 +++- 5 files changed, 48 insertions(+), 6 deletions(-)
tools/hotplug/Linux/block-common.sh +4 -1
@@ -58,8 +58,9 @@ device_major_minor() # write_dev() { local mm + local dev="$1" - mm=$(device_major_minor "$1") + mm=$(device_major_minor "$dev") if [ -z $mm ] then
@@ -68,6 +69,8 @@ write_dev() { xenstore_write "$XENBUS_PATH/physical-device" "$mm" + xenstore_write "$XENBUS_PATH/physical-device-path" "$dev" + success }
tools/libxl/libxl.c +39 -3
78 lines not on this page · raw message
tools/libxl/libxl_bootloader.c +1 -0
@@ -382,6 +382,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)/* This sets the state of the dls struct from Undefined to Idle */ libxl__device_disk_local_init (&bl->dls); bl->dls.ao = ao; + bl->dls.domid = bl->domid; bl->dls.in_disk = bl->disk; bl->dls.blkdev_start = info->blkdev_start; bl->dls.callback = bootloader_disk_attached_cb;
tools/libxl/libxl_dm.c +1 -1
@@ -1207,7 +1207,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, disks[i].format); else target_path =libxl__device_disk_find_local_path (gc, - &disks[i], true); + guest_domid, &disks[i], true);if (!target_path) {LOG (WARN ,"No way to get local access disk to image: %s" , disks[i].vdev);
tools/libxl/libxl_internal.h +3 -1
@@ -1709,7 +1709,7 @@ _hidden char *libxl__blktap_devpath(libxl__gc *gc, _hidden int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params); _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, -libxl_device_disk *disk, +const libxl_device_disk *disk,libxl__device *device);/* Calls poll() again - useful to check whether a signaled condition
@@ -2650,6 +2650,7 @@ typedef void libxl__disk_local_state_callback(libxl__egc*,struct libxl__disk_local_state {/* filled by the user */ libxl__ao *ao; +libxl_domid domid;const libxl_device_disk *in_disk;libxl_device_disk disk;const char *blkdev_start;
@@ -2674,6 +2675,7 @@ static inline void libxl__device_disk_local_init(libxl__disk_local_state *dls)* See if we can find a way to access a disk locally */ _hidden char * libxl__device_disk_find_local_path(libxl__gc *gc, +libxl_domid domid,const libxl_device_disk *disk,bool qdisk_direct);
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 13 lines · George Dunlap
Qemu in dom0 can only provide emulated disks when the qemu process has access to an image of the file. At the moment, this only includes plain files or physical devices in dom0; it does not include anything to do with a hotplug script.
However, hotplug scripts run from dom0 generally do, as a necessary side effect of their activity, create a block device which could be passed to domain 0; this block device can be passed to a qemu device running in dom0 to provide emulated disk support.
This series allows qemu to gain access to that block device, giving it full parity with PV guests for all disks whose backend is in domain 0.
Quoted 7 lines
It also takes steps towards generalizing the "local attach" funcitonality which is used by pygrub to access non-local disks, so that in the future qemu can access emulated disks by attaching them to dom0.
RFC because I haven't tested it since forward-porting it.
I haven't looked at this series, but I expect another posting on top of Ian Jackson's hotplug script interface patch.
If you want me to look at this series, please let me know.
Wei.
Quoted 7 lines
George Dunlap (4):
libxl: Move check for local access to a funciton
libxl: Share logic for finding path between qemuu and pygrubtools/hotplug: Add a "dummy" hotplug script for testing
libxl: Allow local access for block devices with hotplug scripts
Quoted 18 lines
tools/hotplug/Linux/Makefile | 1 + tools/hotplug/Linux/block-common.sh | 5 +- tools/hotplug/Linux/block-dummy | 107 +++++++++++++++++++++++++++++++++ tools/libxl/libxl.c | 115 +++++++++++++++++++++++++++++------- tools/libxl/libxl_bootloader.c | 1 + tools/libxl/libxl_dm.c | 66 ++++++++++++++------- tools/libxl/libxl_internal.h | 12 +++- 7 files changed, 262 insertions(+), 45 deletions(-) create mode 100644 tools/hotplug/Linux/block-dummySignature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel