From nobody Thu May 15 13:53:15 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510080584140771.706173335441; Tue, 7 Nov 2017 10:49:44 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4AD685F15C; Tue, 7 Nov 2017 18:49:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE4CD5D9C6; Tue, 7 Nov 2017 18:49:41 +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 C97544A467; Tue, 7 Nov 2017 18:49:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA7InbWm024814 for ; Tue, 7 Nov 2017 13:49:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4BEA55D964; Tue, 7 Nov 2017 18:49:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45C125D9CD for ; Tue, 7 Nov 2017 18:49:36 +0000 (UTC) Received: from mail-qt0-f181.google.com (mail-qt0-f181.google.com [209.85.216.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1443356D6 for ; Tue, 7 Nov 2017 18:49:34 +0000 (UTC) Received: by mail-qt0-f181.google.com with SMTP id j58so304874qtj.0 for ; Tue, 07 Nov 2017 10:49:34 -0800 (PST) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id t34sm1313175qtb.79.2017.11.07.10.49.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2017 10:49:32 -0800 (PST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4AD685F15C Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4AD685F15C Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="eK07vM0v" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F1443356D6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F1443356D6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=8R4if+jaIdstWjz7sk8FQhGq22Bb9vGLKPeVMTFMtpI=; b=eK07vM0v/KlfvFq6grGWtxZxPjemZ9NuZpaahArG1LQpaQHhCKsAqfZMp3k33uiPO1 4SvsSTqZSvUUdY9rwtYczf5zVyQaidFurE8Qr8snppVfOD6f/vyP9oLe6JNaLf9vpB7S 1tBIjkFZD9nvzw92bmHWY481ubnMjtBtKsyaYlGP5vhyt7w04debLJ304t4eb2iCER0w YmnjZtAyaZxyvTAGMuymAAEplFcLBZNlOTy7t58pQOaNnYdWbrEGs9YwyA8T7rzzQBfW 2yumJQI05sVUuabnQBybOpjybm13gCCoQQIIzCZ2N1DiU0h7hkipxsq7dyXzgdtn1wGx 65pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8R4if+jaIdstWjz7sk8FQhGq22Bb9vGLKPeVMTFMtpI=; b=beqLjju1Qp+qkIcT+htHwBGKH6MO1kH8LAp021YyY4RuNy0Df6L8xZHa7oU2D9uW3f BiS7QCsTi1rTJgzR5XwTQwrcFzfGeghJohKI3RpmCT+HjfF/CfBG+PF87bcEIdU3rBCo RwsPPw7xhq95XJ792fjrYbksDS7AaOaj7xHq59bsJVdcxi60MOHUPVIDyPsvSVrhwX3k fyZ/T001zQoWGglb8J2qSm7Ir0753JQ/qeY9/qZClG+ZHYM6Bd81wIEFMT21nMJKTRWL Rpdnnp2TkXN9PhuJZU2zyoWiuM8jYH084JE0RrtALnCTVCAzuLw182eL64o1pIW4kUlP TUEQ== X-Gm-Message-State: AMCzsaXxqEzvMS5miQh6bKlPmIgyeXV3+mHzrrrYSeN7MLOHCUbcC04Z 5uM5O/0knJfVq139lBQ0h9eFY9eOtXQ= X-Google-Smtp-Source: ABhQp+SNO2jXTxpWbkbj73I2e1GwdCypQFAB3SBrwBkoae9t4ScMrJNw24byCfR6jmwBPzq4XsJvlw== X-Received: by 10.237.37.142 with SMTP id x14mr28057342qtc.6.1510080573967; Tue, 07 Nov 2017 10:49:33 -0800 (PST) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 7 Nov 2017 13:49:18 -0500 Message-Id: <20171107184930.12769-2-dzamirski@datto.com> In-Reply-To: <20171107184930.12769-1-dzamirski@datto.com> References: <20171107184930.12769-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 07 Nov 2017 18:49:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 07 Nov 2017 18:49:35 +0000 (UTC) for IP:'209.85.216.181' DOMAIN:'mail-qt0-f181.google.com' HELO:'mail-qt0-f181.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: -0.221 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.181 mail-qt0-f181.google.com 209.85.216.181 mail-qt0-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/13] vbox: Cleanup partially-defined VM on failure X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 07 Nov 2017 18:49:42 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since the VBOX API requires to register an initial VM before proceeding to attach any remaining devices to it, any failure to attach such devices should result in automatic cleanup of the initially registered VM so that the state of VBOX registry remains clean without any leftover "aborted" VMs in it. Failure to cleanup of such partial VMs results in a warning log so that actual define error stays on the top of the error stack. --- src/vbox/vbox_common.c | 52 ++++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index aa2563cf1..d93b0855f 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1821,6 +1821,8 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const ch= ar *xml, unsigned int flags char uuidstr[VIR_UUID_STRING_BUFLEN]; virDomainPtr ret =3D NULL; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + bool machineReady =3D false; + =20 virCheckFlags(VIR_DOMAIN_DEFINE_VALIDATE, NULL); =20 @@ -1830,12 +1832,11 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int flags if (!data->vboxObj) return ret; =20 - VBOX_IID_INITIALIZE(&mchiid); if (!(def =3D virDomainDefParseString(xml, data->caps, data->xmlopt, - NULL, parse_flags))) { - goto cleanup; - } + NULL, parse_flags))) + return ret; =20 + VBOX_IID_INITIALIZE(&mchiid); virUUIDFormat(def->uuid, uuidstr); =20 rc =3D gVBoxAPI.UIVirtualBox.CreateMachine(data, def, &machine, uuidst= r); @@ -1928,30 +1929,49 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const = char *xml, unsigned int flags vboxAttachUSB(def, data, machine); vboxAttachSharedFolder(def, data, machine); =20 - /* Save the machine settings made till now and close the - * session. also free up the mchiid variable used. + machineReady =3D true; + + cleanup: + /* if machine wasn't even created, cleanup is trivial */ + if (!machine) { + vboxIIDUnalloc(&mchiid); + virDomainDefFree(def); + + return ret; + } + + /* Save the machine settings made till now, even when jumped here on e= rror, + * as otherwise unregister won't cleanup properly. For example, it won= 't + * close media that were partially attached. The VBOX SDK docs say that + * unregister implicitly calls saveSettings but evidently it's not so.= .. */ rc =3D gVBoxAPI.UIMachine.SaveSettings(machine); if (NS_FAILED(rc)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed no saving settings, rc=3D%08x"), (unsigne= d)rc); - goto cleanup; + _("Failed to save VM settings, rc=3D%08x"), rc); + machineReady =3D false; } =20 gVBoxAPI.UISession.Close(data->vboxSession); - vboxIIDUnalloc(&mchiid); - - ret =3D virGetDomain(conn, def->name, def->uuid, -1); - VBOX_RELEASE(machine); =20 - virDomainDefFree(def); + if (machineReady) { + ret =3D virGetDomain(conn, def->name, def->uuid, -1); + } else { + /* Unregister incompletely configured VM to not leave garbage behi= nd */ + rc =3D gVBoxAPI.unregisterMachine(data, &mchiid, &machine); =20 - return ret; + if (NS_SUCCEEDED(rc)) + gVBoxAPI.deleteConfig(machine); + else + VIR_WARN("Could not cleanup partially created VM after failure= , " + "rc=3D%08x", rc); + } =20 - cleanup: VBOX_RELEASE(machine); + vboxIIDUnalloc(&mchiid); virDomainDefFree(def); - return NULL; + + return ret; } =20 static virDomainPtr --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list