From nobody Sun Feb 8 23:25:15 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; 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 1505829664348661.6803936895839; Tue, 19 Sep 2017 07:01:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3227A7C83A; Tue, 19 Sep 2017 14:01:03 +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 F325261F25; Tue, 19 Sep 2017 14:01:02 +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 96C201806104; Tue, 19 Sep 2017 14:01:02 +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 v8JDQ1u6012642 for ; Tue, 19 Sep 2017 09:26:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id E044550ED8; Tue, 19 Sep 2017 13:26:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-150.phx2.redhat.com [10.3.116.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1358197F9 for ; Tue, 19 Sep 2017 13:26:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3227A7C83A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Tue, 19 Sep 2017 09:25:05 -0400 Message-Id: <20170919132518.28151-7-jferlan@redhat.com> In-Reply-To: <20170919132518.28151-1-jferlan@redhat.com> References: <20170919132518.28151-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/19] storage: Use virStoragePoolObjGetDef accessor for storage_util 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 19 Sep 2017 14:01:03 +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_util.c | 116 ++++++++++++++++++++++++-----------------= ---- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 07dba2222..adcec36cc 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -396,6 +396,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UN= USED, virStorageVolDefPtr inputvol, unsigned int flags) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int ret =3D -1; int fd =3D -1; int operation_flags; @@ -431,7 +432,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UN= USED, } =20 operation_flags =3D VIR_FILE_OPEN_FORCE_MODE | VIR_FILE_OPEN_FORCE_OWN= ER; - if (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS) + if (def->type =3D=3D VIR_STORAGE_POOL_NETFS) operation_flags |=3D VIR_FILE_OPEN_FORK; =20 if (vol->target.perms->mode !=3D (mode_t) -1) @@ -597,6 +598,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, virStorageVolDefPtr vol, virCommandPtr cmd) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); struct stat st; gid_t gid; uid_t uid; @@ -606,7 +608,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr= pool, bool filecreated =3D false; int ret =3D -1; =20 - if ((pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS) + if ((def->type =3D=3D VIR_STORAGE_POOL_NETFS) && (((geteuid() =3D=3D 0) && (vol->target.perms->uid !=3D (uid_t) -1) && (vol->target.perms->uid !=3D 0)) @@ -1029,6 +1031,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolO= bjPtr pool, virStorageVolDefPtr inputvol, struct _virStorageBackendQemuImgInfo= *info) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int accessRetCode =3D -1; char *absolutePath =3D NULL; =20 @@ -1071,7 +1074,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolO= bjPtr pool, * validation. */ if ('/' !=3D *(info->backingPath) && - virAsprintf(&absolutePath, "%s/%s", pool->def->target.path, + virAsprintf(&absolutePath, "%s/%s", def->target.path, info->backingPath) < 0) return -1; accessRetCode =3D access(absolutePath ? absolutePath : @@ -1921,7 +1924,7 @@ virStorageBackendPoolPathIsStable(const char *path) =20 /* * Given a volume path directly in /dev/XXX, iterate over the - * entries in the directory pool->def->target.path and find the + * entries in the directory def->target.path and find the * first symlink pointing to the volume path. * * If, the target.path is /dev/, then return the original volume @@ -1940,6 +1943,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, const char *devpath, bool loop) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); DIR *dh; struct dirent *dent; char *stablepath; @@ -1948,8 +1952,8 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, int direrr; =20 /* Logical pools are under /dev but already have stable paths */ - if (pool->def->type =3D=3D VIR_STORAGE_POOL_LOGICAL || - !virStorageBackendPoolPathIsStable(pool->def->target.path)) + if (def->type =3D=3D VIR_STORAGE_POOL_LOGICAL || + !virStorageBackendPoolPathIsStable(def->target.path)) goto ret_strdup; =20 /* We loop here because /dev/disk/by-{id,path} may not have existed @@ -1957,7 +1961,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, * get created. */ reopen: - if (virDirOpenQuiet(&dh, pool->def->target.path) < 0) { + if (virDirOpenQuiet(&dh, def->target.path) < 0) { opentries++; if (loop && errno =3D=3D ENOENT && opentries < 50) { usleep(100 * 1000); @@ -1965,7 +1969,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, } virReportSystemError(errno, _("cannot read dir '%s'"), - pool->def->target.path); + def->target.path); return NULL; } =20 @@ -1981,8 +1985,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, retry: while ((direrr =3D virDirRead(dh, &dent, NULL)) > 0) { if (virAsprintf(&stablepath, "%s/%s", - pool->def->target.path, - dent->d_name) < 0) { + def->target.path, dent->d_name) < 0) { VIR_DIR_CLOSE(dh); return NULL; } @@ -2020,6 +2023,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageVolDefPtr inputvol, unsigned int flags) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int err; =20 virCheckFlags(0, -1); @@ -2044,7 +2048,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED, vol->target.perms->mode), vol->target.perms->uid, vol->target.perms->gid, - (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS + (def->type =3D=3D VIR_STORAGE_POOL_NETFS ? VIR_DIR_CREATE_AS_UID : 0))) < 0) { return -1; } @@ -2064,6 +2068,8 @@ virStorageBackendVolCreateLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, virStoragePoolObjPtr pool, virStorageVolDefPtr vol) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + if (vol->target.format =3D=3D VIR_STORAGE_FILE_DIR) vol->type =3D VIR_STORAGE_VOL_DIR; else if (vol->target.format =3D=3D VIR_STORAGE_FILE_PLOOP) @@ -2081,8 +2087,7 @@ virStorageBackendVolCreateLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, =20 VIR_FREE(vol->target.path); if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, - vol->name) < 0) + def->target.path, vol->name) < 0) return -1; =20 if (virFileExists(vol->target.path)) { @@ -2769,6 +2774,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTR= IBUTE_UNUSED, int virStorageBackendBuildLocal(virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int ret =3D -1; char *parent =3D NULL; char *p =3D NULL; @@ -2776,12 +2782,12 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr po= ol) bool needs_create_as_uid; unsigned int dir_create_flags; =20 - if (VIR_STRDUP(parent, pool->def->target.path) < 0) + if (VIR_STRDUP(parent, def->target.path) < 0) goto cleanup; if (!(p =3D strrchr(parent, '/'))) { virReportError(VIR_ERR_INVALID_ARG, _("path '%s' is not absolute"), - pool->def->target.path); + def->target.path); goto cleanup; } =20 @@ -2797,11 +2803,11 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr po= ol) } =20 dir_create_flags =3D VIR_DIR_CREATE_ALLOW_EXIST; - needs_create_as_uid =3D (pool->def->type =3D=3D VIR_STORAGE_POOL_NETFS= ); - mode =3D pool->def->target.perms.mode; + needs_create_as_uid =3D (def->type =3D=3D VIR_STORAGE_POOL_NETFS); + mode =3D def->target.perms.mode; =20 if (mode =3D=3D (mode_t) -1 && - (needs_create_as_uid || !virFileExists(pool->def->target.path))) + (needs_create_as_uid || !virFileExists(def->target.path))) mode =3D VIR_STORAGE_DEFAULT_POOL_PERM_MODE; if (needs_create_as_uid) dir_create_flags |=3D VIR_DIR_CREATE_AS_UID; @@ -2809,10 +2815,10 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr po= ol) /* Now create the final dir in the path with the uid/gid/mode * requested in the config. If the dir already exists, just set * the perms. */ - if (virDirCreate(pool->def->target.path, + if (virDirCreate(def->target.path, mode, - pool->def->target.perms.uid, - pool->def->target.perms.gid, + def->target.perms.uid, + def->target.perms.gid, dir_create_flags) < 0) goto cleanup; =20 @@ -2837,14 +2843,16 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATT= RIBUTE_UNUSED, virStoragePoolObjPtr pool, unsigned int flags) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + virCheckFlags(0, -1); =20 /* XXX delete all vols first ? */ =20 - if (rmdir(pool->def->target.path) < 0) { + if (rmdir(def->target.path) < 0) { virReportSystemError(errno, _("failed to remove pool '%s'"), - pool->def->target.path); + def->target.path); return -1; } =20 @@ -3576,6 +3584,7 @@ int virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStoragePoolObjPtr pool) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); DIR *dir; struct dirent *ent; struct statvfs sb; @@ -3585,15 +3594,15 @@ virStorageBackendRefreshLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, int direrr; int fd =3D -1, ret =3D -1; =20 - if (virDirOpen(&dir, pool->def->target.path) < 0) + if (virDirOpen(&dir, def->target.path) < 0) goto cleanup; =20 - while ((direrr =3D virDirRead(dir, &ent, pool->def->target.path)) > 0)= { + while ((direrr =3D virDirRead(dir, &ent, def->target.path)) > 0) { int err; =20 if (virStringHasControlChars(ent->d_name)) { VIR_WARN("Ignoring file with control characters under '%s'", - pool->def->target.path); + def->target.path); continue; } =20 @@ -3605,8 +3614,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTR= IBUTE_UNUSED, =20 vol->type =3D VIR_STORAGE_VOL_FILE; if (virAsprintf(&vol->target.path, "%s/%s", - pool->def->target.path, - vol->name) < 0) + def->target.path, vol->name) < 0) goto cleanup; =20 if (VIR_STRDUP(vol->key, vol->target.path) < 0) @@ -3634,17 +3642,17 @@ virStorageBackendRefreshLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, if (VIR_ALLOC(target)) goto cleanup; =20 - if ((fd =3D open(pool->def->target.path, O_RDONLY)) < 0) { + if ((fd =3D open(def->target.path, O_RDONLY)) < 0) { virReportSystemError(errno, _("cannot open path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } =20 if (fstat(fd, &statbuf) < 0) { virReportSystemError(errno, _("cannot stat path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } =20 @@ -3652,24 +3660,24 @@ virStorageBackendRefreshLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, goto cleanup; =20 /* VolTargetInfoFD doesn't update capacity correctly for the pool case= */ - if (statvfs(pool->def->target.path, &sb) < 0) { + if (statvfs(def->target.path, &sb) < 0) { virReportSystemError(errno, _("cannot statvfs path '%s'"), - pool->def->target.path); + def->target.path); goto cleanup; } =20 - pool->def->capacity =3D ((unsigned long long)sb.f_frsize * - (unsigned long long)sb.f_blocks); - pool->def->available =3D ((unsigned long long)sb.f_bfree * - (unsigned long long)sb.f_frsize); - pool->def->allocation =3D pool->def->capacity - pool->def->available; + def->capacity =3D ((unsigned long long)sb.f_frsize * + (unsigned long long)sb.f_blocks); + def->available =3D ((unsigned long long)sb.f_bfree * + (unsigned long long)sb.f_frsize); + def->allocation =3D def->capacity - def->available; =20 - pool->def->target.perms.mode =3D target->perms->mode; - pool->def->target.perms.uid =3D target->perms->uid; - pool->def->target.perms.gid =3D target->perms->gid; - VIR_FREE(pool->def->target.perms.label); - if (VIR_STRDUP(pool->def->target.perms.label, target->perms->label) < = 0) + def->target.perms.mode =3D target->perms->mode; + def->target.perms.uid =3D target->perms->uid; + def->target.perms.gid =3D target->perms->gid; + VIR_FREE(def->target.perms.label); + if (VIR_STRDUP(def->target.perms.label, target->perms->label) < 0) goto cleanup; =20 ret =3D 0; @@ -3739,6 +3747,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, uint32_t lun, const char *dev) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virStorageVolDefPtr vol =3D NULL; char *devpath =3D NULL; int retval =3D -1; @@ -3750,12 +3759,12 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr po= ol, * path to the device if the virDirRead loop to search the * target pool path for our devpath had failed. */ - if (!virStorageBackendPoolPathIsStable(pool->def->target.path) && - !(STREQ(pool->def->target.path, "/dev") || - STREQ(pool->def->target.path, "/dev/"))) { + if (!virStorageBackendPoolPathIsStable(def->target.path) && + !(STREQ(def->target.path, "/dev") || + STREQ(def->target.path, "/dev/"))) { virReportError(VIR_ERR_INVALID_ARG, _("unable to use target path '%s' for dev '%s'"), - NULLSTR(pool->def->target.path), dev); + NULLSTR(def->target.path), dev); goto cleanup; } =20 @@ -3789,11 +3798,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr po= ol, goto cleanup; =20 if (STREQ(devpath, vol->target.path) && - !(STREQ(pool->def->target.path, "/dev") || - STREQ(pool->def->target.path, "/dev/"))) { + !(STREQ(def->target.path, "/dev") || + STREQ(def->target.path, "/dev/"))) { =20 VIR_DEBUG("No stable path found for '%s' in '%s'", - devpath, pool->def->target.path); + devpath, def->target.path); =20 retval =3D -2; goto cleanup; @@ -3808,8 +3817,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool, if (!(vol->key =3D virStorageBackendSCSISerial(vol->target.path))) goto cleanup; =20 - pool->def->capacity +=3D vol->target.capacity; - pool->def->allocation +=3D vol->target.allocation; + def->capacity +=3D vol->target.capacity; + def->allocation +=3D vol->target.allocation; =20 if (virStoragePoolObjAddVol(pool, vol) < 0) goto cleanup; @@ -4086,6 +4095,7 @@ int virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, uint32_t scanhost) { + virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); int retval =3D 0; uint32_t bus, target, lun; const char *device_path =3D "/sys/bus/scsi/devices"; @@ -4127,7 +4137,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr poo= l, if (retval < 0) return -1; =20 - VIR_DEBUG("Found %d LUs for pool %s", found, pool->def->name); + VIR_DEBUG("Found %d LUs for pool %s", found, def->name); =20 return found; } --=20 2.13.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list