From 7a7309fa849577ddd5a4f6bb5bfb69e84a7fec89 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Fri, 28 Feb 2020 20:49:42 -0500 Subject: [PATCH] LU-13274 uapi: make lustre 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 Lustre UAPI headers to be compilable with -std=c99. Enhance our current test covering UAPI header handling. For OpenSFS branch we can't include since we support kernels before struct statx existed and they will collide with the special definitions in lustre_user.h. Change-Id: Ifb0da33180dc3c7e116d6bf2b7f603ad0528277a Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/37678 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Gian-Carlo DeFazio Reviewed-by: Andreas Dilger Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- config/lustre-build.m4 | 2 +- lustre/include/lustre/lustreapi.h | 3 + .../uapi/linux/lustre/lustre_barrier_user.h | 10 +-- lustre/include/uapi/linux/lustre/lustre_cfg.h | 20 +----- lustre/include/uapi/linux/lustre/lustre_fid.h | 12 +--- lustre/include/uapi/linux/lustre/lustre_fiemap.h | 2 +- lustre/include/uapi/linux/lustre/lustre_idl.h | 20 +++--- lustre/include/uapi/linux/lustre/lustre_ioctl.h | 20 ++---- .../include/uapi/linux/lustre/lustre_lfsck_user.h | 10 +-- lustre/include/uapi/linux/lustre/lustre_log_user.h | 8 --- lustre/include/uapi/linux/lustre/lustre_ostid.h | 8 --- lustre/include/uapi/linux/lustre/lustre_user.h | 73 ++++++++++------------ lustre/tests/sanity.sh | 10 ++- 13 files changed, 67 insertions(+), 131 deletions(-) diff --git a/config/lustre-build.m4 b/config/lustre-build.m4 index f196ef0..7d9ab58 100644 --- a/config/lustre-build.m4 +++ b/config/lustre-build.m4 @@ -335,7 +335,7 @@ 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" +EXTRA_KCFLAGS="$EXTRA_KCFLAGS -g -I$PWD/$LIBCFS_INCLUDE_DIR -I$PWD/lnet/include -I$PWD/lustre/include/uapi -I$PWD/lustre/include" AC_SUBST(EXTRA_KCFLAGS) ]) # LB_PROG_CC diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 8db1450..39a8090 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -40,6 +40,9 @@ #include #include +#include +#include +#include #include #if defined(__cplusplus) diff --git a/lustre/include/uapi/linux/lustre/lustre_barrier_user.h b/lustre/include/uapi/linux/lustre/lustre_barrier_user.h index e86b262..3808424 100644 --- a/lustre/include/uapi/linux/lustre/lustre_barrier_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_barrier_user.h @@ -32,15 +32,7 @@ # define _LUSTRE_BARRIER_USER_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 #define BARRIER_VERSION_V1 1 #define BARRIER_TIMEOUT_DEFAULT 30 diff --git a/lustre/include/uapi/linux/lustre/lustre_cfg.h b/lustre/include/uapi/linux/lustre/lustre_cfg.h index 93884d7..30d5c7d 100644 --- a/lustre/include/uapi/linux/lustre/lustre_cfg.h +++ b/lustre/include/uapi/linux/lustre/lustre_cfg.h @@ -36,21 +36,7 @@ #include #include #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -# include -#else -# include -#endif - -/* Handle older distros */ -#ifndef __ALIGN_KERNEL -# define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) -# define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#endif +#include /** \defgroup cfg cfg * @@ -264,7 +250,7 @@ static inline void lustre_cfg_bufs_reset(struct lustre_cfg_bufs *bufs, static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, __u32 index) { __u32 i; - size_t offset; + __kernel_size_t offset; __u32 bufcount; if (!lcfg) @@ -324,7 +310,7 @@ static inline void lustre_cfg_init(struct lustre_cfg *lcfg, int cmd, } } -static inline int lustre_cfg_sanity_check(void *buf, size_t len) +static inline int lustre_cfg_sanity_check(void *buf, __kernel_size_t len) { struct lustre_cfg *lcfg = (struct lustre_cfg *)buf; diff --git a/lustre/include/uapi/linux/lustre/lustre_fid.h b/lustre/include/uapi/linux/lustre/lustre_fid.h index 0cf7c17..f11ad3b 100644 --- a/lustre/include/uapi/linux/lustre/lustre_fid.h +++ b/lustre/include/uapi/linux/lustre/lustre_fid.h @@ -38,15 +38,7 @@ #define _UAPI_LUSTRE_FID_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 /** returns fid object sequence */ static inline __u64 fid_seq(const struct lu_fid *fid) @@ -286,7 +278,7 @@ static inline bool fid_is_last_id(const struct lu_fid *fid) * \param fid an igif to get inode number from. * \return inode number for the igif. */ -static inline ino_t lu_igif_ino(const struct lu_fid *fid) +static inline __kernel_ino_t lu_igif_ino(const struct lu_fid *fid) { return fid_seq(fid); } diff --git a/lustre/include/uapi/linux/lustre/lustre_fiemap.h b/lustre/include/uapi/linux/lustre/lustre_fiemap.h index 68562cd..beea76d 100644 --- a/lustre/include/uapi/linux/lustre/lustre_fiemap.h +++ b/lustre/include/uapi/linux/lustre/lustre_fiemap.h @@ -50,7 +50,7 @@ /* XXX: We use fiemap_extent::fe_reserved[0] */ #define fe_device fe_reserved[0] -static inline size_t fiemap_count_to_size(size_t extent_count) +static inline __kernel_size_t fiemap_count_to_size(size_t extent_count) { return sizeof(struct fiemap) + extent_count * sizeof(struct fiemap_extent); diff --git a/lustre/include/uapi/linux/lustre/lustre_idl.h b/lustre/include/uapi/linux/lustre/lustre_idl.h index 2843da8..c80435c 100644 --- a/lustre/include/uapi/linux/lustre/lustre_idl.h +++ b/lustre/include/uapi/linux/lustre/lustre_idl.h @@ -71,21 +71,19 @@ #include #include +#include #include - /* * This is due to us being out of kernel and the way the OpenSFS branch * handles CFLAGS. */ #ifdef __KERNEL__ # include -# include /* Defn's shared with user-space. */ -# include #else # include -# include -# include #endif +#include +#include #if defined(__cplusplus) extern "C" { @@ -528,12 +526,12 @@ static inline struct lu_dirent *lu_dirent_next(struct lu_dirent *ent) return next; } -static inline size_t lu_dirent_calc_size(size_t namelen, __u16 attr) +static inline __kernel_size_t lu_dirent_calc_size(size_t namelen, __u16 attr) { - size_t size; + __kernel_size_t size; if (attr & LUDA_TYPE) { - const size_t align = sizeof(struct luda_type) - 1; + const __kernel_size_t align = sizeof(struct luda_type) - 1; size = (sizeof(struct lu_dirent) + namelen + 1 + align) & ~align; @@ -1226,7 +1224,7 @@ static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic) } static inline __u32 -lov_mds_md_max_stripe_count(size_t buf_size, __u32 lmm_magic) +lov_mds_md_max_stripe_count(__kernel_size_t buf_size, __u32 lmm_magic) { switch (lmm_magic) { case LOV_MAGIC_V1: { @@ -2255,11 +2253,11 @@ struct lmv_foreign_md { **/ #define LUSTRE_FNV_1A_64_PRIME 0x100000001b3ULL #define LUSTRE_FNV_1A_64_OFFSET_BIAS 0xcbf29ce484222325ULL -static inline __u64 lustre_hash_fnv_1a_64(const void *buf, size_t size) +static inline __u64 lustre_hash_fnv_1a_64(const void *buf, __kernel_size_t size) { __u64 hash = LUSTRE_FNV_1A_64_OFFSET_BIAS; const unsigned char *p = buf; - size_t i; + __kernel_size_t i; for (i = 0; i < size; i++) { hash ^= p[i]; diff --git a/lustre/include/uapi/linux/lustre/lustre_ioctl.h b/lustre/include/uapi/linux/lustre/lustre_ioctl.h index 5a68cfb..424aebf 100644 --- a/lustre/include/uapi/linux/lustre/lustre_ioctl.h +++ b/lustre/include/uapi/linux/lustre/lustre_ioctl.h @@ -31,25 +31,17 @@ #include #include #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -# include -#else -# include -# define __user -#endif +#include #if !defined(__KERNEL__) && !defined(LUSTRE_UTILS) # error This file is for Lustre internal use only. #endif -/* Handle older distros */ -#ifndef __ALIGN_KERNEL -# define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) -# define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) +/* + * sparse kernel source annotations + */ +#ifndef __user +#define __user #endif enum md_echo_cmd { diff --git a/lustre/include/uapi/linux/lustre/lustre_lfsck_user.h b/lustre/include/uapi/linux/lustre/lustre_lfsck_user.h index 79fae23..68c8d3a 100644 --- a/lustre/include/uapi/linux/lustre/lustre_lfsck_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_lfsck_user.h @@ -34,15 +34,7 @@ # define _LUSTRE_LFSCK_USER_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 /** * state machine: diff --git a/lustre/include/uapi/linux/lustre/lustre_log_user.h b/lustre/include/uapi/linux/lustre/lustre_log_user.h index d9fe861..bcf46eb 100644 --- a/lustre/include/uapi/linux/lustre/lustre_log_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_log_user.h @@ -39,15 +39,7 @@ #define _LUSTRE_LOG_USER_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 /* Lustre logs use FIDs constructed from oi_id and oi_seq directly, * without attempting to use the IGIF and IDIF ranges as is done diff --git a/lustre/include/uapi/linux/lustre/lustre_ostid.h b/lustre/include/uapi/linux/lustre/lustre_ostid.h index 4a96640..90fa213 100644 --- a/lustre/include/uapi/linux/lustre/lustre_ostid.h +++ b/lustre/include/uapi/linux/lustre/lustre_ostid.h @@ -36,15 +36,7 @@ #include #include -/* - * This is due to us being out of kernel and the way the OpenSFS branch - * handles CFLAGS. - */ -#ifdef __KERNEL__ -#include -#else #include -#endif static inline __u64 lmm_oi_id(const struct ost_id *oi) { diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index a1ec1b2..3a8ce82 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -42,38 +42,30 @@ * @{ */ +#include +#include #include +#include +#include #include +#include +#include -#ifdef __KERNEL__ -# include -# include -# include /* snprintf() */ -# include -# include -#else /* !__KERNEL__ */ -# include +#ifndef __KERNEL__ # include # include /* snprintf() */ -# include -# include -# define NEED_QUOTA_DEFS -/* # include - this causes complaints about caddr_t */ # include -# include # define FILEID_LUSTRE 0x97 /* for name_to_handle_at() (and llapi_fd2fid()) */ -#endif /* __KERNEL__ */ - -/* Handle older distros */ -#ifndef __ALIGN_KERNEL -# define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) -# define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) -#endif +#endif /* !__KERNEL__ */ #if defined(__cplusplus) extern "C" { #endif +#ifdef __STRICT_ANSI__ +#define typeof __typeof__ +#endif + /* * This is a temporary solution of adding quota type. * Should be removed as soon as system header is updated. @@ -1032,8 +1024,8 @@ static inline bool lmv_is_known_hash_type(__u32 type) extern char *mdt_hash_name[LMV_HASH_TYPE_MAX]; struct lustre_foreign_type { - uint32_t lft_type; - const char *lft_name; + __u32 lft_type; + const char *lft_name; }; /** @@ -1181,7 +1173,7 @@ static inline void obd_uuid2fsname(char *buf, char *uuid, int buflen) #define LUSTRE_QUOTABLOCK_BITS 10 #define LUSTRE_QUOTABLOCK_SIZE (1 << LUSTRE_QUOTABLOCK_BITS) -static inline __u64 lustre_stoqb(size_t space) +static inline __u64 lustre_stoqb(__kernel_size_t space) { return (space + LUSTRE_QUOTABLOCK_SIZE - 1) >> LUSTRE_QUOTABLOCK_BITS; } @@ -1268,10 +1260,10 @@ struct identity_downcall_data { }; struct sepol_downcall_data { - __u32 sdd_magic; - time_t sdd_sepol_mtime; - __u16 sdd_sepol_len; - char sdd_sepol[0]; + __u32 sdd_magic; + __kernel_time_t sdd_sepol_mtime; + __u16 sdd_sepol_len; + char sdd_sepol[0]; }; #ifdef NEED_QUOTA_DEFS @@ -1696,10 +1688,10 @@ struct changelog_ext_xattr { static inline struct changelog_ext_extra_flags *changelog_rec_extra_flags( const struct changelog_rec *rec); -static inline size_t changelog_rec_offset(enum changelog_rec_flags crf, +static inline __kernel_size_t changelog_rec_offset(enum changelog_rec_flags crf, enum changelog_rec_extra_flags cref) { - size_t size = sizeof(struct changelog_rec); + __kernel_size_t size = sizeof(struct changelog_rec); if (crf & CLF_RENAME) size += sizeof(struct changelog_ext_rename); @@ -1722,7 +1714,7 @@ static inline size_t changelog_rec_offset(enum changelog_rec_flags crf, return size; } -static inline size_t changelog_rec_size(const struct changelog_rec *rec) +static inline __kernel_size_t changelog_rec_size(const struct changelog_rec *rec) { enum changelog_rec_extra_flags cref = CLFE_INVALID; @@ -1734,7 +1726,7 @@ static inline size_t changelog_rec_size(const struct changelog_rec *rec) (enum changelog_rec_flags)rec->cr_flags, cref); } -static inline size_t changelog_rec_varsize(const struct changelog_rec *rec) +static inline __kernel_size_t changelog_rec_varsize(const struct changelog_rec *rec) { return changelog_rec_size(rec) - sizeof(*rec) + rec->cr_namelen; } @@ -1860,7 +1852,7 @@ static inline char *changelog_rec_name(const struct changelog_rec *rec) (enum changelog_rec_extra_flags)(cref & CLFE_SUPPORTED)); } -static inline size_t changelog_rec_snamelen(const struct changelog_rec *rec) +static inline __kernel_size_t changelog_rec_snamelen(const struct changelog_rec *rec) { return rec->cr_namelen - strlen(changelog_rec_name(rec)) - 1; } @@ -2217,11 +2209,12 @@ static inline void *hur_data(struct hsm_user_request *hur) /** * Compute the current length of the provided hsm_user_request. This returns -1 - * instead of an errno because ssize_t is defined to be only [ -1, SSIZE_MAX ] + * instead of an errno because __kernel_ssize_t is defined to be only + * [ -1, SSIZE_MAX ] * * return -1 on bounds check error. */ -static inline ssize_t hur_len(struct hsm_user_request *hur) +static inline __kernel_size_t hur_len(struct hsm_user_request *hur) { __u64 size; @@ -2230,7 +2223,7 @@ static inline ssize_t hur_len(struct hsm_user_request *hur) (__u64)hur->hur_request.hr_itemcount * sizeof(hur->hur_user_item[0]) + hur->hur_request.hr_data_len; - if ((ssize_t)size < 0) + if ((__kernel_ssize_t)size < 0) return -1; return size; @@ -2286,7 +2279,7 @@ struct hsm_action_item { * \retval buffer */ static inline char *hai_dump_data_field(const struct hsm_action_item *hai, - char *buffer, size_t len) + char *buffer, __kernel_size_t len) { int i; int data_len; @@ -2323,7 +2316,7 @@ struct hsm_action_list { /* Return pointer to first hai in action list */ static inline struct hsm_action_item *hai_first(struct hsm_action_list *hal) { - size_t offset = __ALIGN_KERNEL(strlen(hal->hal_fsname) + 1, 8); + __kernel_size_t offset = __ALIGN_KERNEL(strlen(hal->hal_fsname) + 1, 8); return (struct hsm_action_item *)(hal->hal_fsname + offset); } @@ -2331,16 +2324,16 @@ static inline struct hsm_action_item *hai_first(struct hsm_action_list *hal) /* Return pointer to next hai */ static inline struct hsm_action_item * hai_next(struct hsm_action_item *hai) { - size_t offset = __ALIGN_KERNEL(hai->hai_len, 8); + __kernel_size_t offset = __ALIGN_KERNEL(hai->hai_len, 8); return (struct hsm_action_item *)((char *)hai + offset); } /* Return size of an hsm_action_list */ -static inline size_t hal_size(struct hsm_action_list *hal) +static inline __kernel_size_t hal_size(struct hsm_action_list *hal) { __u32 i; - size_t sz; + __kernel_size_t sz; struct hsm_action_item *hai; sz = sizeof(*hal) + __ALIGN_KERNEL(strlen(hal->hal_fsname) + 1, 8); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index a2dfedd..3f5767f 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -31,8 +31,8 @@ GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""} export PARALLEL=${PARALLEL:-"no"} TRACE=${TRACE:-""} -LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi} LUSTRE=${LUSTRE:-$(dirname $0)/..} +LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi} . $LUSTRE/tests/test-framework.sh init_test_env $@ @@ -20800,6 +20800,10 @@ test_400a() { # LU-1606, was conf-sanity test_74 local prefix=/usr/include/lustre local prog + # Oleg removes c files in his test rig so test if any c files exist + [ -z "$(ls -A $LUSTRE_TESTS_API_DIR)" ] && \ + skip_env "Needed c test files are missing" + if ! [[ -d $prefix ]]; then # Assume we're running in tree and fixup the include path. extra_flags+=" -I$LUSTRE/../lnet/include/uapi -I$LUSTRE/include/uapi -I$LUSTRE/include" @@ -20807,7 +20811,7 @@ test_400a() { # LU-1606, was conf-sanity test_74 fi for prog in $LUSTRE_TESTS_API_DIR/*.c; do - $CC -Wall -Werror $extra_flags -o $out $prog -llustreapi || + $CC -Wall -Werror -std=c99 $extra_flags -o $out $prog -llustreapi || error "client api broken" done rm -f $out @@ -20839,7 +20843,7 @@ test_400b() { # LU-1606, LU-5011 continue # lustre_ioctl.h is internal header fi - $CC -Wall -Werror -include $header -c -x c /dev/null -o $out || + $CC -Wall -Werror -std=c99 -include $header -c -x c /dev/null -o $out || error "cannot compile '$header'" done rm -f $out -- 1.8.3.1