diff options
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r-- | fs/block_dev.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index b737451e2e9d..dea3b628a6ce 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -48,6 +48,21 @@ inline struct block_device *I_BDEV(struct inode *inode) | |||
48 | 48 | ||
49 | EXPORT_SYMBOL(I_BDEV); | 49 | EXPORT_SYMBOL(I_BDEV); |
50 | 50 | ||
51 | /* | ||
52 | * move the inode from it's current bdi to the a new bdi. if the inode is dirty | ||
53 | * we need to move it onto the dirty list of @dst so that the inode is always | ||
54 | * on the right list. | ||
55 | */ | ||
56 | static void bdev_inode_switch_bdi(struct inode *inode, | ||
57 | struct backing_dev_info *dst) | ||
58 | { | ||
59 | spin_lock(&inode_lock); | ||
60 | inode->i_data.backing_dev_info = dst; | ||
61 | if (inode->i_state & I_DIRTY) | ||
62 | list_move(&inode->i_wb_list, &dst->wb.b_dirty); | ||
63 | spin_unlock(&inode_lock); | ||
64 | } | ||
65 | |||
51 | static sector_t max_block(struct block_device *bdev) | 66 | static sector_t max_block(struct block_device *bdev) |
52 | { | 67 | { |
53 | sector_t retval = ~((sector_t)0); | 68 | sector_t retval = ~((sector_t)0); |
@@ -550,7 +565,7 @@ EXPORT_SYMBOL(bdget); | |||
550 | */ | 565 | */ |
551 | struct block_device *bdgrab(struct block_device *bdev) | 566 | struct block_device *bdgrab(struct block_device *bdev) |
552 | { | 567 | { |
553 | atomic_inc(&bdev->bd_inode->i_count); | 568 | ihold(bdev->bd_inode); |
554 | return bdev; | 569 | return bdev; |
555 | } | 570 | } |
556 | 571 | ||
@@ -580,7 +595,7 @@ static struct block_device *bd_acquire(struct inode *inode) | |||
580 | spin_lock(&bdev_lock); | 595 | spin_lock(&bdev_lock); |
581 | bdev = inode->i_bdev; | 596 | bdev = inode->i_bdev; |
582 | if (bdev) { | 597 | if (bdev) { |
583 | atomic_inc(&bdev->bd_inode->i_count); | 598 | ihold(bdev->bd_inode); |
584 | spin_unlock(&bdev_lock); | 599 | spin_unlock(&bdev_lock); |
585 | return bdev; | 600 | return bdev; |
586 | } | 601 | } |
@@ -591,12 +606,12 @@ static struct block_device *bd_acquire(struct inode *inode) | |||
591 | spin_lock(&bdev_lock); | 606 | spin_lock(&bdev_lock); |
592 | if (!inode->i_bdev) { | 607 | if (!inode->i_bdev) { |
593 | /* | 608 | /* |
594 | * We take an additional bd_inode->i_count for inode, | 609 | * We take an additional reference to bd_inode, |
595 | * and it's released in clear_inode() of inode. | 610 | * and it's released in clear_inode() of inode. |
596 | * So, we can access it via ->i_mapping always | 611 | * So, we can access it via ->i_mapping always |
597 | * without igrab(). | 612 | * without igrab(). |
598 | */ | 613 | */ |
599 | atomic_inc(&bdev->bd_inode->i_count); | 614 | ihold(bdev->bd_inode); |
600 | inode->i_bdev = bdev; | 615 | inode->i_bdev = bdev; |
601 | inode->i_mapping = bdev->bd_inode->i_mapping; | 616 | inode->i_mapping = bdev->bd_inode->i_mapping; |
602 | list_add(&inode->i_devices, &bdev->bd_inodes); | 617 | list_add(&inode->i_devices, &bdev->bd_inodes); |
@@ -1390,7 +1405,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) | |||
1390 | bdi = blk_get_backing_dev_info(bdev); | 1405 | bdi = blk_get_backing_dev_info(bdev); |
1391 | if (bdi == NULL) | 1406 | if (bdi == NULL) |
1392 | bdi = &default_backing_dev_info; | 1407 | bdi = &default_backing_dev_info; |
1393 | bdev->bd_inode->i_data.backing_dev_info = bdi; | 1408 | bdev_inode_switch_bdi(bdev->bd_inode, bdi); |
1394 | } | 1409 | } |
1395 | if (bdev->bd_invalidated) | 1410 | if (bdev->bd_invalidated) |
1396 | rescan_partitions(disk, bdev); | 1411 | rescan_partitions(disk, bdev); |
@@ -1405,8 +1420,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) | |||
1405 | if (ret) | 1420 | if (ret) |
1406 | goto out_clear; | 1421 | goto out_clear; |
1407 | bdev->bd_contains = whole; | 1422 | bdev->bd_contains = whole; |
1408 | bdev->bd_inode->i_data.backing_dev_info = | 1423 | bdev_inode_switch_bdi(bdev->bd_inode, |
1409 | whole->bd_inode->i_data.backing_dev_info; | 1424 | whole->bd_inode->i_data.backing_dev_info); |
1410 | bdev->bd_part = disk_get_part(disk, partno); | 1425 | bdev->bd_part = disk_get_part(disk, partno); |
1411 | if (!(disk->flags & GENHD_FL_UP) || | 1426 | if (!(disk->flags & GENHD_FL_UP) || |
1412 | !bdev->bd_part || !bdev->bd_part->nr_sects) { | 1427 | !bdev->bd_part || !bdev->bd_part->nr_sects) { |
@@ -1439,7 +1454,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) | |||
1439 | disk_put_part(bdev->bd_part); | 1454 | disk_put_part(bdev->bd_part); |
1440 | bdev->bd_disk = NULL; | 1455 | bdev->bd_disk = NULL; |
1441 | bdev->bd_part = NULL; | 1456 | bdev->bd_part = NULL; |
1442 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; | 1457 | bdev_inode_switch_bdi(bdev->bd_inode, &default_backing_dev_info); |
1443 | if (bdev != bdev->bd_contains) | 1458 | if (bdev != bdev->bd_contains) |
1444 | __blkdev_put(bdev->bd_contains, mode, 1); | 1459 | __blkdev_put(bdev->bd_contains, mode, 1); |
1445 | bdev->bd_contains = NULL; | 1460 | bdev->bd_contains = NULL; |
@@ -1533,7 +1548,8 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) | |||
1533 | disk_put_part(bdev->bd_part); | 1548 | disk_put_part(bdev->bd_part); |
1534 | bdev->bd_part = NULL; | 1549 | bdev->bd_part = NULL; |
1535 | bdev->bd_disk = NULL; | 1550 | bdev->bd_disk = NULL; |
1536 | bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; | 1551 | bdev_inode_switch_bdi(bdev->bd_inode, |
1552 | &default_backing_dev_info); | ||
1537 | if (bdev != bdev->bd_contains) | 1553 | if (bdev != bdev->bd_contains) |
1538 | victim = bdev->bd_contains; | 1554 | victim = bdev->bd_contains; |
1539 | bdev->bd_contains = NULL; | 1555 | bdev->bd_contains = NULL; |