From patchwork Tue Apr 9 16:45:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10891723 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A73117E0 for ; Tue, 9 Apr 2019 16:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 858AB285A5 for ; Tue, 9 Apr 2019 16:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 774592888E; Tue, 9 Apr 2019 16:47:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0E0C7285A5 for ; Tue, 9 Apr 2019 16:47:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hDtsd-00088s-99; Tue, 09 Apr 2019 16:45:51 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hDtsc-00088U-GM for xen-devel@lists.xenproject.org; Tue, 09 Apr 2019 16:45:50 +0000 X-Inumbo-ID: edc8db84-5ae6-11e9-92d7-bc764e045a96 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id edc8db84-5ae6-11e9-92d7-bc764e045a96; Tue, 09 Apr 2019 16:45:49 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.60,330,1549929600"; d="scan'208";a="83137612" From: Anthony PERARD To: Date: Tue, 9 Apr 2019 17:45:38 +0100 Message-ID: <20190409164542.30274-6-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190409164542.30274-1-anthony.perard@citrix.com> References: <20190409164542.30274-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/9] libxl_disk: Reorganise libxl_cdrom_insert X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Wei Liu , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is in preparation of cutting libxl_cdrom_insert into several functions to allow asynchronous callbacks. No functional changes. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_disk.c | 58 ++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/tools/libxl/libxl_disk.c b/tools/libxl/libxl_disk.c index 79e30f8d52..f7a1b75ae1 100644 --- a/tools/libxl/libxl_disk.c +++ b/tools/libxl/libxl_disk.c @@ -666,7 +666,7 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, { AO_CREATE(ctx, domid, ao_how); int num = 0, i; - libxl_device_disk *disks = NULL, disk_saved, disk_empty; + libxl_device_disk *disks = NULL, disk_saved; libxl_domain_config d_config; int rc, dm_ver; libxl__device device; @@ -677,16 +677,9 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, flexarray_t *insert = NULL, *empty = NULL; libxl_domain_config_init(&d_config); - libxl_device_disk_init(&disk_empty); libxl_device_disk_init(&disk_saved); libxl_device_disk_copy(ctx, &disk_saved, disk); - disk_empty.format = LIBXL_DISK_FORMAT_EMPTY; - disk_empty.vdev = libxl__strdup(NOGC, disk->vdev); - disk_empty.pdev_path = libxl__strdup(NOGC, ""); - disk_empty.is_cdrom = 1; - libxl__device_disk_setdefault(gc, domid, &disk_empty, false); - libxl_domain_type type = libxl__domain_type(gc, domid); if (type == LIBXL_DOMAIN_TYPE_INVALID) { rc = ERROR_FAIL; @@ -740,23 +733,6 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, be_path = libxl__device_backend_path(gc, &device); libxl_path = libxl__device_libxl_path(gc, &device); - insert = flexarray_make(gc, 4, 1); - - flexarray_append_pair(insert, "type", - libxl__device_disk_string_of_backend(disk->backend)); - if (disk->format != LIBXL_DISK_FORMAT_EMPTY) - flexarray_append_pair(insert, "params", - GCSPRINTF("%s:%s", - libxl__device_disk_string_of_format(disk->format), - disk->pdev_path)); - else - flexarray_append_pair(insert, "params", ""); - - empty = flexarray_make(gc, 4, 1); - flexarray_append_pair(empty, "type", - libxl__device_disk_string_of_backend(disk->backend)); - flexarray_append_pair(empty, "params", ""); - /* Note: CTX lock is already held at this point so lock hierarchy * is maintained. */ @@ -769,11 +745,27 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, /* We need to eject the original image first. This is implemented * by inserting empty media. JSON is not updated. */ + if (dm_ver == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { + libxl_device_disk disk_empty; + + libxl_device_disk_init(&disk_empty); + disk_empty.format = LIBXL_DISK_FORMAT_EMPTY; + disk_empty.vdev = libxl__strdup(NOGC, disk->vdev); + disk_empty.pdev_path = libxl__strdup(NOGC, ""); + disk_empty.is_cdrom = 1; + libxl__device_disk_setdefault(gc, domid, &disk_empty, false); + rc = libxl__qmp_insert_cdrom(gc, domid, &disk_empty); + libxl_device_disk_dispose(&disk_empty); if (rc) goto out; } + empty = flexarray_make(gc, 4, 1); + flexarray_append_pair(empty, "type", + libxl__device_disk_string_of_backend(disk->backend)); + flexarray_append_pair(empty, "params", ""); + for (;;) { rc = libxl__xs_transaction_start(gc, &t); if (rc) goto out; @@ -800,6 +792,10 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, if (rc < 0) goto out; } + /* + * Now that the drive is empty, we can insert the new media. + */ + rc = libxl__get_domain_configuration(gc, domid, &d_config); if (rc) goto out; @@ -813,6 +809,17 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, if (rc) goto out; } + insert = flexarray_make(gc, 4, 1); + flexarray_append_pair(insert, "type", + libxl__device_disk_string_of_backend(disk->backend)); + if (disk->format != LIBXL_DISK_FORMAT_EMPTY) + flexarray_append_pair(insert, "params", + GCSPRINTF("%s:%s", + libxl__device_disk_string_of_format(disk->format), + disk->pdev_path)); + else + flexarray_append_pair(insert, "params", ""); + for (;;) { rc = libxl__xs_transaction_start(gc, &t); if (rc) goto out; @@ -850,7 +857,6 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk, out: libxl__xs_transaction_abort(gc, &t); libxl__device_list_free(&libxl__disk_devtype, disks, num); - libxl_device_disk_dispose(&disk_empty); libxl_device_disk_dispose(&disk_saved); libxl_domain_config_dispose(&d_config);