From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272365; cv=none; d=zohomail.com; s=zohoarc; b=jXIVtduxXlm81tHpb3U5n8fK94c8Ef5eZ2+RLOaa2vBq49cOWZmE1/Hsc1CKrf3W0QZRApoAsZ6QczyEEDXVzZBvdDzvd5eILW3UcEqHB7YI6IYGain6pr5p6IuyhbTWH+FKPYZYS/KTdLbxii41cUIEWt6KeBmty+OkKuHcy/I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272365; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=z29zmpxz0XecfW3bV/jWKGLIHh7GnV7SqbQcjUILZdk=; b=ZK9q4c86VS02yHSjmm/iNcrI86LGEplgFY9Sqkzs7ahf1rKdh92V7cEXdUiHl4DhAnOeVXVpHeAQKG3bJiR0ulqPdL/4l581ozvUArZLmg8gbnHTEi/sXGyyKj0G3NpxQBki5jeh33eERDzerZocVr11GaM01tQhx6M8a8wVHQA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272365548821.5397102268864; Tue, 23 Aug 2022 09:32:45 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-56-4RRcXNSqMKOVHMUWRscs7g-1; Tue, 23 Aug 2022 12:32:40 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA0833C0F368; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92CE71415137; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 76BEF1946A47; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CE6FB1946A40 for ; Tue, 23 Aug 2022 16:32:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BE519403349; Tue, 23 Aug 2022 16:32:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40079492C3B for ; Tue, 23 Aug 2022 16:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272364; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=z29zmpxz0XecfW3bV/jWKGLIHh7GnV7SqbQcjUILZdk=; b=ge4MNMUBMkq52Zkk6YaL/zpLHa3uvra8Z+ktJVlq/XXKYiO0kL+NTGxkhkjuBnn5qcS6Ei w+HHLbyV5w6xbARmRW6cWCXjjfARxAsE/2S8+TWtDkU6ubbcuY7/iBZzSN0Biwesr1Uq7e KqkiaD9eeXB9qIYGzNLVQCgyLa1qZlM= X-MC-Unique: 4RRcXNSqMKOVHMUWRscs7g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 01/24] qemu_block: extract block commit code to separate function Date: Tue, 23 Aug 2022 18:32:04 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272367322100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_block.c | 197 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 9 ++ src/qemu/qemu_driver.c | 181 +------------------------------------ 3 files changed, 207 insertions(+), 180 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index b82e3311e1..c0c4088cbf 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3201,3 +3201,200 @@ qemuBlockExportAddNBD(virDomainObj *vm, =20 return qemuMonitorBlockExportAdd(priv->mon, &nbdprops); } + + +int +qemuBlockCommit(virDomainObj *vm, + virQEMUDriver *driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + int rc =3D -1; + virDomainDiskDef *disk =3D NULL; + virStorageSource *topSource; + virStorageSource *baseSource =3D NULL; + virStorageSource *top_parent =3D NULL; + bool clean_access =3D false; + g_autofree char *backingPath =3D NULL; + qemuBlockJobData *job =3D NULL; + g_autoptr(virStorageSource) mirror =3D NULL; + + if (virDomainObjCheckActive(vm) < 0) + return -1; + + /* Convert bandwidth MiB to bytes, if necessary */ + if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { + if (bandwidth > LLONG_MAX >> 20) { + virReportError(VIR_ERR_OVERFLOW, + _("bandwidth must be less than %llu"), + LLONG_MAX >> 20); + return -1; + } + bandwidth <<=3D 20; + } + + if (!(disk =3D qemuDomainDiskByName(vm->def, path))) + return -1; + + if (!qemuDomainDiskBlockJobIsSupported(disk)) + return -1; + + if (virStorageSourceIsEmpty(disk->src)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk %s has no source file to be committed"), + disk->dst); + return -1; + } + + if (qemuDomainDiskBlockJobIsActive(disk)) + return -1; + + if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) + return -1; + + if (!top || STREQ(top, disk->dst)) + topSource =3D disk->src; + else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, + disk->dst, &top_par= ent))) + return -1; + + if (topSource =3D=3D disk->src) { + /* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */ + if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)) { + virReportError(VIR_ERR_INVALID_ARG, + _("commit of '%s' active layer requires active = flag"), + disk->dst); + return -1; + } + } else if (flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) { + virReportError(VIR_ERR_INVALID_ARG, + _("active commit requested but '%s' is not active"), + topSource->path); + return -1; + } + + if (!virStorageSourceHasBacking(topSource)) { + virReportError(VIR_ERR_INVALID_ARG, + _("top '%s' in chain for '%s' has no backing file"), + topSource->path, path); + return -1; + } + + if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) + baseSource =3D topSource->backingStore; + else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, + base, disk->dst, N= ULL))) + return -1; + + if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && + baseSource !=3D topSource->backingStore) { + virReportError(VIR_ERR_INVALID_ARG, + _("base '%s' is not immediately below '%s' in chain= " + "for '%s'"), + base, topSource->path, path); + return -1; + } + + /* For an active commit, clone enough of the base to act as the mirror= */ + if (topSource =3D=3D disk->src) { + if (!(mirror =3D virStorageSourceCopy(baseSource, false))) + return -1; + if (virStorageSourceInitChainElement(mirror, + disk->src, + true) < 0) + return -1; + } + + if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE && + topSource !=3D disk->src) { + if (top_parent && + qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0) + return -1; + + if (virStorageSourceGetRelativeBackingPath(topSource, baseSource, + &backingPath) < 0) + return -1; + + if (!backingPath) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("can't keep relative backing relationship")); + return -1; + } + } + + /* For the commit to succeed, we must allow qemu to open both the + * 'base' image and the parent of 'top' as read/write; 'top' might + * not have a parent, or might already be read-write. XXX It + * would also be nice to revert 'base' to read-only, as well as + * revoke access to files removed from the chain, when the commit + * operation succeeds, but doing that requires tracking the + * operation in XML across libvirtd restarts. */ + clean_access =3D true; + if (qemuDomainStorageSourceAccessAllow(driver, vm, baseSource, + false, false, false) < 0) + goto error; + + if (top_parent && top_parent !=3D disk->src) { + /* While top_parent is topmost image, we don't need to remember its + * owner as it will be overwritten upon finishing the commit. Henc= e, + * pass chainTop =3D false. */ + if (qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, + false, false, false) < 0) + goto error; + } + + if (!(job =3D qemuBlockJobDiskNewCommit(vm, disk, top_parent, topSourc= e, + baseSource, + flags & VIR_DOMAIN_BLOCK_COMMIT_= DELETE, + flags))) + goto error; + + disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; + + if (!backingPath && top_parent && + !(backingPath =3D qemuBlockGetBackingStoreString(baseSource, false= ))) + goto error; + + qemuDomainObjEnterMonitor(vm); + + rc =3D qemuMonitorBlockCommit(priv->mon, + qemuDomainDiskGetTopNodename(disk), + job->name, + topSource->nodeformat, + baseSource->nodeformat, + backingPath, bandwidth); + + qemuDomainObjExitMonitor(vm); + + if (rc < 0) + goto error; + + if (mirror) { + disk->mirror =3D g_steal_pointer(&mirror); + disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT; + } + qemuBlockJobStarted(job, vm); + + return 0; + + error: + if (clean_access) { + virErrorPtr orig_err; + virErrorPreserveLast(&orig_err); + /* Revert access to read-only, if possible. */ + qemuDomainStorageSourceAccessAllow(driver, vm, baseSource, + true, false, false); + if (top_parent && top_parent !=3D disk->src) + qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, + true, false, false); + + virErrorRestore(&orig_err); + } + qemuBlockJobStartupFinalize(vm, job); + + return -1; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 8a3a10344e..be81ec3c7f 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -276,3 +276,12 @@ qemuBlockExportAddNBD(virDomainObj *vm, const char *exportname, bool writable, const char *bitmap); + +int +qemuBlockCommit(virDomainObj *vm, + virQEMUDriver *driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 707f4cc1bb..d353b6df93 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15375,18 +15375,8 @@ qemuDomainBlockCommit(virDomainPtr dom, unsigned int flags) { virQEMUDriver *driver =3D dom->conn->privateData; - qemuDomainObjPrivate *priv; virDomainObj *vm =3D NULL; int ret =3D -1; - virDomainDiskDef *disk =3D NULL; - virStorageSource *topSource; - virStorageSource *baseSource =3D NULL; - virStorageSource *top_parent =3D NULL; - bool clean_access =3D false; - g_autofree char *backingPath =3D NULL; - unsigned long long speed =3D bandwidth; - qemuBlockJobData *job =3D NULL; - g_autoptr(virStorageSource) mirror =3D NULL; =20 virCheckFlags(VIR_DOMAIN_BLOCK_COMMIT_SHALLOW | VIR_DOMAIN_BLOCK_COMMIT_ACTIVE | @@ -15396,7 +15386,6 @@ qemuDomainBlockCommit(virDomainPtr dom, =20 if (!(vm =3D qemuDomainObjFromDomain(dom))) goto cleanup; - priv =3D vm->privateData; =20 if (virDomainBlockCommitEnsureACL(dom->conn, vm->def) < 0) goto cleanup; @@ -15404,176 +15393,8 @@ qemuDomainBlockCommit(virDomainPtr dom, if (qemuDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) goto cleanup; =20 - if (virDomainObjCheckActive(vm) < 0) - goto endjob; + ret =3D qemuBlockCommit(vm, driver, path, base, top, bandwidth, flags); =20 - /* Convert bandwidth MiB to bytes, if necessary */ - if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { - if (speed > LLONG_MAX >> 20) { - virReportError(VIR_ERR_OVERFLOW, - _("bandwidth must be less than %llu"), - LLONG_MAX >> 20); - goto endjob; - } - speed <<=3D 20; - } - - if (!(disk =3D qemuDomainDiskByName(vm->def, path))) - goto endjob; - - if (!qemuDomainDiskBlockJobIsSupported(disk)) - goto endjob; - - if (virStorageSourceIsEmpty(disk->src)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk %s has no source file to be committed"), - disk->dst); - goto endjob; - } - - if (qemuDomainDiskBlockJobIsActive(disk)) - goto endjob; - - if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) - goto endjob; - - if (!top || STREQ(top, disk->dst)) - topSource =3D disk->src; - else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, - disk->dst, &top_par= ent))) - goto endjob; - - if (topSource =3D=3D disk->src) { - /* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */ - if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)) { - virReportError(VIR_ERR_INVALID_ARG, - _("commit of '%s' active layer requires active = flag"), - disk->dst); - goto endjob; - } - } else if (flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) { - virReportError(VIR_ERR_INVALID_ARG, - _("active commit requested but '%s' is not active"), - topSource->path); - goto endjob; - } - - if (!virStorageSourceHasBacking(topSource)) { - virReportError(VIR_ERR_INVALID_ARG, - _("top '%s' in chain for '%s' has no backing file"), - topSource->path, path); - goto endjob; - } - - if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) - baseSource =3D topSource->backingStore; - else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, - base, disk->dst, N= ULL))) - goto endjob; - - if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && - baseSource !=3D topSource->backingStore) { - virReportError(VIR_ERR_INVALID_ARG, - _("base '%s' is not immediately below '%s' in chain= " - "for '%s'"), - base, topSource->path, path); - goto endjob; - } - - /* For an active commit, clone enough of the base to act as the mirror= */ - if (topSource =3D=3D disk->src) { - if (!(mirror =3D virStorageSourceCopy(baseSource, false))) - goto endjob; - if (virStorageSourceInitChainElement(mirror, - disk->src, - true) < 0) - goto endjob; - } - - if (flags & VIR_DOMAIN_BLOCK_COMMIT_RELATIVE && - topSource !=3D disk->src) { - if (top_parent && - qemuBlockUpdateRelativeBacking(vm, top_parent, disk->src) < 0) - goto endjob; - - if (virStorageSourceGetRelativeBackingPath(topSource, baseSource, - &backingPath) < 0) - goto endjob; - - if (!backingPath) { - virReportError(VIR_ERR_OPERATION_INVALID, "%s", - _("can't keep relative backing relationship")); - goto endjob; - } - } - - /* For the commit to succeed, we must allow qemu to open both the - * 'base' image and the parent of 'top' as read/write; 'top' might - * not have a parent, or might already be read-write. XXX It - * would also be nice to revert 'base' to read-only, as well as - * revoke access to files removed from the chain, when the commit - * operation succeeds, but doing that requires tracking the - * operation in XML across libvirtd restarts. */ - clean_access =3D true; - if (qemuDomainStorageSourceAccessAllow(driver, vm, baseSource, - false, false, false) < 0) - goto endjob; - - if (top_parent && top_parent !=3D disk->src) { - /* While top_parent is topmost image, we don't need to remember its - * owner as it will be overwritten upon finishing the commit. Henc= e, - * pass chainTop =3D false. */ - if (qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, - false, false, false) < 0) - goto endjob; - } - - if (!(job =3D qemuBlockJobDiskNewCommit(vm, disk, top_parent, topSourc= e, - baseSource, - flags & VIR_DOMAIN_BLOCK_COMMIT_= DELETE, - flags))) - goto endjob; - - disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; - - if (!backingPath && top_parent && - !(backingPath =3D qemuBlockGetBackingStoreString(baseSource, false= ))) - goto endjob; - - qemuDomainObjEnterMonitor(vm); - - ret =3D qemuMonitorBlockCommit(priv->mon, - qemuDomainDiskGetTopNodename(disk), - job->name, - topSource->nodeformat, - baseSource->nodeformat, - backingPath, speed); - - qemuDomainObjExitMonitor(vm); - - if (ret < 0) - goto endjob; - - if (mirror) { - disk->mirror =3D g_steal_pointer(&mirror); - disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT; - } - qemuBlockJobStarted(job, vm); - - endjob: - if (ret < 0 && clean_access) { - virErrorPtr orig_err; - virErrorPreserveLast(&orig_err); - /* Revert access to read-only, if possible. */ - qemuDomainStorageSourceAccessAllow(driver, vm, baseSource, - true, false, false); - if (top_parent && top_parent !=3D disk->src) - qemuDomainStorageSourceAccessAllow(driver, vm, top_parent, - true, false, false); - - virErrorRestore(&orig_err); - } - qemuBlockJobStartupFinalize(vm, job); qemuDomainObjEndJob(vm); =20 cleanup: --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272392; cv=none; d=zohomail.com; s=zohoarc; b=TT9YSR8nHnpo3lJ2J2i8JyVOtXYDMff1s41jAI2mA9cdKeMFMFf/aM3qqYZouPsyy6ZdrL5ZJy9s/nksjx6z3EpnpwaapJsDk5D4sfG29D0BOK1tU5S7ymB0MJicLAVzOGa+RnRVDLddmxT+kVoLg2ouQRWocg6QI2mGiseVjiY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272392; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u95g1TXMobQtyts0+sAq5YcMYR2YcW2fs7WAWp7csOg=; b=aQD7Lefm8HZC9bGkTs0f1y5Q8OKydMnffPxgh9qLPy4Y+wDsmcz8wfOElV717ySuGiCzLKo/PQb7QUAH6wzlCzRfv3v/3TpLoyjcD8hlc4ycoR6OFVcNmqqPBlmyIPQZv264fGV2Ot/TldGQ+vsXMxByoV+DcITIY4S4P6ssL/4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272392928855.8907030855283; Tue, 23 Aug 2022 09:33:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-126--5z7eumINVW9FXSkkKu6PQ-1; Tue, 23 Aug 2022 12:32:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0398F3C0F394; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB1804010FA4; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B64E81946A63; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 728421946A40 for ; Tue, 23 Aug 2022 16:32:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 67587403349; Tue, 23 Aug 2022 16:32:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08273492C3B for ; Tue, 23 Aug 2022 16:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272391; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u95g1TXMobQtyts0+sAq5YcMYR2YcW2fs7WAWp7csOg=; b=S7sh73rf5sq4GvaxlBby1PSmJham/dBfQStX26uv5vdazl9ePqHKlwYjENsnPagWgXiE+S ZuARQFEFr7FWDM66jCorS/C95AWSdgYKKhqjSJuqDl8TFPNRCYsejVaHagx7Ed4QC6PfKk mxYOiAHaDBjdj5tFdBq7TsLA4Wpgomg= X-MC-Unique: -5z7eumINVW9FXSkkKu6PQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 02/24] qemu_block: move qemuDomainBlockPivot out of qemu_driver Date: Tue, 23 Aug 2022 18:32:05 +0200 Message-Id: <4c1b269720ae850f5deea1531473c193149bdc96.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272393523100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_block.c | 121 ++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 5 ++ src/qemu/qemu_driver.c | 123 +---------------------------------------- 3 files changed, 127 insertions(+), 122 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index c0c4088cbf..5b34461853 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3398,3 +3398,124 @@ qemuBlockCommit(virDomainObj *vm, =20 return -1; } + + +/* Called while holding the VM job lock, to implement a block job + * abort with pivot; this updates the VM definition as appropriate, on + * either success or failure. */ +int +qemuBlockPivot(virDomainObj *vm, + qemuBlockJobData *job, + virDomainDiskDef *disk) +{ + g_autoptr(qemuBlockStorageSourceChainData) chainattachdata =3D NULL; + int ret =3D -1; + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virJSONValue) bitmapactions =3D NULL; + g_autoptr(virJSONValue) reopenactions =3D NULL; + int rc =3D 0; + + if (job->state !=3D QEMU_BLOCKJOB_STATE_READY) { + virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, + _("block job '%s' not ready for pivot yet"), + job->name); + return -1; + } + + switch ((qemuBlockJobType) job->type) { + case QEMU_BLOCKJOB_TYPE_NONE: + case QEMU_BLOCKJOB_TYPE_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid job type '%d'"), job->type); + return -1; + + case QEMU_BLOCKJOB_TYPE_PULL: + case QEMU_BLOCKJOB_TYPE_COMMIT: + case QEMU_BLOCKJOB_TYPE_BACKUP: + case QEMU_BLOCKJOB_TYPE_INTERNAL: + case QEMU_BLOCKJOB_TYPE_CREATE: + case QEMU_BLOCKJOB_TYPE_BROKEN: + virReportError(VIR_ERR_OPERATION_INVALID, + _("job type '%s' does not support pivot"), + qemuBlockjobTypeToString(job->type)); + return -1; + + case QEMU_BLOCKJOB_TYPE_COPY: + if (!job->jobflagsmissing) { + bool shallow =3D job->jobflags & VIR_DOMAIN_BLOCK_COPY_SHALLOW; + bool reuse =3D job->jobflags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT; + + bitmapactions =3D virJSONValueNewArray(); + + if (qemuMonitorTransactionBitmapAdd(bitmapactions, + disk->mirror->nodeformat, + "libvirt-tmp-activewrite", + false, + false, + 0) < 0) + return -1; + + /* Open and install the backing chain of 'mirror' late if we c= an use + * blockdev-snapshot to do it. This is to appease oVirt that w= ants + * to copy data into the backing chain while the top image is = being + * copied shallow */ + if (reuse && shallow && + virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_SNAPSHOT= _ALLOW_WRITE_ONLY) && + virStorageSourceHasBacking(disk->mirror)) { + + if (!(chainattachdata =3D qemuBuildStorageSourceChainAttac= hPrepareBlockdev(disk->mirror->backingStore))) + return -1; + + reopenactions =3D virJSONValueNewArray(); + + if (qemuMonitorTransactionSnapshotBlockdev(reopenactions, + disk->mirror->b= ackingStore->nodeformat, + disk->mirror->n= odeformat)) + return -1; + } + + } + break; + + case QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT: + bitmapactions =3D virJSONValueNewArray(); + + if (qemuMonitorTransactionBitmapAdd(bitmapactions, + job->data.commit.base->nodefor= mat, + "libvirt-tmp-activewrite", + false, + false, + 0) < 0) + return -1; + + break; + } + + qemuDomainObjEnterMonitor(vm); + + if (chainattachdata) { + if ((rc =3D qemuBlockStorageSourceChainAttach(priv->mon, chainatta= chdata)) =3D=3D 0) { + /* install backing images on success, or unplug them on failur= e */ + if ((rc =3D qemuMonitorTransaction(priv->mon, &reopenactions))= !=3D 0) + qemuBlockStorageSourceChainDetach(priv->mon, chainattachda= ta); + } + } + + if (bitmapactions && rc =3D=3D 0) + ignore_value(qemuMonitorTransaction(priv->mon, &bitmapactions)); + + if (rc =3D=3D 0) + ret =3D qemuMonitorJobComplete(priv->mon, job->name); + + qemuDomainObjExitMonitor(vm); + + /* The pivot failed. The block job in QEMU remains in the synchronised= state */ + if (ret < 0) + return -1; + + if (disk && disk->mirror) + disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT; + job->state =3D QEMU_BLOCKJOB_STATE_PIVOTING; + + return ret; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index be81ec3c7f..d4b564e177 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -285,3 +285,8 @@ qemuBlockCommit(virDomainObj *vm, const char *top, unsigned long bandwidth, unsigned int flags); + +int +qemuBlockPivot(virDomainObj *vm, + qemuBlockJobData *job, + virDomainDiskDef *disk); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d353b6df93..564648f9ac 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14261,127 +14261,6 @@ qemuDomainOpenChannel(virDomainPtr dom, } =20 =20 -/* Called while holding the VM job lock, to implement a block job - * abort with pivot; this updates the VM definition as appropriate, on - * either success or failure. */ -static int -qemuDomainBlockPivot(virDomainObj *vm, - qemuBlockJobData *job, - virDomainDiskDef *disk) -{ - g_autoptr(qemuBlockStorageSourceChainData) chainattachdata =3D NULL; - int ret =3D -1; - qemuDomainObjPrivate *priv =3D vm->privateData; - g_autoptr(virJSONValue) bitmapactions =3D NULL; - g_autoptr(virJSONValue) reopenactions =3D NULL; - int rc =3D 0; - - if (job->state !=3D QEMU_BLOCKJOB_STATE_READY) { - virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, - _("block job '%s' not ready for pivot yet"), - job->name); - return -1; - } - - switch ((qemuBlockJobType) job->type) { - case QEMU_BLOCKJOB_TYPE_NONE: - case QEMU_BLOCKJOB_TYPE_LAST: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid job type '%d'"), job->type); - return -1; - - case QEMU_BLOCKJOB_TYPE_PULL: - case QEMU_BLOCKJOB_TYPE_COMMIT: - case QEMU_BLOCKJOB_TYPE_BACKUP: - case QEMU_BLOCKJOB_TYPE_INTERNAL: - case QEMU_BLOCKJOB_TYPE_CREATE: - case QEMU_BLOCKJOB_TYPE_BROKEN: - virReportError(VIR_ERR_OPERATION_INVALID, - _("job type '%s' does not support pivot"), - qemuBlockjobTypeToString(job->type)); - return -1; - - case QEMU_BLOCKJOB_TYPE_COPY: - if (!job->jobflagsmissing) { - bool shallow =3D job->jobflags & VIR_DOMAIN_BLOCK_COPY_SHALLOW; - bool reuse =3D job->jobflags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT; - - bitmapactions =3D virJSONValueNewArray(); - - if (qemuMonitorTransactionBitmapAdd(bitmapactions, - disk->mirror->nodeformat, - "libvirt-tmp-activewrite", - false, - false, - 0) < 0) - return -1; - - /* Open and install the backing chain of 'mirror' late if we c= an use - * blockdev-snapshot to do it. This is to appease oVirt that w= ants - * to copy data into the backing chain while the top image is = being - * copied shallow */ - if (reuse && shallow && - virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_SNAPSHOT= _ALLOW_WRITE_ONLY) && - virStorageSourceHasBacking(disk->mirror)) { - - if (!(chainattachdata =3D qemuBuildStorageSourceChainAttac= hPrepareBlockdev(disk->mirror->backingStore))) - return -1; - - reopenactions =3D virJSONValueNewArray(); - - if (qemuMonitorTransactionSnapshotBlockdev(reopenactions, - disk->mirror->b= ackingStore->nodeformat, - disk->mirror->n= odeformat)) - return -1; - } - - } - break; - - case QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT: - bitmapactions =3D virJSONValueNewArray(); - - if (qemuMonitorTransactionBitmapAdd(bitmapactions, - job->data.commit.base->nodefor= mat, - "libvirt-tmp-activewrite", - false, - false, - 0) < 0) - return -1; - - break; - } - - qemuDomainObjEnterMonitor(vm); - - if (chainattachdata) { - if ((rc =3D qemuBlockStorageSourceChainAttach(priv->mon, chainatta= chdata)) =3D=3D 0) { - /* install backing images on success, or unplug them on failur= e */ - if ((rc =3D qemuMonitorTransaction(priv->mon, &reopenactions))= !=3D 0) - qemuBlockStorageSourceChainDetach(priv->mon, chainattachda= ta); - } - } - - if (bitmapactions && rc =3D=3D 0) - ignore_value(qemuMonitorTransaction(priv->mon, &bitmapactions)); - - if (rc =3D=3D 0) - ret =3D qemuMonitorJobComplete(priv->mon, job->name); - - qemuDomainObjExitMonitor(vm); - - /* The pivot failed. The block job in QEMU remains in the synchronised= state */ - if (ret < 0) - return -1; - - if (disk && disk->mirror) - disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT; - job->state =3D QEMU_BLOCKJOB_STATE_PIVOTING; - - return ret; -} - - /* bandwidth in MiB/s per public API. Caller must lock vm beforehand, * and not access it afterwards. */ static int @@ -14544,7 +14423,7 @@ qemuDomainBlockJobAbort(virDomainPtr dom, qemuBlockJobSyncBegin(job); =20 if (pivot) { - if ((ret =3D qemuDomainBlockPivot(vm, job, disk)) < 0) + if ((ret =3D qemuBlockPivot(vm, job, disk)) < 0) goto endjob; } else { qemuDomainObjEnterMonitor(vm); --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272390; cv=none; d=zohomail.com; s=zohoarc; b=a8RPvmmCdlkIHMSjBhMF3f9NiYI5K2Tf7LolFT8PzhPMB+sJgLt6Tqi5wayrhd5ZjR4AhtKP3A3AmMbGtGI5hO961VbNHRuJK1sFccnIHuxh/t7brGoMI2O17RxoFSkgd6muqNeR1RUbnMowbGGGVI6AOPnRtpEgIC5Efs/tyxA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272390; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=seGCeKehGFVzEtPhladpZXbM+vsayDwelHBM3qk29Js=; b=TNeGBZpxsvTchxwPiqpl7Iov2frlpnGwf5YRfYHBjNejJ8g1l/0N3iX/30ADQOqaJCGFlDZK20Ul4FejsqEXj4C1aPlIO0GA8Mx1QZvu/N6x/w9F2FFyYcSt0A2gZEL+jID/24HWpuXCZdXxJoET+XoSu6AuUwm37vEausXVWx0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272390851683.3304457371594; Tue, 23 Aug 2022 09:33:10 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-286-LXMQ3TKVOOGfGxOdDCNk5Q-1; Tue, 23 Aug 2022 12:32:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 502EC8037AF; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DB8D1121315; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 280D61946A58; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2A7A71946A40 for ; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0F9FC403349; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4AC8492C3B for ; Tue, 23 Aug 2022 16:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272388; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=seGCeKehGFVzEtPhladpZXbM+vsayDwelHBM3qk29Js=; b=UiqW3/jTBK78y8AC2sRXWUbetIE4XmkQ9V0vtsjZvr9LXW3uiSWZ+lTyMCwMoU+VySBrTj xlAL/90HS64apk5Igd0WVoU5RMrSLDWXomLIMLjOR4k1NPtiB+p+aamRbWIXnyY68BCaSb UkjPLH8Sjny3p9YZgZRa/Swql6RUANw= X-MC-Unique: LXMQ3TKVOOGfGxOdDCNk5Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 03/24] qemu_block: extract qemuBlockCommit impl to separate function Date: Tue, 23 Aug 2022 18:32:06 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272391466100005 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_block.c | 78 ++++++++++++++++++++++++++----------------- src/qemu/qemu_block.h | 10 ++++++ 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 5b34461853..902ec7b2a5 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3204,28 +3204,22 @@ qemuBlockExportAddNBD(virDomainObj *vm, =20 =20 int -qemuBlockCommit(virDomainObj *vm, - virQEMUDriver *driver, - const char *path, - const char *base, - const char *top, - unsigned long bandwidth, - unsigned int flags) +qemuBlockCommitImpl(virDomainObj *vm, + virQEMUDriver *driver, + virDomainDiskDef *disk, + virStorageSource *baseSource, + virStorageSource *topSource, + virStorageSource *top_parent, + unsigned long bandwidth, + unsigned int flags) { qemuDomainObjPrivate *priv =3D vm->privateData; int rc =3D -1; - virDomainDiskDef *disk =3D NULL; - virStorageSource *topSource; - virStorageSource *baseSource =3D NULL; - virStorageSource *top_parent =3D NULL; bool clean_access =3D false; g_autofree char *backingPath =3D NULL; qemuBlockJobData *job =3D NULL; g_autoptr(virStorageSource) mirror =3D NULL; =20 - if (virDomainObjCheckActive(vm) < 0) - return -1; - /* Convert bandwidth MiB to bytes, if necessary */ if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_BANDWIDTH_BYTES)) { if (bandwidth > LLONG_MAX >> 20) { @@ -3237,9 +3231,6 @@ qemuBlockCommit(virDomainObj *vm, bandwidth <<=3D 20; } =20 - if (!(disk =3D qemuDomainDiskByName(vm->def, path))) - return -1; - if (!qemuDomainDiskBlockJobIsSupported(disk)) return -1; =20 @@ -3256,12 +3247,6 @@ qemuBlockCommit(virDomainObj *vm, if (qemuDomainSupportsCheckpointsBlockjobs(vm) < 0) return -1; =20 - if (!top || STREQ(top, disk->dst)) - topSource =3D disk->src; - else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, - disk->dst, &top_par= ent))) - return -1; - if (topSource =3D=3D disk->src) { /* XXX Should we auto-pivot when COMMIT_ACTIVE is not specified? */ if (!(flags & VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)) { @@ -3280,22 +3265,16 @@ qemuBlockCommit(virDomainObj *vm, if (!virStorageSourceHasBacking(topSource)) { virReportError(VIR_ERR_INVALID_ARG, _("top '%s' in chain for '%s' has no backing file"), - topSource->path, path); + topSource->path, disk->src->path); return -1; } =20 - if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) - baseSource =3D topSource->backingStore; - else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, - base, disk->dst, N= ULL))) - return -1; - if ((flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW) && baseSource !=3D topSource->backingStore) { virReportError(VIR_ERR_INVALID_ARG, _("base '%s' is not immediately below '%s' in chain= " "for '%s'"), - base, topSource->path, path); + baseSource->path, topSource->path, disk->src->path); return -1; } =20 @@ -3400,6 +3379,43 @@ qemuBlockCommit(virDomainObj *vm, } =20 =20 +int +qemuBlockCommit(virDomainObj *vm, + virQEMUDriver *driver, + const char *path, + const char *base, + const char *top, + unsigned long bandwidth, + unsigned int flags) +{ + virDomainDiskDef *disk =3D NULL; + virStorageSource *topSource; + virStorageSource *baseSource =3D NULL; + virStorageSource *top_parent =3D NULL; + + if (virDomainObjCheckActive(vm) < 0) + return -1; + + if (!(disk =3D qemuDomainDiskByName(vm->def, path))) + return -1; + + if (!top || STREQ(top, disk->dst)) + topSource =3D disk->src; + else if (!(topSource =3D virStorageSourceChainLookup(disk->src, NULL, = top, + disk->dst, &top_par= ent))) + return -1; + + if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) + baseSource =3D topSource->backingStore; + else if (!(baseSource =3D virStorageSourceChainLookup(disk->src, topSo= urce, + base, disk->dst, N= ULL))) + return -1; + + return qemuBlockCommitImpl(vm, driver, disk, baseSource, topSource, + top_parent, bandwidth, flags); +} + + /* Called while holding the VM job lock, to implement a block job * abort with pivot; this updates the VM definition as appropriate, on * either success or failure. */ diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index d4b564e177..35f7718697 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -277,6 +277,16 @@ qemuBlockExportAddNBD(virDomainObj *vm, bool writable, const char *bitmap); =20 +int +qemuBlockCommitImpl(virDomainObj *vm, + virQEMUDriver *driver, + virDomainDiskDef *disk, + virStorageSource *baseSource, + virStorageSource *topSource, + virStorageSource *top_parent, + unsigned long bandwidth, + unsigned int flags); + int qemuBlockCommit(virDomainObj *vm, virQEMUDriver *driver, --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272401; cv=none; d=zohomail.com; s=zohoarc; b=CaC+gW0k/qP5Nq9x0lPymkIEW3xuQhx4IQO78LYZpcnGwwHSK9KjkG0Mt/D9uCbWBs5T50Vf3sfOZo2mHfKn932mJbMSAtvfMgawOaeEPZTEtHd8IEY0C4Fkkg8SUu7dGthhsa/7RiIkf4+LBKxeqqjyM7pUJMI6AEZ70Xzc3z4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272401; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K1rBEOrMu7mOml3RLwKD7hOogFJNj4aX6SLhvajF7wU=; b=bP2UIX4NuUtDdpbRkmU/9yA+R1OlFAVXmgGS55dYVJLuFdmlUgSMEgUcclOHymtI8BgdxzDN+5wmwD+YInliqHESnbHDC3YGcWSqoG8XaUT5ymWNIPAtfhCGyik0IKUi4f7jQayoip5sdswG8kKsIdorfxzw3vQ6GNmmjD8Sau0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272401351362.96183730488997; Tue, 23 Aug 2022 09:33:21 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-265-MwMBlZRfPmOwOqPeitTnKw-1; Tue, 23 Aug 2022 12:32:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC17F1044565; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B669B2166B29; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8B2421946A62; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B70E31946A64 for ; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AC12F492C3B; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CF6F40315A for ; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272399; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=K1rBEOrMu7mOml3RLwKD7hOogFJNj4aX6SLhvajF7wU=; b=SaU4+4FE31EYx+jsT2pUxxrGQ8yMwuFiRlNqMbPFwsAUjtZodio0J09oVm/H828pj9M88G 11rpnZb4anhIc/NVREeOFeVPHCd1U8cj/8jtvy9dwuJ75XlcGcM9jSXhDrrXPLkL30KOwR DnSfNK3RY5UaGKvkDONM8J1QTUuxHHg= X-MC-Unique: MwMBlZRfPmOwOqPeitTnKw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 04/24] qemu_block: add sync option to qemuBlockCommitImpl Date: Tue, 23 Aug 2022 18:32:07 +0200 Message-Id: <278717f62d05255d7c60bbb5a504a6709d6c2bbf.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272403534100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This will allow starting synchronous block commit job that will be used by snapshot delete code. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_block.c | 6 +++++- src/qemu/qemu_block.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 902ec7b2a5..bc46966d22 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3211,6 +3211,7 @@ qemuBlockCommitImpl(virDomainObj *vm, virStorageSource *topSource, virStorageSource *top_parent, unsigned long bandwidth, + bool sync, unsigned int flags) { qemuDomainObjPrivate *priv =3D vm->privateData; @@ -3338,6 +3339,9 @@ qemuBlockCommitImpl(virDomainObj *vm, !(backingPath =3D qemuBlockGetBackingStoreString(baseSource, false= ))) goto error; =20 + if (sync) + qemuBlockJobSyncBegin(job); + qemuDomainObjEnterMonitor(vm); =20 rc =3D qemuMonitorBlockCommit(priv->mon, @@ -3412,7 +3416,7 @@ qemuBlockCommit(virDomainObj *vm, return -1; =20 return qemuBlockCommitImpl(vm, driver, disk, baseSource, topSource, - top_parent, bandwidth, flags); + top_parent, bandwidth, false, flags); } =20 =20 diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 35f7718697..29b5ac9ea1 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -285,6 +285,7 @@ qemuBlockCommitImpl(virDomainObj *vm, virStorageSource *topSource, virStorageSource *top_parent, unsigned long bandwidth, + bool sync, unsigned int flags); =20 int --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272376; cv=none; d=zohomail.com; s=zohoarc; b=f6thH5J2Dd0sBwL/d/cZVfFYUIChsqNLTQLa/Ghl/cpu06MCgd7LcHCmd1czbuHH4rp87KQY2S8RpcfWuJ/0eHgIuf8aWJlIALDuD5ghpCxje5luQfDDg4ZAMHBjRzemCEZL+D6MKa6ZHZo4KbXTZnoD2Wji6Yl32O1vSPh0sXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272376; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+Ax4iisfFnvwAFaAJcIjjiYJtWZpPsMbD9UeUHI3Ahs=; b=fw4R7/OtRtO7piAZRLWPz7GnwMcEKBP/7pEPrsVVSW9HH5HRI1bukky5IwncwvDJtzXklZBet3dHqGrzRmVX2fmYMaYN78lemCJdXHO3t6XjtyIHzCwUbyQ2MjPFZDpevgNxEioubTVWov0L0HLCceLQHKQEQtjQ88DXdw3WvuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272376294117.94860593116255; Tue, 23 Aug 2022 09:32:56 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-sIALnrwCOiWACNxd0t3Q7w-1; Tue, 23 Aug 2022 12:32:45 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F28438173C0; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DCBE404C6ED; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 24C8D1946A47; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 64AA61946A40 for ; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 562BF40334B; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id E999E492C3B for ; Tue, 23 Aug 2022 16:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272375; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+Ax4iisfFnvwAFaAJcIjjiYJtWZpPsMbD9UeUHI3Ahs=; b=SY6qpJiwDPIsJto1l6VwYZM5FkcWgfhWstAYOk5MJW5YusFaT90R8nQkZUob+JujHg914G 0cFh6aZnq1xaKI7evxNU1lP+LCNleoFyJTWvdL7ad3+nxlkbsRFiciT89Y37ILaHTKVrOa Zmv1i8v9v/Kj5u34fa4c/FkNqVM1i9s= X-MC-Unique: sIALnrwCOiWACNxd0t3Q7w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 05/24] qemu_monitor: introduce qemuMonitorJobFinalize Date: Tue, 23 Aug 2022 18:32:08 +0200 Message-Id: <627358d83419b5ec49a0a44bae1921d1dfeef220.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272377313100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_monitor.c | 12 ++++++++++++ src/qemu/qemu_monitor.h | 5 +++++ src/qemu/qemu_monitor_json.c | 22 ++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 5 +++++ 4 files changed, 44 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index c2808c75a3..6279e75c68 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2930,6 +2930,18 @@ qemuMonitorJobDismiss(qemuMonitor *mon, } =20 =20 +int +qemuMonitorJobFinalize(qemuMonitor *mon, + const char *jobname) +{ + VIR_DEBUG("jobname=3D%s", jobname); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONJobFinalize(mon, jobname); +} + + int qemuMonitorJobComplete(qemuMonitor *mon, const char *jobname) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 63269e15bc..dc35aa52c3 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1029,6 +1029,11 @@ int qemuMonitorJobDismiss(qemuMonitor *mon, const char *jobname) ATTRIBUTE_NONNULL(2); =20 +int +qemuMonitorJobFinalize(qemuMonitor *mon, + const char *jobname) + ATTRIBUTE_NONNULL(2); + int qemuMonitorJobComplete(qemuMonitor *mon, const char *jobname) ATTRIBUTE_NONNULL(2); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 70fba50e6c..9d514bfacc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4410,6 +4410,28 @@ qemuMonitorJSONJobDismiss(qemuMonitor *mon, } =20 =20 +int +qemuMonitorJSONJobFinalize(qemuMonitor *mon, + const char *jobname) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("job-finalize", + "s:id", jobname, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONBlockJobError(cmd, reply, jobname) < 0) + return -1; + + return 0; +} + + int qemuMonitorJSONJobComplete(qemuMonitor *mon, const char *jobname) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index a53e6423df..37f76bcc0c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -373,6 +373,11 @@ qemuMonitorJSONJobDismiss(qemuMonitor *mon, const char *jobname) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +int +qemuMonitorJSONJobFinalize(qemuMonitor *mon, + const char *jobname) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + int qemuMonitorJSONJobComplete(qemuMonitor *mon, const char *jobname) --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272394; cv=none; d=zohomail.com; s=zohoarc; b=idq4oL1RQQM6wXzCeYHFkLC6yKZkcfHBhPaAgGqx6gZrs+3nS+33/yXuZsjtgilf1++PHdQeh9CwyszILZyZyeyd/f43eS0U6Zqn8sZCd+GyUDtnPIqVfO+3RYaJd5NireRqilUjWn48jNtiyDVchR0Eq45+iIES0I+MZd5SzyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272394; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RPLKQFvP4DPAtPTQ5UNr4Nn6/fE2kywufm0FM3GvCck=; b=CcaIggAj3Qc+6lb1x5TIJoH6BC9XEeRrxeX52XRDT5rlhQssFR8+8v2aAqLXOWee//M5t/wxKSM4SjMSd6aYNyFl9EB5lXeWkncHBmPr4vdMJUbroUhYzXM10fhG93c4lD15EJ9PXIXksm1YvzuUiwVZiIWRN7doNajndkkqfUs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 166127239412771.46739907716608; Tue, 23 Aug 2022 09:33:14 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-Ndp2y5fHNtS7jTykWbuW2Q-1; Tue, 23 Aug 2022 12:33:07 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5BF01866DFE; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 158D2492C3B; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D9A7F1946A5E; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 09AD51946A40 for ; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F2D1A40334C; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9308E40315A for ; Tue, 23 Aug 2022 16:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272393; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RPLKQFvP4DPAtPTQ5UNr4Nn6/fE2kywufm0FM3GvCck=; b=B+Qs32qvmScxf0w9bSvtTiaSwZVYjPbUMAS++CMYKW5I0sawtfSAWN+6X5kLW+0b4s9SwD OY3TLF3pIqBLpkWZJRUmyVmNsTmkFJ8xWLExANWpWNzSogZHixw6g3NojoN7KCLsxy7QIY pWnM+DM1uTOG+4p7xLYJomUDQwWayMA= X-MC-Unique: Ndp2y5fHNtS7jTykWbuW2Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 06/24] qemu_monitor: allow setting autofinalize for block commit Date: Tue, 23 Aug 2022 18:32:09 +0200 Message-Id: <781138417ec24b0a8d99cb66f90270ac1f41ba8f.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272395542100009 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_block.c | 6 ++++-- src/qemu/qemu_block.h | 1 + src/qemu/qemu_monitor.c | 9 +++++---- src/qemu/qemu_monitor.h | 3 ++- src/qemu/qemu_monitor_json.c | 4 ++-- src/qemu/qemu_monitor_json.h | 3 ++- tests/qemumonitorjsontest.c | 2 +- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index bc46966d22..ce26afe611 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3212,6 +3212,7 @@ qemuBlockCommitImpl(virDomainObj *vm, virStorageSource *top_parent, unsigned long bandwidth, bool sync, + virTristateBool autofinalize, unsigned int flags) { qemuDomainObjPrivate *priv =3D vm->privateData; @@ -3349,7 +3350,7 @@ qemuBlockCommitImpl(virDomainObj *vm, job->name, topSource->nodeformat, baseSource->nodeformat, - backingPath, bandwidth); + backingPath, bandwidth, autofinalize); =20 qemuDomainObjExitMonitor(vm); =20 @@ -3416,7 +3417,8 @@ qemuBlockCommit(virDomainObj *vm, return -1; =20 return qemuBlockCommitImpl(vm, driver, disk, baseSource, topSource, - top_parent, bandwidth, false, flags); + top_parent, bandwidth, false, + VIR_TRISTATE_BOOL_YES, flags); } =20 =20 diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 29b5ac9ea1..85dd9c086c 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -286,6 +286,7 @@ qemuBlockCommitImpl(virDomainObj *vm, virStorageSource *top_parent, unsigned long bandwidth, bool sync, + virTristateBool autofinalize, unsigned int flags); =20 int diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 6279e75c68..670a601cd3 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2795,16 +2795,17 @@ qemuMonitorBlockCommit(qemuMonitor *mon, const char *topNode, const char *baseNode, const char *backingName, - unsigned long long bandwidth) + unsigned long long bandwidth, + virTristateBool autofinalize) { - VIR_DEBUG("device=3D%s, jobname=3D%s, topNode=3D%s, baseNode=3D%s, bac= kingName=3D%s, bandwidth=3D%llu", + VIR_DEBUG("device=3D%s, jobname=3D%s, topNode=3D%s, baseNode=3D%s, bac= kingName=3D%s, bandwidth=3D%llu, autofinalize=3D%d", device, NULLSTR(jobname), NULLSTR(topNode), - NULLSTR(baseNode), NULLSTR(backingName), bandwidth); + NULLSTR(baseNode), NULLSTR(backingName), bandwidth, autofina= lize); =20 QEMU_CHECK_MONITOR(mon); =20 return qemuMonitorJSONBlockCommit(mon, device, jobname, topNode, baseN= ode, - backingName, bandwidth); + backingName, bandwidth, autofinalize= ); } =20 =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index dc35aa52c3..67353241e5 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -974,7 +974,8 @@ int qemuMonitorBlockCommit(qemuMonitor *mon, const char *topNode, const char *baseNode, const char *backingName, - unsigned long long bandwidth) + unsigned long long bandwidth, + virTristateBool autofinalize) ATTRIBUTE_NONNULL(2); =20 int qemuMonitorArbitraryCommand(qemuMonitor *mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 9d514bfacc..fe0b88e8c5 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -4035,11 +4035,11 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, const char *topNode, const char *baseNode, const char *backingName, - unsigned long long speed) + unsigned long long speed, + virTristateBool autofinalize) { g_autoptr(virJSONValue) cmd =3D NULL; g_autoptr(virJSONValue) reply =3D NULL; - virTristateBool autofinalize =3D VIR_TRISTATE_BOOL_YES; virTristateBool autodismiss =3D VIR_TRISTATE_BOOL_NO; =20 cmd =3D qemuMonitorJSONMakeCommand("block-commit", diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 37f76bcc0c..ba7b70bd57 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -312,7 +312,8 @@ qemuMonitorJSONBlockCommit(qemuMonitor *mon, const char *topNode, const char *baseNode, const char *backingName, - unsigned long long bandwidth) + unsigned long long bandwidth, + virTristateBool autofinalize) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 int diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index b508f63aea..3c61b7ddf7 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1213,7 +1213,7 @@ GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0") GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0") GEN_TEST_FUNC(qemuMonitorJSONBlockdevMirror, "jobname", true, "vdb", "targ= etnode", 1024, 1234, 31234, true, true) GEN_TEST_FUNC(qemuMonitorJSONBlockStream, "vdb", "jobname", "backingnode",= "backingfilename", 1024) -GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "jobname", "topnode", "ba= senode", "backingfilename", 1024) +GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "jobname", "topnode", "ba= senode", "backingfilename", 1024, VIR_TRISTATE_BOOL_YES) GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar") GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", "export", true, "bitmap") --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272451; cv=none; d=zohomail.com; s=zohoarc; b=hzABpDfSkmLQ3s592GBlKZaXKT62NZPU1wDeSFJTJYkAKhqQPuOUqcaI9A1fakf5244AqvvRt8r9aTo9I2/vnMQI4Rh535Sx+dE9AFX95Uvx3WrQawQjP7MxV1eBX8ewnyihixDQnmRvZgMmuZMk+KhOsS7PXGG723ietvGqlsc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272451; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iYdjCOPEb1ubrPRBhY2mUvahxXq5eQvNHkl+T0R0L3c=; b=BEDoHS3KwydeKRi7f/exHrXR3iUjDt2xmbg6A+gfB26Rjwke9uDWHFm2YU65+0BqNjiVonBHeZwIf80Q3xr0SoOcFzk7MADia0W/UNRL1m7TLtH/VjYUfn2q4bkOfsWmDtq8cHvqwhzJqe0LsqwpShXDOuuQba68x1ETcGDYmiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272451154902.006890852442; Tue, 23 Aug 2022 09:34:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-7MYtSa8rMbaottUXWgQC6Q-1; Tue, 23 Aug 2022 12:33:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8AD0294EDC0; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 961B8C15BB3; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 88D481946A47; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AFE9C1946A61 for ; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9DC12403350; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CC69492C3B for ; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272450; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iYdjCOPEb1ubrPRBhY2mUvahxXq5eQvNHkl+T0R0L3c=; b=FwnEy5F2FR02k3r7gnh2k9z9n1ayuwUisSIMBPrf+/TJ3kHEQDjRYZcBohppdSq9VwX3SA D0T50gUDeRh6vRj2IPBUH+Fdr+A3L7FLfL8MYwxh8PdJ2nVZi5dgjb/cQ+WbZt58f3kmNo n/WFVhjD/B8QfGq336hT9Vz0QvkiFHA= X-MC-Unique: 7MYtSa8rMbaottUXWgQC6Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 07/24] qemu_block: introduce qemuBlockFinalize Date: Tue, 23 Aug 2022 18:32:10 +0200 Message-Id: <228ab90322aed3fc8004aa9487230db6c71905ff.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272451803100002 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_block.c | 16 ++++++++++++++++ src/qemu/qemu_block.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index ce26afe611..92b0fc9812 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -3541,3 +3541,19 @@ qemuBlockPivot(virDomainObj *vm, =20 return ret; } + +int +qemuBlockFinalize(virDomainObj *vm, + qemuBlockJobData *job) +{ + int ret; + qemuDomainObjPrivate *priv =3D vm->privateData; + + qemuDomainObjEnterMonitor(vm); + + ret =3D qemuMonitorJobFinalize(priv->mon, job->name); + + qemuDomainObjExitMonitor(vm); + + return ret; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 85dd9c086c..82389d3a58 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -302,3 +302,7 @@ int qemuBlockPivot(virDomainObj *vm, qemuBlockJobData *job, virDomainDiskDef *disk); + +int +qemuBlockFinalize(virDomainObj *vm, + qemuBlockJobData *job); --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272387; cv=none; d=zohomail.com; s=zohoarc; b=AStH6CxKQ7mxkWkitYLMX923s6DEHRCCe0VBlxJXlTXQYoL+ytqgbEYSzfuInzstJYHP89CywxqlH+Nf0CcSnfo5vxmR95Z6ioSfL47swtVR6F2NR7CVEHkqhKvNGzxV2gIeMAGviFwm9mWMbC45ZrSv0Y08lua0xln9LeKghOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272387; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=brVy9swg46nF2omTO/xjQi6y0Q9D1IQYZ7biV8zjjs8=; b=huC0ezCm3WW5US2EQ9Q9Sy314sUEaZ123YZnxNdVjwXZIhDKmOWEk77i2rz8nRuaEhNJxCnVomjgTSEwz1IcpianYMg59cZjOXC8fe+4PyN81kkle6oNLb2UovVfYv42+tzMsfGgF9xh/PO9GUC1q9n+a0r0pGAn4lD5omMB/oM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272387852851.6563812885397; Tue, 23 Aug 2022 09:33:07 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-A_C9BGUZMuqe2fZPXYmamA-1; Tue, 23 Aug 2022 12:32:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 29CDF800DAF; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 159881121315; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DAF751946A60; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 648811946A40 for ; Tue, 23 Aug 2022 16:32:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 471A0492C3B; Tue, 23 Aug 2022 16:32:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC22840334B for ; Tue, 23 Aug 2022 16:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272386; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=brVy9swg46nF2omTO/xjQi6y0Q9D1IQYZ7biV8zjjs8=; b=RkTaFxhwn8ffxD/HfGGoneC5KNcLJE8R6LR6gEXpR4yPl91ym/grXRj1EjGBlWWv+W9NEn lpmTLRgemCqrJnfbt/1na9jQQM4SbJXAAR25KTTlnQDYkhHOw06gMZAdRA+3uGFdtd89eV hEG5+W9L2Vnw7CikGwdMIoaFO1+I8CA= X-MC-Unique: A_C9BGUZMuqe2fZPXYmamA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 08/24] qemu_blockjob: process QEMU_MONITOR_JOB_STATUS_PENDING signal Date: Tue, 23 Aug 2022 18:32:11 +0200 Message-Id: <7e95561a0c92ab65946f66dd0e64a1040a7b389e.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272389411100003 Content-Type: text/plain; charset="utf-8"; x-default="true" QEMU emits this signal when autofinalize is disabled and QEMU is waiting for the caller to start the finalization manually. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_backup.c | 1 + src/qemu/qemu_blockjob.c | 13 ++++++++++++- src/qemu/qemu_blockjob.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index 5280186970..40254c65cd 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -1035,6 +1035,7 @@ qemuBackupNotifyBlockjobEnd(virDomainObj *vm, case QEMU_BLOCKJOB_STATE_NEW: case QEMU_BLOCKJOB_STATE_RUNNING: case QEMU_BLOCKJOB_STATE_ABORTING: + case QEMU_BLOCKJOB_STATE_PENDING: case QEMU_BLOCKJOB_STATE_PIVOTING: case QEMU_BLOCKJOB_STATE_LAST: default: diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index a7aa7b3940..e13e915057 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -55,6 +55,7 @@ VIR_ENUM_IMPL(qemuBlockjobState, "running", "concluded", "aborting", + "pending", "pivoting"); =20 VIR_ENUM_IMPL(qemuBlockjob, @@ -531,6 +532,8 @@ qemuBlockJobRefreshJobs(virDomainObj *vm) if (job->state =3D=3D QEMU_BLOCKJOB_STATE_NEW || job->state =3D=3D QEMU_BLOCKJOB_STATE_RUNNING) job->newstate =3D newstate; + } else if (newstate =3D=3D QEMU_BLOCKJOB_STATE_PENDING) { + job->newstate =3D newstate; } /* don't update the job otherwise */ } @@ -1563,6 +1566,11 @@ qemuBlockJobEventProcess(virQEMUDriver *driver, job->newstate =3D -1; break; =20 + case QEMU_BLOCKJOB_STATE_PENDING: + job->state =3D job->newstate; + qemuDomainSaveStatus(vm); + break; + case QEMU_BLOCKJOB_STATE_NEW: case QEMU_BLOCKJOB_STATE_RUNNING: case QEMU_BLOCKJOB_STATE_LAST: @@ -1684,13 +1692,16 @@ qemuBlockjobConvertMonitorStatus(int monitorstatus) ret =3D QEMU_BLOCKJOB_STATE_CONCLUDED; break; =20 + case QEMU_MONITOR_JOB_STATUS_PENDING: + ret =3D QEMU_BLOCKJOB_STATE_PENDING; + break; + case QEMU_MONITOR_JOB_STATUS_UNKNOWN: case QEMU_MONITOR_JOB_STATUS_CREATED: case QEMU_MONITOR_JOB_STATUS_RUNNING: case QEMU_MONITOR_JOB_STATUS_PAUSED: case QEMU_MONITOR_JOB_STATUS_STANDBY: case QEMU_MONITOR_JOB_STATUS_WAITING: - case QEMU_MONITOR_JOB_STATUS_PENDING: case QEMU_MONITOR_JOB_STATUS_ABORTING: case QEMU_MONITOR_JOB_STATUS_UNDEFINED: case QEMU_MONITOR_JOB_STATUS_NULL: diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index 741d8df6c5..e9b283da20 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -41,6 +41,7 @@ typedef enum { QEMU_BLOCKJOB_STATE_CONCLUDED, /* job has finished, but it's unknown whether it has failed or not */ QEMU_BLOCKJOB_STATE_ABORTING, + QEMU_BLOCKJOB_STATE_PENDING, QEMU_BLOCKJOB_STATE_PIVOTING, QEMU_BLOCKJOB_STATE_LAST } qemuBlockjobState; --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272452; cv=none; d=zohomail.com; s=zohoarc; b=Q4eGw3sTn7pESZ5UF53rrt/kPICWZK15EzuvTcfuAjbBU8HoCBr8ou5cFD8dPzfPuIp2asDI0Ard9MEEmfuPIGEo8emRIag7YPIV2fJWBRBQWTEKXfAI1gUp69HlR/jC6kixaWPa3xywTHfoyOYqGNjxTjA7+5y8EvcJWBxyXFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272452; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A/X91Dx0VgMsC2KlgWRWwOy3ry0ug0SYlZbwyLUcn/k=; b=C9iRZuMB9yyam3xhbFREvpAC9gD06eTxMO6upwb+B5v7BWHsCD84tVyPIECwLLMZeJJl0EyZWSQ4Y37w2kAcAwIGFralwuwJ8e8cHXEXWXH/xO+vMN3GOzgN7Zvf+m/mlT+xp2FZOxCkQjlOh2GRQVm7NAmabUzVlBgRkj/xC0s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272452811512.018396071981; Tue, 23 Aug 2022 09:34:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-cjdeZfluNs23uaiBJJMfVA-1; Tue, 23 Aug 2022 12:33:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A03E83C10686; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89852945D2; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6675A1946A61; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EF3641946A40 for ; Tue, 23 Aug 2022 16:32:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E3A3540334C; Tue, 23 Aug 2022 16:32:38 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 855D9492C3B for ; Tue, 23 Aug 2022 16:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272451; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=A/X91Dx0VgMsC2KlgWRWwOy3ry0ug0SYlZbwyLUcn/k=; b=OAGR08FSfM6KIlJJN5b6vI5pLULNRO5ZxyPaxuWHmUZ5EBOWIwX01k0Irf08jmsrBbaa63 NKgJszLa409YN2K154jWs8E3r2E4iN6A6lcHN4d0/t+Kat6JY9ezME+FKSizfC0sAYI/h8 fkhdFrZY4rDIz+UiVbjhqAZR3GV7df8= X-MC-Unique: cjdeZfluNs23uaiBJJMfVA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 09/24] qemu_snapshot: refactor qemuSnapshotDelete Date: Tue, 23 Aug 2022 18:32:12 +0200 Message-Id: <0c04e2d42d58454a2541b2cc762a63821804da0d.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272453808100008 Content-Type: text/plain; charset="utf-8"; x-default="true" Move code around to make it clear what is called when deleting single snapshot or children snapshots. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 6033deafed..c1c67ac445 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2350,25 +2350,28 @@ qemuSnapshotDelete(virDomainObj *vm, } } } - } else if (snap->nchildren) { - rep.dir =3D cfg->snapshotDir; - rep.parent =3D snap->parent; - rep.vm =3D vm; - rep.err =3D 0; - rep.xmlopt =3D driver->xmlopt; - rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; - virDomainMomentForEachChild(snap, - qemuSnapshotChildrenReparent, - &rep); - if (rep.err < 0) - goto endjob; - virDomainMomentMoveChildren(snap, snap->parent); - } =20 - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - virDomainMomentDropChildren(snap); - ret =3D 0; + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { + virDomainMomentDropChildren(snap); + ret =3D 0; + } else { + ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, meta= data_only); + } } else { + if (snap->nchildren) { + rep.dir =3D cfg->snapshotDir; + rep.parent =3D snap->parent; + rep.vm =3D vm; + rep.err =3D 0; + rep.xmlopt =3D driver->xmlopt; + rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; + virDomainMomentForEachChild(snap, + qemuSnapshotChildrenReparent, + &rep); + if (rep.err < 0) + goto endjob; + virDomainMomentMoveChildren(snap, snap->parent); + } ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata= _only); } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272458; cv=none; d=zohomail.com; s=zohoarc; b=fKOL99gEea3GPfP0xTP6c0+mGPssu2bofJ0UTnKKSJZ5oRUfBBeNhNm13ztVksxw7YFRSERZvLwxUrVSqdA7CLATAzBUQIpsJumE4qC0lKd+w0Aqms1iwKS473f70bCVitYNqaZRErdVnlJ2DKU52a62VBER1KrvnE5kCfvKt78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272458; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n0eAiAk6B+c4mfse9fq4IE6DFnM6nqWB9Z3+LZnvVdE=; b=YISLt9VuzX2/ok0RHUz6kh2iD9QthDvxFns50thIMfi+WJzCd/z91X6+9o+SflP/TtygZO2MQGR9CDz3TyoZx90McGSaetwMVZge66GbWtWtQ2aZxOjBr+mFzwPDcXwMGCWQtSYfp5h6u9xkI4F4cLmKFVp83aplM7sTeNRjon4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272458949547.302468160994; Tue, 23 Aug 2022 09:34:18 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-492-Q1YlX0HSNXKJRVRAzzT_cw-1; Tue, 23 Aug 2022 12:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54C0C1C00ACE; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EF6640315A; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 237A91946A47; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 348281946A61 for ; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1824140334B; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD80F492C3B for ; Tue, 23 Aug 2022 16:32:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272458; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=n0eAiAk6B+c4mfse9fq4IE6DFnM6nqWB9Z3+LZnvVdE=; b=GQkbQVbjrWRvl8HaA5yMe7wsO2ZsY9n32HzYJeOsaXpxo3qubWjvYmVC5AhNRFF+tQ9Rf3 5uWJs8z/rmoCZE+RgF97KTjBENFF2mldBK5ZHoQXHY8oBzurVQnPPNE7bkuyW/oZrvIJHl 7Omsy9Mw4k3NAzfYQi2oLqcMkSpFCZI= X-MC-Unique: Q1YlX0HSNXKJRVRAzzT_cw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 10/24] qemu_snapshot: extract single snapshot deletion to separate function Date: Tue, 23 Aug 2022 18:32:13 +0200 Message-Id: <767e4c745c47e25136a592b230d27e0b8227297e.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272459939100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 46 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index c1c67ac445..b5e6a87566 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2281,6 +2281,35 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 +static int +qemuSnapshotDeleteSingle(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver, + bool metadata_only) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + if (snap->nchildren) { + virQEMUMomentReparent rep; + + rep.dir =3D cfg->snapshotDir; + rep.parent =3D snap->parent; + rep.vm =3D vm; + rep.err =3D 0; + rep.xmlopt =3D driver->xmlopt; + rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; + virDomainMomentForEachChild(snap, + qemuSnapshotChildrenReparent, + &rep); + if (rep.err < 0) + return -1; + virDomainMomentMoveChildren(snap, snap->parent); + } + + return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); +} + + int qemuSnapshotDelete(virDomainObj *vm, virDomainSnapshotPtr snapshot, @@ -2290,7 +2319,6 @@ qemuSnapshotDelete(virDomainObj *vm, int ret =3D -1; virDomainMomentObj *snap =3D NULL; virQEMUMomentRemove rem; - virQEMUMomentReparent rep; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); int external =3D 0; g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); @@ -2358,21 +2386,7 @@ qemuSnapshotDelete(virDomainObj *vm, ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, meta= data_only); } } else { - if (snap->nchildren) { - rep.dir =3D cfg->snapshotDir; - rep.parent =3D snap->parent; - rep.vm =3D vm; - rep.err =3D 0; - rep.xmlopt =3D driver->xmlopt; - rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; - virDomainMomentForEachChild(snap, - qemuSnapshotChildrenReparent, - &rep); - if (rep.err < 0) - goto endjob; - virDomainMomentMoveChildren(snap, snap->parent); - } - ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata= _only); + ret =3D qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only); } =20 endjob: --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272451; cv=none; d=zohomail.com; s=zohoarc; b=loCZAWprFOpMgRejyogY0L5QC0Z3SW3GS3D+KJ1Z6w5FShLCk41ZaX7uBtVYF/lDe9EdKf9RYqog6XRUqqRY38eSqqLp2P0/OHin7JluU4gK3pEcqyLpFmIqYcGKuxsd0YtNPLGFNnMgY79AblvDqsVjX4dVelhN0UYi2bui95c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272451; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QqkMhHUrDhwJm2SC48uiYD/1gxy+hhOA/7u/n0JQKxg=; b=AUTR55hdSJStsCXk7CnlSX/En7qVQ4j9uLszk1K/4pdrq7NWb0U+Kh2JxqCv8crs/KBYrfS+PBIiVb96WWJvpDBkXSbOuNVAZhQuMB/mz9VDiLNs5o5ffBHKp7loOri2RTo/aNpE4bJ1KeeQXzRvF/V7FSHjM46iYTdc3tQJfn4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272451258531.093642965681; Tue, 23 Aug 2022 09:34:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-125-jUHocT-dPKeUUNU925BTjA-1; Tue, 23 Aug 2022 12:33:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC69B3826271; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B72E2945D0; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9DEAD1946A62; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C9D9C1946A52 for ; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B9F7440315A; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A4EC403349 for ; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272450; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QqkMhHUrDhwJm2SC48uiYD/1gxy+hhOA/7u/n0JQKxg=; b=jDwFJxCLAXqbsJiv+yHiq4Ugz9kCGzCNUMMbSrTNO6r0nCJWAsdVdWiciwLqfShGagtcF0 7Gcv6IUhBOYODwVB65w8ZssSaXvF2O/6AUMexik+rA4meq1zEI1U7u8cZRS5SHBVdinc3e BdIvdHTjzEs0hJpxAhyAka78HG4iMB4= X-MC-Unique: jUHocT-dPKeUUNU925BTjA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 11/24] qemu_snapshot: extract children snapshot deletion to separate function Date: Tue, 23 Aug 2022 18:32:14 +0200 Message-Id: <291226670af3c8658a26db7ca2f67acf4acdc7f5.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272451827100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 94 ++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index b5e6a87566..d40d75e75d 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2310,18 +2310,62 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, } =20 =20 -int -qemuSnapshotDelete(virDomainObj *vm, - virDomainSnapshotPtr snapshot, - unsigned int flags) +static int +qemuSnapshotDeleteChildren(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver, + bool metadata_only, + unsigned int flags) { - virQEMUDriver *driver =3D snapshot->domain->conn->privateData; - int ret =3D -1; - virDomainMomentObj *snap =3D NULL; virQEMUMomentRemove rem; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + rem.driver =3D driver; + rem.vm =3D vm; + rem.metadata_only =3D metadata_only; + rem.err =3D 0; + rem.current =3D virDomainSnapshotGetCurrent(vm->snapshots); + rem.found =3D false; + rem.momentDiscard =3D qemuDomainSnapshotDiscard; + virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll, + &rem); + if (rem.err < 0) + return -1; + if (rem.found) { + qemuSnapshotSetCurrent(vm, snap); + + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { + if (qemuDomainSnapshotWriteMetadata(vm, snap, + driver->xmlopt, + cfg->snapshotDir) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to set snapshot '%s' as current"), + snap->def->name); + virDomainSnapshotSetCurrent(vm->snapshots, NULL); + return -1; + } + } + } + + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { + virDomainMomentDropChildren(snap); + return 0; + } + + return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); +} + + +int +qemuSnapshotDelete(virDomainObj *vm, + virDomainSnapshotPtr snapshot, + unsigned int flags) +{ + virQEMUDriver *driver =3D snapshot->domain->conn->privateData; + int ret =3D -1; + virDomainMomentObj *snap =3D NULL; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); int external =3D 0; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY | @@ -2352,39 +2396,7 @@ qemuSnapshotDelete(virDomainObj *vm, =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { - rem.driver =3D driver; - rem.vm =3D vm; - rem.metadata_only =3D metadata_only; - rem.err =3D 0; - rem.current =3D virDomainSnapshotGetCurrent(vm->snapshots); - rem.found =3D false; - rem.momentDiscard =3D qemuDomainSnapshotDiscard; - virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll, - &rem); - if (rem.err < 0) - goto endjob; - if (rem.found) { - qemuSnapshotSetCurrent(vm, snap); - - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - if (qemuDomainSnapshotWriteMetadata(vm, snap, - driver->xmlopt, - cfg->snapshotDir) < 0)= { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to set snapshot '%s' as curre= nt"), - snap->def->name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - goto endjob; - } - } - } - - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - virDomainMomentDropChildren(snap); - ret =3D 0; - } else { - ret =3D qemuDomainSnapshotDiscard(driver, vm, snap, true, meta= data_only); - } + ret =3D qemuSnapshotDeleteChildren(vm, snap, driver, metadata_only= , flags); } else { ret =3D qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only); } --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272385; cv=none; d=zohomail.com; s=zohoarc; b=AL4YMiuq/psH5WQN7mDfu7JF65seEdDg9boMdv2W8NLcxad4HCex/vXt2WWI7U01d21ng5StKyiSyyrQF9qV87vtJE2abd6ByeGVc+bsNkZ9v1gOYiJrP49nuaOXGYhJgWP6fKJ5YqI92vKW+sOdVlpTu1KyfdfbDlQewttrU6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272385; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Zub4eLmjsbfEcMgMepaYhTq0hCyDLWk236e2F6bS8Dc=; b=APfL1KCkJDKOHeDS8wvay5LGVsJWe6/xecfCxRHemz/VoPiJGarFnxcbN6qAoBoPG/GSjFt+7re76ZYnnTcOBVm2PGfLVKsjKdinoj3zZAc+h9PeUK7pmLsZaywUWne++qC0OGDc/JbgXuRg/n6adF7Z1bWzlduxW2kZ0TL/vv4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272385493430.6313068962413; Tue, 23 Aug 2022 09:33:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-AnTE8Hc6N0286D9lB_bw2Q-1; Tue, 23 Aug 2022 12:33:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 080922932482; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8C981121315; Tue, 23 Aug 2022 16:32:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB9EB1946A47; Tue, 23 Aug 2022 16:32:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6CC6C1946A40 for ; Tue, 23 Aug 2022 16:32:41 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 630B9492C3B; Tue, 23 Aug 2022 16:32:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0430440315A for ; Tue, 23 Aug 2022 16:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272384; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Zub4eLmjsbfEcMgMepaYhTq0hCyDLWk236e2F6bS8Dc=; b=C184JNBQqek5xFl1TJ/oSRbmzUGbEvIye4DSUlEuSUEQvm0gjEGtAlpaJ5DFwexI8CXqx/ kabUr+5/4Vq3/7WQIBIDYvDvcQBJ/M1uxY+hk6S0JUtwqCgra/Ikomg4rKK3lEt69w82Du +fgPMnS2NHmCLCB25jnHkLp6EwGOyZ8= X-MC-Unique: AnTE8Hc6N0286D9lB_bw2Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 12/24] qemu_snapshot: rework snapshot children deletion Date: Tue, 23 Aug 2022 18:32:15 +0200 Message-Id: <11280dac0641f3ba9fc832ead24bdfd5b9161182.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272387406100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This simplifies the code a bit by reusing existing parts that deletes a single snapshot. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 69 ++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index d40d75e75d..db04244018 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2310,6 +2310,33 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, } =20 =20 +struct qemuSnapshotDeleteAllData { + virDomainObj *vm; + virQEMUDriver *driver; + bool metadata_only; + int error; +}; + + +static int +qemuSnapshotDeleteAll(void *payload, + const char *name G_GNUC_UNUSED, + void *opaque) +{ + int error; + virDomainMomentObj *snap =3D payload; + struct qemuSnapshotDeleteAllData *data =3D opaque; + + error =3D qemuSnapshotDeleteSingle(data->vm, snap, data->driver, + data->metadata_only); + + if (error !=3D 0 && data->error !=3D 0) + data->error =3D error; + + return 0; +} + + static int qemuSnapshotDeleteChildren(virDomainObj *vm, virDomainMomentObj *snap, @@ -2317,42 +2344,22 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, bool metadata_only, unsigned int flags) { - virQEMUMomentRemove rem; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + struct qemuSnapshotDeleteAllData data =3D { 0 }; =20 - rem.driver =3D driver; - rem.vm =3D vm; - rem.metadata_only =3D metadata_only; - rem.err =3D 0; - rem.current =3D virDomainSnapshotGetCurrent(vm->snapshots); - rem.found =3D false; - rem.momentDiscard =3D qemuDomainSnapshotDiscard; - virDomainMomentForEachDescendant(snap, qemuDomainMomentDiscardAll, - &rem); - if (rem.err < 0) + data.vm =3D vm; + data.driver =3D driver; + data.metadata_only =3D metadata_only; + + virDomainMomentForEachDescendant(snap, qemuSnapshotDeleteAll, &data); + + if (data.error < 0) return -1; - if (rem.found) { - qemuSnapshotSetCurrent(vm, snap); =20 - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - if (qemuDomainSnapshotWriteMetadata(vm, snap, - driver->xmlopt, - cfg->snapshotDir) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to set snapshot '%s' as current"), - snap->def->name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - return -1; - } - } + if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { + return qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only); } =20 - if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) { - virDomainMomentDropChildren(snap); - return 0; - } - - return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); + return 0; } =20 =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272565; cv=none; d=zohomail.com; s=zohoarc; b=ZblXXQ1/rG4uoUOhPoscAHLNWaPtw5rGQrM/rzBP5BfaNpsUYLnmdqQgkazBVBUwkOcws98HrzL6teLvwZGMmBdMYLLVMz1vAGHsNE+yokGB87GF5iRv2Ap9H1/LDm6ONQ63r21XBw7+Uym7FbdU5/R4rv0LUrPKcFEMleNypaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272565; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tt1f4UkaVrSVBrLNHLO12AIrTRr7yiYVO7eoJfTRLxc=; b=Qmd5Heo7REkznHpTHmEdMvt7L0fkoTl0c71bsmNtne6TnptrCoa0whwjh2ZtuCIIPUSJY+GXiwDHf6hciRtlKR2Ob4UYnrhGOe8yCQ7CqqpTfvI4ypuLbKG/GsECzehhHCGg6GsKxle79l9VnF9iv624rkbf69nTzxqh+iPH5kY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 166127256510780.98297399853016; Tue, 23 Aug 2022 09:36:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-589-Rv5roR97NliycEBmoltbwA-1; Tue, 23 Aug 2022 12:33:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 900AF1035395; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C6A714152E0; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 597EB1946A58; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 17EB01946A60 for ; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0B24840334B; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0A6F492C3B for ; Tue, 23 Aug 2022 16:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272564; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tt1f4UkaVrSVBrLNHLO12AIrTRr7yiYVO7eoJfTRLxc=; b=P125Vr+BCLFcO7CzhUmAQq7W3AIHVJ/OsHDy3oDpgQecc8UyuIunUO3v+fA6V6XArXqKVW ZmeiiSpzQVvv1j3WUv/q/a1XKn5y6Q7JkoA2bkPDCaa4iW13ag3VO08XPzppAdvjw9F4Tt oI7nEnzxiejB3+OPrW7B3WOL7YHdGho= X-MC-Unique: Rv5roR97NliycEBmoltbwA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 13/24] qemu_snapshot: move snapshot discard out of qemu_domain.c Date: Tue, 23 Aug 2022 18:32:16 +0200 Message-Id: <49faa46319657e7296ec7b175bc1cef28b52f16c.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272566468100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_domain.c | 95 +-------------------------------------- src/qemu/qemu_domain.h | 9 ---- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_snapshot.c | 96 +++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_snapshot.h | 4 ++ 5 files changed, 102 insertions(+), 104 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d5fef76211..7768f316dd 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -31,6 +31,7 @@ #include "qemu_migration_params.h" #include "qemu_security.h" #include "qemu_slirp.h" +#include "qemu_snapshot.h" #include "qemu_extdevice.h" #include "qemu_blockjob.h" #include "qemu_checkpoint.h" @@ -7030,81 +7031,6 @@ qemuDomainSnapshotForEachQcow2(virQEMUDriver *driver, op, try_all, def->ndisks); } =20 -/* Discard one snapshot (or its metadata), without reparenting any childre= n. */ -int -qemuDomainSnapshotDiscard(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap, - bool update_parent, - bool metadata_only) -{ - g_autofree char *snapFile =3D NULL; - qemuDomainObjPrivate *priv; - virDomainMomentObj *parentsnap =3D NULL; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - - if (!metadata_only) { - if (!virDomainObjIsActive(vm)) { - size_t i; - /* Ignore any skipped disks */ - - /* Prefer action on the disks in use at the time the snapshot = was - * created; but fall back to current definition if dealing wit= h a - * snapshot created prior to libvirt 0.9.5. */ - virDomainDef *def =3D snap->def->dom; - - if (!def) - def =3D vm->def; - - for (i =3D 0; i < def->ndisks; i++) { - if (virDomainDiskTranslateSourcePool(def->disks[i]) < 0) - return -1; - } - - if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d", tr= ue) < 0) - return -1; - } else { - priv =3D vm->privateData; - qemuDomainObjEnterMonitor(vm); - /* we continue on even in the face of error */ - qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); - qemuDomainObjExitMonitor(vm); - } - } - - snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, - snap->def->name); - - if (snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots)) { - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - if (update_parent && snap->def->parent_name) { - parentsnap =3D virDomainSnapshotFindByName(vm->snapshots, - snap->def->parent_nam= e); - if (!parentsnap) { - VIR_WARN("missing parent snapshot matching name '%s'", - snap->def->parent_name); - } else { - virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); - if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, - driver->xmlopt, - cfg->snapshotDir) < 0)= { - VIR_WARN("failed to set parent snapshot '%s' as curren= t", - snap->def->parent_name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - } - } - } - } - - if (unlink(snapFile) < 0) - VIR_WARN("Failed to unlink %s", snapFile); - if (update_parent) - virDomainMomentDropParent(snap); - virDomainSnapshotObjListRemove(vm->snapshots, snap); - - return 0; -} - /* Hash iterator callback to discard multiple snapshots. */ int qemuDomainMomentDiscardAll(void *payload, const char *name G_GNUC_UNUSED, @@ -7123,23 +7049,6 @@ int qemuDomainMomentDiscardAll(void *payload, return 0; } =20 -int -qemuDomainSnapshotDiscardAllMetadata(virQEMUDriver *driver, - virDomainObj *vm) -{ - virQEMUMomentRemove rem =3D { - .driver =3D driver, - .vm =3D vm, - .metadata_only =3D true, - .momentDiscard =3D qemuDomainSnapshotDiscard, - }; - - virDomainSnapshotForEach(vm->snapshots, qemuDomainMomentDiscardAll, &r= em); - virDomainSnapshotObjListRemoveAll(vm->snapshots); - - return rem.err; -} - =20 static void qemuDomainRemoveInactiveCommon(virQEMUDriver *driver, @@ -7150,7 +7059,7 @@ qemuDomainRemoveInactiveCommon(virQEMUDriver *driver, g_autofree char *chkDir =3D NULL; =20 /* Remove any snapshot metadata prior to removing the domain */ - if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) { + if (qemuSnapshotDiscardAllMetadata(driver, vm) < 0) { VIR_WARN("unable to remove all snapshots for domain %s", vm->def->name); } else { diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 592ee9805b..9474962532 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -657,12 +657,6 @@ int qemuDomainSnapshotForEachQcow2(virQEMUDriver *driv= er, const char *op, bool try_all); =20 -int qemuDomainSnapshotDiscard(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap, - bool update_current, - bool metadata_only); - typedef struct _virQEMUMomentRemove virQEMUMomentRemove; struct _virQEMUMomentRemove { virQEMUDriver *driver; @@ -679,9 +673,6 @@ int qemuDomainMomentDiscardAll(void *payload, const char *name, void *data); =20 -int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriver *driver, - virDomainObj *vm); - void qemuDomainRemoveInactive(virQEMUDriver *driver, virDomainObj *vm); =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 564648f9ac..b55654e3c5 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6758,7 +6758,7 @@ qemuDomainUndefineFlags(virDomainPtr dom, nsnapshots); goto endjob; } - if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) + if (qemuSnapshotDiscardAllMetadata(driver, vm) < 0) goto endjob; } if (!virDomainObjIsActive(vm) && diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index db04244018..493d83d017 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2281,6 +2281,100 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 +/* Discard one snapshot (or its metadata), without reparenting any childre= n. */ +static int +qemuSnapshotDiscard(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap, + bool update_parent, + bool metadata_only) +{ + g_autofree char *snapFile =3D NULL; + qemuDomainObjPrivate *priv; + virDomainMomentObj *parentsnap =3D NULL; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + if (!metadata_only) { + if (!virDomainObjIsActive(vm)) { + size_t i; + /* Ignore any skipped disks */ + + /* Prefer action on the disks in use at the time the snapshot = was + * created; but fall back to current definition if dealing wit= h a + * snapshot created prior to libvirt 0.9.5. */ + virDomainDef *def =3D snap->def->dom; + + if (!def) + def =3D vm->def; + + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainDiskTranslateSourcePool(def->disks[i]) < 0) + return -1; + } + + if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d", tr= ue) < 0) + return -1; + } else { + priv =3D vm->privateData; + qemuDomainObjEnterMonitor(vm); + /* we continue on even in the face of error */ + qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); + qemuDomainObjExitMonitor(vm); + } + } + + snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, + snap->def->name); + + if (snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots)) { + virDomainSnapshotSetCurrent(vm->snapshots, NULL); + if (update_parent && snap->def->parent_name) { + parentsnap =3D virDomainSnapshotFindByName(vm->snapshots, + snap->def->parent_nam= e); + if (!parentsnap) { + VIR_WARN("missing parent snapshot matching name '%s'", + snap->def->parent_name); + } else { + virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); + if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, + driver->xmlopt, + cfg->snapshotDir) < 0)= { + VIR_WARN("failed to set parent snapshot '%s' as curren= t", + snap->def->parent_name); + virDomainSnapshotSetCurrent(vm->snapshots, NULL); + } + } + } + } + + if (unlink(snapFile) < 0) + VIR_WARN("Failed to unlink %s", snapFile); + if (update_parent) + virDomainMomentDropParent(snap); + virDomainSnapshotObjListRemove(vm->snapshots, snap); + + return 0; +} + + +int +qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, + virDomainObj *vm) +{ + virQEMUMomentRemove rem =3D { + .driver =3D driver, + .vm =3D vm, + .metadata_only =3D true, + .momentDiscard =3D qemuSnapshotDiscard, + }; + + virDomainSnapshotForEach(vm->snapshots, qemuDomainMomentDiscardAll, &r= em); + virDomainSnapshotObjListRemoveAll(vm->snapshots); + + return rem.err; +} + + static int qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentObj *snap, @@ -2306,7 +2400,7 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentMoveChildren(snap, snap->parent); } =20 - return qemuDomainSnapshotDiscard(driver, vm, snap, true, metadata_only= ); + return qemuSnapshotDiscard(driver, vm, snap, true, metadata_only); } =20 =20 diff --git a/src/qemu/qemu_snapshot.h b/src/qemu/qemu_snapshot.h index f69c05f68c..38437a2fd7 100644 --- a/src/qemu/qemu_snapshot.h +++ b/src/qemu/qemu_snapshot.h @@ -49,6 +49,10 @@ qemuSnapshotRevert(virDomainObj *vm, virDomainSnapshotPtr snapshot, unsigned int flags); =20 +int +qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, + virDomainObj *vm); + int qemuSnapshotDelete(virDomainObj *vm, virDomainSnapshotPtr snapshot, --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272396; cv=none; d=zohomail.com; s=zohoarc; b=Jbtb8iB6lH+zOeNuSDh06asD2IRjbn8PbaaAHLF87yyvLzuDY8qX9xLw9O8/E7LWWXjjP15wU3K+b/d29q4zeRdW9UC8j7OHr5Kqfi+NF2JmjzmGmiKYUc0O9PGhWDIB+OrxFo2CLFhKBybL5Faf4vVuVgyqT4QKNiChpKcQp7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272396; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cet7zJt/47YnqyOlo7ZXRlStuuy0kUBpiq75u5Acu/c=; b=VMCVxAwLZrt9Xr7N8J2ggnxaVkY6/nRjmNBL1+nT7JYL7nVM2zIqWX+j/FRwTY8PC8ULtMGiw2RapoM449F1kupqVfKT1NecS4+ltBpPfr36EYTeoU9hNqOSdUukOguI1mwuns8WPiJ359aAiXI+homFyKS5jp6UTQN96tmbZ80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272396002680.5451497289744; Tue, 23 Aug 2022 09:33:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-308-cMtj3WsKNYCoAJ5_Ut657w-1; Tue, 23 Aug 2022 12:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B46203C1068C; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81B2A2166B2D; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6566B1946A61; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B453D1946A40 for ; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AB115403349; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B732492C3B for ; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cet7zJt/47YnqyOlo7ZXRlStuuy0kUBpiq75u5Acu/c=; b=i6jOwsPcp/B/rgrMSantIj9Z14d0zqWJIeQi7UihndCOnvcobzBUUPf4kWcQS4e0za5H5b A67o4nElfqCgRWOc7InpzYbd4QR5nXuAECFSru2USucFQCIu7DA3oNPJDdJ0oHFkeG9VMH Z2Ut7qSGBRfWUTC1qQrBHIVLW6cnU/k= X-MC-Unique: cMtj3WsKNYCoAJ5_Ut657w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 14/24] qemu_snapshot: introduce qemuSnapshotDiscardMetadata Date: Tue, 23 Aug 2022 18:32:17 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272397480100011 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 493d83d017..b94506c177 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2376,10 +2376,9 @@ qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, =20 =20 static int -qemuSnapshotDeleteSingle(virDomainObj *vm, - virDomainMomentObj *snap, - virQEMUDriver *driver, - bool metadata_only) +qemuSnapshotDiscardMetadata(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 @@ -2400,6 +2399,19 @@ qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentMoveChildren(snap, snap->parent); } =20 + return 0; +} + + +static int +qemuSnapshotDeleteSingle(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver, + bool metadata_only) +{ + if (qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) + return -1; + return qemuSnapshotDiscard(driver, vm, snap, true, metadata_only); } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272452; cv=none; d=zohomail.com; s=zohoarc; b=Ny29dz/YAVZ5OQxC2I74hx09PWwE2gDRMpQQCBEdnFE1vI9FpjPhW7kHQegC+ZLHYDDqNxRkLMSqJl6xNEAjnI/1PDIUCGmVJlVRPjnFoBuG/93TRkyMQlOM01eLxi+6UzklyZMI7eTkagucgfzcECs1gjK4fvsMMwiRmSGrAvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272452; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RmNrq/reoOWLIIu5SBTfeT/hozRi8Zl9uK/krX452gc=; b=gJmAyFXaTDeFeGotQOQYF42R+BwKYCelOwgUJLQDpeczM8U6MOH4UcneV2EFGdWPmiMkmYmbPLnfF3oeP6h728XIWJWgqOGtfTHWzv3zf7sDM94itrfrvPYKRhdC6ovlqSviK1gx/jHhxMEvV9bg+oXx0vcW5Fsfv+9PDVCxubY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272452204555.2187296472982; Tue, 23 Aug 2022 09:34:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-103-sHO3X-jvMNeU7nVRA7E8Lw-1; Tue, 23 Aug 2022 12:33:11 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D34D857CE7; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 297E5492CA8; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 197A11946A5A; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 60B041946A5A for ; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 546BE403349; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id E84E3492C3B for ; Tue, 23 Aug 2022 16:32:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272451; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RmNrq/reoOWLIIu5SBTfeT/hozRi8Zl9uK/krX452gc=; b=Zb5IgDv5fW88PqnKYdEb8PfOeQvpPwhiUglk47ob/f5aye2SkjjSoCedfhUJAiWNIqqZby bLk0mSofJpKAoXAsrChUTJNJC7EX/zYpB8jIDDi84TfPzj4DfurAF7ot3PQ6PenfoX909M 4f8d10wpqK2le/pYNyW+BtQnxaKo5Zg= X-MC-Unique: sHO3X-jvMNeU7nVRA7E8Lw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 15/24] qemu_snapshot: call qemuSnapshotDiscardMetadata from qemuSnapshotDiscard Date: Tue, 23 Aug 2022 18:32:18 +0200 Message-Id: <20ab7a6768359042e2bda2f17769534b890b6dfa.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272453819100009 Content-Type: text/plain; charset="utf-8"; x-default="true" This changes the snapshot delete call order. Previously we did snapshot XML reparenting before the actual snapshot deletion. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 64 +++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index b94506c177..cbacb05c16 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2281,6 +2281,34 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 +static int +qemuSnapshotDiscardMetadata(virDomainObj *vm, + virDomainMomentObj *snap, + virQEMUDriver *driver) +{ + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + + if (snap->nchildren) { + virQEMUMomentReparent rep; + + rep.dir =3D cfg->snapshotDir; + rep.parent =3D snap->parent; + rep.vm =3D vm; + rep.err =3D 0; + rep.xmlopt =3D driver->xmlopt; + rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; + virDomainMomentForEachChild(snap, + qemuSnapshotChildrenReparent, + &rep); + if (rep.err < 0) + return -1; + virDomainMomentMoveChildren(snap, snap->parent); + } + + return 0; +} + + /* Discard one snapshot (or its metadata), without reparenting any childre= n. */ static int qemuSnapshotDiscard(virQEMUDriver *driver, @@ -2323,6 +2351,11 @@ qemuSnapshotDiscard(virQEMUDriver *driver, } } =20 + if (update_parent && + qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) { + return -1; + } + snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, snap->def->name); =20 @@ -2375,43 +2408,12 @@ qemuSnapshotDiscardAllMetadata(virQEMUDriver *drive= r, } =20 =20 -static int -qemuSnapshotDiscardMetadata(virDomainObj *vm, - virDomainMomentObj *snap, - virQEMUDriver *driver) -{ - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); - - if (snap->nchildren) { - virQEMUMomentReparent rep; - - rep.dir =3D cfg->snapshotDir; - rep.parent =3D snap->parent; - rep.vm =3D vm; - rep.err =3D 0; - rep.xmlopt =3D driver->xmlopt; - rep.writeMetadata =3D qemuDomainSnapshotWriteMetadata; - virDomainMomentForEachChild(snap, - qemuSnapshotChildrenReparent, - &rep); - if (rep.err < 0) - return -1; - virDomainMomentMoveChildren(snap, snap->parent); - } - - return 0; -} - - static int qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentObj *snap, virQEMUDriver *driver, bool metadata_only) { - if (qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) - return -1; - return qemuSnapshotDiscard(driver, vm, snap, true, metadata_only); } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272453; cv=none; d=zohomail.com; s=zohoarc; b=L6FU1rgUTU0R4rC4RQz3+4pBCK0BAdiTwPo4L0jXeOQfl1Z9xU84Farr+ijC0EZdH4Cu/Z+SlBbOq3uq/xE9ACVcP4cHmZavEGk7TM7KZcRhDq6QBQQx9ISnxWTB++FvXBx3DgeDnplZORsbO5ZQE6PoMjutHfD/YXi402K6rpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272453; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TqCCNFElR+A5RvneiNDDftkBj8Wj8OKixZKDegEDMWI=; b=B+GUrT0kc0DCvHIWhZXvPmvfc0gBKtF60OTK8sVPLFLRbxDmjJXVgWlVmf2h7mfC8vRLRhE7m2M32/Ih36nMfUA1JthyRbfs07caUy9wgSmf3eIRPQ2ARuFBIGGitKnRuD/b8uNbHBVkL1pIIg5M3KYA8CNl7QZjHvBcoX2bVAo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272453517238.4520338752926; Tue, 23 Aug 2022 09:34:13 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-196-2V6IQuq0Piacb-VmmBNASg-1; Tue, 23 Aug 2022 12:33:07 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0ADDE83DE45; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA8E3C15BB3; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CB3A11946A5A; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 195311946A67 for ; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EFAFE492C3B; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9134340315A for ; Tue, 23 Aug 2022 16:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272451; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TqCCNFElR+A5RvneiNDDftkBj8Wj8OKixZKDegEDMWI=; b=cFjw3/ii39BVVpMSdDQzoWFJGUmKzrbSv7oC+grjf5ZlxZ2kSujUoJtL/wpZyf4cBuQBBR Nlg4FOEjGPVUhLUWdH57md5isTk4ME0PV9yZOrs2OHp8Iw8KnmLFui3bZXQW3rLRoC2xu6 BGLOjTuuA5DwIKKoYm5sNTn1+fK0bJ0= X-MC-Unique: 2V6IQuq0Piacb-VmmBNASg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 16/24] qemu_snapshot: pass update_parent into qemuSnapshotDiscardMetadata Date: Tue, 23 Aug 2022 18:32:19 +0200 Message-Id: <2fe2d702ad4ec7731cdc276f872d6f571bd272bc.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272453805100007 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index cbacb05c16..787186605f 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2284,11 +2284,12 @@ qemuSnapshotChildrenReparent(void *payload, static int qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentObj *snap, - virQEMUDriver *driver) + virQEMUDriver *driver, + bool update_parent) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 - if (snap->nchildren) { + if (update_parent && snap->nchildren) { virQEMUMomentReparent rep; =20 rep.dir =3D cfg->snapshotDir; @@ -2351,10 +2352,8 @@ qemuSnapshotDiscard(virQEMUDriver *driver, } } =20 - if (update_parent && - qemuSnapshotDiscardMetadata(vm, snap, driver) < 0) { + if (qemuSnapshotDiscardMetadata(vm, snap, driver, update_parent) < 0) return -1; - } =20 snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, snap->def->name); --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272445; cv=none; d=zohomail.com; s=zohoarc; b=VgCT8/D4Cos9H8k72BUoKsaAFsSazyYxa+T1B/V5E72HLZG6M+KvgHIVk5Yzv69g/6p/w5T/ZVK1CxPFAkOkTL8vfFPs/lKdEW1QSxIhBtYakTaSIfnPmb5gZMB/15T9ibsOUQ6DDSjsGX9Was1UtFK6coj5vNJXZ4SKmnIUhOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272445; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=evMmbgCAxlCzuOQQWWdhY1rOXMoSrduRayJpIu++d78=; b=c/gRLQwELcHbW3Z1sL60YX5KgLkGx1hGOh94hnLLV3zkZGOI4Ew0JhFgGnkr0YyDb+S1GdHIqfFizdV5V0pzaLQZ2MWspIHWVaei9sPuvhUesgunuXEqWkQT4zhH/VYmKeR6UQXvKJSKcBi62LtTx64T1UJtcvly4A0t/yQ7G3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1661272445985750.8499270494426; Tue, 23 Aug 2022 09:34:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-49-fM3Ej1khOMO_J_yZLGtIrA-1; Tue, 23 Aug 2022 12:33:12 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DDFD12919EAA; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC88E492C3B; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BDD841946A47; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B2C331946A61 for ; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9835F40334B; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39641492C3B for ; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272445; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=evMmbgCAxlCzuOQQWWdhY1rOXMoSrduRayJpIu++d78=; b=TOoZCFf3x7z5HofYVebSIxaS2aWa+Z4VZ8cAvwCbFvPdt/+N5xtYyPkMOQjWcNhfG0ObS0 lgFOD+wgZiZ4CWWxDHfbbJSiltlEdB+kdyOdc6ujPcv7GNUy3uQPpy1RLzI4EsID/PKqVg RHFSlQre7Tvq/phGBGmrN2xhmX+gNvM= X-MC-Unique: fM3Ej1khOMO_J_yZLGtIrA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 17/24] qemu_snapshot: move metadata changes to qemuSnapshotDiscardMetadata Date: Tue, 23 Aug 2022 18:32:20 +0200 Message-Id: <8320a0ab0503ee579f671688bb93430c9b8dad73.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272447809100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 65 ++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 787186605f..591d6db39b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2288,6 +2288,8 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, bool update_parent) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + g_autofree char *snapFile =3D NULL; + virDomainMomentObj *parentsnap =3D NULL; =20 if (update_parent && snap->nchildren) { virQEMUMomentReparent rep; @@ -2306,6 +2308,36 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentMoveChildren(snap, snap->parent); } =20 + snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, + snap->def->name); + + if (snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots)) { + virDomainSnapshotSetCurrent(vm->snapshots, NULL); + if (update_parent && snap->def->parent_name) { + parentsnap =3D virDomainSnapshotFindByName(vm->snapshots, + snap->def->parent_nam= e); + if (!parentsnap) { + VIR_WARN("missing parent snapshot matching name '%s'", + snap->def->parent_name); + } else { + virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); + if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, + driver->xmlopt, + cfg->snapshotDir) < 0)= { + VIR_WARN("failed to set parent snapshot '%s' as curren= t", + snap->def->parent_name); + virDomainSnapshotSetCurrent(vm->snapshots, NULL); + } + } + } + } + + if (unlink(snapFile) < 0) + VIR_WARN("Failed to unlink %s", snapFile); + if (update_parent) + virDomainMomentDropParent(snap); + virDomainSnapshotObjListRemove(vm->snapshots, snap); + return 0; } =20 @@ -2318,10 +2350,7 @@ qemuSnapshotDiscard(virQEMUDriver *driver, bool update_parent, bool metadata_only) { - g_autofree char *snapFile =3D NULL; qemuDomainObjPrivate *priv; - virDomainMomentObj *parentsnap =3D NULL; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); =20 if (!metadata_only) { if (!virDomainObjIsActive(vm)) { @@ -2355,36 +2384,6 @@ qemuSnapshotDiscard(virQEMUDriver *driver, if (qemuSnapshotDiscardMetadata(vm, snap, driver, update_parent) < 0) return -1; =20 - snapFile =3D g_strdup_printf("%s/%s/%s.xml", cfg->snapshotDir, vm->def= ->name, - snap->def->name); - - if (snap =3D=3D virDomainSnapshotGetCurrent(vm->snapshots)) { - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - if (update_parent && snap->def->parent_name) { - parentsnap =3D virDomainSnapshotFindByName(vm->snapshots, - snap->def->parent_nam= e); - if (!parentsnap) { - VIR_WARN("missing parent snapshot matching name '%s'", - snap->def->parent_name); - } else { - virDomainSnapshotSetCurrent(vm->snapshots, parentsnap); - if (qemuDomainSnapshotWriteMetadata(vm, parentsnap, - driver->xmlopt, - cfg->snapshotDir) < 0)= { - VIR_WARN("failed to set parent snapshot '%s' as curren= t", - snap->def->parent_name); - virDomainSnapshotSetCurrent(vm->snapshots, NULL); - } - } - } - } - - if (unlink(snapFile) < 0) - VIR_WARN("Failed to unlink %s", snapFile); - if (update_parent) - virDomainMomentDropParent(snap); - virDomainSnapshotObjListRemove(vm->snapshots, snap); - return 0; } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272458; cv=none; d=zohomail.com; s=zohoarc; b=f4wTuvawj2ynrgAKdX0llLeTNl5EIuo+9Rup6EXQznHdsIr65DLVNKusVbQZHb+VoQPkZmJ6PNCDsmy1HGTsbZqhMZxW9dZOfnLxUoBPFGTq9GyjZOcFjNb2u4PtnkO8u3EMtmB4Px34YEJ0NWvnEzs884VEI2dMCkC2HziPKug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272458; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EBnUJUehIjC8FvN3a/1mxwSy7Vt3iGv/itOqaTzuttM=; b=cxJgCFRBBo7llJoxx9yYGJlHdfRmFQtAOkBgoGpBfHkyfsWMzY3rMaIwsgSsnK10KUspvSVAXapvQBHW1A7rUlaAfCjeNm+WlSD9yYNZIoRNFJ7fRlu4uSHGxyXrJFXE/ucibDHau21v1RKgVKN5fP51jrpm6+q8DQC/37ErIwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272458284230.7488952248724; Tue, 23 Aug 2022 09:34:18 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-sJz0dOICMISE_aillFYfRA-1; Tue, 23 Aug 2022 12:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8A5F28039CF; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 789CD40D2830; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 678F41946A47; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5C1CC1946A40 for ; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 40D95403349; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6679492C3B for ; Tue, 23 Aug 2022 16:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272456; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EBnUJUehIjC8FvN3a/1mxwSy7Vt3iGv/itOqaTzuttM=; b=G96W+9tHEqg7llXDlYnkPb9Pp0nDSFPlZeJRXTSio/PLIGNTu1MT73/Yz9RGWhiZfFt3Dj CHLCO+OuaNSMQgMZP2es/agSlmYTYRHDEDswozCH/nrQcT1D0sTQKzzJBDH5e4PWe6tLaH XxpRyJjXApXh9RrgwKR4ELhau57dAd8= X-MC-Unique: sJz0dOICMISE_aillFYfRA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 18/24] qemu_snapshot: introduce qemuSnapshotDeleteValidate function Date: Tue, 23 Aug 2022 18:32:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272459873100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 42 ++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 591d6db39b..42bc410078 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2469,6 +2469,33 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotDeleteValidate(virDomainMomentObj *snap, + unsigned int flags) +{ + int external =3D 0; + + if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) && + virDomainSnapshotIsExternal(snap)) + external++; + + if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) + virDomainMomentForEachDescendant(snap, + qemuSnapshotCountExternal, + &external); + + if (external) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("deletion of %d external disk snapshots not " + "supported yet"), external); + return -1; + } + + return 0; +} + + int qemuSnapshotDelete(virDomainObj *vm, virDomainSnapshotPtr snapshot, @@ -2478,7 +2505,6 @@ qemuSnapshotDelete(virDomainObj *vm, int ret =3D -1; virDomainMomentObj *snap =3D NULL; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); - int external =3D 0; =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY | @@ -2491,20 +2517,8 @@ qemuSnapshotDelete(virDomainObj *vm, goto endjob; =20 if (!metadata_only) { - if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) && - virDomainSnapshotIsExternal(snap)) - external++; - if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | - VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) - virDomainMomentForEachDescendant(snap, - qemuSnapshotCountExternal, - &external); - if (external) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("deletion of %d external disk snapshots not " - "supported yet"), external); + if (qemuSnapshotDeleteValidate(snap, flags) < 0) goto endjob; - } } =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272396; cv=none; d=zohomail.com; s=zohoarc; b=clTV9SkwbulrEJwwgWmFQC09ghCpvzajt2iX4q3/JxWhzEbhYZLfCvyng82WDNfZcbAQKAXMS/W0VxTQ2bcsEIpd1CLiuHT38mfko0wW+y4QnQofLcvguYgK+ihHlzUTz1HrVOv7zWn8lLnHe4K6Z4r8kLDhdVnq3/cuglVu7Xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272396; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8BFr8I/n09gzjbLrv2T8cXXKFFFPsgQoNb9g6ovsazI=; b=gjNW8A5c925CINUrysgmoDvVXPhwgDJQ12VYiWSzTFUVMq7fBTVysNWPsidTbfVg464VuFoK3emVwupLBxOgA5sGFAlyIViAeqtTdLnYlvhMXp70OCC0T+3DPaOW8IV1SEbX1NigQKF/WU+nrT46EAg9oFlUnG6/m3uPokkEJNw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272396742568.9641639315929; Tue, 23 Aug 2022 09:33:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-237-4t9GaLlmNI-ZUzSVoUFFAA-1; Tue, 23 Aug 2022 12:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A3AF280EA2E; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 193791121315; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 09C621946A40; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E7E441946A60 for ; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DD7BE40334B; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DFC9403349 for ; Tue, 23 Aug 2022 16:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272395; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=8BFr8I/n09gzjbLrv2T8cXXKFFFPsgQoNb9g6ovsazI=; b=dCkzWDpJ3YCN13uPnQ0NEK7dQUd7mNtdxZeRt40Vv5CH9pzWTsUFM5yiDV3QPZ0S5STw80 z6buvhjhGPZIpP8CAzzB0UoWcaT5ERC1Qow01mmUvEpyD4Flq+nOM87wcE8/ddBS53E6L2 1dFMfKjBJPQd0Sk1/iEYU48IrNDJo00= X-MC-Unique: 4t9GaLlmNI-ZUzSVoUFFAA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 19/24] qemu_snapshot: refactor validation of snapshot delete Date: Tue, 23 Aug 2022 18:32:22 +0200 Message-Id: <8b042396782e2b4b5861d3de3fce9fcedd8ad3c8.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272397527100012 Content-Type: text/plain; charset="utf-8"; x-default="true" Prepare the validation function for external snapshot delete support. There is one exception when deleting `children-only` snapshots. If the snapshot tree is like this example: snap1 (external) | +- snap2 (internal) | +- snap3 (internal) | +- snap4 (internal) and user calls `snapshot-delete snap1 --children-only` the current snapshot is external but all the children snapshots are internal only and we are able to delete it. Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 72 +++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 42bc410078..da9b4c30f0 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -100,21 +100,6 @@ qemuSnapObjFromSnapshot(virDomainObj *vm, } =20 =20 -/* Count how many snapshots in a set are external snapshots. */ -static int -qemuSnapshotCountExternal(void *payload, - const char *name G_GNUC_UNUSED, - void *data) -{ - virDomainMomentObj *snap =3D payload; - int *count =3D data; - - if (virDomainSnapshotIsExternal(snap)) - (*count)++; - return 0; -} - - int qemuSnapshotFSFreeze(virDomainObj *vm, const char **mountpoints, @@ -2469,26 +2454,59 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, } =20 =20 +typedef struct { + int external; + int internal; +} qemuSnapshotCount; + + +static int +qemuSnapshotCountExternalInternal(void *payload, + const char *name G_GNUC_UNUSED, + void *data) +{ + virDomainMomentObj *snap =3D payload; + qemuSnapshotCount *count =3D data; + + if (virDomainSnapshotIsExternal(snap)) { + count->external++; + } else { + count->internal++; + } + + return 0; +} + + static int qemuSnapshotDeleteValidate(virDomainMomentObj *snap, unsigned int flags) { - int external =3D 0; - - if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) && - virDomainSnapshotIsExternal(snap)) - external++; + qemuSnapshotCount count =3D { 0 }; =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | - VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { virDomainMomentForEachDescendant(snap, - qemuSnapshotCountExternal, - &external); + qemuSnapshotCountExternalInternal, + &count); + } =20 - if (external) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("deletion of %d external disk snapshots not " - "supported yet"), external); + if (count.external > 0 && count.internal > 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of external and internal children disk = snapshots not supported")); + return -1; + } + + if (count.external > 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of external children disk snapshots not= supported")); + return -1; + } + + if (virDomainSnapshotIsExternal(snap) && + !(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("deletion of external disk snapshots not supporte= d")); return -1; } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272455; cv=none; d=zohomail.com; s=zohoarc; b=NqZXvrR7tVYLsXX0+1m1EtiJ/mD12cWQrSQUK65ZhlVEudKl2Rce/SkwDc5QZz1IRV7P0x//EUghkaS9D4lqct9ERv8QJrRvB3v/binn99mmz1W6FsYHbQ0THgn3rtu2f+HjvPbu1IoQplvkIjxDD6aHzsUpz3SVVC6uGLAkldQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272455; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZT3HKMYXzU3gtCtXMxhLD/1ixCgKIYLDqTJIpW2RHLA=; b=T4UjSdrQhm8FmDyqf1dRaKFQbQBRhT4wOOS4Z1aoM0t4g+goPnC0oVxd9dJ9jm0eCp2rT/PpylZfZ3NF+/IqzZ421yzqAnSxuxvSZK/BvBOtPQ1zbxAmZRJr7kcQuY5e1sGI4B+pqXnwrEjmdZYAbPW40K1N6iDG8dgNxXsL/8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272455566789.5925251085099; Tue, 23 Aug 2022 09:34:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-PUFEGCnyPTmrfbvIKh9ROQ-1; Tue, 23 Aug 2022 12:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D378382C96C; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 657C8C15BB3; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5A4C21946A5E; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 97EAC1946A67 for ; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 861C1403357; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26ACC40315A for ; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272453; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZT3HKMYXzU3gtCtXMxhLD/1ixCgKIYLDqTJIpW2RHLA=; b=dLgOvKaQNxoiS4wyXQcl9u7zK9DkwJ1UDLD6Dajgm3uSIQCau1lEwiFbu4NQrybT+JcpdM RVUfHp6XpOXsotA1ueDNSy7y193hXfkNOykaCIZWhW9D2rPZFTPrv0PXx/oLtkio9L0UDX F2aUJQ3EWTB85O7Vli94bQx6NrkjDTQ= X-MC-Unique: PUFEGCnyPTmrfbvIKh9ROQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 20/24] qemu_snapshot: prepare data for external snapshot deletion Date: Tue, 23 Aug 2022 18:32:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272455878100001 Content-Type: text/plain; charset="utf-8"; x-default="true" In order to save some CPU cycles we will collect all the necessary data to delete external snapshot before we even start. They will be later used by code that deletes the snapshots and updates metadata when needed. With external snapshots we need data that libvirt gets from running QEMU process so if the VM is not running we need to start paused QEMU process for the snapshot deletion and kill at afterwards. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 144 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index da9b4c30f0..dade5dcea4 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2232,6 +2232,120 @@ qemuSnapshotRevert(virDomainObj *vm, } =20 =20 +typedef struct { + virDomainMomentObj *parentSnap; + virDomainSnapshotDiskDef *snapDisk; + virDomainDiskDef *domDisk; + virDomainDiskDef *parentDomDisk; + virStorageSource *diskSrc; + virStorageSource *parentDiskSrc; + virStorageSource *prevDiskSrc; + qemuBlockJobData *job; +} qemuSnapshotDeleteExternalData; + + +static virDomainMomentObj* +qemuSnapshotFindParentSnapForDisk(virDomainMomentObj *snap, + virDomainSnapshotDiskDef *snapDisk) +{ + virDomainMomentObj *parentSnap =3D snap->parent; + + while (parentSnap) { + ssize_t i; + virDomainSnapshotDef *parentSnapdef =3D virDomainSnapshotObjGetDef= (parentSnap); + + if (!parentSnapdef) + break; + + for (i =3D 0; i < parentSnapdef->ndisks; i++) { + virDomainSnapshotDiskDef *parentSnapDisk =3D &(parentSnapdef->= disks[i]); + + if (parentSnapDisk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION= _NO && + STREQ(snapDisk->name, parentSnapDisk->name)) { + return parentSnap; + } + } + + parentSnap =3D parentSnap->parent; + } + + return NULL; +} + + +static GPtrArray* +qemuSnapshotDeleteExternalPrepare(virDomainObj *vm, + virDomainMomentObj *snap) +{ + ssize_t i; + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); + g_autoptr(GPtrArray) ret =3D g_ptr_array_new_full(0, g_free); + + for (i =3D 0; i < snapdef->ndisks; i++) { + g_autofree qemuSnapshotDeleteExternalData *data =3D NULL; + virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); + + if (snapDisk->snapshot =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_NO) + continue; + + data =3D g_new0(qemuSnapshotDeleteExternalData, 1); + data->snapDisk =3D snapDisk; + + data->domDisk =3D qemuDomainDiskByName(vm->def, snapDisk->name); + if (!data->domDisk) + return NULL; + + data->diskSrc =3D virStorageSourceChainLookup(data->domDisk->src, = NULL, + data->snapDisk->src->p= ath, + NULL, &data->prevDiskS= rc); + if (!data->diskSrc) + return NULL; + + if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapDisk-= >src)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("VM disk source and snapshot disk source are = not the same")); + return NULL; + } + + data->parentDomDisk =3D virDomainDiskByTarget(snapdef->parent.dom, + data->snapDisk->name); + if (!data->parentDomDisk) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("failed to find disk '%s' in snapshot VM XML"= ), + snapDisk->name); + return NULL; + } + + data->parentDiskSrc =3D data->diskSrc->backingStore; + if (!data->parentDiskSrc) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("failed to find parent disk source in backing= chain")); + return NULL; + } + + if (!virStorageSourceIsSameLocation(data->parentDiskSrc, data->par= entDomDisk->src)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("snapshot VM disk source and parent disk sour= ce are not the same")); + return NULL; + } + + data->parentSnap =3D qemuSnapshotFindParentSnapForDisk(snap, data-= >snapDisk); + + if (data->parentSnap && !virDomainSnapshotIsExternal(data->parentS= nap)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("parent snapshot '%s' for disk '%s' is intern= al snapshot"), + snapDisk->name, + data->parentSnap->def->name); + return NULL; + } + + g_ptr_array_add(ret, g_steal_pointer(&data)); + } + + return g_steal_pointer(&ret); +} + + typedef struct _virQEMUMomentReparent virQEMUMomentReparent; struct _virQEMUMomentReparent { const char *dir; @@ -2504,9 +2618,9 @@ qemuSnapshotDeleteValidate(virDomainMomentObj *snap, } =20 if (virDomainSnapshotIsExternal(snap) && - !(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { + (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("deletion of external disk snapshots not supporte= d")); + _("deletion of external disk snapshot with internal= children disk snapshots not supported")); return -1; } =20 @@ -2523,6 +2637,8 @@ qemuSnapshotDelete(virDomainObj *vm, int ret =3D -1; virDomainMomentObj *snap =3D NULL; bool metadata_only =3D !!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_= ONLY); + bool stop_qemu =3D false; + g_autoptr(GPtrArray) externalData =3D NULL; =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY | @@ -2537,6 +2653,25 @@ qemuSnapshotDelete(virDomainObj *vm, if (!metadata_only) { if (qemuSnapshotDeleteValidate(snap, flags) < 0) goto endjob; + + if (virDomainSnapshotIsExternal(snap) && + !(flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | + VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))) { + if (!virDomainObjIsActive(vm)) { + if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB= _NONE, + NULL, -1, NULL, NULL, + VIR_NETDEV_VPORT_PROFILE_OP_CREATE, + VIR_QEMU_PROCESS_START_PAUSED) < 0) { + goto endjob; + } + + stop_qemu =3D true; + } + + externalData =3D qemuSnapshotDeleteExternalPrepare(vm, snap); + if (!externalData) + goto endjob; + } } =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | @@ -2547,6 +2682,11 @@ qemuSnapshotDelete(virDomainObj *vm, } =20 endjob: + if (stop_qemu) { + qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN, + VIR_ASYNC_JOB_NONE, 0); + } + qemuDomainObjEndJob(vm); =20 return ret; --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272509; cv=none; d=zohomail.com; s=zohoarc; b=n0VwjeBswLpYUfC77k5EdZ6F2vx1Ov9ZMz9gGqnDYjakvOItGKxgKNQGH8ooKlFOFo2mA3RlWcbB45X6MhfWxDAIXuXMLcnkWrpNUcACn0PXG2jp1vFxUf8xq/0dGDRQzews1WZoC7hh7ZMkaUhXb/+L7xIxAp9D6o+V9MbOACc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272509; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v+HYVtbcgrVGmkJ4IRRKH3a5GPsQwq/DvmhbviKNV0Y=; b=MIGxXxLOUswAhN8I1c4Sq2XOI3cX9Qqj565TAbp9Qao7CBlN/bcjglfv4vr8cVQGbp8xAQoXfgH3NiaDZHZ7AqptQUbure+iTDjT6pPEt2XuHS5hZ9SwxcAVuwrrplToApzlLGLfumUSSUmV66wMnpr5C+GF8h72CWZtU1fNnwM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272509189727.6907483267495; Tue, 23 Aug 2022 09:35:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-157-hmHyH6I0N7WJb-XNH9tI9g-1; Tue, 23 Aug 2022 12:33:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C07BA85A585; Tue, 23 Aug 2022 16:32:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC2F82026D4C; Tue, 23 Aug 2022 16:32:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 84A091946A58; Tue, 23 Aug 2022 16:32:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 44DAD1946A40 for ; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 30F4240315A; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id C43B3403349 for ; Tue, 23 Aug 2022 16:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272508; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=v+HYVtbcgrVGmkJ4IRRKH3a5GPsQwq/DvmhbviKNV0Y=; b=K1LQPoE7A/Rorwber2wmmjqkaf0Stb9DezvNgsO5gPpUWo5i8YBbzApp+vxo1LaCYXFkRw XnMHAvKaqSVRx4r03WjakZ/H3f9GMdsQxNTWbE5qdtvWmquiuInqajLjbd40mEb4ajv7Y8 XlRtLbAs9ZPtSXjxroH/dQXi0yfk/Gg= X-MC-Unique: hmHyH6I0N7WJb-XNH9tI9g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 21/24] qemu_snapshot: implement deletion of external snapshot Date: Tue, 23 Aug 2022 18:32:24 +0200 Message-Id: <5260562e0e77aae8e772ad92f29f0355e6f4c2a8.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272510193100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When deleting snapshot we are starting block-commit job over all disks that are part of the snapshot. This operation may fail as it writes data changes to the backing qcow2 image so we need to wait for all the disks to finish the operation and wait for correct signal from QEMU. If deleting active snapshot we will get `ready` signal and for inactive snapshots we need to disable autofinalize in order to get `pending` signal. At this point if commit for any disk fails for some reason and we abort the VM is still in consistent state and user can fix the reason why the deletion failed. After that we do `pivot` or `finalize` if it's active snapshot or not to finish the block job. It still may fail but there is nothing else we can do about it. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 163 +++++++++++++++++++++++++++++++++++---- 1 file changed, 147 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index dade5dcea4..64ee395230 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2380,6 +2380,114 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 +static int +qemuSnapshotJobRunning(virDomainObj *vm, + qemuBlockJobData *job) +{ + qemuBlockJobUpdate(vm, job, VIR_ASYNC_JOB_NONE); + + while (job->state !=3D QEMU_BLOCKJOB_STATE_READY && + job->state !=3D QEMU_BLOCKJOB_STATE_PENDING && + job->state !=3D QEMU_BLOCKJOB_STATE_FAILED && + job->state !=3D QEMU_BLOCKJOB_STATE_CANCELLED && + job->state !=3D QEMU_BLOCKJOB_STATE_COMPLETED) { + if (qemuDomainObjWait(vm) < 0) + return -1; + qemuBlockJobUpdate(vm, job, VIR_ASYNC_JOB_NONE); + } + + return 0; +} + + +static int +qemuSnapshotJobFinishing(virDomainObj *vm, + qemuBlockJobData *job) +{ + qemuBlockJobUpdate(vm, job, VIR_ASYNC_JOB_NONE); + + while (job->state !=3D QEMU_BLOCKJOB_STATE_READY && + job->state !=3D QEMU_BLOCKJOB_STATE_FAILED && + job->state !=3D QEMU_BLOCKJOB_STATE_CANCELLED && + job->state !=3D QEMU_BLOCKJOB_STATE_COMPLETED) { + if (qemuDomainObjWait(vm) < 0) + return -1; + qemuBlockJobUpdate(vm, job, VIR_ASYNC_JOB_NONE); + } + + return 0; +} + + +static int +qemuSnapshotDiscardExternal(virDomainObj *vm, + virQEMUDriver *driver, + GPtrArray *externalData) +{ + ssize_t i; + + for (i =3D 0; i < externalData->len; i++) { + qemuSnapshotDeleteExternalData *data =3D g_ptr_array_index(externa= lData, i); + virTristateBool autofinalize =3D VIR_TRISTATE_BOOL_NO; + unsigned int commitFlags =3D VIR_DOMAIN_BLOCK_COMMIT_DELETE; + + if (data->domDisk->src =3D=3D data->diskSrc) { + commitFlags |=3D VIR_DOMAIN_BLOCK_COMMIT_ACTIVE; + autofinalize =3D VIR_TRISTATE_BOOL_YES; + } + + if (qemuBlockCommitImpl(vm, driver, + data->domDisk, + data->parentDiskSrc, + data->diskSrc, + data->prevDiskSrc, + 0, true, autofinalize, commitFlags) < 0) { + return -1; + } + + data->job =3D qemuBlockJobDiskGetJob(data->domDisk); + if (!data->job) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("disk '%s' does not have an active block job"= ), + data->domDisk->dst); + return -1; + } + } + + for (i =3D 0; i < externalData->len; i++) { + qemuSnapshotDeleteExternalData *data =3D g_ptr_array_index(externa= lData, i); + + if (qemuSnapshotJobRunning(vm, data->job) < 0) + return -1; + + if (data->job->state =3D=3D QEMU_BLOCKJOB_STATE_FAILED) + return -1; + } + + for (i =3D 0; i < externalData->len; i++) { + qemuSnapshotDeleteExternalData *data =3D g_ptr_array_index(externa= lData, i); + + if (data->job->state =3D=3D QEMU_BLOCKJOB_STATE_READY) { + if (qemuBlockPivot(vm, data->job, NULL) < 0) + return -1; + } else if (data->job->state =3D=3D QEMU_BLOCKJOB_STATE_PENDING) { + if (qemuBlockFinalize(vm, data->job) < 0) + return -1; + } + + if (qemuSnapshotJobFinishing(vm, data->job) < 0) + return -1; + + if (data->job->state =3D=3D QEMU_BLOCKJOB_STATE_FAILED) + return -1; + + qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_NONE); + } + + return 0; +} + + static int qemuSnapshotDiscardMetadata(virDomainObj *vm, virDomainMomentObj *snap, @@ -2443,11 +2551,12 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, =20 /* Discard one snapshot (or its metadata), without reparenting any childre= n. */ static int -qemuSnapshotDiscard(virQEMUDriver *driver, - virDomainObj *vm, - virDomainMomentObj *snap, - bool update_parent, - bool metadata_only) +qemuSnapshotDiscardImpl(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap, + GPtrArray *externalData, + bool update_parent, + bool metadata_only) { qemuDomainObjPrivate *priv; =20 @@ -2469,14 +2578,24 @@ qemuSnapshotDiscard(virQEMUDriver *driver, return -1; } =20 - if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d", tr= ue) < 0) - return -1; + if (virDomainSnapshotIsExternal(snap)) { + if (qemuSnapshotDiscardExternal(vm, driver, externalData) = < 0) + return -1; + } else { + if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d"= , true) < 0) + return -1; + } } else { - priv =3D vm->privateData; - qemuDomainObjEnterMonitor(vm); - /* we continue on even in the face of error */ - qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); - qemuDomainObjExitMonitor(vm); + if (virDomainSnapshotIsExternal(snap)) { + if (qemuSnapshotDiscardExternal(vm, driver, externalData) = < 0) + return -1; + } else { + priv =3D vm->privateData; + qemuDomainObjEnterMonitor(vm); + /* we continue on even in the face of error */ + qemuMonitorDeleteSnapshot(priv->mon, snap->def->name); + qemuDomainObjExitMonitor(vm); + } } } =20 @@ -2487,6 +2606,17 @@ qemuSnapshotDiscard(virQEMUDriver *driver, } =20 =20 +static int +qemuSnapshotDiscard(virQEMUDriver *driver, + virDomainObj *vm, + virDomainMomentObj *snap, + bool update_parent, + bool metadata_only) +{ + return qemuSnapshotDiscardImpl(driver, vm, snap, NULL, update_parent, = metadata_only); +} + + int qemuSnapshotDiscardAllMetadata(virQEMUDriver *driver, virDomainObj *vm) @@ -2509,9 +2639,10 @@ static int qemuSnapshotDeleteSingle(virDomainObj *vm, virDomainMomentObj *snap, virQEMUDriver *driver, + GPtrArray *externalData, bool metadata_only) { - return qemuSnapshotDiscard(driver, vm, snap, true, metadata_only); + return qemuSnapshotDiscardImpl(driver, vm, snap, externalData, true, m= etadata_only); } =20 =20 @@ -2532,7 +2663,7 @@ qemuSnapshotDeleteAll(void *payload, virDomainMomentObj *snap =3D payload; struct qemuSnapshotDeleteAllData *data =3D opaque; =20 - error =3D qemuSnapshotDeleteSingle(data->vm, snap, data->driver, + error =3D qemuSnapshotDeleteSingle(data->vm, snap, data->driver, NULL, data->metadata_only); =20 if (error !=3D 0 && data->error !=3D 0) @@ -2561,7 +2692,7 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, return -1; =20 if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { - return qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only); + return qemuSnapshotDeleteSingle(vm, snap, driver, NULL, metadata_o= nly); } =20 return 0; @@ -2678,7 +2809,7 @@ qemuSnapshotDelete(virDomainObj *vm, VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { ret =3D qemuSnapshotDeleteChildren(vm, snap, driver, metadata_only= , flags); } else { - ret =3D qemuSnapshotDeleteSingle(vm, snap, driver, metadata_only); + ret =3D qemuSnapshotDeleteSingle(vm, snap, driver, externalData, m= etadata_only); } =20 endjob: --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272450; cv=none; d=zohomail.com; s=zohoarc; b=cZPoIi/xbNLqaoKEM+uCt7+VtqLMXdYEOtV3g/DXN1RC2wBFi+0Wp2QJ0upD8QrlK6LNyvn0r2D2LTg+s7jZi+r3qrO7QBl3SLFd6vvpaGyieWOBm6sM3MOkn3HaGmMGVo7ktizA0kUORbFAngiZRtjPbyRhWa545T6sw1zahmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272450; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RzeamUlG8wDkNVQJfic2v7EzPQXig5gkzAv93+xcXBw=; b=HuWubPIxwjZTUjnrbB8F9tE938pDwmj76BPTDLmElI7WWoSErjq3BYiKYW+85eISFtq8/vJZNMHly3rVrHQWG5OdyxAZz3cBcOJfwakb2QTF8d3y3iuzz/FE0nISQRv2eKbe9ciitWhmMq9XgJLZFmoQlSHV+VHSprZCPRgQrnY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 166127245076269.7725427733343; Tue, 23 Aug 2022 09:34:10 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-EQaJ1PwUNoeCSSw9PiR75g-1; Tue, 23 Aug 2022 12:33:10 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 056CF382C972; Tue, 23 Aug 2022 16:32:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4736492C3B; Tue, 23 Aug 2022 16:32:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B6C4A1946A5A; Tue, 23 Aug 2022 16:32:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E80701946A40 for ; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CE28E403349; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CD59492C3B for ; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272449; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=RzeamUlG8wDkNVQJfic2v7EzPQXig5gkzAv93+xcXBw=; b=grnsE8xAJ6nqS5CH1Ivv30FTl8ClFW9upC2wrV6znoJzWEZfZm0DGGhVmorypxtZe/py0y bfD3JXimmw4bmCmFZ9yg1yw7BwsTjD4stIgJ6/dgEbJ4HfyPRhzTZ/CJ7RcLyKVJPIE2HD I/RgSjUF4pHWBlPNTd098AxmFOiegWE= X-MC-Unique: EQaJ1PwUNoeCSSw9PiR75g-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 22/24] qemu_snapshot: update metadata when deleting snapshots Date: Tue, 23 Aug 2022 18:32:25 +0200 Message-Id: <3630384242f7dacf3b44d3ee7b16322111347c39.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272451795100001 Content-Type: text/plain; charset="utf-8"; x-default="true" With external snapshots we need to modify the metadata bit more then what is required for internal snapshots. Mainly the storage source location changes with every external snapshot. This means that if we delete non-leaf snapshot we need to update all children snapshots and modify the disk sources for all affected disks. Signed-off-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 116 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 64ee395230..37ae3f04d0 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2380,6 +2380,109 @@ qemuSnapshotChildrenReparent(void *payload, } =20 =20 +typedef struct _qemuSnapshotUpdateDisksData qemuSnapshotUpdateDisksData; +struct _qemuSnapshotUpdateDisksData { + virDomainMomentObj *snap; + virDomainObj *vm; + virQEMUDriver *driver; + int error; + int (*writeMetadata)(virDomainObj *, virDomainMomentObj *, + virDomainXMLOption *, const char *); +}; + + +static int +qemuSnapshotUpdateDisksSingle(virDomainMomentObj *snap, + virDomainDef *def, + virDomainDef *parentDef, + virDomainSnapshotDiskDef *snapDisk) +{ + virDomainDiskDef *disk =3D NULL; + + if (!(disk =3D qemuDomainDiskByName(def, snapDisk->name))) + return -1; + + if (virDomainSnapshotIsExternal(snap)) { + virDomainDiskDef *parentDisk =3D NULL; + + if (!(parentDisk =3D qemuDomainDiskByName(parentDef, snapDisk->nam= e))) + return -1; + + if (virStorageSourceIsSameLocation(snapDisk->src, disk->src)) { + virObjectUnref(disk->src); + disk->src =3D virStorageSourceCopy(parentDisk->src, false); + } + } + + if (disk->src->backingStore) { + virStorageSource *cur =3D disk->src; + virStorageSource *next =3D disk->src->backingStore; + + while (next) { + if (virStorageSourceIsSameLocation(snapDisk->src, next)) { + cur->backingStore =3D next->backingStore; + next->backingStore =3D NULL; + virObjectUnref(next); + break; + } + + cur =3D next; + next =3D cur->backingStore; + } + } + + return 0; +} + + +static int +qemuSnapshotDeleteUpdateDisks(void *payload, + const char *name G_GNUC_UNUSED, + void *opaque) +{ + virDomainMomentObj *snap =3D payload; + qemuSnapshotUpdateDisksData *data =3D opaque; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(data->dr= iver); + virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(data->sna= p); + ssize_t i; + + if (data->error < 0) + return 0; + + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); + + if (snapDisk->snapshot =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_NO) + continue; + + if (qemuSnapshotUpdateDisksSingle(snap, snap->def->dom, + data->snap->def->dom, snapDisk) = < 0) { + data->error =3D -1; + return 0; + } + + if (snap->def->inactiveDom) { + virDomainDef *dom =3D data->snap->def->inactiveDom; + + if (!dom) + dom =3D data->snap->def->dom; + + if (qemuSnapshotUpdateDisksSingle(snap, snap->def->inactiveDom, + dom, snapDisk) < 0) { + data->error =3D -1; + return 0; + } + } + } + + data->error =3D data->writeMetadata(data->vm, + snap, + data->driver->xmlopt, + cfg->snapshotDir); + return 0; +} + + static int qemuSnapshotJobRunning(virDomainObj *vm, qemuBlockJobData *job) @@ -2500,6 +2603,7 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, =20 if (update_parent && snap->nchildren) { virQEMUMomentReparent rep; + qemuSnapshotUpdateDisksData data; =20 rep.dir =3D cfg->snapshotDir; rep.parent =3D snap->parent; @@ -2512,6 +2616,18 @@ qemuSnapshotDiscardMetadata(virDomainObj *vm, &rep); if (rep.err < 0) return -1; + + data.snap =3D snap; + data.driver =3D driver; + data.vm =3D vm; + data.error =3D 0; + data.writeMetadata =3D qemuDomainSnapshotWriteMetadata; + virDomainMomentForEachDescendant(snap, + qemuSnapshotDeleteUpdateDisks, + &data); + if (data.error < 0) + return -1; + virDomainMomentMoveChildren(snap, snap->parent); } =20 --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272515; cv=none; d=zohomail.com; s=zohoarc; b=iJJWGyO1awORgs7VsPXAWsw31yGv6j3MiMLKCgyrG4vQeSPOhVSwSmmisU2sWzcWdclFj3TvZWzXvSGXrhEw8qPx2fIM3OKta0smgjtMSwXdLrC4o9DAMhskdC3q3Izxk/NVIzeB4rlvMtDNvNwNB9a4gQJADQzRV7YhAkPv6QU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272515; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Eh5Of1RzQW6p0p5IrbAkZLbiV/lNmEtukL6RcD7ObfI=; b=jzkMzbbtxGMNjif5ab3ml8yJ45afuR285x3LNAbn1qGNwpsHQDP7DKyWiSChHrIr4ryDWSE0Hu7jeiRYGyMBU/Q1/7pjIJAp+/b+LuXbH6X4TXAOh5O1sfP8uqthhIllt9HLtaIRPrc9aXtTBaodUkK4sZ8HVLDjU/bTXXU4Rro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272515980420.1199677589875; Tue, 23 Aug 2022 09:35:15 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-262-VH3Ji4YpN1We2qIYX73iAw-1; Tue, 23 Aug 2022 12:33:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 074421C0BC88; Tue, 23 Aug 2022 16:32:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E588A112132D; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C8E7B1946A63; Tue, 23 Aug 2022 16:32:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8107F1946A5A for ; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 7690840315A; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17EAD492C3B for ; Tue, 23 Aug 2022 16:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272514; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Eh5Of1RzQW6p0p5IrbAkZLbiV/lNmEtukL6RcD7ObfI=; b=XMWG+NpHEv3KcE7oVXf6G5u9AKjkEV0J/pSfSpFrAT8aqXO/WMBtI0F2T8zh7detIjddQi zJX/p2vFwLSokW2VnSgv6g2KtkY+1mEHVsbiJ0MvlShinGv0WtjmzfNrZMOuiy2Jcyk0k6 pzuVh09BdLJ8t99Zt/9Y8BmjdpUldVw= X-MC-Unique: VH3Ji4YpN1We2qIYX73iAw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 23/24] qemu_snapshot: when deleting snapshot invalidate parent snapshot Date: Tue, 23 Aug 2022 18:32:26 +0200 Message-Id: <7189ec43e3ac3439e87f15c573dc54739c4f8a29.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272518123100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When deleting external snapshots the operation may fail at any point which could lead to situation that some disks finished the block commit operation but for some disks it failed and the libvirt job ends. In order to make sure that the qcow2 images are in consistent state introduce new element "" that will mark the disk in snapshot metadata as invalid until the snapshot delete is completed successfully. This will prevent deleting snapshot with the invalid disk and in future reverting to snapshot with the invalid disk. Signed-off-by: Pavel Hrdina --- src/conf/snapshot_conf.c | 5 +++++ src/conf/snapshot_conf.h | 1 + src/qemu/qemu_snapshot.c | 42 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index ae635edd08..155da42862 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -158,6 +158,8 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, return -1; } =20 + def->invalid =3D !!virXPathNode("./invalid", ctxt); + if ((cur =3D virXPathNode("./source", ctxt)) && virDomainStorageSourceParse(cur, ctxt, src, flags, xmlopt) < 0) return -1; @@ -761,6 +763,9 @@ virDomainSnapshotDiskDefFormat(virBuffer *buf, virBufferAsprintf(&attrBuf, " snapshot=3D'%s'", virDomainSnapshotLocationTypeToString(disk->snap= shot)); =20 + if (disk->invalid) + virBufferAddLit(&childBuf, "\n"); + if (disk->src->path || disk->src->format !=3D 0) { g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) driverChildBuf =3D VIR_BUFFER_INIT_CHILD(&childB= uf); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 1f787f1a94..de6e420f77 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -52,6 +52,7 @@ typedef struct _virDomainSnapshotDiskDef virDomainSnapsho= tDiskDef; struct _virDomainSnapshotDiskDef { char *name; /* name matching the snapshot =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_NO) continue; =20 + if (snapDisk->invalid) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("snapshot is in invalid state")); + return NULL; + } + data =3D g_new0(qemuSnapshotDeleteExternalData, 1); data->snapDisk =3D snapDisk; =20 @@ -2522,6 +2528,36 @@ qemuSnapshotJobFinishing(virDomainObj *vm, } =20 =20 +static int +qemuSnapshotSetInvalid(virDomainObj *vm, + virDomainMomentObj *snap, + virDomainSnapshotDiskDef *disk, + bool invalid) +{ + ssize_t i; + qemuDomainObjPrivate *priv =3D vm->privateData; + virQEMUDriver *driver =3D priv->driver; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + virDomainSnapshotDef *snapdef =3D NULL; + + if (!snap) + return 0; + + snapdef =3D virDomainSnapshotObjGetDef(snap); + if (!snapdef) + return 0; + + for (i =3D 0; i < snapdef->ndisks; i++) { + virDomainSnapshotDiskDef *snapDisk =3D &(snapdef->disks[i]); + + if (STREQ(snapDisk->name, disk->name)) + snapDisk->invalid =3D invalid; + } + + return qemuDomainSnapshotWriteMetadata(vm, snap, driver->xmlopt, cfg->= snapshotDir); +} + + static int qemuSnapshotDiscardExternal(virDomainObj *vm, virQEMUDriver *driver, @@ -2539,6 +2575,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, autofinalize =3D VIR_TRISTATE_BOOL_YES; } =20 + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, t= rue) < 0) + return -1; + if (qemuBlockCommitImpl(vm, driver, data->domDisk, data->parentDiskSrc, @@ -2585,6 +2624,9 @@ qemuSnapshotDiscardExternal(virDomainObj *vm, return -1; =20 qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_NONE); + + if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, f= alse) < 0) + return -1; } =20 return 0; --=20 2.37.2 From nobody Fri May 17 05:26:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1661272446; cv=none; d=zohomail.com; s=zohoarc; b=kvzzxJQjX9urjxMOpP1MtLVcktIUkylzR7kbeJ+qn0FY9tP4Cx+IlNvws68ZdqQIZOekUW6pXOAVjqYURgnP0dV38qWXbsutENWLRMlceqV/z0pZ6hs9okcibnO0Rv+e+oPIYo4X6xEZW7+EDr72MsS9lo9UCYxJYewHYrSu3EQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661272446; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ej0p97fT8KPBX1ZOBQ12MLDQNpYF2vfuK7KP/++lXgg=; b=f3YeiNklb4fT2mOI7M5+EgOcvXENCtZH6kqUmii+2cbCJETFj2yse5HzUEjSUISgcg0vnTjFB44WDp+zUMmhutnZxUWsFTcBnE3rxIa9GG1exhCyvG/TUQ957aVqCDTGt0Rb8smv978/xg6o4CMo5/HlLzX1imlGLBXqScj3VdQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1661272446631768.550703025147; Tue, 23 Aug 2022 09:34:06 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-96-AgqaOsZ2NH-Yp9JtuCf38Q-1; Tue, 23 Aug 2022 12:33:07 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DCEA851790; Tue, 23 Aug 2022 16:32:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5341B2166B2A; Tue, 23 Aug 2022 16:32:51 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 318471946A5C; Tue, 23 Aug 2022 16:32:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3ABC81946A40 for ; Tue, 23 Aug 2022 16:32:49 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2EFF6492C3B; Tue, 23 Aug 2022 16:32:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id C371B40315A for ; Tue, 23 Aug 2022 16:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661272445; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Ej0p97fT8KPBX1ZOBQ12MLDQNpYF2vfuK7KP/++lXgg=; b=JE8xqxvsFeMXmv1wbto/r2JgJmX6ZvTFyyKPkR3S+4EDXB+fDQikQnTdTnX1dG3ejAE90i cQq/UvBMzlOzlbMnMBiPnNrAE9NPlv5iPuhU9cDvFm1IATH2fmgJui4IJUQ+izbnHBoSO+ QAyd7hxozQmjnp6xv4MIMguPTCTpkZc= X-MC-Unique: AgqaOsZ2NH-Yp9JtuCf38Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt RFC 24/24] qemu_snapshot: allow deletion of external snapshot with internal snapshot children Date: Tue, 23 Aug 2022 18:32:27 +0200 Message-Id: <39a047f8e5bbdd6d91b8cc1169e35d403ef62446.1661271812.git.phrdina@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1661272447810100002 Content-Type: text/plain; charset="utf-8"; x-default="true" --- Just example how we could support this specific use-case where snapshot in question is external and all children are only internal. But I would rather drop this patch and in the following patch series drop support for both children flags completely as users or management applications can to that themselves. src/qemu/qemu_snapshot.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 29d147f834..092bec6cc2 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2835,6 +2835,7 @@ static int qemuSnapshotDeleteChildren(virDomainObj *vm, virDomainMomentObj *snap, virQEMUDriver *driver, + GPtrArray *externalData, bool metadata_only, unsigned int flags) { @@ -2850,7 +2851,7 @@ qemuSnapshotDeleteChildren(virDomainObj *vm, return -1; =20 if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) { - return qemuSnapshotDeleteSingle(vm, snap, driver, NULL, metadata_o= nly); + return qemuSnapshotDeleteSingle(vm, snap, driver, externalData, me= tadata_only); } =20 return 0; @@ -2906,13 +2907,6 @@ qemuSnapshotDeleteValidate(virDomainMomentObj *snap, return -1; } =20 - if (virDomainSnapshotIsExternal(snap) && - (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("deletion of external disk snapshot with internal= children disk snapshots not supported")); - return -1; - } - return 0; } =20 @@ -2943,9 +2937,7 @@ qemuSnapshotDelete(virDomainObj *vm, if (qemuSnapshotDeleteValidate(snap, flags) < 0) goto endjob; =20 - if (virDomainSnapshotIsExternal(snap) && - !(flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | - VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY))) { + if (virDomainSnapshotIsExternal(snap)) { if (!virDomainObjIsActive(vm)) { if (qemuProcessStart(NULL, driver, vm, NULL, VIR_ASYNC_JOB= _NONE, NULL, -1, NULL, NULL, @@ -2965,7 +2957,8 @@ qemuSnapshotDelete(virDomainObj *vm, =20 if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN | VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) { - ret =3D qemuSnapshotDeleteChildren(vm, snap, driver, metadata_only= , flags); + ret =3D qemuSnapshotDeleteChildren(vm, snap, driver, externalData, + metadata_only, flags); } else { ret =3D qemuSnapshotDeleteSingle(vm, snap, driver, externalData, m= etadata_only); } --=20 2.37.2