aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/segment.c
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/segment.c
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/segment.c')
-rw-r--r--fs/nilfs2/segment.c51
1 files changed, 12 insertions, 39 deletions
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