From nobody Sat Apr 20 16:31:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1486497055307544.0757040031598; Tue, 7 Feb 2017 11:50:55 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17JlVbl046011; Tue, 7 Feb 2017 14:47:31 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v17JkaYk025409 for ; Tue, 7 Feb 2017 14:46:36 -0500 Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17JkadY027551 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 7 Feb 2017 14:46:36 -0500 Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF70D81254 for ; Tue, 7 Feb 2017 19:46:35 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Tue, 07 Feb 2017 12:46:33 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Tue, 7 Feb 2017 12:46:23 -0700 Message-Id: <20170207194624.25043-2-jfehlig@suse.com> In-Reply-To: <20170207194624.25043-1-jfehlig@suse.com> References: <20170207194624.25043-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 200 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Feb 2017 19:46:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Feb 2017 19:46:36 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH V2 1/2] libxl: set default disk format in device post-parse X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When starting a domian, a libxl_domain_config object is created from virDomainDef. Any virDomainDiskDef devices with a format of VIR_STORAGE_FILE_NONE are mapped to LIBXL_DISK_FORMAT_RAW in the corresponding libxl_disk_device, but the virDomainDiskDef format is never updated to reflect the change. A better place to set a default format for disk devices is the device post-parse callback, ensuring the virDomainDiskDef object reflects the default format. Signed-off-by: Jim Fehlig --- src/libxl/libxl_conf.c | 10 ++-------- src/libxl/libxl_domain.c | 7 ++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index b5186f2..da63105 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -765,8 +765,6 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_= disk *x_disk) x_disk->format =3D LIBXL_DISK_FORMAT_VHD; x_disk->backend =3D LIBXL_DISK_BACKEND_TAP; break; - case VIR_STORAGE_FILE_NONE: - /* No subtype specified, default to raw/tap */ case VIR_STORAGE_FILE_RAW: x_disk->format =3D LIBXL_DISK_FORMAT_RAW; x_disk->backend =3D LIBXL_DISK_BACKEND_TAP; @@ -802,8 +800,6 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_= disk *x_disk) case VIR_STORAGE_FILE_VHD: x_disk->format =3D LIBXL_DISK_FORMAT_VHD; break; - case VIR_STORAGE_FILE_NONE: - /* No subtype specified, default to raw */ case VIR_STORAGE_FILE_RAW: x_disk->format =3D LIBXL_DISK_FORMAT_RAW; break; @@ -816,8 +812,7 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_= disk *x_disk) return -1; } } else if (STREQ(driver, "file")) { - if (format !=3D VIR_STORAGE_FILE_NONE && - format !=3D VIR_STORAGE_FILE_RAW) { + if (format !=3D VIR_STORAGE_FILE_RAW) { virReportError(VIR_ERR_INTERNAL_ERROR, _("libxenlight does not support disk format= %s " "with disk driver %s"), @@ -828,8 +823,7 @@ libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_= disk *x_disk) x_disk->format =3D LIBXL_DISK_FORMAT_RAW; x_disk->backend =3D LIBXL_DISK_BACKEND_QDISK; } else if (STREQ(driver, "phy")) { - if (format !=3D VIR_STORAGE_FILE_NONE && - format !=3D VIR_STORAGE_FILE_RAW) { + if (format !=3D VIR_STORAGE_FILE_RAW) { virReportError(VIR_ERR_INTERNAL_ERROR, _("libxenlight does not support disk format= %s " "with disk driver %s"), diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index ed73cd2..c0ace33 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -362,16 +362,21 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr d= ev, } } =20 - /* for network-based disks, set 'qemu' as the default driver */ if (dev->type =3D=3D VIR_DOMAIN_DEVICE_DISK) { virDomainDiskDefPtr disk =3D dev->data.disk; int actual_type =3D virStorageSourceGetActualType(disk->src); + int format =3D virDomainDiskGetFormat(disk); =20 + /* for network-based disks, set 'qemu' as the default driver */ if (actual_type =3D=3D VIR_STORAGE_TYPE_NETWORK) { if (!virDomainDiskGetDriver(disk) && virDomainDiskSetDriver(disk, "qemu") < 0) return -1; } + + /* xl.cfg default format is raw. See xl-disk-configuration(5) */ + if (format =3D=3D VIR_STORAGE_FILE_NONE) + virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); } =20 return 0; --=20 2.9.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 16:31:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1486497032864810.4184066338707; Tue, 7 Feb 2017 11:50:32 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17JkcMq045939; Tue, 7 Feb 2017 14:46:39 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v17JkblL025417 for ; Tue, 7 Feb 2017 14:46:37 -0500 Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v17Jkb4N027554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 7 Feb 2017 14:46:37 -0500 Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0FD1E61B8E for ; Tue, 7 Feb 2017 19:46:36 +0000 (UTC) Received: from linux-tbji.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Tue, 07 Feb 2017 12:46:33 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Tue, 7 Feb 2017 12:46:24 -0700 Message-Id: <20170207194624.25043-3-jfehlig@suse.com> In-Reply-To: <20170207194624.25043-1-jfehlig@suse.com> References: <20170207194624.25043-1-jfehlig@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 200 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 07 Feb 2017 19:46:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 07 Feb 2017 19:46:36 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'jfehlig@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.501 (BAYES_50, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH V2 2/2] libxl: fix disk detach when not specified X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When a user does not explicitly set a in the disk config, libvirt defers selection of a default to libxl. This approach works fine when starting a domain with such configuration or attaching a disk to a running domain. But when detaching such a disk, libxl will fail with "unrecognized disk backend type: 0". libxl makes no attempt to recalculate a default backend (driver) on detach and simply fails when uninitialized. This patch updates the libvirt disk config with the backend selected by libxl when starting a domain or attaching a disk to a running domain. Another benefit of this approach is that the live XML is also updated with the backend driver selected by libxl. Signed-off-by: Jim Fehlig --- src/libxl/libxl_conf.c | 32 ++++++++++++++++++++++++++++++++ src/libxl/libxl_conf.h | 4 ++++ src/libxl/libxl_domain.c | 25 +++++++++++++++++++++++++ src/libxl/libxl_driver.c | 1 + 4 files changed, 62 insertions(+) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index da63105..4e38676 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -907,6 +907,38 @@ libxlMakeDiskList(virDomainDefPtr def, libxl_domain_co= nfig *d_config) return -1; } =20 +/* + * Update libvirt disk config with libxl disk config. + * + * This function can be used to update the libvirt disk config with default + * values selected by libxl. Currently only the backend type is selected by + * libxl when not explicitly specified by the user. + */ +void +libxlUpdateDiskDef(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) +{ + const char *driver =3D NULL; + + if (virDomainDiskGetDriver(l_disk)) + return; + + switch (x_disk->backend) { + case LIBXL_DISK_BACKEND_QDISK: + driver =3D "qemu"; + break; + case LIBXL_DISK_BACKEND_TAP: + driver =3D "tap"; + break; + case LIBXL_DISK_BACKEND_PHY: + driver =3D "phy"; + break; + case LIBXL_DISK_BACKEND_UNKNOWN: + break; + } + if (driver) + ignore_value(virDomainDiskSetDriver(l_disk, driver)); +} + int libxlMakeNic(virDomainDefPtr def, virDomainNetDefPtr l_nic, diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index 69d7885..b944f6c 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -175,6 +175,10 @@ int libxlDriverConfigLoadFile(libxlDriverConfigPtr cfg, =20 int libxlMakeDisk(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev); + +void +libxlUpdateDiskDef(virDomainDiskDefPtr l_dev, libxl_device_disk *x_dev); + int libxlMakeNic(virDomainDefPtr def, virDomainNetDefPtr l_nic, diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index c0ace33..57ec661 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1072,6 +1072,30 @@ libxlDomainCreateIfaceNames(virDomainDefPtr def, lib= xl_domain_config *d_config) } } =20 +static void +libxlDomainUpdateDiskParams(virDomainDefPtr def, libxl_ctx *ctx) +{ + libxl_device_disk *disks; + int num_disks =3D 0; + size_t i; + int idx; + + disks =3D libxl_device_disk_list(ctx, def->id, &num_disks); + if (!disks) + return; + + for (i =3D 0; i < num_disks; i++) { + if ((idx =3D virDomainDiskIndexByName(def, disks[i].vdev, false)) = < 0) + continue; + + libxlUpdateDiskDef(def->disks[idx], &disks[i]); + } + + for (i =3D 0; i < num_disks; i++) + libxl_device_disk_dispose(&disks[i]); + VIR_FREE(disks); +} + #ifdef LIBXL_HAVE_DEVICE_CHANNEL static void libxlDomainCreateChannelPTY(virDomainDefPtr def, libxl_ctx *ctx) @@ -1315,6 +1339,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, goto destroy_dom; =20 libxlDomainCreateIfaceNames(vm->def, &d_config); + libxlDomainUpdateDiskParams(vm->def, cfg->ctx); =20 #ifdef LIBXL_HAVE_DEVICE_CHANNEL if (vm->def->nchannels > 0) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 3a69720..e7827cc 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3028,6 +3028,7 @@ libxlDomainAttachDeviceDiskLive(virDomainObjPtr vm, v= irDomainDeviceDefPtr dev) goto cleanup; } =20 + libxlUpdateDiskDef(l_disk, &x_disk); virDomainDiskInsertPreAlloced(vm->def, l_disk); =20 } else { --=20 2.9.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list