11
11
12
12
#include <linux/bug.h>
13
13
#include <linux/compiler.h>
14
+ #include <linux/gfp.h>
14
15
#include <linux/kconfig.h>
15
16
#include <linux/kernel.h>
16
17
#include <linux/rcupdate.h>
@@ -197,6 +198,20 @@ static inline int xa_err(void *entry)
197
198
return 0 ;
198
199
}
199
200
201
+ typedef unsigned __bitwise xa_mark_t ;
202
+ #define XA_MARK_0 ((__force xa_mark_t)0U)
203
+ #define XA_MARK_1 ((__force xa_mark_t)1U)
204
+ #define XA_MARK_2 ((__force xa_mark_t)2U)
205
+ #define XA_PRESENT ((__force xa_mark_t)8U)
206
+ #define XA_MARK_MAX XA_MARK_2
207
+
208
+ /*
209
+ * Values for xa_flags. The radix tree stores its GFP flags in the xa_flags,
210
+ * and we remain compatible with that.
211
+ */
212
+ #define XA_FLAGS_MARK (mark ) ((__force gfp_t)((1U << __GFP_BITS_SHIFT) << \
213
+ (__force unsigned)(mark)))
214
+
200
215
/**
201
216
* struct xarray - The anchor of the XArray.
202
217
* @xa_lock: Lock that protects the contents of the XArray.
@@ -252,6 +267,9 @@ struct xarray {
252
267
253
268
void xa_init_flags (struct xarray * , gfp_t flags );
254
269
void * xa_load (struct xarray * , unsigned long index );
270
+ bool xa_get_mark (struct xarray * , unsigned long index , xa_mark_t );
271
+ void xa_set_mark (struct xarray * , unsigned long index , xa_mark_t );
272
+ void xa_clear_mark (struct xarray * , unsigned long index , xa_mark_t );
255
273
256
274
/**
257
275
* xa_init() - Initialise an empty XArray.
@@ -278,6 +296,19 @@ static inline bool xa_empty(const struct xarray *xa)
278
296
return xa -> xa_head == NULL ;
279
297
}
280
298
299
+ /**
300
+ * xa_marked() - Inquire whether any entry in this array has a mark set
301
+ * @xa: Array
302
+ * @mark: Mark value
303
+ *
304
+ * Context: Any context.
305
+ * Return: %true if any entry has this mark set.
306
+ */
307
+ static inline bool xa_marked (const struct xarray * xa , xa_mark_t mark )
308
+ {
309
+ return xa -> xa_flags & XA_FLAGS_MARK (mark );
310
+ }
311
+
281
312
#define xa_trylock (xa ) spin_trylock(&(xa)->xa_lock)
282
313
#define xa_lock (xa ) spin_lock(&(xa)->xa_lock)
283
314
#define xa_unlock (xa ) spin_unlock(&(xa)->xa_lock)
@@ -290,6 +321,12 @@ static inline bool xa_empty(const struct xarray *xa)
290
321
#define xa_unlock_irqrestore (xa , flags ) \
291
322
spin_unlock_irqrestore(&(xa)->xa_lock, flags)
292
323
324
+ /*
325
+ * Versions of the normal API which require the caller to hold the xa_lock.
326
+ */
327
+ void __xa_set_mark (struct xarray * , unsigned long index , xa_mark_t );
328
+ void __xa_clear_mark (struct xarray * , unsigned long index , xa_mark_t );
329
+
293
330
/* Everything below here is the Advanced API. Proceed with caution. */
294
331
295
332
/*
@@ -388,6 +425,22 @@ static inline void *xa_entry_locked(const struct xarray *xa,
388
425
lockdep_is_held (& xa -> xa_lock ));
389
426
}
390
427
428
+ /* Private */
429
+ static inline struct xa_node * xa_parent (const struct xarray * xa ,
430
+ const struct xa_node * node )
431
+ {
432
+ return rcu_dereference_check (node -> parent ,
433
+ lockdep_is_held (& xa -> xa_lock ));
434
+ }
435
+
436
+ /* Private */
437
+ static inline struct xa_node * xa_parent_locked (const struct xarray * xa ,
438
+ const struct xa_node * node )
439
+ {
440
+ return rcu_dereference_protected (node -> parent ,
441
+ lockdep_is_held (& xa -> xa_lock ));
442
+ }
443
+
391
444
/* Private */
392
445
static inline struct xa_node * xa_to_node (const void * entry )
393
446
{
@@ -588,6 +641,12 @@ static inline bool xas_valid(const struct xa_state *xas)
588
641
return !xas_invalid (xas );
589
642
}
590
643
644
+ /* True if the pointer is something other than a node */
645
+ static inline bool xas_not_node (struct xa_node * node )
646
+ {
647
+ return ((unsigned long )node & 3 ) || !node ;
648
+ }
649
+
591
650
/**
592
651
* xas_reset() - Reset an XArray operation state.
593
652
* @xas: XArray operation state.
@@ -625,6 +684,10 @@ static inline bool xas_retry(struct xa_state *xas, const void *entry)
625
684
626
685
void * xas_load (struct xa_state * );
627
686
687
+ bool xas_get_mark (const struct xa_state * , xa_mark_t );
688
+ void xas_set_mark (const struct xa_state * , xa_mark_t );
689
+ void xas_clear_mark (const struct xa_state * , xa_mark_t );
690
+
628
691
/**
629
692
* xas_reload() - Refetch an entry from the xarray.
630
693
* @xas: XArray operation state.
0 commit comments