segbuf.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #include <linux/backing-dev.h>
  30. /**
  31. * struct nilfs_segsum_info - On-memory segment summary
  32. * @flags: Flags
  33. * @nfinfo: Number of file information structures
  34. * @nblocks: Number of blocks included in the partial segment
  35. * @nsumblk: Number of summary blocks
  36. * @sumbytes: Byte count of segment summary
  37. * @nfileblk: Total number of file blocks
  38. * @seg_seq: Segment sequence 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. time_t ctime;
  51. sector_t next;
  52. };
  53. /* macro for the flags */
  54. #define NILFS_SEG_HAS_SR(sum) ((sum)->flags & NILFS_SS_SR)
  55. #define NILFS_SEG_LOGBGN(sum) ((sum)->flags & NILFS_SS_LOGBGN)
  56. #define NILFS_SEG_LOGEND(sum) ((sum)->flags & NILFS_SS_LOGEND)
  57. #define NILFS_SEG_DSYNC(sum) ((sum)->flags & NILFS_SS_SYNDT)
  58. #define NILFS_SEG_SIMPLEX(sum) \
  59. (((sum)->flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == \
  60. (NILFS_SS_LOGBGN | NILFS_SS_LOGEND))
  61. #define NILFS_SEG_EMPTY(sum) ((sum)->nblocks == (sum)->nsumblk)
  62. /**
  63. * struct nilfs_segment_buffer - Segment buffer
  64. * @sb_super: back pointer to a superblock struct
  65. * @sb_list: List head to chain this structure
  66. * @sb_segent: Pointer for attaching a segment entry
  67. * @sb_sum: On-memory segment summary
  68. * @sb_segnum: Index number of the full segment
  69. * @sb_nextnum: Index number of the next full segment
  70. * @sb_fseg_start: Start block number of the full segment
  71. * @sb_fseg_end: End block number of the full segment
  72. * @sb_pseg_start: Disk block number of partial segment
  73. * @sb_rest_blocks: Number of residual blocks in the current segment
  74. * @sb_segsum_buffers: List of buffers for segment summaries
  75. * @sb_payload_buffers: List of buffers for segment payload
  76. * @sb_io_error: I/O error status
  77. */
  78. struct nilfs_segment_buffer {
  79. struct super_block *sb_super;
  80. struct list_head sb_list;
  81. struct nilfs_segment_entry *sb_segent;
  82. /* Segment information */
  83. struct nilfs_segsum_info sb_sum;
  84. __u64 sb_segnum;
  85. __u64 sb_nextnum;
  86. sector_t sb_fseg_start, sb_fseg_end;
  87. sector_t sb_pseg_start;
  88. unsigned sb_rest_blocks;
  89. /* Buffers */
  90. struct list_head sb_segsum_buffers;
  91. struct list_head sb_payload_buffers; /* including super root */
  92. /* io status */
  93. int sb_io_error;
  94. };
  95. #define NILFS_LIST_SEGBUF(head) \
  96. list_entry((head), struct nilfs_segment_buffer, sb_list)
  97. #define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
  98. #define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
  99. #define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
  100. #define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
  101. #define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
  102. #define nilfs_for_each_segbuf_before(s, t, h) \
  103. for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
  104. (s) = NILFS_NEXT_SEGBUF(s))
  105. #define NILFS_SEGBUF_FIRST_BH(head) \
  106. (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
  107. #define NILFS_SEGBUF_NEXT_BH(bh) \
  108. (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
  109. b_assoc_buffers))
  110. #define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
  111. int __init nilfs_init_segbuf_cache(void);
  112. void nilfs_destroy_segbuf_cache(void);
  113. struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
  114. void nilfs_segbuf_free(struct nilfs_segment_buffer *);
  115. int nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
  116. struct the_nilfs *);
  117. void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
  118. struct the_nilfs *);
  119. int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t);
  120. int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
  121. int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
  122. struct buffer_head **);
  123. void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
  124. void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *, u32);
  125. void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *, u32);
  126. static inline void
  127. nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
  128. struct buffer_head *bh)
  129. {
  130. list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
  131. segbuf->sb_sum.nblocks++;
  132. segbuf->sb_sum.nsumblk++;
  133. }
  134. static inline void
  135. nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
  136. struct buffer_head *bh)
  137. {
  138. list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
  139. segbuf->sb_sum.nblocks++;
  140. }
  141. static inline void
  142. nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
  143. struct buffer_head *bh)
  144. {
  145. get_bh(bh);
  146. nilfs_segbuf_add_payload_buffer(segbuf, bh);
  147. segbuf->sb_sum.nfileblk++;
  148. }
  149. void nilfs_release_buffers(struct list_head *);
  150. static inline void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
  151. {
  152. nilfs_release_buffers(&segbuf->sb_segsum_buffers);
  153. nilfs_release_buffers(&segbuf->sb_payload_buffers);
  154. }
  155. struct nilfs_write_info {
  156. struct bio *bio;
  157. int start, end; /* The region to be submitted */
  158. int rest_blocks;
  159. int max_pages;
  160. int nr_vecs;
  161. sector_t blocknr;
  162. int nbio;
  163. atomic_t err;
  164. struct completion bio_event;
  165. /* completion event of segment write */
  166. /*
  167. * The following fields must be set explicitly
  168. */
  169. struct super_block *sb;
  170. struct backing_dev_info *bdi; /* backing dev info */
  171. struct buffer_head *bh_sr;
  172. };
  173. void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *,
  174. struct nilfs_write_info *);
  175. int nilfs_segbuf_write(struct nilfs_segment_buffer *,
  176. struct nilfs_write_info *);
  177. int nilfs_segbuf_wait(struct nilfs_segment_buffer *,
  178. struct nilfs_write_info *);
  179. #endif /* _NILFS_SEGBUF_H */