xfs_icreate_item.c 4.7 KB

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