[libvirt] one more warning

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

 



One more warning question:
Compiling with all storage backends disabled, I get this:

storage_backend.c:91: warning: comparison of unsigned expression < 0 is always false

That's because of this code:

static virStorageBackendPtr backends[] = {
#if WITH_STORAGE_DIR
    &virStorageBackendDirectory,
#endif
#if WITH_STORAGE_FS
    &virStorageBackendFileSystem,
    &virStorageBackendNetFileSystem,
#endif
#if WITH_STORAGE_LVM
    &virStorageBackendLogical,
#endif
#if WITH_STORAGE_ISCSI
    &virStorageBackendISCSI,
#endif
#if WITH_STORAGE_DISK
    &virStorageBackendDisk,
#endif
};


virStorageBackendPtr
virStorageBackendForType(int type) {
    unsigned int i;
    for (i = 0 ; i < ARRAY_CARDINALITY(backends); i++)
        if (backends[i]->type == type)
            return backends[i];

    virStorageReportError(NULL, VIR_ERR_INTERNAL_ERROR,
                          _("missing backend for pool type %d"), type);
    return NULL;
}

The above loses because ARRAY_CARDINALITY(backends) is 0.

One solution is to always have at least one backend,
e.g., the first one, in which case, this patch works fine:
[but if you like this (i don't), it'd make sense also to remove the
configure-time option ]

diff --git a/src/storage_backend.c b/src/storage_backend.c
index e33f98c..264cc53 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -56,9 +56,7 @@
 #if WITH_STORAGE_DISK
 #include "storage_backend_disk.h"
 #endif
-#if WITH_STORAGE_DIR
 #include "storage_backend_fs.h"
-#endif

 VIR_ENUM_IMPL(virStorageBackendPartTable,
               VIR_STORAGE_POOL_DISK_LAST,
@@ -66,9 +64,7 @@ VIR_ENUM_IMPL(virStorageBackendPartTable,
               "mac", "bsd", "pc98", "sun", "lvm2");

 static virStorageBackendPtr backends[] = {
-#if WITH_STORAGE_DIR
     &virStorageBackendDirectory,
-#endif
 #if WITH_STORAGE_FS
     &virStorageBackendFileSystem,
     &virStorageBackendNetFileSystem,

Another way is to add a NULL pointer at the end
and change the loop not to use the array size at all:

    for (i = 0; backends[i]; i++)
        if (backends[i]->type == type)
            return backends[i];

I chose the latter:

diff --git a/src/storage_backend.c b/src/storage_backend.c
index e33f98c..1f4ed10 100644
--- a/src/storage_backend.c
+++ b/src/storage_backend.c
@@ -82,13 +82,14 @@ static virStorageBackendPtr backends[] = {
 #if WITH_STORAGE_DISK
     &virStorageBackendDisk,
 #endif
+    NULL
 };


 virStorageBackendPtr
 virStorageBackendForType(int type) {
     unsigned int i;
-    for (i = 0 ; i < ARRAY_CARDINALITY(backends); i++)
+    for (i = 0; backends[i]; i++)
         if (backends[i]->type == type)
             return backends[i];

--
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]