[PATCH 25/62] xarray: Add xa_init

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx>

For initialising xarrays in code rather than data.

Signed-off-by: Matthew Wilcox <mawilcox@xxxxxxxxxxxxx>
---
 include/linux/xarray.h | 13 +++++++++++++
 lib/xarray.c           | 15 +++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/include/linux/xarray.h b/include/linux/xarray.h
index 08ddad60a43d..19a3974fdc4f 100644
--- a/include/linux/xarray.h
+++ b/include/linux/xarray.h
@@ -81,6 +81,19 @@ struct xarray {
 
 #define DEFINE_XARRAY(name) struct xarray name = XARRAY_INIT(name)
 
+void __xa_init(struct xarray *, gfp_t flags);
+
+/**
+ * xa_init() - Initialise an empty XArray.
+ * @xa: XArray.
+ *
+ * An empty XArray is full of NULL entries.
+ */
+static inline void xa_init(struct xarray *xa)
+{
+	__xa_init(xa, 0);
+}
+
 void *xa_load(struct xarray *, unsigned long index);
 void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
 void *xa_cmpxchg(struct xarray *, unsigned long index,
diff --git a/lib/xarray.c b/lib/xarray.c
index 5409048e8b44..59f45c07988f 100644
--- a/lib/xarray.c
+++ b/lib/xarray.c
@@ -868,6 +868,21 @@ void *xas_find(struct xarray *xa, struct xa_state *xas, unsigned long max)
 }
 EXPORT_SYMBOL_GPL(xas_find);
 
+/**
+ * __xa_init() - Initialise an empty XArray
+ * @xa: XArray.
+ * @flags: XA_FLAG_ values
+ *
+ * An empty XArray is full of NULL pointers.
+ */
+void __xa_init(struct xarray *xa, gfp_t flags)
+{
+	spin_lock_init(&xa->xa_lock);
+	xa->xa_flags = flags;
+	xa->xa_head = NULL;
+}
+EXPORT_SYMBOL(__xa_init);
+
 /**
  * xa_load() - Load an entry from an XArray.
  * @xa: XArray.
-- 
2.15.0




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux