From 8d9a89a3a0c142317a4ff383d610d07116fd95ae Mon Sep 17 00:00:00 2001 From: Xin LI Date: Wed, 11 Jul 2007 14:26:27 +0000 Subject: [PATCH] MFp4: Make use of the kernel unit number allocation facility for tmpfs nodes. Submitted by: Mingyan Guo Approved by: re (tmpfs blanket) --- sys/fs/tmpfs/tmpfs.h | 6 ++---- sys/fs/tmpfs/tmpfs_subr.c | 2 ++ sys/fs/tmpfs/tmpfs_vfsops.c | 20 ++++++-------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/sys/fs/tmpfs/tmpfs.h b/sys/fs/tmpfs/tmpfs.h index 37313424f012..9ef773135ef5 100644 --- a/sys/fs/tmpfs/tmpfs.h +++ b/sys/fs/tmpfs/tmpfs.h @@ -288,10 +288,8 @@ struct tmpfs_mount { * of empty files and then simply removing them. */ ino_t tm_nodes_max; - /* Number of nodes currently allocated. This number only grows. - * When it reaches tm_nodes_max, no more new nodes can be allocated. - * Of course, the old, unused ones can be reused. */ - ino_t tm_nodes_last; + /* unrhdr used to allocate inode numbers */ + struct unrhdr * tm_ino_unr; /* Number of nodes currently that are in use. */ ino_t tm_nodes_inuse; diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c index b9a706d30dc6..24c0dc9bf9c3 100644 --- a/sys/fs/tmpfs/tmpfs_subr.c +++ b/sys/fs/tmpfs/tmpfs_subr.c @@ -114,6 +114,7 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp, enum vtype type, nnode->tn_uid = uid; nnode->tn_gid = gid; nnode->tn_mode = mode; + nnode->tn_id = alloc_unr(tmp->tm_ino_unr); /* Type-specific initialization. */ switch (nnode->tn_type) { @@ -225,6 +226,7 @@ tmpfs_free_node(struct tmpfs_mount *tmp, struct tmpfs_node *node) break; } + free_unr(tmp->tm_ino_unr, node->tn_id); uma_zfree(tmp->tm_node_pool, node); TMPFS_LOCK(tmp); diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c index 5ee548bd09ba..993d3f9ed36d 100644 --- a/sys/fs/tmpfs/tmpfs_vfsops.c +++ b/sys/fs/tmpfs/tmpfs_vfsops.c @@ -146,19 +146,7 @@ tmpfs_node_ctor(void *mem, int size, void *arg, int flags) { struct tmpfs_node *node = (struct tmpfs_node *)mem; - if (node->tn_id == 0) { - /* if this node structure first time used */ - struct tmpfs_mount *tmp = (struct tmpfs_mount *)arg; - TMPFS_LOCK(tmp); - node->tn_id = tmp->tm_nodes_last++; - TMPFS_UNLOCK(tmp); - if (node->tn_id == INT_MAX) - panic("all avariable id is used."); - node->tn_gen = arc4random(); - } else { - node->tn_gen++; - } - + node->tn_gen++; node->tn_size = 0; node->tn_status = 0; node->tn_flags = 0; @@ -185,6 +173,7 @@ tmpfs_node_init(void *mem, int size, int flags) node->tn_id = 0; mtx_init(&node->tn_interlock, "tmpfs node interlock", NULL, MTX_DEF); + node->tn_gen = arc4random(); return (0); } @@ -278,13 +267,13 @@ tmpfs_mount(struct mount *mp, struct thread *td) mtx_init(&tmp->allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF); tmp->tm_nodes_max = nodes; - tmp->tm_nodes_last = 2; tmp->tm_nodes_inuse = 0; tmp->tm_maxfilesize = get_swpgtotal() * PAGE_SIZE; LIST_INIT(&tmp->tm_nodes_used); tmp->tm_pages_max = pages; tmp->tm_pages_used = 0; + tmp->tm_ino_unr = new_unrhdr(2, INT_MAX, &tmp->allnode_lock); tmp->tm_dirent_pool = uma_zcreate( "TMPFS dirent", sizeof(struct tmpfs_dirent), @@ -307,9 +296,11 @@ tmpfs_mount(struct mount *mp, struct thread *td) if (error != 0 || root == NULL) { uma_zdestroy(tmp->tm_node_pool); uma_zdestroy(tmp->tm_dirent_pool); + delete_unrhdr(tmp->tm_ino_unr); free(tmp, M_TMPFSMNT); return error; } + KASSERT(root->tn_id == 2, ("tmpfs root with invalid ino: %d", root->tn_id)); tmp->tm_root = root; MNT_ILOCK(mp); @@ -377,6 +368,7 @@ tmpfs_unmount(struct mount *mp, int mntflags, struct thread *l) uma_zdestroy(tmp->tm_dirent_pool); uma_zdestroy(tmp->tm_node_pool); + delete_unrhdr(tmp->tm_ino_unr); mtx_destroy(&tmp->allnode_lock); MPASS(tmp->tm_pages_used == 0);