From nobody Sat May 18 23:55:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1533459221073592.399573809985; Sun, 5 Aug 2018 01:53:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 619413082A55; Sun, 5 Aug 2018 08:53:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27ACC173A5; Sun, 5 Aug 2018 08:53:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D245618363F4; Sun, 5 Aug 2018 08:53:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w73Cxpgg020292 for ; Fri, 3 Aug 2018 08:59:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9EA7B2156711; Fri, 3 Aug 2018 12:59:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-135.ams2.redhat.com [10.36.117.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 916F4215670D; Fri, 3 Aug 2018 12:59:50 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 3 Aug 2018 13:59:47 +0100 Message-Id: <20180803125947.1536-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: ensure "pc" machine is always used as default if available 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sun, 05 Aug 2018 08:53:40 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 It is increasingly likely that some distro is going to change the default "x86" machine type in QEMU from "pc" to "q35". This will certainly break existing applications which write their XML on the assumption that its using a "pc" machine by default. For example they'll lack a IDE CDROM and get PCI-X instad of PCI which changes the topology radically. Libvirt promises to isolate applications from hypervisor changes that may cause incompatibilities, so we must ensure that we always use the "pc" machine type if it is available. Only use QEMU's own reported default machine type if "pc" does not exist. Note this change assumes there will always be a "pc" alias as long as a versioned "pc-XXX" machine type exists. If QEMU were to ship a "pc-XXX" machine type but not provide the "pc" alias, it is too hard to decide which to default so. Versioned machine types are supposed to be considered opaque strings, so we can't apply any sensible ordering ourselves and QEMU isn't reporting the list of machines in any sensible ordering itself. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_capabilities.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 0fb800589a..9eb58afef3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2242,6 +2242,17 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuC= aps, int ret =3D -1; size_t i; size_t defIdx =3D 0; + ssize_t preferredIdx =3D -1; + const char *preferredAlias =3D NULL; + + /* Historically QEMU defaulted to 'pc' machine type but in + * future might switch 'q35'. Such a change is considered + * an ABI break from lbivirt's POV, so we must be sure to + * keep 'pc' as default machine no matter what QEMU says. + */ + if (qemuCaps->arch =3D=3D VIR_ARCH_X86_64 || + qemuCaps->arch =3D=3D VIR_ARCH_I686) + preferredAlias =3D "pc"; =20 if ((nmachines =3D qemuMonitorGetMachines(mon, &machines)) < 0) return -1; @@ -2263,12 +2274,16 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemu= Caps, mach->maxCpus =3D machines[i]->maxCpus; mach->hotplugCpus =3D machines[i]->hotplugCpus; =20 + if (STREQ_NULLABLE(mach->alias, preferredAlias)) + preferredIdx =3D qemuCaps->nmachineTypes - 1; + if (machines[i]->isDefault) defIdx =3D qemuCaps->nmachineTypes - 1; } =20 - if (defIdx) - virQEMUCapsSetDefaultMachine(qemuCaps, defIdx); + if (preferredIdx =3D=3D -1) + preferredIdx =3D defIdx; + virQEMUCapsSetDefaultMachine(qemuCaps, preferredIdx); =20 ret =3D 0; =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list