aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Elder <elder@inktank.com>2013-04-01 19:58:26 -0400
committerSage Weil <sage@inktank.com>2013-05-02 00:17:52 -0400
commitef4859d6479d19bcc65c3156cf3b7dd747355c29 (patch)
tree83a977e35c7dd32834d707f93173c1e00da06384
parent8058fd45039724695d5b67a574544452635d64a9 (diff)
libceph: define ceph_decode_pgid() only once
There are two basically identical definitions of __decode_pgid() in libceph, one in "net/ceph/osdmap.c" and the other in "net/ceph/osd_client.c". Get rid of both, and instead define a single inline version in "include/linux/ceph/osdmap.h". Signed-off-by: Alex Elder <elder@inktank.com> Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rw-r--r--include/linux/ceph/osdmap.h24
-rw-r--r--net/ceph/osd_client.c22
-rw-r--r--net/ceph/osdmap.c22
3 files changed, 27 insertions, 41 deletions
diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index 167daf60c4e8..d05cc4451af6 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -3,6 +3,7 @@
3 3
4#include <linux/rbtree.h> 4#include <linux/rbtree.h>
5#include <linux/ceph/types.h> 5#include <linux/ceph/types.h>
6#include <linux/ceph/decode.h>
6#include <linux/ceph/ceph_fs.h> 7#include <linux/ceph/ceph_fs.h>
7#include <linux/crush/crush.h> 8#include <linux/crush/crush.h>
8 9
@@ -119,6 +120,29 @@ static inline struct ceph_entity_addr *ceph_osd_addr(struct ceph_osdmap *map,
119 return &map->osd_addr[osd]; 120 return &map->osd_addr[osd];
120} 121}
121 122
123static inline int ceph_decode_pgid(void **p, void *end, struct ceph_pg *pgid)
124{
125 __u8 version;
126
127 if (!ceph_has_room(p, end, 1 + 8 + 4 + 4)) {
128 pr_warning("incomplete pg encoding");
129
130 return -EINVAL;
131 }
132 version = ceph_decode_8(p);
133 if (version > 1) {
134 pr_warning("do not understand pg encoding %d > 1",
135 (int)version);
136 return -EINVAL;
137 }
138
139 pgid->pool = ceph_decode_64(p);
140 pgid->seed = ceph_decode_32(p);
141 *p += 4; /* skip deprecated preferred value */
142
143 return 0;
144}
145
122extern struct ceph_osdmap *osdmap_decode(void **p, void *end); 146extern struct ceph_osdmap *osdmap_decode(void **p, void *end);
123extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end, 147extern struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
124 struct ceph_osdmap *map, 148 struct ceph_osdmap *map,
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 69ef6539ca14..ca79cad50840 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1268,26 +1268,6 @@ static void complete_request(struct ceph_osd_request *req)
1268 complete_all(&req->r_safe_completion); /* fsync waiter */ 1268 complete_all(&req->r_safe_completion); /* fsync waiter */
1269} 1269}
1270 1270
1271static int __decode_pgid(void **p, void *end, struct ceph_pg *pgid)
1272{
1273 __u8 v;
1274
1275 ceph_decode_need(p, end, 1 + 8 + 4 + 4, bad);
1276 v = ceph_decode_8(p);
1277 if (v > 1) {
1278 pr_warning("do not understand pg encoding %d > 1", v);
1279 return -EINVAL;
1280 }
1281 pgid->pool = ceph_decode_64(p);
1282 pgid->seed = ceph_decode_32(p);
1283 *p += 4;
1284 return 0;
1285
1286bad:
1287 pr_warning("incomplete pg encoding");
1288 return -EINVAL;
1289}
1290
1291/* 1271/*
1292 * handle osd op reply. either call the callback if it is specified, 1272 * handle osd op reply. either call the callback if it is specified,
1293 * or do the completion to wake up the waiting thread. 1273 * or do the completion to wake up the waiting thread.
@@ -1321,7 +1301,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1321 ceph_decode_need(&p, end, object_len, bad); 1301 ceph_decode_need(&p, end, object_len, bad);
1322 p += object_len; 1302 p += object_len;
1323 1303
1324 err = __decode_pgid(&p, end, &pg); 1304 err = ceph_decode_pgid(&p, end, &pg);
1325 if (err) 1305 if (err)
1326 goto bad; 1306 goto bad;
1327 1307
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 09898711f2fd..603ddd92db19 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -654,24 +654,6 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
654 return 0; 654 return 0;
655} 655}
656 656
657static int __decode_pgid(void **p, void *end, struct ceph_pg *pg)
658{
659 u8 v;
660
661 ceph_decode_need(p, end, 1+8+4+4, bad);
662 v = ceph_decode_8(p);
663 if (v != 1)
664 goto bad;
665 pg->pool = ceph_decode_64(p);
666 pg->seed = ceph_decode_32(p);
667 *p += 4; /* skip preferred */
668 return 0;
669
670bad:
671 dout("error decoding pgid\n");
672 return -EINVAL;
673}
674
675/* 657/*
676 * decode a full map. 658 * decode a full map.
677 */ 659 */
@@ -765,7 +747,7 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
765 struct ceph_pg pgid; 747 struct ceph_pg pgid;
766 struct ceph_pg_mapping *pg; 748 struct ceph_pg_mapping *pg;
767 749
768 err = __decode_pgid(p, end, &pgid); 750 err = ceph_decode_pgid(p, end, &pgid);
769 if (err) 751 if (err)
770 goto bad; 752 goto bad;
771 ceph_decode_need(p, end, sizeof(u32), bad); 753 ceph_decode_need(p, end, sizeof(u32), bad);
@@ -983,7 +965,7 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
983 struct ceph_pg pgid; 965 struct ceph_pg pgid;
984 u32 pglen; 966 u32 pglen;
985 967
986 err = __decode_pgid(p, end, &pgid); 968 err = ceph_decode_pgid(p, end, &pgid);
987 if (err) 969 if (err)
988 goto bad; 970 goto bad;
989 ceph_decode_need(p, end, sizeof(u32), bad); 971 ceph_decode_need(p, end, sizeof(u32), bad);