segbuf.h 6.2 KB

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