1 /* $NetBSD: chfs_vnode_cache.c,v 1.1 2011/11/24 15:51:32 ahoka Exp $ */
4 * Copyright (c) 2010 Department of Software Engineering,
5 * University of Szeged, Hungary
6 * Copyright (C) 2010 Tamas Toth <ttoth@inf.u-szeged.hu>
7 * Copyright (C) 2010 Adam Hoka <ahoka@NetBSD.org>
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by the Department of Software Engineering, University of Szeged, Hungary
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 struct chfs_vnode_cache
**
39 chfs_vnocache_hash_init(void)
41 return kmem_zalloc(VNODECACHE_SIZE
*
42 sizeof(struct chfs_vnode_cache
*), KM_SLEEP
);
46 * chfs_set_vnode_cache_state - set state of a vnode_cache
47 * @chmp: fs super block info
52 chfs_vnode_cache_set_state(struct chfs_mount
*chmp
,
53 struct chfs_vnode_cache
* vc
, int state
)
55 /* XXX do we really need locking here? */
56 KASSERT(mutex_owned(&chmp
->chm_lock_vnocache
));
61 * chfs_get_vnode_cache - get a vnode_cache from the vnocache_hash
62 * @chmp: fs super block info
63 * @ino: inode for search
64 * Returns the vnode_cache.
66 struct chfs_vnode_cache
*
67 chfs_vnode_cache_get(struct chfs_mount
*chmp
, ino_t vno
)
69 struct chfs_vnode_cache
* ret
;
71 KASSERT(mutex_owned(&chmp
->chm_lock_vnocache
));
73 ret
= chmp
->chm_vnocache_hash
[vno
% VNODECACHE_SIZE
];
79 while (ret
&& ret
->vno
< vno
) {
83 if (ret
&& ret
->vno
!= vno
) {
91 * chfs_add_vnode_cache - add a vnode_cache to the vnocache_hash
92 * @chmp: fs super block info
93 * @new: new vnode_cache
96 chfs_vnode_cache_add(struct chfs_mount
*chmp
,
97 struct chfs_vnode_cache
* new)
99 struct chfs_vnode_cache
** prev
;
101 KASSERT(mutex_owned(&chmp
->chm_lock_vnocache
));
104 new->vno
= ++chmp
->chm_max_vno
;
107 prev
= &chmp
->chm_vnocache_hash
[new->vno
% VNODECACHE_SIZE
];
109 while ((*prev
) && (*prev
)->vno
< new->vno
) {
110 prev
= &((*prev
)->next
);
117 * chfs_del_vnode_cache - del a vnode_cache from the vnocache_hash
118 * @chmp: fs super block info
119 * @old: old vnode_cache
122 chfs_vnode_cache_remove(struct chfs_mount
*chmp
,
123 struct chfs_vnode_cache
* old
)
125 struct chfs_vnode_cache
** prev
;
127 KASSERT(mutex_owned(&chmp
->chm_lock_vnocache
));
129 prev
= &chmp
->chm_vnocache_hash
[old
->vno
% VNODECACHE_SIZE
];
130 while ((*prev
) && (*prev
)->vno
< old
->vno
) {
131 prev
= &(*prev
)->next
;
134 if ((*prev
) == old
) {
138 if (old
->state
!= VNO_STATE_READING
&&
139 old
->state
!= VNO_STATE_CLEARING
) {
140 chfs_vnode_cache_free(old
);
145 * chfs_free_vnode_caches - free the vnocache_hash
146 * @chmp: fs super block info
149 chfs_vnocache_hash_destroy(struct chfs_vnode_cache
**hash
)
151 struct chfs_vnode_cache
*this, *next
;
154 for (i
= 0; i
< VNODECACHE_SIZE
; i
++) {
158 chfs_vnode_cache_free(this);