diff options
| author | Ilya Dryomov <idryomov@gmail.com> | 2016-04-28 10:07:22 -0400 |
|---|---|---|
| committer | Ilya Dryomov <idryomov@gmail.com> | 2016-05-25 18:36:23 -0400 |
| commit | fcd00b68bbe2bf5606cb45c2cd4a250a390bcc1f (patch) | |
| tree | 7db18711377a59e78b22df4f6d73411620cc92df | |
| parent | 42a2c09f2b0b95fa147bcdb56cdc02b980b9ac5e (diff) | |
libceph: DEFINE_RB_FUNCS macro
Given
struct foo {
u64 id;
struct rb_node bar_node;
};
generate insert_bar(), erase_bar() and lookup_bar() functions with
DEFINE_RB_FUNCS(bar, struct foo, id, bar_node)
The key is assumed to be an integer (u64, int, etc), compared with
< and >. nodefld has to be initialized with RB_CLEAR_NODE().
Start using it for MDS, MON and OSD requests and OSD sessions.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
| -rw-r--r-- | fs/ceph/mds_client.c | 54 | ||||
| -rw-r--r-- | include/linux/ceph/libceph.h | 57 | ||||
| -rw-r--r-- | net/ceph/mon_client.c | 52 | ||||
| -rw-r--r-- | net/ceph/osd_client.c | 97 |
4 files changed, 88 insertions, 172 deletions
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 85b8517f17a0..cff85af425d4 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c | |||
| @@ -567,51 +567,23 @@ void ceph_mdsc_release_request(struct kref *kref) | |||
| 567 | kfree(req); | 567 | kfree(req); |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | DEFINE_RB_FUNCS(request, struct ceph_mds_request, r_tid, r_node) | ||
| 571 | |||
| 570 | /* | 572 | /* |
| 571 | * lookup session, bump ref if found. | 573 | * lookup session, bump ref if found. |
| 572 | * | 574 | * |
| 573 | * called under mdsc->mutex. | 575 | * called under mdsc->mutex. |
| 574 | */ | 576 | */ |
| 575 | static struct ceph_mds_request *__lookup_request(struct ceph_mds_client *mdsc, | 577 | static struct ceph_mds_request * |
| 576 | u64 tid) | 578 | lookup_get_request(struct ceph_mds_client *mdsc, u64 tid) |
| 577 | { | 579 | { |
| 578 | struct ceph_mds_request *req; | 580 | struct ceph_mds_request *req; |
| 579 | struct rb_node *n = mdsc->request_tree.rb_node; | ||
| 580 | |||
| 581 | while (n) { | ||
| 582 | req = rb_entry(n, struct ceph_mds_request, r_node); | ||
| 583 | if (tid < req->r_tid) | ||
| 584 | n = n->rb_left; | ||
| 585 | else if (tid > req->r_tid) | ||
| 586 | n = n->rb_right; | ||
| 587 | else { | ||
| 588 | ceph_mdsc_get_request(req); | ||
| 589 | return req; | ||
| 590 | } | ||
| 591 | } | ||
| 592 | return NULL; | ||
| 593 | } | ||
| 594 | 581 | ||
| 595 | static void __insert_request(struct ceph_mds_client *mdsc, | 582 | req = lookup_request(&mdsc->request_tree, tid); |
| 596 | struct ceph_mds_request *new) | 583 | if (req) |
| 597 | { | 584 | ceph_mdsc_get_request(req); |
| 598 | struct rb_node **p = &mdsc->request_tree.rb_node; | ||
| 599 | struct rb_node *parent = NULL; | ||
| 600 | struct ceph_mds_request *req = NULL; | ||
| 601 | 585 | ||
| 602 | while (*p) { | 586 | return req; |
| 603 | parent = *p; | ||
| 604 | req = rb_entry(parent, struct ceph_mds_request, r_node); | ||
| 605 | if (new->r_tid < req->r_tid) | ||
| 606 | p = &(*p)->rb_left; | ||
| 607 | else if (new->r_tid > req->r_tid) | ||
| 608 | p = &(*p)->rb_right; | ||
| 609 | else | ||
| 610 | BUG(); | ||
| 611 | } | ||
| 612 | |||
| 613 | rb_link_node(&new->r_node, parent, p); | ||
| 614 | rb_insert_color(&new->r_node, &mdsc->request_tree); | ||
| 615 | } | 587 | } |
| 616 | 588 | ||
| 617 | /* | 589 | /* |
| @@ -630,7 +602,7 @@ static void __register_request(struct ceph_mds_client *mdsc, | |||
| 630 | req->r_num_caps); | 602 | req->r_num_caps); |
| 631 | dout("__register_request %p tid %lld\n", req, req->r_tid); | 603 | dout("__register_request %p tid %lld\n", req, req->r_tid); |
| 632 | ceph_mdsc_get_request(req); | 604 | ceph_mdsc_get_request(req); |
| 633 | __insert_request(mdsc, req); | 605 | insert_request(&mdsc->request_tree, req); |
| 634 | 606 | ||
| 635 | req->r_uid = current_fsuid(); | 607 | req->r_uid = current_fsuid(); |
| 636 | req->r_gid = current_fsgid(); | 608 | req->r_gid = current_fsgid(); |
| @@ -663,8 +635,7 @@ static void __unregister_request(struct ceph_mds_client *mdsc, | |||
| 663 | } | 635 | } |
| 664 | } | 636 | } |
| 665 | 637 | ||
| 666 | rb_erase(&req->r_node, &mdsc->request_tree); | 638 | erase_request(&mdsc->request_tree, req); |
| 667 | RB_CLEAR_NODE(&req->r_node); | ||
| 668 | 639 | ||
| 669 | if (req->r_unsafe_dir && req->r_got_unsafe) { | 640 | if (req->r_unsafe_dir && req->r_got_unsafe) { |
| 670 | struct ceph_inode_info *ci = ceph_inode(req->r_unsafe_dir); | 641 | struct ceph_inode_info *ci = ceph_inode(req->r_unsafe_dir); |
| @@ -1722,6 +1693,7 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) | |||
| 1722 | INIT_LIST_HEAD(&req->r_unsafe_target_item); | 1693 | INIT_LIST_HEAD(&req->r_unsafe_target_item); |
| 1723 | req->r_fmode = -1; | 1694 | req->r_fmode = -1; |
| 1724 | kref_init(&req->r_kref); | 1695 | kref_init(&req->r_kref); |
| 1696 | RB_CLEAR_NODE(&req->r_node); | ||
| 1725 | INIT_LIST_HEAD(&req->r_wait); | 1697 | INIT_LIST_HEAD(&req->r_wait); |
| 1726 | init_completion(&req->r_completion); | 1698 | init_completion(&req->r_completion); |
| 1727 | init_completion(&req->r_safe_completion); | 1699 | init_completion(&req->r_safe_completion); |
| @@ -2414,7 +2386,7 @@ static void handle_reply(struct ceph_mds_session *session, struct ceph_msg *msg) | |||
| 2414 | /* get request, session */ | 2386 | /* get request, session */ |
| 2415 | tid = le64_to_cpu(msg->hdr.tid); | 2387 | tid = le64_to_cpu(msg->hdr.tid); |
| 2416 | mutex_lock(&mdsc->mutex); | 2388 | mutex_lock(&mdsc->mutex); |
| 2417 | req = __lookup_request(mdsc, tid); | 2389 | req = lookup_get_request(mdsc, tid); |
| 2418 | if (!req) { | 2390 | if (!req) { |
| 2419 | dout("handle_reply on unknown tid %llu\n", tid); | 2391 | dout("handle_reply on unknown tid %llu\n", tid); |
| 2420 | mutex_unlock(&mdsc->mutex); | 2392 | mutex_unlock(&mdsc->mutex); |
| @@ -2604,7 +2576,7 @@ static void handle_forward(struct ceph_mds_client *mdsc, | |||
| 2604 | fwd_seq = ceph_decode_32(&p); | 2576 | fwd_seq = ceph_decode_32(&p); |
| 2605 | 2577 | ||
| 2606 | mutex_lock(&mdsc->mutex); | 2578 | mutex_lock(&mdsc->mutex); |
| 2607 | req = __lookup_request(mdsc, tid); | 2579 | req = lookup_get_request(mdsc, tid); |
| 2608 | if (!req) { | 2580 | if (!req) { |
| 2609 | dout("forward tid %llu to mds%d - req dne\n", tid, next_mds); | 2581 | dout("forward tid %llu to mds%d - req dne\n", tid, next_mds); |
| 2610 | goto out; /* dup reply? */ | 2582 | goto out; /* dup reply? */ |
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h index db92a8d4926e..690985daad1c 100644 --- a/include/linux/ceph/libceph.h +++ b/include/linux/ceph/libceph.h | |||
| @@ -180,6 +180,63 @@ static inline int calc_pages_for(u64 off, u64 len) | |||
| 180 | (off >> PAGE_SHIFT); | 180 | (off >> PAGE_SHIFT); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | /* | ||
| 184 | * These are not meant to be generic - an integer key is assumed. | ||
| 185 | */ | ||
| 186 | #define DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \ | ||
| 187 | static void insert_##name(struct rb_root *root, type *t) \ | ||
| 188 | { \ | ||
| 189 | struct rb_node **n = &root->rb_node; \ | ||
| 190 | struct rb_node *parent = NULL; \ | ||
| 191 | \ | ||
| 192 | BUG_ON(!RB_EMPTY_NODE(&t->nodefld)); \ | ||
| 193 | \ | ||
| 194 | while (*n) { \ | ||
| 195 | type *cur = rb_entry(*n, type, nodefld); \ | ||
| 196 | \ | ||
| 197 | parent = *n; \ | ||
| 198 | if (t->keyfld < cur->keyfld) \ | ||
| 199 | n = &(*n)->rb_left; \ | ||
| 200 | else if (t->keyfld > cur->keyfld) \ | ||
| 201 | n = &(*n)->rb_right; \ | ||
| 202 | else \ | ||
| 203 | BUG(); \ | ||
| 204 | } \ | ||
| 205 | \ | ||
| 206 | rb_link_node(&t->nodefld, parent, n); \ | ||
| 207 | rb_insert_color(&t->nodefld, root); \ | ||
| 208 | } \ | ||
| 209 | static void erase_##name(struct rb_root *root, type *t) \ | ||
| 210 | { \ | ||
| 211 | BUG_ON(RB_EMPTY_NODE(&t->nodefld)); \ | ||
| 212 | rb_erase(&t->nodefld, root); \ | ||
| 213 | RB_CLEAR_NODE(&t->nodefld); \ | ||
| 214 | } | ||
| 215 | |||
| 216 | #define DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld) \ | ||
| 217 | static type *lookup_##name(struct rb_root *root, \ | ||
| 218 | typeof(((type *)0)->keyfld) key) \ | ||
| 219 | { \ | ||
| 220 | struct rb_node *n = root->rb_node; \ | ||
| 221 | \ | ||
| 222 | while (n) { \ | ||
| 223 | type *cur = rb_entry(n, type, nodefld); \ | ||
| 224 | \ | ||
| 225 | if (key < cur->keyfld) \ | ||
| 226 | n = n->rb_left; \ | ||
| 227 | else if (key > cur->keyfld) \ | ||
| 228 | n = n->rb_right; \ | ||
| 229 | else \ | ||
| 230 | return cur; \ | ||
| 231 | } \ | ||
| 232 | \ | ||
| 233 | return NULL; \ | ||
| 234 | } | ||
| 235 | |||
| 236 | #define DEFINE_RB_FUNCS(name, type, keyfld, nodefld) \ | ||
| 237 | DEFINE_RB_INSDEL_FUNCS(name, type, keyfld, nodefld) \ | ||
| 238 | DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld) | ||
| 239 | |||
| 183 | extern struct kmem_cache *ceph_inode_cachep; | 240 | extern struct kmem_cache *ceph_inode_cachep; |
| 184 | extern struct kmem_cache *ceph_cap_cachep; | 241 | extern struct kmem_cache *ceph_cap_cachep; |
| 185 | extern struct kmem_cache *ceph_cap_flush_cachep; | 242 | extern struct kmem_cache *ceph_cap_flush_cachep; |
diff --git a/net/ceph/mon_client.c b/net/ceph/mon_client.c index 3dfafdad92aa..a426a4b03e75 100644 --- a/net/ceph/mon_client.c +++ b/net/ceph/mon_client.c | |||
| @@ -478,45 +478,7 @@ out: | |||
| 478 | /* | 478 | /* |
| 479 | * generic requests (currently statfs, mon_get_version) | 479 | * generic requests (currently statfs, mon_get_version) |
| 480 | */ | 480 | */ |
| 481 | static struct ceph_mon_generic_request *__lookup_generic_req( | 481 | DEFINE_RB_FUNCS(generic_request, struct ceph_mon_generic_request, tid, node) |
| 482 | struct ceph_mon_client *monc, u64 tid) | ||
| 483 | { | ||
| 484 | struct ceph_mon_generic_request *req; | ||
| 485 | struct rb_node *n = monc->generic_request_tree.rb_node; | ||
| 486 | |||
| 487 | while (n) { | ||
| 488 | req = rb_entry(n, struct ceph_mon_generic_request, node); | ||
| 489 | if (tid < req->tid) | ||
| 490 | n = n->rb_left; | ||
| 491 | else if (tid > req->tid) | ||
| 492 | n = n->rb_right; | ||
| 493 | else | ||
| 494 | return req; | ||
| 495 | } | ||
| 496 | return NULL; | ||
| 497 | } | ||
| 498 | |||
| 499 | static void __insert_generic_request(struct ceph_mon_client *monc, | ||
| 500 | struct ceph_mon_generic_request *new) | ||
| 501 | { | ||
| 502 | struct rb_node **p = &monc->generic_request_tree.rb_node; | ||
| 503 | struct rb_node *parent = NULL; | ||
| 504 | struct ceph_mon_generic_request *req = NULL; | ||
| 505 | |||
| 506 | while (*p) { | ||
| 507 | parent = *p; | ||
| 508 | req = rb_entry(parent, struct ceph_mon_generic_request, node); | ||
| 509 | if (new->tid < req->tid) | ||
| 510 | p = &(*p)->rb_left; | ||
| 511 | else if (new->tid > req->tid) | ||
| 512 | p = &(*p)->rb_right; | ||
| 513 | else | ||
| 514 | BUG(); | ||
| 515 | } | ||
| 516 | |||
| 517 | rb_link_node(&new->node, parent, p); | ||
| 518 | rb_insert_color(&new->node, &monc->generic_request_tree); | ||
| 519 | } | ||
| 520 | 482 | ||
| 521 | static void release_generic_request(struct kref *kref) | 483 | static void release_generic_request(struct kref *kref) |
| 522 | { | 484 | { |
| @@ -551,7 +513,7 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con, | |||
| 551 | struct ceph_msg *m; | 513 | struct ceph_msg *m; |
| 552 | 514 | ||
| 553 | mutex_lock(&monc->mutex); | 515 | mutex_lock(&monc->mutex); |
| 554 | req = __lookup_generic_req(monc, tid); | 516 | req = lookup_generic_request(&monc->generic_request_tree, tid); |
| 555 | if (!req) { | 517 | if (!req) { |
| 556 | dout("get_generic_reply %lld dne\n", tid); | 518 | dout("get_generic_reply %lld dne\n", tid); |
| 557 | *skip = 1; | 519 | *skip = 1; |
| @@ -578,14 +540,14 @@ static int __do_generic_request(struct ceph_mon_client *monc, u64 tid, | |||
| 578 | /* register request */ | 540 | /* register request */ |
| 579 | req->tid = tid != 0 ? tid : ++monc->last_tid; | 541 | req->tid = tid != 0 ? tid : ++monc->last_tid; |
| 580 | req->request->hdr.tid = cpu_to_le64(req->tid); | 542 | req->request->hdr.tid = cpu_to_le64(req->tid); |
| 581 | __insert_generic_request(monc, req); | 543 | insert_generic_request(&monc->generic_request_tree, req); |
| 582 | ceph_con_send(&monc->con, ceph_msg_get(req->request)); | 544 | ceph_con_send(&monc->con, ceph_msg_get(req->request)); |
| 583 | mutex_unlock(&monc->mutex); | 545 | mutex_unlock(&monc->mutex); |
| 584 | 546 | ||
| 585 | err = wait_for_completion_interruptible(&req->completion); | 547 | err = wait_for_completion_interruptible(&req->completion); |
| 586 | 548 | ||
| 587 | mutex_lock(&monc->mutex); | 549 | mutex_lock(&monc->mutex); |
| 588 | rb_erase(&req->node, &monc->generic_request_tree); | 550 | erase_generic_request(&monc->generic_request_tree, req); |
| 589 | 551 | ||
| 590 | if (!err) | 552 | if (!err) |
| 591 | err = req->result; | 553 | err = req->result; |
| @@ -619,7 +581,7 @@ static void handle_statfs_reply(struct ceph_mon_client *monc, | |||
| 619 | dout("handle_statfs_reply %p tid %llu\n", msg, tid); | 581 | dout("handle_statfs_reply %p tid %llu\n", msg, tid); |
| 620 | 582 | ||
| 621 | mutex_lock(&monc->mutex); | 583 | mutex_lock(&monc->mutex); |
| 622 | req = __lookup_generic_req(monc, tid); | 584 | req = lookup_generic_request(&monc->generic_request_tree, tid); |
| 623 | if (req) { | 585 | if (req) { |
| 624 | *(struct ceph_statfs *)req->buf = reply->st; | 586 | *(struct ceph_statfs *)req->buf = reply->st; |
| 625 | req->result = 0; | 587 | req->result = 0; |
| @@ -651,6 +613,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf) | |||
| 651 | return -ENOMEM; | 613 | return -ENOMEM; |
| 652 | 614 | ||
| 653 | kref_init(&req->kref); | 615 | kref_init(&req->kref); |
| 616 | RB_CLEAR_NODE(&req->node); | ||
| 654 | req->buf = buf; | 617 | req->buf = buf; |
| 655 | init_completion(&req->completion); | 618 | init_completion(&req->completion); |
| 656 | 619 | ||
| @@ -696,7 +659,7 @@ static void handle_get_version_reply(struct ceph_mon_client *monc, | |||
| 696 | goto bad; | 659 | goto bad; |
| 697 | 660 | ||
| 698 | mutex_lock(&monc->mutex); | 661 | mutex_lock(&monc->mutex); |
| 699 | req = __lookup_generic_req(monc, handle); | 662 | req = lookup_generic_request(&monc->generic_request_tree, handle); |
| 700 | if (req) { | 663 | if (req) { |
| 701 | *(u64 *)req->buf = ceph_decode_64(&p); | 664 | *(u64 *)req->buf = ceph_decode_64(&p); |
| 702 | req->result = 0; | 665 | req->result = 0; |
| @@ -732,6 +695,7 @@ int ceph_monc_do_get_version(struct ceph_mon_client *monc, const char *what, | |||
| 732 | return -ENOMEM; | 695 | return -ENOMEM; |
| 733 | 696 | ||
| 734 | kref_init(&req->kref); | 697 | kref_init(&req->kref); |
| 698 | RB_CLEAR_NODE(&req->node); | ||
| 735 | req->buf = newest; | 699 | req->buf = newest; |
| 736 | init_completion(&req->completion); | 700 | init_completion(&req->completion); |
| 737 | 701 | ||
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c index c423e11d6857..8256051ed88f 100644 --- a/net/ceph/osd_client.c +++ b/net/ceph/osd_client.c | |||
| @@ -875,45 +875,7 @@ EXPORT_SYMBOL(ceph_osdc_new_request); | |||
| 875 | /* | 875 | /* |
| 876 | * We keep osd requests in an rbtree, sorted by ->r_tid. | 876 | * We keep osd requests in an rbtree, sorted by ->r_tid. |
| 877 | */ | 877 | */ |
| 878 | static void __insert_request(struct ceph_osd_client *osdc, | 878 | DEFINE_RB_FUNCS(request, struct ceph_osd_request, r_tid, r_node) |
| 879 | struct ceph_osd_request *new) | ||
| 880 | { | ||
| 881 | struct rb_node **p = &osdc->requests.rb_node; | ||
| 882 | struct rb_node *parent = NULL; | ||
| 883 | struct ceph_osd_request *req = NULL; | ||
| 884 | |||
| 885 | while (*p) { | ||
| 886 | parent = *p; | ||
| 887 | req = rb_entry(parent, struct ceph_osd_request, r_node); | ||
| 888 | if (new->r_tid < req->r_tid) | ||
| 889 | p = &(*p)->rb_left; | ||
| 890 | else if (new->r_tid > req->r_tid) | ||
| 891 | p = &(*p)->rb_right; | ||
| 892 | else | ||
| 893 | BUG(); | ||
| 894 | } | ||
| 895 | |||
| 896 | rb_link_node(&new->r_node, parent, p); | ||
| 897 | rb_insert_color(&new->r_node, &osdc->requests); | ||
| 898 | } | ||
| 899 | |||
| 900 | static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc, | ||
| 901 | u64 tid) | ||
| 902 | { | ||
| 903 | struct ceph_osd_request *req; | ||
| 904 | struct rb_node *n = osdc->requests.rb_node; | ||
| 905 | |||
| 906 | while (n) { | ||
| 907 | req = rb_entry(n, struct ceph_osd_request, r_node); | ||
| 908 | if (tid < req->r_tid) | ||
| 909 | n = n->rb_left; | ||
| 910 | else if (tid > req->r_tid) | ||
| 911 | n = n->rb_right; | ||
| 912 | else | ||
| 913 | return req; | ||
| 914 | } | ||
| 915 | return NULL; | ||
| 916 | } | ||
| 917 | 879 | ||
| 918 | static struct ceph_osd_request * | 880 | static struct ceph_osd_request * |
| 919 | __lookup_request_ge(struct ceph_osd_client *osdc, | 881 | __lookup_request_ge(struct ceph_osd_client *osdc, |
| @@ -1101,6 +1063,8 @@ static void put_osd(struct ceph_osd *osd) | |||
| 1101 | } | 1063 | } |
| 1102 | } | 1064 | } |
| 1103 | 1065 | ||
| 1066 | DEFINE_RB_FUNCS(osd, struct ceph_osd, o_osd, o_node) | ||
| 1067 | |||
| 1104 | /* | 1068 | /* |
| 1105 | * remove an osd from our map | 1069 | * remove an osd from our map |
| 1106 | */ | 1070 | */ |
| @@ -1111,8 +1075,7 @@ static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) | |||
| 1111 | WARN_ON(!list_empty(&osd->o_linger_requests)); | 1075 | WARN_ON(!list_empty(&osd->o_linger_requests)); |
| 1112 | 1076 | ||
| 1113 | list_del_init(&osd->o_osd_lru); | 1077 | list_del_init(&osd->o_osd_lru); |
| 1114 | rb_erase(&osd->o_node, &osdc->osds); | 1078 | erase_osd(&osdc->osds, osd); |
| 1115 | RB_CLEAR_NODE(&osd->o_node); | ||
| 1116 | } | 1079 | } |
| 1117 | 1080 | ||
| 1118 | static void remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) | 1081 | static void remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) |
| @@ -1188,45 +1151,6 @@ static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) | |||
| 1188 | return 0; | 1151 | return 0; |
| 1189 | } | 1152 | } |
| 1190 | 1153 | ||
| 1191 | static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new) | ||
| 1192 | { | ||
| 1193 | struct rb_node **p = &osdc->osds.rb_node; | ||
| 1194 | struct rb_node *parent = NULL; | ||
| 1195 | struct ceph_osd *osd = NULL; | ||
| 1196 | |||
| 1197 | dout("__insert_osd %p osd%d\n", new, new->o_osd); | ||
| 1198 | while (*p) { | ||
| 1199 | parent = *p; | ||
| 1200 | osd = rb_entry(parent, struct ceph_osd, o_node); | ||
| 1201 | if (new->o_osd < osd->o_osd) | ||
| 1202 | p = &(*p)->rb_left; | ||
| 1203 | else if (new->o_osd > osd->o_osd) | ||
| 1204 | p = &(*p)->rb_right; | ||
| 1205 | else | ||
| 1206 | BUG(); | ||
| 1207 | } | ||
| 1208 | |||
| 1209 | rb_link_node(&new->o_node, parent, p); | ||
| 1210 | rb_insert_color(&new->o_node, &osdc->osds); | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o) | ||
| 1214 | { | ||
| 1215 | struct ceph_osd *osd; | ||
| 1216 | struct rb_node *n = osdc->osds.rb_node; | ||
| 1217 | |||
| 1218 | while (n) { | ||
| 1219 | osd = rb_entry(n, struct ceph_osd, o_node); | ||
| 1220 | if (o < osd->o_osd) | ||
| 1221 | n = n->rb_left; | ||
| 1222 | else if (o > osd->o_osd) | ||
| 1223 | n = n->rb_right; | ||
| 1224 | else | ||
| 1225 | return osd; | ||
| 1226 | } | ||
| 1227 | return NULL; | ||
| 1228 | } | ||
| 1229 | |||
| 1230 | static void __schedule_osd_timeout(struct ceph_osd_client *osdc) | 1154 | static void __schedule_osd_timeout(struct ceph_osd_client *osdc) |
| 1231 | { | 1155 | { |
| 1232 | schedule_delayed_work(&osdc->timeout_work, | 1156 | schedule_delayed_work(&osdc->timeout_work, |
| @@ -1248,7 +1172,7 @@ static void __register_request(struct ceph_osd_client *osdc, | |||
| 1248 | req->r_tid = ++osdc->last_tid; | 1172 | req->r_tid = ++osdc->last_tid; |
| 1249 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); | 1173 | req->r_request->hdr.tid = cpu_to_le64(req->r_tid); |
| 1250 | dout("__register_request %p tid %lld\n", req, req->r_tid); | 1174 | dout("__register_request %p tid %lld\n", req, req->r_tid); |
| 1251 | __insert_request(osdc, req); | 1175 | insert_request(&osdc->requests, req); |
| 1252 | ceph_osdc_get_request(req); | 1176 | ceph_osdc_get_request(req); |
| 1253 | osdc->num_requests++; | 1177 | osdc->num_requests++; |
| 1254 | if (osdc->num_requests == 1) { | 1178 | if (osdc->num_requests == 1) { |
| @@ -1270,8 +1194,7 @@ static void __unregister_request(struct ceph_osd_client *osdc, | |||
| 1270 | } | 1194 | } |
| 1271 | 1195 | ||
| 1272 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); | 1196 | dout("__unregister_request %p tid %lld\n", req, req->r_tid); |
| 1273 | rb_erase(&req->r_node, &osdc->requests); | 1197 | erase_request(&osdc->requests, req); |
| 1274 | RB_CLEAR_NODE(&req->r_node); | ||
| 1275 | osdc->num_requests--; | 1198 | osdc->num_requests--; |
| 1276 | 1199 | ||
| 1277 | if (req->r_osd) { | 1200 | if (req->r_osd) { |
| @@ -1482,7 +1405,7 @@ static int __map_request(struct ceph_osd_client *osdc, | |||
| 1482 | req->r_osd = NULL; | 1405 | req->r_osd = NULL; |
| 1483 | } | 1406 | } |
| 1484 | 1407 | ||
| 1485 | req->r_osd = __lookup_osd(osdc, o); | 1408 | req->r_osd = lookup_osd(&osdc->osds, o); |
| 1486 | if (!req->r_osd && o >= 0) { | 1409 | if (!req->r_osd && o >= 0) { |
| 1487 | err = -ENOMEM; | 1410 | err = -ENOMEM; |
| 1488 | req->r_osd = create_osd(osdc, o); | 1411 | req->r_osd = create_osd(osdc, o); |
| @@ -1492,7 +1415,7 @@ static int __map_request(struct ceph_osd_client *osdc, | |||
| 1492 | } | 1415 | } |
| 1493 | 1416 | ||
| 1494 | dout("map_request osd %p is osd%d\n", req->r_osd, o); | 1417 | dout("map_request osd %p is osd%d\n", req->r_osd, o); |
| 1495 | __insert_osd(osdc, req->r_osd); | 1418 | insert_osd(&osdc->osds, req->r_osd); |
| 1496 | 1419 | ||
| 1497 | ceph_con_open(&req->r_osd->o_con, | 1420 | ceph_con_open(&req->r_osd->o_con, |
| 1498 | CEPH_ENTITY_TYPE_OSD, o, | 1421 | CEPH_ENTITY_TYPE_OSD, o, |
| @@ -1822,7 +1745,7 @@ static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg) | |||
| 1822 | /* lookup */ | 1745 | /* lookup */ |
| 1823 | down_read(&osdc->map_sem); | 1746 | down_read(&osdc->map_sem); |
| 1824 | mutex_lock(&osdc->request_mutex); | 1747 | mutex_lock(&osdc->request_mutex); |
| 1825 | req = __lookup_request(osdc, tid); | 1748 | req = lookup_request(&osdc->requests, tid); |
| 1826 | if (req == NULL) { | 1749 | if (req == NULL) { |
| 1827 | dout("handle_reply tid %llu dne\n", tid); | 1750 | dout("handle_reply tid %llu dne\n", tid); |
| 1828 | goto bad_mutex; | 1751 | goto bad_mutex; |
| @@ -2880,7 +2803,7 @@ static struct ceph_msg *get_reply(struct ceph_connection *con, | |||
| 2880 | 2803 | ||
| 2881 | tid = le64_to_cpu(hdr->tid); | 2804 | tid = le64_to_cpu(hdr->tid); |
| 2882 | mutex_lock(&osdc->request_mutex); | 2805 | mutex_lock(&osdc->request_mutex); |
| 2883 | req = __lookup_request(osdc, tid); | 2806 | req = lookup_request(&osdc->requests, tid); |
| 2884 | if (!req) { | 2807 | if (!req) { |
| 2885 | dout("%s osd%d tid %llu unknown, skipping\n", __func__, | 2808 | dout("%s osd%d tid %llu unknown, skipping\n", __func__, |
| 2886 | osd->o_osd, tid); | 2809 | osd->o_osd, tid); |
