^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-2002,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_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "xfs_inode_item.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "xfs_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "xfs_trans_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "xfs_buf_item.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "xfs_log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "xfs_error.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) kmem_zone_t *xfs_ili_zone; /* inode log item zone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return container_of(lip, struct xfs_inode_log_item, ili_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) xfs_inode_item_data_fork_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct xfs_inode_log_item *iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int *nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) switch (ip->i_df.if_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) case XFS_DINODE_FMT_EXTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if ((iip->ili_fields & XFS_ILOG_DEXT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ip->i_df.if_nextents > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ip->i_df.if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* worst case, doesn't subtract delalloc extents */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *nbytes += XFS_IFORK_DSIZE(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) case XFS_DINODE_FMT_BTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ip->i_df.if_broot_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *nbytes += ip->i_df.if_broot_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) case XFS_DINODE_FMT_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if ((iip->ili_fields & XFS_ILOG_DDATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ip->i_df.if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) *nbytes += roundup(ip->i_df.if_bytes, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) case XFS_DINODE_FMT_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ASSERT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) xfs_inode_item_attr_fork_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct xfs_inode_log_item *iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int *nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) switch (ip->i_afp->if_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) case XFS_DINODE_FMT_EXTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if ((iip->ili_fields & XFS_ILOG_AEXT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ip->i_afp->if_nextents > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ip->i_afp->if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* worst case, doesn't subtract unused space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) *nbytes += XFS_IFORK_ASIZE(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) case XFS_DINODE_FMT_BTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ip->i_afp->if_broot_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *nbytes += ip->i_afp->if_broot_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case XFS_DINODE_FMT_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if ((iip->ili_fields & XFS_ILOG_ADATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) ip->i_afp->if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) *nbytes += roundup(ip->i_afp->if_bytes, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) *nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ASSERT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * This returns the number of iovecs needed to log the given inode item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * We need one iovec for the inode log format structure, one for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * inode core, and possibly one for the inode data/extents/b-tree root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * and one for the inode attribute data/extents/b-tree root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) xfs_inode_item_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int *nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int *nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *nvecs += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) *nbytes += sizeof(struct xfs_inode_log_format) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) xfs_log_dinode_size(ip->i_mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) xfs_inode_item_data_fork_size(iip, nvecs, nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (XFS_IFORK_Q(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) xfs_inode_item_attr_fork_size(iip, nvecs, nbytes);
^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) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) xfs_inode_item_format_data_fork(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct xfs_inode_log_item *iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct xfs_inode_log_format *ilf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct xfs_log_vec *lv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct xfs_log_iovec **vecp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) size_t data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) switch (ip->i_df.if_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) case XFS_DINODE_FMT_EXTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if ((iip->ili_fields & XFS_ILOG_DEXT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ip->i_df.if_nextents > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ip->i_df.if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct xfs_bmbt_rec *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ASSERT(xfs_iext_count(&ip->i_df) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) data_bytes = xfs_iextents_copy(ip, p, XFS_DATA_FORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) xlog_finish_iovec(lv, *vecp, data_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ASSERT(data_bytes <= ip->i_df.if_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) ilf->ilf_dsize = data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) iip->ili_fields &= ~XFS_ILOG_DEXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) case XFS_DINODE_FMT_BTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) ~(XFS_ILOG_DDATA | XFS_ILOG_DEXT | XFS_ILOG_DEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if ((iip->ili_fields & XFS_ILOG_DBROOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) ip->i_df.if_broot_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ASSERT(ip->i_df.if_broot != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IBROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ip->i_df.if_broot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ip->i_df.if_broot_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ilf->ilf_dsize = ip->i_df.if_broot_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) ASSERT(!(iip->ili_fields &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) XFS_ILOG_DBROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) iip->ili_fields &= ~XFS_ILOG_DBROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case XFS_DINODE_FMT_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) ~(XFS_ILOG_DEXT | XFS_ILOG_DBROOT | XFS_ILOG_DEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if ((iip->ili_fields & XFS_ILOG_DDATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) ip->i_df.if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Round i_bytes up to a word boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * The underlying memory is guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * to be there by xfs_idata_realloc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) data_bytes = roundup(ip->i_df.if_bytes, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ASSERT(ip->i_df.if_u1.if_data != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ASSERT(ip->i_d.di_size > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_ILOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) ip->i_df.if_u1.if_data, data_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ilf->ilf_dsize = (unsigned)data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) iip->ili_fields &= ~XFS_ILOG_DDATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case XFS_DINODE_FMT_DEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ~(XFS_ILOG_DDATA | XFS_ILOG_DBROOT | XFS_ILOG_DEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (iip->ili_fields & XFS_ILOG_DEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ilf->ilf_u.ilfu_rdev = sysv_encode_dev(VFS_I(ip)->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) ASSERT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) xfs_inode_item_format_attr_fork(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct xfs_inode_log_item *iip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct xfs_inode_log_format *ilf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct xfs_log_vec *lv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct xfs_log_iovec **vecp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) size_t data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) switch (ip->i_afp->if_format) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) case XFS_DINODE_FMT_EXTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if ((iip->ili_fields & XFS_ILOG_AEXT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) ip->i_afp->if_nextents > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) ip->i_afp->if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct xfs_bmbt_rec *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ASSERT(xfs_iext_count(ip->i_afp) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ip->i_afp->if_nextents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) p = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_EXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) data_bytes = xfs_iextents_copy(ip, p, XFS_ATTR_FORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) xlog_finish_iovec(lv, *vecp, data_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) ilf->ilf_asize = data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) iip->ili_fields &= ~XFS_ILOG_AEXT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) case XFS_DINODE_FMT_BTREE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ~(XFS_ILOG_ADATA | XFS_ILOG_AEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if ((iip->ili_fields & XFS_ILOG_ABROOT) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) ip->i_afp->if_broot_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ASSERT(ip->i_afp->if_broot != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_BROOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ip->i_afp->if_broot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ip->i_afp->if_broot_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ilf->ilf_asize = ip->i_afp->if_broot_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) iip->ili_fields &= ~XFS_ILOG_ABROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case XFS_DINODE_FMT_LOCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ~(XFS_ILOG_AEXT | XFS_ILOG_ABROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if ((iip->ili_fields & XFS_ILOG_ADATA) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ip->i_afp->if_bytes > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Round i_bytes up to a word boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * The underlying memory is guaranteed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * to be there by xfs_idata_realloc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) data_bytes = roundup(ip->i_afp->if_bytes, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) ASSERT(ip->i_afp->if_u1.if_data != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_IATTR_LOCAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ip->i_afp->if_u1.if_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) data_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ilf->ilf_asize = (unsigned)data_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) ilf->ilf_size++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) iip->ili_fields &= ~XFS_ILOG_ADATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ASSERT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Convert an incore timestamp to a log timestamp. Note that the log format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * specifies host endian format!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static inline xfs_ictimestamp_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) xfs_inode_to_log_dinode_ts(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) const struct timespec64 tv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct xfs_legacy_ictimestamp *lits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) xfs_ictimestamp_t its;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (xfs_inode_has_bigtime(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return xfs_inode_encode_bigtime(tv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) lits = (struct xfs_legacy_ictimestamp *)&its;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) lits->t_sec = tv.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) lits->t_nsec = tv.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return its;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) xfs_inode_to_log_dinode(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct xfs_log_dinode *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) xfs_lsn_t lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) struct xfs_icdinode *from = &ip->i_d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) struct inode *inode = VFS_I(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) to->di_magic = XFS_DINODE_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) to->di_format = xfs_ifork_format(&ip->i_df);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) to->di_uid = i_uid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) to->di_gid = i_gid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) to->di_projid_lo = from->di_projid & 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) to->di_projid_hi = from->di_projid >> 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) memset(to->di_pad, 0, sizeof(to->di_pad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) memset(to->di_pad3, 0, sizeof(to->di_pad3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) to->di_atime = xfs_inode_to_log_dinode_ts(ip, inode->i_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) to->di_mtime = xfs_inode_to_log_dinode_ts(ip, inode->i_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) to->di_ctime = xfs_inode_to_log_dinode_ts(ip, inode->i_ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) to->di_nlink = inode->i_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) to->di_gen = inode->i_generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) to->di_mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) to->di_size = from->di_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) to->di_nblocks = from->di_nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) to->di_extsize = from->di_extsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) to->di_nextents = xfs_ifork_nextents(&ip->i_df);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) to->di_anextents = xfs_ifork_nextents(ip->i_afp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) to->di_forkoff = from->di_forkoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) to->di_aformat = xfs_ifork_format(ip->i_afp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) to->di_dmevmask = from->di_dmevmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) to->di_dmstate = from->di_dmstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) to->di_flags = from->di_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* log a dummy value to ensure log structure is fully initialised */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) to->di_next_unlinked = NULLAGINO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (xfs_sb_version_has_v3inode(&ip->i_mount->m_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) to->di_version = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) to->di_changecount = inode_peek_iversion(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) to->di_crtime = xfs_inode_to_log_dinode_ts(ip, from->di_crtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) to->di_flags2 = from->di_flags2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) to->di_cowextsize = from->di_cowextsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) to->di_ino = ip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) to->di_lsn = lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) memset(to->di_pad2, 0, sizeof(to->di_pad2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) uuid_copy(&to->di_uuid, &ip->i_mount->m_sb.sb_meta_uuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) to->di_flushiter = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) to->di_version = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) to->di_flushiter = from->di_flushiter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * Format the inode core. Current timestamp data is only in the VFS inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * fields, so we need to grab them from there. Hence rather than just copying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * the XFS inode core structure, format the fields directly into the iovec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) xfs_inode_item_format_core(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct xfs_log_vec *lv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct xfs_log_iovec **vecp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct xfs_log_dinode *dic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) dic = xlog_prepare_iovec(lv, vecp, XLOG_REG_TYPE_ICORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) xfs_inode_to_log_dinode(ip, dic, ip->i_itemp->ili_item.li_lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) xlog_finish_iovec(lv, *vecp, xfs_log_dinode_size(ip->i_mount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * This is called to fill in the vector of log iovecs for the given inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * log item. It fills the first item with an inode log format structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * the second with the on-disk inode structure, and a possible third and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * fourth with the inode data/extents/b-tree root and inode attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * data/extents/b-tree root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Note: Always use the 64 bit inode log format structure so we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * leave an uninitialised hole in the format item on 64 bit systems. Log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * recovery on 32 bit systems handles this just fine, so there's no reason
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * for not using an initialising the properly padded structure all the time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) xfs_inode_item_format(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct xfs_log_vec *lv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct xfs_log_iovec *vecp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) struct xfs_inode_log_format *ilf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ilf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_IFORMAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ilf->ilf_type = XFS_LI_INODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ilf->ilf_ino = ip->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ilf->ilf_blkno = ip->i_imap.im_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) ilf->ilf_len = ip->i_imap.im_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ilf->ilf_boffset = ip->i_imap.im_boffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ilf->ilf_fields = XFS_ILOG_CORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) ilf->ilf_size = 2; /* format + core */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * make sure we don't leak uninitialised data into the log in the case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * when we don't log every field in the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ilf->ilf_dsize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) ilf->ilf_asize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ilf->ilf_pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) memset(&ilf->ilf_u, 0, sizeof(ilf->ilf_u));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) xlog_finish_iovec(lv, vecp, sizeof(*ilf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) xfs_inode_item_format_core(ip, lv, &vecp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) xfs_inode_item_format_data_fork(iip, ilf, lv, &vecp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) if (XFS_IFORK_Q(ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) xfs_inode_item_format_attr_fork(iip, ilf, lv, &vecp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) iip->ili_fields &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ~(XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) /* update the format with the exact fields we actually logged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ilf->ilf_fields |= (iip->ili_fields & ~XFS_ILOG_TIMESTAMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * This is called to pin the inode associated with the inode log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * item in memory so it cannot be written out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) xfs_inode_item_pin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct xfs_log_item *lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ASSERT(lip->li_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) trace_xfs_inode_pin(ip, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) atomic_inc(&ip->i_pincount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) * This is called to unpin the inode associated with the inode log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * item which was previously pinned with a call to xfs_inode_item_pin().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * Note that unpin can race with inode cluster buffer freeing marking the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * stale. In that case, flush completions are run from the buffer unpin call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * which may happen before the inode is unpinned. If we lose the race, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * will be no buffer attached to the log item, but the inode will be marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * XFS_ISTALE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) xfs_inode_item_unpin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct xfs_inode *ip = INODE_ITEM(lip)->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) trace_xfs_inode_unpin(ip, _RET_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) ASSERT(lip->li_buf || xfs_iflags_test(ip, XFS_ISTALE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ASSERT(atomic_read(&ip->i_pincount) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (atomic_dec_and_test(&ip->i_pincount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) wake_up_bit(&ip->i_flags, __XFS_IPINNED_BIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) STATIC uint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) xfs_inode_item_push(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct list_head *buffer_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) __releases(&lip->li_ailp->ail_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) __acquires(&lip->li_ailp->ail_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct xfs_buf *bp = lip->li_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) uint rval = XFS_ITEM_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) ASSERT(iip->ili_item.li_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (xfs_ipincount(ip) > 0 || xfs_buf_ispinned(bp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) (ip->i_flags & XFS_ISTALE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return XFS_ITEM_PINNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) if (xfs_iflags_test(ip, XFS_IFLUSHING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return XFS_ITEM_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (!xfs_buf_trylock(bp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return XFS_ITEM_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) spin_unlock(&lip->li_ailp->ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * We need to hold a reference for flushing the cluster buffer as it may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * fail the buffer without IO submission. In which case, we better get a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) * reference for that completion because otherwise we don't get a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) * reference for IO until we queue the buffer for delwri submission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) xfs_buf_hold(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) error = xfs_iflush_cluster(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (!xfs_buf_delwri_queue(bp, buffer_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) rval = XFS_ITEM_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * Release the buffer if we were unable to flush anything. On
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * any other error, the buffer has already been released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (error == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) rval = XFS_ITEM_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) spin_lock(&lip->li_ailp->ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * Unlock the inode associated with the inode log item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) xfs_inode_item_release(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) struct xfs_log_item *lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) unsigned short lock_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) ASSERT(ip->i_itemp != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) lock_flags = iip->ili_lock_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) iip->ili_lock_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (lock_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) xfs_iunlock(ip, lock_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * This is called to find out where the oldest active copy of the inode log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * item in the on disk log resides now that the last log write of it completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * at the given lsn. Since we always re-log all dirty data in an inode, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * latest copy in the on disk log is the only one that matters. Therefore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * simply return the given lsn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * If the inode has been marked stale because the cluster is being freed, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * don't want to (re-)insert this inode into the AIL. There is a race condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * where the cluster buffer may be unpinned before the inode is inserted into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * the AIL during transaction committed processing. If the buffer is unpinned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * before the inode item has been committed and inserted, then it is possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) * for the buffer to be written and IO completes before the inode is inserted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * into the AIL. In that case, we'd be inserting a clean, stale inode into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * AIL which will never get removed. It will, however, get reclaimed which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) * triggers an assert in xfs_inode_free() complaining about freein an inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) * still in the AIL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) * To avoid this, just unpin the inode directly and return a LSN of -1 so the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * transaction committed code knows that it does not need to do any further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * processing on the item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) STATIC xfs_lsn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) xfs_inode_item_committed(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) xfs_lsn_t lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct xfs_inode *ip = iip->ili_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (xfs_iflags_test(ip, XFS_ISTALE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) xfs_inode_item_unpin(lip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) xfs_inode_item_committing(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct xfs_log_item *lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) xfs_lsn_t commit_lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) INODE_ITEM(lip)->ili_last_lsn = commit_lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return xfs_inode_item_release(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) static const struct xfs_item_ops xfs_inode_item_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) .iop_size = xfs_inode_item_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) .iop_format = xfs_inode_item_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) .iop_pin = xfs_inode_item_pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) .iop_unpin = xfs_inode_item_unpin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) .iop_release = xfs_inode_item_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .iop_committed = xfs_inode_item_committed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) .iop_push = xfs_inode_item_push,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) .iop_committing = xfs_inode_item_committing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * Initialize the inode log item for a newly allocated (in-core) inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) xfs_inode_item_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct xfs_inode_log_item *iip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) ASSERT(ip->i_itemp == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) iip = ip->i_itemp = kmem_cache_zalloc(xfs_ili_zone,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) GFP_KERNEL | __GFP_NOFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) iip->ili_inode = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) spin_lock_init(&iip->ili_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) xfs_log_item_init(mp, &iip->ili_item, XFS_LI_INODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) &xfs_inode_item_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^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) * Free the inode log item and any memory hanging off of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) xfs_inode_item_destroy(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct xfs_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) struct xfs_inode_log_item *iip = ip->i_itemp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) ASSERT(iip->ili_item.li_buf == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) ip->i_itemp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) kmem_free(iip->ili_item.li_lv_shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) kmem_cache_free(xfs_ili_zone, iip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * We only want to pull the item from the AIL if it is actually there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * and its location in the log has not changed since we started the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * flush. Thus, we only bother if the inode's lsn has not changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) xfs_iflush_ail_updates(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct xfs_ail *ailp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct list_head *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct xfs_log_item *lip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) xfs_lsn_t tail_lsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* this is an opencoded batch version of xfs_trans_ail_delete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) spin_lock(&ailp->ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) list_for_each_entry(lip, list, li_bio_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) xfs_lsn_t lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) clear_bit(XFS_LI_FAILED, &lip->li_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (INODE_ITEM(lip)->ili_flush_lsn != lip->li_lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) lsn = xfs_ail_delete_one(ailp, lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (!tail_lsn && lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) tail_lsn = lsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) xfs_ail_update_finish(ailp, tail_lsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * Walk the list of inodes that have completed their IOs. If they are clean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * remove them from the list and dissociate them from the buffer. Buffers that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * are still dirty remain linked to the buffer and on the list. Caller must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * handle them appropriately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) xfs_iflush_finish(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) struct xfs_buf *bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) struct list_head *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) struct xfs_log_item *lip, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) list_for_each_entry_safe(lip, n, list, li_bio_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) bool drop_buffer = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) spin_lock(&iip->ili_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) * Remove the reference to the cluster buffer if the inode is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) * clean in memory and drop the buffer reference once we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) * dropped the locks we hold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ASSERT(iip->ili_item.li_buf == bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (!iip->ili_fields) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) iip->ili_item.li_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) list_del_init(&lip->li_bio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) drop_buffer = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) iip->ili_last_fields = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) iip->ili_flush_lsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) spin_unlock(&iip->ili_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) xfs_iflags_clear(iip->ili_inode, XFS_IFLUSHING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (drop_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) xfs_buf_rele(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * Inode buffer IO completion routine. It is responsible for removing inodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * attached to the buffer from the AIL if they have not been re-logged and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * completing the inode flush.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) xfs_buf_inode_iodone(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) struct xfs_log_item *lip, *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) LIST_HEAD(flushed_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) LIST_HEAD(ail_updates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * Pull the attached inodes from the buffer one at a time and take the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * appropriate action on them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct xfs_inode_log_item *iip = INODE_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (xfs_iflags_test(iip->ili_inode, XFS_ISTALE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) xfs_iflush_abort(iip->ili_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (!iip->ili_last_fields)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* Do an unlocked check for needing the AIL lock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (iip->ili_flush_lsn == lip->li_lsn ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) test_bit(XFS_LI_FAILED, &lip->li_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) list_move_tail(&lip->li_bio_list, &ail_updates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) list_move_tail(&lip->li_bio_list, &flushed_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (!list_empty(&ail_updates)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) xfs_iflush_ail_updates(bp->b_mount->m_ail, &ail_updates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) list_splice_tail(&ail_updates, &flushed_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) xfs_iflush_finish(bp, &flushed_inodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (!list_empty(&flushed_inodes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) list_splice_tail(&flushed_inodes, &bp->b_li_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) xfs_buf_inode_io_fail(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) struct xfs_log_item *lip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) list_for_each_entry(lip, &bp->b_li_list, li_bio_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) set_bit(XFS_LI_FAILED, &lip->li_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) * This is the inode flushing abort routine. It is called when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) * the filesystem is shutting down to clean up the inode state. It is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) * responsible for removing the inode item from the AIL if it has not been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * re-logged and clearing the inode's flush state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) xfs_iflush_abort(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) struct xfs_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) struct xfs_inode_log_item *iip = ip->i_itemp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct xfs_buf *bp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (iip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * Clear the failed bit before removing the item from the AIL so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * xfs_trans_ail_delete() doesn't try to clear and release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * buffer attached to the log item before we are done with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) clear_bit(XFS_LI_FAILED, &iip->ili_item.li_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) xfs_trans_ail_delete(&iip->ili_item, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * Clear the inode logging fields so no more flushes are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * attempted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) spin_lock(&iip->ili_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) iip->ili_last_fields = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) iip->ili_fields = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) iip->ili_fsync_fields = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) iip->ili_flush_lsn = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) bp = iip->ili_item.li_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) iip->ili_item.li_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) list_del_init(&iip->ili_item.li_bio_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) spin_unlock(&iip->ili_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) xfs_iflags_clear(ip, XFS_IFLUSHING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) if (bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) xfs_buf_rele(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) * convert an xfs_inode_log_format struct from the old 32 bit version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) * (which can have different field alignments) to the native 64 bit version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) xfs_inode_item_format_convert(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) struct xfs_log_iovec *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct xfs_inode_log_format *in_f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) if (buf->i_len != sizeof(*in_f32)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) in_f->ilf_type = in_f32->ilf_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) in_f->ilf_size = in_f32->ilf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) in_f->ilf_fields = in_f32->ilf_fields;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) in_f->ilf_asize = in_f32->ilf_asize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) in_f->ilf_dsize = in_f32->ilf_dsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) in_f->ilf_ino = in_f32->ilf_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) memcpy(&in_f->ilf_u, &in_f32->ilf_u, sizeof(in_f->ilf_u));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) in_f->ilf_blkno = in_f32->ilf_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) in_f->ilf_len = in_f32->ilf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) in_f->ilf_boffset = in_f32->ilf_boffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }