xfs_trans_extfree.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2000,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  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
  7. * published by the Free Software Foundation.
  8. *
  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.
  13. *
  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
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_log.h"
  22. #include "xfs_trans.h"
  23. #include "xfs_sb.h"
  24. #include "xfs_ag.h"
  25. #include "xfs_mount.h"
  26. #include "xfs_trans_priv.h"
  27. #include "xfs_extfree_item.h"
  28. /*
  29. * This routine is called to allocate an "extent free intention"
  30. * log item that will hold nextents worth of extents. The
  31. * caller must use all nextents extents, because we are not
  32. * flexible about this at all.
  33. */
  34. xfs_efi_log_item_t *
  35. xfs_trans_get_efi(xfs_trans_t *tp,
  36. uint nextents)
  37. {
  38. xfs_efi_log_item_t *efip;
  39. ASSERT(tp != NULL);
  40. ASSERT(nextents > 0);
  41. efip = xfs_efi_init(tp->t_mountp, nextents);
  42. ASSERT(efip != NULL);
  43. /*
  44. * Get a log_item_desc to point at the new item.
  45. */
  46. xfs_trans_add_item(tp, &efip->efi_item);
  47. return efip;
  48. }
  49. /*
  50. * This routine is called to indicate that the described
  51. * extent is to be logged as needing to be freed. It should
  52. * be called once for each extent to be freed.
  53. */
  54. void
  55. xfs_trans_log_efi_extent(xfs_trans_t *tp,
  56. xfs_efi_log_item_t *efip,
  57. xfs_fsblock_t start_block,
  58. xfs_extlen_t ext_len)
  59. {
  60. uint next_extent;
  61. xfs_extent_t *extp;
  62. tp->t_flags |= XFS_TRANS_DIRTY;
  63. efip->efi_item.li_desc->lid_flags |= XFS_LID_DIRTY;
  64. /*
  65. * atomic_inc_return gives us the value after the increment;
  66. * we want to use it as an array index so we need to subtract 1 from
  67. * it.
  68. */
  69. next_extent = atomic_inc_return(&efip->efi_next_extent) - 1;
  70. ASSERT(next_extent < efip->efi_format.efi_nextents);
  71. extp = &(efip->efi_format.efi_extents[next_extent]);
  72. extp->ext_start = start_block;
  73. extp->ext_len = ext_len;
  74. }
  75. /*
  76. * This routine is called to allocate an "extent free done"
  77. * log item that will hold nextents worth of extents. The
  78. * caller must use all nextents extents, because we are not
  79. * flexible about this at all.
  80. */
  81. xfs_efd_log_item_t *
  82. xfs_trans_get_efd(xfs_trans_t *tp,
  83. xfs_efi_log_item_t *efip,
  84. uint nextents)
  85. {
  86. xfs_efd_log_item_t *efdp;
  87. ASSERT(tp != NULL);
  88. ASSERT(nextents > 0);
  89. efdp = xfs_efd_init(tp->t_mountp, efip, nextents);
  90. ASSERT(efdp != NULL);
  91. /*
  92. * Get a log_item_desc to point at the new item.
  93. */
  94. xfs_trans_add_item(tp, &efdp->efd_item);
  95. return efdp;
  96. }
  97. /*
  98. * This routine is called to indicate that the described
  99. * extent is to be logged as having been freed. It should
  100. * be called once for each extent freed.
  101. */
  102. void
  103. xfs_trans_log_efd_extent(xfs_trans_t *tp,
  104. xfs_efd_log_item_t *efdp,
  105. xfs_fsblock_t start_block,
  106. xfs_extlen_t ext_len)
  107. {
  108. uint next_extent;
  109. xfs_extent_t *extp;
  110. tp->t_flags |= XFS_TRANS_DIRTY;
  111. efdp->efd_item.li_desc->lid_flags |= XFS_LID_DIRTY;
  112. next_extent = efdp->efd_next_extent;
  113. ASSERT(next_extent < efdp->efd_format.efd_nextents);
  114. extp = &(efdp->efd_format.efd_extents[next_extent]);
  115. extp->ext_start = start_block;
  116. extp->ext_len = ext_len;
  117. efdp->efd_next_extent++;
  118. }