xfs_trans_extfree.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_macros.h"
  34. #include "xfs_types.h"
  35. #include "xfs_inum.h"
  36. #include "xfs_log.h"
  37. #include "xfs_trans.h"
  38. #include "xfs_sb.h"
  39. #include "xfs_dir.h"
  40. #include "xfs_dmapi.h"
  41. #include "xfs_mount.h"
  42. #include "xfs_trans_priv.h"
  43. #include "xfs_extfree_item.h"
  44. /*
  45. * This routine is called to allocate an "extent free intention"
  46. * log item that will hold nextents worth of extents. The
  47. * caller must use all nextents extents, because we are not
  48. * flexible about this at all.
  49. */
  50. xfs_efi_log_item_t *
  51. xfs_trans_get_efi(xfs_trans_t *tp,
  52. uint nextents)
  53. {
  54. xfs_efi_log_item_t *efip;
  55. ASSERT(tp != NULL);
  56. ASSERT(nextents > 0);
  57. efip = xfs_efi_init(tp->t_mountp, nextents);
  58. ASSERT(efip != NULL);
  59. /*
  60. * Get a log_item_desc to point at the new item.
  61. */
  62. (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efip);
  63. return (efip);
  64. }
  65. /*
  66. * This routine is called to indicate that the described
  67. * extent is to be logged as needing to be freed. It should
  68. * be called once for each extent to be freed.
  69. */
  70. void
  71. xfs_trans_log_efi_extent(xfs_trans_t *tp,
  72. xfs_efi_log_item_t *efip,
  73. xfs_fsblock_t start_block,
  74. xfs_extlen_t ext_len)
  75. {
  76. xfs_log_item_desc_t *lidp;
  77. uint next_extent;
  78. xfs_extent_t *extp;
  79. lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efip);
  80. ASSERT(lidp != NULL);
  81. tp->t_flags |= XFS_TRANS_DIRTY;
  82. lidp->lid_flags |= XFS_LID_DIRTY;
  83. next_extent = efip->efi_next_extent;
  84. ASSERT(next_extent < efip->efi_format.efi_nextents);
  85. extp = &(efip->efi_format.efi_extents[next_extent]);
  86. extp->ext_start = start_block;
  87. extp->ext_len = ext_len;
  88. efip->efi_next_extent++;
  89. }
  90. /*
  91. * This routine is called to allocate an "extent free done"
  92. * log item that will hold nextents worth of extents. The
  93. * caller must use all nextents extents, because we are not
  94. * flexible about this at all.
  95. */
  96. xfs_efd_log_item_t *
  97. xfs_trans_get_efd(xfs_trans_t *tp,
  98. xfs_efi_log_item_t *efip,
  99. uint nextents)
  100. {
  101. xfs_efd_log_item_t *efdp;
  102. ASSERT(tp != NULL);
  103. ASSERT(nextents > 0);
  104. efdp = xfs_efd_init(tp->t_mountp, efip, nextents);
  105. ASSERT(efdp != NULL);
  106. /*
  107. * Get a log_item_desc to point at the new item.
  108. */
  109. (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efdp);
  110. return (efdp);
  111. }
  112. /*
  113. * This routine is called to indicate that the described
  114. * extent is to be logged as having been freed. It should
  115. * be called once for each extent freed.
  116. */
  117. void
  118. xfs_trans_log_efd_extent(xfs_trans_t *tp,
  119. xfs_efd_log_item_t *efdp,
  120. xfs_fsblock_t start_block,
  121. xfs_extlen_t ext_len)
  122. {
  123. xfs_log_item_desc_t *lidp;
  124. uint next_extent;
  125. xfs_extent_t *extp;
  126. lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efdp);
  127. ASSERT(lidp != NULL);
  128. tp->t_flags |= XFS_TRANS_DIRTY;
  129. lidp->lid_flags |= XFS_LID_DIRTY;
  130. next_extent = efdp->efd_next_extent;
  131. ASSERT(next_extent < efdp->efd_format.efd_nextents);
  132. extp = &(efdp->efd_format.efd_extents[next_extent]);
  133. extp->ext_start = start_block;
  134. extp->ext_len = ext_len;
  135. efdp->efd_next_extent++;
  136. }