blob: e461e93b0350934c268ce5ab404377eb49cb2a8d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_buf_item.h"
25#include "xfs_sb.h"
David Chinnerda353b02007-08-28 14:00:13 +100026#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_dmapi.h"
28#include "xfs_mount.h"
29#include "xfs_trans_priv.h"
30#include "xfs_extfree_item.h"
31
32
33kmem_zone_t *xfs_efi_zone;
34kmem_zone_t *xfs_efd_zone;
35
36STATIC void xfs_efi_item_unlock(xfs_efi_log_item_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Christoph Hellwig7d795ca2005-06-21 15:41:19 +100038void
39xfs_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) {
Denys Vlasenkof0e2d932008-05-19 16:31:57 +100044 kmem_free(efip);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +100045 } else {
46 kmem_zone_free(xfs_efi_zone, efip);
47 }
48}
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
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*/
56STATIC uint
57xfs_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 */
69STATIC void
70xfs_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;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +000085 log_vector->i_type = XLOG_REG_TYPE_EFI_FORMAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 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*/
94STATIC void
95xfs_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*/
108STATIC void
109xfs_efi_item_unpin(xfs_efi_log_item_t *efip, int stale)
110{
David Chinner783a2f62008-10-30 17:39:58 +1100111 struct xfs_ail *ailp = efip->efi_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
David Chinnerfc1829f2008-10-30 17:39:46 +1100113 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (efip->efi_flags & XFS_EFI_CANCELED) {
David Chinner783a2f62008-10-30 17:39:58 +1100115 /* xfs_trans_ail_delete() drops the AIL lock. */
116 xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000117 xfs_efi_item_free(efip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 } else {
119 efip->efi_flags |= XFS_EFI_COMMITTED;
David Chinnerfc1829f2008-10-30 17:39:46 +1100120 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
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 */
131STATIC void
132xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
133{
David Chinner783a2f62008-10-30 17:39:58 +1100134 struct xfs_ail *ailp = efip->efi_item.li_ailp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 xfs_log_item_desc_t *lidp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
David Chinnerfc1829f2008-10-30 17:39:46 +1100137 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 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);
David Chinner783a2f62008-10-30 17:39:58 +1100144
145 /* xfs_trans_ail_delete() drops the AIL lock. */
146 xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000147 xfs_efi_item_free(efip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 } else {
149 efip->efi_flags |= XFS_EFI_COMMITTED;
David Chinnerfc1829f2008-10-30 17:39:46 +1100150 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
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*/
162STATIC uint
163xfs_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*/
172STATIC void
173xfs_efi_item_unlock(xfs_efi_log_item_t *efip)
174{
175 if (efip->efi_item.li_flags & XFS_LI_ABORTED)
Eric Sandeen065d3122006-09-28 11:02:44 +1000176 xfs_efi_item_free(efip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 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*/
187STATIC xfs_lsn_t
188xfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
189{
190 return lsn;
191}
192
193/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 * 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*/
199STATIC void
200xfs_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*/
213STATIC void
214xfs_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 */
David Chinner7989cb82007-02-10 18:34:56 +1100222static struct xfs_item_ops xfs_efi_item_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .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 */
244xfs_efi_log_item_t *
245xfs_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
Dave Chinner43f5efc2010-03-23 10:10:00 +1100262 xfs_log_item_init(mp, &efip->efi_item, XFS_LI_EFI, &xfs_efi_item_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 efip->efi_format.efi_nextents = nextents;
264 efip->efi_format.efi_id = (__psint_t)(void*)efip;
265
266 return (efip);
267}
268
269/*
Tim Shimmin6d192a92006-06-09 14:55:38 +1000270 * Copy an EFI format buffer from the given buf, and into the destination
271 * EFI format structure.
272 * The given buffer can be in 32 bit or 64 bit form (which has different padding),
273 * one of which will be the native format for this kernel.
274 * It will handle the conversion of formats if necessary.
275 */
276int
277xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
278{
279 xfs_efi_log_format_t *src_efi_fmt = (xfs_efi_log_format_t *)buf->i_addr;
280 uint i;
281 uint len = sizeof(xfs_efi_log_format_t) +
282 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t);
283 uint len32 = sizeof(xfs_efi_log_format_32_t) +
284 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_32_t);
285 uint len64 = sizeof(xfs_efi_log_format_64_t) +
286 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_64_t);
287
288 if (buf->i_len == len) {
289 memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len);
290 return 0;
291 } else if (buf->i_len == len32) {
292 xfs_efi_log_format_32_t *src_efi_fmt_32 =
293 (xfs_efi_log_format_32_t *)buf->i_addr;
294
295 dst_efi_fmt->efi_type = src_efi_fmt_32->efi_type;
296 dst_efi_fmt->efi_size = src_efi_fmt_32->efi_size;
297 dst_efi_fmt->efi_nextents = src_efi_fmt_32->efi_nextents;
298 dst_efi_fmt->efi_id = src_efi_fmt_32->efi_id;
299 for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
300 dst_efi_fmt->efi_extents[i].ext_start =
301 src_efi_fmt_32->efi_extents[i].ext_start;
302 dst_efi_fmt->efi_extents[i].ext_len =
303 src_efi_fmt_32->efi_extents[i].ext_len;
304 }
305 return 0;
306 } else if (buf->i_len == len64) {
307 xfs_efi_log_format_64_t *src_efi_fmt_64 =
308 (xfs_efi_log_format_64_t *)buf->i_addr;
309
310 dst_efi_fmt->efi_type = src_efi_fmt_64->efi_type;
311 dst_efi_fmt->efi_size = src_efi_fmt_64->efi_size;
312 dst_efi_fmt->efi_nextents = src_efi_fmt_64->efi_nextents;
313 dst_efi_fmt->efi_id = src_efi_fmt_64->efi_id;
314 for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
315 dst_efi_fmt->efi_extents[i].ext_start =
316 src_efi_fmt_64->efi_extents[i].ext_start;
317 dst_efi_fmt->efi_extents[i].ext_len =
318 src_efi_fmt_64->efi_extents[i].ext_len;
319 }
320 return 0;
321 }
322 return EFSCORRUPTED;
323}
324
325/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 * This is called by the efd item code below to release references to
327 * the given efi item. Each efd calls this with the number of
328 * extents that it has logged, and when the sum of these reaches
329 * the total number of extents logged by this efi item we can free
330 * the efi item.
331 *
332 * Freeing the efi item requires that we remove it from the AIL.
333 * We'll use the AIL lock to protect our counters as well as
334 * the removal from the AIL.
335 */
336void
337xfs_efi_release(xfs_efi_log_item_t *efip,
338 uint nextents)
339{
David Chinner783a2f62008-10-30 17:39:58 +1100340 struct xfs_ail *ailp = efip->efi_item.li_ailp;
David Chinnerfc1829f2008-10-30 17:39:46 +1100341 int extents_left;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 ASSERT(efip->efi_next_extent > 0);
344 ASSERT(efip->efi_flags & XFS_EFI_COMMITTED);
345
David Chinnerfc1829f2008-10-30 17:39:46 +1100346 spin_lock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 ASSERT(efip->efi_next_extent >= nextents);
348 efip->efi_next_extent -= nextents;
349 extents_left = efip->efi_next_extent;
350 if (extents_left == 0) {
David Chinner783a2f62008-10-30 17:39:58 +1100351 /* xfs_trans_ail_delete() drops the AIL lock. */
352 xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000353 xfs_efi_item_free(efip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 } else {
David Chinnerfc1829f2008-10-30 17:39:46 +1100355 spin_unlock(&ailp->xa_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000359STATIC void
360xfs_efd_item_free(xfs_efd_log_item_t *efdp)
361{
362 int nexts = efdp->efd_format.efd_nextents;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000364 if (nexts > XFS_EFD_MAX_FAST_EXTENTS) {
Denys Vlasenkof0e2d932008-05-19 16:31:57 +1000365 kmem_free(efdp);
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000366 } else {
367 kmem_zone_free(xfs_efd_zone, efdp);
368 }
369}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371/*
372 * This returns the number of iovecs needed to log the given efd item.
373 * We only need 1 iovec for an efd item. It just logs the efd_log_format
374 * structure.
375 */
376/*ARGSUSED*/
377STATIC uint
378xfs_efd_item_size(xfs_efd_log_item_t *efdp)
379{
380 return 1;
381}
382
383/*
384 * This is called to fill in the vector of log iovecs for the
385 * given efd log item. We use only 1 iovec, and we point that
386 * at the efd_log_format structure embedded in the efd item.
387 * It is at this point that we assert that all of the extent
388 * slots in the efd item have been filled.
389 */
390STATIC void
391xfs_efd_item_format(xfs_efd_log_item_t *efdp,
392 xfs_log_iovec_t *log_vector)
393{
394 uint size;
395
396 ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents);
397
398 efdp->efd_format.efd_type = XFS_LI_EFD;
399
400 size = sizeof(xfs_efd_log_format_t);
401 size += (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t);
402 efdp->efd_format.efd_size = 1;
403
404 log_vector->i_addr = (xfs_caddr_t)&(efdp->efd_format);
405 log_vector->i_len = size;
Christoph Hellwig4139b3b2010-01-19 09:56:45 +0000406 log_vector->i_type = XLOG_REG_TYPE_EFD_FORMAT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 ASSERT(size >= sizeof(xfs_efd_log_format_t));
408}
409
410
411/*
412 * Pinning has no meaning for an efd item, so just return.
413 */
414/*ARGSUSED*/
415STATIC void
416xfs_efd_item_pin(xfs_efd_log_item_t *efdp)
417{
418 return;
419}
420
421
422/*
423 * Since pinning has no meaning for an efd item, unpinning does
424 * not either.
425 */
426/*ARGSUSED*/
427STATIC void
428xfs_efd_item_unpin(xfs_efd_log_item_t *efdp, int stale)
429{
430 return;
431}
432
433/*ARGSUSED*/
434STATIC void
435xfs_efd_item_unpin_remove(xfs_efd_log_item_t *efdp, xfs_trans_t *tp)
436{
437 return;
438}
439
440/*
441 * Efd items have no locking, so just return success.
442 */
443/*ARGSUSED*/
444STATIC uint
445xfs_efd_item_trylock(xfs_efd_log_item_t *efdp)
446{
447 return XFS_ITEM_LOCKED;
448}
449
450/*
451 * Efd items have no locking or pushing, so return failure
452 * so that the caller doesn't bother with us.
453 */
454/*ARGSUSED*/
455STATIC void
456xfs_efd_item_unlock(xfs_efd_log_item_t *efdp)
457{
458 if (efdp->efd_item.li_flags & XFS_LI_ABORTED)
Eric Sandeen065d3122006-09-28 11:02:44 +1000459 xfs_efd_item_free(efdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return;
461}
462
463/*
464 * When the efd item is committed to disk, all we need to do
465 * is delete our reference to our partner efi item and then
466 * free ourselves. Since we're freeing ourselves we must
467 * return -1 to keep the transaction code from further referencing
468 * this item.
469 */
470/*ARGSUSED*/
471STATIC xfs_lsn_t
472xfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn)
473{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 /*
475 * If we got a log I/O error, it's always the case that the LR with the
476 * EFI got unpinned and freed before the EFD got aborted.
477 */
478 if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0)
479 xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
480
Christoph Hellwig7d795ca2005-06-21 15:41:19 +1000481 xfs_efd_item_free(efdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 return (xfs_lsn_t)-1;
483}
484
485/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 * There isn't much you can do to push on an efd item. It is simply
487 * stuck waiting for the log to be flushed to disk.
488 */
489/*ARGSUSED*/
490STATIC void
491xfs_efd_item_push(xfs_efd_log_item_t *efdp)
492{
493 return;
494}
495
496/*
497 * The EFD dependency tracking op doesn't do squat. It can't because
498 * it doesn't know where the free extent is coming from. The dependency
499 * tracking has to be handled by the "enclosing" metadata object. For
500 * example, for inodes, the inode is locked throughout the extent freeing
501 * so the dependency should be recorded there.
502 */
503/*ARGSUSED*/
504STATIC void
505xfs_efd_item_committing(xfs_efd_log_item_t *efip, xfs_lsn_t lsn)
506{
507 return;
508}
509
510/*
511 * This is the ops vector shared by all efd log items.
512 */
David Chinner7989cb82007-02-10 18:34:56 +1100513static struct xfs_item_ops xfs_efd_item_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .iop_size = (uint(*)(xfs_log_item_t*))xfs_efd_item_size,
515 .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
516 xfs_efd_item_format,
517 .iop_pin = (void(*)(xfs_log_item_t*))xfs_efd_item_pin,
518 .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efd_item_unpin,
519 .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
520 xfs_efd_item_unpin_remove,
521 .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efd_item_trylock,
522 .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efd_item_unlock,
523 .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
524 xfs_efd_item_committed,
525 .iop_push = (void(*)(xfs_log_item_t*))xfs_efd_item_push,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .iop_pushbuf = NULL,
527 .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
528 xfs_efd_item_committing
529};
530
531
532/*
533 * Allocate and initialize an efd item with the given number of extents.
534 */
535xfs_efd_log_item_t *
536xfs_efd_init(xfs_mount_t *mp,
537 xfs_efi_log_item_t *efip,
538 uint nextents)
539
540{
541 xfs_efd_log_item_t *efdp;
542 uint size;
543
544 ASSERT(nextents > 0);
545 if (nextents > XFS_EFD_MAX_FAST_EXTENTS) {
546 size = (uint)(sizeof(xfs_efd_log_item_t) +
547 ((nextents - 1) * sizeof(xfs_extent_t)));
548 efdp = (xfs_efd_log_item_t*)kmem_zalloc(size, KM_SLEEP);
549 } else {
550 efdp = (xfs_efd_log_item_t*)kmem_zone_zalloc(xfs_efd_zone,
551 KM_SLEEP);
552 }
553
Dave Chinner43f5efc2010-03-23 10:10:00 +1100554 xfs_log_item_init(mp, &efdp->efd_item, XFS_LI_EFD, &xfs_efd_item_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 efdp->efd_efip = efip;
556 efdp->efd_format.efd_nextents = nextents;
557 efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
558
559 return (efdp);
560}