Whamcloud - gitweb
LU-13274 uapi: make lnet UAPI headers C99 compliant 71/37971/11
authorJames Simmons <jsimmons@infradead.org>
Tue, 24 Mar 2020 18:49:48 +0000 (14:49 -0400)
committerOleg Drokin <green@whamcloud.com>
Tue, 7 Apr 2020 17:53:26 +0000 (17:53 +0000)
Attempting to compile strict C99 user land applications or
libraries with the Lustre UAPI headers will fail. These same
errors can be seen by enabling CONFIG_UAPI_HEADER_TEST as well.
Update the LNet UAPI headers to be compilable with -std=c99.
Add LNet test covering UAPI header handling.

Test-Parameters: trivial testlist=sanity-lnet

Change-Id: Ic1c30ed2d4d9d1d7f11b657d3817a05161367e13
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/37971
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
20 files changed:
Makefile.in
autoMakefile.am
config/lustre-build.m4
libcfs/include/libcfs/util/ioctl.h
lnet/include/uapi/linux/lnet/libcfs_ioctl.h
lnet/include/uapi/linux/lnet/lnet-dlc.h
lnet/include/uapi/linux/lnet/lnetctl.h
lnet/include/uapi/linux/lnet/lnetst.h
lnet/include/uapi/linux/lnet/nidstr.h
lnet/utils/Makefile.am
lnet/utils/lnetconfig/Makefile.am
lnet/utils/lnetconfig/cyaml.h [moved from lnet/include/cyaml.h with 100% similarity]
lnet/utils/lnetctl.c
lustre/autoconf/lustre-core.m4
lustre/include/lustre_handles.h
lustre/include/lustre_import.h
lustre/obdclass/lu_object.c
lustre/tests/sanity-lnet.sh
lustre/utils/Makefile.am
lustre/utils/lfs.c

index 76cb6e9..8644108 100644 (file)
@@ -1,4 +1,4 @@
-obj-m += @LDISKFS_SUBDIR@/ @LIBCFS_SUBDIR@/ lnet/
+obj-m += @LDISKFS_SUBDIR@/ libcfs/ lnet/
 obj-m += lustre/
 
 @INCLUDE_RULES@
index a1644c7..51c27d0 100644 (file)
@@ -1,15 +1,15 @@
 SUBDIRS := @LDISKFS_SUBDIR@ \
        . \
        @LUSTREIOKIT_SUBDIR@ \
-       @LIBCFS_SUBDIR@ \
        @SNMP_SUBDIR@ \
+       libcfs \
        lnet \
        lustre
 
 DIST_SUBDIRS := ldiskfs \
        lustre-iokit \
-       @LIBCFS_SUBDIR@ \
        @SNMP_DIST_SUBDIR@ \
+       libcfs \
        lnet \
        lustre \
        config
index 7d9ab58..4f3ac4f 100644 (file)
@@ -103,19 +103,6 @@ AC_SUBST(LUSTREIOKIT_SUBDIR)
 AM_CONDITIONAL([BUILD_LUSTREIOKIT], [test "x$enable_iokit" = xyes])
 ]) # LB_PATH_LUSTREIOKIT
 
-# Define no libcfs by default.
-AC_DEFUN([LB_LIBCFS_DIR], [
-AS_IF([test "x$libcfs_is_module" = xyes], [
-               LIBCFS_INCLUDE_DIR="libcfs/include"
-               LIBCFS_SUBDIR="libcfs"
-       ], [
-               LIBCFS_INCLUDE_DIR="lnet/include"
-               LIBCFS_SUBDIR=""
-       ])
-AC_SUBST(LIBCFS_INCLUDE_DIR)
-AC_SUBST(LIBCFS_SUBDIR)
-]) # LB_LIBCFS_DIR
-
 #
 # LB_LIBMOUNT
 #
@@ -329,13 +316,14 @@ AS_IF([test $target_cpu = powerpc64], [
        CC="$CC -m64"
 ])
 
-CPPFLAGS="-I$PWD/$LIBCFS_INCLUDE_DIR -I$PWD/lnet/include -I$PWD/lnet/include/uapi -I$PWD/lustre/include -I$PWD/lustre/include/uapi $CPPFLAGS"
+# UAPI headers, libcfs/include for util headers, lustre/include for liblustreapi and friends
+CPPFLAGS="-I$PWD/libcfs/include -I$PWD/lnet/include/uapi -I$PWD/lustre/include -I$PWD/lustre/include/uapi $CPPFLAGS"
 
 CCASFLAGS="-Wall -fPIC -D_GNU_SOURCE"
 AC_SUBST(CCASFLAGS)
 
-# everyone builds against lnet and lustre
-EXTRA_KCFLAGS="$EXTRA_KCFLAGS -g -I$PWD/$LIBCFS_INCLUDE_DIR -I$PWD/lnet/include -I$PWD/lustre/include/uapi -I$PWD/lustre/include"
+# everyone builds against lnet and lustre kernel headers
+EXTRA_KCFLAGS="$EXTRA_KCFLAGS -g -I$PWD/libcfs/include -I$PWD/libcfs/include/libcfs -I$PWD/lnet/include/uapi -I$PWD/lnet/include -I$PWD/lustre/include/uapi -I$PWD/lustre/include"
 AC_SUBST(EXTRA_KCFLAGS)
 ]) # LB_PROG_CC
 
@@ -609,8 +597,6 @@ LB_CONFIG_DIST
 LB_DOWNSTREAM_RELEASE
 LB_USES_DPKG
 
-LB_LIBCFS_DIR
-
 LB_INCLUDE_RULES
 
 LB_PATH_DEFAULTS
index a42e0c5..f93ed87 100644 (file)
@@ -43,7 +43,7 @@
 /* Sparse annotation. */
 #define __user
 
-#include <uapi/linux/lnet/libcfs_ioctl.h>
+#include <linux/lnet/libcfs_ioctl.h>
 
 #define LIBCFS_IOC_INIT(data)                                  \
 do {                                                           \
index 1b0daad..e6419f0 100644 (file)
 #include <linux/types.h>
 #include <linux/ioctl.h>
 
+/*
+ * sparse kernel source annotations
+ */
+#ifndef __user
+#define __user
+#endif
+
 #define LIBCFS_IOCTL_VERSION 0x0001000a
 #define LIBCFS_IOCTL_VERSION2 0x0001000b
 
index a1d2d0c..bba8aa3 100644 (file)
 #define __UAPI_LNET_DLC_H_
 
 #include <linux/types.h>
-/*
- * This is due to us being out of kernel and the way the OpenSFS branch
- * handles CFLAGS.
- */
-#ifdef __KERNEL__
-# include <uapi/linux/lnet/libcfs_ioctl.h>
-# include <uapi/linux/lnet/lnet-types.h>
-#else
-# include <linux/lnet/libcfs_ioctl.h>
-# include <linux/lnet/lnet-types.h>
-#endif
+#include <linux/lnet/libcfs_ioctl.h>
+#include <linux/lnet/lnet-types.h>
 
 #define MAX_NUM_SHOW_ENTRIES   32
 #define LNET_MAX_STR_LEN       128
 #define LNET_RT_MULTI_HOP      (1 << 1)
 
 /*
+ * sparse kernel source annotations
+ */
+#ifndef __user
+#define __user
+#endif
+
+/*
  * To allow for future enhancements to extend the tunables
  * add a hdr to this structure, so that the version can be set
  * and checked for backwards compatibility. Newer versions of LNet
@@ -124,7 +122,7 @@ struct lnet_ioctl_ping_data {
        __u32 op_param;
        __u32 ping_count;
        __u32 ping_flags;
-       bool mr_info;
+       __u32 mr_info;
        struct lnet_process_id ping_id;
        struct lnet_process_id __user *ping_buf;
 };
@@ -264,7 +262,7 @@ struct lnet_ioctl_peer_cfg {
        lnet_nid_t prcfg_prim_nid;
        lnet_nid_t prcfg_cfg_nid;
        __u32 prcfg_count;
-       bool prcfg_mr;
+       __u32 prcfg_mr;
        __u32 prcfg_state;
        __u32 prcfg_size;
        void __user *prcfg_bulk;
@@ -272,16 +270,16 @@ struct lnet_ioctl_peer_cfg {
 
 struct lnet_ioctl_reset_health_cfg {
        struct libcfs_ioctl_hdr rh_hdr;
-       enum lnet_health_type rh_type;
-       bool rh_all;
-       int rh_value;
+       enum lnet_health_type rh_type:32;
+       __u16 rh_all:1;
+       __s16 rh_value;
        lnet_nid_t rh_nid;
 };
 
 struct lnet_ioctl_recovery_list {
        struct libcfs_ioctl_hdr rlst_hdr;
-       enum lnet_health_type rlst_type;
-       int rlst_num_nids;
+       enum lnet_health_type rlst_type:32;
+       __u32 rlst_num_nids;
        lnet_nid_t rlst_nid_array[LNET_MAX_SHOW_NUM_NID];
 };
 
index cdf5849..bbbed82 100644 (file)
 #define __UAPI_LNETCTL_H_
 
 #include <linux/types.h>
-/*
- * This is due to us being out of kernel and the way the OpenSFS branch
- * handles CFLAGS.
- */
-#ifdef __KERNEL__
-# include <uapi/linux/lnet/lnet-types.h>
-#else
-# include <linux/lnet/lnet-types.h>
-#endif
-
-#include <stdbool.h>
+#include <linux/lnet/lnet-types.h>
 
 /** \addtogroup lnet_fault_simulation
  * @{ */
@@ -111,9 +101,9 @@ struct lnet_fault_attr {
                        /** error type mask */
                        __u32                   da_health_error_mask;
                        /** randomize error generation */
-                       bool                    da_random;
+                       __u32                   da_random:1,
                        /** drop all messages if flag is set */
-                       bool                    da_drop_all;
+                                               da_drop_all:1;
                } drop;
                /** message latency simulation */
                struct {
index 804e5e8..bce9477 100644 (file)
@@ -36,6 +36,8 @@
 #define __UAPI_LNET_ST_H__
 
 #include <linux/types.h>
+#include <linux/lnet/lnet-types.h>
+#include <linux/time.h>
 
 #define LST_FEAT_NONE          (0)
 #define LST_FEAT_BULK_LEN      (1 << 0)        /* enable variable page size */
 #define LSTIO_BATCH_QUERY      0xC27           /* query batch status */
 #define LSTIO_STAT_QUERY       0xC30           /* get stats */
 
+/*
+ * sparse kernel source annotations
+ */
+#ifndef __user
+#define __user
+#endif
+
 struct lst_sid {
        lnet_nid_t      ses_nid;        /* nid of console node */
        __s64           ses_stamp;      /* time stamp in milliseconds */
@@ -117,6 +126,13 @@ struct lstcon_test_batch_ent {
 };                                                     /*** test/batch verbose information entry,
                                                         *** for list_batch command */
 
+/* This will go away once we move to netlink */
+#if !defined(__KERNEL__) && !defined(__LIBCFS_UTIL_LIST_H__)
+struct list_head {
+       struct list_head *next, *prev;
+};
+#endif
+
 struct lstcon_rpc_ent {
        struct list_head        rpe_link;               /* link chain */
        struct lnet_process_id  rpe_peer;               /* peer's id */
index c4a297f..a32f379 100644 (file)
 #define _LNET_NIDSTRINGS_H
 
 #include <linux/types.h>
-/*
- * This is due to us being out of kernel and the way the OpenSFS branch
- * handles CFLAGS.
- */
-#ifdef __KERNEL__
-# include <uapi/linux/lnet/lnet-types.h>
-#else
-# include <linux/lnet/lnet-types.h>
-#endif
+#include <linux/lnet/lnet-types.h>
 
 /**
  *  Lustre Network Driver types.
@@ -73,20 +65,20 @@ struct list_head;
 char *libcfs_next_nidstring(void);
 int libcfs_isknown_lnd(__u32 lnd);
 char *libcfs_lnd2modname(__u32 lnd);
-char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size);
+char *libcfs_lnd2str_r(__u32 lnd, char *buf, __kernel_size_t buf_size);
 static inline char *libcfs_lnd2str(__u32 lnd)
 {
        return libcfs_lnd2str_r(lnd, libcfs_next_nidstring(),
                                LNET_NIDSTR_SIZE);
 }
 int libcfs_str2lnd(const char *str);
-char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size);
+char *libcfs_net2str_r(__u32 net, char *buf, __kernel_size_t buf_size);
 static inline char *libcfs_net2str(__u32 net)
 {
        return libcfs_net2str_r(net, libcfs_next_nidstring(),
                                LNET_NIDSTR_SIZE);
 }
-char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size);
+char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, __kernel_size_t buf_size);
 static inline char *libcfs_nid2str(lnet_nid_t nid)
 {
        return libcfs_nid2str_r(nid, libcfs_next_nidstring(),
@@ -105,13 +97,13 @@ int cfs_expand_nidlist(struct list_head *nidlist, lnet_nid_t *lnet_nidlist,
 int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
 int cfs_ip_addr_match(__u32 addr, struct list_head *list);
 int cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
-                              char *max_nid, size_t nidstr_length);
+                              char *max_nid, __kernel_size_t nidstr_length);
 
 struct netstrfns {
        __u32   nf_type;
        char    *nf_name;
        char    *nf_modname;
-       void    (*nf_addr2str)(__u32 addr, char *str, size_t size);
+       void    (*nf_addr2str)(__u32 addr, char *str, __kernel_size_t size);
        int     (*nf_str2addr)(const char *str, int nob, __u32 *addr);
        int     (*nf_parse_addrlist)(char *str, int len,
                                     struct list_head *list);
index fdd0918..93d2219 100644 (file)
@@ -44,6 +44,7 @@ routerstat_SOURCES = routerstat.c
 routerstat_LDADD = $(top_builddir)/lnet/utils/lnetconfig/liblnetconfig.la
 
 lst_SOURCES = lst.c
+lst_CFLAGS = -fPIC -D_LINUX_TIME_H -D_GNU_SOURCE
 lst_LDADD = $(top_builddir)/lnet/utils/lnetconfig/liblnetconfig.la \
            $(LIBEFENCE)
 
index b14785f..642ef2f 100644 (file)
 lib_LTLIBRARIES = liblnetconfig.la
 
 liblnetconfig_la_SOURCES  = liblnetconfig.c liblnetconfig.h \
-                           liblnetconfig_lnd.c liblnd.h cyaml.c \
-                           $(top_builddir)/lnet/include/cyaml.h
+                           liblnetconfig_lnd.c liblnd.h cyaml.c cyaml.h
 liblnetconfig_la_CPPFLAGS = -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 \
-                           -DLUSTRE_UTILS=1 -I$(top_builddir)/lnet/include
+                           -DLUSTRE_UTILS=1 -fPIC
 liblnetconfig_la_LDFLAGS = -L$(top_builddir)/libcfs/libcfs -lyaml -lm \
                           $(LIBREADLINE) -version-info 4:0:0
 liblnetconfig_la_LIBADD = $(top_builddir)/libcfs/libcfs/libcfs.la
index 5c23c5c..d600730 100644 (file)
@@ -30,7 +30,7 @@
 #include <limits.h>
 #include <libcfs/util/ioctl.h>
 #include <libcfs/util/parser.h>
-#include <cyaml.h>
+#include "lnetconfig/cyaml.h"
 #include "lnetconfig/liblnetconfig.h"
 
 #define LNET_CONFIGURE         true
index 9e53606..a466c76 100644 (file)
@@ -5,7 +5,6 @@
 #
 AC_DEFUN([LC_CONFIG_SRCDIR], [
 AC_CONFIG_SRCDIR([lustre/obdclass/obdo.c])
-libcfs_is_module="yes"
 ldiskfs_is_ext4="yes"
 ])
 
index e94e1f6..004bc80 100644 (file)
  */
 
 #include <linux/rcupdate.h>
-#ifdef HAVE_REFCOUNT_T
 #include <linux/refcount.h>
-#else
-#include <libcfs/linux/linux-refcount.h>
-#endif
 #include <linux/spinlock.h>
 #include <libcfs/libcfs.h>
 
index aa2e9a3..92398da 100644 (file)
 #include <linux/atomic.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
-#ifdef HAVE_REFCOUNT_T
 #include <linux/refcount.h>
-#else
-#include <libcfs/linux/linux-refcount.h>
-#endif
 #include <linux/spinlock.h>
 #include <linux/time.h>
 #include <linux/types.h>
index cd2f481..b67bed1 100644 (file)
 
 #include <linux/module.h>
 #include <linux/list.h>
-#ifdef HAVE_PROCESSOR_H
 #include <linux/processor.h>
-#else
-#include <libcfs/linux/processor.h>
-#endif
 #include <linux/random.h>
 
 #include <libcfs/libcfs.h>
index d9b6819..4a78b38 100755 (executable)
@@ -1179,6 +1179,39 @@ test_203() {
 }
 run_test 203 "add a network using an interface in the non-default namespace"
 
+test_300() {
+       # LU-13274
+       local header
+       local out=$TMP/$tfile
+       local prefix=/usr/include/linux/lnet
+
+       # We use a hard coded prefix so that this test will not fail
+       # when run in tree.
+       CC=${CC:-cc}
+       if ! which $CC > /dev/null 2>&1; then
+               skip_env "$CC is not installed"
+       fi
+
+       cleanup_lnet || exit 1
+       load_lnet
+
+       if ! [[ -d $prefix ]]; then
+               # Assume we're running in tree and fixup the include path.
+               prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
+       fi
+
+       for header in $prefix/*.h; do
+               if ! [[ -f "$header" ]]; then
+                       continue
+               fi
+
+               $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out ||
+                       error "cannot compile '$header'"
+       done
+       rm -f $out
+}
+run_test 300 "packaged LNet UAPI headers can be compiled"
+
 complete $SECONDS
 
 cleanup_testsuite
index 118a719..5d664dd 100644 (file)
@@ -67,6 +67,7 @@ lctl_LDADD :=  liblustreapi.la $(PTHREAD_LIBS) -lyaml
 lctl_DEPENDENCIES := liblustreapi.la
 
 lfs_SOURCES = lfs.c lfs_project.c lfs_project.h
+lfs_CFLAGS := -fPIC -I $(top_builddir)/lnet/utils
 lfs_LDADD := liblustreapi.la -lz
 lfs_LDADD += $(top_builddir)/lnet/utils/lnetconfig/liblnetconfig.la
 lfs_DEPENDENCIES := liblustreapi.la
index 03778a3..a1198e0 100644 (file)
@@ -76,7 +76,7 @@
 #include <linux/lustre/lustre_ver.h>
 #include <linux/lustre/lustre_param.h>
 #include <linux/lnet/nidstr.h>
-#include <cyaml.h>
+#include <lnetconfig/cyaml.h>
 
 #ifndef ARRAY_SIZE
 # define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))