From nobody Thu May 15 11:40:24 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 1507290384602872.6812778999719; Fri, 6 Oct 2017 04:46:24 -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 EA0207EAB1; Fri, 6 Oct 2017 11:46:22 +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 C5F9066842; Fri, 6 Oct 2017 11:46:22 +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 842D81806104; Fri, 6 Oct 2017 11:46:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v96BNN1q028177 for ; Fri, 6 Oct 2017 07:23:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id E35E860605; Fri, 6 Oct 2017 11:23:23 +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 ACB5560603 for ; Fri, 6 Oct 2017 11:23:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EA0207EAB1 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 07:23:16 -0400 Message-Id: <20171006112317.29715-6-jferlan@redhat.com> In-Reply-To: <20171006112317.29715-1-jferlan@redhat.com> References: <20171006112317.29715-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH REPOST 5/6] storage: Use virStoragePoolObjGetDef accessor for FS backend 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.28]); Fri, 06 Oct 2017 11:46:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In preparation for privatizing the object, use the accessor. Signed-off-by: John Ferlan --- src/storage/storage_backend_fs.c | 90 ++++++++++++++++++++++--------------= ---- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend= _fs.c index 847dbc9e02..f54759983c 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -222,25 +222,27 @@ virStorageBackendFileSystemNetFindPoolSources(virConn= ectPtr conn ATTRIBUTE_UNUSE static int virStorageBackendFileSystemIsValid(virStoragePoolObjPtr pool) { - if (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS) { - if (pool->def->source.nhost !=3D 1) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + + if (def->type =3D=3D VIR_STORAGE_POOL_NETFS) { + if (def->source.nhost !=3D 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("expected exactly 1 host for the storage pool= ")); return -1; } - if (pool->def->source.hosts[0].name =3D=3D NULL) { + if (def->source.hosts[0].name =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source host")); return -1; } - if (pool->def->source.dir =3D=3D NULL) { + if (def->source.dir =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source path")); return -1; } } else { - if (pool->def->source.ndevice !=3D 1) { - if (pool->def->source.ndevice =3D=3D 0) + if (def->source.ndevice !=3D 1) { + if (def->source.ndevice =3D=3D 0) virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing source device")); else @@ -264,22 +266,23 @@ virStorageBackendFileSystemIsValid(virStoragePoolObjP= tr pool) static char * virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src =3D NULL; =20 - if (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS) { - if (pool->def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_CIFS) { + if (def->type =3D=3D VIR_STORAGE_POOL_NETFS) { + if (def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_CIFS) { if (virAsprintf(&src, "//%s/%s", - pool->def->source.hosts[0].name, - pool->def->source.dir) < 0) + def->source.hosts[0].name, + def->source.dir) < 0) return NULL; } else { if (virAsprintf(&src, "%s:%s", - pool->def->source.hosts[0].name, - pool->def->source.dir) < 0) + def->source.hosts[0].name, + def->source.dir) < 0) return NULL; } } else { - if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0) + if (VIR_STRDUP(src, def->source.devices[0].path) < 0) return NULL; } return src; @@ -297,6 +300,7 @@ static int virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) { int ret =3D -1; + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src =3D NULL; FILE *mtab; struct mntent ent; @@ -317,8 +321,7 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjP= tr pool) /* compare both mount destinations and sources to be sure the moun= ted * FS pool is really the one we're looking for */ - if ((rc1 =3D virFileComparePaths(ent.mnt_dir, - pool->def->target.path)) < 0 || + if ((rc1 =3D virFileComparePaths(ent.mnt_dir, def->target.path)) <= 0 || (rc2 =3D virFileComparePaths(ent.mnt_fsname, src)) < 0) goto cleanup; =20 @@ -349,16 +352,17 @@ virStorageBackendFileSystemIsMounted(virStoragePoolOb= jPtr pool) static int virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); char *src =3D NULL; /* 'mount -t auto' doesn't seem to auto determine nfs (or cifs), * while plain 'mount' does. We have to craft separate argvs to * accommodate this */ - bool netauto =3D (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS && - pool->def->source.format =3D=3D VIR_STORAGE_POOL_NETFS= _AUTO); - bool glusterfs =3D (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS && - pool->def->source.format =3D=3D VIR_STORAGE_POOL_NET= FS_GLUSTERFS); - bool cifsfs =3D (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS && - pool->def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_= CIFS); + bool netauto =3D (def->type =3D=3D VIR_STORAGE_POOL_NETFS && + def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_AUTO); + bool glusterfs =3D (def->type =3D=3D VIR_STORAGE_POOL_NETFS && + def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_GLU= STERFS); + bool cifsfs =3D (def->type =3D=3D VIR_STORAGE_POOL_NETFS && + def->source.format =3D=3D VIR_STORAGE_POOL_NETFS_CIFS); virCommandPtr cmd =3D NULL; int ret =3D -1; int rc; @@ -371,7 +375,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr p= ool) =20 /* Short-circuit if already mounted */ if (rc =3D=3D 1) { - VIR_INFO("Target '%s' is already mounted", pool->def->target.path); + VIR_INFO("Target '%s' is already mounted", def->target.path); return 0; } =20 @@ -381,34 +385,34 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr= pool) if (netauto) cmd =3D virCommandNewArgList(MOUNT, src, - pool->def->target.path, + def->target.path, NULL); else if (glusterfs) cmd =3D virCommandNewArgList(MOUNT, "-t", - virStoragePoolFormatFileSystemNetTypeTo= String(pool->def->source.format), + virStoragePoolFormatFileSystemNetTypeTo= String(def->source.format), src, "-o", "direct-io-mode=3D1", - pool->def->target.path, + def->target.path, NULL); else if (cifsfs) cmd =3D virCommandNewArgList(MOUNT, "-t", - virStoragePoolFormatFileSystemNetTypeTo= String(pool->def->source.format), + virStoragePoolFormatFileSystemNetTypeTo= String(def->source.format), src, - pool->def->target.path, + def->target.path, "-o", "guest", NULL); else cmd =3D virCommandNewArgList(MOUNT, "-t", - (pool->def->type =3D=3D VIR_STORAGE_POO= L_FS ? - virStoragePoolFormatFileSystemTypeToSt= ring(pool->def->source.format) : - virStoragePoolFormatFileSystemNetTypeT= oString(pool->def->source.format)), + (def->type =3D=3D VIR_STORAGE_POOL_FS ? + virStoragePoolFormatFileSystemTypeToSt= ring(def->source.format) : + virStoragePoolFormatFileSystemNetTypeT= oString(def->source.format)), src, - pool->def->target.path, + def->target.path, NULL); =20 if (virCommandRun(cmd, NULL) < 0) @@ -435,7 +439,9 @@ static int virStorageBackendFileSystemStart(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { - if (pool->def->type !=3D VIR_STORAGE_POOL_DIR && + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + + if (def->type !=3D VIR_STORAGE_POOL_DIR && virStorageBackendFileSystemMount(pool) < 0) return -1; =20 @@ -459,6 +465,7 @@ static int virStorageBackendFileSystemStop(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virCommandPtr cmd =3D NULL; int ret =3D -1; int rc; @@ -470,7 +477,7 @@ virStorageBackendFileSystemStop(virConnectPtr conn ATTR= IBUTE_UNUSED, if ((rc =3D virStorageBackendFileSystemIsMounted(pool)) !=3D 1) return rc; =20 - cmd =3D virCommandNewArgList(UMOUNT, pool->def->target.path, NULL); + cmd =3D virCommandNewArgList(UMOUNT, def->target.path, NULL); if (virCommandRun(cmd, NULL) < 0) goto cleanup; =20 @@ -486,8 +493,10 @@ static int virStorageBackendFileSystemCheck(virStoragePoolObjPtr pool, bool *isActive) { - if (pool->def->type =3D=3D VIR_STORAGE_POOL_DIR) { - *isActive =3D virFileExists(pool->def->target.path); + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + + if (def->type =3D=3D VIR_STORAGE_POOL_DIR) { + *isActive =3D virFileExists(def->target.path); #if WITH_STORAGE_FS } else { int ret; @@ -561,25 +570,26 @@ static int virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool, unsigned int flags) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); const char *device =3D NULL, *format =3D NULL; bool ok_to_mkfs =3D false; int ret =3D -1; =20 - if (pool->def->source.devices =3D=3D NULL) { + if (def->source.devices =3D=3D NULL) { virReportError(VIR_ERR_OPERATION_INVALID, _("No source device specified when formatting pool = '%s'"), - pool->def->name); + def->name); goto error; } =20 - device =3D pool->def->source.devices[0].path; - format =3D virStoragePoolFormatFileSystemTypeToString(pool->def->sourc= e.format); + device =3D def->source.devices[0].path; + format =3D virStoragePoolFormatFileSystemTypeToString(def->source.form= at); VIR_DEBUG("source device: '%s' format: '%s'", device, format); =20 if (!virFileExists(device)) { virReportError(VIR_ERR_OPERATION_INVALID, _("Source device does not exist when formatting poo= l '%s'"), - pool->def->name); + def->name); goto error; } =20 --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list