1
2
3
4
5
6
7
8
9
10#ifndef _NILFS_SEGBUF_H
11#define _NILFS_SEGBUF_H
12
13#include <linux/fs.h>
14#include <linux/buffer_head.h>
15#include <linux/bio.h>
16#include <linux/completion.h>
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31struct nilfs_segsum_info {
32 unsigned int flags;
33 unsigned long nfinfo;
34 unsigned long nblocks;
35 unsigned long nsumblk;
36 unsigned long sumbytes;
37 unsigned long nfileblk;
38 u64 seg_seq;
39 __u64 cno;
40 time64_t ctime;
41 sector_t next;
42};
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct nilfs_segment_buffer {
63 struct super_block *sb_super;
64 struct list_head sb_list;
65
66
67 struct nilfs_segsum_info sb_sum;
68 __u64 sb_segnum;
69 __u64 sb_nextnum;
70 sector_t sb_fseg_start, sb_fseg_end;
71 sector_t sb_pseg_start;
72 unsigned int sb_rest_blocks;
73
74
75 struct list_head sb_segsum_buffers;
76 struct list_head sb_payload_buffers;
77 struct buffer_head *sb_super_root;
78
79
80 int sb_nbio;
81 atomic_t sb_err;
82 struct completion sb_bio_event;
83};
84
85#define NILFS_LIST_SEGBUF(head) \
86 list_entry((head), struct nilfs_segment_buffer, sb_list)
87#define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
88#define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
89#define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
90#define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
91#define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
92
93#define nilfs_for_each_segbuf_before(s, t, h) \
94 for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
95 (s) = NILFS_NEXT_SEGBUF(s))
96
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
104extern struct kmem_cache *nilfs_segbuf_cachep;
105
106struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
107void nilfs_segbuf_free(struct nilfs_segment_buffer *);
108void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
109 struct the_nilfs *);
110void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
111 struct nilfs_segment_buffer *prev);
112void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
113 struct the_nilfs *);
114int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t,
115 __u64);
116int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
117int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
118 struct buffer_head **);
119void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
120
121static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf)
122{
123 unsigned int flags = segbuf->sb_sum.flags;
124
125 return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) ==
126 (NILFS_SS_LOGBGN | NILFS_SS_LOGEND);
127}
128
129static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
130{
131 return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
132}
133
134static inline void
135nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
136 struct buffer_head *bh)
137{
138 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
139 segbuf->sb_sum.nblocks++;
140 segbuf->sb_sum.nsumblk++;
141}
142
143static inline void
144nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
145 struct buffer_head *bh)
146{
147 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
148 segbuf->sb_sum.nblocks++;
149}
150
151static inline void
152nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
153 struct buffer_head *bh)
154{
155 get_bh(bh);
156 nilfs_segbuf_add_payload_buffer(segbuf, bh);
157 segbuf->sb_sum.nfileblk++;
158}
159
160void nilfs_clear_logs(struct list_head *logs);
161void nilfs_truncate_logs(struct list_head *logs,
162 struct nilfs_segment_buffer *last);
163int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
164int nilfs_wait_on_logs(struct list_head *logs);
165void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
166
167static inline void nilfs_destroy_logs(struct list_head *logs)
168{
169 nilfs_truncate_logs(logs, NULL);
170}
171
172#endif
173