1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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>
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44struct 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;
52 __u64 cno;
53 time_t ctime;
54 sector_t next;
55};
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75struct nilfs_segment_buffer {
76 struct super_block *sb_super;
77 struct list_head sb_list;
78
79
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
88 struct list_head sb_segsum_buffers;
89 struct list_head sb_payload_buffers;
90 struct buffer_head *sb_super_root;
91
92
93 int sb_nbio;
94 atomic_t sb_err;
95 struct completion sb_bio_event;
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
117extern struct kmem_cache *nilfs_segbuf_cachep;
118
119struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
120void nilfs_segbuf_free(struct nilfs_segment_buffer *);
121void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
122 struct the_nilfs *);
123void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
124 struct nilfs_segment_buffer *prev);
125void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
126 struct the_nilfs *);
127int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t, __u64);
128int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
129int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
130 struct buffer_head **);
131void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
132
133static 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
141static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
142{
143 return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
144}
145
146static inline void
147nilfs_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
155static inline void
156nilfs_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
163static inline void
164nilfs_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
172void nilfs_clear_logs(struct list_head *logs);
173void nilfs_truncate_logs(struct list_head *logs,
174 struct nilfs_segment_buffer *last);
175int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
176int nilfs_wait_on_logs(struct list_head *logs);
177void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
178
179static inline void nilfs_destroy_logs(struct list_head *logs)
180{
181 nilfs_truncate_logs(logs, NULL);
182}
183
184#endif
185