From 7803d21b36b0545c35f7f65b703a0790c04444fe Mon Sep 17 00:00:00 2001 From: Matthew Wilcox Date: Mon, 18 Feb 2019 08:38:17 -0500 Subject: [PATCH] ocfs2: Convert nn_status_idr to XArray Signed-off-by: Matthew Wilcox --- fs/ocfs2/cluster/tcp.c | 47 +++++++++++---------------------- fs/ocfs2/cluster/tcp_internal.h | 4 +-- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c index 48a3398f0bf5..375154386ffa 100644 --- a/fs/ocfs2/cluster/tcp.c +++ b/fs/ocfs2/cluster/tcp.c @@ -43,7 +43,7 @@ #include #include #include -#include +#include #include #include #include @@ -293,13 +293,8 @@ static int o2net_prep_nsw(struct o2net_node *nn, struct o2net_status_wait *nsw) { int ret; - spin_lock(&nn->nn_lock); - ret = idr_alloc(&nn->nn_status_idr, nsw, 0, 0, GFP_ATOMIC); - if (ret >= 0) { - nsw->ns_id = ret; - list_add_tail(&nsw->ns_node_item, &nn->nn_status_list); - } - spin_unlock(&nn->nn_lock); + ret = xa_alloc(&nn->nn_statuses, &nsw->ns_id, nsw, xa_limit_31b, + GFP_ATOMIC); if (ret < 0) return ret; @@ -316,11 +311,11 @@ static void o2net_complete_nsw_locked(struct o2net_node *nn, { assert_spin_locked(&nn->nn_lock); - if (!list_empty(&nsw->ns_node_item)) { - list_del_init(&nsw->ns_node_item); + if (nsw->ns_id != -1) { nsw->ns_sys_status = sys_status; nsw->ns_status = status; - idr_remove(&nn->nn_status_idr, nsw->ns_id); + xa_erase(&nn->nn_statuses, nsw->ns_id); + nsw->ns_id = -1; wake_up(&nsw->ns_wq); } } @@ -331,30 +326,23 @@ static void o2net_complete_nsw(struct o2net_node *nn, s32 status) { spin_lock(&nn->nn_lock); - if (nsw == NULL) { - if (id > INT_MAX) - goto out; - - nsw = idr_find(&nn->nn_status_idr, id); - if (nsw == NULL) - goto out; - } - - o2net_complete_nsw_locked(nn, nsw, sys_status, status); - -out: + if (nsw == NULL) + nsw = xa_load(&nn->nn_statuses, id); + if (nsw != NULL) + o2net_complete_nsw_locked(nn, nsw, sys_status, status); spin_unlock(&nn->nn_lock); return; } static void o2net_complete_nodes_nsw(struct o2net_node *nn) { - struct o2net_status_wait *nsw, *tmp; + struct o2net_status_wait *nsw; + unsigned long index; unsigned int num_kills = 0; assert_spin_locked(&nn->nn_lock); - list_for_each_entry_safe(nsw, tmp, &nn->nn_status_list, ns_node_item) { + xa_for_each(&nn->nn_statuses, index, nsw) { o2net_complete_nsw_locked(nn, nsw, O2NET_ERR_DIED, 0); num_kills++; } @@ -368,7 +356,7 @@ static int o2net_nsw_completed(struct o2net_node *nn, { int completed; spin_lock(&nn->nn_lock); - completed = list_empty(&nsw->ns_node_item); + completed = (nsw->ns_id == -1); spin_unlock(&nn->nn_lock); return completed; } @@ -1020,9 +1008,7 @@ int o2net_send_message_vec(u32 msg_type, u32 key, struct kvec *caller_vec, struct kvec *vec = NULL; struct o2net_sock_container *sc = NULL; struct o2net_node *nn = o2net_nn_from_num(target_node); - struct o2net_status_wait nsw = { - .ns_node_item = LIST_HEAD_INIT(nsw.ns_node_item), - }; + struct o2net_status_wait nsw = { }; struct o2net_send_tracking nst; o2net_init_nst(&nst, msg_type, key, current, target_node); @@ -2155,8 +2141,7 @@ int o2net_init(void) /* until we see hb from a node we'll return einval */ nn->nn_persistent_error = -ENOTCONN; init_waitqueue_head(&nn->nn_sc_wq); - idr_init(&nn->nn_status_idr); - INIT_LIST_HEAD(&nn->nn_status_list); + xa_init_flags(&nn->nn_statuses, XA_FLAGS_ALLOC); } return 0; diff --git a/fs/ocfs2/cluster/tcp_internal.h b/fs/ocfs2/cluster/tcp_internal.h index e6a2b9dfcd16..4bf37310900e 100644 --- a/fs/ocfs2/cluster/tcp_internal.h +++ b/fs/ocfs2/cluster/tcp_internal.h @@ -89,8 +89,7 @@ struct o2net_node { * or fails or when an accepted socket is attached. */ wait_queue_head_t nn_sc_wq; - struct idr nn_status_idr; - struct list_head nn_status_list; + struct xarray nn_statuses; /* connects are attempted from when heartbeat comes up until either hb * goes down, the node is unconfigured, or a connect succeeds. @@ -202,7 +201,6 @@ struct o2net_status_wait { s32 ns_status; int ns_id; wait_queue_head_t ns_wq; - struct list_head ns_node_item; }; #ifdef CONFIG_DEBUG_FS -- 2.50.1