From: John L. Hammond Date: Fri, 11 Jul 2014 19:31:26 +0000 (-0500) Subject: LU-5327 libcfs: add libcfs/types.h X-Git-Tag: 2.6.51~41 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=d3e3c5777dd6929d43c2c9028aab1079d8b2406c LU-5327 libcfs: add libcfs/types.h 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 Change-Id: Iaab8e552d2d8a1c87ca2675f5068bc2943d8ce18 Reviewed-on: http://review.whamcloud.com/11070 Tested-by: Jenkins Reviewed-by: Robert Read Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 81d3552..1889814 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -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 - #include -],[ - 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 diff --git a/libcfs/include/libcfs/Makefile.am b/libcfs/include/libcfs/Makefile.am index cb5ccb2..407efe1 100644 --- a/libcfs/include/libcfs/Makefile.am +++ b/libcfs/include/libcfs/Makefile.am @@ -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 \ diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 98682d8..450d597 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -41,6 +41,8 @@ #define __attribute__(x) #endif +#include + #if !defined(__WINNT__) && !defined(__KERNEL__) #include #elif defined(__linux__) diff --git a/libcfs/include/libcfs/libcfs_ioctl.h b/libcfs/include/libcfs/libcfs_ioctl.h index ba4350b..ceb948e 100644 --- a/libcfs/include/libcfs/libcfs_ioctl.h +++ b/libcfs/include/libcfs/libcfs_ioctl.h @@ -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' diff --git a/libcfs/include/libcfs/linux/kp30.h b/libcfs/include/libcfs/linux/kp30.h index e100620..8204dba 100644 --- a/libcfs/include/libcfs/linux/kp30.h +++ b/libcfs/include/libcfs/linux/kp30.h @@ -99,66 +99,6 @@ # 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, diff --git a/libcfs/include/libcfs/linux/libcfs.h b/libcfs/include/libcfs/linux/libcfs.h index 8c1d920..f96a780 100644 --- a/libcfs/include/libcfs/linux/libcfs.h +++ b/libcfs/include/libcfs/linux/libcfs.h @@ -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 diff --git a/libcfs/include/libcfs/posix/Makefile.am b/libcfs/include/libcfs/posix/Makefile.am index def79ff..1a5753c 100644 --- a/libcfs/include/libcfs/posix/Makefile.am +++ b/libcfs/include/libcfs/posix/Makefile.am @@ -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 diff --git a/libcfs/include/libcfs/posix/libcfs.h b/libcfs/include/libcfs/posix/libcfs.h index c839486..da04cfd 100644 --- a/libcfs/include/libcfs/posix/libcfs.h +++ b/libcfs/include/libcfs/posix/libcfs.h @@ -98,13 +98,11 @@ #endif #include -#include #include #include #include #include #include -#include #include # 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 index 77a589b..0000000 --- a/libcfs/include/libcfs/posix/posix-types.h +++ /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 - */ -#ifndef _LUSTRE_POSIX_TYPES_H -#define _LUSTRE_POSIX_TYPES_H - -#ifdef __linux__ -# include -#endif -#include /* 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 index b7ef6e2..0000000 --- a/libcfs/include/libcfs/posix/posix-wordsize.h +++ /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 - */ - -#ifndef __LIBCFS_LINUX_KP30_H__ -#define __LIBCFS_LINUX_KP30_H__ - -#if defined(__CYGWIN__) -# include -#endif -#ifdef HAVE_SYS_IOCTL_H -# include -#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 index 0000000..059caca --- /dev/null +++ b/libcfs/include/libcfs/types.h @@ -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 + +#ifndef __KERNEL__ +# include /* LONG_MAX */ +# include /* 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 */ diff --git a/lustre/include/lustre/ll_fiemap.h b/lustre/include/lustre/ll_fiemap.h index 1753f14..ff989a1 100644 --- a/lustre/include/lustre/ll_fiemap.h +++ b/lustre/include/lustre/ll_fiemap.h @@ -46,7 +46,7 @@ #if !defined(__KERNEL__) #include -#include +#include struct ll_fiemap_extent { __u64 fe_logical; /* logical offset in bytes for the start of diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 6625a83..5a0fb59 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -46,9 +46,12 @@ * @{ */ -#ifndef __KERNEL__ -#include -#include +#include + +#ifdef __KERNEL__ +# include /* snprintf() */ +#else +# include /* snprintf() */ #endif #include #if defined(__linux__)