aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSage Weil <sage@inktank.com>2013-02-23 13:38:16 -0500
committerSage Weil <sage@inktank.com>2013-02-26 18:01:57 -0500
commit5b191d9914eb68257f47de9d5bfe099b77f0687c (patch)
tree2465631736897b02dd16de136ef5b69dadb943f1
parent12979354a1d6ef25d86f381e4d5f9e103f29913a (diff)
libceph: decode into cpu-native ceph_pg type
Always decode data into our cpu-native ceph_pg type that has the correct field widths. Limit any remaining uses of ceph_pg_v1 to dealing with the legacy protocol. Signed-off-by: Sage Weil <sage@inktank.com> Reviewed-by: Alex Elder <elder@inktank.com>
-rw-r--r--fs/ceph/ioctl.c5
-rw-r--r--include/linux/ceph/osd_client.h2
-rw-r--r--include/linux/ceph/osdmap.h11
-rw-r--r--net/ceph/debugfs.c5
-rw-r--r--net/ceph/osd_client.c9
-rw-r--r--net/ceph/osdmap.c78
6 files changed, 62 insertions, 48 deletions
diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index e831436d6e68..fb036ed3e129 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -186,7 +186,7 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
186 u64 len = 1, olen; 186 u64 len = 1, olen;
187 u64 tmp; 187 u64 tmp;
188 struct ceph_object_layout ol; 188 struct ceph_object_layout ol;
189 struct ceph_pg_v1 pgid; 189 struct ceph_pg pgid;
190 int r; 190 int r;
191 191
192 /* copy and validate */ 192 /* copy and validate */
@@ -212,7 +212,8 @@ static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
212 ceph_calc_object_layout(&ol, dl.object_name, &ci->i_layout, 212 ceph_calc_object_layout(&ol, dl.object_name, &ci->i_layout,
213 osdc->osdmap); 213 osdc->osdmap);
214 214
215 pgid = ol.ol_pgid; 215 pgid.pool = le32_to_cpu(ol.ol_pgid.pool);
216 pgid.seed = le16_to_cpu(ol.ol_pgid.ps);
216 dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid); 217 dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid);
217 if (dl.osd >= 0) { 218 if (dl.osd >= 0) {
218 struct ceph_entity_addr *a = 219 struct ceph_entity_addr *a =
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index be2867330e23..388158ff0cbc 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -56,7 +56,7 @@ struct ceph_osd_request {
56 struct list_head r_linger_item; 56 struct list_head r_linger_item;
57 struct list_head r_linger_osd; 57 struct list_head r_linger_osd;
58 struct ceph_osd *r_osd; 58 struct ceph_osd *r_osd;
59 struct ceph_pg_v1 r_pgid; 59 struct ceph_pg r_pgid;
60 int r_pg_osds[CEPH_PG_MAX_SIZE]; 60 int r_pg_osds[CEPH_PG_MAX_SIZE];
61 int r_num_pg_osds; 61 int r_num_pg_osds;
62 62
diff --git a/include/linux/ceph/osdmap.h b/include/linux/ceph/osdmap.h
index eb4989aa48e8..8a612df4c248 100644
--- a/include/linux/ceph/osdmap.h
+++ b/include/linux/ceph/osdmap.h
@@ -18,6 +18,11 @@
18 * The map can be updated either via an incremental map (diff) describing 18 * The map can be updated either via an incremental map (diff) describing
19 * the change between two successive epochs, or as a fully encoded map. 19 * the change between two successive epochs, or as a fully encoded map.
20 */ 20 */
21struct ceph_pg {
22 uint64_t pool;
23 uint32_t seed;
24};
25
21struct ceph_pg_pool_info { 26struct ceph_pg_pool_info {
22 struct rb_node node; 27 struct rb_node node;
23 int id; 28 int id;
@@ -28,7 +33,7 @@ struct ceph_pg_pool_info {
28 33
29struct ceph_pg_mapping { 34struct ceph_pg_mapping {
30 struct rb_node node; 35 struct rb_node node;
31 struct ceph_pg_v1 pgid; 36 struct ceph_pg pgid;
32 int len; 37 int len;
33 int osds[]; 38 int osds[];
34}; 39};
@@ -119,10 +124,10 @@ extern int ceph_calc_object_layout(struct ceph_object_layout *ol,
119 struct ceph_file_layout *fl, 124 struct ceph_file_layout *fl,
120 struct ceph_osdmap *osdmap); 125 struct ceph_osdmap *osdmap);
121extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, 126extern int ceph_calc_pg_acting(struct ceph_osdmap *osdmap,
122 struct ceph_pg_v1 pgid, 127 struct ceph_pg pgid,
123 int *acting); 128 int *acting);
124extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, 129extern int ceph_calc_pg_primary(struct ceph_osdmap *osdmap,
125 struct ceph_pg_v1 pgid); 130 struct ceph_pg pgid);
126 131
127extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id); 132extern const char *ceph_pg_pool_name_by_id(struct ceph_osdmap *map, u64 id);
128extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name); 133extern int ceph_pg_poolid_by_name(struct ceph_osdmap *map, const char *name);
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index 38b5dc1823d4..61a9af634f8b 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -131,10 +131,9 @@ static int osdc_show(struct seq_file *s, void *pp)
131 131
132 req = rb_entry(p, struct ceph_osd_request, r_node); 132 req = rb_entry(p, struct ceph_osd_request, r_node);
133 133
134 seq_printf(s, "%lld\tosd%d\t%d.%x\t", req->r_tid, 134 seq_printf(s, "%lld\tosd%d\t%lld.%x\t", req->r_tid,
135 req->r_osd ? req->r_osd->o_osd : -1, 135 req->r_osd ? req->r_osd->o_osd : -1,
136 le32_to_cpu(req->r_pgid.pool), 136 req->r_pgid.pool, req->r_pgid.seed);
137 le16_to_cpu(req->r_pgid.ps));
138 137
139 head = req->r_request->front.iov_base; 138 head = req->r_request->front.iov_base;
140 op = (void *)(head + 1); 139 op = (void *)(head + 1);
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index e3ab8d60d080..1990834e518b 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -914,7 +914,7 @@ static int __map_request(struct ceph_osd_client *osdc,
914 struct ceph_osd_request *req, int force_resend) 914 struct ceph_osd_request *req, int force_resend)
915{ 915{
916 struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base; 916 struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
917 struct ceph_pg_v1 pgid; 917 struct ceph_pg pgid;
918 int acting[CEPH_PG_MAX_SIZE]; 918 int acting[CEPH_PG_MAX_SIZE];
919 int o = -1, num = 0; 919 int o = -1, num = 0;
920 int err; 920 int err;
@@ -926,7 +926,8 @@ static int __map_request(struct ceph_osd_client *osdc,
926 list_move(&req->r_req_lru_item, &osdc->req_notarget); 926 list_move(&req->r_req_lru_item, &osdc->req_notarget);
927 return err; 927 return err;
928 } 928 }
929 pgid = reqhead->layout.ol_pgid; 929 pgid.pool = le32_to_cpu(reqhead->layout.ol_pgid.pool);
930 pgid.seed = le16_to_cpu(reqhead->layout.ol_pgid.ps);
930 req->r_pgid = pgid; 931 req->r_pgid = pgid;
931 932
932 err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting); 933 err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting);
@@ -943,8 +944,8 @@ static int __map_request(struct ceph_osd_client *osdc,
943 (req->r_osd == NULL && o == -1)) 944 (req->r_osd == NULL && o == -1))
944 return 0; /* no change */ 945 return 0; /* no change */
945 946
946 dout("map_request tid %llu pgid %d.%x osd%d (was osd%d)\n", 947 dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
947 req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o, 948 req->r_tid, pgid.pool, pgid.seed, o,
948 req->r_osd ? req->r_osd->o_osd : -1); 949 req->r_osd ? req->r_osd->o_osd : -1);
949 950
950 /* record full pg acting set */ 951 /* record full pg acting set */
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 8c89ac25081a..81118db5bd11 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -350,14 +350,15 @@ bad:
350 * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid 350 * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid
351 * to a set of osds) 351 * to a set of osds)
352 */ 352 */
353static int pgid_cmp(struct ceph_pg_v1 l, struct ceph_pg_v1 r) 353static int pgid_cmp(struct ceph_pg l, struct ceph_pg r)
354{ 354{
355 u64 a = *(u64 *)&l; 355 if (l.pool < r.pool)
356 u64 b = *(u64 *)&r; 356 return -1;
357 357 if (l.pool > r.pool)
358 if (a < b) 358 return 1;
359 if (l.seed < r.seed)
359 return -1; 360 return -1;
360 if (a > b) 361 if (l.seed > r.seed)
361 return 1; 362 return 1;
362 return 0; 363 return 0;
363} 364}
@@ -389,7 +390,7 @@ static int __insert_pg_mapping(struct ceph_pg_mapping *new,
389} 390}
390 391
391static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root, 392static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root,
392 struct ceph_pg_v1 pgid) 393 struct ceph_pg pgid)
393{ 394{
394 struct rb_node *n = root->rb_node; 395 struct rb_node *n = root->rb_node;
395 struct ceph_pg_mapping *pg; 396 struct ceph_pg_mapping *pg;
@@ -403,25 +404,26 @@ static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root,
403 } else if (c > 0) { 404 } else if (c > 0) {
404 n = n->rb_right; 405 n = n->rb_right;
405 } else { 406 } else {
406 dout("__lookup_pg_mapping %llx got %p\n", 407 dout("__lookup_pg_mapping %lld.%x got %p\n",
407 *(u64 *)&pgid, pg); 408 pgid.pool, pgid.seed, pg);
408 return pg; 409 return pg;
409 } 410 }
410 } 411 }
411 return NULL; 412 return NULL;
412} 413}
413 414
414static int __remove_pg_mapping(struct rb_root *root, struct ceph_pg_v1 pgid) 415static int __remove_pg_mapping(struct rb_root *root, struct ceph_pg pgid)
415{ 416{
416 struct ceph_pg_mapping *pg = __lookup_pg_mapping(root, pgid); 417 struct ceph_pg_mapping *pg = __lookup_pg_mapping(root, pgid);
417 418
418 if (pg) { 419 if (pg) {
419 dout("__remove_pg_mapping %llx %p\n", *(u64 *)&pgid, pg); 420 dout("__remove_pg_mapping %lld.%x %p\n", pgid.pool, pgid.seed,
421 pg);
420 rb_erase(&pg->node, root); 422 rb_erase(&pg->node, root);
421 kfree(pg); 423 kfree(pg);
422 return 0; 424 return 0;
423 } 425 }
424 dout("__remove_pg_mapping %llx dne\n", *(u64 *)&pgid); 426 dout("__remove_pg_mapping %lld.%x dne\n", pgid.pool, pgid.seed);
425 return -ENOENT; 427 return -ENOENT;
426} 428}
427 429
@@ -721,11 +723,14 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
721 ceph_decode_32_safe(p, end, len, bad); 723 ceph_decode_32_safe(p, end, len, bad);
722 for (i = 0; i < len; i++) { 724 for (i = 0; i < len; i++) {
723 int n, j; 725 int n, j;
724 struct ceph_pg_v1 pgid; 726 struct ceph_pg pgid;
727 struct ceph_pg_v1 pgid_v1;
725 struct ceph_pg_mapping *pg; 728 struct ceph_pg_mapping *pg;
726 729
727 ceph_decode_need(p, end, sizeof(u32) + sizeof(u64), bad); 730 ceph_decode_need(p, end, sizeof(u32) + sizeof(u64), bad);
728 ceph_decode_copy(p, &pgid, sizeof(pgid)); 731 ceph_decode_copy(p, &pgid_v1, sizeof(pgid_v1));
732 pgid.pool = le32_to_cpu(pgid_v1.pool);
733 pgid.seed = le16_to_cpu(pgid_v1.ps);
729 n = ceph_decode_32(p); 734 n = ceph_decode_32(p);
730 err = -EINVAL; 735 err = -EINVAL;
731 if (n > (UINT_MAX - sizeof(*pg)) / sizeof(u32)) 736 if (n > (UINT_MAX - sizeof(*pg)) / sizeof(u32))
@@ -743,7 +748,8 @@ struct ceph_osdmap *osdmap_decode(void **p, void *end)
743 err = __insert_pg_mapping(pg, &map->pg_temp); 748 err = __insert_pg_mapping(pg, &map->pg_temp);
744 if (err) 749 if (err)
745 goto bad; 750 goto bad;
746 dout(" added pg_temp %llx len %d\n", *(u64 *)&pgid, len); 751 dout(" added pg_temp %lld.%x len %d\n", pgid.pool, pgid.seed,
752 len);
747 } 753 }
748 754
749 /* crush */ 755 /* crush */
@@ -944,10 +950,13 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
944 while (len--) { 950 while (len--) {
945 struct ceph_pg_mapping *pg; 951 struct ceph_pg_mapping *pg;
946 int j; 952 int j;
947 struct ceph_pg_v1 pgid; 953 struct ceph_pg_v1 pgid_v1;
954 struct ceph_pg pgid;
948 u32 pglen; 955 u32 pglen;
949 ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad); 956 ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad);
950 ceph_decode_copy(p, &pgid, sizeof(pgid)); 957 ceph_decode_copy(p, &pgid_v1, sizeof(pgid_v1));
958 pgid.pool = le32_to_cpu(pgid_v1.pool);
959 pgid.seed = le16_to_cpu(pgid_v1.ps);
951 pglen = ceph_decode_32(p); 960 pglen = ceph_decode_32(p);
952 961
953 if (pglen) { 962 if (pglen) {
@@ -973,8 +982,8 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
973 kfree(pg); 982 kfree(pg);
974 goto bad; 983 goto bad;
975 } 984 }
976 dout(" added pg_temp %llx len %d\n", *(u64 *)&pgid, 985 dout(" added pg_temp %lld.%x len %d\n", pgid.pool,
977 pglen); 986 pgid.seed, pglen);
978 } else { 987 } else {
979 /* remove */ 988 /* remove */
980 __remove_pg_mapping(&map->pg_temp, pgid); 989 __remove_pg_mapping(&map->pg_temp, pgid);
@@ -1079,26 +1088,25 @@ int ceph_calc_object_layout(struct ceph_object_layout *ol,
1079 struct ceph_osdmap *osdmap) 1088 struct ceph_osdmap *osdmap)
1080{ 1089{
1081 unsigned int num, num_mask; 1090 unsigned int num, num_mask;
1082 struct ceph_pg_v1 pgid; 1091 struct ceph_pg pgid;
1083 int poolid = le32_to_cpu(fl->fl_pg_pool);
1084 struct ceph_pg_pool_info *pool; 1092 struct ceph_pg_pool_info *pool;
1085 unsigned int ps;
1086 1093
1087 BUG_ON(!osdmap); 1094 BUG_ON(!osdmap);
1088 1095
1089 pool = __lookup_pg_pool(&osdmap->pg_pools, poolid); 1096 pgid.pool = le32_to_cpu(fl->fl_pg_pool);
1097 pool = __lookup_pg_pool(&osdmap->pg_pools, pgid.pool);
1090 if (!pool) 1098 if (!pool)
1091 return -EIO; 1099 return -EIO;
1092 ps = ceph_str_hash(pool->v.object_hash, oid, strlen(oid)); 1100 pgid.seed = ceph_str_hash(pool->v.object_hash, oid, strlen(oid));
1093 num = le32_to_cpu(pool->v.pg_num); 1101 num = le32_to_cpu(pool->v.pg_num);
1094 num_mask = pool->pg_num_mask; 1102 num_mask = pool->pg_num_mask;
1095 1103
1096 pgid.ps = cpu_to_le16(ps); 1104 dout("calc_object_layout '%s' pgid %lld.%x\n", oid, pgid.pool,
1097 pgid.preferred = cpu_to_le16(-1); 1105 pgid.seed);
1098 pgid.pool = fl->fl_pg_pool;
1099 dout("calc_object_layout '%s' pgid %d.%x\n", oid, poolid, ps);
1100 1106
1101 ol->ol_pgid = pgid; 1107 ol->ol_pgid.ps = cpu_to_le16(pgid.seed);
1108 ol->ol_pgid.pool = fl->fl_pg_pool;
1109 ol->ol_pgid.preferred = cpu_to_le16(-1);
1102 ol->ol_stripe_unit = fl->fl_object_stripe_unit; 1110 ol->ol_stripe_unit = fl->fl_object_stripe_unit;
1103 return 0; 1111 return 0;
1104} 1112}
@@ -1108,7 +1116,7 @@ EXPORT_SYMBOL(ceph_calc_object_layout);
1108 * Calculate raw osd vector for the given pgid. Return pointer to osd 1116 * Calculate raw osd vector for the given pgid. Return pointer to osd
1109 * array, or NULL on failure. 1117 * array, or NULL on failure.
1110 */ 1118 */
1111static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid, 1119static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1112 int *osds, int *num) 1120 int *osds, int *num)
1113{ 1121{
1114 struct ceph_pg_mapping *pg; 1122 struct ceph_pg_mapping *pg;
@@ -1116,8 +1124,8 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid,
1116 int ruleno; 1124 int ruleno;
1117 unsigned int poolid, ps, pps, t, r; 1125 unsigned int poolid, ps, pps, t, r;
1118 1126
1119 poolid = le32_to_cpu(pgid.pool); 1127 poolid = pgid.pool;
1120 ps = le16_to_cpu(pgid.ps); 1128 ps = pgid.seed;
1121 1129
1122 pool = __lookup_pg_pool(&osdmap->pg_pools, poolid); 1130 pool = __lookup_pg_pool(&osdmap->pg_pools, poolid);
1123 if (!pool) 1131 if (!pool)
@@ -1126,7 +1134,7 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid,
1126 /* pg_temp? */ 1134 /* pg_temp? */
1127 t = ceph_stable_mod(ps, le32_to_cpu(pool->v.pg_num), 1135 t = ceph_stable_mod(ps, le32_to_cpu(pool->v.pg_num),
1128 pool->pgp_num_mask); 1136 pool->pgp_num_mask);
1129 pgid.ps = cpu_to_le16(t); 1137 pgid.seed = t;
1130 pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid); 1138 pg = __lookup_pg_mapping(&osdmap->pg_temp, pgid);
1131 if (pg) { 1139 if (pg) {
1132 *num = pg->len; 1140 *num = pg->len;
@@ -1163,7 +1171,7 @@ static int *calc_pg_raw(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid,
1163/* 1171/*
1164 * Return acting set for given pgid. 1172 * Return acting set for given pgid.
1165 */ 1173 */
1166int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid, 1174int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg pgid,
1167 int *acting) 1175 int *acting)
1168{ 1176{
1169 int rawosds[CEPH_PG_MAX_SIZE], *osds; 1177 int rawosds[CEPH_PG_MAX_SIZE], *osds;
@@ -1184,7 +1192,7 @@ int ceph_calc_pg_acting(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid,
1184/* 1192/*
1185 * Return primary osd for given pgid, or -1 if none. 1193 * Return primary osd for given pgid, or -1 if none.
1186 */ 1194 */
1187int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg_v1 pgid) 1195int ceph_calc_pg_primary(struct ceph_osdmap *osdmap, struct ceph_pg pgid)
1188{ 1196{
1189 int rawosds[CEPH_PG_MAX_SIZE], *osds; 1197 int rawosds[CEPH_PG_MAX_SIZE], *osds;
1190 int i, num = CEPH_PG_MAX_SIZE; 1198 int i, num = CEPH_PG_MAX_SIZE;