aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-29 02:51:16 -0500
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-30 07:06:35 -0500
commite29df395bc6d2d0c89b3d8a5939a24b1b43c2fb6 (patch)
tree6d6f570d8158d7a18570492d9f5f5edf843ed28c /fs/nilfs2
parent9c965bac169f786cc6cca8ff81d3b636e923c960 (diff)
nilfs2: add iterator for segment buffers
This adds a few iterator functions for segment buffers to make it easy to handle multiple series of logs. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2')
-rw-r--r--fs/nilfs2/segbuf.c45
-rw-r--r--fs/nilfs2/segbuf.h18
-rw-r--r--fs/nilfs2/segment.c51
3 files changed, 66 insertions, 48 deletions
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 636590c92c8b..d856d62bf886 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -234,7 +234,7 @@ void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf,
234 raw_sum->ss_datasum = cpu_to_le32(crc); 234 raw_sum->ss_datasum = cpu_to_le32(crc);
235} 235}
236 236
237void nilfs_release_buffers(struct list_head *list) 237static void nilfs_release_buffers(struct list_head *list)
238{ 238{
239 struct buffer_head *bh, *n; 239 struct buffer_head *bh, *n;
240 240
@@ -256,6 +256,49 @@ void nilfs_release_buffers(struct list_head *list)
256 } 256 }
257} 257}
258 258
259static void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
260{
261 nilfs_release_buffers(&segbuf->sb_segsum_buffers);
262 nilfs_release_buffers(&segbuf->sb_payload_buffers);
263}
264
265/*
266 * Iterators for segment buffers
267 */
268void nilfs_clear_logs(struct list_head *logs)
269{
270 struct nilfs_segment_buffer *segbuf;
271
272 list_for_each_entry(segbuf, logs, sb_list)
273 nilfs_segbuf_clear(segbuf);
274}
275
276void nilfs_truncate_logs(struct list_head *logs,
277 struct nilfs_segment_buffer *last)
278{
279 struct nilfs_segment_buffer *n, *segbuf;
280
281 segbuf = list_prepare_entry(last, logs, sb_list);
282 list_for_each_entry_safe_continue(segbuf, n, logs, sb_list) {
283 list_del_init(&segbuf->sb_list);
284 nilfs_segbuf_clear(segbuf);
285 nilfs_segbuf_free(segbuf);
286 }
287}
288
289int nilfs_wait_on_logs(struct list_head *logs)
290{
291 struct nilfs_segment_buffer *segbuf;
292 int err;
293
294 list_for_each_entry(segbuf, logs, sb_list) {
295 err = nilfs_segbuf_wait(segbuf);
296 if (err)
297 return err;
298 }
299 return 0;
300}
301
259/* 302/*
260 * BIO operations 303 * BIO operations
261 */ 304 */
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index 241a00dc4988..7fbaf5eee016 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -164,16 +164,18 @@ nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
164 segbuf->sb_sum.nfileblk++; 164 segbuf->sb_sum.nfileblk++;
165} 165}
166 166
167void nilfs_release_buffers(struct list_head *);
168
169static inline void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
170{
171 nilfs_release_buffers(&segbuf->sb_segsum_buffers);
172 nilfs_release_buffers(&segbuf->sb_payload_buffers);
173}
174
175int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, 167int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
176 struct the_nilfs *nilfs); 168 struct the_nilfs *nilfs);
177int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); 169int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
178 170
171void nilfs_clear_logs(struct list_head *logs);
172void nilfs_truncate_logs(struct list_head *logs,
173 struct nilfs_segment_buffer *last);
174int nilfs_wait_on_logs(struct list_head *logs);
175
176static inline void nilfs_destroy_logs(struct list_head *logs)
177{
178 nilfs_truncate_logs(logs, NULL);
179}
180
179#endif /* _NILFS_SEGBUF_H */ 181#endif /* _NILFS_SEGBUF_H */
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 4422cdae112a..689deb9d41d1 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -1276,7 +1276,7 @@ static int nilfs_segctor_collect_blocks(struct nilfs_sc_info *sci, int mode)
1276static int nilfs_segctor_begin_construction(struct nilfs_sc_info *sci, 1276static int nilfs_segctor_begin_construction(struct nilfs_sc_info *sci,
1277 struct the_nilfs *nilfs) 1277 struct the_nilfs *nilfs)
1278{ 1278{
1279 struct nilfs_segment_buffer *segbuf, *n; 1279 struct nilfs_segment_buffer *segbuf;
1280 __u64 nextnum; 1280 __u64 nextnum;
1281 int err; 1281 int err;
1282 1282
@@ -1313,18 +1313,14 @@ static int nilfs_segctor_begin_construction(struct nilfs_sc_info *sci,
1313 nilfs_segbuf_set_next_segnum(segbuf, nextnum, nilfs); 1313 nilfs_segbuf_set_next_segnum(segbuf, nextnum, nilfs);
1314 1314
1315 /* truncating segment buffers */ 1315 /* truncating segment buffers */
1316 list_for_each_entry_safe_continue(segbuf, n, &sci->sc_segbufs, 1316 nilfs_truncate_logs(&sci->sc_segbufs, segbuf);
1317 sb_list) {
1318 list_del_init(&segbuf->sb_list);
1319 nilfs_segbuf_free(segbuf);
1320 }
1321 return 0; 1317 return 0;
1322} 1318}
1323 1319
1324static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci, 1320static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci,
1325 struct the_nilfs *nilfs, int nadd) 1321 struct the_nilfs *nilfs, int nadd)
1326{ 1322{
1327 struct nilfs_segment_buffer *segbuf, *prev, *n; 1323 struct nilfs_segment_buffer *segbuf, *prev;
1328 struct inode *sufile = nilfs->ns_sufile; 1324 struct inode *sufile = nilfs->ns_sufile;
1329 __u64 nextnextnum; 1325 __u64 nextnextnum;
1330 LIST_HEAD(list); 1326 LIST_HEAD(list);
@@ -1369,12 +1365,11 @@ static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci,
1369 failed_segbuf: 1365 failed_segbuf:
1370 nilfs_segbuf_free(segbuf); 1366 nilfs_segbuf_free(segbuf);
1371 failed: 1367 failed:
1372 list_for_each_entry_safe(segbuf, n, &list, sb_list) { 1368 list_for_each_entry(segbuf, &list, sb_list) {
1373 ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); 1369 ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum);
1374 WARN_ON(ret); /* never fails */ 1370 WARN_ON(ret); /* never fails */
1375 list_del_init(&segbuf->sb_list);
1376 nilfs_segbuf_free(segbuf);
1377 } 1371 }
1372 nilfs_destroy_logs(&list);
1378 return err; 1373 return err;
1379} 1374}
1380 1375
@@ -1411,27 +1406,6 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci,
1411 } 1406 }
1412} 1407}
1413 1408
1414static void nilfs_segctor_clear_segment_buffers(struct nilfs_sc_info *sci)
1415{
1416 struct nilfs_segment_buffer *segbuf;
1417
1418 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list)
1419 nilfs_segbuf_clear(segbuf);
1420 sci->sc_super_root = NULL;
1421}
1422
1423static void nilfs_segctor_destroy_segment_buffers(struct nilfs_sc_info *sci)
1424{
1425 struct nilfs_segment_buffer *segbuf;
1426
1427 while (!list_empty(&sci->sc_segbufs)) {
1428 segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs);
1429 list_del_init(&segbuf->sb_list);
1430 nilfs_segbuf_free(segbuf);
1431 }
1432 /* sci->sc_curseg = NULL; */
1433}
1434
1435static void nilfs_segctor_end_construction(struct nilfs_sc_info *sci, 1409static void nilfs_segctor_end_construction(struct nilfs_sc_info *sci,
1436 struct the_nilfs *nilfs, int err) 1410 struct the_nilfs *nilfs, int err)
1437{ 1411{
@@ -1447,7 +1421,8 @@ static void nilfs_segctor_end_construction(struct nilfs_sc_info *sci,
1447 WARN_ON(ret); /* do not happen */ 1421 WARN_ON(ret); /* do not happen */
1448 } 1422 }
1449 } 1423 }
1450 nilfs_segctor_clear_segment_buffers(sci); 1424 nilfs_clear_logs(&sci->sc_segbufs);
1425 sci->sc_super_root = NULL;
1451} 1426}
1452 1427
1453static void nilfs_segctor_update_segusage(struct nilfs_sc_info *sci, 1428static void nilfs_segctor_update_segusage(struct nilfs_sc_info *sci,
@@ -1490,17 +1465,15 @@ static void nilfs_segctor_truncate_segments(struct nilfs_sc_info *sci,
1490 struct nilfs_segment_buffer *last, 1465 struct nilfs_segment_buffer *last,
1491 struct inode *sufile) 1466 struct inode *sufile)
1492{ 1467{
1493 struct nilfs_segment_buffer *segbuf = last, *n; 1468 struct nilfs_segment_buffer *segbuf = last;
1494 int ret; 1469 int ret;
1495 1470
1496 list_for_each_entry_safe_continue(segbuf, n, &sci->sc_segbufs, 1471 list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) {
1497 sb_list) {
1498 list_del_init(&segbuf->sb_list);
1499 sci->sc_segbuf_nblocks -= segbuf->sb_rest_blocks; 1472 sci->sc_segbuf_nblocks -= segbuf->sb_rest_blocks;
1500 ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum); 1473 ret = nilfs_sufile_free(sufile, segbuf->sb_nextnum);
1501 WARN_ON(ret); 1474 WARN_ON(ret);
1502 nilfs_segbuf_free(segbuf);
1503 } 1475 }
1476 nilfs_truncate_logs(&sci->sc_segbufs, last);
1504} 1477}
1505 1478
1506 1479
@@ -1539,7 +1512,7 @@ static int nilfs_segctor_collect(struct nilfs_sc_info *sci,
1539 NULL); 1512 NULL);
1540 WARN_ON(err); /* do not happen */ 1513 WARN_ON(err); /* do not happen */
1541 } 1514 }
1542 nilfs_segctor_clear_segment_buffers(sci); 1515 nilfs_clear_logs(&sci->sc_segbufs);
1543 1516
1544 err = nilfs_segctor_extend_segments(sci, nilfs, nadd); 1517 err = nilfs_segctor_extend_segments(sci, nilfs, nadd);
1545 if (unlikely(err)) 1518 if (unlikely(err))
@@ -2179,7 +2152,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2179 } while (sci->sc_stage.scnt != NILFS_ST_DONE); 2152 } while (sci->sc_stage.scnt != NILFS_ST_DONE);
2180 2153
2181 out: 2154 out:
2182 nilfs_segctor_destroy_segment_buffers(sci); 2155 nilfs_destroy_logs(&sci->sc_segbufs);
2183 nilfs_segctor_check_out_files(sci, sbi); 2156 nilfs_segctor_check_out_files(sci, sbi);
2184 return err; 2157 return err;
2185 2158