From patchwork Wed Mar 16 16:09:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Dunlap X-Patchwork-Id: 8602181 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 09F1EC0553 for ; Wed, 16 Mar 2016 16:16:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EEB1620172 for ; Wed, 16 Mar 2016 16:16:47 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 539EA202F2 for ; Wed, 16 Mar 2016 16:16:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agE58-0006Lk-HD; Wed, 16 Mar 2016 16:13:58 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1agE57-0006LF-HF for xen-devel@lists.xen.org; Wed, 16 Mar 2016 16:13:57 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 53/6B-04060-44689E65; Wed, 16 Mar 2016 16:13:56 +0000 X-Env-Sender: prvs=8762a1c56=George.Dunlap@citrix.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1458144834!29680842!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64109 invoked from network); 16 Mar 2016 16:13:55 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Mar 2016 16:13:55 -0000 X-IronPort-AV: E=Sophos;i="5.24,345,1454976000"; d="scan'208";a="346050218" From: George Dunlap To: Date: Wed, 16 Mar 2016 16:09:15 +0000 Message-ID: <1458144557-29070-7-git-send-email-george.dunlap@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1458144557-29070-1-git-send-email-george.dunlap@citrix.com> References: <1458144557-29070-1-git-send-email-george.dunlap@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: George Dunlap , Ian Jackson , Wei Liu , Roger Pau Monne Subject: [Xen-devel] [PATCH 6/8] libxl: Allow local access for block devices with hotplug scripts X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: George Dunlap 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; and if they use block-common.sh:write_dev, this path will bre written to physical-device-path. 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. Unfortunately, at the time pygrub runs, the devices have not yet been set up. Rather than try to stash the domid somewhere to pass, we just pass -1. This allows qemuu to boot with block devices created with hotplug scripts. Signed-off-by: George Dunlap --- CC: Ian Jackson CC: Wei Liu CC: Roger Pau Monne --- tools/libxl/libxl.c | 38 +++++++++++++++++++++++++++++++++++--- tools/libxl/libxl_dm.c | 3 +-- tools/libxl/libxl_internal.h | 3 ++- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index d6302a9..490a7d2 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2296,7 +2296,7 @@ int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk) } int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, - libxl_device_disk *disk, + const libxl_device_disk *disk, libxl__device *device) { int devid; @@ -3002,6 +3002,7 @@ static char * libxl__alloc_vdev(libxl__gc *gc, void *get_vdev_user, /* Callbacks */ char * libxl__device_disk_find_local_path(libxl__gc *gc, + libxl_domid domid, const libxl_device_disk *disk, bool qdisk_direct) { char *path = NULL; @@ -3032,6 +3033,37 @@ char * libxl__device_disk_find_local_path(libxl__gc *gc, path = libxl__strdup(gc, disk->pdev_path); LOG(DEBUG, "Directly accessing local QDISK target %s", path); goto out; + } + + /* + * If the format isn't raw and / or we're using a script, then see + * if the script has written a path to the "cooked" node + */ + if(disk->script && domid != INVALID_DOMID) { + libxl__device device; + char *be_path, *pdpath; + int rc; + + LOG(DEBUG, "Run from a script; checking for physical-device-path (vdev %s)", + disk->vdev); + + rc = libxl__device_from_disk(gc, domid, disk, &device); + if (rc < 0) + goto out; + + be_path = libxl__device_backend_path(gc, &device); + + pdpath = libxl__sprintf(gc, "%s/physical-device-path", be_path); + + LOG(DEBUG, "Attempting to read node %s", pdpath); + path = libxl__xs_read(gc, XBT_NULL, pdpath); + + if (path) + LOG(DEBUG, "Accessing cooked block device %s", path); + else + LOG(DEBUG, "No physical-device-path, can't access locally."); + + goto out; } out: @@ -3058,7 +3090,8 @@ 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, false))) { + if ((dls->diskpath = libxl__device_disk_find_local_path(gc, INVALID_DOMID, + in_disk, false))) { LOG(DEBUG, "Local path found, executing callback."); dls->callback(egc, dls, 0); } else { @@ -3073,7 +3106,6 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc, 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, diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 917ebbf..646a49c 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1206,8 +1206,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc, target_path = libxl__blktap_devpath(gc, disks[i].pdev_path, disks[i].format); else - target_path = libxl__device_disk_find_local_path(gc, - &disks[i], true); + target_path = libxl__device_disk_find_local_path(gc, guest_domid, &disks[i], true); if (!target_path) { LOG(WARN, "No way to get local access disk to image: %s", disks[i].vdev); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index a511c6d..6291b9c 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -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 @@ -2674,6 +2674,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);