]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: drop redundant parameters during probe
authorEric Blake <eblake@redhat.com>
Tue, 1 Apr 2014 23:52:41 +0000 (17:52 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 2 Apr 2014 12:03:01 +0000 (06:03 -0600)
Now that each virStorageSource can track allocation information,
and given that we already have the information without extra
syscalls, it's easier to just always populate the information
directly into the struct than it is to sometimes pass the address
of the struct members down the call chain.

* src/storage/storage_backend.h (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Update signature.
* src/storage/storage_backend.c (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Always populate struct
members instead.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol): Update client.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_disk.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_scsi.c

index c8cf50e3fe185b8e87870c20479d44c8a0d6389c..8fe3687099698a15fc1d025e11179d0f02b9f23f 100644 (file)
@@ -1385,8 +1385,6 @@ virStorageBackendVolOpen(const char *path, struct stat *sb,
 
 int
 virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
-                                     unsigned long long *allocation,
-                                     unsigned long long *capacity,
                                      bool withBlockVolFormat,
                                      unsigned int openflags)
 {
@@ -1397,11 +1395,7 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
         goto cleanup;
     fd = ret;
 
-    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target,
-                                                      fd,
-                                                      &sb,
-                                                      allocation,
-                                                      capacity)) < 0)
+    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
         goto cleanup;
 
     if (withBlockVolFormat) {
@@ -1417,22 +1411,18 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
 
 int
 virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
-                               bool withCapacity,
                                bool withBlockVolFormat,
                                unsigned int openflags)
 {
     int ret;
 
     if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
-                                    &vol->target.allocation,
-                                    withCapacity ? &vol->target.capacity : NULL,
                                     withBlockVolFormat,
                                     openflags)) < 0)
         return ret;
 
     if (vol->backingStore.path &&
         (ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
-                                            NULL, NULL,
                                             withBlockVolFormat,
                                             VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
         return ret;
@@ -1453,50 +1443,42 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
 int
 virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
                                        int fd,
-                                       struct stat *sb,
-                                       unsigned long long *allocation,
-                                       unsigned long long *capacity)
+                                       struct stat *sb)
 {
 #if WITH_SELINUX
     security_context_t filecon = NULL;
 #endif
 
-    if (allocation) {
-        if (S_ISREG(sb->st_mode)) {
+    if (S_ISREG(sb->st_mode)) {
 #ifndef WIN32
-            *allocation = (unsigned long long)sb->st_blocks *
-                          (unsigned long long)DEV_BSIZE;
+        target->allocation = (unsigned long long)sb->st_blocks *
+            (unsigned long long)DEV_BSIZE;
 #else
-            *allocation = sb->st_size;
+        target->allocation = sb->st_size;
 #endif
-            /* Regular files may be sparse, so logical size (capacity) is not same
-             * as actual allocation above
-             */
-            if (capacity)
-                *capacity = sb->st_size;
-        } else if (S_ISDIR(sb->st_mode)) {
-            *allocation = 0;
-            if (capacity)
-                *capacity = 0;
-
-        } 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
-             * size of both CHAR / BLOCK devices we should check for in
-             * configure
-             */
-            end = lseek(fd, 0, SEEK_END);
-            if (end == (off_t)-1) {
-                virReportSystemError(errno,
-                                     _("cannot seek to end of file '%s'"),
-                                     target->path);
-                return -1;
-            }
-            *allocation = end;
-            if (capacity)
-                *capacity = end;
+        /* Regular files may be sparse, so logical size (capacity) is not same
+         * as actual allocation above
+         */
+        target->capacity = sb->st_size;
+    } else if (S_ISDIR(sb->st_mode)) {
+        target->allocation = 0;
+        target->capacity = 0;
+    } 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
+         * size of both CHAR / BLOCK devices we should check for in
+         * configure
+         */
+        end = lseek(fd, 0, SEEK_END);
+        if (end == (off_t)-1) {
+            virReportSystemError(errno,
+                                 _("cannot seek to end of file '%s'"),
+                                 target->path);
+            return -1;
         }
+        target->allocation = end;
+        target->capacity = end;
     }
 
     if (!target->perms && VIR_ALLOC(target->perms) < 0)
index 8442c13e973d4ebb4bed75fd85ee51d6bc8c57a0..89511f8c8239856a62eb65129526762ffa54cb09 100644 (file)
@@ -138,19 +138,14 @@ int virStorageBackendVolOpen(const char *path, struct stat *sb,
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
-                                   bool withCapacity,
                                    bool withBlockVolFormat,
                                    unsigned int openflags);
 int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
-                                         unsigned long long *allocation,
-                                         unsigned long long *capacity,
                                          bool withBlockVolFormat,
                                          unsigned int openflags);
 int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
                                            int fd,
-                                           struct stat *sb,
-                                           unsigned long long *allocation,
-                                           unsigned long long *capacity);
+                                           struct stat *sb);
 
 char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
                                   const char *devpath,
index 13336fc9f700d633b11f2f021002294d428b8a6f..9cebccae2b8dac08f669b06b9db9f274735f9e6a 100644 (file)
@@ -113,7 +113,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
     }
 
     /* Refresh allocation/capacity/perms */
-    if (virStorageBackendUpdateVolInfo(vol, true, false,
+    if (virStorageBackendUpdateVolInfo(vol, false,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
         return -1;
 
index e8617cbe2bdd3c726c7c44c7e5bef14efd3672b4..501fa8d2583f89c0f816446effae11e47b2b8f9f 100644 (file)
@@ -65,8 +65,6 @@ static int ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
 virStorageBackendProbeTarget(virStorageSourcePtr target,
                              char **backingStore,
                              int *backingStoreFormat,
-                             unsigned long long *allocation,
-                             unsigned long long *capacity,
                              virStorageEncryptionPtr *encryption)
 {
     int fd = -1;
@@ -86,9 +84,7 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         goto error; /* Take care to propagate ret, it is not always -1 */
     fd = ret;
 
-    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb,
-                                                      allocation,
-                                                      capacity)) < 0) {
+    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0) {
         goto error;
     }
 
@@ -143,8 +139,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         ret = 0;
     }
 
-    if (capacity && meta && meta->capacity)
-        *capacity = meta->capacity;
+    if (meta && meta->capacity)
+        target->capacity = meta->capacity;
 
     if (encryption && meta && meta->encrypted) {
         if (VIR_ALLOC(*encryption) < 0)
@@ -880,8 +876,6 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         if ((ret = virStorageBackendProbeTarget(&vol->target,
                                                 &backingStore,
                                                 &backingStoreFormat,
-                                                &vol->target.allocation,
-                                                &vol->target.capacity,
                                                 &vol->target.encryption)) < 0) {
             if (ret == -2) {
                 /* Silently ignore non-regular files,
@@ -909,7 +903,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
             vol->backingStore.format = backingStoreFormat;
 
             if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
-                                        NULL, NULL, false,
+                                                     false,
                                         VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
                 /* The backing file is currently unavailable, the capacity,
                  * allocation, owner, group and mode are unknown. Just log the
@@ -1194,7 +1188,7 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
     int ret;
 
     /* Refresh allocation / permissions info in case its changed */
-    ret = virStorageBackendUpdateVolInfo(vol, false, false,
+    ret = virStorageBackendUpdateVolInfo(vol, false,
                                          VIR_STORAGE_VOL_FS_OPEN_FLAGS);
     if (ret < 0)
         return ret;
index 6eed3ec2ec3855676b197dde1884b274ea7173fd..4aec44bae226385b0f6e2d8ad93e83d5e79edb23 100644 (file)
@@ -267,9 +267,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     if (VIR_ALLOC(vol) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st,
-                                               &vol->target.allocation,
-                                               &vol->target.capacity) < 0)
+    if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st) < 0)
         goto cleanup;
 
     if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0)
index a597e6745c71334d97829cc880abc1c7e02c7099..ed3a012cfb22c72d0f2e3eb3545adcf4221864d7 100644 (file)
@@ -149,7 +149,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
     if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolInfo(vol, true, false,
+    if (virStorageBackendUpdateVolInfo(vol, false,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
         goto cleanup;
 
index 8c3b0dfae5698e573aac48107315d824645998b7..f0ed189e614e40b58448d74ed2118719be3756cc 100644 (file)
@@ -60,7 +60,7 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
     if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolInfo(vol, true, true,
+    if (virStorageBackendUpdateVolInfo(vol, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
         goto cleanup;
     }
index 6652a6a3a8d330725e5bd831b5e6889603a35ed2..cf546fbe40b8098fb6985043dc88a2358349c465 100644 (file)
@@ -199,7 +199,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
         goto free_vol;
     }
 
-    if (virStorageBackendUpdateVolInfo(vol, true, true,
+    if (virStorageBackendUpdateVolInfo(vol, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to update volume for '%s'"),