1 /*
2 * Copyright (c) 2002 - 2003, Stockholms Universitet
3 * (Stockholm University, Stockholm Sweden)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the university nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <xfs/xfs_locl.h>
35 #include <xfs/xfs_common.h>
36 #include <xfs/xfs_fs.h>
37 #include <xfs/xfs_deb.h>
38 #include <xfs/xfs_node.h>
39 #include <xfs/xfs_vnodeops.h>
40 #include <xfs/xfs_queue.h>
41
42 RCSID("$arla: xfs_node.c,v 1.3 2003/02/06 12:56:09 lha Exp $");
43
44 #define xfs_hash(node) \
45 (((node)->a+(node)->b+(node)->c+(node)->d) % XN_HASHSIZE)
46
47 /*
48 * Init the nnp node storage system
49 */
50
51 void
52 nnfs_init_head(struct xfs_nodelist_head *head)
53 {
54 int i;
55
56 for (i = 0; i < XN_HASHSIZE; i++)
57 NNPQUEUE_INIT(&head->nh_nodelist[i]);
58 }
59
60 /*
61 * Tries to purge all nodes from the hashtable. Nodes that unpurgeable
62 * (still used nodes) are given to proc for special termination
63 * (conversion to dead node).
64 */
65
66 void
67 xfs_node_purge(struct xfs_nodelist_head *head,
68 void (*func)(struct xfs_node *))
69 {
70 panic("xfs_node_purge");
71 }
72
73 /*
74 * xfs_node_find returns the node with the handle `handlep'.
75 */
76
77 struct xfs_node *
78 xfs_node_find(struct xfs_nodelist_head *head, xfs_handle *handlep)
79 {
80 struct nh_node_list *h;
81 struct xfs_node *nn;
82
83 h = &head->nh_nodelist[xfs_hash(handlep)];
84
85 NNPQUEUE_FOREACH(nn, h, nn_hash) {
86 if (xfs_handle_eq(handlep, &nn->handle))
87 break;
88 }
89
90 return nn;
91 }
92
93 /*
94 * Remove the node `node' from the node storage system.
95 */
96
97 void
98 xfs_remove_node(struct xfs_nodelist_head *head, struct xfs_node *node)
99 {
100 struct nh_node_list *h;
101
102 h = &head->nh_nodelist[xfs_hash(&node->handle)];
103 NNPQUEUE_REMOVE(node, h, nn_hash);
104 }
105
106 /*
107 * Add the node `node' from the node storage system.
108 */
109
110 void
111 xfs_insert(struct xfs_nodelist_head *head, struct xfs_node *node)
112 {
113 struct nh_node_list *h;
114
115 h = &head->nh_nodelist[xfs_hash(&node->handle)];
116 NNPQUEUE_INSERT_HEAD(h, node, nn_hash);
117 }
118
119 /*
120 * Update `old_handlep' in the node list `head' to `new_handlep'.
121 */
122
123 int
124 xfs_update_handle(struct xfs_nodelist_head *head,
125 xfs_handle *old_handlep, xfs_handle *new_handlep)
126 {
127 struct xfs_node *node;
128
129 node = xfs_node_find(head, new_handlep);
130 if (node)
131 return EEXIST;
132 node = xfs_node_find(head, old_handlep);
133 if (node == NULL)
134 return ENOENT;
135 xfs_remove_node(head, node);
136 node->handle = *new_handlep;
137 xfs_insert(head, node);
138
139 return 0;
140 }