From 5bda5cd0bddfb2d264b96c063ea07d6a682614f0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Jan 2008 15:34:36 -0800 Subject: [PATCH] cleaned up int types, page size info, byteorder for userspace --- src/config.cc | 13 ++++++++++ src/crush/crush.h | 4 +++- src/include/buffer.h | 2 +- src/include/byteorder.h | 53 +++++++++++++++++++++++++++++++++++++++++ src/include/ceph_fs.h | 4 +++- src/include/inttypes.h | 15 ++++++++++++ src/include/page.h | 19 +++++++++++++++ src/include/types.h | 3 ++- 8 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/include/byteorder.h create mode 100644 src/include/inttypes.h create mode 100644 src/include/page.h diff --git a/src/config.cc b/src/config.cc index 6ae5554b7a2bb..47a4ff0bc5133 100644 --- a/src/config.cc +++ b/src/config.cc @@ -39,6 +39,19 @@ Mutex _dout_lock; ostream *_dout = &std::cout; ostream *_derr = &std::cerr; +// page size crap, see page.h +int _get_bits_of(int v) { + int n = 0; + while (v) { + n++; + v = v >> 1; + } + return n; +} +unsigned _page_size = sysconf(_SC_PAGESIZE); +unsigned _page_mask = ~(_page_size - 1); +unsigned long _page_shift = _get_bits_of(_page_size); + // file layouts struct ceph_file_layout g_OSD_FileLayout = { fl_stripe_unit: 1<<22, diff --git a/src/crush/crush.h b/src/crush/crush.h index 470dcb8326794..d6743a5d0e49e 100644 --- a/src/crush/crush.h +++ b/src/crush/crush.h @@ -5,11 +5,13 @@ extern "C" { #endif -#include /* just for int types */ #ifndef __KERNEL__ # include # define BUG_ON(x) assert(!(x)) +# include "include/inttypes.h" /* just for int types */ +#else +# include #endif diff --git a/src/include/buffer.h b/src/include/buffer.h index 14a3998cb11a3..18fa3c552e83c 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -26,7 +26,7 @@ # include #endif -#include +#include "page.h" // // these are in config.o diff --git a/src/include/byteorder.h b/src/include/byteorder.h new file mode 100644 index 0000000000000..982536100eef7 --- /dev/null +++ b/src/include/byteorder.h @@ -0,0 +1,53 @@ +/* + * byteorder.h + * + * LGPL 2 + */ + +#ifndef _CEPH_BYTEORDER_H +#define _CEPH_BYTEORDER_H + +typedef __u64 __le64; +typedef __u32 __le32; +typedef __u16 __le16; + +static __inline__ __u16 swab16(__u16 val) +{ + return (val >> 8) | (val << 8); +} +static __inline__ __u32 swab32(__u32 val) +{ + return (( val >> 24) | + ((val >> 8) & 0xff00) | + ((val << 8) & 0xff0000) | + ((val << 24))); +} +static __inline__ __u64 swab64(__u64 val) +{ + return (( val >> 56) | + ((val >> 40) & 0xff00ull) | + ((val >> 24) & 0xff0000ull) | + ((val >> 8) & 0xff000000ull) | + ((val << 8) & 0xff00000000ull) | + ((val << 24) & 0xff0000000000ull) | + ((val << 40) & 0xff000000000000ull) | + ((val << 56))); +} + +#ifdef WORDS_BIGENDIAN +# define cpu_to_le64(x) swab64((x)) +# define le64_to_cpu(x) swab64((x)) +# define cpu_to_le32(x) swab32((x)) +# define le32_to_cpu(x) swab32((x)) +# define cpu_to_le16(x) swab16((x)) +# define le16_to_cpu(x) swab16((x)) +#else +# define cpu_to_le64(x) ((__u64)(x)) +# define le64_to_cpu(x) ((__u64)(x)) +# define cpu_to_le32(x) ((__u32)(x)) +# define le32_to_cpu(x) ((__u32)(x)) +# define cpu_to_le16(x) ((__u16)(x)) +# define le16_to_cpu(x) ((__u16)(x)) +#endif + +#endif diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 7c4c645e61c6d..0b187fee0d8a3 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -8,10 +8,12 @@ #ifdef __KERNEL__ # include +# include #else # include +# include "inttypes.h" +# include "byteorder.h" #endif -#include #define CEPH_MON_PORT 2138 diff --git a/src/include/inttypes.h b/src/include/inttypes.h new file mode 100644 index 0000000000000..c9147102fc488 --- /dev/null +++ b/src/include/inttypes.h @@ -0,0 +1,15 @@ +#ifndef _CEPH_INTTYPES_H +#define _CEPH_INTTYPES_H + +#include + +typedef uint64_t __u64; +typedef int64_t __s64; +typedef uint32_t __u32; +typedef int32_t __s32; +typedef uint16_t __u16; +typedef int16_t __s16; +typedef uint8_t __u8; +typedef int8_t __s8; + +#endif diff --git a/src/include/page.h b/src/include/page.h new file mode 100644 index 0000000000000..baadcf16cc932 --- /dev/null +++ b/src/include/page.h @@ -0,0 +1,19 @@ +#ifndef __CEPH_PAGE_H +#define __CEPH_PAGE_H + +// these are in config.cc +extern unsigned _page_size; +extern unsigned long _page_mask; +extern unsigned _page_shift; + +#define PAGE_SIZE _page_size +#define PAGE_MASK _page_mask +#define PAGE_SHIFT _page_shift + +/* +#define PAGE_SIZE 4096 +#define PAGE_MASK (~(4095)) +#define PAGE_SHIFT 12 +*/ + +#endif diff --git a/src/include/types.h b/src/include/types.h index 020a5e7e52d21..914fc1d744f29 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -15,6 +15,8 @@ #ifndef __MDS_TYPES_H #define __MDS_TYPES_H +#include "ceph_fs.h" + extern "C" { #include #include @@ -36,7 +38,6 @@ using namespace std; #include using namespace __gnu_cxx; -#include "ceph_fs.h" #include "object.h" -- 2.39.5