xfs_icreate_item.c 4.2 KB

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