@@ -145,6 +145,10 @@ void *xa_clear_tag(struct xarray *, unsigned long index, xa_tag_t);
void *xa_find(struct xarray *xa, unsigned long *index, unsigned long max);
void *xa_next(struct xarray *xa, unsigned long *index, unsigned long max);
+int xa_get_entries(struct xarray *, void **dst, unsigned long start,
+ unsigned long max, unsigned int n);
+int xa_get_tagged(struct xarray *, void **dst, unsigned long start,
+ unsigned long max, unsigned int n, xa_tag_t);
/**
* xa_for_each() - Iterate over a portion of an XArray.
@@ -1243,3 +1243,72 @@ void *xa_next(struct xarray *xa, unsigned long *indexp, unsigned long max)
return entry;
}
EXPORT_SYMBOL(xa_next);
+
+/**
+ * xa_get_entries() - Copy entries from the xarray into a normal array
+ * @xa: The source XArray to copy from
+ * @dst: The buffer to copy pointers into
+ * @start: The first index in the XArray eligible to be copied from
+ * @max: The last index in the XArray eligible to be copied from
+ * @n: The maximum number of entries to copy
+ *
+ * Return: The number of entries copied.
+ */
+int xa_get_entries(struct xarray *xa, void **dst, unsigned long start,
+ unsigned long max, unsigned int n)
+{
+ XA_STATE(xas, start);
+ void *entry;
+ unsigned int i = 0;
+
+ if (!n)
+ return 0;
+
+ rcu_read_lock();
+ xas_for_each(xa, &xas, entry, max) {
+ if (xas_retry(&xas, entry))
+ continue;
+ dst[i++] = entry;
+ if (i == n)
+ break;
+ }
+ rcu_read_unlock();
+
+ return i;
+}
+EXPORT_SYMBOL(xa_get_entries);
+
+/**
+ * xa_get_tagged() - Copy tagged entries from the xarray into a normal array.
+ * @xa: The source XArray to copy from.
+ * @dst: The buffer to copy pointers into.
+ * @start: The first index in the XArray eligible to be copied from.
+ * @max: The last index in the XArray eligible to be copied from
+ * @n: The maximum number of entries to copy.
+ * @tag: Tag number.
+ *
+ * Return: The number of entries copied.
+ */
+int xa_get_tagged(struct xarray *xa, void **dst, unsigned long start,
+ unsigned long max, unsigned int n, xa_tag_t tag)
+{
+ XA_STATE(xas, start);
+ void *entry;
+ unsigned int i = 0;
+
+ if (!n)
+ return 0;
+
+ rcu_read_lock();
+ xas_for_each_tag(xa, &xas, entry, max, tag) {
+ if (xas_retry(&xas, entry))
+ continue;
+ dst[i++] = entry;
+ if (i == n)
+ break;
+ }
+ rcu_read_unlock();
+
+ return i;
+}
+EXPORT_SYMBOL(xa_get_tagged);