[PATCHv4 6/8] storage: improve allocation stats reported on gluster files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We already had code for handling allocation different than
capacity for sparse files; we just had to wire it up to be
used when inspecting gluster images.

* src/storage/storage_backend.c
(virStorageBackendUpdateVolTargetInfoFD): Handle no fd.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Handle sparse files.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/storage/storage_backend.c         | 8 ++++----
 src/storage/storage_backend_gluster.c | 7 ++++++-
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index c94e89a..57c1728 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1296,9 +1296,9 @@ int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,

 /*
  * virStorageBackendUpdateVolTargetInfoFD:
- * @conn: connection to report errors on
  * @target: target definition ptr of volume to update
- * @fd: fd of storage volume to update, via virStorageBackendOpenVol*
+ * @fd: fd of storage volume to update, via virStorageBackendOpenVol*, or -1
+ * @sb: details about file (must match @fd, if that is provided)
  * @allocation: If not NULL, updated allocation information will be stored
  * @capacity: If not NULL, updated capacity info will be stored
  *
@@ -1333,7 +1333,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
             if (capacity)
                 *capacity = 0;

-        } else {
+        } else if (fd >= 0) {
             off_t end;
             /* XXX this is POSIX compliant, but doesn't work for CHAR files,
              * only BLOCK. There is a Linux specific ioctl() for getting
@@ -1368,7 +1368,7 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,

 #if WITH_SELINUX
     /* XXX: make this a security driver call */
-    if (fgetfilecon_raw(fd, &filecon) == -1) {
+    if (fd >= 0 && fgetfilecon_raw(fd, &filecon) == -1) {
         if (errno != ENODATA && errno != ENOTSUP) {
             virReportSystemError(errno,
                                  _("cannot get file context of '%s'"),
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 89abb57..a4fd4b3 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -168,6 +168,12 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,

     if (VIR_ALLOC(vol) < 0)
         goto cleanup;
+
+    if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st,
+                                               &vol->allocation,
+                                               &vol->capacity) < 0)
+        goto cleanup;
+
     if (VIR_STRDUP(vol->name, name) < 0)
         goto cleanup;
     if (virAsprintf(&vol->key, "/%s%s%s", state->volname, state->dir,
@@ -194,7 +200,6 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     /* FIXME - must open files to determine if they are non-raw */
     vol->type = VIR_STORAGE_VOL_NETWORK;
     vol->target.format = VIR_STORAGE_FILE_RAW;
-    vol->capacity = vol->allocation = st->st_size;

     *volptr = vol;
     vol = NULL;
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]