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