storage: Use virStoragePoolObjGetDef accessor for storage_util

In preparation for privatizing the object, use the accessor.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-05-08 08:47:32 -04:00
parent 296d6e2d93
commit c0682800cd
1 changed files with 63 additions and 53 deletions

View File

@ -396,6 +396,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
virStorageVolDefPtr inputvol, virStorageVolDefPtr inputvol,
unsigned int flags) unsigned int flags)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int ret = -1; int ret = -1;
int fd = -1; int fd = -1;
int operation_flags; int operation_flags;
@ -431,7 +432,7 @@ storageBackendCreateRaw(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
operation_flags = VIR_FILE_OPEN_FORCE_MODE | VIR_FILE_OPEN_FORCE_OWNER; operation_flags = VIR_FILE_OPEN_FORCE_MODE | VIR_FILE_OPEN_FORCE_OWNER;
if (pool->def->type == VIR_STORAGE_POOL_NETFS) if (def->type == VIR_STORAGE_POOL_NETFS)
operation_flags |= VIR_FILE_OPEN_FORK; operation_flags |= VIR_FILE_OPEN_FORK;
if (vol->target.perms->mode != (mode_t) -1) if (vol->target.perms->mode != (mode_t) -1)
@ -597,6 +598,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol, virStorageVolDefPtr vol,
virCommandPtr cmd) virCommandPtr cmd)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
struct stat st; struct stat st;
gid_t gid; gid_t gid;
uid_t uid; uid_t uid;
@ -606,7 +608,7 @@ virStorageBackendCreateExecCommand(virStoragePoolObjPtr pool,
bool filecreated = false; bool filecreated = false;
int ret = -1; int ret = -1;
if ((pool->def->type == VIR_STORAGE_POOL_NETFS) if ((def->type == VIR_STORAGE_POOL_NETFS)
&& (((geteuid() == 0) && (((geteuid() == 0)
&& (vol->target.perms->uid != (uid_t) -1) && (vol->target.perms->uid != (uid_t) -1)
&& (vol->target.perms->uid != 0)) && (vol->target.perms->uid != 0))
@ -1029,6 +1031,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
virStorageVolDefPtr inputvol, virStorageVolDefPtr inputvol,
struct _virStorageBackendQemuImgInfo *info) struct _virStorageBackendQemuImgInfo *info)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int accessRetCode = -1; int accessRetCode = -1;
char *absolutePath = NULL; char *absolutePath = NULL;
@ -1071,7 +1074,7 @@ storageBackendCreateQemuImgSetBacking(virStoragePoolObjPtr pool,
* validation. * validation.
*/ */
if ('/' != *(info->backingPath) && if ('/' != *(info->backingPath) &&
virAsprintf(&absolutePath, "%s/%s", pool->def->target.path, virAsprintf(&absolutePath, "%s/%s", def->target.path,
info->backingPath) < 0) info->backingPath) < 0)
return -1; return -1;
accessRetCode = access(absolutePath ? absolutePath : accessRetCode = access(absolutePath ? absolutePath :
@ -1921,7 +1924,7 @@ virStorageBackendPoolPathIsStable(const char *path)
/* /*
* Given a volume path directly in /dev/XXX, iterate over the * 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. * first symlink pointing to the volume path.
* *
* If, the target.path is /dev/, then return the original volume * If, the target.path is /dev/, then return the original volume
@ -1940,6 +1943,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
const char *devpath, const char *devpath,
bool loop) bool loop)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
DIR *dh; DIR *dh;
struct dirent *dent; struct dirent *dent;
char *stablepath; char *stablepath;
@ -1948,8 +1952,8 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
int direrr; int direrr;
/* Logical pools are under /dev but already have stable paths */ /* Logical pools are under /dev but already have stable paths */
if (pool->def->type == VIR_STORAGE_POOL_LOGICAL || if (def->type == VIR_STORAGE_POOL_LOGICAL ||
!virStorageBackendPoolPathIsStable(pool->def->target.path)) !virStorageBackendPoolPathIsStable(def->target.path))
goto ret_strdup; goto ret_strdup;
/* We loop here because /dev/disk/by-{id,path} may not have existed /* We loop here because /dev/disk/by-{id,path} may not have existed
@ -1957,7 +1961,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
* get created. * get created.
*/ */
reopen: reopen:
if (virDirOpenQuiet(&dh, pool->def->target.path) < 0) { if (virDirOpenQuiet(&dh, def->target.path) < 0) {
opentries++; opentries++;
if (loop && errno == ENOENT && opentries < 50) { if (loop && errno == ENOENT && opentries < 50) {
usleep(100 * 1000); usleep(100 * 1000);
@ -1965,7 +1969,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
} }
virReportSystemError(errno, virReportSystemError(errno,
_("cannot read dir '%s'"), _("cannot read dir '%s'"),
pool->def->target.path); def->target.path);
return NULL; return NULL;
} }
@ -1981,8 +1985,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
retry: retry:
while ((direrr = virDirRead(dh, &dent, NULL)) > 0) { while ((direrr = virDirRead(dh, &dent, NULL)) > 0) {
if (virAsprintf(&stablepath, "%s/%s", if (virAsprintf(&stablepath, "%s/%s",
pool->def->target.path, def->target.path, dent->d_name) < 0) {
dent->d_name) < 0) {
VIR_DIR_CLOSE(dh); VIR_DIR_CLOSE(dh);
return NULL; return NULL;
} }
@ -2020,6 +2023,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
virStorageVolDefPtr inputvol, virStorageVolDefPtr inputvol,
unsigned int flags) unsigned int flags)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int err; int err;
virCheckFlags(0, -1); virCheckFlags(0, -1);
@ -2044,7 +2048,7 @@ createFileDir(virConnectPtr conn ATTRIBUTE_UNUSED,
vol->target.perms->mode), vol->target.perms->mode),
vol->target.perms->uid, vol->target.perms->uid,
vol->target.perms->gid, vol->target.perms->gid,
(pool->def->type == VIR_STORAGE_POOL_NETFS (def->type == VIR_STORAGE_POOL_NETFS
? VIR_DIR_CREATE_AS_UID : 0))) < 0) { ? VIR_DIR_CREATE_AS_UID : 0))) < 0) {
return -1; return -1;
} }
@ -2064,6 +2068,8 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
virStorageVolDefPtr vol) virStorageVolDefPtr vol)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
if (vol->target.format == VIR_STORAGE_FILE_DIR) if (vol->target.format == VIR_STORAGE_FILE_DIR)
vol->type = VIR_STORAGE_VOL_DIR; vol->type = VIR_STORAGE_VOL_DIR;
else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) else if (vol->target.format == VIR_STORAGE_FILE_PLOOP)
@ -2081,8 +2087,7 @@ virStorageBackendVolCreateLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
VIR_FREE(vol->target.path); VIR_FREE(vol->target.path);
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, def->target.path, vol->name) < 0)
vol->name) < 0)
return -1; return -1;
if (virFileExists(vol->target.path)) { if (virFileExists(vol->target.path)) {
@ -2768,6 +2773,7 @@ virStorageBackendVolWipeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
int int
virStorageBackendBuildLocal(virStoragePoolObjPtr pool) virStorageBackendBuildLocal(virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int ret = -1; int ret = -1;
char *parent = NULL; char *parent = NULL;
char *p = NULL; char *p = NULL;
@ -2775,12 +2781,12 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool)
bool needs_create_as_uid; bool needs_create_as_uid;
unsigned int dir_create_flags; unsigned int dir_create_flags;
if (VIR_STRDUP(parent, pool->def->target.path) < 0) if (VIR_STRDUP(parent, def->target.path) < 0)
goto cleanup; goto cleanup;
if (!(p = strrchr(parent, '/'))) { if (!(p = strrchr(parent, '/'))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("path '%s' is not absolute"), _("path '%s' is not absolute"),
pool->def->target.path); def->target.path);
goto cleanup; goto cleanup;
} }
@ -2796,11 +2802,11 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool)
} }
dir_create_flags = VIR_DIR_CREATE_ALLOW_EXIST; dir_create_flags = VIR_DIR_CREATE_ALLOW_EXIST;
needs_create_as_uid = (pool->def->type == VIR_STORAGE_POOL_NETFS); needs_create_as_uid = (def->type == VIR_STORAGE_POOL_NETFS);
mode = pool->def->target.perms.mode; mode = def->target.perms.mode;
if (mode == (mode_t) -1 && if (mode == (mode_t) -1 &&
(needs_create_as_uid || !virFileExists(pool->def->target.path))) (needs_create_as_uid || !virFileExists(def->target.path)))
mode = VIR_STORAGE_DEFAULT_POOL_PERM_MODE; mode = VIR_STORAGE_DEFAULT_POOL_PERM_MODE;
if (needs_create_as_uid) if (needs_create_as_uid)
dir_create_flags |= VIR_DIR_CREATE_AS_UID; dir_create_flags |= VIR_DIR_CREATE_AS_UID;
@ -2808,10 +2814,10 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool)
/* Now create the final dir in the path with the uid/gid/mode /* Now create the final dir in the path with the uid/gid/mode
* requested in the config. If the dir already exists, just set * requested in the config. If the dir already exists, just set
* the perms. */ * the perms. */
if (virDirCreate(pool->def->target.path, if (virDirCreate(def->target.path,
mode, mode,
pool->def->target.perms.uid, def->target.perms.uid,
pool->def->target.perms.gid, def->target.perms.gid,
dir_create_flags) < 0) dir_create_flags) < 0)
goto cleanup; goto cleanup;
@ -2836,14 +2842,16 @@ virStorageBackendDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool, virStoragePoolObjPtr pool,
unsigned int flags) unsigned int flags)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virCheckFlags(0, -1); virCheckFlags(0, -1);
/* XXX delete all vols first ? */ /* XXX delete all vols first ? */
if (rmdir(pool->def->target.path) < 0) { if (rmdir(def->target.path) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("failed to remove pool '%s'"), _("failed to remove pool '%s'"),
pool->def->target.path); def->target.path);
return -1; return -1;
} }
@ -3575,6 +3583,7 @@ int
virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED, virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool) virStoragePoolObjPtr pool)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
struct statvfs sb; struct statvfs sb;
@ -3584,15 +3593,15 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
int direrr; int direrr;
int fd = -1, ret = -1; int fd = -1, ret = -1;
if (virDirOpen(&dir, pool->def->target.path) < 0) if (virDirOpen(&dir, def->target.path) < 0)
goto cleanup; goto cleanup;
while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) { while ((direrr = virDirRead(dir, &ent, def->target.path)) > 0) {
int err; int err;
if (virStringHasControlChars(ent->d_name)) { if (virStringHasControlChars(ent->d_name)) {
VIR_WARN("Ignoring file with control characters under '%s'", VIR_WARN("Ignoring file with control characters under '%s'",
pool->def->target.path); def->target.path);
continue; continue;
} }
@ -3604,8 +3613,7 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
vol->type = VIR_STORAGE_VOL_FILE; vol->type = VIR_STORAGE_VOL_FILE;
if (virAsprintf(&vol->target.path, "%s/%s", if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->target.path, def->target.path, vol->name) < 0)
vol->name) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(vol->key, vol->target.path) < 0) if (VIR_STRDUP(vol->key, vol->target.path) < 0)
@ -3633,17 +3641,17 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
if (VIR_ALLOC(target)) if (VIR_ALLOC(target))
goto cleanup; goto cleanup;
if ((fd = open(pool->def->target.path, O_RDONLY)) < 0) { if ((fd = open(def->target.path, O_RDONLY)) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("cannot open path '%s'"), _("cannot open path '%s'"),
pool->def->target.path); def->target.path);
goto cleanup; goto cleanup;
} }
if (fstat(fd, &statbuf) < 0) { if (fstat(fd, &statbuf) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("cannot stat path '%s'"), _("cannot stat path '%s'"),
pool->def->target.path); def->target.path);
goto cleanup; goto cleanup;
} }
@ -3651,24 +3659,24 @@ virStorageBackendRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
goto cleanup; goto cleanup;
/* VolTargetInfoFD doesn't update capacity correctly for the pool case */ /* 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, virReportSystemError(errno,
_("cannot statvfs path '%s'"), _("cannot statvfs path '%s'"),
pool->def->target.path); def->target.path);
goto cleanup; goto cleanup;
} }
pool->def->capacity = ((unsigned long long)sb.f_frsize * def->capacity = ((unsigned long long)sb.f_frsize *
(unsigned long long)sb.f_blocks); (unsigned long long)sb.f_blocks);
pool->def->available = ((unsigned long long)sb.f_bfree * def->available = ((unsigned long long)sb.f_bfree *
(unsigned long long)sb.f_frsize); (unsigned long long)sb.f_frsize);
pool->def->allocation = pool->def->capacity - pool->def->available; def->allocation = def->capacity - def->available;
pool->def->target.perms.mode = target->perms->mode; def->target.perms.mode = target->perms->mode;
pool->def->target.perms.uid = target->perms->uid; def->target.perms.uid = target->perms->uid;
pool->def->target.perms.gid = target->perms->gid; def->target.perms.gid = target->perms->gid;
VIR_FREE(pool->def->target.perms.label); VIR_FREE(def->target.perms.label);
if (VIR_STRDUP(pool->def->target.perms.label, target->perms->label) < 0) if (VIR_STRDUP(def->target.perms.label, target->perms->label) < 0)
goto cleanup; goto cleanup;
ret = 0; ret = 0;
@ -3738,6 +3746,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
uint32_t lun, uint32_t lun,
const char *dev) const char *dev)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStorageVolDefPtr vol = NULL; virStorageVolDefPtr vol = NULL;
char *devpath = NULL; char *devpath = NULL;
int retval = -1; int retval = -1;
@ -3749,12 +3758,12 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
* path to the device if the virDirRead loop to search the * path to the device if the virDirRead loop to search the
* target pool path for our devpath had failed. * target pool path for our devpath had failed.
*/ */
if (!virStorageBackendPoolPathIsStable(pool->def->target.path) && if (!virStorageBackendPoolPathIsStable(def->target.path) &&
!(STREQ(pool->def->target.path, "/dev") || !(STREQ(def->target.path, "/dev") ||
STREQ(pool->def->target.path, "/dev/"))) { STREQ(def->target.path, "/dev/"))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("unable to use target path '%s' for dev '%s'"), _("unable to use target path '%s' for dev '%s'"),
NULLSTR(pool->def->target.path), dev); NULLSTR(def->target.path), dev);
goto cleanup; goto cleanup;
} }
@ -3788,11 +3797,11 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
goto cleanup; goto cleanup;
if (STREQ(devpath, vol->target.path) && if (STREQ(devpath, vol->target.path) &&
!(STREQ(pool->def->target.path, "/dev") || !(STREQ(def->target.path, "/dev") ||
STREQ(pool->def->target.path, "/dev/"))) { STREQ(def->target.path, "/dev/"))) {
VIR_DEBUG("No stable path found for '%s' in '%s'", VIR_DEBUG("No stable path found for '%s' in '%s'",
devpath, pool->def->target.path); devpath, def->target.path);
retval = -2; retval = -2;
goto cleanup; goto cleanup;
@ -3807,8 +3816,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
if (!(vol->key = virStorageBackendSCSISerial(vol->target.path))) if (!(vol->key = virStorageBackendSCSISerial(vol->target.path)))
goto cleanup; goto cleanup;
pool->def->capacity += vol->target.capacity; def->capacity += vol->target.capacity;
pool->def->allocation += vol->target.allocation; def->allocation += vol->target.allocation;
if (virStoragePoolObjAddVol(pool, vol) < 0) if (virStoragePoolObjAddVol(pool, vol) < 0)
goto cleanup; goto cleanup;
@ -4085,6 +4094,7 @@ int
virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool, virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
uint32_t scanhost) uint32_t scanhost)
{ {
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
int retval = 0; int retval = 0;
uint32_t bus, target, lun; uint32_t bus, target, lun;
const char *device_path = "/sys/bus/scsi/devices"; const char *device_path = "/sys/bus/scsi/devices";
@ -4126,7 +4136,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
if (retval < 0) if (retval < 0)
return -1; return -1;
VIR_DEBUG("Found %d LUs for pool %s", found, pool->def->name); VIR_DEBUG("Found %d LUs for pool %s", found, def->name);
return found; return found;
} }