From 59fc0e27d58ca126e57fc8f1d5627c48f9077754 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 30 Sep 2009 11:01:37 -0700 Subject: [PATCH] kclient: more fixes from akpm's review --- src/TODO | 5 ++++- src/include/ceph_fs.cc | 2 +- src/include/msgr.h | 10 ++++----- src/include/rados.h | 13 +++++------- src/kernel/Makefile | 2 +- src/kernel/buffer.c | 34 ++++++++++++++++++++++++++++++ src/kernel/buffer.h | 48 +++++++++--------------------------------- src/kernel/osdmap.h | 19 ++++++++++++----- 8 files changed, 74 insertions(+), 59 deletions(-) create mode 100644 src/kernel/buffer.c diff --git a/src/TODO b/src/TODO index eb7a86f6c8dd0..d7f1e8c1284be 100644 --- a/src/TODO +++ b/src/TODO @@ -23,7 +23,10 @@ v0.16 /- uninline frags /- uninline string hash - +- document data structures +- audit all inline in kclient +- document on-wire protocol +- ceph_buffer fixes bugs - mislinked directory? diff --git a/src/include/ceph_fs.cc b/src/include/ceph_fs.cc index fc615ba076dfe..e228496bfea94 100644 --- a/src/include/ceph_fs.cc +++ b/src/include/ceph_fs.cc @@ -65,7 +65,7 @@ static unsigned long ceph_partial_name_hash(unsigned long c, unsigned long prevh */ static unsigned long ceph_end_name_hash(unsigned long hash) { - return (unsigned int) hash; + return hash & 0xffffffff; } /* Compute the hash for a name string. */ diff --git a/src/include/msgr.h b/src/include/msgr.h index 968b4ba0849f8..541e5bc0dc291 100644 --- a/src/include/msgr.h +++ b/src/include/msgr.h @@ -21,7 +21,7 @@ * whenever the wire protocol changes. try to keep this string length * constant. */ -#define CEPH_BANNER "ceph v019" +#define CEPH_BANNER "ceph v020" #define CEPH_BANNER_MAX_LEN 30 @@ -90,10 +90,10 @@ struct ceph_entity_inst { #define CEPH_MSGR_TAG_RETRY_GLOBAL 5 /* server->client + gseq: try again with higher gseq */ #define CEPH_MSGR_TAG_CLOSE 6 /* closing pipe */ -#define CEPH_MSGR_TAG_MSG 10 /* message */ -#define CEPH_MSGR_TAG_ACK 11 /* message ack */ -#define CEPH_MSGR_TAG_KEEPALIVE 12 /* just a keepalive byte! */ -#define CEPH_MSGR_TAG_BADPROTOVER 13 /* bad protocol version */ +#define CEPH_MSGR_TAG_MSG 7 /* message */ +#define CEPH_MSGR_TAG_ACK 8 /* message ack */ +#define CEPH_MSGR_TAG_KEEPALIVE 9 /* just a keepalive byte! */ +#define CEPH_MSGR_TAG_BADPROTOVER 10 /* bad protocol version */ /* diff --git a/src/include/rados.h b/src/include/rados.h index ab3e698472f18..d7ab9dd863dd6 100644 --- a/src/include/rados.h +++ b/src/include/rados.h @@ -2,8 +2,8 @@ #define __RADOS_H /* - * Data types for RADOS, the distributed object storage layer used by - * the Ceph file system. + * Data types for the Ceph distributed object storage layer RADOS + * (Reliable Autonomic Distributed Object Store). */ #include "msgr.h" @@ -55,20 +55,15 @@ struct ceph_timespec { * placement group. * we encode this into one __le64. */ -#define CEPH_PG_TYPE_REP 1 -#define CEPH_PG_TYPE_RAID4 2 union ceph_pg { __u64 pg64; struct { __s16 preferred; /* preferred primary osd */ __u16 ps; /* placement seed */ __u32 pool; /* implies crush ruleset */ - } pg; + } __attribute__ ((packed)) pg; } __attribute__ ((packed)); -#define ceph_pg_is_rep(pg) ((pg).pg.type == CEPH_PG_TYPE_REP) -#define ceph_pg_is_raid4(pg) ((pg).pg.type == CEPH_PG_TYPE_RAID4) - /* * pg_pool is a set of pgs storing a pool of objects * @@ -86,6 +81,8 @@ union ceph_pg { * * lpgp_num -- as above. */ +#define CEPH_PG_TYPE_REP 1 +#define CEPH_PG_TYPE_RAID4 2 struct ceph_pg_pool { __u8 type; __u8 size; diff --git a/src/kernel/Makefile b/src/kernel/Makefile index d7493d61614dd..7da6d69dba29c 100644 --- a/src/kernel/Makefile +++ b/src/kernel/Makefile @@ -8,7 +8,7 @@ obj-$(CONFIG_CEPH_FS) += ceph.o ceph-objs := super.o inode.o dir.o file.o addr.o ioctl.o \ export.o caps.o snap.o xattr.o \ - messenger.o msgpool.o \ + messenger.o msgpool.o buffer.o \ mds_client.o mdsmap.o \ mon_client.o \ osd_client.o osdmap.o crush/crush.o crush/mapper.o \ diff --git a/src/kernel/buffer.c b/src/kernel/buffer.c new file mode 100644 index 0000000000000..635e7df4bd6ca --- /dev/null +++ b/src/kernel/buffer.c @@ -0,0 +1,34 @@ + +#include "ceph_debug.h" +#include "buffer.h" + +struct ceph_buffer *ceph_buffer_new(gfp_t gfp) +{ + struct ceph_buffer *b; + + b = kmalloc(sizeof(*b), gfp); + if (!b) + return NULL; + atomic_set(&b->nref, 1); + b->vec.iov_base = NULL; + b->vec.iov_len = 0; + b->alloc_len = 0; + return b; +} + +int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp) +{ + if (len <= PAGE_SIZE) { + b->vec.iov_base = kmalloc(len, gfp); + b->is_vmalloc = false; + } else { + b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL); + b->is_vmalloc = true; + } + if (!b->vec.iov_base) + return -ENOMEM; + b->alloc_len = len; + b->vec.iov_len = len; + return 0; +} + diff --git a/src/kernel/buffer.h b/src/kernel/buffer.h index 128593d3bc9ae..bbedaf47ab9e5 100644 --- a/src/kernel/buffer.h +++ b/src/kernel/buffer.h @@ -2,10 +2,9 @@ #define __FS_CEPH_BUFFER_H #include -#include #include - -#include "ceph_debug.h" +#include +#include /* * a simple reference counted buffer. @@ -20,35 +19,8 @@ struct ceph_buffer { bool is_vmalloc; }; -static inline struct ceph_buffer *ceph_buffer_new(gfp_t gfp) -{ - struct ceph_buffer *b; - - b = kmalloc(sizeof(*b), gfp); - if (!b) - return NULL; - atomic_set(&b->nref, 1); - b->vec.iov_base = NULL; - b->vec.iov_len = 0; - b->alloc_len = 0; - return b; -} - -static inline int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp) -{ - if (len <= PAGE_SIZE) { - b->vec.iov_base = kmalloc(len, gfp); - b->is_vmalloc = false; - } else { - b->vec.iov_base = __vmalloc(len, gfp, PAGE_KERNEL); - b->is_vmalloc = true; - } - if (!b->vec.iov_base) - return -ENOMEM; - b->alloc_len = len; - b->vec.iov_len = len; - return 0; -} +struct ceph_buffer *ceph_buffer_new(gfp_t gfp); +int ceph_buffer_alloc(struct ceph_buffer *b, int len, gfp_t gfp); static inline struct ceph_buffer *ceph_buffer_get(struct ceph_buffer *b) { @@ -71,13 +43,13 @@ static inline void ceph_buffer_put(struct ceph_buffer *b) static inline struct ceph_buffer *ceph_buffer_new_alloc(int len, gfp_t gfp) { - struct ceph_buffer *b = ceph_buffer_new(gfp); + struct ceph_buffer *b = ceph_buffer_new(gfp); - if (b && ceph_buffer_alloc(b, len, gfp) < 0) { - ceph_buffer_put(b); - b = NULL; - } - return b; + if (b && ceph_buffer_alloc(b, len, gfp) < 0) { + ceph_buffer_put(b); + b = NULL; + } + return b; } #endif diff --git a/src/kernel/osdmap.h b/src/kernel/osdmap.h index cdf6f1aecf0a9..07127c6fb134c 100644 --- a/src/kernel/osdmap.h +++ b/src/kernel/osdmap.h @@ -53,7 +53,9 @@ struct ceph_osdmap { struct crush_map *crush; }; -/* file layout helpers */ +/* + * file layout helpers + */ #define ceph_file_layout_su(l) ((__s32)le32_to_cpu((l).fl_stripe_unit)) #define ceph_file_layout_stripe_count(l) \ ((__s32)le32_to_cpu((l).fl_stripe_count)) @@ -66,12 +68,19 @@ struct ceph_osdmap { #define ceph_file_layout_pg_pool(l) \ ((__s32)le32_to_cpu((l).fl_pg_pool)) -#define ceph_file_layout_stripe_width(l) (le32_to_cpu((l).fl_stripe_unit) * \ - le32_to_cpu((l).fl_stripe_count)) +static inline unsigned ceph_file_layout_stripe_width(struct ceph_file_layout *l) +{ + return le32_to_cpu(l->fl_stripe_unit) * + le32_to_cpu(l->fl_stripe_count); +} /* "period" == bytes before i start on a new set of objects */ -#define ceph_file_layout_period(l) (le32_to_cpu((l).fl_object_size) * \ - le32_to_cpu((l).fl_stripe_count)) +static inline unsigned ceph_file_layout_period(struct ceph_file_layout *l) +{ + return le32_to_cpu(l->fl_object_size) * + le32_to_cpu(l->fl_stripe_count); +} + static inline int ceph_osd_is_up(struct ceph_osdmap *map, int osd) { -- 2.39.5