xfs_trans_extfree.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_dmapi.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_trans_priv.h"
  28. #include "xfs_extfree_item.h"
  29. /*
  30. * This routine is called to allocate an "extent free intention"
  31. * log item that will hold nextents worth of extents. The
  32. * caller must use all nextents extents, because we are not
  33. * flexible about this at all.
  34. */
  35. xfs_efi_log_item_t *
  36. xfs_trans_get_efi(xfs_trans_t *tp,
  37. uint nextents)
  38. {
  39. xfs_efi_log_item_t *efip;
  40. ASSERT(tp != NULL);
  41. ASSERT(nextents > 0);
  42. efip = xfs_efi_init(tp->t_mountp, nextents);
  43. ASSERT(efip != NULL);
  44. /*
  45. * Get a log_item_desc to point at the new item.
  46. */
  47. (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efip);
  48. return (efip);
  49. }
  50. /*
  51. * This routine is called to indicate that the described
  52. * extent is to be logged as needing to be freed. It should
  53. * be called once for each extent to be freed.
  54. */
  55. void
  56. xfs_trans_log_efi_extent(xfs_trans_t *tp,
  57. xfs_efi_log_item_t *efip,
  58. xfs_fsblock_t start_block,
  59. xfs_extlen_t ext_len)
  60. {
  61. xfs_log_item_desc_t *lidp;
  62. uint next_extent;
  63. xfs_extent_t *extp;
  64. lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efip);
  65. ASSERT(lidp != NULL);
  66. tp->t_flags |= XFS_TRANS_DIRTY;
  67. lidp->lid_flags |= XFS_LID_DIRTY;
  68. next_extent = efip->efi_next_extent;
  69. ASSERT(next_extent < efip->efi_format.efi_nextents);
  70. extp = &(efip->efi_format.efi_extents[next_extent]);
  71. extp->ext_start = start_block;
  72. extp->ext_len = ext_len;
  73. efip->efi_next_extent++;
  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. (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efdp);
  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. xfs_log_item_desc_t *lidp;
  109. uint next_extent;
  110. xfs_extent_t *extp;
  111. lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efdp);
  112. ASSERT(lidp != NULL);
  113. tp->t_flags |= XFS_TRANS_DIRTY;
  114. lidp->lid_flags |= XFS_LID_DIRTY;
  115. next_extent = efdp->efd_next_extent;
  116. ASSERT(next_extent < efdp->efd_format.efd_nextents);
  117. extp = &(efdp->efd_format.efd_extents[next_extent]);
  118. extp->ext_start = start_block;
  119. extp->ext_len = ext_len;
  120. efdp->efd_next_extent++;
  121. }