This means pool XML actually reports accurate user/group/mode/label.
This uses UpdateVolTargetInfoFD in a bit of a hackish way, but it works
---
src/storage/storage_backend_fs.c | 58 ++++++++++++++++++++++++++++++----------
1 file changed, 44 insertions(+), 14 deletions(-)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 51d6bb3..804b7c3 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -816,12 +816,6 @@ virStorageBackendFileSystemBuild(virConnectPtr conn
ATTRIBUTE_UNUSED,
goto error;
}
- /* Reflect the actual uid and gid to the config. */
- if (pool->def->target.perms.uid == (uid_t) -1)
- pool->def->target.perms.uid = geteuid();
- if (pool->def->target.perms.gid == (gid_t) -1)
- pool->def->target.perms.gid = getegid();
-
if (flags != 0) {
ret = virStorageBackendMakeFileSystem(pool, flags);
} else {
@@ -845,8 +839,11 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn
ATTRIBUTE_UNUSED,
DIR *dir;
struct dirent *ent;
struct statvfs sb;
+ struct stat statbuf;
virStorageVolDefPtr vol = NULL;
+ virStorageSourcePtr target = NULL;
int direrr;
+ int fd = -1, ret = -1;
if (!(dir = opendir(pool->def->target.path))) {
virReportSystemError(errno,
@@ -856,7 +853,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn
ATTRIBUTE_UNUSED,
}
while ((direrr = virDirRead(dir, &ent, pool->def->target.path)) > 0) {
- int ret;
+ int err;
if (virStringHasControlChars(ent->d_name)) {
VIR_WARN("Ignoring file with control characters under
'%s'",
@@ -880,15 +877,15 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn
ATTRIBUTE_UNUSED,
if (VIR_STRDUP(vol->key, vol->target.path) < 0)
goto error;
- if ((ret = virStorageBackendProbeTarget(&vol->target,
+ if ((err = virStorageBackendProbeTarget(&vol->target,
&vol->target.encryption)) < 0)
{
- if (ret == -2) {
+ if (err == -2) {
/* Silently ignore non-regular files,
* eg '.' '..', 'lost+found', dangling symbolic
link */
virStorageVolDefFree(vol);
vol = NULL;
continue;
- } else if (ret == -3) {
+ } else if (err == -3) {
/* The backing file is currently unavailable, its format is not
* explicitly specified, the probe to auto detect the format
* failed: continue with faked RAW format, since AUTO will
@@ -918,27 +915,60 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn
ATTRIBUTE_UNUSED,
if (direrr < 0)
goto error;
closedir(dir);
+ dir = NULL;
+ vol = NULL;
+
+ if (VIR_ALLOC(target))
+ goto error;
+
+ if ((fd = open(pool->def->target.path, O_RDONLY)) < 0) {
+ virReportSystemError(errno,
+ _("cannot open path '%s'"),
+ pool->def->target.path);
+ goto error;
+ }
+ if (fstat(fd, &statbuf) < 0) {
+ virReportSystemError(errno,
+ _("cannot stat path '%s'"),
+ pool->def->target.path);
+ goto error;
+ }
+
+ if (virStorageBackendUpdateVolTargetInfoFD(target, fd, &statbuf) < 0)
+ goto error;
+
+ /* VolTargetInfoFD doesn't update capacity correctly for the pool case */
if (statvfs(pool->def->target.path, &sb) < 0) {
virReportSystemError(errno,
_("cannot statvfs path '%s'"),
pool->def->target.path);
- return -1;
+ goto error;
}
+
pool->def->capacity = ((unsigned long long)sb.f_frsize *
(unsigned long long)sb.f_blocks);
pool->def->available = ((unsigned long long)sb.f_bfree *
(unsigned long long)sb.f_frsize);
pool->def->allocation = pool->def->capacity -
pool->def->available;
- return 0;
+ pool->def->target.perms.mode = target->perms->mode;
+ pool->def->target.perms.uid = target->perms->uid;
+ pool->def->target.perms.gid = target->perms->gid;
+ VIR_FREE(pool->def->target.perms.label);
+ if (VIR_STRDUP(pool->def->target.perms.label, target->perms->label) <
0)
+ goto error;
+ ret = 0;
error:
if (dir)
closedir(dir);
+ VIR_FORCE_CLOSE(fd);
virStorageVolDefFree(vol);
- virStoragePoolObjClearVols(pool);
- return -1;
+ virStorageSourceFree(target);
+ if (ret < 0)
+ virStoragePoolObjClearVols(pool);
+ return ret;
}
--
2.3.6