~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/btrfs/ulist.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /*
  3  * Copyright (C) 2011 STRATO AG
  4  * written by Arne Jansen <sensille@gmx.net>
  5  */
  6 
  7 #ifndef BTRFS_ULIST_H
  8 #define BTRFS_ULIST_H
  9 
 10 #include <linux/types.h>
 11 #include <linux/list.h>
 12 #include <linux/rbtree.h>
 13 
 14 /*
 15  * ulist is a generic data structure to hold a collection of unique u64
 16  * values. The only operations it supports is adding to the list and
 17  * enumerating it.
 18  * It is possible to store an auxiliary value along with the key.
 19  *
 20  */
 21 struct ulist_iterator {
 22         struct list_head *cur_list;  /* hint to start search */
 23 };
 24 
 25 /*
 26  * element of the list
 27  */
 28 struct ulist_node {
 29         u64 val;                /* value to store */
 30         u64 aux;                /* auxiliary value saved along with the val */
 31 
 32         struct list_head list;  /* used to link node */
 33         struct rb_node rb_node; /* used to speed up search */
 34 };
 35 
 36 struct ulist {
 37         /*
 38          * number of elements stored in list
 39          */
 40         unsigned long nnodes;
 41 
 42         struct list_head nodes;
 43         struct rb_root root;
 44         struct ulist_node *prealloc;
 45 };
 46 
 47 void ulist_init(struct ulist *ulist);
 48 void ulist_release(struct ulist *ulist);
 49 void ulist_reinit(struct ulist *ulist);
 50 struct ulist *ulist_alloc(gfp_t gfp_mask);
 51 void ulist_prealloc(struct ulist *ulist, gfp_t mask);
 52 void ulist_free(struct ulist *ulist);
 53 int ulist_add(struct ulist *ulist, u64 val, u64 aux, gfp_t gfp_mask);
 54 int ulist_add_merge(struct ulist *ulist, u64 val, u64 aux,
 55                     u64 *old_aux, gfp_t gfp_mask);
 56 int ulist_del(struct ulist *ulist, u64 val, u64 aux);
 57 
 58 /* just like ulist_add_merge() but take a pointer for the aux data */
 59 static inline int ulist_add_merge_ptr(struct ulist *ulist, u64 val, void *aux,
 60                                       void **old_aux, gfp_t gfp_mask)
 61 {
 62 #if BITS_PER_LONG == 32
 63         u64 old64 = (uintptr_t)*old_aux;
 64         int ret = ulist_add_merge(ulist, val, (uintptr_t)aux, &old64, gfp_mask);
 65         *old_aux = (void *)((uintptr_t)old64);
 66         return ret;
 67 #else
 68         return ulist_add_merge(ulist, val, (u64)aux, (u64 *)old_aux, gfp_mask);
 69 #endif
 70 }
 71 
 72 struct ulist_node *ulist_next(const struct ulist *ulist,
 73                               struct ulist_iterator *uiter);
 74 
 75 #define ULIST_ITER_INIT(uiter) ((uiter)->cur_list = NULL)
 76 
 77 #endif
 78 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php