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