xfs_log.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_LOG_H__
  7. #define __XFS_LOG_H__
  8. struct xfs_cil_ctx;
  9. struct xfs_log_vec {
  10. struct list_head lv_list; /* CIL lv chain ptrs */
  11. uint32_t lv_order_id; /* chain ordering info */
  12. int lv_niovecs; /* number of iovecs in lv */
  13. struct xfs_log_iovec *lv_iovecp; /* iovec array */
  14. struct xfs_log_item *lv_item; /* owner */
  15. char *lv_buf; /* formatted buffer */
  16. int lv_bytes; /* accounted space in buffer */
  17. int lv_buf_len; /* aligned size of buffer */
  18. int lv_size; /* size of allocated lv */
  19. };
  20. #define XFS_LOG_VEC_ORDERED (-1)
  21. /*
  22. * Calculate the log iovec length for a given user buffer length. Intended to be
  23. * used by ->iop_size implementations when sizing buffers of arbitrary
  24. * alignments.
  25. */
  26. static inline int
  27. xlog_calc_iovec_len(int len)
  28. {
  29. return roundup(len, sizeof(uint32_t));
  30. }
  31. void *xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
  32. uint type);
  33. static inline void
  34. xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec,
  35. int data_len)
  36. {
  37. struct xlog_op_header *oph = vec->i_addr;
  38. int len;
  39. /*
  40. * Always round up the length to the correct alignment so callers don't
  41. * need to know anything about this log vec layout requirement. This
  42. * means we have to zero the area the data to be written does not cover.
  43. * This is complicated by fact the payload region is offset into the
  44. * logvec region by the opheader that tracks the payload.
  45. */
  46. len = xlog_calc_iovec_len(data_len);
  47. if (len - data_len != 0) {
  48. char *buf = vec->i_addr + sizeof(struct xlog_op_header);
  49. memset(buf + data_len, 0, len - data_len);
  50. }
  51. /*
  52. * The opheader tracks aligned payload length, whilst the logvec tracks
  53. * the overall region length.
  54. */
  55. oph->oh_len = cpu_to_be32(len);
  56. len += sizeof(struct xlog_op_header);
  57. lv->lv_buf_len += len;
  58. lv->lv_bytes += len;
  59. vec->i_len = len;
  60. /* Catch buffer overruns */
  61. ASSERT((void *)lv->lv_buf + lv->lv_bytes <= (void *)lv + lv->lv_size);
  62. }
  63. /*
  64. * Copy the amount of data requested by the caller into a new log iovec.
  65. */
  66. static inline void *
  67. xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
  68. uint type, void *data, int len)
  69. {
  70. void *buf;
  71. buf = xlog_prepare_iovec(lv, vecp, type);
  72. memcpy(buf, data, len);
  73. xlog_finish_iovec(lv, *vecp, len);
  74. return buf;
  75. }
  76. static inline void *
  77. xlog_copy_from_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
  78. const struct xfs_log_iovec *src)
  79. {
  80. return xlog_copy_iovec(lv, vecp, src->i_type, src->i_addr, src->i_len);
  81. }
  82. /*
  83. * By comparing each component, we don't have to worry about extra
  84. * endian issues in treating two 32 bit numbers as one 64 bit number
  85. */
  86. static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
  87. {
  88. if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
  89. return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
  90. if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
  91. return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
  92. return 0;
  93. }
  94. #define XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
  95. /*
  96. * Flags to xfs_log_force()
  97. *
  98. * XFS_LOG_SYNC: Synchronous force in-core log to disk
  99. */
  100. #define XFS_LOG_SYNC 0x1
  101. /* Log manager interfaces */
  102. struct xfs_mount;
  103. struct xlog_in_core;
  104. struct xlog_ticket;
  105. struct xfs_log_item;
  106. struct xfs_item_ops;
  107. struct xfs_trans;
  108. struct xlog;
  109. int xfs_log_force(struct xfs_mount *mp, uint flags);
  110. int xfs_log_force_seq(struct xfs_mount *mp, xfs_csn_t seq, uint flags,
  111. int *log_forced);
  112. int xfs_log_mount(struct xfs_mount *mp,
  113. struct xfs_buftarg *log_target,
  114. xfs_daddr_t start_block,
  115. int num_bblocks);
  116. int xfs_log_mount_finish(struct xfs_mount *mp);
  117. void xfs_log_mount_cancel(struct xfs_mount *);
  118. xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
  119. xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
  120. void xfs_log_space_wake(struct xfs_mount *mp);
  121. int xfs_log_reserve(struct xfs_mount *mp, int length, int count,
  122. struct xlog_ticket **ticket, bool permanent);
  123. int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
  124. void xfs_log_unmount(struct xfs_mount *mp);
  125. bool xfs_log_writable(struct xfs_mount *mp);
  126. struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
  127. void xfs_log_ticket_put(struct xlog_ticket *ticket);
  128. void xlog_cil_process_committed(struct list_head *list);
  129. bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
  130. void xfs_log_work_queue(struct xfs_mount *mp);
  131. int xfs_log_quiesce(struct xfs_mount *mp);
  132. void xfs_log_clean(struct xfs_mount *mp);
  133. bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
  134. xfs_lsn_t xlog_grant_push_threshold(struct xlog *log, int need_bytes);
  135. bool xlog_force_shutdown(struct xlog *log, uint32_t shutdown_flags);
  136. void xlog_use_incompat_feat(struct xlog *log);
  137. void xlog_drop_incompat_feat(struct xlog *log);
  138. int xfs_attr_use_log_assist(struct xfs_mount *mp);
  139. #endif /* __XFS_LOG_H__ */