vhost: fix header for strict compilation flags
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>
Wed, 26 Apr 2017 12:07:13 +0000 (14:07 +0200)
committerThomas Monjalon <thomas@monjalon.net>
Sun, 30 Apr 2017 22:13:15 +0000 (00:13 +0200)
Exported headers must allow compilation with the strictest flags. This
commit addresses the following errors:

 In file included from /tmp/check-includes.sh.20132.c:1:0:
 build/include/rte_vhost.h:73:30: error: ISO C forbids zero-size array
    'regions' [-Werror=pedantic]
 [...]

Also:

- Add C++ awareness to rte_vhost.h for consistency with rte_eth_vhost.h.
- Move Linux includes into C++ block to prevent linking issues with
  exported symbols.
- Update check-includes.sh following the removal of rte_virtio_net.h.

Finally, update check-includes.sh to ignore rte_vhost.h and rte_eth_vhost.h
from now on since the Linux headers they depend on are not clean enough:

 In file included from /usr/include/linux/vhost.h:17:0,
                  from build/include/rte_vhost.h:43,
                  from build/include/rte_eth_vhost.h:44,
                  from /tmp/check-includes.sh.20132.c:1:
 /usr/include/linux/virtio_ring.h: In function 'vring_init':
 /usr/include/linux/virtio_ring.h:146:16: error: pointer of type 'void *'
    used in arithmetic [-Werror=pointer-arith]
 [...]
 In file included from build/include/rte_vhost.h:43:0,
                  from build/include/rte_eth_vhost.h:44,
                  from /tmp/check-includes.sh.20132.c:1:
 /usr/include/linux/vhost.h: At top level:
 /usr/include/linux/vhost.h:73:3: error: ISO C99 doesn't support unnamed
    structs/unions [-Werror=pedantic]
 [...]

Fixes: eb32247457fe ("vhost: export guest memory regions")
Fixes: a798beb47c8e ("vhost: rename header file")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
devtools/check-includes.sh
lib/librte_vhost/rte_vhost.h

index d65adc6..c4ec73f 100755 (executable)
@@ -109,10 +109,12 @@ include_dir=${1:-build/include}
        'rte_byteorder_64.h' \
        'generic/*' \
        'exec-env/*' \
+       'rte_vhost.h' \
+       'rte_eth_vhost.h' \
 }
 : ${IGNORE_CXX= \
+       'rte_vhost.h' \
        'rte_eth_vhost.h' \
-       'rte_virtio_net.h' \
 }
 
 temp_cc=/tmp/${0##*/}.$$.c
index 7a586e4..605e47c 100644 (file)
  */
 
 #include <stdint.h>
-#include <linux/vhost.h>
-#include <linux/virtio_ring.h>
 #include <sys/eventfd.h>
 
 #include <rte_memory.h>
 #include <rte_mempool.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* These are not C++-aware. */
+#include <linux/vhost.h>
+#include <linux/virtio_ring.h>
+
 #define RTE_VHOST_USER_CLIENT          (1ULL << 0)
 #define RTE_VHOST_USER_NO_RECONNECT    (1ULL << 1)
 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY       (1ULL << 2)
@@ -70,7 +76,7 @@ struct rte_vhost_mem_region {
  */
 struct rte_vhost_memory {
        uint32_t nregions;
-       struct rte_vhost_mem_region regions[0];
+       struct rte_vhost_mem_region regions[];
 };
 
 struct rte_vhost_vring {
@@ -426,4 +432,8 @@ int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
                              struct rte_vhost_vring *vring);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _RTE_VHOST_H_ */