slot_map.c (c1f3ee120bb61045b1c0a3ead620d1d65af47130) slot_map.c (8e8a4603b5422c9145880e73b23bc4c2c4de0098)
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * slot_map.c
5 *
6 *
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 35 unchanged lines hidden (view full) ---

44
45static s16 __ocfs2_node_num_to_slot(struct ocfs2_slot_info *si,
46 s16 global);
47static void __ocfs2_fill_slot(struct ocfs2_slot_info *si,
48 s16 slot_num,
49 s16 node_num);
50
51/* post the slot information on disk into our slot_info struct. */
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * slot_map.c
5 *
6 *
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.

--- 35 unchanged lines hidden (view full) ---

44
45static s16 __ocfs2_node_num_to_slot(struct ocfs2_slot_info *si,
46 s16 global);
47static void __ocfs2_fill_slot(struct ocfs2_slot_info *si,
48 s16 slot_num,
49 s16 node_num);
50
51/* post the slot information on disk into our slot_info struct. */
52void ocfs2_update_slot_info(struct ocfs2_slot_info *si)
52static void ocfs2_update_slot_info(struct ocfs2_slot_info *si)
53{
54 int i;
55 __le16 *disk_info;
56
57 /* we don't read the slot block here as ocfs2_super_lock
58 * should've made sure we have the most recent copy. */
59 spin_lock(&si->si_lock);
60 disk_info = (__le16 *) si->si_bh->b_data;
61
62 for (i = 0; i < si->si_size; i++)
63 si->si_global_node_nums[i] = le16_to_cpu(disk_info[i]);
64
65 spin_unlock(&si->si_lock);
66}
67
53{
54 int i;
55 __le16 *disk_info;
56
57 /* we don't read the slot block here as ocfs2_super_lock
58 * should've made sure we have the most recent copy. */
59 spin_lock(&si->si_lock);
60 disk_info = (__le16 *) si->si_bh->b_data;
61
62 for (i = 0; i < si->si_size; i++)
63 si->si_global_node_nums[i] = le16_to_cpu(disk_info[i]);
64
65 spin_unlock(&si->si_lock);
66}
67
68int ocfs2_refresh_slot_info(struct ocfs2_super *osb)
69{
70 int ret;
71 struct ocfs2_slot_info *si = osb->slot_info;
72 struct buffer_head *bh;
73
74 if (si == NULL)
75 return 0;
76
77 bh = si->si_bh;
78 ret = ocfs2_read_block(osb, bh->b_blocknr, &bh, 0, si->si_inode);
79 if (ret == 0)
80 ocfs2_update_slot_info(si);
81
82 return ret;
83}
84
68/* post the our slot info stuff into it's destination bh and write it
69 * out. */
85/* post the our slot info stuff into it's destination bh and write it
86 * out. */
70int ocfs2_update_disk_slots(struct ocfs2_super *osb,
71 struct ocfs2_slot_info *si)
87static int ocfs2_update_disk_slots(struct ocfs2_super *osb,
88 struct ocfs2_slot_info *si)
72{
73 int status, i;
74 __le16 *disk_info = (__le16 *) si->si_bh->b_data;
75
76 spin_lock(&si->si_lock);
77 for (i = 0; i < si->si_size; i++)
78 disk_info[i] = cpu_to_le16(si->si_global_node_nums[i]);
79 spin_unlock(&si->si_lock);

--- 50 unchanged lines hidden (view full) ---

130 s16 ret;
131
132 spin_lock(&si->si_lock);
133 ret = __ocfs2_node_num_to_slot(si, global);
134 spin_unlock(&si->si_lock);
135 return ret;
136}
137
89{
90 int status, i;
91 __le16 *disk_info = (__le16 *) si->si_bh->b_data;
92
93 spin_lock(&si->si_lock);
94 for (i = 0; i < si->si_size; i++)
95 disk_info[i] = cpu_to_le16(si->si_global_node_nums[i]);
96 spin_unlock(&si->si_lock);

--- 50 unchanged lines hidden (view full) ---

147 s16 ret;
148
149 spin_lock(&si->si_lock);
150 ret = __ocfs2_node_num_to_slot(si, global);
151 spin_unlock(&si->si_lock);
152 return ret;
153}
154
155static void __ocfs2_free_slot_info(struct ocfs2_slot_info *si)
156{
157 if (si == NULL)
158 return;
159
160 if (si->si_inode)
161 iput(si->si_inode);
162 if (si->si_bh)
163 brelse(si->si_bh);
164
165 kfree(si);
166}
167
138static void __ocfs2_fill_slot(struct ocfs2_slot_info *si,
139 s16 slot_num,
140 s16 node_num)
141{
142 BUG_ON(slot_num == OCFS2_INVALID_SLOT);
143 BUG_ON(slot_num >= si->si_num_slots);
144 BUG_ON((node_num != O2NM_INVALID_NODE_NUM) &&
145 (node_num >= O2NM_MAX_NODES));
146
147 si->si_global_node_nums[slot_num] = node_num;
148}
149
168static void __ocfs2_fill_slot(struct ocfs2_slot_info *si,
169 s16 slot_num,
170 s16 node_num)
171{
172 BUG_ON(slot_num == OCFS2_INVALID_SLOT);
173 BUG_ON(slot_num >= si->si_num_slots);
174 BUG_ON((node_num != O2NM_INVALID_NODE_NUM) &&
175 (node_num >= O2NM_MAX_NODES));
176
177 si->si_global_node_nums[slot_num] = node_num;
178}
179
150void ocfs2_clear_slot(struct ocfs2_slot_info *si,
151 s16 slot_num)
180int ocfs2_clear_slot(struct ocfs2_super *osb, s16 slot_num)
152{
181{
182 struct ocfs2_slot_info *si = osb->slot_info;
183
184 if (si == NULL)
185 return 0;
186
153 spin_lock(&si->si_lock);
154 __ocfs2_fill_slot(si, slot_num, OCFS2_INVALID_SLOT);
155 spin_unlock(&si->si_lock);
187 spin_lock(&si->si_lock);
188 __ocfs2_fill_slot(si, slot_num, OCFS2_INVALID_SLOT);
189 spin_unlock(&si->si_lock);
190
191 return ocfs2_update_disk_slots(osb, osb->slot_info);
156}
157
158int ocfs2_init_slot_info(struct ocfs2_super *osb)
159{
160 int status, i;
161 u64 blkno;
162 struct inode *inode = NULL;
163 struct buffer_head *bh = NULL;

--- 33 unchanged lines hidden (view full) ---

197 goto bail;
198 }
199
200 si->si_inode = inode;
201 si->si_bh = bh;
202 osb->slot_info = si;
203bail:
204 if (status < 0 && si)
192}
193
194int ocfs2_init_slot_info(struct ocfs2_super *osb)
195{
196 int status, i;
197 u64 blkno;
198 struct inode *inode = NULL;
199 struct buffer_head *bh = NULL;

--- 33 unchanged lines hidden (view full) ---

233 goto bail;
234 }
235
236 si->si_inode = inode;
237 si->si_bh = bh;
238 osb->slot_info = si;
239bail:
240 if (status < 0 && si)
205 ocfs2_free_slot_info(si);
241 __ocfs2_free_slot_info(si);
206
207 return status;
208}
209
242
243 return status;
244}
245
210void ocfs2_free_slot_info(struct ocfs2_slot_info *si)
246void ocfs2_free_slot_info(struct ocfs2_super *osb)
211{
247{
212 if (si->si_inode)
213 iput(si->si_inode);
214 if (si->si_bh)
215 brelse(si->si_bh);
216 kfree(si);
248 struct ocfs2_slot_info *si = osb->slot_info;
249
250 osb->slot_info = NULL;
251 __ocfs2_free_slot_info(si);
217}
218
219int ocfs2_find_slot(struct ocfs2_super *osb)
220{
221 int status;
222 s16 slot;
223 struct ocfs2_slot_info *si;
224

--- 55 unchanged lines hidden (view full) ---

280
281 status = ocfs2_update_disk_slots(osb, si);
282 if (status < 0) {
283 mlog_errno(status);
284 goto bail;
285 }
286
287bail:
252}
253
254int ocfs2_find_slot(struct ocfs2_super *osb)
255{
256 int status;
257 s16 slot;
258 struct ocfs2_slot_info *si;
259

--- 55 unchanged lines hidden (view full) ---

315
316 status = ocfs2_update_disk_slots(osb, si);
317 if (status < 0) {
318 mlog_errno(status);
319 goto bail;
320 }
321
322bail:
288 osb->slot_info = NULL;
289 ocfs2_free_slot_info(si);
323 ocfs2_free_slot_info(osb);
290}
291
324}
325