From nobody Sat Apr 27 20:48:18 2024 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; 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 ARC-Seal: i=1; a=rsa-sha256; t=1612581119; cv=none; d=zohomail.com; s=zohoarc; b=femFTW5bvpNDvYlShe1E3gfJ9CkkQhtRcLSftirT/GrOgSXwoTNhd8Vz5jsjjqrziJ4I07ggSznHeh9mDdi+NEqMzmyW8/tJRW1SMNBYCIeRnXYvnqHinllzVSV7FkWKnTCDHUU6N7P4XfGYQk84sXkqGA0afx635FXiAFe2z6Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612581119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=NHxarQIO+rfYl6o7g8dITjtoLDlldLBGewuIrEvSwx8=; b=FjjOA6FuwgXqEREmX9N8QoVPD+y3K/O4j6escgXC6ZTI9sl5piE0LJSmKZLP6VwsVSJKUFjY6pPbsrsOyHJJgXPA+dg9h83y2ZqccURVjrge9ng3QvIhVm1JB2y6Vyq4V4XIeI64voJwXhpMAOzLpTym0xyr2XCDHcE/Qw549kY= 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 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 1612581119150932.5417066543848; Fri, 5 Feb 2021 19:11:59 -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-130-xIkQ8McmMvauQoNSrQb3sg-1; Fri, 05 Feb 2021 22:11:55 -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 360AE8030C1; Sat, 6 Feb 2021 03:11:49 +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 B6AA910016FF; Sat, 6 Feb 2021 03:11:45 +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 673AC18095CC; Sat, 6 Feb 2021 03:11:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1163BWM5001022 for ; Fri, 5 Feb 2021 22:11:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id A0F9E2166B2F; Sat, 6 Feb 2021 03:11:32 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9B1642166B2B for ; Sat, 6 Feb 2021 03:11:29 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 AD04B858F17 for ; Sat, 6 Feb 2021 03:11:29 +0000 (UTC) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.70.202]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-rU0hMV-CNIuZ52Pr_wOX1Q-1; Fri, 05 Feb 2021 22:11:26 -0500 Received: from localhost (unknown [192.168.167.235]) by regular1.263xmail.com (Postfix) with ESMTP id 03305716 for ; Sat, 6 Feb 2021 11:11:19 +0800 (CST) Received: from localhost.localdomain (unknown [14.18.236.70]) by smtp.263.net (postfix) whith ESMTP id P19733T140185207551744S1612581072814093_; Sat, 06 Feb 2021 11:11:18 +0800 (CST) X-MC-Unique: xIkQ8McmMvauQoNSrQb3sg-1 X-MC-Unique: rU0hMV-CNIuZ52Pr_wOX1Q-1 X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: yili@winhong.com X-SENDER: yili@winhong.com X-LOGIN-NAME: yili@winhong.com X-FST-TO: libvir-list@redhat.com X-SENDER-IP: 14.18.236.70 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 From: Yi Li To: libvir-list@redhat.com Subject: [PATCH] Rework qemuMigrationDstPrecreateDisk() Date: Sat, 6 Feb 2021 11:11:11 +0800 Message-Id: <20210206031111.1597608-1-yili@winhong.com> MIME-Version: 1.0 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.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 1163BWM5001022 X-loop: libvir-list@redhat.com Cc: Yi Li 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: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 'conn' vairable which are used only inside the func. Let's declare inside the func body to make that obvious. Use g_autofree to allow removal of 'cleanup:' and the 'ret' variable. Signed-off-by: Yi Li --- src/qemu/qemu_migration.c | 68 +++++++++++++++------------------------ 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index f44d31c971..6bb0677f86 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -169,15 +169,15 @@ qemuMigrationSrcRestoreDomainState(virQEMUDriverPtr d= river, virDomainObjPtr vm) =20 =20 static int -qemuMigrationDstPrecreateDisk(virConnectPtr *conn, - virDomainDiskDefPtr disk, +qemuMigrationDstPrecreateDisk(virDomainDiskDefPtr disk, unsigned long long capacity) { - int ret =3D -1; - virStoragePoolPtr pool =3D NULL; - virStorageVolPtr vol =3D NULL; - char *volName =3D NULL, *basePath =3D NULL; - char *volStr =3D NULL; + g_autoptr(virConnect) conn =3D NULL; + g_autoptr(virStoragePool) pool =3D NULL; + g_autoptr(virStorageVol) vol =3D NULL; + char *volName =3D NULL; + g_autofree char *basePath =3D NULL; + g_autofree char *volStr =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; const char *format =3D NULL; unsigned int flags =3D 0; @@ -198,32 +198,28 @@ qemuMigrationDstPrecreateDisk(virConnectPtr *conn, virReportError(VIR_ERR_INVALID_ARG, _("malformed disk path: %s"), disk->src->path); - goto cleanup; + return -1; } =20 *volName =3D '\0'; volName++; =20 - if (!*conn) { - if (!(*conn =3D virGetConnectStorage())) - goto cleanup; - } + if (!(conn =3D virGetConnectStorage())) + return -1; =20 - if (!(pool =3D virStoragePoolLookupByTargetPath(*conn, basePath))) - goto cleanup; + if (!(pool =3D virStoragePoolLookupByTargetPath(conn, basePath))) + return -1; format =3D virStorageFileFormatTypeToString(disk->src->format); if (disk->src->format =3D=3D VIR_STORAGE_FILE_QCOW2) flags |=3D VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA; break; =20 case VIR_STORAGE_TYPE_VOLUME: - if (!*conn) { - if (!(*conn =3D virGetConnectStorage())) - goto cleanup; - } + if (!(conn =3D virGetConnectStorage())) + return -1; =20 - if (!(pool =3D virStoragePoolLookupByName(*conn, disk->src->srcpoo= l->pool))) - goto cleanup; + if (!(pool =3D virStoragePoolLookupByName(conn, disk->src->srcpool= ->pool))) + return -1; format =3D virStorageFileFormatTypeToString(disk->src->format); volName =3D disk->src->srcpool->volume; if (disk->src->format =3D=3D VIR_STORAGE_FILE_QCOW2) @@ -245,13 +241,13 @@ qemuMigrationDstPrecreateDisk(virConnectPtr *conn, _("cannot precreate storage for disk type '%s'"), virStorageTypeToString(disk->src->type)); goto cleanup; + return -1; } =20 if ((vol =3D virStorageVolLookupByName(pool, volName))) { VIR_DEBUG("Skipping creation of already existing volume of name '%= s'", volName); - ret =3D 0; - goto cleanup; + return 0; } =20 virBufferAddLit(&buf, "\n"); @@ -269,19 +265,13 @@ qemuMigrationDstPrecreateDisk(virConnectPtr *conn, if (!(volStr =3D virBufferContentAndReset(&buf))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to create volume XML")); - goto cleanup; + return -1; } =20 if (!(vol =3D virStorageVolCreateXML(pool, volStr, flags))) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(basePath); - VIR_FREE(volStr); - virObjectUnref(vol); - virObjectUnref(pool); - return ret; + return 0; } =20 static bool @@ -313,9 +303,7 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm, const char **migrate_disks, bool incremental) { - int ret =3D -1; size_t i =3D 0; - virConnectPtr conn =3D NULL; =20 if (!nbd || !nbd->ndisks) return 0; @@ -332,7 +320,7 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find disk by target: %s"), nbd->disks[i].target); - goto cleanup; + return -1; } =20 if (disk->src->type =3D=3D VIR_STORAGE_TYPE_NVME) { @@ -352,20 +340,16 @@ qemuMigrationDstPrecreateStorage(virDomainObjPtr vm, virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("pre-creation of storage targets for incremen= tal " "storage migration is not supported")); - goto cleanup; + return -1; } =20 VIR_DEBUG("Proceeding with disk source %s", NULLSTR(diskSrcPath)); =20 - if (qemuMigrationDstPrecreateDisk(&conn, - disk, nbd->disks[i].capacity) < = 0) - goto cleanup; + if (qemuMigrationDstPrecreateDisk(disk, nbd->disks[i].capacity) < = 0) + return -1; } =20 - ret =3D 0; - cleanup: - virObjectUnref(conn); - return ret; + return 0; } =20 =20 --=20 2.25.3