xfs_icreate_item.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2008-2010, 2013 Dave Chinner
  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_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_bit.h"
  25. #include "xfs_mount.h"
  26. #include "xfs_trans.h"
  27. #include "xfs_trans_priv.h"
  28. #include "xfs_error.h"
  29. #include "xfs_icreate_item.h"
  30. #include "xfs_log.h"
  31. kmem_zone_t *xfs_icreate_zone; /* inode create item zone */
  32. static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip)
  33. {
  34. return container_of(lip, struct xfs_icreate_item, ic_item);
  35. }
  36. /*
  37. * This returns the number of iovecs needed to log the given inode item.
  38. *
  39. * We only need one iovec for the icreate log structure.
  40. */
  41. STATIC void
  42. xfs_icreate_item_size(
  43. struct xfs_log_item *lip,
  44. int *nvecs,
  45. int *nbytes)
  46. {
  47. *nvecs += 1;
  48. *nbytes += sizeof(struct xfs_icreate_log);
  49. }
  50. /*
  51. * This is called to fill in the vector of log iovecs for the
  52. * given inode create log item.
  53. */
  54. STATIC void
  55. xfs_icreate_item_format(
  56. struct xfs_log_item *lip,
  57. struct xfs_log_vec *lv)
  58. {
  59. struct xfs_icreate_item *icp = ICR_ITEM(lip);
  60. struct xfs_log_iovec *vecp = NULL;
  61. xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE,
  62. &icp->ic_format,
  63. sizeof(struct xfs_icreate_log));
  64. }
  65. /* Pinning has no meaning for the create item, so just return. */
  66. STATIC void
  67. xfs_icreate_item_pin(
  68. struct xfs_log_item *lip)
  69. {
  70. }
  71. /* pinning has no meaning for the create item, so just return. */
  72. STATIC void
  73. xfs_icreate_item_unpin(
  74. struct xfs_log_item *lip,
  75. int remove)
  76. {
  77. }
  78. STATIC void
  79. xfs_icreate_item_unlock(
  80. struct xfs_log_item *lip)
  81. {
  82. struct xfs_icreate_item *icp = ICR_ITEM(lip);
  83. if (icp->ic_item.li_flags & XFS_LI_ABORTED)
  84. kmem_zone_free(xfs_icreate_zone, icp);
  85. return;
  86. }
  87. /*
  88. * Because we have ordered buffers being tracked in the AIL for the inode
  89. * creation, we don't need the create item after this. Hence we can free
  90. * the log item and return -1 to tell the caller we're done with the item.
  91. */
  92. STATIC xfs_lsn_t
  93. xfs_icreate_item_committed(
  94. struct xfs_log_item *lip,
  95. xfs_lsn_t lsn)
  96. {
  97. struct xfs_icreate_item *icp = ICR_ITEM(lip);
  98. kmem_zone_free(xfs_icreate_zone, icp);
  99. return (xfs_lsn_t)-1;
  100. }
  101. /* item can never get into the AIL */
  102. STATIC uint
  103. xfs_icreate_item_push(
  104. struct xfs_log_item *lip,
  105. struct list_head *buffer_list)
  106. {
  107. ASSERT(0);
  108. return XFS_ITEM_SUCCESS;
  109. }
  110. /* Ordered buffers do the dependency tracking here, so this does nothing. */
  111. STATIC void
  112. xfs_icreate_item_committing(
  113. struct xfs_log_item *lip,
  114. xfs_lsn_t lsn)
  115. {
  116. }
  117. /*
  118. * This is the ops vector shared by all buf log items.
  119. */
  120. static struct xfs_item_ops xfs_icreate_item_ops = {
  121. .iop_size = xfs_icreate_item_size,
  122. .iop_format = xfs_icreate_item_format,
  123. .iop_pin = xfs_icreate_item_pin,
  124. .iop_unpin = xfs_icreate_item_unpin,
  125. .iop_push = xfs_icreate_item_push,
  126. .iop_unlock = xfs_icreate_item_unlock,
  127. .iop_committed = xfs_icreate_item_committed,
  128. .iop_committing = xfs_icreate_item_committing,
  129. };
  130. /*
  131. * Initialize the inode log item for a newly allocated (in-core) inode.
  132. *
  133. * Inode extents can only reside within an AG. Hence specify the starting
  134. * block for the inode chunk by offset within an AG as well as the
  135. * length of the allocated extent.
  136. *
  137. * This joins the item to the transaction and marks it dirty so
  138. * that we don't need a separate call to do this, nor does the
  139. * caller need to know anything about the icreate item.
  140. */
  141. void
  142. xfs_icreate_log(
  143. struct xfs_trans *tp,
  144. xfs_agnumber_t agno,
  145. xfs_agblock_t agbno,
  146. unsigned int count,
  147. unsigned int inode_size,
  148. xfs_agblock_t length,
  149. unsigned int generation)
  150. {
  151. struct xfs_icreate_item *icp;
  152. icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP);
  153. xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE,
  154. &xfs_icreate_item_ops);
  155. icp->ic_format.icl_type = XFS_LI_ICREATE;
  156. icp->ic_format.icl_size = 1; /* single vector */
  157. icp->ic_format.icl_ag = cpu_to_be32(agno);
  158. icp->ic_format.icl_agbno = cpu_to_be32(agbno);
  159. icp->ic_format.icl_count = cpu_to_be32(count);
  160. icp->ic_format.icl_isize = cpu_to_be32(inode_size);
  161. icp->ic_format.icl_length = cpu_to_be32(length);
  162. icp->ic_format.icl_gen = cpu_to_be32(generation);
  163. xfs_trans_add_item(tp, &icp->ic_item);
  164. tp->t_flags |= XFS_TRANS_DIRTY;
  165. icp->ic_item.li_desc->lid_flags |= XFS_LID_DIRTY;
  166. }