From nobody Mon Feb 9 12:43:16 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=quarantine dis=quarantine) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1604404908; cv=none; d=zohomail.com; s=zohoarc; b=lXyniVGmDK0TIiUN2ruhmtA5xGgXH8uM0/Salh3WWC4hcTV9tT89NeaLwCYzqXPh+c2wddK/bZJcmW1JWHK5kBy2i4xU2tnTEkMp5s17lEXL/BctTJ8wlx8HsH/XLU17mEgOBx0hsCYXsxinydjuMe3KP3S5fyehpyc0FzjSANE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604404908; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=mE2ob7ygtuHdx9TXp15nhVrB4pb/3GmUF5WF0YHdLfs=; b=DU1hPpkq4fpyi6PUAnm1kVEd9dhndit3jvUma2t0KI8SZKJ0f5iMVBI8ibl7j2w9N/kSCwxw7E4GtGKG7kE7Xzut3a4fC1K9PUn3/GGnfleGgDbBmJ+DnQWxb8cu+ygYcMr4yCgt4cb519UwogaU/wtEFihYjz3wnCIeCwWup7s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=quarantine dis=quarantine) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1604404908770178.44729218626253; Tue, 3 Nov 2020 04:01:48 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-536-ddpbtoCrPp-4fjkWEmw1NQ-1; Tue, 03 Nov 2020 07:01:43 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E75BF10A0B81; Tue, 3 Nov 2020 12:01:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3B8C1002D48; Tue, 3 Nov 2020 12:01:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8B87C181A06C; Tue, 3 Nov 2020 12:01:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0A3C1ZXh011594 for ; Tue, 3 Nov 2020 07:01:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 991F7110E9B8; Tue, 3 Nov 2020 12:01:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9559C110E9B6 for ; Tue, 3 Nov 2020 12:01:33 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41E00185A78B for ; Tue, 3 Nov 2020 12:01:33 +0000 (UTC) Received: from relay3.sw.ru (relay.sw.ru [185.231.240.75]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-202-RzMrQYa0NRaDoCa28ZAYqQ-1; Tue, 03 Nov 2020 07:01:30 -0500 Received: from [10.28.15.159] (helo=vz7.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kZuzs-007EMR-0t for libvir-list@redhat.com; Tue, 03 Nov 2020 15:01:08 +0300 X-MC-Unique: ddpbtoCrPp-4fjkWEmw1NQ-1 X-MC-Unique: RzMrQYa0NRaDoCa28ZAYqQ-1 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Subject: [PATCH v2 04/10] qemu: remove duplicate code for removing remnant files Date: Tue, 3 Nov 2020 15:00:02 +0300 Message-Id: <1604404808-825155-5-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1604404808-825155-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1604404808-825155-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch also changes functionality a bit. First if unlinking of old config file is failed we rollback and return error previously and now we return success. I don't think this makes much differe= nce. I guess in both cases on libvirtd restart we have to deal with both new and= old config existing on disk with different names but same uuid. Second if unlinking of old autolink is failed we rollback previously which was not right as at this point we already unlink old config file. So this is fixed now. Signed-off-by: Nikolay Shirokovskiy --- src/qemu/qemu_domain.c | 29 +++++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 5 +++++ src/qemu/qemu_driver.c | 39 ++++++++------------------------------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d7dbca4..7b2c165 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11094,3 +11094,32 @@ qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPt= r driver, =20 return 0; } + + +int +qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg, + const char *name, + bool bestEffort) +{ + g_autofree char *cfg_file =3D NULL; + g_autofree char *autostart_link =3D NULL; + + cfg_file =3D virDomainConfigFile(cfg->configDir, name); + autostart_link =3D virDomainConfigFile(cfg->autostartDir, name); + + if (virFileExists(cfg_file) && + unlink(cfg_file) < 0) { + virReportSystemError(errno, _("Failed to unlink '%s'"), cfg_file); + if (!bestEffort) + return -1; + } + + if (virFileIsLink(autostart_link) =3D=3D 1 && + unlink(autostart_link) < 0) { + virReportSystemError(errno, _("Failed to unlink '%s'"), autostart_= link); + if (!bestEffort) + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index fc69678..a2dfe86 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1050,3 +1050,8 @@ qemuDomainFileWrapperFDClose(virDomainObjPtr vm, int qemuDomainInterfaceSetDefaultQDisc(virQEMUDriverPtr driver, virDomainNetDefPtr net); + +int +qemuDomainNamePathsCleanup(virQEMUDriverConfigPtr cfg, + const char *name, + bool bestEffort); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 621facc..52c42cf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19112,6 +19112,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm, virObjectEventPtr event_new =3D NULL; virObjectEventPtr event_old =3D NULL; int ret =3D -1; + virErrorPtr err =3D NULL; g_autofree char *new_dom_name =3D NULL; g_autofree char *old_dom_name =3D NULL; g_autofree char *new_dom_cfg_file =3D NULL; @@ -19158,25 +19159,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm, new_dom_name =3D NULL; =20 if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0) - goto rollback; - - if (virFileExists(old_dom_cfg_file) && - unlink(old_dom_cfg_file) < 0) { - virReportSystemError(errno, - _("cannot remove old domain config file %s"), - old_dom_cfg_file); - goto rollback; - } - - if (vm->autostart) { - if (virFileIsLink(old_dom_autostart_link) && - unlink(old_dom_autostart_link) < 0) { - virReportSystemError(errno, - _("Failed to delete symlink '%s'"), - old_dom_autostart_link); - goto rollback; - } - } + goto cleanup; =20 event_old =3D virDomainEventLifecycleNew(vm->def->id, old_dom_name, vm= ->def->uuid, VIR_DOMAIN_EVENT_UNDEFINED, @@ -19189,23 +19172,17 @@ qemuDomainRenameCallback(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - return ret; - - rollback: - if (old_dom_name) { + if (old_dom_name && ret < 0) { new_dom_name =3D vm->def->name; vm->def->name =3D old_dom_name; old_dom_name =3D NULL; } =20 - if (virFileExists(new_dom_cfg_file)) - unlink(new_dom_cfg_file); - - if (vm->autostart && - virFileExists(new_dom_autostart_link)) - unlink(new_dom_autostart_link); - - goto cleanup; + if (ret < 0) + virErrorPreserveLast(&err); + qemuDomainNamePathsCleanup(cfg, ret < 0 ? new_dom_name : old_dom_name,= true); + virErrorRestore(&err); + return ret; } =20 static int qemuDomainRename(virDomainPtr dom, --=20 1.8.3.1