[BACK]Return to ufs_dirhash.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / ufs / ufs

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/ufs/ufs/ufs_dirhash.c between version 1.10.6.1 and 1.13.2.2

version 1.10.6.1, 2006/04/01 12:07:57 version 1.13.2.2, 2007/04/13 11:28:13
Line 75  static doff_t ufsdirhash_getprev(struct 
Line 75  static doff_t ufsdirhash_getprev(struct 
 static int ufsdirhash_recycle(int wanted);  static int ufsdirhash_recycle(int wanted);
   
 static POOL_INIT(ufsdirhash_pool, DH_NBLKOFF * sizeof(daddr_t), 0, 0, 0,  static POOL_INIT(ufsdirhash_pool, DH_NBLKOFF * sizeof(daddr_t), 0, 0, 0,
     "ufsdirhash", &pool_allocator_nointr);      "ufsdirhash", &pool_allocator_nointr, IPL_NONE);
   
 #define DIRHASHLIST_LOCK()              do { } while (0)  #define DIRHASHLIST_LOCK()              mutex_enter(&ufsdirhash_lock)
 #define DIRHASHLIST_UNLOCK()            do { } while (0)  #define DIRHASHLIST_UNLOCK()            mutex_exit(&ufsdirhash_lock)
 #define DIRHASH_LOCK(dh)                do { } while (0)  #define DIRHASH_LOCK(dh)                mutex_enter(&(dh)->dh_lock)
 #define DIRHASH_UNLOCK(dh)              do { } while (0)  #define DIRHASH_UNLOCK(dh)              mutex_exit(&(dh)->dh_lock)
 #define DIRHASH_BLKALLOC_WAITOK()       pool_get(&ufsdirhash_pool, PR_WAITOK)  #define DIRHASH_BLKALLOC_WAITOK()       pool_get(&ufsdirhash_pool, PR_WAITOK)
 #define DIRHASH_BLKFREE(ptr)            pool_put(&ufsdirhash_pool, ptr)  #define DIRHASH_BLKFREE(ptr)            pool_put(&ufsdirhash_pool, ptr)
   
 /* Dirhash list; recently-used entries are near the tail. */  /* Dirhash list; recently-used entries are near the tail. */
 static TAILQ_HEAD(, dirhash) ufsdirhash_list;  static TAILQ_HEAD(, dirhash) ufsdirhash_list;
   
   /* Protects: ufsdirhash_list, `dh_list' field, ufs_dirhashmem. */
   static kmutex_t ufsdirhash_lock;
   
   /*
    * Locking order:
    *      ufsdirhash_lock
    *      dh_lock
    *
    * The dh_lock mutex should be acquired either via the inode lock, or via
    * ufsdirhash_lock. Only the owner of the inode may free the associated
    * dirhash, but anything can steal its memory and set dh_hash to NULL.
    */
   
 /*  /*
  * Attempt to build up a hash table for the directory contents in   * Attempt to build up a hash table for the directory contents in
  * inode 'ip'. Returns 0 on success, or -1 of the operation failed.   * inode 'ip'. Returns 0 on success, or -1 of the operation failed.
Line 163  ufsdirhash_build(struct inode *ip)
Line 176  ufsdirhash_build(struct inode *ip)
                 DIRHASHLIST_UNLOCK();                  DIRHASHLIST_UNLOCK();
                 return (-1);                  return (-1);
         }          }
           mutex_init(&dh->dh_lock, MUTEX_DEFAULT, IPL_NONE);
         dh->dh_hash = (doff_t **)malloc(narrays * sizeof(dh->dh_hash[0]),          dh->dh_hash = (doff_t **)malloc(narrays * sizeof(dh->dh_hash[0]),
             M_DIRHASH, M_NOWAIT | M_ZERO);              M_DIRHASH, M_NOWAIT | M_ZERO);
         dh->dh_blkfree = (u_int8_t *)malloc(nblocks * sizeof(dh->dh_blkfree[0]),          dh->dh_blkfree = (u_int8_t *)malloc(nblocks * sizeof(dh->dh_blkfree[0]),
Line 196  ufsdirhash_build(struct inode *ip)
Line 210  ufsdirhash_build(struct inode *ip)
         while (pos < ip->i_size) {          while (pos < ip->i_size) {
                 if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)                  if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
                     != 0) {                      != 0) {
                         preempt(1);                          preempt();
                 }                  }
                 /* If necessary, get the next directory block. */                  /* If necessary, get the next directory block. */
                 if ((pos & bmask) == 0) {                  if ((pos & bmask) == 0) {
Line 244  fail:
Line 258  fail:
         }          }
         if (dh->dh_blkfree != NULL)          if (dh->dh_blkfree != NULL)
                 FREE(dh->dh_blkfree, M_DIRHASH);                  FREE(dh->dh_blkfree, M_DIRHASH);
           mutex_destroy(&dh->dh_lock);
         FREE(dh, M_DIRHASH);          FREE(dh, M_DIRHASH);
         ip->i_dirhash = NULL;          ip->i_dirhash = NULL;
         DIRHASHLIST_LOCK();          DIRHASHLIST_LOCK();
Line 282  ufsdirhash_free(struct inode *ip)
Line 297  ufsdirhash_free(struct inode *ip)
                     dh->dh_narrays * DH_NBLKOFF * sizeof(**dh->dh_hash) +                      dh->dh_narrays * DH_NBLKOFF * sizeof(**dh->dh_hash) +
                     dh->dh_nblk * sizeof(*dh->dh_blkfree);                      dh->dh_nblk * sizeof(*dh->dh_blkfree);
         }          }
           mutex_destroy(&dh->dh_lock);
         FREE(dh, M_DIRHASH);          FREE(dh, M_DIRHASH);
         ip->i_dirhash = NULL;          ip->i_dirhash = NULL;
   
Line 318  ufsdirhash_lookup(struct inode *ip, cons
Line 334  ufsdirhash_lookup(struct inode *ip, cons
                 return (EJUSTRETURN);                  return (EJUSTRETURN);
         /*          /*
          * Move this dirhash towards the end of the list if it has a           * Move this dirhash towards the end of the list if it has a
          * score higher than the next entry, and acquire the dh_mtx.           * score higher than the next entry, and acquire the dh_lock.
          * Optimise the case where it's already the last by performing           * Optimise the case where it's already the last by performing
          * an unlocked read of the TAILQ_NEXT pointer.           * an unlocked read of the TAILQ_NEXT pointer.
          *           *
          * In both cases, end up holding just dh_mtx.           * In both cases, end up holding just dh_lock.
          */           */
         if (TAILQ_NEXT(dh, dh_list) != NULL) {          if (TAILQ_NEXT(dh, dh_list) != NULL) {
                 DIRHASHLIST_LOCK();                  DIRHASHLIST_LOCK();
Line 400  restart:
Line 416  restart:
                         if (ufs_blkatoff(vp, (off_t)blkoff, NULL, &bp) != 0)                          if (ufs_blkatoff(vp, (off_t)blkoff, NULL, &bp) != 0)
                                 return (EJUSTRETURN);                                  return (EJUSTRETURN);
                 }                  }
                 dp = (struct direct *)(bp->b_data + (offset & bmask));                  dp = (struct direct *)((char *)bp->b_data + (offset & bmask));
                 if (dp->d_reclen == 0 || dp->d_reclen >                  if (dp->d_reclen == 0 || dp->d_reclen >
                     dirblksiz - (offset & (dirblksiz - 1))) {                      dirblksiz - (offset & (dirblksiz - 1))) {
                         /* Corrupted directory. */                          /* Corrupted directory. */
Line 875  ufsdirhash_hash(struct dirhash *dh, cons
Line 891  ufsdirhash_hash(struct dirhash *dh, cons
  * by the value specified by `diff'.   * by the value specified by `diff'.
  *   *
  * The caller must ensure we have exclusive access to `dh'; normally   * The caller must ensure we have exclusive access to `dh'; normally
  * that means that dh_mtx should be held, but this is also called   * that means that dh_lock should be held, but this is also called
  * from ufsdirhash_build() where exclusive access can be assumed.   * from ufsdirhash_build() where exclusive access can be assumed.
  */   */
 static void  static void
Line 919  ufsdirhash_findslot(struct dirhash *dh, 
Line 935  ufsdirhash_findslot(struct dirhash *dh, 
 {  {
         int slot;          int slot;
   
           KASSERT(mutex_owned(&dh->dh_lock));
   
         /* Find the entry. */          /* Find the entry. */
         KASSERT(dh->dh_hused < dh->dh_hlen);          KASSERT(dh->dh_hused < dh->dh_hlen);
         slot = ufsdirhash_hash(dh, name, namelen);          slot = ufsdirhash_hash(dh, name, namelen);
Line 941  ufsdirhash_delslot(struct dirhash *dh, i
Line 959  ufsdirhash_delslot(struct dirhash *dh, i
 {  {
         int i;          int i;
   
           KASSERT(mutex_owned(&dh->dh_lock));
   
         /* Mark the entry as deleted. */          /* Mark the entry as deleted. */
         DH_ENTRY(dh, slot) = DIRHASH_DEL;          DH_ENTRY(dh, slot) = DIRHASH_DEL;
   
Line 1053  ufsdirhash_init()
Line 1073  ufsdirhash_init()
 {  {
 #ifdef _LKM  #ifdef _LKM
         pool_init(&ufsdirhash_pool, DH_NBLKOFF * sizeof(daddr_t), 0, 0, 0,          pool_init(&ufsdirhash_pool, DH_NBLKOFF * sizeof(daddr_t), 0, 0, 0,
             "ufsdirhash", &pool_allocator_nointr);              "ufsdirhash", &pool_allocator_nointr, IPL_NONE);
 #endif  #endif
           mutex_init(&ufsdirhash_lock, MUTEX_DEFAULT, IPL_NONE);
         TAILQ_INIT(&ufsdirhash_list);          TAILQ_INIT(&ufsdirhash_list);
 }  }
   
Line 1065  ufsdirhash_done(void)
Line 1086  ufsdirhash_done(void)
 #ifdef _LKM  #ifdef _LKM
         pool_destroy(&ufsdirhash_pool);          pool_destroy(&ufsdirhash_pool);
 #endif  #endif
           mutex_destroy(&ufsdirhash_lock);
 }  }
   
 SYSCTL_SETUP(sysctl_vfs_ufs_setup, "sysctl vfs.ufs.dirhash subtree setup")  SYSCTL_SETUP(sysctl_vfs_ufs_setup, "sysctl vfs.ufs.dirhash subtree setup")

Legend:
Removed from v.1.10.6.1  
changed lines
  Added in v.1.13.2.2

CVSweb <webmaster@jp.NetBSD.org>