aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/free-space-cache.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@redhat.com>2011-05-27 14:07:49 -0400
committerJosef Bacik <josef@redhat.com>2011-06-08 16:37:28 -0400
commit2cdc342c204dba69ca3b2ec43d8e6ff41ed920b8 (patch)
treee077a03c0b17799150b837deeffb27f3842be536 /fs/btrfs/free-space-cache.c
parentf2bb8f5cfb3bce595b2de251ed7638047fc4e530 (diff)
Btrfs: fix bitmap regression
In cleaning up the clustering code I accidently introduced a regression by adding bitmap entries to the cluster rb tree. The problem is if we've maxed out the number of bitmaps we can have for the block group we can only add free space to the bitmaps, but since the bitmap is on the cluster we can't find it and we try to create another one. This would result in a panic because the total bitmaps was bigger than the max bitmaps that were allowed. This patch fixes this by checking to see if we have a cluster, and then looking at the cluster rb tree to see if it has a bitmap entry and if it does and that space belongs to that bitmap, go ahead and add it to that bitmap. I could hit this panic every time with an fs_mark test within a couple of minutes. With this patch I no longer hit the panic and fs_mark goes to completion. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/free-space-cache.c')
-rw-r--r--fs/btrfs/free-space-cache.c88
1 files changed, 69 insertions, 19 deletions
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index f56caacfd8ad..8258ccf85dbd 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -1417,6 +1417,23 @@ again:
1417 return 0; 1417 return 0;
1418} 1418}
1419 1419
1420static u64 add_bytes_to_bitmap(struct btrfs_free_space_ctl *ctl,
1421 struct btrfs_free_space *info, u64 offset,
1422 u64 bytes)
1423{
1424 u64 bytes_to_set = 0;
1425 u64 end;
1426
1427 end = info->offset + (u64)(BITS_PER_BITMAP * ctl->unit);
1428
1429 bytes_to_set = min(end - offset, bytes);
1430
1431 bitmap_set_bits(ctl, info, offset, bytes_to_set);
1432
1433 return bytes_to_set;
1434
1435}
1436
1420static bool use_bitmap(struct btrfs_free_space_ctl *ctl, 1437static bool use_bitmap(struct btrfs_free_space_ctl *ctl,
1421 struct btrfs_free_space *info) 1438 struct btrfs_free_space *info)
1422{ 1439{
@@ -1453,12 +1470,18 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl,
1453 return true; 1470 return true;
1454} 1471}
1455 1472
1473static struct btrfs_free_space_op free_space_op = {
1474 .recalc_thresholds = recalculate_thresholds,
1475 .use_bitmap = use_bitmap,
1476};
1477
1456static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl, 1478static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl,
1457 struct btrfs_free_space *info) 1479 struct btrfs_free_space *info)
1458{ 1480{
1459 struct btrfs_free_space *bitmap_info; 1481 struct btrfs_free_space *bitmap_info;
1482 struct btrfs_block_group_cache *block_group = NULL;
1460 int added = 0; 1483 int added = 0;
1461 u64 bytes, offset, end; 1484 u64 bytes, offset, bytes_added;
1462 int ret; 1485 int ret;
1463 1486
1464 bytes = info->bytes; 1487 bytes = info->bytes;
@@ -1467,6 +1490,47 @@ static int insert_into_bitmap(struct btrfs_free_space_ctl *ctl,
1467 if (!ctl->op->use_bitmap(ctl, info)) 1490 if (!ctl->op->use_bitmap(ctl, info))
1468 return 0; 1491 return 0;
1469 1492
1493 if (ctl->op == &free_space_op)
1494 block_group = ctl->private;
1495
1496 /*
1497 * Since we link bitmaps right into the cluster we need to see if we
1498 * have a cluster here, and if so and it has our bitmap we need to add
1499 * the free space to that bitmap.
1500 */
1501 if (block_group && !list_empty(&block_group->cluster_list)) {
1502 struct btrfs_free_cluster *cluster;
1503 struct rb_node *node;
1504 struct btrfs_free_space *entry;
1505
1506 cluster = list_entry(block_group->cluster_list.next,
1507 struct btrfs_free_cluster,
1508 block_group_list);
1509 spin_lock(&cluster->lock);
1510 node = rb_first(&cluster->root);
1511 if (!node) {
1512 spin_unlock(&cluster->lock);
1513 goto again;
1514 }
1515
1516 entry = rb_entry(node, struct btrfs_free_space, offset_index);
1517 if (!entry->bitmap) {
1518 spin_unlock(&cluster->lock);
1519 goto again;
1520 }
1521
1522 if (entry->offset == offset_to_bitmap(ctl, offset)) {
1523 bytes_added = add_bytes_to_bitmap(ctl, entry,
1524 offset, bytes);
1525 bytes -= bytes_added;
1526 offset += bytes_added;
1527 }
1528 spin_unlock(&cluster->lock);
1529 if (!bytes) {
1530 ret = 1;
1531 goto out;
1532 }
1533 }
1470again: 1534again:
1471 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset), 1535 bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset),
1472 1, 0); 1536 1, 0);
@@ -1475,19 +1539,10 @@ again:
1475 goto new_bitmap; 1539 goto new_bitmap;
1476 } 1540 }
1477 1541
1478 end = bitmap_info->offset + (u64)(BITS_PER_BITMAP * ctl->unit); 1542 bytes_added = add_bytes_to_bitmap(ctl, bitmap_info, offset, bytes);
1479 1543 bytes -= bytes_added;
1480 if (offset >= bitmap_info->offset && offset + bytes > end) { 1544 offset += bytes_added;
1481 bitmap_set_bits(ctl, bitmap_info, offset, end - offset); 1545 added = 0;
1482 bytes -= end - offset;
1483 offset = end;
1484 added = 0;
1485 } else if (offset >= bitmap_info->offset && offset + bytes <= end) {
1486 bitmap_set_bits(ctl, bitmap_info, offset, bytes);
1487 bytes = 0;
1488 } else {
1489 BUG();
1490 }
1491 1546
1492 if (!bytes) { 1547 if (!bytes) {
1493 ret = 1; 1548 ret = 1;
@@ -1766,11 +1821,6 @@ void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
1766 "\n", count); 1821 "\n", count);
1767} 1822}
1768 1823
1769static struct btrfs_free_space_op free_space_op = {
1770 .recalc_thresholds = recalculate_thresholds,
1771 .use_bitmap = use_bitmap,
1772};
1773
1774void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group) 1824void btrfs_init_free_space_ctl(struct btrfs_block_group_cache *block_group)
1775{ 1825{
1776 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; 1826 struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;