xfs: refactor log recovery icreate item dispatch for pass2 commit functions
[linux-2.6-block.git] / fs / xfs / xfs_extfree_item.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #include "xfs.h"
7 #include "xfs_fs.h"
8 #include "xfs_format.h"
9 #include "xfs_log_format.h"
10 #include "xfs_trans_resv.h"
11 #include "xfs_bit.h"
12 #include "xfs_shared.h"
13 #include "xfs_mount.h"
14 #include "xfs_defer.h"
15 #include "xfs_trans.h"
16 #include "xfs_trans_priv.h"
17 #include "xfs_extfree_item.h"
18 #include "xfs_log.h"
19 #include "xfs_btree.h"
20 #include "xfs_rmap.h"
21 #include "xfs_alloc.h"
22 #include "xfs_bmap.h"
23 #include "xfs_trace.h"
24 #include "xfs_error.h"
25 #include "xfs_log_recover.h"
26
27 kmem_zone_t     *xfs_efi_zone;
28 kmem_zone_t     *xfs_efd_zone;
29
30 static inline struct xfs_efi_log_item *EFI_ITEM(struct xfs_log_item *lip)
31 {
32         return container_of(lip, struct xfs_efi_log_item, efi_item);
33 }
34
35 void
36 xfs_efi_item_free(
37         struct xfs_efi_log_item *efip)
38 {
39         kmem_free(efip->efi_item.li_lv_shadow);
40         if (efip->efi_format.efi_nextents > XFS_EFI_MAX_FAST_EXTENTS)
41                 kmem_free(efip);
42         else
43                 kmem_cache_free(xfs_efi_zone, efip);
44 }
45
46 /*
47  * Freeing the efi requires that we remove it from the AIL if it has already
48  * been placed there. However, the EFI may not yet have been placed in the AIL
49  * when called by xfs_efi_release() from EFD processing due to the ordering of
50  * committed vs unpin operations in bulk insert operations. Hence the reference
51  * count to ensure only the last caller frees the EFI.
52  */
53 void
54 xfs_efi_release(
55         struct xfs_efi_log_item *efip)
56 {
57         ASSERT(atomic_read(&efip->efi_refcount) > 0);
58         if (atomic_dec_and_test(&efip->efi_refcount)) {
59                 xfs_trans_ail_delete(&efip->efi_item, SHUTDOWN_LOG_IO_ERROR);
60                 xfs_efi_item_free(efip);
61         }
62 }
63
64 /*
65  * This returns the number of iovecs needed to log the given efi item.
66  * We only need 1 iovec for an efi item.  It just logs the efi_log_format
67  * structure.
68  */
69 static inline int
70 xfs_efi_item_sizeof(
71         struct xfs_efi_log_item *efip)
72 {
73         return sizeof(struct xfs_efi_log_format) +
74                (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t);
75 }
76
77 STATIC void
78 xfs_efi_item_size(
79         struct xfs_log_item     *lip,
80         int                     *nvecs,
81         int                     *nbytes)
82 {
83         *nvecs += 1;
84         *nbytes += xfs_efi_item_sizeof(EFI_ITEM(lip));
85 }
86
87 /*
88  * This is called to fill in the vector of log iovecs for the
89  * given efi log item. We use only 1 iovec, and we point that
90  * at the efi_log_format structure embedded in the efi item.
91  * It is at this point that we assert that all of the extent
92  * slots in the efi item have been filled.
93  */
94 STATIC void
95 xfs_efi_item_format(
96         struct xfs_log_item     *lip,
97         struct xfs_log_vec      *lv)
98 {
99         struct xfs_efi_log_item *efip = EFI_ITEM(lip);
100         struct xfs_log_iovec    *vecp = NULL;
101
102         ASSERT(atomic_read(&efip->efi_next_extent) ==
103                                 efip->efi_format.efi_nextents);
104
105         efip->efi_format.efi_type = XFS_LI_EFI;
106         efip->efi_format.efi_size = 1;
107
108         xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFI_FORMAT,
109                         &efip->efi_format,
110                         xfs_efi_item_sizeof(efip));
111 }
112
113
114 /*
115  * The unpin operation is the last place an EFI is manipulated in the log. It is
116  * either inserted in the AIL or aborted in the event of a log I/O error. In
117  * either case, the EFI transaction has been successfully committed to make it
118  * this far. Therefore, we expect whoever committed the EFI to either construct
119  * and commit the EFD or drop the EFD's reference in the event of error. Simply
120  * drop the log's EFI reference now that the log is done with it.
121  */
122 STATIC void
123 xfs_efi_item_unpin(
124         struct xfs_log_item     *lip,
125         int                     remove)
126 {
127         struct xfs_efi_log_item *efip = EFI_ITEM(lip);
128         xfs_efi_release(efip);
129 }
130
131 /*
132  * The EFI has been either committed or aborted if the transaction has been
133  * cancelled. If the transaction was cancelled, an EFD isn't going to be
134  * constructed and thus we free the EFI here directly.
135  */
136 STATIC void
137 xfs_efi_item_release(
138         struct xfs_log_item     *lip)
139 {
140         xfs_efi_release(EFI_ITEM(lip));
141 }
142
143 static const struct xfs_item_ops xfs_efi_item_ops = {
144         .iop_size       = xfs_efi_item_size,
145         .iop_format     = xfs_efi_item_format,
146         .iop_unpin      = xfs_efi_item_unpin,
147         .iop_release    = xfs_efi_item_release,
148 };
149
150
151 /*
152  * Allocate and initialize an efi item with the given number of extents.
153  */
154 struct xfs_efi_log_item *
155 xfs_efi_init(
156         struct xfs_mount        *mp,
157         uint                    nextents)
158
159 {
160         struct xfs_efi_log_item *efip;
161         uint                    size;
162
163         ASSERT(nextents > 0);
164         if (nextents > XFS_EFI_MAX_FAST_EXTENTS) {
165                 size = (uint)(sizeof(struct xfs_efi_log_item) +
166                         ((nextents - 1) * sizeof(xfs_extent_t)));
167                 efip = kmem_zalloc(size, 0);
168         } else {
169                 efip = kmem_zone_zalloc(xfs_efi_zone, 0);
170         }
171
172         xfs_log_item_init(mp, &efip->efi_item, XFS_LI_EFI, &xfs_efi_item_ops);
173         efip->efi_format.efi_nextents = nextents;
174         efip->efi_format.efi_id = (uintptr_t)(void *)efip;
175         atomic_set(&efip->efi_next_extent, 0);
176         atomic_set(&efip->efi_refcount, 2);
177
178         return efip;
179 }
180
181 /*
182  * Copy an EFI format buffer from the given buf, and into the destination
183  * EFI format structure.
184  * The given buffer can be in 32 bit or 64 bit form (which has different padding),
185  * one of which will be the native format for this kernel.
186  * It will handle the conversion of formats if necessary.
187  */
188 int
189 xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
190 {
191         xfs_efi_log_format_t *src_efi_fmt = buf->i_addr;
192         uint i;
193         uint len = sizeof(xfs_efi_log_format_t) + 
194                 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t);  
195         uint len32 = sizeof(xfs_efi_log_format_32_t) + 
196                 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_32_t);  
197         uint len64 = sizeof(xfs_efi_log_format_64_t) + 
198                 (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_64_t);  
199
200         if (buf->i_len == len) {
201                 memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len);
202                 return 0;
203         } else if (buf->i_len == len32) {
204                 xfs_efi_log_format_32_t *src_efi_fmt_32 = buf->i_addr;
205
206                 dst_efi_fmt->efi_type     = src_efi_fmt_32->efi_type;
207                 dst_efi_fmt->efi_size     = src_efi_fmt_32->efi_size;
208                 dst_efi_fmt->efi_nextents = src_efi_fmt_32->efi_nextents;
209                 dst_efi_fmt->efi_id       = src_efi_fmt_32->efi_id;
210                 for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
211                         dst_efi_fmt->efi_extents[i].ext_start =
212                                 src_efi_fmt_32->efi_extents[i].ext_start;
213                         dst_efi_fmt->efi_extents[i].ext_len =
214                                 src_efi_fmt_32->efi_extents[i].ext_len;
215                 }
216                 return 0;
217         } else if (buf->i_len == len64) {
218                 xfs_efi_log_format_64_t *src_efi_fmt_64 = buf->i_addr;
219
220                 dst_efi_fmt->efi_type     = src_efi_fmt_64->efi_type;
221                 dst_efi_fmt->efi_size     = src_efi_fmt_64->efi_size;
222                 dst_efi_fmt->efi_nextents = src_efi_fmt_64->efi_nextents;
223                 dst_efi_fmt->efi_id       = src_efi_fmt_64->efi_id;
224                 for (i = 0; i < dst_efi_fmt->efi_nextents; i++) {
225                         dst_efi_fmt->efi_extents[i].ext_start =
226                                 src_efi_fmt_64->efi_extents[i].ext_start;
227                         dst_efi_fmt->efi_extents[i].ext_len =
228                                 src_efi_fmt_64->efi_extents[i].ext_len;
229                 }
230                 return 0;
231         }
232         XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
233         return -EFSCORRUPTED;
234 }
235
236 static inline struct xfs_efd_log_item *EFD_ITEM(struct xfs_log_item *lip)
237 {
238         return container_of(lip, struct xfs_efd_log_item, efd_item);
239 }
240
241 STATIC void
242 xfs_efd_item_free(struct xfs_efd_log_item *efdp)
243 {
244         kmem_free(efdp->efd_item.li_lv_shadow);
245         if (efdp->efd_format.efd_nextents > XFS_EFD_MAX_FAST_EXTENTS)
246                 kmem_free(efdp);
247         else
248                 kmem_cache_free(xfs_efd_zone, efdp);
249 }
250
251 /*
252  * This returns the number of iovecs needed to log the given efd item.
253  * We only need 1 iovec for an efd item.  It just logs the efd_log_format
254  * structure.
255  */
256 static inline int
257 xfs_efd_item_sizeof(
258         struct xfs_efd_log_item *efdp)
259 {
260         return sizeof(xfs_efd_log_format_t) +
261                (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t);
262 }
263
264 STATIC void
265 xfs_efd_item_size(
266         struct xfs_log_item     *lip,
267         int                     *nvecs,
268         int                     *nbytes)
269 {
270         *nvecs += 1;
271         *nbytes += xfs_efd_item_sizeof(EFD_ITEM(lip));
272 }
273
274 /*
275  * This is called to fill in the vector of log iovecs for the
276  * given efd log item. We use only 1 iovec, and we point that
277  * at the efd_log_format structure embedded in the efd item.
278  * It is at this point that we assert that all of the extent
279  * slots in the efd item have been filled.
280  */
281 STATIC void
282 xfs_efd_item_format(
283         struct xfs_log_item     *lip,
284         struct xfs_log_vec      *lv)
285 {
286         struct xfs_efd_log_item *efdp = EFD_ITEM(lip);
287         struct xfs_log_iovec    *vecp = NULL;
288
289         ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents);
290
291         efdp->efd_format.efd_type = XFS_LI_EFD;
292         efdp->efd_format.efd_size = 1;
293
294         xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_EFD_FORMAT,
295                         &efdp->efd_format,
296                         xfs_efd_item_sizeof(efdp));
297 }
298
299 /*
300  * The EFD is either committed or aborted if the transaction is cancelled. If
301  * the transaction is cancelled, drop our reference to the EFI and free the EFD.
302  */
303 STATIC void
304 xfs_efd_item_release(
305         struct xfs_log_item     *lip)
306 {
307         struct xfs_efd_log_item *efdp = EFD_ITEM(lip);
308
309         xfs_efi_release(efdp->efd_efip);
310         xfs_efd_item_free(efdp);
311 }
312
313 static const struct xfs_item_ops xfs_efd_item_ops = {
314         .flags          = XFS_ITEM_RELEASE_WHEN_COMMITTED,
315         .iop_size       = xfs_efd_item_size,
316         .iop_format     = xfs_efd_item_format,
317         .iop_release    = xfs_efd_item_release,
318 };
319
320 /*
321  * Allocate an "extent free done" log item that will hold nextents worth of
322  * extents.  The caller must use all nextents extents, because we are not
323  * flexible about this at all.
324  */
325 static struct xfs_efd_log_item *
326 xfs_trans_get_efd(
327         struct xfs_trans                *tp,
328         struct xfs_efi_log_item         *efip,
329         unsigned int                    nextents)
330 {
331         struct xfs_efd_log_item         *efdp;
332
333         ASSERT(nextents > 0);
334
335         if (nextents > XFS_EFD_MAX_FAST_EXTENTS) {
336                 efdp = kmem_zalloc(sizeof(struct xfs_efd_log_item) +
337                                 (nextents - 1) * sizeof(struct xfs_extent),
338                                 0);
339         } else {
340                 efdp = kmem_zone_zalloc(xfs_efd_zone, 0);
341         }
342
343         xfs_log_item_init(tp->t_mountp, &efdp->efd_item, XFS_LI_EFD,
344                           &xfs_efd_item_ops);
345         efdp->efd_efip = efip;
346         efdp->efd_format.efd_nextents = nextents;
347         efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
348
349         xfs_trans_add_item(tp, &efdp->efd_item);
350         return efdp;
351 }
352
353 /*
354  * Free an extent and log it to the EFD. Note that the transaction is marked
355  * dirty regardless of whether the extent free succeeds or fails to support the
356  * EFI/EFD lifecycle rules.
357  */
358 static int
359 xfs_trans_free_extent(
360         struct xfs_trans                *tp,
361         struct xfs_efd_log_item         *efdp,
362         xfs_fsblock_t                   start_block,
363         xfs_extlen_t                    ext_len,
364         const struct xfs_owner_info     *oinfo,
365         bool                            skip_discard)
366 {
367         struct xfs_mount                *mp = tp->t_mountp;
368         struct xfs_extent               *extp;
369         uint                            next_extent;
370         xfs_agnumber_t                  agno = XFS_FSB_TO_AGNO(mp, start_block);
371         xfs_agblock_t                   agbno = XFS_FSB_TO_AGBNO(mp,
372                                                                 start_block);
373         int                             error;
374
375         trace_xfs_bmap_free_deferred(tp->t_mountp, agno, 0, agbno, ext_len);
376
377         error = __xfs_free_extent(tp, start_block, ext_len,
378                                   oinfo, XFS_AG_RESV_NONE, skip_discard);
379         /*
380          * Mark the transaction dirty, even on error. This ensures the
381          * transaction is aborted, which:
382          *
383          * 1.) releases the EFI and frees the EFD
384          * 2.) shuts down the filesystem
385          */
386         tp->t_flags |= XFS_TRANS_DIRTY;
387         set_bit(XFS_LI_DIRTY, &efdp->efd_item.li_flags);
388
389         next_extent = efdp->efd_next_extent;
390         ASSERT(next_extent < efdp->efd_format.efd_nextents);
391         extp = &(efdp->efd_format.efd_extents[next_extent]);
392         extp->ext_start = start_block;
393         extp->ext_len = ext_len;
394         efdp->efd_next_extent++;
395
396         return error;
397 }
398
399 /* Sort bmap items by AG. */
400 static int
401 xfs_extent_free_diff_items(
402         void                            *priv,
403         struct list_head                *a,
404         struct list_head                *b)
405 {
406         struct xfs_mount                *mp = priv;
407         struct xfs_extent_free_item     *ra;
408         struct xfs_extent_free_item     *rb;
409
410         ra = container_of(a, struct xfs_extent_free_item, xefi_list);
411         rb = container_of(b, struct xfs_extent_free_item, xefi_list);
412         return  XFS_FSB_TO_AGNO(mp, ra->xefi_startblock) -
413                 XFS_FSB_TO_AGNO(mp, rb->xefi_startblock);
414 }
415
416 /* Log a free extent to the intent item. */
417 STATIC void
418 xfs_extent_free_log_item(
419         struct xfs_trans                *tp,
420         struct xfs_efi_log_item         *efip,
421         struct xfs_extent_free_item     *free)
422 {
423         uint                            next_extent;
424         struct xfs_extent               *extp;
425
426         tp->t_flags |= XFS_TRANS_DIRTY;
427         set_bit(XFS_LI_DIRTY, &efip->efi_item.li_flags);
428
429         /*
430          * atomic_inc_return gives us the value after the increment;
431          * we want to use it as an array index so we need to subtract 1 from
432          * it.
433          */
434         next_extent = atomic_inc_return(&efip->efi_next_extent) - 1;
435         ASSERT(next_extent < efip->efi_format.efi_nextents);
436         extp = &efip->efi_format.efi_extents[next_extent];
437         extp->ext_start = free->xefi_startblock;
438         extp->ext_len = free->xefi_blockcount;
439 }
440
441 static struct xfs_log_item *
442 xfs_extent_free_create_intent(
443         struct xfs_trans                *tp,
444         struct list_head                *items,
445         unsigned int                    count,
446         bool                            sort)
447 {
448         struct xfs_mount                *mp = tp->t_mountp;
449         struct xfs_efi_log_item         *efip = xfs_efi_init(mp, count);
450         struct xfs_extent_free_item     *free;
451
452         ASSERT(count > 0);
453
454         xfs_trans_add_item(tp, &efip->efi_item);
455         if (sort)
456                 list_sort(mp, items, xfs_extent_free_diff_items);
457         list_for_each_entry(free, items, xefi_list)
458                 xfs_extent_free_log_item(tp, efip, free);
459         return &efip->efi_item;
460 }
461
462 /* Get an EFD so we can process all the free extents. */
463 static struct xfs_log_item *
464 xfs_extent_free_create_done(
465         struct xfs_trans                *tp,
466         struct xfs_log_item             *intent,
467         unsigned int                    count)
468 {
469         return &xfs_trans_get_efd(tp, EFI_ITEM(intent), count)->efd_item;
470 }
471
472 /* Process a free extent. */
473 STATIC int
474 xfs_extent_free_finish_item(
475         struct xfs_trans                *tp,
476         struct xfs_log_item             *done,
477         struct list_head                *item,
478         struct xfs_btree_cur            **state)
479 {
480         struct xfs_extent_free_item     *free;
481         int                             error;
482
483         free = container_of(item, struct xfs_extent_free_item, xefi_list);
484         error = xfs_trans_free_extent(tp, EFD_ITEM(done),
485                         free->xefi_startblock,
486                         free->xefi_blockcount,
487                         &free->xefi_oinfo, free->xefi_skip_discard);
488         kmem_free(free);
489         return error;
490 }
491
492 /* Abort all pending EFIs. */
493 STATIC void
494 xfs_extent_free_abort_intent(
495         struct xfs_log_item             *intent)
496 {
497         xfs_efi_release(EFI_ITEM(intent));
498 }
499
500 /* Cancel a free extent. */
501 STATIC void
502 xfs_extent_free_cancel_item(
503         struct list_head                *item)
504 {
505         struct xfs_extent_free_item     *free;
506
507         free = container_of(item, struct xfs_extent_free_item, xefi_list);
508         kmem_free(free);
509 }
510
511 const struct xfs_defer_op_type xfs_extent_free_defer_type = {
512         .max_items      = XFS_EFI_MAX_FAST_EXTENTS,
513         .create_intent  = xfs_extent_free_create_intent,
514         .abort_intent   = xfs_extent_free_abort_intent,
515         .create_done    = xfs_extent_free_create_done,
516         .finish_item    = xfs_extent_free_finish_item,
517         .cancel_item    = xfs_extent_free_cancel_item,
518 };
519
520 /*
521  * AGFL blocks are accounted differently in the reserve pools and are not
522  * inserted into the busy extent list.
523  */
524 STATIC int
525 xfs_agfl_free_finish_item(
526         struct xfs_trans                *tp,
527         struct xfs_log_item             *done,
528         struct list_head                *item,
529         struct xfs_btree_cur            **state)
530 {
531         struct xfs_mount                *mp = tp->t_mountp;
532         struct xfs_efd_log_item         *efdp = EFD_ITEM(done);
533         struct xfs_extent_free_item     *free;
534         struct xfs_extent               *extp;
535         struct xfs_buf                  *agbp;
536         int                             error;
537         xfs_agnumber_t                  agno;
538         xfs_agblock_t                   agbno;
539         uint                            next_extent;
540
541         free = container_of(item, struct xfs_extent_free_item, xefi_list);
542         ASSERT(free->xefi_blockcount == 1);
543         agno = XFS_FSB_TO_AGNO(mp, free->xefi_startblock);
544         agbno = XFS_FSB_TO_AGBNO(mp, free->xefi_startblock);
545
546         trace_xfs_agfl_free_deferred(mp, agno, 0, agbno, free->xefi_blockcount);
547
548         error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
549         if (!error)
550                 error = xfs_free_agfl_block(tp, agno, agbno, agbp,
551                                             &free->xefi_oinfo);
552
553         /*
554          * Mark the transaction dirty, even on error. This ensures the
555          * transaction is aborted, which:
556          *
557          * 1.) releases the EFI and frees the EFD
558          * 2.) shuts down the filesystem
559          */
560         tp->t_flags |= XFS_TRANS_DIRTY;
561         set_bit(XFS_LI_DIRTY, &efdp->efd_item.li_flags);
562
563         next_extent = efdp->efd_next_extent;
564         ASSERT(next_extent < efdp->efd_format.efd_nextents);
565         extp = &(efdp->efd_format.efd_extents[next_extent]);
566         extp->ext_start = free->xefi_startblock;
567         extp->ext_len = free->xefi_blockcount;
568         efdp->efd_next_extent++;
569
570         kmem_free(free);
571         return error;
572 }
573
574 /* sub-type with special handling for AGFL deferred frees */
575 const struct xfs_defer_op_type xfs_agfl_free_defer_type = {
576         .max_items      = XFS_EFI_MAX_FAST_EXTENTS,
577         .create_intent  = xfs_extent_free_create_intent,
578         .abort_intent   = xfs_extent_free_abort_intent,
579         .create_done    = xfs_extent_free_create_done,
580         .finish_item    = xfs_agfl_free_finish_item,
581         .cancel_item    = xfs_extent_free_cancel_item,
582 };
583
584 /*
585  * Process an extent free intent item that was recovered from
586  * the log.  We need to free the extents that it describes.
587  */
588 int
589 xfs_efi_recover(
590         struct xfs_mount        *mp,
591         struct xfs_efi_log_item *efip)
592 {
593         struct xfs_efd_log_item *efdp;
594         struct xfs_trans        *tp;
595         int                     i;
596         int                     error = 0;
597         xfs_extent_t            *extp;
598         xfs_fsblock_t           startblock_fsb;
599
600         ASSERT(!test_bit(XFS_EFI_RECOVERED, &efip->efi_flags));
601
602         /*
603          * First check the validity of the extents described by the
604          * EFI.  If any are bad, then assume that all are bad and
605          * just toss the EFI.
606          */
607         for (i = 0; i < efip->efi_format.efi_nextents; i++) {
608                 extp = &efip->efi_format.efi_extents[i];
609                 startblock_fsb = XFS_BB_TO_FSB(mp,
610                                    XFS_FSB_TO_DADDR(mp, extp->ext_start));
611                 if (startblock_fsb == 0 ||
612                     extp->ext_len == 0 ||
613                     startblock_fsb >= mp->m_sb.sb_dblocks ||
614                     extp->ext_len >= mp->m_sb.sb_agblocks) {
615                         /*
616                          * This will pull the EFI from the AIL and
617                          * free the memory associated with it.
618                          */
619                         set_bit(XFS_EFI_RECOVERED, &efip->efi_flags);
620                         xfs_efi_release(efip);
621                         return -EFSCORRUPTED;
622                 }
623         }
624
625         error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp);
626         if (error)
627                 return error;
628         efdp = xfs_trans_get_efd(tp, efip, efip->efi_format.efi_nextents);
629
630         for (i = 0; i < efip->efi_format.efi_nextents; i++) {
631                 extp = &efip->efi_format.efi_extents[i];
632                 error = xfs_trans_free_extent(tp, efdp, extp->ext_start,
633                                               extp->ext_len,
634                                               &XFS_RMAP_OINFO_ANY_OWNER, false);
635                 if (error)
636                         goto abort_error;
637
638         }
639
640         set_bit(XFS_EFI_RECOVERED, &efip->efi_flags);
641         error = xfs_trans_commit(tp);
642         return error;
643
644 abort_error:
645         xfs_trans_cancel(tp);
646         return error;
647 }
648
649 const struct xlog_recover_item_ops xlog_efi_item_ops = {
650         .item_type              = XFS_LI_EFI,
651 };
652
653 const struct xlog_recover_item_ops xlog_efd_item_ops = {
654         .item_type              = XFS_LI_EFD,
655 };