segbuf.h 6.0 KB

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