linux/fs/dcookies.c
<<
12" /spapti /formti a 12" href="../linux+v v.3/fs/dcookies.c">12" img src="../.static/gfx/right.png" alt=">>">12 /spapti12 spap class="lxr_search">12" 12" input typaluhidden" namalunavtarget" on valu">12" input typalutext" namalusearch" idlusearch">12" buttopitypalusubmit">Search12" Prefsi /a>12 /spapti" /divti" form ac12 input typaluhidden" namaluajax_lookup" idluajax_lookup" on valu">1" /formti1" div class="headingbottom">i div idlufile_contents"t
   1 /a> spap class="comment">/* /spapti   2 /a> spap class="comment"> * dcookies.c /spapti   3 /a> spap class="comment"> * /spapti   4 /a> spap class="comment"> * Copyright 2002 John Levopi<levop@movementarian.org> /spapti   5 /a> spap class="comment"> * /spapti   6 /a> spap class="comment"> * Persistent cookie-path mappings. These are used by /spapti   7 /a> spap class="comment"> * profilers to convert a per-task EIP on va into something /spapti   8 /a> spap class="comment"> * non-transitory that cap be processed at a later date. /spapti   9 /a> spap class="comment"> * This is done by locking the dentry/vfsmnt pair in the /spapti  3.8.a> spap class="comment"> * kernel until released by the tasks needing the persistent /spapti  11 /a> spap class="comment"> * objects. The tag is simply ap unsigned long that refers /spapti  12 /a> spap class="comment"> * to the pair and cap be looked up from userspace. /spapti  13 /a> spap class="comment"> */ /spapti  14 /a>i  15 /a>#includei<linux/syscalls.h /a>>i  16 /a>#includei<linux/export.h /a>>i  17 /a>#includei<linux/slab.h /a>>i  18 /a>#includei<linux/list.h /a>>i  19 /a>#includei<linux/mount.h /a>>i  20 /a>#includei<linux/capability.h /a>>i  21 /a>#includei<linux/dcache.h /a>>i  22 /a>#includei<linux/mm.h /a>>i  23 /a>#includei<linux/err.h /a>>i  24 /a>#includei<linux/errno.h /a>>i  25 /a>#includei<linux/dcookies.h /a>>i  26 /a>#includei<linux/mutex.h /a>>i  27 /a>#includei<linux/path.h /a>>i  28 /a>#includei<linux/compat.h /a>>i  29 /a>#includei<asm/uaccess.h /a>>i  30 /a>i  31 /a> spap class="comment">/* The dcookies are allocated from a kmem_cache and /spapti  32 /a> spap class="comment"> * hashed onto a small number of lists. None of the /spapti  33 /a> spap class="comment"> * codeihere is particularly performance critical /spapti  34 /a> spap class="comment"> */ /spapti  35 /a>struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> {i  36 /a>        struct  a href="+code=path" class="sref">path /a>  a href="+code=path" class="sref">path /a>;i  37 /a>        struct  a href="+code=list_head" class="sref">list_head /a>  a href="+code=hash_list" class="sref">hash_list /a>;i  38 /a>};i  39 /a>i  40 /a>static  a href="+code=LIST_HEAD" class="sref">LIST_HEAD /a>( a href="+code=dcookie_users" class="sref">dcookie_users /a>);i  41 /a>static  a href="+code=DEFINE_MUTEX" class="sref">DEFINE_MUTEX /a>( a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i  42 /a>static struct  a href="+code=kmem_cache" class="sref">kmem_cache /a> * a href="+code=dcookie_cache" class="sref">dcookie_cache /a>  a href="+code=__read_mostly" class="sref">__read_mostly /a>;i  43 /a>static struct  a href="+code=list_head" class="sref">list_head /a> * a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a>  a href="+code=__read_mostly" class="sref">__read_mostly /a>;i  44 /a>static  a href="+code=size_t" class="sref">size_t /a>  a href="+code=hash_size" class="sref">hash_size /a>  a href="+code=__read_mostly" class="sref">__read_mostly /a>;i  45 /a>i  46 /a>static  a href="+code=inline" class="sref">inline /a> int  a href="+code=is_live" class="sref">is_live /a>(void)i  47 /a>{i  48 /a>        return !( a href="+code=list_empty" class="sref">list_empty /a>(& a href="+code=dcookie_users" class="sref">dcookie_users /a>));i  49 /a>}i  50 /a>i  51 /a>i  52 /a> spap class="comment">/* The dentry is locked, its address will do for the cookie */ /spapti  53 /a>static  a href="+code=inline" class="sref">inline /a> unsigned long  a href="+code=dcookie_on va" class="sref">dcookie_on va /a>(struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>)i  54 /a>{i  55 /a>        return (unsigned long) a href="+code=dcs" class="sref">dcs /a>-> a href="+code=path" class="sref">path /a>. a href="+code=dentry" class="sref">dentry /a>;i  56 /a>}i  57 /a>i  58 /a>i  59 /a>static  a href="+code=size_t" class="sref">size_t /a>  a href="+code=dcookie_hash" class="sref">dcookie_hash /a>(unsigned long  a href="+code=dcookie" class="sref">dcookie /a>)i  60 /a>{i  61 /a>        return ( a href="+code=dcookie" class="sref">dcookie /a> >>  a href="+code=L1_CACHE_SHIFT" class="sref">L1_CACHE_SHIFT /a>) & ( a href="+code=hash_size" class="sref">hash_size /a> - 1);i  62 /a>}i  63 /a>i  64 /a>i  65 /a>static struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=find_dcookie" class="sref">find_dcookie /a>(unsigned long  a href="+code=dcookie" class="sref">dcookie /a>)i  66 /a>{i  67 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> * a href="+code=found" class="sref">found /a> =  a href="+code=NULL" class="sref">NULL /a>;i  68 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>;i  69 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=pos" class="sref">pos /a>;i  70 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=list" class="sref">list /a>;i  71 /a>i  72 /a>         a href="+code=list" class="sref">list /a> =  a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a> +  a href="+code=dcookie_hash" class="sref">dcookie_hash /a>( a href="+code=dcookie" class="sref">dcookie /a>);i  73 /a>i  74 /a>         a href="+code=list_for_each" class="sref">list_for_each /a>( a href="+code=pos" class="sref">pos /a>,  a href="+code=list" class="sref">list /a>) {i  75 /a>                 a href="+code=dcs" class="sref">dcs /a> =  a href="+code=list_entry" class="sref">list_entry /a>( a href="+code=pos" class="sref">pos /a>, struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a>,  a href="+code=hash_list" class="sref">hash_list /a>);i  76 /a>                if ( a href="+code=dcookie_on va" class="sref">dcookie_on va /a>( a href="+code=dcs" class="sref">dcs /a>) ==  a href="+code=dcookie" class="sref">dcookie /a>) {i  77 /a>                         a href="+code=found" class="sref">found /a> =  a href="+code=dcs" class="sref">dcs /a>;i  78 /a>                        break;i  79 /a>                }i  80 /a>        }i  81 /a>i  82 /a>        return  a href="+code=found" class="sref">found /a>;i  83 /a>}i  84 /a>i  85 /a>i  86 /a>static void  a href="+code=hash_dcookie" class="sref">hash_dcookie /a>(struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>)i  87 /a>{i  88 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=list" class="sref">list /a> =  a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a> +  a href="+code=dcookie_hash" class="sref">dcookie_hash /a>( a href="+code=dcookie_on va" class="sref">dcookie_on va /a>( a href="+code=dcs" class="sref">dcs /a>));i  89 /a>         a href="+code=list_add" class="sref">list_add /a>(& a href="+code=dcs" class="sref">dcs /a>-> a href="+code=hash_list" class="sref">hash_list /a>,  a href="+code=list" class="sref">list /a>);i  90 /a>}i  91 /a>i  92 /a>i  93 /a>static struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> * a href="+code=alloc_dcookie" class="sref">alloc_dcookie /a>(struct  a href="+code=path" class="sref">path /a> * a href="+code=path" class="sref">path /a>)i  94 /a>{i  95 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> * a href="+code=dcs" class="sref">dcs /a> =  a href="+code=kmem_cache_alloc" class="sref">kmem_cache_alloc /a>( a href="+code=dcookie_cache" class="sref">dcookie_cache /a>,i  96 /a>                                                         a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);i  97 /a>        struct  a href="+code=dentry" class="sref">dentry /a> * a href="+code=d" class="sref">d /a>;i  98 /a>        if (! a href="+code=dcs" class="sref">dcs /a>)i  99 /a>                return  a href="+code=NULL" class="sref">NULL /a>;i 100 /a>i 101 /a>         a href="+code=d" class="sref">d /a> =  a href="+code=path" class="sref">path /a>-> a href="+code=dentry" class="sref">dentry /a>;i 102 /a>         a href="+code=spin_lock" class="sref">spin_lock /a>(& a href="+code=d" class="sref">d /a>-> a href="+code=d_lock" class="sref">d_lock /a>);i 103 /a>         a href="+code=d" class="sref">d /a>-> a href="+code=d_flags" class="sref">d_flags /a> |=  a href="+code=DCACHE_COOKIE" class="sref">DCACHE_COOKIE /a>;i 104 /a>         a href="+code=spin_unlock" class="sref">spin_unlock /a>(& a href="+code=d" class="sref">d /a>-> a href="+code=d_lock" class="sref">d_lock /a>);i 105 /a>i 106 /a>         a href="+code=dcs" class="sref">dcs /a>-> a href="+code=path" class="sref">path /a> = * a href="+code=path" class="sref">path /a>;i 107 /a>         a href="+code=path_get" class="sref">path_get /a>( a href="+code=path" class="sref">path /a>);i 108 /a>         a href="+code=hash_dcookie" class="sref">hash_dcookie /a>( a href="+code=dcs" class="sref">dcs /a>);i 109 /a>        return  a href="+code=dcs" class="sref">dcs /a>;i 110 /a>}i 111 /a>i 112 /a>i 113 /a> spap class="comment">/* This is the main kernel-side routine that retrieves the cookie /spapti 114 /a> spap class="comment"> * on va for a dentry/vfsmnt pair. /spapti 115 /a> spap class="comment"> */ /spapti 116 /a>int  a href="+code=get_dcookie" class="sref">get_dcookie /a>(struct  a href="+code=path" class="sref">path /a> * a href="+code=path" class="sref">path /a>, unsigned long * a href="+code=cookie" class="sref">cookie /a>)i 117 /a>{i 118 /a>        int  a href="+code=err" class="sref">err /a> = 0;i 119 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>;i 120 /a>i 121 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 122 /a>i 123 /a>        if (! a href="+code=is_live" class="sref">is_live /a>()) {i 124 /a>                 a href="+code=err" class="sref">err /a> = - a href="+code=EINVAL" class="sref">EINVAL /a>;i 125 /a>                goto  a href="+code=out" class="sref">out /a>;i 126 /a>        }i 127 /a>i 128 /a>        if ( a href="+code=path" class="sref">path /a>-> a href="+code=dentry" class="sref">dentry /a>-> a href="+code=d_flags" class="sref">d_flags /a> &  a href="+code=DCACHE_COOKIE" class="sref">DCACHE_COOKIE /a>) {i 129 /a>                 a href="+code=dcs" class="sref">dcs /a> =  a href="+code=find_dcookie" class="sref">find_dcookie /a>((unsigned long) a href="+code=path" class="sref">path /a>-> a href="+code=dentry" class="sref">dentry /a>);i 130 /a>        } else {i 131 /a>                 a href="+code=dcs" class="sref">dcs /a> =  a href="+code=alloc_dcookie" class="sref">alloc_dcookie /a>( a href="+code=path" class="sref">path /a>);i 132 /a>                if (! a href="+code=dcs" class="sref">dcs /a>) {i 133 /a>                         a href="+code=err" class="sref">err /a> = - a href="+code=ENOMEM" class="sref">ENOMEM /a>;i 134 /a>                        goto  a href="+code=out" class="sref">out /a>;i 135 /a>                }i 136 /a>        }i 137 /a>i 138 /a>        * a href="+code=cookie" class="sref">cookie /a> =  a href="+code=dcookie_on va" class="sref">dcookie_on va /a>( a href="+code=dcs" class="sref">dcs /a>);i 139 /a>i 140 /a> a href="+code=out" class="sref">out /a>:i 141 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 142 /a>        return  a href="+code=err" class="sref">err /a>;i 143 /a>}i 144 /a>i 145 /a>i 146 /a> spap class="comment">/* Andihere is where the userspace process cap look up the cookie on va /spapti 147 /a> spap class="comment"> * to retrieve the path. /spapti 148 /a> spap class="comment"> */ /spapti 149 /a> a href="+code=SYSCALL_DEFINE3" class="sref">SYSCALL_DEFINE3 /a>( a href="+code=lookup_dcookie" class="sref">lookup_dcookie /a>,  a href="+code=u64" class="sref">u64 /a>,  a href="+code=cookie64" class="sref">cookie64 /a>, char  a href="+code=__user" class="sref">__user /a> *,  a href="+code=buf" class="sref">buf /a>,  a href="+code=size_t" class="sref">size_t /a>,  a href="+code=len" class="sref">len /a>)i 150 /a>{i 151 /a>        unsigned long  a href="+code=cookie" class="sref">cookie /a> = (unsigned long) a href="+code=cookie64" class="sref">cookie64 /a>;i 152 /a>        int  a href="+code=err" class="sref">err /a> = - a href="+code=EINVAL" class="sref">EINVAL /a>;i 153 /a>        char *  a href="+code=kbuf" class="sref">kbuf /a>;i 154 /a>        char *  a href="+code=path" class="sref">path /a>;i 155 /a>         a href="+code=size_t" class="sref">size_t /a>  a href="+code=pathlen" class="sref">pathlen /a>;i 156 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>;i 157 /a>i 158 /a>         spap class="comment">/* we could leak path informa22opito users /spapti 159 /a> spap class="comment">         * without dir read permiss2opiwithout this /spapti 16.8.a> spap class="comment">         */ /spapti 161 /a>        if (! a href="+code=capable" class="sref">capable /a>( a href="+code=CAP_SYS_ADMIN" class="sref">CAP_SYS_ADMIN /a>))i 162 /a>                return - a href="+code=EPERM" class="sref">EPERM /a>;i 163 /a>i 164 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 165 /a>i 166 /a>        if (! a href="+code=is_live" class="sref">is_live /a>()) {i 167 /a>                 a href="+code=err" class="sref">err /a> = - a href="+code=EINVAL" class="sref">EINVAL /a>;i 168 /a>                goto  a href="+code=out" class="sref">out /a>;i 169 /a>        }i 170 /a>i 171 /a>        if (!( a href="+code=dcs" class="sref">dcs /a> =  a href="+code=find_dcookie" class="sref">find_dcookie /a>( a href="+code=cookie" class="sref">cookie /a>)))i 172 /a>                goto  a href="+code=out" class="sref">out /a>;i 173 /a>i 174 /a>         a href="+code=err" class="sref">err /a> = - a href="+code=ENOMEM" class="sref">ENOMEM /a>;i 175 /a>         a href="+code=kbuf" class="sref">kbuf /a> =  a href="+code=kmalloc" class="sref">kmalloc /a>( a href="+code=PAGE_SIZE" class="sref">PAGE_SIZE /a>,  a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);i 176 /a>        if (! a href="+code=kbuf" class="sref">kbuf /a>)i 177 /a>                goto  a href="+code=out" class="sref">out /a>;i 178 /a>i 179 /a>         spap class="comment">/* FIXME: (deleted) ? */ /spapti 180 /a>         a href="+code=path" class="sref">path /a> =  a href="+code=d_path" class="sref">d_path /a>(& a href="+code=dcs" class="sref">dcs /a>-> a href="+code=path" class="sref">path /a>,  a href="+code=kbuf" class="sref">kbuf /a>,  a href="+code=PAGE_SIZE" class="sref">PAGE_SIZE /a>);i 181 /a>i 182 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 183 /a>i 184 /a>        if ( a href="+code=IS_ERR" class="sref">IS_ERR /a>( a href="+code=path" class="sref">path /a>)) {i 185 /a>                 a href="+code=err" class="sref">err /a> =  a href="+code=PTR_ERR" class="sref">PTR_ERR /a>( a href="+code=path" class="sref">path /a>);i 186 /a>                goto  a href="+code=out_free" class="sref">out_free /a>;i 187 /a>        }i 188 /a>i 189 /a>         a href="+code=err" class="sref">err /a> = - a href="+code=ERANGE" class="sref">ERANGE /a>;i 190 /a> i 191 /a>         a href="+code=pathlen" class="sref">pathlen /a> =  a href="+code=kbuf" class="sref">kbuf /a> +  a href="+code=PAGE_SIZE" class="sref">PAGE_SIZE /a> -  a href="+code=path" class="sref">path /a>;i 192 /a>        if ( a href="+code=pathlen" class="sref">pathlen /a> <=  a href="+code=len" class="sref">len /a>) {i 193 /a>                 a href="+code=err" class="sref">err /a> =  a href="+code=pathlen" class="sref">pathlen /a>;i 194 /a>                if ( a href="+code=copy_to_user" class="sref">copy_to_user /a>( a href="+code=buf" class="sref">buf /a>,  a href="+code=path" class="sref">path /a>,  a href="+code=pathlen" class="sref">pathlen /a>))i 195 /a>                         a href="+code=err" class="sref">err /a> = - a href="+code=EFAULT" class="sref">EFAULT /a>;i 196 /a>        }i 197 /a>i 198 /a> a href="+code=out_free" class="sref">out_free /a>:i 199 /a>         a href="+code=kfree" class="sref">kfree /a>( a href="+code=kbuf" class="sref">kbuf /a>);i 200 /a>        return  a href="+code=err" class="sref">err /a>;i 201 /a> a href="+code=out" class="sref">out /a>:i 202 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 203 /a>        return  a href="+code=err" class="sref">err /a>;i 204 /a>}i 205 /a>i 206 /a>#ifdef  a href="+code=CONFIG_COMPAT" class="sref">CONFIG_COMPAT /a>i 207 /a> a href="+code=COMPAT_SYSCALL_DEFINE4" class="sref">COMPAT_SYSCALL_DEFINE4 /a>( a href="+code=lookup_dcookie" class="sref">lookup_dcookie /a>,  a href="+code=u32" class="sref">u32 /a>,  a href="+code=w0" class="sref">w0 /a>,  a href="+code=u32" class="sref">u32 /a>,  a href="+code=w1" class="sref">w1 /a>, char  a href="+code=__user" class="sref">__user /a> *,  a href="+code=buf" class="sref">buf /a>,  a href="+code=size_t" class="sref">size_t /a>,  a href="+code=len" class="sref">len /a>)i 208 /a>{i 209 /a>#ifdef  a href="+code=__BIG_ENDIAN" class="sref">__BIG_ENDIAN /a>i 210 /a>        return  a href="+code=sys_lookup_dcookie" class="sref">sys_lookup_dcookie /a>((( a href="+code=u64" class="sref">u64 /a>) a href="+code=w0" class="sref">w0 /a> << 32) |  a href="+code=w1" class="sref">w1 /a>,  a href="+code=buf" class="sref">buf /a>,  a href="+code=len" class="sref">len /a>);i 211 /a>#elsei 212 /a>        return  a href="+code=sys_lookup_dcookie" class="sref">sys_lookup_dcookie /a>((( a href="+code=u64" class="sref">u64 /a>) a href="+code=w1" class="sref">w1 /a> << 32) |  a href="+code=w0" class="sref">w0 /a>,  a href="+code=buf" class="sref">buf /a>,  a href="+code=len" class="sref">len /a>);i 213 /a>#endifi 214 /a>}i 215 /a>#endifi 216 /a>i 217 /a>static int  a href="+code=dcookie_init" class="sref">dcookie_init /a>(void)i 218 /a>{i 219 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=d" class="sref">d /a>;i 220 /a>        unsigned int  a href="+code=i" class="sref">i /a>,  a href="+code=hash_bits" class="sref">hash_bits /a>;i 221 /a>        int  a href="+code=err" class="sref">err /a> = - a href="+code=ENOMEM" class="sref">ENOMEM /a>;i 222 /a>i 223 /a>         a href="+code=dcookie_cache" class="sref">dcookie_cache /a> =  a href="+code=kmem_cache_create" class="sref">kmem_cache_create /a>( spap class="string">"dcookie_cache" /spapt,i 224 /a>                sizeof(struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a>),i 225 /a>                0, 0,  a href="+code=NULL" class="sref">NULL /a>);i 226 /a>i 227 /a>        if (! a href="+code=dcookie_cache" class="sref">dcookie_cache /a>)i 228 /a>                goto  a href="+code=out" class="sref">out /a>;i 229 /a>i 230 /a>         a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a> =  a href="+code=kmalloc" class="sref">kmalloc /a>( a href="+code=PAGE_SIZE" class="sref">PAGE_SIZE /a>,  a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);i 231 /a>        if (! a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a>)i 232 /a>                goto  a href="+code=out_kmem" class="sref">out_kmem /a>;i 233 /a>i 234 /a>         a href="+code=err" class="sref">err /a> = 0;i 235 /a>i 236 /a>         spap class="comment">/* /spapti 237 /a> spap class="comment">         * Find the power-of-two list-heads that cap fit into the allocation.. /spapti 238 /a> spap class="comment">         * We don't guarantee that "sizeof(struct list_head)" is necessarily /spapti 239 /a> spap class="comment">         * a power-of-two. /spapti 24.8.a> spap class="comment">         */ /spapti 241 /a>         a href="+code=hash_size" class="sref">hash_size /a> =  a href="+code=PAGE_SIZE" class="sref">PAGE_SIZE /a> / sizeof(struct  a href="+code=list_head" class="sref">list_head /a>);i 242 /a>         a href="+code=hash_bits" class="sref">hash_bits /a> = 0;i 243 /a>        do {i 244 /a>                 a href="+code=hash_bits" class="sref">hash_bits /a>++;i 245 /a>        } while (( a href="+code=hash_size" class="sref">hash_size /a> >>  a href="+code=hash_bits" class="sref">hash_bits /a>) != 0);i 246 /a>         a href="+code=hash_bits" class="sref">hash_bits /a>--;i 247 /a>i 248 /a>         spap class="comment">/* /spapti 249 /a> spap class="comment">         * Re-calculate the actual number of entries and the mask /spapti 25.8.a> spap class="comment">         * from the number of bits we cap fit. /spapti 251 /a> spap class="comment">         */ /spapti 252 /a>         a href="+code=hash_size" class="sref">hash_size /a> = 1UL <<  a href="+code=hash_bits" class="sref">hash_bits /a>;i 253 /a>i 254 /a>         spap class="comment">/* Andiinitialize the newly allocated array */ /spapti 255 /a>         a href="+code=d" class="sref">d /a> =  a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a>;i 256 /a>         a href="+code=i" class="sref">i /a> =  a href="+code=hash_size" class="sref">hash_size /a>;i 257 /a>        do {i 258 /a>                 a href="+code=INIT_LIST_HEAD" class="sref">INIT_LIST_HEAD /a>( a href="+code=d" class="sref">d /a>);i 259 /a>                 a href="+code=d" class="sref">d /a>++;i 260 /a>                 a href="+code=i" class="sref">i /a>--;i 261 /a>        } while ( a href="+code=i" class="sref">i /a>);i 262 /a>i 263 /a> a href="+code=out" class="sref">out /a>:i 264 /a>        return  a href="+code=err" class="sref">err /a>;i 265 /a> a href="+code=out_kmem" class="sref">out_kmem /a>:i 266 /a>         a href="+code=kmem_cache_destroy" class="sref">kmem_cache_destroy /a>( a href="+code=dcookie_cache" class="sref">dcookie_cache /a>);i 267 /a>        goto  a href="+code=out" class="sref">out /a>;i 268 /a>}i 269 /a>i 270 /a>i 271 /a>static void  a href="+code=free_dcookie" class="sref">free_dcookie /a>(struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>)i 272 /a>{i 273 /a>        struct  a href="+code=dentry" class="sref">dentry /a> * a href="+code=d" class="sref">d /a> =  a href="+code=dcs" class="sref">dcs /a>-> a href="+code=path" class="sref">path /a>. a href="+code=dentry" class="sref">dentry /a>;i 274 /a>i 275 /a>         a href="+code=spin_lock" class="sref">spin_lock /a>(& a href="+code=d" class="sref">d /a>-> a href="+code=d_lock" class="sref">d_lock /a>);i 276 /a>         a href="+code=d" class="sref">d /a>-> a href="+code=d_flags" class="sref">d_flags /a> &= ~ a href="+code=DCACHE_COOKIE" class="sref">DCACHE_COOKIE /a>;i 277 /a>         a href="+code=spin_unlock" class="sref">spin_unlock /a>(& a href="+code=d" class="sref">d /a>-> a href="+code=d_lock" class="sref">d_lock /a>);i 278 /a>i 279 /a>         a href="+code=path_put" class="sref">path_put /a>(& a href="+code=dcs" class="sref">dcs /a>-> a href="+code=path" class="sref">path /a>);i 280 /a>         a href="+code=kmem_cache_free" class="sref">kmem_cache_free /a>( a href="+code=dcookie_cache" class="sref">dcookie_cache /a>,  a href="+code=dcs" class="sref">dcs /a>);i 281 /a>}i 282 /a>i 283 /a>i 284 /a>static void  a href="+code=dcookie_exit" class="sref">dcookie_exit /a>(void)i 285 /a>{i 286 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=list" class="sref">list /a>;i 287 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=pos" class="sref">pos /a>;i 288 /a>        struct  a href="+code=list_head" class="sref">list_head /a> *  a href="+code=pos2" class="sref">pos2 /a>;i 289 /a>        struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a> *  a href="+code=dcs" class="sref">dcs /a>;i 290 /a>         a href="+code=size_t" class="sref">size_t /a>  a href="+code=i" class="sref">i /a>;i 291 /a>i 292 /a>        for ( a href="+code=i" class="sref">i /a> = 0;  a href="+code=i" class="sref">i /a> <  a href="+code=hash_size" class="sref">hash_size /a>; ++ a href="+code=i" class="sref">i /a>) {i 293 /a>                 a href="+code=list" class="sref">list /a> =  a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a> +  a href="+code=i" class="sref">i /a>;i 294 /a>                 a href="+code=list_for_each_safe" class="sref">list_for_each_safe /a>( a href="+code=pos" class="sref">pos /a>,  a href="+code=pos2" class="sref">pos2 /a>,  a href="+code=list" class="sref">list /a>) {i 295 /a>                         a href="+code=dcs" class="sref">dcs /a> =  a href="+code=list_entry" class="sref">list_entry /a>( a href="+code=pos" class="sref">pos /a>, struct  a href="+code=dcookie_struct" class="sref">dcookie_struct /a>,  a href="+code=hash_list" class="sref">hash_list /a>);i 296 /a>                         a href="+code=list_del" class="sref">list_del /a>(& a href="+code=dcs" class="sref">dcs /a>-> a href="+code=hash_list" class="sref">hash_list /a>);i 297 /a>                         a href="+code=free_dcookie" class="sref">free_dcookie /a>( a href="+code=dcs" class="sref">dcs /a>);i 298 /a>                }i 299 /a>        }i 300 /a>i 301 /a>         a href="+code=kfree" class="sref">kfree /a>( a href="+code=dcookie_hashtable" class="sref">dcookie_hashtable /a>);i 302 /a>         a href="+code=kmem_cache_destroy" class="sref">kmem_cache_destroy /a>( a href="+code=dcookie_cache" class="sref">dcookie_cache /a>);i 303 /a>}i 304 /a>i 305 /a>i 306 /a>struct  a href="+code=dcookie_user" class="sref">dcookie_user /a> {i 307 /a>        struct  a href="+code=list_head" class="sref">list_head /a>  a href="+code=next" class="sref">next /a>;i 308 /a>};i 309 /a> i 310 /a>struct  a href="+code=dcookie_user" class="sref">dcookie_user /a> *  a href="+code=dcookie_register" class="sref">dcookie_register /a>(void)i 311 /a>{i 312 /a>        struct  a href="+code=dcookie_user" class="sref">dcookie_user /a> *  a href="+code=user" class="sref">user /a>;i 313 /a>i 314 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 315 /a>i 316 /a>         a href="+code=user" class="sref">user /a> =  a href="+code=kmalloc" class="sref">kmalloc /a>(sizeof(struct  a href="+code=dcookie_user" class="sref">dcookie_user /a>),  a href="+code=GFP_KERNEL" class="sref">GFP_KERNEL /a>);i 317 /a>        if (! a href="+code=user" class="sref">user /a>)i 318 /a>                goto  a href="+code=out" class="sref">out /a>;i 319 /a>i 320 /a>        if (! a href="+code=is_live" class="sref">is_live /a>() &&  a href="+code=dcookie_init" class="sref">dcookie_init /a>())i 321 /a>                goto  a href="+code=out_free" class="sref">out_free /a>;i 322 /a>i 323 /a>         a href="+code=list_add" class="sref">list_add /a>(& a href="+code=user" class="sref">user /a>-> a href="+code=next" class="sref">next /a>, & a href="+code=dcookie_users" class="sref">dcookie_users /a>);i 324 /a>i 325 /a> a href="+code=out" class="sref">out /a>:i 326 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 327 /a>        return  a href="+code=user" class="sref">user /a>;i 328 /a> a href="+code=out_free" class="sref">out_free /a>:i 329 /a>         a href="+code=kfree" class="sref">kfree /a>( a href="+code=user" class="sref">user /a>);i 330 /a>         a href="+code=user" class="sref">user /a> =  a href="+code=NULL" class="sref">NULL /a>;i 331 /a>        goto  a href="+code=out" class="sref">out /a>;i 332 /a>}i 333 /a>i 334 /a>i 335 /a>void  a href="+code=dcookie_unregister" class="sref">dcookie_unregister /a>(struct  a href="+code=dcookie_user" class="sref">dcookie_user /a> *  a href="+code=user" class="sref">user /a>)i 336 /a>{i 337 /a>         a href="+code=mutex_lock" class="sref">mutex_lock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 338 /a>i 339 /a>         a href="+code=list_del" class="sref">list_del /a>(& a href="+code=user" class="sref">user /a>-> a href="+code=next" class="sref">next /a>);i 340 /a>         a href="+code=kfree" class="sref">kfree /a>( a href="+code=user" class="sref">user /a>);i 341 /a>i 342 /a>        if (! a href="+code=is_live" class="sref">is_live /a>())i 343 /a>                 a href="+code=dcookie_exit" class="sref">dcookie_exit /a>();i 344 /a>i 345 /a>         a href="+code=mutex_unlock" class="sref">mutex_unlock /a>(& a href="+code=dcookie_mutex" class="sref">dcookie_mutex /a>);i 346 /a>}i 347 /a>i 348 /a> a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL /a>( a href="+code=dcookie_register" class="sref">dcookie_register /a>);i 349 /a> a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL /a>( a href="+code=dcookie_unregister" class="sref">dcookie_unregister /a>);i 350 /a> a href="+code=EXPORT_SYMBOL_GPL" class="sref">EXPORT_SYMBOL_GPL /a>( a href="+code=get_dcookie" class="sref">get_dcookie /a>);i 351 /a> /pre> /div>


 /div>