]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: improve the while loop virStorageBackendFileSystemIsMounted
authorYi Li <yili@winhong.com>
Thu, 31 Oct 2019 03:55:26 +0000 (11:55 +0800)
committerJán Tomko <jtomko@redhat.com>
Tue, 12 Nov 2019 12:56:47 +0000 (13:56 +0100)
Move virStorageBackendFileSystemGetPoolSource outside of the while loop

Signed-off-by: Yi Li <yili@winhong.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_fs.c

index 02b824867a0d986ed7ece616b88cc9316e00bc5e..27c10982e4996e0c0b39a6c0f8bdc92abdf71802 100644 (file)
@@ -258,10 +258,10 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
         goto cleanup;
     }
 
-    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
-        if (!(src = virStorageBackendFileSystemGetPoolSource(pool)))
-            goto cleanup;
+    if ((src = virStorageBackendFileSystemGetPoolSource(pool)) == NULL)
+        goto cleanup;
 
+    while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
         /* compare both mount destinations and sources to be sure the mounted
          * FS pool is really the one we're looking for
          */
@@ -273,8 +273,6 @@ virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool)
             ret = 1;
             goto cleanup;
         }
-
-        VIR_FREE(src);
     }
 
     ret = 0;