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