[PATCH V3 01/10] xarray: add __xa_load() version
Chaitanya Kulkarni
chaitanya.kulkarni at wdc.com
Tue Jul 14 19:30:48 EDT 2020
This patch adds a new xarray API __xa_load() that moves xa_load() core
to its low level function __xa_load(). Caller is responsible for handling
RCU locking. This API is needed for NVMe subsystem so that it can take
an advantage of the RCU locking provided by the XAarray for reference
counting.
This is a preparation patch for replacing linked list with XArray for
NVMe host and core subsystem.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
---
include/linux/xarray.h | 1 +
lib/xarray.c | 26 ++++++++++++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index b4d70e7568b2..ea63005779ab 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -344,6 +344,7 @@ struct xarray {
*/
#define DEFINE_XARRAY_ALLOC1(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC1)
+void *__xa_load(struct xarray *xa, unsigned long index);
void *xa_load(struct xarray *, unsigned long index);
void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
void *xa_erase(struct xarray *, unsigned long index);
diff --git a/lib/xarray.c b/lib/xarray.c
index e9e641d3c0c3..cb9188e74505 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -1288,24 +1288,42 @@ void *xas_find_conflict(struct xa_state *xas)
EXPORT_SYMBOL_GPL(xas_find_conflict);
/**
- * xa_load() - Load an entry from an XArray.
+ * __xa_load() - core load API without rcu read locking.
* @xa: XArray.
* @index: index into array.
*
- * Context: Any context. Takes and releases the RCU lock.
+ * Context: Any context. Caller is responsible for the RCU lock/unlock.
* Return: The entry at @index in @xa.
*/
-void *xa_load(struct xarray *xa, unsigned long index)
+void *__xa_load(struct xarray *xa, unsigned long index)
{
XA_STATE(xas, xa, index);
void *entry;
- rcu_read_lock();
do {
entry = xas_load(&xas);
if (xa_is_zero(entry))
entry = NULL;
} while (xas_retry(&xas, entry));
+
+ return entry;
+}
+EXPORT_SYMBOL_GPL(__xa_load);
+
+/**
+ * xa_load() - Load an entry from an XArray.
+ * @xa: XArray.
+ * @index: index into array.
+ *
+ * Context: Any context. Takes and releases the RCU lock.
+ * Return: The entry at @index in @xa.
+ */
+void *xa_load(struct xarray *xa, unsigned long index)
+{
+ void *entry;
+
+ rcu_read_lock();
+ entry = __xa_load(xa, index);
rcu_read_unlock();
return entry;
--
2.26.0
More information about the Linux-nvme
mailing list