]> www.infradead.org Git - users/willy/xarray.git/commitdiff
nvme target: Convert p2p_ns_map to XArray
authorMatthew Wilcox <willy@infradead.org>
Thu, 25 Oct 2018 18:05:37 +0000 (14:05 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 9 Aug 2019 01:38:12 +0000 (21:38 -0400)
Straightforward conversion, no locking changes.

Signed-off-by: Matthew Wilcox <willy@infradead.org>
drivers/nvme/host/nvme.h
drivers/nvme/target/core.c
drivers/nvme/target/nvmet.h

index 26b563f9985b5a9bf4163a18646e9fee68a2ae17..57c597c6ec5989f5eab232e13c70384510fa85ba 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/nvme.h>
 #include <linux/cdev.h>
+#include <linux/idr.h>
 #include <linux/pci.h>
 #include <linux/kref.h>
 #include <linux/blk-mq.h>
index dad0243c7c96cfd5f84d5e996b09dcc5fa78d07b..406e5b301710e6f74f89d8d419c7385d3a7d4462 100644 (file)
@@ -487,7 +487,8 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,
                }
        }
 
-       ret = radix_tree_insert(&ctrl->p2p_ns_map, ns->nsid, p2p_dev);
+       ret = xa_err(xa_store(&ctrl->p2p_ns_map, ns->nsid, p2p_dev,
+                               GFP_KERNEL));
        if (ret < 0)
                pci_dev_put(p2p_dev);
 
@@ -558,7 +559,7 @@ out_unlock:
        return ret;
 out_dev_put:
        list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
-               pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid));
+               pci_dev_put(xa_erase(&ctrl->p2p_ns_map, ns->nsid));
 out_dev_disable:
        nvmet_ns_dev_disable(ns);
        goto out_unlock;
@@ -579,7 +580,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
                subsys->max_nsid = nvmet_max_nsid(subsys);
 
        list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
-               pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid));
+               pci_dev_put(xa_erase(&ctrl->p2p_ns_map, ns->nsid));
 
        mutex_unlock(&subsys->lock);
 
@@ -931,7 +932,7 @@ int nvmet_req_alloc_sgl(struct nvmet_req *req)
 
        if (IS_ENABLED(CONFIG_PCI_P2PDMA)) {
                if (req->sq->ctrl && req->ns)
-                       p2p_dev = radix_tree_lookup(&req->sq->ctrl->p2p_ns_map,
+                       p2p_dev = xa_load(&req->sq->ctrl->p2p_ns_map,
                                                    req->ns->nsid);
 
                req->p2p_dev = NULL;
@@ -1163,16 +1164,13 @@ static void nvmet_setup_p2p_ns_map(struct nvmet_ctrl *ctrl,
                nvmet_p2pmem_ns_add_p2p(ctrl, ns);
 }
 
-/*
- * Note: ctrl->subsys->lock should be held when calling this function
- */
 static void nvmet_release_p2p_ns_map(struct nvmet_ctrl *ctrl)
 {
-       struct radix_tree_iter iter;
-       void __rcu **slot;
+       struct pci_dev *pdev;
+       unsigned long index;
 
-       radix_tree_for_each_slot(slot, &ctrl->p2p_ns_map, &iter, 0)
-               pci_dev_put(radix_tree_deref_slot(slot));
+       xa_for_each(&ctrl->p2p_ns_map, index, pdev)
+               pci_dev_put(pdev);
 
        put_device(ctrl->p2p_client);
 }
@@ -1227,7 +1225,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
 
        INIT_WORK(&ctrl->async_event_work, nvmet_async_event_work);
        INIT_LIST_HEAD(&ctrl->async_events);
-       INIT_RADIX_TREE(&ctrl->p2p_ns_map, GFP_KERNEL);
+       xa_init(&ctrl->p2p_ns_map);
        INIT_WORK(&ctrl->fatal_err_work, nvmet_fatal_error_handler);
 
        memcpy(ctrl->subsysnqn, subsysnqn, NVMF_NQN_SIZE);
index 6ee66c6107391899898f812a4b4347b284d6c333..56a43babed6b510d10e2e2fd5531606c2e8a5ce5 100644 (file)
@@ -18,7 +18,7 @@
 #include <linux/configfs.h>
 #include <linux/rcupdate.h>
 #include <linux/blkdev.h>
-#include <linux/radix-tree.h>
+#include <linux/xarray.h>
 
 #define NVMET_ASYNC_EVENTS             4
 #define NVMET_ERROR_LOG_SLOTS          128
@@ -195,7 +195,7 @@ struct nvmet_ctrl {
        char                    hostnqn[NVMF_NQN_FIELD_LEN];
 
        struct device           *p2p_client;
-       struct radix_tree_root  p2p_ns_map;
+       struct xarray           p2p_ns_map;
 
        spinlock_t              error_lock;
        u64                     err_counter;