Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/ufs/ufs/ufs_dirhash.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/ufs/ufs/ufs_dirhash.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.21.10.2 retrieving revision 1.37 diff -u -p -r1.21.10.2 -r1.37 --- src/sys/ufs/ufs/ufs_dirhash.c 2009/06/20 07:20:38 1.21.10.2 +++ src/sys/ufs/ufs/ufs_dirhash.c 2014/12/20 00:28:05 1.37 @@ -1,4 +1,4 @@ -/* $NetBSD: ufs_dirhash.c,v 1.21.10.2 2009/06/20 07:20:38 yamt Exp $ */ +/* $NetBSD: ufs_dirhash.c,v 1.37 2014/12/20 00:28:05 christos Exp $ */ /* * Copyright (c) 2001, 2002 Ian Dowse. All rights reserved. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.21.10.2 2009/06/20 07:20:38 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ufs_dirhash.c,v 1.37 2014/12/20 00:28:05 christos Exp $"); /* * This implements a hash-based lookup scheme for UFS directories. @@ -146,7 +146,7 @@ ufsdirhash_build(struct inode *ip) vp = ip->i_vnode; /* Allocate 50% more entries than this dir size could ever need. */ KASSERT(ip->i_size >= dirblksiz); - nslots = ip->i_size / DIRECTSIZ(1); + nslots = ip->i_size / UFS_DIRECTSIZ(1); nslots = (nslots * 3 + 1) / 2; narrays = howmany(nslots, DH_NBLKOFF); nslots = narrays * DH_NBLKOFF; @@ -239,7 +239,7 @@ ufsdirhash_build(struct inode *ip) slot = WRAPINCR(slot, dh->dh_hlen); dh->dh_hused++; DH_ENTRY(dh, slot) = pos; - ufsdirhash_adjfree(dh, pos, -DIRSIZ(0, ep, needswap), + ufsdirhash_adjfree(dh, pos, -UFS_DIRSIZ(0, ep, needswap), dirblksiz); } pos += ep->d_reclen; @@ -255,6 +255,7 @@ ufsdirhash_build(struct inode *ip) return (0); fail: + ip->i_dirhash = NULL; DIRHASH_UNLOCK(dh); if (dh->dh_hash != NULL) { for (i = 0; i < narrays; i++) @@ -266,7 +267,6 @@ fail: kmem_free(dh->dh_blkfree, dh->dh_blkfreesz); mutex_destroy(&dh->dh_lock); pool_cache_put(ufsdirhash_cache, dh); - ip->i_dirhash = NULL; atomic_add_int(&ufs_dirhashmem, -memreqd); return (-1); } @@ -283,6 +283,8 @@ ufsdirhash_free(struct inode *ip) if ((dh = ip->i_dirhash) == NULL) return; + ip->i_dirhash = NULL; + if (dh->dh_onlist) { DIRHASHLIST_LOCK(); if (dh->dh_onlist) @@ -303,7 +305,6 @@ ufsdirhash_free(struct inode *ip) } mutex_destroy(&dh->dh_lock); pool_cache_put(ufsdirhash_cache, dh); - ip->i_dirhash = NULL; atomic_add_int(&ufs_dirhashmem, -mem); } @@ -316,7 +317,7 @@ ufsdirhash_free(struct inode *ip) * If successful, the directory offset is stored in *offp, and a * pointer to a struct buf containing the entry is stored in *bpp. If * prevoffp is non-NULL, the offset of the previous entry within - * the DIRBLKSIZ-sized block is stored in *prevoffp (if the entry + * the UFS_DIRBLKSIZ-sized block is stored in *prevoffp (if the entry * is the first in a block, the start of the block is used). */ int @@ -448,7 +449,7 @@ restart: /* Check for sequential access, and update offset. */ if (dh->dh_seqopt == 0 && dh->dh_seqoff == offset) dh->dh_seqopt = 1; - dh->dh_seqoff = offset + DIRSIZ(0, dp, needswap); + dh->dh_seqoff = offset + UFS_DIRSIZ(0, dp, needswap); DIRHASH_UNLOCK(dh); *bpp = bp; @@ -483,7 +484,7 @@ restart: * the offset of the directory entry that begins the free space. * This will either be the offset of an existing entry that has free * space at the end, or the offset of an entry with d_ino == 0 at - * the start of a DIRBLKSIZ block. + * the start of a UFS_DIRBLKSIZ block. * * To use the space, the caller may need to compact existing entries in * the directory. The total number of bytes in all of the entries involved @@ -540,7 +541,7 @@ ufsdirhash_findfree(struct inode *ip, in brelse(bp, 0); return (-1); } - if (dp->d_ino == 0 || dp->d_reclen > DIRSIZ(0, dp, needswap)) + if (dp->d_ino == 0 || dp->d_reclen > UFS_DIRSIZ(0, dp, needswap)) break; i += dp->d_reclen; dp = (struct direct *)((char *)dp + dp->d_reclen); @@ -557,7 +558,7 @@ ufsdirhash_findfree(struct inode *ip, in while (i < dirblksiz && freebytes < slotneeded) { freebytes += dp->d_reclen; if (dp->d_ino != 0) - freebytes -= DIRSIZ(0, dp, needswap); + freebytes -= UFS_DIRSIZ(0, dp, needswap); if (dp->d_reclen == 0) { DIRHASH_UNLOCK(dh); brelse(bp, 0); @@ -655,7 +656,7 @@ ufsdirhash_add(struct inode *ip, struct DH_ENTRY(dh, slot) = offset; /* Update the per-block summary info. */ - ufsdirhash_adjfree(dh, offset, -DIRSIZ(0, dirp, needswap), dirblksiz); + ufsdirhash_adjfree(dh, offset, -UFS_DIRSIZ(0, dirp, needswap), dirblksiz); DIRHASH_UNLOCK(dh); } @@ -690,7 +691,7 @@ ufsdirhash_remove(struct inode *ip, stru ufsdirhash_delslot(dh, slot); /* Update the per-block summary info. */ - ufsdirhash_adjfree(dh, offset, DIRSIZ(0, dirp, needswap), dirblksiz); + ufsdirhash_adjfree(dh, offset, UFS_DIRSIZ(0, dirp, needswap), dirblksiz); DIRHASH_UNLOCK(dh); } @@ -724,7 +725,7 @@ ufsdirhash_move(struct inode *ip, struct /* * Inform dirhash that the directory has grown by one block that - * begins at offset (i.e. the new length is offset + DIRBLKSIZ). + * begins at offset (i.e. the new length is offset + UFS_DIRBLKSIZ). */ void ufsdirhash_newblk(struct inode *ip, doff_t offset) @@ -868,7 +869,7 @@ ufsdirhash_checkblock(struct inode *ip, /* Check that the entry exists (will panic if it doesn't). */ ufsdirhash_findslot(dh, dp->d_name, dp->d_namlen, offset + i); - nfree += dp->d_reclen - DIRSIZ(0, dp, needswap); + nfree += dp->d_reclen - UFS_DIRSIZ(0, dp, needswap); } if (i != dirblksiz) panic("ufsdirhash_checkblock: bad dir end"); @@ -1000,7 +1001,7 @@ ufsdirhash_delslot(struct dirhash *dh, i /* * Given a directory entry and its offset, find the offset of the - * previous entry in the same DIRBLKSIZ-sized block. Returns an + * previous entry in the same UFS_DIRBLKSIZ-sized block. Returns an * offset, or -1 if there is no previous entry in the block or some * other problem occurred. */ @@ -1086,7 +1087,7 @@ ufsdirhash_recycle(int wanted) /* Account for the returned memory, and repeat if necessary. */ DIRHASHLIST_LOCK(); - ufs_dirhashmem -= mem; + atomic_add_int(&ufs_dirhashmem, -mem); } /* Success. */ return (0); @@ -1099,16 +1100,10 @@ ufsdirhash_sysctl_init(void) sysctl_createv(&ufsdirhash_sysctl_log, 0, NULL, &rnode, CTLFLAG_PERMANENT, - CTLTYPE_NODE, "vfs", NULL, - NULL, 0, NULL, 0, - CTL_VFS, CTL_EOL); - - sysctl_createv(&ufsdirhash_sysctl_log, 0, &rnode, &rnode, - CTLFLAG_PERMANENT, CTLTYPE_NODE, "ufs", SYSCTL_DESCR("ufs"), NULL, 0, NULL, 0, - CTL_CREATE, CTL_EOL); + CTL_VFS, CTL_CREATE, CTL_EOL); sysctl_createv(&ufsdirhash_sysctl_log, 0, &rnode, &rnode, CTLFLAG_PERMANENT,