diff options
| author | reinoud <reinoud@NetBSD.org> | 2008-08-30 10:49:27 +0000 |
|---|---|---|
| committer | reinoud <reinoud@NetBSD.org> | 2008-08-30 10:49:27 +0000 |
| commit | 627e960617ddc38cc2bbd178356dee2e2998c8a5 (patch) | |
| tree | 7bfaa0e0932b331f22b861b6c4c5a1006d625809 /sys | |
| parent | a8ac39af81052d842204acaf2104737314183237 (diff) | |
Back out dirhash kernel module for now.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/conf/files | 3 | ||||
| -rw-r--r-- | sys/fs/dirhash.c | 475 | ||||
| -rw-r--r-- | sys/fs/dirhash.h | 109 | ||||
| -rw-r--r-- | sys/fs/files.fs | 6 | ||||
| -rw-r--r-- | sys/modules/Makefile | 3 | ||||
| -rw-r--r-- | sys/modules/dirhash/Makefile | 11 |
6 files changed, 2 insertions, 605 deletions
diff --git a/sys/conf/files b/sys/conf/files index ca7f4e99445..be1ad4a55ca 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.913 2008/08/29 14:20:25 reinoud Exp $ +# $NetBSD: files,v 1.914 2008/08/30 10:49:27 reinoud Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -1271,7 +1271,6 @@ file dev/pud/pud_dev.c pud # File systems # include "coda/files.coda" -include "fs/files.fs" include "fs/adosfs/files.adosfs" include "fs/cd9660/files.cd9660" include "fs/efs/files.efs" diff --git a/sys/fs/dirhash.c b/sys/fs/dirhash.c deleted file mode 100644 index 9f0e057ffba..00000000000 --- a/sys/fs/dirhash.c +++ /dev/null @@ -1,475 +0,0 @@ -/* $NetBSD: dirhash.c,v 1.1 2008/08/29 14:20:26 reinoud Exp $ */ - -/* - * Copyright (c) 2008 Reinoud Zandijk - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -#include <sys/cdefs.h> -#ifndef lint -__KERNEL_RCSID(0, "$NetBSD: dirhash.c,v 1.1 2008/08/29 14:20:26 reinoud Exp $"); -#endif /* not lint */ - -#if 1 -# define DPRINTF(a) ; -#else -# define DPRINTF(a) printf(a); -#endif - -#include <sys/sysctl.h> -#include <fs/dirhash.h> -#include <sys/module.h> - -MODULE(MODULE_CLASS_MISC, dirhash, NULL); - - -static struct sysctllog *sysctl_log; -struct pool dirhash_pool; -struct pool dirhash_entry_pool; - -kmutex_t dirhashmutex; -uint32_t maxdirhashsize = DIRHASH_SIZE; -uint32_t dirhashsize = 0; -TAILQ_HEAD(_dirhash, dirhash) dirhash_queue; - - -#define CURDIRHASHSIZE_SYSCTLOPT 1 -#define MAXDIRHASHSIZE_SYSCTLOPT 2 -static int -dirhash_modcmd(modcmd_t cmd, void *arg) -{ - /* const struct sysctlnode *node; */ - size_t size; - uint32_t max_entries; - int error = 0; - - switch (cmd) { - case MODULE_CMD_INIT: - /* initialise dirhash queue */ - TAILQ_INIT(&dirhash_queue); - - /* init dirhash pools */ - size = sizeof(struct dirhash); - pool_init(&dirhash_pool, size, 0, 0, 0, - "dirhash_pool", NULL, IPL_NONE); - - size = sizeof(struct dirhash_entry); - pool_init(&dirhash_entry_pool, size, 0, 0, 0, - "dirhash_entry_pool", NULL, IPL_NONE); - - mutex_init(&dirhashmutex, MUTEX_DEFAULT, IPL_NONE); - max_entries = maxdirhashsize / size; - pool_sethiwat(&dirhash_entry_pool, max_entries); - dirhashsize = 0; - - /* create sysctl knobs and dials */ - sysctl_log = NULL; -#if 0 - sysctl_createv(&sysctl_log, 0, NULL, &node, - CTLFLAG_PERMANENT, - CTLTYPE_NODE, "vfs", NULL, - NULL, 0, NULL, 0, - CTL_VFS, CTL_EOL); - sysctl_createv(&sysctl_log, 0, NULL, &node, - CTLFLAG_PERMANENT, - CTLTYPE_INT, "curdirhashsize", - SYSCTL_DESCR("Current memory to be used by dirhash"), - NULL, 0, &dirhashsize, 0, - CTL_VFS, 0, CURDIRHASHSIZE_SYSCTLOPT, CTL_EOL); - sysctl_createv(&sysctl_log, 0, NULL, &node, - CTLFLAG_PERMANENT | CTLFLAG_READWRITE, - CTLTYPE_INT, "maxdirhashsize", - SYSCTL_DESCR("Max memory to be used by dirhash"), - NULL, 0, &maxdirhashsize, 0, - CTL_VFS, 0, MAXDIRHASHSIZE_SYSCTLOPT, CTL_EOL); - -#endif - break; - case MODULE_CMD_FINI: - pool_destroy(&dirhash_pool); - pool_destroy(&dirhash_entry_pool); - - mutex_destroy(&dirhashmutex); - - /* sysctl_teardown(&sysctl_log); */ - break; - default: - error = ENOTTY; - break; - } - - return (error); -} - - -/* - * generic dirhash implementation - */ - -static uint32_t -dirhash_hash(const char *str, int namelen) -{ - uint32_t hash = 5381; - int i, c; - - for (i = 0; i < namelen; i++) { - c = *str++; - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - } - return hash; -} - - -void -dirhash_purge_entries(struct dirhash *dirh) -{ - struct dirhash_entry *dirh_e; - uint32_t hashline; - - if (dirh == NULL) - return; - - if (dirh->size == 0) - return; - - for (hashline = 0; hashline < DIRHASH_HASHSIZE; hashline++) { - dirh_e = LIST_FIRST(&dirh->entries[hashline]); - while (dirh_e) { - LIST_REMOVE(dirh_e, next); - pool_put(&dirhash_entry_pool, dirh_e); - dirh_e = LIST_FIRST(&dirh->entries[hashline]); - } - } - dirh_e = LIST_FIRST(&dirh->free_entries); - - while (dirh_e) { - LIST_REMOVE(dirh_e, next); - pool_put(&dirhash_entry_pool, dirh_e); - dirh_e = LIST_FIRST(&dirh->entries[hashline]); - } - - dirh->flags &= ~DIRH_COMPLETE; - dirh->flags |= DIRH_PURGED; - - dirhashsize -= dirh->size; - dirh->size = 0; -} - - -void -dirhash_purge(struct dirhash **dirhp) -{ - struct dirhash *dirh = *dirhp; - - if (dirh == NULL) - return; - - mutex_enter(&dirhashmutex); - - dirhash_purge_entries(dirh); - TAILQ_REMOVE(&dirhash_queue, dirh, next); - pool_put(&dirhash_pool, dirh); - - *dirhp = NULL; - - mutex_exit(&dirhashmutex); -} - - -void -dirhash_get(struct dirhash **dirhp) -{ - struct dirhash *dirh; - uint32_t hashline; - - mutex_enter(&dirhashmutex); - - dirh = *dirhp; - if (*dirhp == NULL) { - dirh = pool_get(&dirhash_pool, PR_WAITOK); - *dirhp = dirh; - memset(dirh, 0, sizeof(struct dirhash)); - for (hashline = 0; hashline < DIRHASH_HASHSIZE; hashline++) - LIST_INIT(&dirh->entries[hashline]); - dirh->size = 0; - dirh->refcnt = 0; - dirh->flags = 0; - } else { - TAILQ_REMOVE(&dirhash_queue, dirh, next); - } - - dirh->refcnt++; - TAILQ_INSERT_HEAD(&dirhash_queue, dirh, next); - - mutex_exit(&dirhashmutex); -} - - -void -dirhash_put(struct dirhash *dirh) -{ - - mutex_enter(&dirhashmutex); - dirh->refcnt--; - mutex_exit(&dirhashmutex); -} - - -void -dirhash_enter(struct dirhash *dirh, - struct dirent *dirent, uint64_t offset, uint32_t entry_size, int new) -{ - struct dirhash *del_dirh, *prev_dirh; - struct dirhash_entry *dirh_e; - uint32_t hashvalue, hashline; - int entrysize; - - /* make sure we have a dirhash to work on */ - KASSERT(dirh); - KASSERT(dirh->refcnt > 0); - - /* are we trying to re-enter an entry? */ - if (!new && (dirh->flags & DIRH_COMPLETE)) - return; - - /* calculate our hash */ - hashvalue = dirhash_hash(dirent->d_name, dirent->d_namlen); - hashline = hashvalue & DIRHASH_HASHMASK; - - /* lookup and insert entry if not there yet */ - LIST_FOREACH(dirh_e, &dirh->entries[hashline], next) { - /* check for hash collision */ - if (dirh_e->hashvalue != hashvalue) - continue; - if (dirh_e->offset != offset) - continue; - /* got it already */ - KASSERT(dirh_e->d_namlen == dirent->d_namlen); - KASSERT(dirh_e->entry_size == entry_size); - return; - } - - DPRINTF(("dirhash enter %"PRIu64", %d, %d for `%*.*s`\n", - offset, entry_size, dirent->d_namlen, - dirent->d_namlen, dirent->d_namlen, dirent->d_name)); - - /* check if entry is in free space list */ - LIST_FOREACH(dirh_e, &dirh->free_entries, next) { - if (dirh_e->offset == offset) { - DPRINTF(("\tremoving free entry\n")); - LIST_REMOVE(dirh_e, next); - break; - } - } - - /* ensure we are not passing the dirhash limit */ - entrysize = sizeof(struct dirhash_entry); - if (dirhashsize + entrysize > maxdirhashsize) { - del_dirh = TAILQ_LAST(&dirhash_queue, _dirhash); - KASSERT(del_dirh); - while (dirhashsize + entrysize > maxdirhashsize) { - /* no use trying to delete myself */ - if (del_dirh == dirh) - break; - prev_dirh = TAILQ_PREV(del_dirh, _dirhash, next); - if (del_dirh->refcnt == 0) - dirhash_purge_entries(del_dirh); - del_dirh = prev_dirh; - } - } - - /* add to the hashline */ - dirh_e = pool_get(&dirhash_entry_pool, PR_WAITOK); - memset(dirh_e, 0, sizeof(struct dirhash_entry)); - - dirh_e->hashvalue = hashvalue; - dirh_e->offset = offset; - dirh_e->d_namlen = dirent->d_namlen; - dirh_e->entry_size = entry_size; - - dirh->size += sizeof(struct dirhash_entry); - dirhashsize += sizeof(struct dirhash_entry); - LIST_INSERT_HEAD(&dirh->entries[hashline], dirh_e, next); -} - - -void -dirhash_enter_freed(struct dirhash *dirh, uint64_t offset, - uint32_t entry_size) -{ - struct dirhash_entry *dirh_e; - - /* make sure we have a dirhash to work on */ - KASSERT(dirh); - KASSERT(dirh->refcnt > 0); - -#ifdef DEBUG - /* check for double entry of free space */ - LIST_FOREACH(dirh_e, &dirh->free_entries, next) - KASSERT(dirh_e->offset != offset); -#endif - - DPRINTF(("dirhash enter FREED %"PRIu64", %d\n", - offset, entry_size)); - dirh_e = pool_get(&dirhash_entry_pool, PR_WAITOK); - memset(dirh_e, 0, sizeof(struct dirhash_entry)); - - dirh_e->hashvalue = 0; /* not relevant */ - dirh_e->offset = offset; - dirh_e->d_namlen = 0; /* not relevant */ - dirh_e->entry_size = entry_size; - - /* XXX it might be preferable to append them at the tail */ - LIST_INSERT_HEAD(&dirh->free_entries, dirh_e, next); - dirh->size += sizeof(struct dirhash_entry); - dirhashsize += sizeof(struct dirhash_entry); -} - - -void -dirhash_remove(struct dirhash *dirh, struct dirent *dirent, - uint64_t offset, uint32_t entry_size) -{ - struct dirhash_entry *dirh_e; - uint32_t hashvalue, hashline; - - DPRINTF(("dirhash remove %"PRIu64", %d for `%*.*s`\n", - offset, entry_size, - dirent->d_namlen, dirent->d_namlen, dirent->d_name)); - - /* make sure we have a dirhash to work on */ - KASSERT(dirh); - KASSERT(dirh->refcnt > 0); - - /* calculate our hash */ - hashvalue = dirhash_hash(dirent->d_name, dirent->d_namlen); - hashline = hashvalue & DIRHASH_HASHMASK; - - /* lookup entry */ - LIST_FOREACH(dirh_e, &dirh->entries[hashline], next) { - /* check for hash collision */ - if (dirh_e->hashvalue != hashvalue) - continue; - if (dirh_e->offset != offset) - continue; - - /* got it! */ - KASSERT(dirh_e->d_namlen == dirent->d_namlen); - KASSERT(dirh_e->entry_size == entry_size); - LIST_REMOVE(dirh_e, next); - dirh->size -= sizeof(struct dirhash_entry); - dirhashsize -= sizeof(struct dirhash_entry); - - dirhash_enter_freed(dirh, offset, entry_size); - return; - } - - /* not found! */ - panic("dirhash_remove couldn't find entry in hash table\n"); -} - - -/* BUGALERT: don't use result longer than needed, never past the node lock */ -/* call with NULL *result initially and it will return nonzero if again */ -int -dirhash_lookup(struct dirhash *dirh, const char *d_name, int d_namlen, - struct dirhash_entry **result) -{ - struct dirhash_entry *dirh_e; - uint32_t hashvalue, hashline; - - /* vnode should be locked */ - //KASSERT(VOP_ISLOCKED(dirh->vnode)); - - /* make sure we have a dirhash to work on */ - KASSERT(dirh); - KASSERT(dirh->refcnt > 0); - - /* start where we were */ - if (*result) { - dirh_e = *result; - - /* retrieve information to avoid recalculation and advance */ - hashvalue = dirh_e->hashvalue; - dirh_e = LIST_NEXT(*result, next); - } else { - /* calculate our hash and lookup all entries in hashline */ - hashvalue = dirhash_hash(d_name, d_namlen); - hashline = hashvalue & DIRHASH_HASHMASK; - dirh_e = LIST_FIRST(&dirh->entries[hashline]); - } - - for (; dirh_e; dirh_e = LIST_NEXT(dirh_e, next)) { - /* check for hash collision */ - if (dirh_e->hashvalue != hashvalue) - continue; - if (dirh_e->d_namlen != d_namlen) - continue; - /* might have an entry in the cache */ - *result = dirh_e; - return 1; - } - - *result = NULL; - return 0; -} - - -/* BUGALERT: don't use result longer than needed, never past the node lock */ -/* call with NULL *result initially and it will return nonzero if again */ -int -dirhash_lookup_freed(struct dirhash *dirh, uint32_t min_entrysize, - struct dirhash_entry **result) -{ - struct dirhash_entry *dirh_e; - - //KASSERT(VOP_ISLOCKED(dirh->vnode)); - - /* make sure we have a dirhash to work on */ - KASSERT(dirh); - KASSERT(dirh->refcnt > 0); - - /* start where we were */ - if (*result) { - dirh_e = LIST_NEXT(*result, next); - } else { - /* lookup all entries that match */ - dirh_e = LIST_FIRST(&dirh->free_entries); - } - - for (; dirh_e; dirh_e = LIST_NEXT(dirh_e, next)) { - /* check for minimum size */ - if (dirh_e->entry_size < min_entrysize) - continue; - /* might be a candidate */ - *result = dirh_e; - return 1; - } - - *result = NULL; - return 0; -} - - diff --git a/sys/fs/dirhash.h b/sys/fs/dirhash.h deleted file mode 100644 index 18d5cc36fc7..00000000000 --- a/sys/fs/dirhash.h +++ /dev/null @@ -1,109 +0,0 @@ -/* $NetBSD: dirhash.h,v 1.2 2008/08/29 14:54:54 reinoud Exp $ */ - -/* - * Copyright (c) 2008 Reinoud Zandijk - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -#include <sys/cdefs.h> -#ifndef lint -__KERNEL_RCSID(0, "$NetBSD: dirhash.h,v 1.2 2008/08/29 14:54:54 reinoud Exp $"); -#endif /* not lint */ - -#include <sys/param.h> -#include <sys/systm.h> -#include <sys/sysctl.h> -#include <sys/namei.h> -#include <sys/proc.h> -#include <sys/kernel.h> -#include <sys/vnode.h> -#include <miscfs/genfs/genfs_node.h> -#include <sys/mount.h> -#include <sys/buf.h> -#include <sys/file.h> -#include <sys/device.h> -#include <sys/disklabel.h> -#include <sys/ioctl.h> -#include <sys/malloc.h> -#include <sys/dirent.h> -#include <sys/stat.h> -#include <sys/conf.h> -#include <sys/kauth.h> -#include <dev/clock_subr.h> - - -#ifndef DIRHASH_SIZE -# define DIRHASH_SIZE (1024*1024) -#endif - -#define DIRHASH_HASHBITS 5 -#define DIRHASH_HASHSIZE (1<<DIRHASH_HASHBITS) -#define DIRHASH_HASHMASK (DIRHASH_HASHSIZE -1) - - -/* dirent's d_namlen is to avoid useless costly fid->dirent translations */ -struct dirhash_entry { - uint32_t hashvalue; - uint64_t offset; - uint32_t d_namlen; - uint32_t entry_size; - LIST_ENTRY(dirhash_entry) next; -}; - - -struct dirhash { - uint32_t flags; - uint32_t size; /* in bytes */ - uint32_t refcnt; - LIST_HEAD(, dirhash_entry) entries[DIRHASH_HASHSIZE]; - LIST_HEAD(, dirhash_entry) free_entries; - TAILQ_ENTRY(dirhash) next; -}; - -#define DIRH_PURGED 0x0001 /* dirhash has been purged */ -#define DIRH_COMPLETE 0x0002 /* dirhash is complete */ -#define DIRH_BROKEN 0x0004 /* dirhash is broken on readin */ -#define DIRH_FLAGBITS \ - "\10\1DIRH_PURGED\2DIRH_COMPLETE\3DIRH_BROKEN" - - -extern uint32_t maxdirhashsize; -extern uint32_t dirhashsize; - -void dirhash_purge(struct dirhash **dirh); -void dirhash_purge_entries(struct dirhash *dirh); -void dirhash_get(struct dirhash **dirhp); -void dirhash_put(struct dirhash *dirh); -void dirhash_enter(struct dirhash *dirh, - struct dirent *dirent, uint64_t offset, uint32_t entry_size, int new); -void dirhash_enter_freed(struct dirhash *dirh, uint64_t offset, - uint32_t entry_size); -void dirhash_remove(struct dirhash *dirh, struct dirent *dirent, - uint64_t offset, uint32_t entry_size); -int dirhash_lookup(struct dirhash *dirh, const char *d_name, int d_namlen, - struct dirhash_entry **result); -int dirhash_lookup_freed(struct dirhash *dirh, uint32_t min_entrysize, - struct dirhash_entry **result); - diff --git a/sys/fs/files.fs b/sys/fs/files.fs deleted file mode 100644 index 2fb49312f54..00000000000 --- a/sys/fs/files.fs +++ /dev/null @@ -1,6 +0,0 @@ -# $NetBSD: files.fs,v 1.1 2008/08/29 14:20:26 reinoud Exp $ - -defflag DIRHASH - -file fs/dirhash.c dirhash - diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 2f8794ad495..ae93fd20fd0 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2008/08/29 14:20:26 reinoud Exp $ +# $NetBSD: Makefile,v 1.9 2008/08/30 10:49:27 reinoud Exp $ SUBDIR= miniroot SUBDIR+= putter @@ -15,7 +15,6 @@ SUBDIR+= adosfs SUBDIR+= cd9660 SUBDIR+= coda SUBDIR+= coda5 -SUBDIR+= dirhash SUBDIR+= efs SUBDIR+= ext2fs SUBDIR+= fdesc diff --git a/sys/modules/dirhash/Makefile b/sys/modules/dirhash/Makefile deleted file mode 100644 index 696cbf8d942..00000000000 --- a/sys/modules/dirhash/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $NetBSD: Makefile,v 1.1 2008/08/29 14:20:26 reinoud Exp $ - -.include "../Makefile.inc" - -.PATH: ${S}/fs - -KMOD= dirhash -SRCS= dirhash.c - -.include <bsd.kmodule.mk> - |
