From nobody Wed May 14 15:52:41 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 1523477480198550.418928469838; Wed, 11 Apr 2018 13:11:20 -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 D361930B8F91; Wed, 11 Apr 2018 20:11:18 +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 9BFD46E6EF; Wed, 11 Apr 2018 20:11:18 +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 21D7E18033EB; Wed, 11 Apr 2018 20:11:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3BKBGxh019384 for ; Wed, 11 Apr 2018 16:11:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id D01CE65935; Wed, 11 Apr 2018 20:11:16 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DD73895B3 for ; Wed, 11 Apr 2018 20:11:14 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 11 Apr 2018 16:10:03 -0400 Message-Id: <20180411201005.14749-9-jferlan@redhat.com> In-Reply-To: <20180411201005.14749-1-jferlan@redhat.com> References: <20180411201005.14749-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/10] 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.49]); Wed, 11 Apr 2018 20:11:19 +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 56ac64630f..c417680dac 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6611,7 +6611,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) { @@ -15873,6 +15874,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 @@ -15886,10 +15888,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) { @@ -15972,7 +15983,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, @@ -16058,7 +16070,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 f02114c693..20fcdf7f26 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5882,6 +5882,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. @@ -5933,7 +6034,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 @@ -5957,6 +6059,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), @@ -6317,7 +6422,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 2741115673..30a73ff3f1 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -78,6 +78,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