segbuf.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * segbuf.h - NILFS Segment buffer prototypes and definitions
  4. *
  5. * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
  6. *
  7. * Written by Ryusuke Konishi.
  8. *
  9. */
  10. #ifndef _NILFS_SEGBUF_H
  11. #define _NILFS_SEGBUF_H
  12. #include <linux/fs.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/bio.h>
  15. #include <linux/completion.h>
  16. /**
  17. * struct nilfs_segsum_info - On-memory segment summary
  18. * @flags: Flags
  19. * @nfinfo: Number of file information structures
  20. * @nblocks: Number of blocks included in the partial segment
  21. * @nsumblk: Number of summary blocks
  22. * @sumbytes: Byte count of segment summary
  23. * @nfileblk: Total number of file blocks
  24. * @seg_seq: Segment sequence number
  25. * @cno: Checkpoint number
  26. * @ctime: Creation time
  27. * @next: Block number of the next full segment
  28. */
  29. struct nilfs_segsum_info {
  30. unsigned int flags;
  31. unsigned long nfinfo;
  32. unsigned long nblocks;
  33. unsigned long nsumblk;
  34. unsigned long sumbytes;
  35. unsigned long nfileblk;
  36. u64 seg_seq;
  37. __u64 cno;
  38. time64_t ctime;
  39. sector_t next;
  40. };
  41. /**
  42. * struct nilfs_segment_buffer - Segment buffer
  43. * @sb_super: back pointer to a superblock struct
  44. * @sb_list: List head to chain this structure
  45. * @sb_sum: On-memory segment summary
  46. * @sb_segnum: Index number of the full segment
  47. * @sb_nextnum: Index number of the next full segment
  48. * @sb_fseg_start: Start block number of the full segment
  49. * @sb_fseg_end: End block number of the full segment
  50. * @sb_pseg_start: Disk block number of partial segment
  51. * @sb_rest_blocks: Number of residual blocks in the current segment
  52. * @sb_segsum_buffers: List of buffers for segment summaries
  53. * @sb_payload_buffers: List of buffers for segment payload
  54. * @sb_super_root: Pointer to buffer storing a super root block (if exists)
  55. * @sb_nbio: Number of flying bio requests
  56. * @sb_err: I/O error status
  57. * @sb_bio_event: Completion event of log writing
  58. */
  59. struct nilfs_segment_buffer {
  60. struct super_block *sb_super;
  61. struct list_head sb_list;
  62. /* Segment information */
  63. struct nilfs_segsum_info sb_sum;
  64. __u64 sb_segnum;
  65. __u64 sb_nextnum;
  66. sector_t sb_fseg_start, sb_fseg_end;
  67. sector_t sb_pseg_start;
  68. unsigned int sb_rest_blocks;
  69. /* Buffers */
  70. struct list_head sb_segsum_buffers;
  71. struct list_head sb_payload_buffers; /* including super root */
  72. struct buffer_head *sb_super_root;
  73. /* io status */
  74. int sb_nbio;
  75. atomic_t sb_err;
  76. struct completion sb_bio_event;
  77. };
  78. #define NILFS_LIST_SEGBUF(head) \
  79. list_entry((head), struct nilfs_segment_buffer, sb_list)
  80. #define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
  81. #define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
  82. #define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
  83. #define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
  84. #define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
  85. #define nilfs_for_each_segbuf_before(s, t, h) \
  86. for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
  87. (s) = NILFS_NEXT_SEGBUF(s))
  88. #define NILFS_SEGBUF_FIRST_BH(head) \
  89. (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
  90. #define NILFS_SEGBUF_NEXT_BH(bh) \
  91. (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
  92. b_assoc_buffers))
  93. #define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
  94. extern struct kmem_cache *nilfs_segbuf_cachep;
  95. struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
  96. void nilfs_segbuf_free(struct nilfs_segment_buffer *);
  97. void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
  98. struct the_nilfs *);
  99. void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
  100. struct nilfs_segment_buffer *prev);
  101. void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
  102. struct the_nilfs *);
  103. int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t,
  104. __u64);
  105. int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
  106. int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
  107. struct buffer_head **);
  108. void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
  109. static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf)
  110. {
  111. unsigned int flags = segbuf->sb_sum.flags;
  112. return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) ==
  113. (NILFS_SS_LOGBGN | NILFS_SS_LOGEND);
  114. }
  115. static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
  116. {
  117. return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
  118. }
  119. static inline void
  120. nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
  121. struct buffer_head *bh)
  122. {
  123. list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
  124. segbuf->sb_sum.nblocks++;
  125. segbuf->sb_sum.nsumblk++;
  126. }
  127. static inline void
  128. nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
  129. struct buffer_head *bh)
  130. {
  131. list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
  132. segbuf->sb_sum.nblocks++;
  133. }
  134. static inline void
  135. nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
  136. struct buffer_head *bh)
  137. {
  138. get_bh(bh);
  139. nilfs_segbuf_add_payload_buffer(segbuf, bh);
  140. segbuf->sb_sum.nfileblk++;
  141. }
  142. void nilfs_clear_logs(struct list_head *logs);
  143. void nilfs_truncate_logs(struct list_head *logs,
  144. struct nilfs_segment_buffer *last);
  145. int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
  146. int nilfs_wait_on_logs(struct list_head *logs);
  147. void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
  148. static inline void nilfs_destroy_logs(struct list_head *logs)
  149. {
  150. nilfs_truncate_logs(logs, NULL);
  151. }
  152. #endif /* _NILFS_SEGBUF_H */