From nobody Mon Feb 9 12:43:25 2026 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 1508873751384348.23528045631167; Tue, 24 Oct 2017 12:35:51 -0700 (PDT) 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 D77E27F7B0; Tue, 24 Oct 2017 19:35:48 +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 6D40C5DA60; Tue, 24 Oct 2017 19:35:48 +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 30FC96EF21; Tue, 24 Oct 2017 19:35:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9OJZiO0009673 for ; Tue, 24 Oct 2017 15:35:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3147060176; Tue, 24 Oct 2017 19:35:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 243776017B for ; Tue, 24 Oct 2017 19:35:42 +0000 (UTC) Received: from mail-qk0-f181.google.com (mail-qk0-f181.google.com [209.85.220.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 A6A085AFC7 for ; Tue, 24 Oct 2017 19:35:41 +0000 (UTC) Received: by mail-qk0-f181.google.com with SMTP id 17so27695097qkq.8 for ; Tue, 24 Oct 2017 12:35:41 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id f66sm683127qkc.25.2017.10.24.12.35.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Oct 2017 12:35:40 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D77E27F7B0 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx04.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 D77E27F7B0 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="OI1xrg6r" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A6A085AFC7 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A6A085AFC7 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=7qwPvHpstl/rFs3LhxT1LVN9yCHFLZvwVAHJU6tlg4o=; b=OI1xrg6rwRbWxRts0zgV4C7tvf1DqG/pCAyPa4KxnjsOFKld50hdQnL/jwm3lMn/dR 626ajFxcdbjvoK84blHxIhLjGPDDyBsZxVJ+/M6xtwYdWWrUkOOP/yNNp8jNwe7bafl6 3O0/ocTsBkEDXZX2xhCMdEWlQwAArdr9vyFVDaP4EBTYuSBcyXQKB4M0H+kxoOCu4S3m AqxJ2JVqvlSNdOembO+kId9LxskA5AfqmS72UmVf8sqb/nAGsZzPAjepv4Dni/yPBrkc G/GnYnHU9hsWJcKs3p33+wlpE+ckXxYSHJ9nBG4D+o/qJIAd0qvhQQJmxeCuMVlOGtue 5Jqg== 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=7qwPvHpstl/rFs3LhxT1LVN9yCHFLZvwVAHJU6tlg4o=; b=ZE80EKZ8N+6pJT1VOvnp8q9vlDLruyiTqX1PnfExiPP3N8X0CerAxj3LIcoPKSOJ+9 vC9gD5hz+gE/PEnes6l34btwfzz9VX0o/SgmTgAOdcKcVhhHS8UJOInybXrDYrFAch1q g3h+B/e/oBDLGMY0NkrwevwgZMoRGNE8rvgMgkn7URuPi+5TYTtXsAYpMYP9NqJsoeTl RqQiRAGas1+6zfrM27+9Pfht5JOrDz+ys1mjTtZB7ns8TUAjIVvYZ9g6vPmKdoWNgzs7 IQUmgXpfH6OzM3kmsmwmUssYMACTJ1sOhP9MzxiKcC+tnESaABpPbGgGakJgppaMciqc qn1A== X-Gm-Message-State: AMCzsaUT7HiB0YoCfkdyiUaYMzxQUsWKE1D6cGUbo61b7EmcSuJFcjoN bflzlnJGTHw00sk8dttMznf0V5iOyeY= X-Google-Smtp-Source: ABhQp+Th2nwje2TSjEnd1mbZ3UguxSyHbqQVcjuMPMrDuwsoRr53VJUahUrewksdVWp91nNHeoo9Vg== X-Received: by 10.55.31.141 with SMTP id n13mr22499992qkh.179.1508873740682; Tue, 24 Oct 2017 12:35:40 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Tue, 24 Oct 2017 15:35:26 -0400 Message-Id: <20171024193538.9078-4-dzamirski@datto.com> In-Reply-To: <20171024193538.9078-1-dzamirski@datto.com> References: <20171024193538.9078-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Oct 2017 19:35:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 24 Oct 2017 19:35:41 +0000 (UTC) for IP:'209.85.220.181' DOMAIN:'mail-qk0-f181.google.com' HELO:'mail-qk0-f181.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.469 (DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.181 mail-qk0-f181.google.com 209.85.220.181 mail-qk0-f181.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 03/15] 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.28]); Tue, 24 Oct 2017 19:35:49 +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 | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 92ee37164..812c940e6 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -1853,6 +1853,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 @@ -1862,12 +1864,12 @@ 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; + return ret; } =20 + VBOX_IID_INITIALIZE(&mchiid); virUUIDFormat(def->uuid, uuidstr); =20 rc =3D gVBoxAPI.UIVirtualBox.CreateMachine(data, def, &machine, uuidst= r); @@ -1959,30 +1961,41 @@ 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: + /* 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: + vboxIIDUnalloc(&mchiid); VBOX_RELEASE(machine); virDomainDefFree(def); - return NULL; + + return ret; } =20 static virDomainPtr --=20 2.14.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list