diff options
author | delphij <delphij@FreeBSD.org> | 2007-07-11 14:26:27 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2007-07-11 14:26:27 +0000 |
commit | ff9bf4b792638d7157d3edd6df71e2a8c02e5ba6 (patch) | |
tree | 7846bc16fbfcca0ddb40e6528c2589212c9f1c56 /sys | |
parent | a0e02f86c06ab807051f8c40db4f3045d0dac429 (diff) | |
download | FreeBSD-src-ff9bf4b792638d7157d3edd6df71e2a8c02e5ba6.zip FreeBSD-src-ff9bf4b792638d7157d3edd6df71e2a8c02e5ba6.tar.gz |
MFp4: Make use of the kernel unit number allocation facility
for tmpfs nodes.
Submitted by: Mingyan Guo <guomingyan gmail com>
Approved by: re (tmpfs blanket)
Diffstat (limited to 'sys')
-rw-r--r-- | sys/fs/tmpfs/tmpfs.h | 6 | ||||
-rw-r--r-- | sys/fs/tmpfs/tmpfs_subr.c | 2 | ||||
-rw-r--r-- | 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 3731342..9ef7731 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 b9a706d..24c0dc9 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 5ee548b..993d3f9 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); |