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