Whamcloud - gitweb
LU-13274 uapi: make lustre UAPI headers C99 compliant 78/37678/6
authorJames Simmons <jsimmons@infradead.org>
Sat, 29 Feb 2020 01:49:42 +0000 (20:49 -0500)
committerOleg Drokin <green@whamcloud.com>
Wed, 11 Mar 2020 02:19:24 +0000 (02:19 +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 Lustre UAPI headers to be compilable with -std=c99.
Enhance our current test covering UAPI header handling.

For OpenSFS branch we can't include <linux/stat.h> 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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/37678
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Gian-Carlo DeFazio <defazio1@llnl.gov>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
13 files changed:
config/lustre-build.m4
lustre/include/lustre/lustreapi.h
lustre/include/uapi/linux/lustre/lustre_barrier_user.h
lustre/include/uapi/linux/lustre/lustre_cfg.h
lustre/include/uapi/linux/lustre/lustre_fid.h
lustre/include/uapi/linux/lustre/lustre_fiemap.h
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/include/uapi/linux/lustre/lustre_ioctl.h
lustre/include/uapi/linux/lustre/lustre_lfsck_user.h
lustre/include/uapi/linux/lustre/lustre_log_user.h
lustre/include/uapi/linux/lustre/lustre_ostid.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/tests/sanity.sh

index f196ef0..7d9ab58 100644 (file)
@@ -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
 
index 8db1450..39a8090 100644 (file)
@@ -40,6 +40,9 @@
 
 #include <stdarg.h>
 #include <stdint.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/types.h>
 #include <linux/lustre/lustre_user.h>
 
 #if defined(__cplusplus)
index e86b262..3808424 100644 (file)
 # define _LUSTRE_BARRIER_USER_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/lustre/lustre_user.h>
-#else
-# include <linux/lustre/lustre_user.h>
-#endif
+#include <linux/lustre/lustre_user.h>
 
 #define BARRIER_VERSION_V1     1
 #define BARRIER_TIMEOUT_DEFAULT        30
index 93884d7..30d5c7d 100644 (file)
 #include <linux/errno.h>
 #include <linux/kernel.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/lustre/lustre_user.h>
-#else
-# include <linux/lustre/lustre_user.h>
-#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 <linux/lustre/lustre_user.h>
 
 /** \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;
 
index 0cf7c17..f11ad3b 100644 (file)
 #define _UAPI_LUSTRE_FID_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/lustre/lustre_idl.h>
-#else
-# include <linux/lustre/lustre_idl.h>
-#endif
+#include <linux/lustre/lustre_idl.h>
 
 /** 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);
 }
index 68562cd..beea76d 100644 (file)
@@ -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);
index 2843da8..c80435c 100644 (file)
 
 #include <asm/byteorder.h>
 #include <linux/errno.h>
+#include <linux/fiemap.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>
-# include <uapi/linux/lustre/lustre_user.h> /* Defn's shared with user-space. */
-# include <uapi/linux/lustre/lustre_ver.h>
 #else
 # include <linux/lnet/lnet-types.h>
-# include <linux/lustre/lustre_user.h>
-# include <linux/lustre/lustre_ver.h>
 #endif
+#include <linux/lustre/lustre_user.h>
+#include <linux/lustre/lustre_ver.h>
 
 #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];
index 5a68cfb..424aebf 100644 (file)
 #include <linux/ioctl.h>
 #include <linux/kernel.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/lustre/lustre_idl.h>
-#else
-# include <linux/lustre/lustre_idl.h>
-# define __user
-#endif
+#include <linux/lustre/lustre_idl.h>
 
 #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 {
index 79fae23..68c8d3a 100644 (file)
 # define _LUSTRE_LFSCK_USER_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/lustre/lustre_user.h>
-#else
-# include <linux/lustre/lustre_user.h>
-#endif
+#include <linux/lustre/lustre_user.h>
 
 /**
  * state machine:
index d9fe861..bcf46eb 100644 (file)
 #define _LUSTRE_LOG_USER_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/lustre/lustre_fid.h>
-#else
 #include <linux/lustre/lustre_fid.h>
-#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
index 4a96640..90fa213 100644 (file)
 
 #include <linux/errno.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/lustre/lustre_fid.h>
-#else
 #include <linux/lustre/lustre_fid.h>
-#endif
 
 static inline __u64 lmm_oi_id(const struct ost_id *oi)
 {
index a1ec1b2..3a8ce82 100644 (file)
  * @{
  */
 
+#include <linux/fs.h>
+#include <linux/limits.h>
 #include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/quota.h>
 #include <linux/types.h>
+#include <linux/unistd.h>
+#include <linux/lustre/lustre_fiemap.h>
 
-#ifdef __KERNEL__
-# include <linux/fs.h>
-# include <linux/quota.h>
-# include <linux/string.h> /* snprintf() */
-# include <linux/version.h>
-# include <uapi/linux/lustre/lustre_fiemap.h>
-#else /* !__KERNEL__ */
-# include <limits.h>
+#ifndef __KERNEL__
 # include <stdbool.h>
 # include <stdio.h> /* snprintf() */
-# include <stdint.h>
-# include <string.h>
-# define NEED_QUOTA_DEFS
-/* # include <sys/quota.h> - this causes complaints about caddr_t */
 # include <sys/stat.h>
-# include <linux/lustre/lustre_fiemap.h>
 # 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);
index a2dfedd..3f5767f 100755 (executable)
@@ -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