Whamcloud - gitweb
LU-5327 libcfs: add libcfs/types.h 70/11070/3
authorJohn L. Hammond <john.hammond@intel.com>
Fri, 11 Jul 2014 19:31:26 +0000 (14:31 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 1 Aug 2014 06:46:57 +0000 (06:46 +0000)
Add libcfs/include/libcfs/types.h which unconditionally includes
linux/types.h and defines the LP*64 macros by testing for
_ASM_GENERIC_INT_L64_H or _ASM_GENERIC_INT_LL64_H. Remove autoconf
tests to determine in __u64 is unsigned long or unsigned long
long. Remove the headers posix-types.h and posix-wordsize.h. This
fixes two problems:

  1) Use of the LP*64 macros may make lustre headers unusable when
     config.h is not included (like when the headers are used out of
     tree).

  2) Some platforms (like powerpc64) define __u64 to be unsigned long
     in the kernel and unsigned long long in userspace. This means
     that a single autoconf test cannot be used to determine how to
     define the terrible LP*64 macros.

Imaginary ports of Lustre to non-Linux platforms may handle this
change by adding linux/types.h somewhere in their include path and
putting the right typedefs and defines therein.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: Iaab8e552d2d8a1c87ca2675f5068bc2943d8ce18
Reviewed-on: http://review.whamcloud.com/11070
Tested-by: Jenkins
Reviewed-by: Robert Read <robert.read@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
13 files changed:
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/libcfs_ioctl.h
libcfs/include/libcfs/linux/kp30.h
libcfs/include/libcfs/linux/libcfs.h
libcfs/include/libcfs/posix/Makefile.am
libcfs/include/libcfs/posix/libcfs.h
libcfs/include/libcfs/posix/posix-types.h [deleted file]
libcfs/include/libcfs/posix/posix-wordsize.h [deleted file]
libcfs/include/libcfs/types.h [new file with mode: 0644]
lustre/include/lustre/ll_fiemap.h
lustre/include/lustre/lustre_user.h

index 81d3552..1889814 100644 (file)
@@ -49,28 +49,6 @@ AS_IF([test "x$enable_panic_dumplog" = xyes],
 ]) # LIBCFS_CONFIG_PANIC_DUMPLOG
 
 #
-# LIBCFS_U64_LONG_LONG_LINUX
-#
-# check kernel __u64 type
-#
-AC_DEFUN([LIBCFS_U64_LONG_LONG_LINUX], [
-tmp_flags="$EXTRA_KCFLAGS"
-EXTRA_KCFLAGS="$EXTRA_KCFLAGS -Werror"
-LB_CHECK_COMPILE([if Linux kernel '__u64' is 'long long' type],
-kernel_u64_long_long, [
-       #include <linux/types.h>
-       #include <linux/stddef.h>
-],[
-       unsigned long long *data;
-       data = (__u64*)sizeof(data);
-],[
-       AC_DEFINE(HAVE_KERN__U64_LONG_LONG, 1,
-               [Linux kernel __u64 is long long type])
-])
-EXTRA_KCFLAGS="$tmp_flags"
-]) # LIBCFS_U64_LONG_LONG_LINUX
-
-#
 # LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
 #
 # 2.6.32-30.el6 adds a new 'walk_stack' field in 'struct stacktrace_ops'
@@ -332,7 +310,6 @@ AC_MSG_NOTICE([LibCFS kernel checks
 ==============================================================================])
 LIBCFS_CONFIG_PANIC_DUMPLOG
 
-LIBCFS_U64_LONG_LONG_LINUX
 # 2.6.32
 LIBCFS_STACKTRACE_OPS_HAVE_WALK_STACK
 LC_SHRINKER_WANT_SHRINK_PTR
index cb5ccb2..407efe1 100644 (file)
@@ -4,6 +4,12 @@ SUBDIRS += darwin
 endif
 DIST_SUBDIRS = linux posix util darwin
 
+libcfsdir = $(includedir)/libcfs
+
+if UTILS
+libcfs_HEADERS = types.h
+endif
+
 EXTRA_DIST = \
        bitmap.h \
        curproc.h \
@@ -28,6 +34,7 @@ EXTRA_DIST = \
        list.h \
        lucache.h \
        params_tree.h \
+       types.h \
        user-bitops.h \
        user-crypto.h \
        user-lock.h \
index 98682d8..450d597 100644 (file)
@@ -41,6 +41,8 @@
 #define __attribute__(x)
 #endif
 
+#include <libcfs/types.h>
+
 #if !defined(__WINNT__) && !defined(__KERNEL__)
 #include <libcfs/posix/libcfs.h>
 #elif defined(__linux__)
index ba4350b..ceb948e 100644 (file)
@@ -108,6 +108,7 @@ struct libcfs_ioctl_handler {
 
 /* 'f' ioctls are defined in lustre_ioctl.h and lustre_user.h except for: */
 #define LIBCFS_IOC_DEBUG_MASK             _IOWR('f', 250, long)
+#define IOCTL_LIBCFS_TYPE                long
 
 /* ioctls for manipulating snapshots 30- */
 #define IOC_LIBCFS_TYPE                   'e'
index e100620..8204dba 100644 (file)
 # define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
 # define time(a) CURRENT_TIME
 
-#define IOCTL_LIBCFS_TYPE long
-
-#ifdef __CYGWIN__
-# ifndef BITS_PER_LONG
-#  if (~0UL) == 0xffffffffUL
-#   define BITS_PER_LONG 32
-#  else
-#   define BITS_PER_LONG 64
-#  endif
-# endif
-#endif
-
-#if BITS_PER_LONG > 32
-# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
-#else
-# define LI_POISON ((int)0x5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a)
-#endif
-
-/* this is a bit chunky */
-
-#define _LWORDSIZE BITS_PER_LONG
-
-#if defined(HAVE_KERN__U64_LONG_LONG)
-# define LPU64 "%llu"
-# define LPD64 "%lld"
-# define LPX64 "%#llx"
-# define LPX64i "%llx"
-# define LPO64 "%#llo"
-# define LPF64 "L"
-#else
-# define LPU64 "%lu"
-# define LPD64 "%ld"
-# define LPX64 "%#lx"
-# define LPX64i "%lx"
-# define LPO64 "%#lo"
-# define LPF64 "l"
-#endif
-
-/*
- * long_ptr_t & ulong_ptr_t, same to "long" for gcc
- */
-# define LPLU "%lu"
-# define LPLD "%ld"
-# define LPLX "%#lx"
-
-/*
- * pid_t
- */
-# define LPPID "%d"
-
-#ifndef LPU64
-# error "No word size defined"
-#endif
-
-#undef _LWORDSIZE
-
 #ifdef HAVE_SYSCTL_CTLNAME
 #define INIT_CTL_NAME  .ctl_name = CTL_UNNUMBERED,
 #define INIT_STRATEGY  .strategy = &sysctl_intvec,
index 8c1d920..f96a780 100644 (file)
@@ -119,10 +119,6 @@ do {                                                                    \
 struct cfs_stack_trace {
 };
 
-/* long integer with size equal to pointer */
-typedef unsigned long ulong_ptr_t;
-typedef long long_ptr_t;
-
 #ifndef WITH_WATCHDOG
 #define WITH_WATCHDOG
 #endif
index def79ff..1a5753c 100644 (file)
@@ -1,7 +1 @@
-libcfsposixdir = $(includedir)/libcfs/posix
-
-if UTILS
-libcfsposix_HEADERS = posix-types.h
-endif
-
-EXTRA_DIST = libcfs.h posix-wordsize.h posix-types.h posix-crypto.h
\ No newline at end of file
+EXTRA_DIST = libcfs.h posix-crypto.h
index c839486..da04cfd 100644 (file)
 #endif
 
 #include <libcfs/list.h>
-#include <libcfs/posix/posix-types.h>
 #include <libcfs/user-time.h>
 #include <libcfs/user-prim.h>
 #include <libcfs/user-mem.h>
 #include <libcfs/user-lock.h>
 #include <libcfs/user-tcpip.h>
-#include <libcfs/posix/posix-wordsize.h>
 #include <libcfs/user-bitops.h>
 
 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
diff --git a/libcfs/include/libcfs/posix/posix-types.h b/libcfs/include/libcfs/posix/posix-types.h
deleted file mode 100644 (file)
index 77a589b..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * libcfs/include/libcfs/posix/posix-types.h
- *
- * Define the linux types we use for posix userspace.
- *
- * Author: Robert Read <rread@sun.com>
- */
-#ifndef _LUSTRE_POSIX_TYPES_H
-#define _LUSTRE_POSIX_TYPES_H
-
-#ifdef __linux__
-# include <linux/types.h>
-#endif
-#include <stdbool.h> /* for bool */
-
-#ifndef _LINUX_TYPES_H
-/*
- * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
- * header files exported to user space
- */
-
-#ifndef HAVE___S8
-#define HAVE___S8
-typedef __signed__ char __s8;
-#endif
-#ifndef HAVE___U8
-#define HAVE___U8
-typedef unsigned char __u8;
-#endif
-
-#ifndef HAVE___S16
-#define HAVE___S16
-typedef __signed__ short __s16;
-#endif
-#ifndef HAVE___U16
-#define HAVE___U16
-typedef unsigned short __u16;
-#endif
-
-#ifndef HAVE___S32
-#define HAVE___S32
-typedef __signed__ int __s32;
-#endif
-#ifndef HAVE___U32
-#define HAVE___U32
-typedef unsigned int __u32;
-#endif
-
-/*
- * The kernel defines user space 64bit values as l64 on powerpc. We must
- * match that definition to avoid conflicting definition compile errors.
- */
-#if defined(__powerpc64__) && !defined(__KERNEL__)
-# ifndef HAVE___S64
-# define HAVE___S64
-typedef __signed__ long __s64;
-# endif
-# ifndef HAVE___U64
-# define HAVE___U64
-typedef unsigned long __u64;
-# endif
-#else /* !defined(__powerpc64__) || defined(__KERNEL__) */
-# ifndef HAVE___S64
-# define HAVE___S64
-typedef __signed__ long long __s64;
-# endif
-# ifndef HAVE___U64
-# define HAVE___U64
-typedef unsigned long long __u64;
-# endif
-#endif /* defined(__powerpc64__) && !defined(__KERNEL__) */
-#endif /* _LINUX_TYPES_H */
-
-/* long integer with size equal to pointer */
-typedef unsigned long ulong_ptr_t;
-typedef long long_ptr_t;
-
-/* Sparse annotations, copied from linux/compiler.h. */
-#define __user
-#define __kernel
-#define __safe
-#define __force
-#define __nocast
-#define __iomem
-#define __chk_user_ptr(x) ((void)0)
-#define __chk_io_ptr(x) ((void)0)
-#define __builtin_warning(x, y...) (1)
-#define __acquires(x)
-#define __releases(x)
-#define __acquire(x) ((void)0)
-#define __release(x) ((void)0)
-#define __cond_lock(x, c) (c)
-
-typedef unsigned long pgoff_t;
-
-#endif
diff --git a/libcfs/include/libcfs/posix/posix-wordsize.h b/libcfs/include/libcfs/posix/posix-wordsize.h
deleted file mode 100644 (file)
index b7ef6e2..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * libcfs/include/libcfs/posix/posix-wordsize.h
- *
- * Wordsize related  defines for posix userspace.
- *
- * Author: Robert Read <rread@sun.com>
- */
-
-#ifndef __LIBCFS_LINUX_KP30_H__
-#define __LIBCFS_LINUX_KP30_H__
-
-#if defined(__CYGWIN__)
-# include <cygwin-ioctl.h>
-#endif
-#ifdef HAVE_SYS_IOCTL_H
-# include <sys/ioctl.h>
-#endif
-#ifndef _IOWR
-# include "ioctl.h"
-#endif
-
-# define CFS_MODULE_PARM(name, t, type, perm, desc)
-#define symbol_get(x) inter_module_get(#x)
-#define symbol_put(x) inter_module_put(#x)
-
-#ifdef __CYGWIN__
-# ifndef BITS_PER_LONG
-#  if (~0UL) == 0xffffffffUL
-#   define BITS_PER_LONG 32
-#  else
-#   define BITS_PER_LONG 64
-#  endif
-# endif
-#else 
-#  define BITS_PER_LONG __WORDSIZE
-#endif
-
-#define IOCTL_LIBCFS_TYPE long
-
-#if BITS_PER_LONG > 32
-# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
-#else
-# define LI_POISON ((int)0x5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a)
-#endif
-
-# define LPU64 "%llu"
-# define LPD64 "%lld"
-# define LPX64 "%#llx"
-# define LPX64i "%llx"
-# define LPO64 "%#llo"
-# define LPF64 "ll"
-
-/*
- * long_ptr_t & ulong_ptr_t, same to "long" for gcc
- */
-# define LPLU "%lu"
-# define LPLD "%ld"
-# define LPLX "%#lx"
-
-/*
- * pid_t
- */
-# define LPPID "%d"
-
-#endif
diff --git a/libcfs/include/libcfs/types.h b/libcfs/include/libcfs/types.h
new file mode 100644 (file)
index 0000000..059caca
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
+ */
+#ifndef _LIBCFS_TYPES_H
+#define _LIBCFS_TYPES_H
+
+#include <linux/types.h>
+
+#ifndef __KERNEL__
+# include <limits.h> /* LONG_MAX */
+# include <stdbool.h> /* bool */
+#endif /* !__KERNEL__ */
+
+#if defined(_ASM_GENERIC_INT_L64_H)
+# define LPF64 "l"
+#elif defined(_ASM_GENERIC_INT_LL64_H)
+# define LPF64 "ll"
+#elif !defined(LPF64)
+# error "cannot define LPF64"
+#endif /* !LPF64 */
+
+#define LPU64 "%"LPF64"u"
+#define LPD64 "%"LPF64"d"
+#define LPX64 "%#"LPF64"x"
+#define LPX64i "%"LPF64"x"
+#define LPO64 "%#"LPF64"o"
+
+#define LPLU "%lu"
+#define LPLD "%ld"
+#define LPLX "%#lx"
+#define LPPID "%d"
+
+#ifndef BITS_PER_LONG
+# if LONG_MAX == 9223372036854775807
+#  define BITS_PER_LONG 64
+# elif LONG_MAX == 2147483647
+#  define BITS_PER_LONG 32
+# else /* LONG_MAX == 2147483647 */
+#  error "cannot define BITS_PER_LONG"
+# endif /* LONG_MAX != 2147483647 */
+#endif /* !BITS_PER_LONG */
+
+#if BITS_PER_LONG == 64
+# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
+# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
+# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
+#elif BITS_PER_LONG == 32
+# define LI_POISON ((int)0x5a5a5a5a)
+# define LL_POISON ((long)0x5a5a5a5a)
+# define LP_POISON ((void *)(long)0x5a5a5a5a)
+#else /* BITS_PER_LONG == 32 */
+# error "cannot define L{I,L,P}_POISON"
+#endif /* BITS_PER_LONG != 32 */
+
+typedef unsigned long ulong_ptr_t;
+typedef long long_ptr_t;
+
+#endif /* _LIBCFS_TYPES_H */
index 1753f14..ff989a1 100644 (file)
@@ -46,7 +46,7 @@
 #if !defined(__KERNEL__)
 
 #include <stddef.h>
-#include <libcfs/posix/posix-types.h>
+#include <libcfs/types.h>
 
 struct ll_fiemap_extent {
         __u64 fe_logical;  /* logical offset in bytes for the start of
index 6625a83..5a0fb59 100644 (file)
  * @{
  */
 
-#ifndef __KERNEL__
-#include <stdio.h>
-#include <libcfs/posix/posix-types.h>
+#include <libcfs/types.h>
+
+#ifdef __KERNEL__
+# include <linux/string.h> /* snprintf() */
+#else
+# include <stdio.h> /* snprintf() */
 #endif
 #include <lustre/ll_fiemap.h>
 #if defined(__linux__)