The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/hpfs/hpfs_hash.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. All advertising materials mentioning features or use of this software
   14  *    must display the following acknowledgement:
   15  *      This product includes software developed by the University of
   16  *      California, Berkeley and its contributors.
   17  * 4. Neither the name of the University nor the names of its contributors
   18  *    may be used to endorse or promote products derived from this software
   19  *    without specific prior written permission.
   20  *
   21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   31  * SUCH DAMAGE.
   32  *
   33  *      @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
   34  * $FreeBSD$
   35  */
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/kernel.h>
   40 #include <sys/lock.h>
   41 #include <sys/vnode.h>
   42 #include <sys/mount.h>
   43 #include <sys/malloc.h>
   44 #include <sys/proc.h>
   45 
   46 #include <fs/hpfs/hpfs.h>
   47 
   48 MALLOC_DEFINE(M_HPFSHASH, "HPFS hash", "HPFS node hash tables");
   49 
   50 /*
   51  * Structures associated with hpfsnode cacheing.
   52  */
   53 static LIST_HEAD(hphashhead, hpfsnode) *hpfs_hphashtbl;
   54 static u_long   hpfs_hphash;            /* size of hash table - 1 */
   55 #define HPNOHASH(dev, lsn)      (&hpfs_hphashtbl[(minor(dev) + (lsn)) & hpfs_hphash])
   56 #ifndef NULL_SIMPLELOCKS
   57 static struct simplelock hpfs_hphash_slock;
   58 #endif
   59 struct lock hpfs_hphash_lock;
   60 
   61 /*
   62  * Initialize inode hash table.
   63  */
   64 void
   65 hpfs_hphashinit()
   66 {
   67 
   68         lockinit (&hpfs_hphash_lock, PINOD, "hpfs_hphashlock", 0, 0);
   69         hpfs_hphashtbl = HASHINIT(desiredvnodes, M_HPFSHASH, M_WAITOK,
   70             &hpfs_hphash);
   71         simple_lock_init(&hpfs_hphash_slock);
   72 }
   73 
   74 /*
   75  * Use the device/inum pair to find the incore inode, and return a pointer
   76  * to it. If it is in core, return it, even if it is locked.
   77  */
   78 struct hpfsnode *
   79 hpfs_hphashlookup(dev, ino)
   80         dev_t dev;
   81         lsn_t ino;
   82 {
   83         struct hpfsnode *hp;
   84 
   85         simple_lock(&hpfs_hphash_slock);
   86         for (hp = HPNOHASH(dev, ino)->lh_first; hp; hp = hp->h_hash.le_next)
   87                 if (ino == hp->h_no && dev == hp->h_dev)
   88                         break;
   89         simple_unlock(&hpfs_hphash_slock);
   90 
   91         return (hp);
   92 }
   93 
   94 #if 0
   95 struct hpfsnode *
   96 hpfs_hphashget(dev, ino)
   97         dev_t dev;
   98         lsn_t ino;
   99 {
  100         struct hpfsnode *hp;
  101 
  102 loop:
  103         simple_lock(&hpfs_hphash_slock);
  104         for (hp = HPNOHASH(dev, ino)->lh_first; hp; hp = hp->h_hash.le_next) {
  105                 if (ino == hp->h_no && dev == hp->h_dev) {
  106                         LOCKMGR(&hp->h_intlock, LK_EXCLUSIVE | LK_INTERLOCK, &hpfs_hphash_slock, NULL);
  107                         return (hp);
  108                 }
  109         }
  110         simple_unlock(&hpfs_hphash_slock);
  111         return (hp);
  112 }
  113 #endif
  114 
  115 struct vnode *
  116 hpfs_hphashvget(dev, ino, p)
  117         dev_t dev;
  118         lsn_t ino;
  119         struct proc *p;
  120 {
  121         struct hpfsnode *hp;
  122         struct vnode *vp;
  123 
  124 loop:
  125         simple_lock(&hpfs_hphash_slock);
  126         for (hp = HPNOHASH(dev, ino)->lh_first; hp; hp = hp->h_hash.le_next) {
  127                 if (ino == hp->h_no && dev == hp->h_dev) {
  128                         vp = HPTOV(hp);
  129                         simple_lock (&vp->v_interlock);
  130                         simple_unlock (&hpfs_hphash_slock);
  131                         if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p))
  132                                 goto loop;
  133                         return (vp);
  134                 }
  135         }
  136         simple_unlock(&hpfs_hphash_slock);
  137         return (NULLVP);
  138 }
  139 
  140 /*
  141  * Insert the hpfsnode into the hash table.
  142  */
  143 void
  144 hpfs_hphashins(hp)
  145         struct hpfsnode *hp;
  146 {
  147         struct hphashhead *hpp;
  148 
  149         simple_lock(&hpfs_hphash_slock);
  150         hpp = HPNOHASH(hp->h_dev, hp->h_no);
  151         hp->h_flag |= H_HASHED;
  152         LIST_INSERT_HEAD(hpp, hp, h_hash);
  153         simple_unlock(&hpfs_hphash_slock);
  154 }
  155 
  156 /*
  157  * Remove the inode from the hash table.
  158  */
  159 void
  160 hpfs_hphashrem(hp)
  161         struct hpfsnode *hp;
  162 {
  163         simple_lock(&hpfs_hphash_slock);
  164         if (hp->h_flag & H_HASHED) {
  165                 hp->h_flag &= ~H_HASHED;
  166                 LIST_REMOVE(hp, h_hash);
  167 #ifdef DIAGNOSTIC
  168                 hp->h_hash.le_next = NULL;
  169                 hp->h_hash.le_prev = NULL;
  170 #endif
  171         }
  172         simple_unlock(&hpfs_hphash_slock);
  173 }

Cache object: a1199e3f3ae323316c5d741df9f82629


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.