From: James Simmons Date: Tue, 24 Mar 2020 18:49:48 +0000 (-0400) Subject: LU-13274 uapi: make lnet UAPI headers C99 compliant X-Git-Tag: 2.13.54~226 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=742897a967cff5be53c447d14b17ae405c2b31f2 LU-13274 uapi: make lnet UAPI headers C99 compliant 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 Reviewed-on: https://review.whamcloud.com/37971 Tested-by: jenkins Reviewed-by: Shaun Tancheff Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/Makefile.in b/Makefile.in index 76cb6e9..8644108 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -obj-m += @LDISKFS_SUBDIR@/ @LIBCFS_SUBDIR@/ lnet/ +obj-m += @LDISKFS_SUBDIR@/ libcfs/ lnet/ obj-m += lustre/ @INCLUDE_RULES@ diff --git a/autoMakefile.am b/autoMakefile.am index a1644c7..51c27d0 100644 --- a/autoMakefile.am +++ b/autoMakefile.am @@ -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 diff --git a/config/lustre-build.m4 b/config/lustre-build.m4 index 7d9ab58..4f3ac4f 100644 --- a/config/lustre-build.m4 +++ b/config/lustre-build.m4 @@ -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 diff --git a/libcfs/include/libcfs/util/ioctl.h b/libcfs/include/libcfs/util/ioctl.h index a42e0c5..f93ed87 100644 --- a/libcfs/include/libcfs/util/ioctl.h +++ b/libcfs/include/libcfs/util/ioctl.h @@ -43,7 +43,7 @@ /* Sparse annotation. */ #define __user -#include +#include #define LIBCFS_IOC_INIT(data) \ do { \ diff --git a/lnet/include/uapi/linux/lnet/libcfs_ioctl.h b/lnet/include/uapi/linux/lnet/libcfs_ioctl.h index 1b0daad..e6419f0 100644 --- a/lnet/include/uapi/linux/lnet/libcfs_ioctl.h +++ b/lnet/include/uapi/linux/lnet/libcfs_ioctl.h @@ -40,6 +40,13 @@ #include #include +/* + * sparse kernel source annotations + */ +#ifndef __user +#define __user +#endif + #define LIBCFS_IOCTL_VERSION 0x0001000a #define LIBCFS_IOCTL_VERSION2 0x0001000b diff --git a/lnet/include/uapi/linux/lnet/lnet-dlc.h b/lnet/include/uapi/linux/lnet/lnet-dlc.h index a1d2d0c..bba8aa3 100644 --- a/lnet/include/uapi/linux/lnet/lnet-dlc.h +++ b/lnet/include/uapi/linux/lnet/lnet-dlc.h @@ -30,17 +30,8 @@ #define __UAPI_LNET_DLC_H_ #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -# include -# include -#else -# include -# include -#endif +#include +#include #define MAX_NUM_SHOW_ENTRIES 32 #define LNET_MAX_STR_LEN 128 @@ -52,6 +43,13 @@ #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]; }; diff --git a/lnet/include/uapi/linux/lnet/lnetctl.h b/lnet/include/uapi/linux/lnet/lnetctl.h index cdf5849..bbbed82 100644 --- a/lnet/include/uapi/linux/lnet/lnetctl.h +++ b/lnet/include/uapi/linux/lnet/lnetctl.h @@ -23,17 +23,7 @@ #define __UAPI_LNETCTL_H_ #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -# include -#else -# include -#endif - -#include +#include /** \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 { diff --git a/lnet/include/uapi/linux/lnet/lnetst.h b/lnet/include/uapi/linux/lnet/lnetst.h index 804e5e8..bce9477 100644 --- a/lnet/include/uapi/linux/lnet/lnetst.h +++ b/lnet/include/uapi/linux/lnet/lnetst.h @@ -36,6 +36,8 @@ #define __UAPI_LNET_ST_H__ #include +#include +#include #define LST_FEAT_NONE (0) #define LST_FEAT_BULK_LEN (1 << 0) /* enable variable page size */ @@ -65,6 +67,13 @@ #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 */ diff --git a/lnet/include/uapi/linux/lnet/nidstr.h b/lnet/include/uapi/linux/lnet/nidstr.h index c4a297f..a32f379 100644 --- a/lnet/include/uapi/linux/lnet/nidstr.h +++ b/lnet/include/uapi/linux/lnet/nidstr.h @@ -29,15 +29,7 @@ #define _LNET_NIDSTRINGS_H #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -# include -#else -# include -#endif +#include /** * 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); diff --git a/lnet/utils/Makefile.am b/lnet/utils/Makefile.am index fdd0918..93d2219 100644 --- a/lnet/utils/Makefile.am +++ b/lnet/utils/Makefile.am @@ -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) diff --git a/lnet/utils/lnetconfig/Makefile.am b/lnet/utils/lnetconfig/Makefile.am index b14785f..642ef2f 100644 --- a/lnet/utils/lnetconfig/Makefile.am +++ b/lnet/utils/lnetconfig/Makefile.am @@ -29,10 +29,9 @@ 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 diff --git a/lnet/include/cyaml.h b/lnet/utils/lnetconfig/cyaml.h similarity index 100% rename from lnet/include/cyaml.h rename to lnet/utils/lnetconfig/cyaml.h diff --git a/lnet/utils/lnetctl.c b/lnet/utils/lnetctl.c index 5c23c5c..d600730 100644 --- a/lnet/utils/lnetctl.c +++ b/lnet/utils/lnetctl.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include "lnetconfig/cyaml.h" #include "lnetconfig/liblnetconfig.h" #define LNET_CONFIGURE true diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 9e53606..a466c76 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -5,7 +5,6 @@ # AC_DEFUN([LC_CONFIG_SRCDIR], [ AC_CONFIG_SRCDIR([lustre/obdclass/obdo.c]) -libcfs_is_module="yes" ldiskfs_is_ext4="yes" ]) diff --git a/lustre/include/lustre_handles.h b/lustre/include/lustre_handles.h index e94e1f6..004bc80 100644 --- a/lustre/include/lustre_handles.h +++ b/lustre/include/lustre_handles.h @@ -39,11 +39,7 @@ */ #include -#ifdef HAVE_REFCOUNT_T #include -#else -#include -#endif #include #include diff --git a/lustre/include/lustre_import.h b/lustre/include/lustre_import.h index aa2e9a3..92398da 100644 --- a/lustre/include/lustre_import.h +++ b/lustre/include/lustre_import.h @@ -45,11 +45,7 @@ #include #include #include -#ifdef HAVE_REFCOUNT_T #include -#else -#include -#endif #include #include #include diff --git a/lustre/obdclass/lu_object.c b/lustre/obdclass/lu_object.c index cd2f481..b67bed1 100644 --- a/lustre/obdclass/lu_object.c +++ b/lustre/obdclass/lu_object.c @@ -42,11 +42,7 @@ #include #include -#ifdef HAVE_PROCESSOR_H #include -#else -#include -#endif #include #include diff --git a/lustre/tests/sanity-lnet.sh b/lustre/tests/sanity-lnet.sh index d9b6819..4a78b38 100755 --- a/lustre/tests/sanity-lnet.sh +++ b/lustre/tests/sanity-lnet.sh @@ -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 diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index 118a719..5d664dd 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -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 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 03778a3..a1198e0 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -76,7 +76,7 @@ #include #include #include -#include +#include #ifndef ARRAY_SIZE # define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))