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 /fs/ceph/mds_client.c | |
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>
Diffstat (limited to 'fs/ceph/mds_client.c')
-rw-r--r-- | fs/ceph/mds_client.c | 54 |
1 files changed, 13 insertions, 41 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? */ |