From nobody Thu May 15 11:27:40 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; 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 1507325000355943.8233574442834; Fri, 6 Oct 2017 14:23:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09DB6CD18D; Fri, 6 Oct 2017 21:23:19 +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 D3D4B679CA; Fri, 6 Oct 2017 21:23:17 +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 608DF41F78; Fri, 6 Oct 2017 21:23:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96KxUtE021944 for ; Fri, 6 Oct 2017 16:59:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4461B5D75E; Fri, 6 Oct 2017 20:59:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-17.phx2.redhat.com [10.3.116.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B9795D75C for ; Fri, 6 Oct 2017 20:59:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 09DB6CD18D Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Oct 2017 16:59:22 -0400 Message-Id: <20171006205925.28633-2-jferlan@redhat.com> In-Reply-To: <20171006205925.28633-1-jferlan@redhat.com> References: <20171006205925.28633-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] storage: Extract out the LVCREATE 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 Oct 2017 21:23:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Refactor to extract out the LVCREATE command. This also removes the need for the local @created since the error path can now only be reached after the creation of the logical volume. Signed-off-by: John Ferlan --- src/storage/storage_backend_logical.c | 65 +++++++++++++++++++------------= ---- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_ba= ckend_logical.c index 0ad357729b..8d28be3adb 100644 --- a/src/storage/storage_backend_logical.c +++ b/src/storage/storage_backend_logical.c @@ -937,30 +937,11 @@ virStorageBackendLogicalDeleteVol(virConnectPtr conn = ATTRIBUTE_UNUSED, =20 =20 static int -virStorageBackendLogicalCreateVol(virConnectPtr conn, - virStoragePoolObjPtr pool, - virStorageVolDefPtr vol) +virStorageBackendLogicalLVCreate(virStorageVolDefPtr vol, + virStoragePoolDefPtr def) { - int fd =3D -1; - virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + int ret; virCommandPtr cmd =3D NULL; - virErrorPtr err; - struct stat sb; - bool created =3D false; - - if (vol->target.encryption !=3D NULL) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("storage pool does not support encrypted " - "volumes")); - return -1; - } - - vol->type =3D VIR_STORAGE_VOL_BLOCK; - - VIR_FREE(vol->target.path); - if (virAsprintf(&vol->target.path, "%s/%s", - def->target.path, vol->name) < 0) - return -1; =20 cmd =3D virCommandNewArgList(LVCREATE, "--name", vol->name, @@ -981,12 +962,38 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, else virCommandAddArg(cmd, def->source.name); =20 - if (virCommandRun(cmd, NULL) < 0) - goto error; - - created =3D true; + ret =3D virCommandRun(cmd, NULL); virCommandFree(cmd); - cmd =3D NULL; + return ret; +} + + +static int +virStorageBackendLogicalCreateVol(virConnectPtr conn, + virStoragePoolObjPtr pool, + virStorageVolDefPtr vol) +{ + int fd =3D -1; + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + virErrorPtr err; + struct stat sb; + + if (vol->target.encryption !=3D NULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("storage pool does not support encrypted " + "volumes")); + return -1; + } + + vol->type =3D VIR_STORAGE_VOL_BLOCK; + + VIR_FREE(vol->target.path); + if (virAsprintf(&vol->target.path, "%s/%s", + def->target.path, vol->name) < 0) + return -1; + + if (virStorageBackendLogicalLVCreate(vol, def) < 0) + return -1; =20 if ((fd =3D virStorageBackendVolOpen(vol->target.path, &sb, VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0) @@ -1030,9 +1037,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn, error: err =3D virSaveLastError(); VIR_FORCE_CLOSE(fd); - if (created) - virStorageBackendLogicalDeleteVol(conn, pool, vol, 0); - virCommandFree(cmd); + virStorageBackendLogicalDeleteVol(conn, pool, vol, 0); virSetError(err); virFreeError(err); return -1; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list