aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-03-22 12:50:38 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-05-09 22:32:30 -0400
commitaaed1d5bfac459ead9aaad324e7fe3326250f50a (patch)
tree389f305354db9a45a482ff38e5f0ffab030c76bd
parent1e2b68bf285dce604388fcb6f85b7e612156db17 (diff)
nilfs2: move out checksum routines to segment buffer code
This moves out checksum routines in log writer to segbuf.c for cleanup. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
-rw-r--r--fs/nilfs2/segbuf.c39
-rw-r--r--fs/nilfs2/segbuf.h3
-rw-r--r--fs/nilfs2/segment.c33
3 files changed, 39 insertions, 36 deletions
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index a24ca9cc6afb..6bf3b1f3406e 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -202,8 +202,8 @@ void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *segbuf)
202/* 202/*
203 * CRC calculation routines 203 * CRC calculation routines
204 */ 204 */
205void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *segbuf, 205static void
206 u32 seed) 206nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *segbuf, u32 seed)
207{ 207{
208 struct buffer_head *bh; 208 struct buffer_head *bh;
209 struct nilfs_segment_summary *raw_sum; 209 struct nilfs_segment_summary *raw_sum;
@@ -230,8 +230,8 @@ void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *segbuf,
230 raw_sum->ss_sumsum = cpu_to_le32(crc); 230 raw_sum->ss_sumsum = cpu_to_le32(crc);
231} 231}
232 232
233void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf, 233static void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf,
234 u32 seed) 234 u32 seed)
235{ 235{
236 struct buffer_head *bh; 236 struct buffer_head *bh;
237 struct nilfs_segment_summary *raw_sum; 237 struct nilfs_segment_summary *raw_sum;
@@ -257,6 +257,20 @@ void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf,
257 raw_sum->ss_datasum = cpu_to_le32(crc); 257 raw_sum->ss_datasum = cpu_to_le32(crc);
258} 258}
259 259
260static void
261nilfs_segbuf_fill_in_super_root_crc(struct nilfs_segment_buffer *segbuf,
262 u32 seed)
263{
264 struct nilfs_super_root *raw_sr;
265 u32 crc;
266
267 raw_sr = (struct nilfs_super_root *)segbuf->sb_super_root->b_data;
268 crc = crc32_le(seed,
269 (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum),
270 NILFS_SR_BYTES - sizeof(raw_sr->sr_sum));
271 raw_sr->sr_sum = cpu_to_le32(crc);
272}
273
260static void nilfs_release_buffers(struct list_head *list) 274static void nilfs_release_buffers(struct list_head *list)
261{ 275{
262 struct buffer_head *bh, *n; 276 struct buffer_head *bh, *n;
@@ -336,6 +350,23 @@ int nilfs_wait_on_logs(struct list_head *logs)
336 return ret; 350 return ret;
337} 351}
338 352
353/**
354 * nilfs_add_checksums_on_logs - add checksums on the logs
355 * @logs: list of segment buffers storing target logs
356 * @seed: checksum seed value
357 */
358void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed)
359{
360 struct nilfs_segment_buffer *segbuf;
361
362 list_for_each_entry(segbuf, logs, sb_list) {
363 if (segbuf->sb_super_root)
364 nilfs_segbuf_fill_in_super_root_crc(segbuf, seed);
365 nilfs_segbuf_fill_in_segsum_crc(segbuf, seed);
366 nilfs_segbuf_fill_in_data_crc(segbuf, seed);
367 }
368}
369
339/* 370/*
340 * BIO operations 371 * BIO operations
341 */ 372 */
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index a1a0af6119ea..ae12c2c3e370 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -139,8 +139,6 @@ int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
139int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *, 139int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
140 struct buffer_head **); 140 struct buffer_head **);
141void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *); 141void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
142void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *, u32);
143void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *, u32);
144 142
145static inline void 143static inline void
146nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf, 144nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
@@ -173,6 +171,7 @@ void nilfs_truncate_logs(struct list_head *logs,
173 struct nilfs_segment_buffer *last); 171 struct nilfs_segment_buffer *last);
174int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs); 172int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
175int nilfs_wait_on_logs(struct list_head *logs); 173int nilfs_wait_on_logs(struct list_head *logs);
174void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
176 175
177static inline void nilfs_destroy_logs(struct list_head *logs) 176static inline void nilfs_destroy_logs(struct list_head *logs)
178{ 177{
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 7ab0270b2629..f649f0189589 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -932,35 +932,6 @@ static void nilfs_segctor_fill_in_file_bmap(struct nilfs_sc_info *sci,
932 } 932 }
933} 933}
934 934
935/*
936 * CRC calculation routines
937 */
938static void nilfs_fill_in_super_root_crc(struct buffer_head *bh_sr, u32 seed)
939{
940 struct nilfs_super_root *raw_sr =
941 (struct nilfs_super_root *)bh_sr->b_data;
942 u32 crc;
943
944 crc = crc32_le(seed,
945 (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum),
946 NILFS_SR_BYTES - sizeof(raw_sr->sr_sum));
947 raw_sr->sr_sum = cpu_to_le32(crc);
948}
949
950static void nilfs_segctor_fill_in_checksums(struct nilfs_sc_info *sci,
951 u32 seed)
952{
953 struct nilfs_segment_buffer *segbuf;
954
955 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) {
956 if (segbuf->sb_super_root)
957 nilfs_fill_in_super_root_crc(segbuf->sb_super_root,
958 seed);
959 nilfs_segbuf_fill_in_segsum_crc(segbuf, seed);
960 nilfs_segbuf_fill_in_data_crc(segbuf, seed);
961 }
962}
963
964static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci, 935static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci,
965 struct the_nilfs *nilfs) 936 struct the_nilfs *nilfs)
966{ 937{
@@ -2174,7 +2145,9 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2174 nilfs_abort_logs(&sci->sc_segbufs, failed_page, err); 2145 nilfs_abort_logs(&sci->sc_segbufs, failed_page, err);
2175 goto failed_to_write; 2146 goto failed_to_write;
2176 } 2147 }
2177 nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed); 2148
2149 nilfs_add_checksums_on_logs(&sci->sc_segbufs,
2150 nilfs->ns_crc_seed);
2178 2151
2179 err = nilfs_segctor_write(sci, nilfs); 2152 err = nilfs_segctor_write(sci, nilfs);
2180 if (unlikely(err)) 2153 if (unlikely(err))