| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 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 |  | 
 | 26 | #include <linux/fs.h> | 
 | 27 | #include <linux/buffer_head.h> | 
 | 28 | #include <linux/bio.h> | 
 | 29 | #include <linux/completion.h> | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 30 |  | 
 | 31 | /** | 
 | 32 |  * struct nilfs_segsum_info - On-memory segment summary | 
 | 33 |  * @flags: Flags | 
 | 34 |  * @nfinfo: Number of file information structures | 
 | 35 |  * @nblocks: Number of blocks included in the partial segment | 
 | 36 |  * @nsumblk: Number of summary blocks | 
 | 37 |  * @sumbytes: Byte count of segment summary | 
 | 38 |  * @nfileblk: Total number of file blocks | 
 | 39 |  * @seg_seq: Segment sequence number | 
| Ryusuke Konishi | 50614bc | 2010-04-10 17:59:15 +0900 | [diff] [blame] | 40 |  * @cno: Checkpoint number | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 41 |  * @ctime: Creation time | 
 | 42 |  * @next: Block number of the next full segment | 
 | 43 |  */ | 
 | 44 | struct nilfs_segsum_info { | 
 | 45 | 	unsigned int		flags; | 
 | 46 | 	unsigned long		nfinfo; | 
 | 47 | 	unsigned long		nblocks; | 
 | 48 | 	unsigned long		nsumblk; | 
 | 49 | 	unsigned long		sumbytes; | 
 | 50 | 	unsigned long		nfileblk; | 
 | 51 | 	u64			seg_seq; | 
| Ryusuke Konishi | 50614bc | 2010-04-10 17:59:15 +0900 | [diff] [blame] | 52 | 	__u64			cno; | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 53 | 	time_t			ctime; | 
 | 54 | 	sector_t		next; | 
 | 55 | }; | 
 | 56 |  | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 57 | /** | 
 | 58 |  * struct nilfs_segment_buffer - Segment buffer | 
 | 59 |  * @sb_super: back pointer to a superblock struct | 
 | 60 |  * @sb_list: List head to chain this structure | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 61 |  * @sb_sum: On-memory segment summary | 
 | 62 |  * @sb_segnum: Index number of the full segment | 
 | 63 |  * @sb_nextnum: Index number of the next full segment | 
 | 64 |  * @sb_fseg_start: Start block number of the full segment | 
 | 65 |  * @sb_fseg_end: End block number of the full segment | 
 | 66 |  * @sb_pseg_start: Disk block number of partial segment | 
 | 67 |  * @sb_rest_blocks: Number of residual blocks in the current segment | 
 | 68 |  * @sb_segsum_buffers: List of buffers for segment summaries | 
 | 69 |  * @sb_payload_buffers: List of buffers for segment payload | 
| Ryusuke Konishi | 1e2b68b | 2010-03-23 01:15:31 +0900 | [diff] [blame] | 70 |  * @sb_super_root: Pointer to buffer storing a super root block (if exists) | 
| Ryusuke Konishi | 9284ad2 | 2009-11-25 01:04:21 +0900 | [diff] [blame] | 71 |  * @sb_nbio: Number of flying bio requests | 
 | 72 |  * @sb_err: I/O error status | 
 | 73 |  * @sb_bio_event: Completion event of log writing | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 74 |  */ | 
 | 75 | struct nilfs_segment_buffer { | 
 | 76 | 	struct super_block     *sb_super; | 
 | 77 | 	struct list_head	sb_list; | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 78 |  | 
 | 79 | 	/* Segment information */ | 
 | 80 | 	struct nilfs_segsum_info sb_sum; | 
 | 81 | 	__u64			sb_segnum; | 
 | 82 | 	__u64			sb_nextnum; | 
 | 83 | 	sector_t		sb_fseg_start, sb_fseg_end; | 
 | 84 | 	sector_t		sb_pseg_start; | 
 | 85 | 	unsigned		sb_rest_blocks; | 
 | 86 |  | 
 | 87 | 	/* Buffers */ | 
 | 88 | 	struct list_head	sb_segsum_buffers; | 
 | 89 | 	struct list_head	sb_payload_buffers; /* including super root */ | 
| Ryusuke Konishi | 1e2b68b | 2010-03-23 01:15:31 +0900 | [diff] [blame] | 90 | 	struct buffer_head     *sb_super_root; | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 91 |  | 
 | 92 | 	/* io status */ | 
| Ryusuke Konishi | 9284ad2 | 2009-11-25 01:04:21 +0900 | [diff] [blame] | 93 | 	int			sb_nbio; | 
 | 94 | 	atomic_t		sb_err; | 
 | 95 | 	struct completion	sb_bio_event; | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 96 | }; | 
 | 97 |  | 
 | 98 | #define NILFS_LIST_SEGBUF(head)  \ | 
 | 99 | 	list_entry((head), struct nilfs_segment_buffer, sb_list) | 
 | 100 | #define NILFS_NEXT_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.next) | 
 | 101 | #define NILFS_PREV_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.prev) | 
 | 102 | #define NILFS_LAST_SEGBUF(head)    NILFS_LIST_SEGBUF((head)->prev) | 
 | 103 | #define NILFS_FIRST_SEGBUF(head)   NILFS_LIST_SEGBUF((head)->next) | 
 | 104 | #define NILFS_SEGBUF_IS_LAST(segbuf, head)  ((segbuf)->sb_list.next == (head)) | 
 | 105 |  | 
 | 106 | #define nilfs_for_each_segbuf_before(s, t, h) \ | 
 | 107 | 	for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \ | 
 | 108 | 	     (s) = NILFS_NEXT_SEGBUF(s)) | 
 | 109 |  | 
 | 110 | #define NILFS_SEGBUF_FIRST_BH(head)  \ | 
 | 111 | 	(list_entry((head)->next, struct buffer_head, b_assoc_buffers)) | 
 | 112 | #define NILFS_SEGBUF_NEXT_BH(bh)  \ | 
 | 113 | 	(list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \ | 
 | 114 | 		    b_assoc_buffers)) | 
 | 115 | #define NILFS_SEGBUF_BH_IS_LAST(bh, head)  ((bh)->b_assoc_buffers.next == head) | 
 | 116 |  | 
| Li Hong | 41c88bd | 2010-04-06 00:54:11 +0800 | [diff] [blame] | 117 | extern struct kmem_cache *nilfs_segbuf_cachep; | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 118 |  | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 119 | struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *); | 
 | 120 | void nilfs_segbuf_free(struct nilfs_segment_buffer *); | 
| Ryusuke Konishi | cece552 | 2009-04-06 19:01:58 -0700 | [diff] [blame] | 121 | void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long, | 
 | 122 | 		      struct the_nilfs *); | 
| Ryusuke Konishi | a694291 | 2009-11-29 23:03:04 +0900 | [diff] [blame] | 123 | void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf, | 
 | 124 | 			   struct nilfs_segment_buffer *prev); | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 125 | void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64, | 
 | 126 | 				  struct the_nilfs *); | 
| Ryusuke Konishi | 50614bc | 2010-04-10 17:59:15 +0900 | [diff] [blame] | 127 | int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t, __u64); | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 128 | int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *); | 
 | 129 | int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *, | 
 | 130 | 				struct buffer_head **); | 
 | 131 | void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *); | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 132 |  | 
| Ryusuke Konishi | 4762077 | 2010-05-23 21:48:36 +0900 | [diff] [blame] | 133 | static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf) | 
 | 134 | { | 
 | 135 | 	unsigned int flags = segbuf->sb_sum.flags; | 
 | 136 |  | 
 | 137 | 	return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == | 
 | 138 | 		(NILFS_SS_LOGBGN | NILFS_SS_LOGEND); | 
 | 139 | } | 
 | 140 |  | 
 | 141 | static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf) | 
 | 142 | { | 
 | 143 | 	return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk; | 
 | 144 | } | 
 | 145 |  | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 146 | static inline void | 
 | 147 | nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf, | 
 | 148 | 			       struct buffer_head *bh) | 
 | 149 | { | 
 | 150 | 	list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers); | 
 | 151 | 	segbuf->sb_sum.nblocks++; | 
 | 152 | 	segbuf->sb_sum.nsumblk++; | 
 | 153 | } | 
 | 154 |  | 
 | 155 | static inline void | 
 | 156 | nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf, | 
 | 157 | 				struct buffer_head *bh) | 
 | 158 | { | 
 | 159 | 	list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers); | 
 | 160 | 	segbuf->sb_sum.nblocks++; | 
 | 161 | } | 
 | 162 |  | 
 | 163 | static inline void | 
 | 164 | nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf, | 
 | 165 | 			     struct buffer_head *bh) | 
 | 166 | { | 
 | 167 | 	get_bh(bh); | 
 | 168 | 	nilfs_segbuf_add_payload_buffer(segbuf, bh); | 
 | 169 | 	segbuf->sb_sum.nfileblk++; | 
 | 170 | } | 
 | 171 |  | 
| Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 172 | void nilfs_clear_logs(struct list_head *logs); | 
 | 173 | void nilfs_truncate_logs(struct list_head *logs, | 
 | 174 | 			 struct nilfs_segment_buffer *last); | 
| Ryusuke Konishi | d1c6b72 | 2009-12-17 00:55:40 +0900 | [diff] [blame] | 175 | int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs); | 
| Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 176 | int nilfs_wait_on_logs(struct list_head *logs); | 
| Ryusuke Konishi | aaed1d5 | 2010-03-23 01:50:38 +0900 | [diff] [blame] | 177 | void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed); | 
| Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 178 |  | 
 | 179 | static inline void nilfs_destroy_logs(struct list_head *logs) | 
 | 180 | { | 
 | 181 | 	nilfs_truncate_logs(logs, NULL); | 
 | 182 | } | 
 | 183 |  | 
| Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 184 | #endif /* _NILFS_SEGBUF_H */ |