]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
1da177e4 | 21 | #include "xfs_log.h" |
a844f451 | 22 | #include "xfs_inum.h" |
1da177e4 LT |
23 | #include "xfs_trans.h" |
24 | #include "xfs_buf_item.h" | |
25 | #include "xfs_sb.h" | |
da353b0d | 26 | #include "xfs_ag.h" |
1da177e4 LT |
27 | #include "xfs_dmapi.h" |
28 | #include "xfs_mount.h" | |
29 | #include "xfs_trans_priv.h" | |
30 | #include "xfs_extfree_item.h" | |
31 | ||
32 | ||
33 | kmem_zone_t *xfs_efi_zone; | |
34 | kmem_zone_t *xfs_efd_zone; | |
35 | ||
36 | STATIC void xfs_efi_item_unlock(xfs_efi_log_item_t *); | |
1da177e4 | 37 | |
7d795ca3 CH |
38 | void |
39 | xfs_efi_item_free(xfs_efi_log_item_t *efip) | |
40 | { | |
41 | int nexts = efip->efi_format.efi_nextents; | |
42 | ||
43 | if (nexts > XFS_EFI_MAX_FAST_EXTENTS) { | |
f0e2d93c | 44 | kmem_free(efip); |
7d795ca3 CH |
45 | } else { |
46 | kmem_zone_free(xfs_efi_zone, efip); | |
47 | } | |
48 | } | |
1da177e4 LT |
49 | |
50 | /* | |
51 | * This returns the number of iovecs needed to log the given efi item. | |
52 | * We only need 1 iovec for an efi item. It just logs the efi_log_format | |
53 | * structure. | |
54 | */ | |
55 | /*ARGSUSED*/ | |
56 | STATIC uint | |
57 | xfs_efi_item_size(xfs_efi_log_item_t *efip) | |
58 | { | |
59 | return 1; | |
60 | } | |
61 | ||
62 | /* | |
63 | * This is called to fill in the vector of log iovecs for the | |
64 | * given efi log item. We use only 1 iovec, and we point that | |
65 | * at the efi_log_format structure embedded in the efi item. | |
66 | * It is at this point that we assert that all of the extent | |
67 | * slots in the efi item have been filled. | |
68 | */ | |
69 | STATIC void | |
70 | xfs_efi_item_format(xfs_efi_log_item_t *efip, | |
71 | xfs_log_iovec_t *log_vector) | |
72 | { | |
73 | uint size; | |
74 | ||
75 | ASSERT(efip->efi_next_extent == efip->efi_format.efi_nextents); | |
76 | ||
77 | efip->efi_format.efi_type = XFS_LI_EFI; | |
78 | ||
79 | size = sizeof(xfs_efi_log_format_t); | |
80 | size += (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t); | |
81 | efip->efi_format.efi_size = 1; | |
82 | ||
83 | log_vector->i_addr = (xfs_caddr_t)&(efip->efi_format); | |
84 | log_vector->i_len = size; | |
4139b3b3 | 85 | log_vector->i_type = XLOG_REG_TYPE_EFI_FORMAT; |
1da177e4 LT |
86 | ASSERT(size >= sizeof(xfs_efi_log_format_t)); |
87 | } | |
88 | ||
89 | ||
90 | /* | |
91 | * Pinning has no meaning for an efi item, so just return. | |
92 | */ | |
93 | /*ARGSUSED*/ | |
94 | STATIC void | |
95 | xfs_efi_item_pin(xfs_efi_log_item_t *efip) | |
96 | { | |
97 | return; | |
98 | } | |
99 | ||
100 | ||
101 | /* | |
102 | * While EFIs cannot really be pinned, the unpin operation is the | |
103 | * last place at which the EFI is manipulated during a transaction. | |
104 | * Here we coordinate with xfs_efi_cancel() to determine who gets to | |
105 | * free the EFI. | |
106 | */ | |
107 | /*ARGSUSED*/ | |
108 | STATIC void | |
109 | xfs_efi_item_unpin(xfs_efi_log_item_t *efip, int stale) | |
110 | { | |
783a2f65 | 111 | struct xfs_ail *ailp = efip->efi_item.li_ailp; |
1da177e4 | 112 | |
fc1829f3 | 113 | spin_lock(&ailp->xa_lock); |
1da177e4 | 114 | if (efip->efi_flags & XFS_EFI_CANCELED) { |
783a2f65 DC |
115 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
116 | xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip); | |
7d795ca3 | 117 | xfs_efi_item_free(efip); |
1da177e4 LT |
118 | } else { |
119 | efip->efi_flags |= XFS_EFI_COMMITTED; | |
fc1829f3 | 120 | spin_unlock(&ailp->xa_lock); |
1da177e4 | 121 | } |
1da177e4 LT |
122 | } |
123 | ||
124 | /* | |
125 | * like unpin only we have to also clear the xaction descriptor | |
126 | * pointing the log item if we free the item. This routine duplicates | |
127 | * unpin because efi_flags is protected by the AIL lock. Freeing | |
128 | * the descriptor and then calling unpin would force us to drop the AIL | |
129 | * lock which would open up a race condition. | |
130 | */ | |
131 | STATIC void | |
132 | xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp) | |
133 | { | |
783a2f65 | 134 | struct xfs_ail *ailp = efip->efi_item.li_ailp; |
1da177e4 | 135 | xfs_log_item_desc_t *lidp; |
1da177e4 | 136 | |
fc1829f3 | 137 | spin_lock(&ailp->xa_lock); |
1da177e4 LT |
138 | if (efip->efi_flags & XFS_EFI_CANCELED) { |
139 | /* | |
140 | * free the xaction descriptor pointing to this item | |
141 | */ | |
142 | lidp = xfs_trans_find_item(tp, (xfs_log_item_t *) efip); | |
143 | xfs_trans_free_item(tp, lidp); | |
783a2f65 DC |
144 | |
145 | /* xfs_trans_ail_delete() drops the AIL lock. */ | |
146 | xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip); | |
7d795ca3 | 147 | xfs_efi_item_free(efip); |
1da177e4 LT |
148 | } else { |
149 | efip->efi_flags |= XFS_EFI_COMMITTED; | |
fc1829f3 | 150 | spin_unlock(&ailp->xa_lock); |
1da177e4 | 151 | } |
1da177e4 LT |
152 | } |
153 | ||
154 | /* | |
155 | * Efi items have no locking or pushing. However, since EFIs are | |
156 | * pulled from the AIL when their corresponding EFDs are committed | |
157 | * to disk, their situation is very similar to being pinned. Return | |
158 | * XFS_ITEM_PINNED so that the caller will eventually flush the log. | |
159 | * This should help in getting the EFI out of the AIL. | |
160 | */ | |
161 | /*ARGSUSED*/ | |
162 | STATIC uint | |
163 | xfs_efi_item_trylock(xfs_efi_log_item_t *efip) | |
164 | { | |
165 | return XFS_ITEM_PINNED; | |
166 | } | |
167 | ||
168 | /* | |
169 | * Efi items have no locking, so just return. | |
170 | */ | |
171 | /*ARGSUSED*/ | |
172 | STATIC void | |
173 | xfs_efi_item_unlock(xfs_efi_log_item_t *efip) | |
174 | { | |
175 | if (efip->efi_item.li_flags & XFS_LI_ABORTED) | |
065d312e | 176 | xfs_efi_item_free(efip); |
1da177e4 LT |
177 | return; |
178 | } | |
179 | ||
180 | /* | |
181 | * The EFI is logged only once and cannot be moved in the log, so | |
182 | * simply return the lsn at which it's been logged. The canceled | |
183 | * flag is not paid any attention here. Checking for that is delayed | |
184 | * until the EFI is unpinned. | |
185 | */ | |
186 | /*ARGSUSED*/ | |
187 | STATIC xfs_lsn_t | |
188 | xfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn) | |
189 | { | |
190 | return lsn; | |
191 | } | |
192 | ||
1da177e4 LT |
193 | /* |
194 | * There isn't much you can do to push on an efi item. It is simply | |
195 | * stuck waiting for all of its corresponding efd items to be | |
196 | * committed to disk. | |
197 | */ | |
198 | /*ARGSUSED*/ | |
199 | STATIC void | |
200 | xfs_efi_item_push(xfs_efi_log_item_t *efip) | |
201 | { | |
202 | return; | |
203 | } | |
204 | ||
205 | /* | |
206 | * The EFI dependency tracking op doesn't do squat. It can't because | |
207 | * it doesn't know where the free extent is coming from. The dependency | |
208 | * tracking has to be handled by the "enclosing" metadata object. For | |
209 | * example, for inodes, the inode is locked throughout the extent freeing | |
210 | * so the dependency should be recorded there. | |
211 | */ | |
212 | /*ARGSUSED*/ | |
213 | STATIC void | |
214 | xfs_efi_item_committing(xfs_efi_log_item_t *efip, xfs_lsn_t lsn) | |
215 | { | |
216 | return; | |
217 | } | |
218 | ||
219 | /* | |
220 | * This is the ops vector shared by all efi log items. | |
221 | */ | |
7989cb8e | 222 | static struct xfs_item_ops xfs_efi_item_ops = { |
1da177e4 LT |
223 | .iop_size = (uint(*)(xfs_log_item_t*))xfs_efi_item_size, |
224 | .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*)) | |
225 | xfs_efi_item_format, | |
226 | .iop_pin = (void(*)(xfs_log_item_t*))xfs_efi_item_pin, | |
227 | .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efi_item_unpin, | |
228 | .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *)) | |
229 | xfs_efi_item_unpin_remove, | |
230 | .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efi_item_trylock, | |
231 | .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efi_item_unlock, | |
232 | .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t)) | |
233 | xfs_efi_item_committed, | |
234 | .iop_push = (void(*)(xfs_log_item_t*))xfs_efi_item_push, | |
1da177e4 LT |
235 | .iop_pushbuf = NULL, |
236 | .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t)) | |
237 | xfs_efi_item_committing | |
238 | }; | |
239 | ||
240 | ||
241 | /* | |
242 | * Allocate and initialize an efi item with the given number of extents. | |
243 | */ | |
244 | xfs_efi_log_item_t * | |
245 | xfs_efi_init(xfs_mount_t *mp, | |
246 | uint nextents) | |
247 | ||
248 | { | |
249 | xfs_efi_log_item_t *efip; | |
250 | uint size; | |
251 | ||
252 | ASSERT(nextents > 0); | |
253 | if (nextents > XFS_EFI_MAX_FAST_EXTENTS) { | |
254 | size = (uint)(sizeof(xfs_efi_log_item_t) + | |
255 | ((nextents - 1) * sizeof(xfs_extent_t))); | |
256 | efip = (xfs_efi_log_item_t*)kmem_zalloc(size, KM_SLEEP); | |
257 | } else { | |
258 | efip = (xfs_efi_log_item_t*)kmem_zone_zalloc(xfs_efi_zone, | |
259 | KM_SLEEP); | |
260 | } | |
261 | ||
262 | efip->efi_item.li_type = XFS_LI_EFI; | |
263 | efip->efi_item.li_ops = &xfs_efi_item_ops; | |
264 | efip->efi_item.li_mountp = mp; | |
fc1829f3 | 265 | efip->efi_item.li_ailp = mp->m_ail; |
1da177e4 LT |
266 | efip->efi_format.efi_nextents = nextents; |
267 | efip->efi_format.efi_id = (__psint_t)(void*)efip; | |
268 | ||
269 | return (efip); | |
270 | } | |
271 | ||
6d192a9b TS |
272 | /* |
273 | * Copy an EFI format buffer from the given buf, and into the destination | |
274 | * EFI format structure. | |
275 | * The given buffer can be in 32 bit or 64 bit form (which has different padding), | |
276 | * one of which will be the native format for this kernel. | |
277 | * It will handle the conversion of formats if necessary. | |
278 | */ | |
279 | int | |
280 | xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt) | |
281 | { | |
282 | xfs_efi_log_format_t *src_efi_fmt = (xfs_efi_log_format_t *)buf->i_addr; | |
283 | uint i; | |
284 | uint len = sizeof(xfs_efi_log_format_t) + | |
285 | (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t); | |
286 | uint len32 = sizeof(xfs_efi_log_format_32_t) + | |
287 | (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_32_t); | |
288 | uint len64 = sizeof(xfs_efi_log_format_64_t) + | |
289 | (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_64_t); | |
290 | ||
291 | if (buf->i_len == len) { | |
292 | memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len); | |
293 | return 0; | |
294 | } else if (buf->i_len == len32) { | |
295 | xfs_efi_log_format_32_t *src_efi_fmt_32 = | |
296 | (xfs_efi_log_format_32_t *)buf->i_addr; | |
297 | ||
298 | dst_efi_fmt->efi_type = src_efi_fmt_32->efi_type; | |
299 | dst_efi_fmt->efi_size = src_efi_fmt_32->efi_size; | |
300 | dst_efi_fmt->efi_nextents = src_efi_fmt_32->efi_nextents; | |
301 | dst_efi_fmt->efi_id = src_efi_fmt_32->efi_id; | |
302 | for (i = 0; i < dst_efi_fmt->efi_nextents; i++) { | |
303 | dst_efi_fmt->efi_extents[i].ext_start = | |
304 | src_efi_fmt_32->efi_extents[i].ext_start; | |
305 | dst_efi_fmt->efi_extents[i].ext_len = | |
306 | src_efi_fmt_32->efi_extents[i].ext_len; | |
307 | } | |
308 | return 0; | |
309 | } else if (buf->i_len == len64) { | |
310 | xfs_efi_log_format_64_t *src_efi_fmt_64 = | |
311 | (xfs_efi_log_format_64_t *)buf->i_addr; | |
312 | ||
313 | dst_efi_fmt->efi_type = src_efi_fmt_64->efi_type; | |
314 | dst_efi_fmt->efi_size = src_efi_fmt_64->efi_size; | |
315 | dst_efi_fmt->efi_nextents = src_efi_fmt_64->efi_nextents; | |
316 | dst_efi_fmt->efi_id = src_efi_fmt_64->efi_id; | |
317 | for (i = 0; i < dst_efi_fmt->efi_nextents; i++) { | |
318 | dst_efi_fmt->efi_extents[i].ext_start = | |
319 | src_efi_fmt_64->efi_extents[i].ext_start; | |
320 | dst_efi_fmt->efi_extents[i].ext_len = | |
321 | src_efi_fmt_64->efi_extents[i].ext_len; | |
322 | } | |
323 | return 0; | |
324 | } | |
325 | return EFSCORRUPTED; | |
326 | } | |
327 | ||
1da177e4 LT |
328 | /* |
329 | * This is called by the efd item code below to release references to | |
330 | * the given efi item. Each efd calls this with the number of | |
331 | * extents that it has logged, and when the sum of these reaches | |
332 | * the total number of extents logged by this efi item we can free | |
333 | * the efi item. | |
334 | * | |
335 | * Freeing the efi item requires that we remove it from the AIL. | |
336 | * We'll use the AIL lock to protect our counters as well as | |
337 | * the removal from the AIL. | |
338 | */ | |
339 | void | |
340 | xfs_efi_release(xfs_efi_log_item_t *efip, | |
341 | uint nextents) | |
342 | { | |
783a2f65 | 343 | struct xfs_ail *ailp = efip->efi_item.li_ailp; |
fc1829f3 | 344 | int extents_left; |
1da177e4 | 345 | |
1da177e4 LT |
346 | ASSERT(efip->efi_next_extent > 0); |
347 | ASSERT(efip->efi_flags & XFS_EFI_COMMITTED); | |
348 | ||
fc1829f3 | 349 | spin_lock(&ailp->xa_lock); |
1da177e4 LT |
350 | ASSERT(efip->efi_next_extent >= nextents); |
351 | efip->efi_next_extent -= nextents; | |
352 | extents_left = efip->efi_next_extent; | |
353 | if (extents_left == 0) { | |
783a2f65 DC |
354 | /* xfs_trans_ail_delete() drops the AIL lock. */ |
355 | xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip); | |
7d795ca3 | 356 | xfs_efi_item_free(efip); |
1da177e4 | 357 | } else { |
fc1829f3 | 358 | spin_unlock(&ailp->xa_lock); |
1da177e4 | 359 | } |
1da177e4 LT |
360 | } |
361 | ||
7d795ca3 CH |
362 | STATIC void |
363 | xfs_efd_item_free(xfs_efd_log_item_t *efdp) | |
364 | { | |
365 | int nexts = efdp->efd_format.efd_nextents; | |
1da177e4 | 366 | |
7d795ca3 | 367 | if (nexts > XFS_EFD_MAX_FAST_EXTENTS) { |
f0e2d93c | 368 | kmem_free(efdp); |
7d795ca3 CH |
369 | } else { |
370 | kmem_zone_free(xfs_efd_zone, efdp); | |
371 | } | |
372 | } | |
1da177e4 LT |
373 | |
374 | /* | |
375 | * This returns the number of iovecs needed to log the given efd item. | |
376 | * We only need 1 iovec for an efd item. It just logs the efd_log_format | |
377 | * structure. | |
378 | */ | |
379 | /*ARGSUSED*/ | |
380 | STATIC uint | |
381 | xfs_efd_item_size(xfs_efd_log_item_t *efdp) | |
382 | { | |
383 | return 1; | |
384 | } | |
385 | ||
386 | /* | |
387 | * This is called to fill in the vector of log iovecs for the | |
388 | * given efd log item. We use only 1 iovec, and we point that | |
389 | * at the efd_log_format structure embedded in the efd item. | |
390 | * It is at this point that we assert that all of the extent | |
391 | * slots in the efd item have been filled. | |
392 | */ | |
393 | STATIC void | |
394 | xfs_efd_item_format(xfs_efd_log_item_t *efdp, | |
395 | xfs_log_iovec_t *log_vector) | |
396 | { | |
397 | uint size; | |
398 | ||
399 | ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents); | |
400 | ||
401 | efdp->efd_format.efd_type = XFS_LI_EFD; | |
402 | ||
403 | size = sizeof(xfs_efd_log_format_t); | |
404 | size += (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t); | |
405 | efdp->efd_format.efd_size = 1; | |
406 | ||
407 | log_vector->i_addr = (xfs_caddr_t)&(efdp->efd_format); | |
408 | log_vector->i_len = size; | |
4139b3b3 | 409 | log_vector->i_type = XLOG_REG_TYPE_EFD_FORMAT; |
1da177e4 LT |
410 | ASSERT(size >= sizeof(xfs_efd_log_format_t)); |
411 | } | |
412 | ||
413 | ||
414 | /* | |
415 | * Pinning has no meaning for an efd item, so just return. | |
416 | */ | |
417 | /*ARGSUSED*/ | |
418 | STATIC void | |
419 | xfs_efd_item_pin(xfs_efd_log_item_t *efdp) | |
420 | { | |
421 | return; | |
422 | } | |
423 | ||
424 | ||
425 | /* | |
426 | * Since pinning has no meaning for an efd item, unpinning does | |
427 | * not either. | |
428 | */ | |
429 | /*ARGSUSED*/ | |
430 | STATIC void | |
431 | xfs_efd_item_unpin(xfs_efd_log_item_t *efdp, int stale) | |
432 | { | |
433 | return; | |
434 | } | |
435 | ||
436 | /*ARGSUSED*/ | |
437 | STATIC void | |
438 | xfs_efd_item_unpin_remove(xfs_efd_log_item_t *efdp, xfs_trans_t *tp) | |
439 | { | |
440 | return; | |
441 | } | |
442 | ||
443 | /* | |
444 | * Efd items have no locking, so just return success. | |
445 | */ | |
446 | /*ARGSUSED*/ | |
447 | STATIC uint | |
448 | xfs_efd_item_trylock(xfs_efd_log_item_t *efdp) | |
449 | { | |
450 | return XFS_ITEM_LOCKED; | |
451 | } | |
452 | ||
453 | /* | |
454 | * Efd items have no locking or pushing, so return failure | |
455 | * so that the caller doesn't bother with us. | |
456 | */ | |
457 | /*ARGSUSED*/ | |
458 | STATIC void | |
459 | xfs_efd_item_unlock(xfs_efd_log_item_t *efdp) | |
460 | { | |
461 | if (efdp->efd_item.li_flags & XFS_LI_ABORTED) | |
065d312e | 462 | xfs_efd_item_free(efdp); |
1da177e4 LT |
463 | return; |
464 | } | |
465 | ||
466 | /* | |
467 | * When the efd item is committed to disk, all we need to do | |
468 | * is delete our reference to our partner efi item and then | |
469 | * free ourselves. Since we're freeing ourselves we must | |
470 | * return -1 to keep the transaction code from further referencing | |
471 | * this item. | |
472 | */ | |
473 | /*ARGSUSED*/ | |
474 | STATIC xfs_lsn_t | |
475 | xfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn) | |
476 | { | |
1da177e4 LT |
477 | /* |
478 | * If we got a log I/O error, it's always the case that the LR with the | |
479 | * EFI got unpinned and freed before the EFD got aborted. | |
480 | */ | |
481 | if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0) | |
482 | xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents); | |
483 | ||
7d795ca3 | 484 | xfs_efd_item_free(efdp); |
1da177e4 LT |
485 | return (xfs_lsn_t)-1; |
486 | } | |
487 | ||
1da177e4 LT |
488 | /* |
489 | * There isn't much you can do to push on an efd item. It is simply | |
490 | * stuck waiting for the log to be flushed to disk. | |
491 | */ | |
492 | /*ARGSUSED*/ | |
493 | STATIC void | |
494 | xfs_efd_item_push(xfs_efd_log_item_t *efdp) | |
495 | { | |
496 | return; | |
497 | } | |
498 | ||
499 | /* | |
500 | * The EFD dependency tracking op doesn't do squat. It can't because | |
501 | * it doesn't know where the free extent is coming from. The dependency | |
502 | * tracking has to be handled by the "enclosing" metadata object. For | |
503 | * example, for inodes, the inode is locked throughout the extent freeing | |
504 | * so the dependency should be recorded there. | |
505 | */ | |
506 | /*ARGSUSED*/ | |
507 | STATIC void | |
508 | xfs_efd_item_committing(xfs_efd_log_item_t *efip, xfs_lsn_t lsn) | |
509 | { | |
510 | return; | |
511 | } | |
512 | ||
513 | /* | |
514 | * This is the ops vector shared by all efd log items. | |
515 | */ | |
7989cb8e | 516 | static struct xfs_item_ops xfs_efd_item_ops = { |
1da177e4 LT |
517 | .iop_size = (uint(*)(xfs_log_item_t*))xfs_efd_item_size, |
518 | .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*)) | |
519 | xfs_efd_item_format, | |
520 | .iop_pin = (void(*)(xfs_log_item_t*))xfs_efd_item_pin, | |
521 | .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efd_item_unpin, | |
522 | .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*)) | |
523 | xfs_efd_item_unpin_remove, | |
524 | .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efd_item_trylock, | |
525 | .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efd_item_unlock, | |
526 | .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t)) | |
527 | xfs_efd_item_committed, | |
528 | .iop_push = (void(*)(xfs_log_item_t*))xfs_efd_item_push, | |
1da177e4 LT |
529 | .iop_pushbuf = NULL, |
530 | .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t)) | |
531 | xfs_efd_item_committing | |
532 | }; | |
533 | ||
534 | ||
535 | /* | |
536 | * Allocate and initialize an efd item with the given number of extents. | |
537 | */ | |
538 | xfs_efd_log_item_t * | |
539 | xfs_efd_init(xfs_mount_t *mp, | |
540 | xfs_efi_log_item_t *efip, | |
541 | uint nextents) | |
542 | ||
543 | { | |
544 | xfs_efd_log_item_t *efdp; | |
545 | uint size; | |
546 | ||
547 | ASSERT(nextents > 0); | |
548 | if (nextents > XFS_EFD_MAX_FAST_EXTENTS) { | |
549 | size = (uint)(sizeof(xfs_efd_log_item_t) + | |
550 | ((nextents - 1) * sizeof(xfs_extent_t))); | |
551 | efdp = (xfs_efd_log_item_t*)kmem_zalloc(size, KM_SLEEP); | |
552 | } else { | |
553 | efdp = (xfs_efd_log_item_t*)kmem_zone_zalloc(xfs_efd_zone, | |
554 | KM_SLEEP); | |
555 | } | |
556 | ||
557 | efdp->efd_item.li_type = XFS_LI_EFD; | |
558 | efdp->efd_item.li_ops = &xfs_efd_item_ops; | |
559 | efdp->efd_item.li_mountp = mp; | |
fc1829f3 | 560 | efdp->efd_item.li_ailp = mp->m_ail; |
1da177e4 LT |
561 | efdp->efd_efip = efip; |
562 | efdp->efd_format.efd_nextents = nextents; | |
563 | efdp->efd_format.efd_efi_id = efip->efi_format.efi_id; | |
564 | ||
565 | return (efdp); | |
566 | } |