aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Dryomov <idryomov@gmail.com>2017-06-21 11:27:17 -0400
committerIlya Dryomov <idryomov@gmail.com>2017-07-07 11:25:18 -0400
commitab75144be08cfc1d80f49e9c37970fcadb1215a2 (patch)
tree0b4b67a13e71ff799600ad9ebc04a882a4dae709
parenta303bb0e58345fe9f7ab2f82b90266f2b5036058 (diff)
libceph: kill __{insert,lookup,remove}_pg_mapping()
Switch to DEFINE_RB_FUNCS2-generated {insert,lookup,erase}_pg_mapping(). Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--net/ceph/osdmap.c87
1 files changed, 15 insertions, 72 deletions
diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 41b380ac68ac..423747714017 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -457,69 +457,8 @@ static void free_pg_mapping(struct ceph_pg_mapping *pg)
457 * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid 457 * rbtree of pg_mapping for handling pg_temp (explicit mapping of pgid
458 * to a set of osds) and primary_temp (explicit primary setting) 458 * to a set of osds) and primary_temp (explicit primary setting)
459 */ 459 */
460static int __insert_pg_mapping(struct ceph_pg_mapping *new, 460DEFINE_RB_FUNCS2(pg_mapping, struct ceph_pg_mapping, pgid, ceph_pg_compare,
461 struct rb_root *root) 461 RB_BYPTR, const struct ceph_pg *, node)
462{
463 struct rb_node **p = &root->rb_node;
464 struct rb_node *parent = NULL;
465 struct ceph_pg_mapping *pg = NULL;
466 int c;
467
468 dout("__insert_pg_mapping %llx %p\n", *(u64 *)&new->pgid, new);
469 while (*p) {
470 parent = *p;
471 pg = rb_entry(parent, struct ceph_pg_mapping, node);
472 c = ceph_pg_compare(&new->pgid, &pg->pgid);
473 if (c < 0)
474 p = &(*p)->rb_left;
475 else if (c > 0)
476 p = &(*p)->rb_right;
477 else
478 return -EEXIST;
479 }
480
481 rb_link_node(&new->node, parent, p);
482 rb_insert_color(&new->node, root);
483 return 0;
484}
485
486static struct ceph_pg_mapping *__lookup_pg_mapping(struct rb_root *root,
487 const struct ceph_pg *pgid)
488{
489 struct rb_node *n = root->rb_node;
490 struct ceph_pg_mapping *pg;
491 int c;
492
493 while (n) {
494 pg = rb_entry(n, struct ceph_pg_mapping, node);
495 c = ceph_pg_compare(pgid, &pg->pgid);
496 if (c < 0) {
497 n = n->rb_left;
498 } else if (c > 0) {
499 n = n->rb_right;
500 } else {
501 dout("__lookup_pg_mapping %lld.%x got %p\n",
502 pgid->pool, pgid->seed, pg);
503 return pg;
504 }
505 }
506 return NULL;
507}
508
509static int __remove_pg_mapping(struct rb_root *root, const struct ceph_pg *pgid)
510{
511 struct ceph_pg_mapping *pg = __lookup_pg_mapping(root, pgid);
512
513 if (pg) {
514 dout("__remove_pg_mapping %lld.%x %p\n", pgid->pool, pgid->seed,
515 pg);
516 rb_erase(&pg->node, root);
517 kfree(pg);
518 return 0;
519 }
520 dout("__remove_pg_mapping %lld.%x dne\n", pgid->pool, pgid->seed);
521 return -ENOENT;
522}
523 462
524/* 463/*
525 * rbtree of pg pool info 464 * rbtree of pg pool info
@@ -829,15 +768,15 @@ void ceph_osdmap_destroy(struct ceph_osdmap *map)
829 struct ceph_pg_mapping *pg = 768 struct ceph_pg_mapping *pg =
830 rb_entry(rb_first(&map->pg_temp), 769 rb_entry(rb_first(&map->pg_temp),
831 struct ceph_pg_mapping, node); 770 struct ceph_pg_mapping, node);
832 rb_erase(&pg->node, &map->pg_temp); 771 erase_pg_mapping(&map->pg_temp, pg);
833 kfree(pg); 772 free_pg_mapping(pg);
834 } 773 }
835 while (!RB_EMPTY_ROOT(&map->primary_temp)) { 774 while (!RB_EMPTY_ROOT(&map->primary_temp)) {
836 struct ceph_pg_mapping *pg = 775 struct ceph_pg_mapping *pg =
837 rb_entry(rb_first(&map->primary_temp), 776 rb_entry(rb_first(&map->primary_temp),
838 struct ceph_pg_mapping, node); 777 struct ceph_pg_mapping, node);
839 rb_erase(&pg->node, &map->primary_temp); 778 erase_pg_mapping(&map->primary_temp, pg);
840 kfree(pg); 779 free_pg_mapping(pg);
841 } 780 }
842 while (!RB_EMPTY_ROOT(&map->pg_pools)) { 781 while (!RB_EMPTY_ROOT(&map->pg_pools)) {
843 struct ceph_pg_pool_info *pi = 782 struct ceph_pg_pool_info *pi =
@@ -1055,8 +994,12 @@ static int decode_pg_mapping(void **p, void *end, struct rb_root *mapping_root,
1055 if (ret) 994 if (ret)
1056 return ret; 995 return ret;
1057 996
1058 ret = __remove_pg_mapping(mapping_root, &pgid); 997 pg = lookup_pg_mapping(mapping_root, &pgid);
1059 WARN_ON(!incremental && ret != -ENOENT); 998 if (pg) {
999 WARN_ON(!incremental);
1000 erase_pg_mapping(mapping_root, pg);
1001 free_pg_mapping(pg);
1002 }
1060 1003
1061 if (fn) { 1004 if (fn) {
1062 pg = fn(p, end, incremental); 1005 pg = fn(p, end, incremental);
@@ -1065,7 +1008,7 @@ static int decode_pg_mapping(void **p, void *end, struct rb_root *mapping_root,
1065 1008
1066 if (pg) { 1009 if (pg) {
1067 pg->pgid = pgid; /* struct */ 1010 pg->pgid = pgid; /* struct */
1068 __insert_pg_mapping(pg, mapping_root); 1011 insert_pg_mapping(mapping_root, pg);
1069 } 1012 }
1070 } 1013 }
1071 } 1014 }
@@ -2242,7 +2185,7 @@ static void get_temp_osds(struct ceph_osdmap *osdmap,
2242 ceph_osds_init(temp); 2185 ceph_osds_init(temp);
2243 2186
2244 /* pg_temp? */ 2187 /* pg_temp? */
2245 pg = __lookup_pg_mapping(&osdmap->pg_temp, &pgid); 2188 pg = lookup_pg_mapping(&osdmap->pg_temp, &pgid);
2246 if (pg) { 2189 if (pg) {
2247 for (i = 0; i < pg->pg_temp.len; i++) { 2190 for (i = 0; i < pg->pg_temp.len; i++) {
2248 if (ceph_osd_is_down(osdmap, pg->pg_temp.osds[i])) { 2191 if (ceph_osd_is_down(osdmap, pg->pg_temp.osds[i])) {
@@ -2265,7 +2208,7 @@ static void get_temp_osds(struct ceph_osdmap *osdmap,
2265 } 2208 }
2266 2209
2267 /* primary_temp? */ 2210 /* primary_temp? */
2268 pg = __lookup_pg_mapping(&osdmap->primary_temp, &pgid); 2211 pg = lookup_pg_mapping(&osdmap->primary_temp, &pgid);
2269 if (pg) 2212 if (pg)
2270 temp->primary = pg->primary_temp.osd; 2213 temp->primary = pg->primary_temp.osd;
2271} 2214}