From nobody Wed Dec 17 04:16:59 2025 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 1524528085314340.36183200733194; Mon, 23 Apr 2018 17:01:25 -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 3745A31524D5; Tue, 24 Apr 2018 00:01:21 +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 B0F2F77440; Tue, 24 Apr 2018 00:01:20 +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 9949A180596F; Tue, 24 Apr 2018 00:01:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3O00dgf001177 for ; Mon, 23 Apr 2018 20:00:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 261F618A6F; Tue, 24 Apr 2018 00:00:39 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5B2418A67 for ; Tue, 24 Apr 2018 00:00:38 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 23 Apr 2018 20:00:02 -0400 Message-Id: <20180424000005.689-9-jferlan@redhat.com> In-Reply-To: <20180424000005.689-1-jferlan@redhat.com> References: <20180424000005.689-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 08/11] qemu: Handle genid processing during startup/launch 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-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.41]); Tue, 24 Apr 2018 00:01:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Before we generate the command line for qemu, if the domain about to be launched desires to utilize the VM Generation ID functionality, then handle both the regenerating the GUID value for backup recovery (restore operation) and the startup after snapshot as well as checking that the genid value that's about to be placed on the command line doesn't duplicate some other already running domain. Signed-off-by: John Ferlan --- src/qemu/qemu_driver.c | 22 +++++++--- src/qemu/qemu_process.c | 110 ++++++++++++++++++++++++++++++++++++++++++++= +++- src/qemu/qemu_process.h | 1 + 3 files changed, 126 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bfb7973100..ee242720dc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6591,7 +6591,8 @@ qemuDomainSaveImageStartVM(virConnectPtr conn, if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, asyncJob, "stdio", *fd, path, NULL, VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, - VIR_QEMU_PROCESS_START_PAUSED) =3D=3D 0) + VIR_QEMU_PROCESS_START_PAUSED | + VIR_QEMU_PROCESS_START_GEN_VMID) =3D=3D 0) restored =3D true; =20 if (intermediatefd !=3D -1) { @@ -15881,6 +15882,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, * the migratable XML or it will always fail otherwise */ if (config) { bool compatible; + bool abiflags =3D VIR_DOMAIN_DEF_ABI_CHECK_SKIP_GENID; =20 /* Replace the CPU in config and put the original one in p= riv * once we're done. When we have the updated CPU def in the @@ -15894,10 +15896,19 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr s= napshot, goto endjob; =20 compatible =3D qemuDomainDefCheckABIStability(driver, = vm->def, - config, 0); + config, ab= iflags); } else { compatible =3D qemuDomainCheckABIStability(driver, vm,= config, - 0); + abiflags); + } + + /* If using VM GenID, there is no way currently to change + * the genid for the running guest, so set an error and + * mark as incompatible. */ + if (compatible && config->genidRequested) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("domain genid update requires restart= ")); + compatible =3D false; } =20 if (!compatible) { @@ -15980,7 +15991,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, cookie ? cookie->cpu : NULL, QEMU_ASYNC_JOB_START, NULL, -1, NULL, sn= ap, VIR_NETDEV_VPORT_PROFILE_OP_CREATE, - VIR_QEMU_PROCESS_START_PAUSED); + VIR_QEMU_PROCESS_START_PAUSED | + VIR_QEMU_PROCESS_START_GEN_VMID); virDomainAuditStart(vm, "from-snapshot", rc >=3D 0); detail =3D VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT; event =3D virDomainEventLifecycleNewFromObj(vm, @@ -16066,7 +16078,7 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) { /* Flush first event, now do transition 2 or 3 */ bool paused =3D (flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED) != =3D 0; - unsigned int start_flags =3D 0; + unsigned int start_flags =3D VIR_QEMU_PROCESS_START_GEN_VMID; =20 start_flags |=3D paused ? VIR_QEMU_PROCESS_START_PAUSED : 0; =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 6a5262ae46..06ec4ddeb9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5880,6 +5880,107 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, =20 =20 /** + * qemuProcessCheckGenID: + * @vm: Domain to be checked + * @opaque: Domain about to be started + * + * For each running domain, let's make sure the domain to be started doesn= 't + * duplicate any running domain's genid GUID value + * + * Returns 0 on success, -1 on failure w/ error message set + */ +static int +qemuProcessCheckGenID(virDomainObjPtr vm, + void *opaque) +{ + int ret =3D 0; + virDomainObjPtr startvm =3D opaque; + + /* Ignore ourselves as we're already locked */ + if (vm =3D=3D startvm) + return 0; + + virObjectLock(vm); + + if (!virDomainObjIsActive(vm)) + goto cleanup; + + if (!vm->def->genidRequested) + goto cleanup; + + if (memcmp(startvm->def->genid, vm->def->genid, VIR_UUID_BUFLEN) =3D= =3D 0) { + /* For a generated value, just change it. Perhaps a result of + * not using virDomainDefCopy which generates a new genid when + * def->genidRequested is true. */ + if (startvm->def->genidGenerated) { + if (virUUIDGenerate(startvm->def->genid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to regenerate genid")); + ret =3D -1; + } + } else { + char guidstr[VIR_UUID_STRING_BUFLEN]; + + virUUIDFormat(startvm->def->genid, guidstr); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("domain '%s' already running with genid '%s'"= ), + vm->def->name, guidstr); + ret =3D -1; + } + goto cleanup; + } + + cleanup: + virObjectUnlock(vm); + return ret; +} + + +/** + * qemuProcessGenID: + * @driver: Pointer to driver + * @vm: Pointer to domain object + * @flags: qemuProcessStartFlags + * + * If this domain is requesting to use genid + */ +static int +qemuProcessGenID(virQEMUDriverPtr driver, + virDomainObjPtr vm, + unsigned int flags) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + if (!vm->def->genidRequested) + return 0; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VMGENID)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this QEMU does not support the 'genid' capability= ")); + return -1; + } + + /* If we are coming from a path where we must provide a new gen id + * value regardless of whether it was previously generated or provided, + * then generate a new GUID value before we build the command line. */ + if (flags & VIR_QEMU_PROCESS_START_GEN_VMID) { + if (virUUIDGenerate(vm->def->genid)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to regenerate genid")); + return -1; + } + } + + /* Now let's make sure the genid this domain has is not duplicitous + * with something else running. */ + if (virDomainObjListForEach(driver->domains, qemuProcessCheckGenID, vm= ) < 0) + return -1; + + return 0; +} + + +/** * qemuProcessLaunch: * * Launch a new QEMU process with stopped virtual CPUs. @@ -5931,7 +6032,8 @@ qemuProcessLaunch(virConnectPtr conn, virCheckFlags(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | VIR_QEMU_PROCESS_START_AUTODESTROY | - VIR_QEMU_PROCESS_START_NEW, -1); + VIR_QEMU_PROCESS_START_NEW | + VIR_QEMU_PROCESS_START_GEN_VMID, -1); =20 cfg =3D virQEMUDriverGetConfig(driver); =20 @@ -5955,6 +6057,9 @@ qemuProcessLaunch(virConnectPtr conn, goto cleanup; logfile =3D qemuDomainLogContextGetWriteFD(logCtxt); =20 + if (qemuProcessGenID(driver, vm, flags) < 0) + goto cleanup; + VIR_DEBUG("Building emulator command line"); if (!(cmd =3D qemuBuildCommandLine(driver, qemuDomainLogContextGetManager(logCtx= t), @@ -6315,7 +6420,8 @@ qemuProcessStart(virConnectPtr conn, =20 virCheckFlagsGoto(VIR_QEMU_PROCESS_START_COLD | VIR_QEMU_PROCESS_START_PAUSED | - VIR_QEMU_PROCESS_START_AUTODESTROY, cleanup); + VIR_QEMU_PROCESS_START_AUTODESTROY | + VIR_QEMU_PROCESS_START_GEN_VMID, cleanup); =20 if (!migrateFrom && !snapshot) flags |=3D VIR_QEMU_PROCESS_START_NEW; diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 9dd5c97642..0ebe4cdf2d 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -79,6 +79,7 @@ typedef enum { VIR_QEMU_PROCESS_START_AUTODESTROY =3D 1 << 2, VIR_QEMU_PROCESS_START_PRETEND =3D 1 << 3, VIR_QEMU_PROCESS_START_NEW =3D 1 << 4, /* internal, new VM is= starting */ + VIR_QEMU_PROCESS_START_GEN_VMID =3D 1 << 5, /* Generate a new VMID= */ } qemuProcessStartFlags; =20 int qemuProcessStart(virConnectPtr conn, --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list