1153323Srodrigc/* 2159451Srodrigc * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. 3159451Srodrigc * All Rights Reserved. 4153323Srodrigc * 5159451Srodrigc * This program is free software; you can redistribute it and/or 6159451Srodrigc * modify it under the terms of the GNU General Public License as 7153323Srodrigc * published by the Free Software Foundation. 8153323Srodrigc * 9159451Srodrigc * This program is distributed in the hope that it would be useful, 10159451Srodrigc * but WITHOUT ANY WARRANTY; without even the implied warranty of 11159451Srodrigc * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12159451Srodrigc * GNU General Public License for more details. 13153323Srodrigc * 14159451Srodrigc * You should have received a copy of the GNU General Public License 15159451Srodrigc * along with this program; if not, write the Free Software Foundation, 16159451Srodrigc * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17153323Srodrigc */ 18153323Srodrigc#include "xfs.h" 19159451Srodrigc#include "xfs_fs.h" 20153323Srodrigc#include "xfs_types.h" 21159451Srodrigc#include "xfs_log.h" 22153323Srodrigc#include "xfs_inum.h" 23153323Srodrigc#include "xfs_trans.h" 24153323Srodrigc#include "xfs_buf_item.h" 25153323Srodrigc#include "xfs_sb.h" 26153323Srodrigc#include "xfs_dir.h" 27153323Srodrigc#include "xfs_dmapi.h" 28153323Srodrigc#include "xfs_mount.h" 29153323Srodrigc#include "xfs_trans_priv.h" 30153323Srodrigc#include "xfs_extfree_item.h" 31153323Srodrigc 32153323Srodrigc 33153323Srodrigckmem_zone_t *xfs_efi_zone; 34153323Srodrigckmem_zone_t *xfs_efd_zone; 35153323Srodrigc 36153323SrodrigcSTATIC void xfs_efi_item_unlock(xfs_efi_log_item_t *); 37153323SrodrigcSTATIC void xfs_efi_item_abort(xfs_efi_log_item_t *); 38153323SrodrigcSTATIC void xfs_efd_item_abort(xfs_efd_log_item_t *); 39153323Srodrigc 40153323Srodrigc 41159451Srodrigcvoid 42159451Srodrigcxfs_efi_item_free(xfs_efi_log_item_t *efip) 43159451Srodrigc{ 44159451Srodrigc int nexts = efip->efi_format.efi_nextents; 45153323Srodrigc 46159451Srodrigc if (nexts > XFS_EFI_MAX_FAST_EXTENTS) { 47159451Srodrigc kmem_free(efip, sizeof(xfs_efi_log_item_t) + 48159451Srodrigc (nexts - 1) * sizeof(xfs_extent_t)); 49159451Srodrigc } else { 50159451Srodrigc kmem_zone_free(xfs_efi_zone, efip); 51159451Srodrigc } 52159451Srodrigc} 53159451Srodrigc 54153323Srodrigc/* 55153323Srodrigc * This returns the number of iovecs needed to log the given efi item. 56153323Srodrigc * We only need 1 iovec for an efi item. It just logs the efi_log_format 57153323Srodrigc * structure. 58153323Srodrigc */ 59153323Srodrigc/*ARGSUSED*/ 60153323SrodrigcSTATIC uint 61153323Srodrigcxfs_efi_item_size(xfs_efi_log_item_t *efip) 62153323Srodrigc{ 63153323Srodrigc return 1; 64153323Srodrigc} 65153323Srodrigc 66153323Srodrigc/* 67153323Srodrigc * This is called to fill in the vector of log iovecs for the 68153323Srodrigc * given efi log item. We use only 1 iovec, and we point that 69153323Srodrigc * at the efi_log_format structure embedded in the efi item. 70153323Srodrigc * It is at this point that we assert that all of the extent 71153323Srodrigc * slots in the efi item have been filled. 72153323Srodrigc */ 73153323SrodrigcSTATIC void 74153323Srodrigcxfs_efi_item_format(xfs_efi_log_item_t *efip, 75153323Srodrigc xfs_log_iovec_t *log_vector) 76153323Srodrigc{ 77153323Srodrigc uint size; 78153323Srodrigc 79153323Srodrigc ASSERT(efip->efi_next_extent == efip->efi_format.efi_nextents); 80153323Srodrigc 81153323Srodrigc efip->efi_format.efi_type = XFS_LI_EFI; 82153323Srodrigc 83153323Srodrigc size = sizeof(xfs_efi_log_format_t); 84153323Srodrigc size += (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t); 85153323Srodrigc efip->efi_format.efi_size = 1; 86153323Srodrigc 87153323Srodrigc log_vector->i_addr = (xfs_caddr_t)&(efip->efi_format); 88153323Srodrigc log_vector->i_len = size; 89159451Srodrigc XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_EFI_FORMAT); 90153323Srodrigc ASSERT(size >= sizeof(xfs_efi_log_format_t)); 91153323Srodrigc} 92153323Srodrigc 93153323Srodrigc 94153323Srodrigc/* 95153323Srodrigc * Pinning has no meaning for an efi item, so just return. 96153323Srodrigc */ 97153323Srodrigc/*ARGSUSED*/ 98153323SrodrigcSTATIC void 99153323Srodrigcxfs_efi_item_pin(xfs_efi_log_item_t *efip) 100153323Srodrigc{ 101153323Srodrigc return; 102153323Srodrigc} 103153323Srodrigc 104153323Srodrigc 105153323Srodrigc/* 106153323Srodrigc * While EFIs cannot really be pinned, the unpin operation is the 107153323Srodrigc * last place at which the EFI is manipulated during a transaction. 108153323Srodrigc * Here we coordinate with xfs_efi_cancel() to determine who gets to 109153323Srodrigc * free the EFI. 110153323Srodrigc */ 111153323Srodrigc/*ARGSUSED*/ 112153323SrodrigcSTATIC void 113153323Srodrigcxfs_efi_item_unpin(xfs_efi_log_item_t *efip, int stale) 114153323Srodrigc{ 115153323Srodrigc xfs_mount_t *mp; 116153323Srodrigc SPLDECL(s); 117153323Srodrigc 118153323Srodrigc mp = efip->efi_item.li_mountp; 119153323Srodrigc AIL_LOCK(mp, s); 120153323Srodrigc if (efip->efi_flags & XFS_EFI_CANCELED) { 121153323Srodrigc /* 122153323Srodrigc * xfs_trans_delete_ail() drops the AIL lock. 123153323Srodrigc */ 124153323Srodrigc xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s); 125159451Srodrigc xfs_efi_item_free(efip); 126153323Srodrigc } else { 127153323Srodrigc efip->efi_flags |= XFS_EFI_COMMITTED; 128153323Srodrigc AIL_UNLOCK(mp, s); 129153323Srodrigc } 130153323Srodrigc} 131153323Srodrigc 132153323Srodrigc/* 133153323Srodrigc * like unpin only we have to also clear the xaction descriptor 134153323Srodrigc * pointing the log item if we free the item. This routine duplicates 135153323Srodrigc * unpin because efi_flags is protected by the AIL lock. Freeing 136153323Srodrigc * the descriptor and then calling unpin would force us to drop the AIL 137153323Srodrigc * lock which would open up a race condition. 138153323Srodrigc */ 139153323SrodrigcSTATIC void 140153323Srodrigcxfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp) 141153323Srodrigc{ 142153323Srodrigc xfs_mount_t *mp; 143153323Srodrigc xfs_log_item_desc_t *lidp; 144153323Srodrigc SPLDECL(s); 145153323Srodrigc 146153323Srodrigc mp = efip->efi_item.li_mountp; 147153323Srodrigc AIL_LOCK(mp, s); 148153323Srodrigc if (efip->efi_flags & XFS_EFI_CANCELED) { 149153323Srodrigc /* 150153323Srodrigc * free the xaction descriptor pointing to this item 151153323Srodrigc */ 152153323Srodrigc lidp = xfs_trans_find_item(tp, (xfs_log_item_t *) efip); 153153323Srodrigc xfs_trans_free_item(tp, lidp); 154153323Srodrigc /* 155153323Srodrigc * pull the item off the AIL. 156153323Srodrigc * xfs_trans_delete_ail() drops the AIL lock. 157153323Srodrigc */ 158153323Srodrigc xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s); 159159451Srodrigc xfs_efi_item_free(efip); 160153323Srodrigc } else { 161153323Srodrigc efip->efi_flags |= XFS_EFI_COMMITTED; 162153323Srodrigc AIL_UNLOCK(mp, s); 163153323Srodrigc } 164153323Srodrigc} 165153323Srodrigc 166153323Srodrigc/* 167153323Srodrigc * Efi items have no locking or pushing. However, since EFIs are 168153323Srodrigc * pulled from the AIL when their corresponding EFDs are committed 169153323Srodrigc * to disk, their situation is very similar to being pinned. Return 170153323Srodrigc * XFS_ITEM_PINNED so that the caller will eventually flush the log. 171153323Srodrigc * This should help in getting the EFI out of the AIL. 172153323Srodrigc */ 173153323Srodrigc/*ARGSUSED*/ 174153323SrodrigcSTATIC uint 175153323Srodrigcxfs_efi_item_trylock(xfs_efi_log_item_t *efip) 176153323Srodrigc{ 177153323Srodrigc return XFS_ITEM_PINNED; 178153323Srodrigc} 179153323Srodrigc 180153323Srodrigc/* 181153323Srodrigc * Efi items have no locking, so just return. 182153323Srodrigc */ 183153323Srodrigc/*ARGSUSED*/ 184153323SrodrigcSTATIC void 185153323Srodrigcxfs_efi_item_unlock(xfs_efi_log_item_t *efip) 186153323Srodrigc{ 187153323Srodrigc if (efip->efi_item.li_flags & XFS_LI_ABORTED) 188153323Srodrigc xfs_efi_item_abort(efip); 189153323Srodrigc return; 190153323Srodrigc} 191153323Srodrigc 192153323Srodrigc/* 193153323Srodrigc * The EFI is logged only once and cannot be moved in the log, so 194153323Srodrigc * simply return the lsn at which it's been logged. The canceled 195153323Srodrigc * flag is not paid any attention here. Checking for that is delayed 196153323Srodrigc * until the EFI is unpinned. 197153323Srodrigc */ 198153323Srodrigc/*ARGSUSED*/ 199153323SrodrigcSTATIC xfs_lsn_t 200153323Srodrigcxfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn) 201153323Srodrigc{ 202153323Srodrigc return lsn; 203153323Srodrigc} 204153323Srodrigc 205153323Srodrigc/* 206153323Srodrigc * This is called when the transaction logging the EFI is aborted. 207153323Srodrigc * Free up the EFI and return. No need to clean up the slot for 208153323Srodrigc * the item in the transaction. That was done by the unpin code 209153323Srodrigc * which is called prior to this routine in the abort/fs-shutdown path. 210153323Srodrigc */ 211153323SrodrigcSTATIC void 212153323Srodrigcxfs_efi_item_abort(xfs_efi_log_item_t *efip) 213153323Srodrigc{ 214159451Srodrigc xfs_efi_item_free(efip); 215153323Srodrigc} 216153323Srodrigc 217153323Srodrigc/* 218153323Srodrigc * There isn't much you can do to push on an efi item. It is simply 219153323Srodrigc * stuck waiting for all of its corresponding efd items to be 220153323Srodrigc * committed to disk. 221153323Srodrigc */ 222153323Srodrigc/*ARGSUSED*/ 223153323SrodrigcSTATIC void 224153323Srodrigcxfs_efi_item_push(xfs_efi_log_item_t *efip) 225153323Srodrigc{ 226153323Srodrigc return; 227153323Srodrigc} 228153323Srodrigc 229153323Srodrigc/* 230153323Srodrigc * The EFI dependency tracking op doesn't do squat. It can't because 231153323Srodrigc * it doesn't know where the free extent is coming from. The dependency 232153323Srodrigc * tracking has to be handled by the "enclosing" metadata object. For 233153323Srodrigc * example, for inodes, the inode is locked throughout the extent freeing 234153323Srodrigc * so the dependency should be recorded there. 235153323Srodrigc */ 236153323Srodrigc/*ARGSUSED*/ 237153323SrodrigcSTATIC void 238153323Srodrigcxfs_efi_item_committing(xfs_efi_log_item_t *efip, xfs_lsn_t lsn) 239153323Srodrigc{ 240153323Srodrigc return; 241153323Srodrigc} 242153323Srodrigc 243153323Srodrigc/* 244153323Srodrigc * This is the ops vector shared by all efi log items. 245153323Srodrigc */ 246159451SrodrigcSTATIC struct xfs_item_ops xfs_efi_item_ops = { 247153323Srodrigc .iop_size = (uint(*)(xfs_log_item_t*))xfs_efi_item_size, 248153323Srodrigc .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*)) 249153323Srodrigc xfs_efi_item_format, 250153323Srodrigc .iop_pin = (void(*)(xfs_log_item_t*))xfs_efi_item_pin, 251153323Srodrigc .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efi_item_unpin, 252153323Srodrigc .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *)) 253153323Srodrigc xfs_efi_item_unpin_remove, 254153323Srodrigc .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efi_item_trylock, 255153323Srodrigc .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efi_item_unlock, 256153323Srodrigc .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t)) 257153323Srodrigc xfs_efi_item_committed, 258153323Srodrigc .iop_push = (void(*)(xfs_log_item_t*))xfs_efi_item_push, 259153323Srodrigc .iop_abort = (void(*)(xfs_log_item_t*))xfs_efi_item_abort, 260153323Srodrigc .iop_pushbuf = NULL, 261153323Srodrigc .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t)) 262153323Srodrigc xfs_efi_item_committing 263153323Srodrigc}; 264153323Srodrigc 265153323Srodrigc 266153323Srodrigc/* 267153323Srodrigc * Allocate and initialize an efi item with the given number of extents. 268153323Srodrigc */ 269153323Srodrigcxfs_efi_log_item_t * 270153323Srodrigcxfs_efi_init(xfs_mount_t *mp, 271153323Srodrigc uint nextents) 272153323Srodrigc 273153323Srodrigc{ 274153323Srodrigc xfs_efi_log_item_t *efip; 275153323Srodrigc uint size; 276153323Srodrigc 277153323Srodrigc ASSERT(nextents > 0); 278153323Srodrigc if (nextents > XFS_EFI_MAX_FAST_EXTENTS) { 279153323Srodrigc size = (uint)(sizeof(xfs_efi_log_item_t) + 280153323Srodrigc ((nextents - 1) * sizeof(xfs_extent_t))); 281153323Srodrigc efip = (xfs_efi_log_item_t*)kmem_zalloc(size, KM_SLEEP); 282153323Srodrigc } else { 283153323Srodrigc efip = (xfs_efi_log_item_t*)kmem_zone_zalloc(xfs_efi_zone, 284153323Srodrigc KM_SLEEP); 285153323Srodrigc } 286153323Srodrigc 287153323Srodrigc efip->efi_item.li_type = XFS_LI_EFI; 288153323Srodrigc efip->efi_item.li_ops = &xfs_efi_item_ops; 289153323Srodrigc efip->efi_item.li_mountp = mp; 290153323Srodrigc efip->efi_format.efi_nextents = nextents; 291153323Srodrigc efip->efi_format.efi_id = (__psint_t)(void*)efip; 292153323Srodrigc 293153323Srodrigc return (efip); 294153323Srodrigc} 295153323Srodrigc 296153323Srodrigc/* 297153323Srodrigc * This is called by the efd item code below to release references to 298153323Srodrigc * the given efi item. Each efd calls this with the number of 299153323Srodrigc * extents that it has logged, and when the sum of these reaches 300153323Srodrigc * the total number of extents logged by this efi item we can free 301153323Srodrigc * the efi item. 302153323Srodrigc * 303153323Srodrigc * Freeing the efi item requires that we remove it from the AIL. 304153323Srodrigc * We'll use the AIL lock to protect our counters as well as 305153323Srodrigc * the removal from the AIL. 306153323Srodrigc */ 307153323Srodrigcvoid 308153323Srodrigcxfs_efi_release(xfs_efi_log_item_t *efip, 309153323Srodrigc uint nextents) 310153323Srodrigc{ 311153323Srodrigc xfs_mount_t *mp; 312153323Srodrigc int extents_left; 313153323Srodrigc SPLDECL(s); 314153323Srodrigc 315153323Srodrigc mp = efip->efi_item.li_mountp; 316153323Srodrigc ASSERT(efip->efi_next_extent > 0); 317153323Srodrigc ASSERT(efip->efi_flags & XFS_EFI_COMMITTED); 318153323Srodrigc 319153323Srodrigc AIL_LOCK(mp, s); 320153323Srodrigc ASSERT(efip->efi_next_extent >= nextents); 321153323Srodrigc efip->efi_next_extent -= nextents; 322153323Srodrigc extents_left = efip->efi_next_extent; 323153323Srodrigc if (extents_left == 0) { 324153323Srodrigc /* 325153323Srodrigc * xfs_trans_delete_ail() drops the AIL lock. 326153323Srodrigc */ 327153323Srodrigc xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s); 328159451Srodrigc xfs_efi_item_free(efip); 329153323Srodrigc } else { 330153323Srodrigc AIL_UNLOCK(mp, s); 331153323Srodrigc } 332153323Srodrigc} 333153323Srodrigc 334153323Srodrigc/* 335153323Srodrigc * This is called when the transaction that should be committing the 336153323Srodrigc * EFD corresponding to the given EFI is aborted. The committed and 337153323Srodrigc * canceled flags are used to coordinate the freeing of the EFI and 338153323Srodrigc * the references by the transaction that committed it. 339153323Srodrigc */ 340153323SrodrigcSTATIC void 341153323Srodrigcxfs_efi_cancel( 342153323Srodrigc xfs_efi_log_item_t *efip) 343153323Srodrigc{ 344153323Srodrigc xfs_mount_t *mp; 345153323Srodrigc SPLDECL(s); 346153323Srodrigc 347153323Srodrigc mp = efip->efi_item.li_mountp; 348153323Srodrigc AIL_LOCK(mp, s); 349153323Srodrigc if (efip->efi_flags & XFS_EFI_COMMITTED) { 350153323Srodrigc /* 351153323Srodrigc * xfs_trans_delete_ail() drops the AIL lock. 352153323Srodrigc */ 353153323Srodrigc xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s); 354159451Srodrigc xfs_efi_item_free(efip); 355153323Srodrigc } else { 356153323Srodrigc efip->efi_flags |= XFS_EFI_CANCELED; 357153323Srodrigc AIL_UNLOCK(mp, s); 358153323Srodrigc } 359153323Srodrigc} 360153323Srodrigc 361159451SrodrigcSTATIC void 362159451Srodrigcxfs_efd_item_free(xfs_efd_log_item_t *efdp) 363159451Srodrigc{ 364159451Srodrigc int nexts = efdp->efd_format.efd_nextents; 365153323Srodrigc 366159451Srodrigc if (nexts > XFS_EFD_MAX_FAST_EXTENTS) { 367159451Srodrigc kmem_free(efdp, sizeof(xfs_efd_log_item_t) + 368159451Srodrigc (nexts - 1) * sizeof(xfs_extent_t)); 369159451Srodrigc } else { 370159451Srodrigc kmem_zone_free(xfs_efd_zone, efdp); 371159451Srodrigc } 372159451Srodrigc} 373153323Srodrigc 374153323Srodrigc/* 375153323Srodrigc * This returns the number of iovecs needed to log the given efd item. 376153323Srodrigc * We only need 1 iovec for an efd item. It just logs the efd_log_format 377153323Srodrigc * structure. 378153323Srodrigc */ 379153323Srodrigc/*ARGSUSED*/ 380153323SrodrigcSTATIC uint 381153323Srodrigcxfs_efd_item_size(xfs_efd_log_item_t *efdp) 382153323Srodrigc{ 383153323Srodrigc return 1; 384153323Srodrigc} 385153323Srodrigc 386153323Srodrigc/* 387153323Srodrigc * This is called to fill in the vector of log iovecs for the 388153323Srodrigc * given efd log item. We use only 1 iovec, and we point that 389153323Srodrigc * at the efd_log_format structure embedded in the efd item. 390153323Srodrigc * It is at this point that we assert that all of the extent 391153323Srodrigc * slots in the efd item have been filled. 392153323Srodrigc */ 393153323SrodrigcSTATIC void 394153323Srodrigcxfs_efd_item_format(xfs_efd_log_item_t *efdp, 395153323Srodrigc xfs_log_iovec_t *log_vector) 396153323Srodrigc{ 397153323Srodrigc uint size; 398153323Srodrigc 399153323Srodrigc ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents); 400153323Srodrigc 401153323Srodrigc efdp->efd_format.efd_type = XFS_LI_EFD; 402153323Srodrigc 403153323Srodrigc size = sizeof(xfs_efd_log_format_t); 404153323Srodrigc size += (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t); 405153323Srodrigc efdp->efd_format.efd_size = 1; 406153323Srodrigc 407153323Srodrigc log_vector->i_addr = (xfs_caddr_t)&(efdp->efd_format); 408153323Srodrigc log_vector->i_len = size; 409159451Srodrigc XLOG_VEC_SET_TYPE(log_vector, XLOG_REG_TYPE_EFD_FORMAT); 410153323Srodrigc ASSERT(size >= sizeof(xfs_efd_log_format_t)); 411153323Srodrigc} 412153323Srodrigc 413153323Srodrigc 414153323Srodrigc/* 415153323Srodrigc * Pinning has no meaning for an efd item, so just return. 416153323Srodrigc */ 417153323Srodrigc/*ARGSUSED*/ 418153323SrodrigcSTATIC void 419153323Srodrigcxfs_efd_item_pin(xfs_efd_log_item_t *efdp) 420153323Srodrigc{ 421153323Srodrigc return; 422153323Srodrigc} 423153323Srodrigc 424153323Srodrigc 425153323Srodrigc/* 426153323Srodrigc * Since pinning has no meaning for an efd item, unpinning does 427153323Srodrigc * not either. 428153323Srodrigc */ 429153323Srodrigc/*ARGSUSED*/ 430153323SrodrigcSTATIC void 431153323Srodrigcxfs_efd_item_unpin(xfs_efd_log_item_t *efdp, int stale) 432153323Srodrigc{ 433153323Srodrigc return; 434153323Srodrigc} 435153323Srodrigc 436153323Srodrigc/*ARGSUSED*/ 437153323SrodrigcSTATIC void 438153323Srodrigcxfs_efd_item_unpin_remove(xfs_efd_log_item_t *efdp, xfs_trans_t *tp) 439153323Srodrigc{ 440153323Srodrigc return; 441153323Srodrigc} 442153323Srodrigc 443153323Srodrigc/* 444153323Srodrigc * Efd items have no locking, so just return success. 445153323Srodrigc */ 446153323Srodrigc/*ARGSUSED*/ 447153323SrodrigcSTATIC uint 448153323Srodrigcxfs_efd_item_trylock(xfs_efd_log_item_t *efdp) 449153323Srodrigc{ 450153323Srodrigc return XFS_ITEM_LOCKED; 451153323Srodrigc} 452153323Srodrigc 453153323Srodrigc/* 454153323Srodrigc * Efd items have no locking or pushing, so return failure 455153323Srodrigc * so that the caller doesn't bother with us. 456153323Srodrigc */ 457153323Srodrigc/*ARGSUSED*/ 458153323SrodrigcSTATIC void 459153323Srodrigcxfs_efd_item_unlock(xfs_efd_log_item_t *efdp) 460153323Srodrigc{ 461153323Srodrigc if (efdp->efd_item.li_flags & XFS_LI_ABORTED) 462153323Srodrigc xfs_efd_item_abort(efdp); 463153323Srodrigc return; 464153323Srodrigc} 465153323Srodrigc 466153323Srodrigc/* 467153323Srodrigc * When the efd item is committed to disk, all we need to do 468153323Srodrigc * is delete our reference to our partner efi item and then 469153323Srodrigc * free ourselves. Since we're freeing ourselves we must 470153323Srodrigc * return -1 to keep the transaction code from further referencing 471153323Srodrigc * this item. 472153323Srodrigc */ 473153323Srodrigc/*ARGSUSED*/ 474153323SrodrigcSTATIC xfs_lsn_t 475153323Srodrigcxfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn) 476153323Srodrigc{ 477153323Srodrigc /* 478153323Srodrigc * If we got a log I/O error, it's always the case that the LR with the 479153323Srodrigc * EFI got unpinned and freed before the EFD got aborted. 480153323Srodrigc */ 481153323Srodrigc if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0) 482153323Srodrigc xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents); 483153323Srodrigc 484159451Srodrigc xfs_efd_item_free(efdp); 485153323Srodrigc return (xfs_lsn_t)-1; 486153323Srodrigc} 487153323Srodrigc 488153323Srodrigc/* 489153323Srodrigc * The transaction of which this EFD is a part has been aborted. 490153323Srodrigc * Inform its companion EFI of this fact and then clean up after 491153323Srodrigc * ourselves. No need to clean up the slot for the item in the 492153323Srodrigc * transaction. That was done by the unpin code which is called 493153323Srodrigc * prior to this routine in the abort/fs-shutdown path. 494153323Srodrigc */ 495153323SrodrigcSTATIC void 496153323Srodrigcxfs_efd_item_abort(xfs_efd_log_item_t *efdp) 497153323Srodrigc{ 498153323Srodrigc /* 499153323Srodrigc * If we got a log I/O error, it's always the case that the LR with the 500153323Srodrigc * EFI got unpinned and freed before the EFD got aborted. So don't 501153323Srodrigc * reference the EFI at all in that case. 502153323Srodrigc */ 503153323Srodrigc if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0) 504153323Srodrigc xfs_efi_cancel(efdp->efd_efip); 505153323Srodrigc 506159451Srodrigc xfs_efd_item_free(efdp); 507153323Srodrigc} 508153323Srodrigc 509153323Srodrigc/* 510153323Srodrigc * There isn't much you can do to push on an efd item. It is simply 511153323Srodrigc * stuck waiting for the log to be flushed to disk. 512153323Srodrigc */ 513153323Srodrigc/*ARGSUSED*/ 514153323SrodrigcSTATIC void 515153323Srodrigcxfs_efd_item_push(xfs_efd_log_item_t *efdp) 516153323Srodrigc{ 517153323Srodrigc return; 518153323Srodrigc} 519153323Srodrigc 520153323Srodrigc/* 521153323Srodrigc * The EFD dependency tracking op doesn't do squat. It can't because 522153323Srodrigc * it doesn't know where the free extent is coming from. The dependency 523153323Srodrigc * tracking has to be handled by the "enclosing" metadata object. For 524153323Srodrigc * example, for inodes, the inode is locked throughout the extent freeing 525153323Srodrigc * so the dependency should be recorded there. 526153323Srodrigc */ 527153323Srodrigc/*ARGSUSED*/ 528153323SrodrigcSTATIC void 529153323Srodrigcxfs_efd_item_committing(xfs_efd_log_item_t *efip, xfs_lsn_t lsn) 530153323Srodrigc{ 531153323Srodrigc return; 532153323Srodrigc} 533153323Srodrigc 534153323Srodrigc/* 535153323Srodrigc * This is the ops vector shared by all efd log items. 536153323Srodrigc */ 537159451SrodrigcSTATIC struct xfs_item_ops xfs_efd_item_ops = { 538153323Srodrigc .iop_size = (uint(*)(xfs_log_item_t*))xfs_efd_item_size, 539153323Srodrigc .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*)) 540153323Srodrigc xfs_efd_item_format, 541153323Srodrigc .iop_pin = (void(*)(xfs_log_item_t*))xfs_efd_item_pin, 542153323Srodrigc .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_efd_item_unpin, 543153323Srodrigc .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*)) 544153323Srodrigc xfs_efd_item_unpin_remove, 545153323Srodrigc .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_efd_item_trylock, 546153323Srodrigc .iop_unlock = (void(*)(xfs_log_item_t*))xfs_efd_item_unlock, 547153323Srodrigc .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t)) 548153323Srodrigc xfs_efd_item_committed, 549153323Srodrigc .iop_push = (void(*)(xfs_log_item_t*))xfs_efd_item_push, 550153323Srodrigc .iop_abort = (void(*)(xfs_log_item_t*))xfs_efd_item_abort, 551153323Srodrigc .iop_pushbuf = NULL, 552153323Srodrigc .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t)) 553153323Srodrigc xfs_efd_item_committing 554153323Srodrigc}; 555153323Srodrigc 556153323Srodrigc 557153323Srodrigc/* 558153323Srodrigc * Allocate and initialize an efd item with the given number of extents. 559153323Srodrigc */ 560153323Srodrigcxfs_efd_log_item_t * 561153323Srodrigcxfs_efd_init(xfs_mount_t *mp, 562153323Srodrigc xfs_efi_log_item_t *efip, 563153323Srodrigc uint nextents) 564153323Srodrigc 565153323Srodrigc{ 566153323Srodrigc xfs_efd_log_item_t *efdp; 567153323Srodrigc uint size; 568153323Srodrigc 569153323Srodrigc ASSERT(nextents > 0); 570153323Srodrigc if (nextents > XFS_EFD_MAX_FAST_EXTENTS) { 571153323Srodrigc size = (uint)(sizeof(xfs_efd_log_item_t) + 572153323Srodrigc ((nextents - 1) * sizeof(xfs_extent_t))); 573153323Srodrigc efdp = (xfs_efd_log_item_t*)kmem_zalloc(size, KM_SLEEP); 574153323Srodrigc } else { 575153323Srodrigc efdp = (xfs_efd_log_item_t*)kmem_zone_zalloc(xfs_efd_zone, 576153323Srodrigc KM_SLEEP); 577153323Srodrigc } 578153323Srodrigc 579153323Srodrigc efdp->efd_item.li_type = XFS_LI_EFD; 580153323Srodrigc efdp->efd_item.li_ops = &xfs_efd_item_ops; 581153323Srodrigc efdp->efd_item.li_mountp = mp; 582153323Srodrigc efdp->efd_efip = efip; 583153323Srodrigc efdp->efd_format.efd_nextents = nextents; 584153323Srodrigc efdp->efd_format.efd_efi_id = efip->efi_format.efi_id; 585153323Srodrigc 586153323Srodrigc return (efdp); 587153323Srodrigc} 588