]> www.infradead.org Git - users/willy/xarray.git/commitdiff
ocfs2: Convert nn_status_idr to XArray
authorMatthew Wilcox <willy@infradead.org>
Mon, 18 Feb 2019 13:38:17 +0000 (08:38 -0500)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 8 Aug 2019 14:29:41 +0000 (10:29 -0400)
Signed-off-by: Matthew Wilcox <willy@infradead.org>
fs/ocfs2/cluster/tcp.c
fs/ocfs2/cluster/tcp_internal.h

index 48a3398f0bf546d0d8cedc8c11e76abc595d6715..375154386ffa90dd2863469d36843c233481598a 100644 (file)
@@ -43,7 +43,7 @@
 #include <linux/sched/mm.h>
 #include <linux/jiffies.h>
 #include <linux/slab.h>
-#include <linux/idr.h>
+#include <linux/xarray.h>
 #include <linux/kref.h>
 #include <linux/net.h>
 #include <linux/export.h>
@@ -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;
index e6a2b9dfcd16ab07e0aa5ad215bbdc0b86e80e55..4bf37310900e2e5fb4bdd1eea5df60a486226a73 100644 (file)
@@ -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