super.c (b4b9d34c855ef383402cd1acefb1e33a515ae5f5) super.c (3c62be17d4f562f43fe1d03b48194399caa35aa5)
1/*
2 * fs/f2fs/super.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 699 unchanged lines hidden (view full) ---

708}
709
710static void destroy_percpu_info(struct f2fs_sb_info *sbi)
711{
712 percpu_counter_destroy(&sbi->alloc_valid_block_count);
713 percpu_counter_destroy(&sbi->total_valid_inode_count);
714}
715
1/*
2 * fs/f2fs/super.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as

--- 699 unchanged lines hidden (view full) ---

708}
709
710static void destroy_percpu_info(struct f2fs_sb_info *sbi)
711{
712 percpu_counter_destroy(&sbi->alloc_valid_block_count);
713 percpu_counter_destroy(&sbi->total_valid_inode_count);
714}
715
716static void destroy_device_list(struct f2fs_sb_info *sbi)
717{
718 int i;
719
720 for (i = 0; i < sbi->s_ndevs; i++) {
721 blkdev_put(FDEV(i).bdev, FMODE_EXCL);
722#ifdef CONFIG_BLK_DEV_ZONED
723 kfree(FDEV(i).blkz_type);
724#endif
725 }
726 kfree(sbi->devs);
727}
728
716static void f2fs_put_super(struct super_block *sb)
717{
718 struct f2fs_sb_info *sbi = F2FS_SB(sb);
719
720 if (sbi->s_proc) {
721 remove_proc_entry("segment_info", sbi->s_proc);
722 remove_proc_entry("segment_bits", sbi->s_proc);
723 remove_proc_entry(sb->s_id, f2fs_proc_root);

--- 44 unchanged lines hidden (view full) ---

768 kobject_put(&sbi->s_kobj);
769 wait_for_completion(&sbi->s_kobj_unregister);
770
771 sb->s_fs_info = NULL;
772 if (sbi->s_chksum_driver)
773 crypto_free_shash(sbi->s_chksum_driver);
774 kfree(sbi->raw_super);
775
729static void f2fs_put_super(struct super_block *sb)
730{
731 struct f2fs_sb_info *sbi = F2FS_SB(sb);
732
733 if (sbi->s_proc) {
734 remove_proc_entry("segment_info", sbi->s_proc);
735 remove_proc_entry("segment_bits", sbi->s_proc);
736 remove_proc_entry(sb->s_id, f2fs_proc_root);

--- 44 unchanged lines hidden (view full) ---

781 kobject_put(&sbi->s_kobj);
782 wait_for_completion(&sbi->s_kobj_unregister);
783
784 sb->s_fs_info = NULL;
785 if (sbi->s_chksum_driver)
786 crypto_free_shash(sbi->s_chksum_driver);
787 kfree(sbi->raw_super);
788
789 destroy_device_list(sbi);
790
776 destroy_percpu_info(sbi);
777 kfree(sbi);
778}
779
780int f2fs_sync_fs(struct super_block *sb, int sync)
781{
782 struct f2fs_sb_info *sbi = F2FS_SB(sb);
783 int err = 0;

--- 727 unchanged lines hidden (view full) ---

1511 if (err)
1512 return err;
1513
1514 return percpu_counter_init(&sbi->total_valid_inode_count, 0,
1515 GFP_KERNEL);
1516}
1517
1518#ifdef CONFIG_BLK_DEV_ZONED
791 destroy_percpu_info(sbi);
792 kfree(sbi);
793}
794
795int f2fs_sync_fs(struct super_block *sb, int sync)
796{
797 struct f2fs_sb_info *sbi = F2FS_SB(sb);
798 int err = 0;

--- 727 unchanged lines hidden (view full) ---

1526 if (err)
1527 return err;
1528
1529 return percpu_counter_init(&sbi->total_valid_inode_count, 0,
1530 GFP_KERNEL);
1531}
1532
1533#ifdef CONFIG_BLK_DEV_ZONED
1519static int init_blkz_info(struct f2fs_sb_info *sbi)
1534static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
1520{
1535{
1521 struct block_device *bdev = sbi->sb->s_bdev;
1536 struct block_device *bdev = FDEV(devi).bdev;
1522 sector_t nr_sectors = bdev->bd_part->nr_sects;
1523 sector_t sector = 0;
1524 struct blk_zone *zones;
1525 unsigned int i, nr_zones;
1526 unsigned int n = 0;
1527 int err = -EIO;
1528
1529 if (!f2fs_sb_mounted_blkzoned(sbi->sb))
1530 return 0;
1531
1537 sector_t nr_sectors = bdev->bd_part->nr_sects;
1538 sector_t sector = 0;
1539 struct blk_zone *zones;
1540 unsigned int i, nr_zones;
1541 unsigned int n = 0;
1542 int err = -EIO;
1543
1544 if (!f2fs_sb_mounted_blkzoned(sbi->sb))
1545 return 0;
1546
1547 if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
1548 SECTOR_TO_BLOCK(bdev_zone_size(bdev)))
1549 return -EINVAL;
1532 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_size(bdev));
1550 sbi->blocks_per_blkz = SECTOR_TO_BLOCK(bdev_zone_size(bdev));
1551 if (sbi->log_blocks_per_blkz && sbi->log_blocks_per_blkz !=
1552 __ilog2_u32(sbi->blocks_per_blkz))
1553 return -EINVAL;
1533 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
1554 sbi->log_blocks_per_blkz = __ilog2_u32(sbi->blocks_per_blkz);
1534 sbi->nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
1535 sbi->log_blocks_per_blkz;
1555 FDEV(devi).nr_blkz = SECTOR_TO_BLOCK(nr_sectors) >>
1556 sbi->log_blocks_per_blkz;
1536 if (nr_sectors & (bdev_zone_size(bdev) - 1))
1557 if (nr_sectors & (bdev_zone_size(bdev) - 1))
1537 sbi->nr_blkz++;
1558 FDEV(devi).nr_blkz++;
1538
1559
1539 sbi->blkz_type = kmalloc(sbi->nr_blkz, GFP_KERNEL);
1540 if (!sbi->blkz_type)
1560 FDEV(devi).blkz_type = kmalloc(FDEV(devi).nr_blkz, GFP_KERNEL);
1561 if (!FDEV(devi).blkz_type)
1541 return -ENOMEM;
1542
1543#define F2FS_REPORT_NR_ZONES 4096
1544
1545 zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone),
1546 GFP_KERNEL);
1547 if (!zones)
1548 return -ENOMEM;

--- 8 unchanged lines hidden (view full) ---

1557 if (err)
1558 break;
1559 if (!nr_zones) {
1560 err = -EIO;
1561 break;
1562 }
1563
1564 for (i = 0; i < nr_zones; i++) {
1562 return -ENOMEM;
1563
1564#define F2FS_REPORT_NR_ZONES 4096
1565
1566 zones = kcalloc(F2FS_REPORT_NR_ZONES, sizeof(struct blk_zone),
1567 GFP_KERNEL);
1568 if (!zones)
1569 return -ENOMEM;

--- 8 unchanged lines hidden (view full) ---

1578 if (err)
1579 break;
1580 if (!nr_zones) {
1581 err = -EIO;
1582 break;
1583 }
1584
1585 for (i = 0; i < nr_zones; i++) {
1565 sbi->blkz_type[n] = zones[i].type;
1586 FDEV(devi).blkz_type[n] = zones[i].type;
1566 sector += zones[i].len;
1567 n++;
1568 }
1569 }
1570
1571 kfree(zones);
1572
1573 return err;

--- 87 unchanged lines hidden (view full) ---

1661 bh = sb_getblk(sbi->sb, sbi->valid_super_block);
1662 if (!bh)
1663 return -EIO;
1664 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
1665 brelse(bh);
1666 return err;
1667}
1668
1587 sector += zones[i].len;
1588 n++;
1589 }
1590 }
1591
1592 kfree(zones);
1593
1594 return err;

--- 87 unchanged lines hidden (view full) ---

1682 bh = sb_getblk(sbi->sb, sbi->valid_super_block);
1683 if (!bh)
1684 return -EIO;
1685 err = __f2fs_commit_super(bh, F2FS_RAW_SUPER(sbi));
1686 brelse(bh);
1687 return err;
1688}
1689
1690static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
1691{
1692 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
1693 int i;
1694
1695 for (i = 0; i < MAX_DEVICES; i++) {
1696 if (!RDEV(i).path[0])
1697 return 0;
1698
1699 if (i == 0) {
1700 sbi->devs = kzalloc(sizeof(struct f2fs_dev_info) *
1701 MAX_DEVICES, GFP_KERNEL);
1702 if (!sbi->devs)
1703 return -ENOMEM;
1704 }
1705
1706 memcpy(FDEV(i).path, RDEV(i).path, MAX_PATH_LEN);
1707 FDEV(i).total_segments = le32_to_cpu(RDEV(i).total_segments);
1708 if (i == 0) {
1709 FDEV(i).start_blk = 0;
1710 FDEV(i).end_blk = FDEV(i).start_blk +
1711 (FDEV(i).total_segments <<
1712 sbi->log_blocks_per_seg) - 1 +
1713 le32_to_cpu(raw_super->segment0_blkaddr);
1714 } else {
1715 FDEV(i).start_blk = FDEV(i - 1).end_blk + 1;
1716 FDEV(i).end_blk = FDEV(i).start_blk +
1717 (FDEV(i).total_segments <<
1718 sbi->log_blocks_per_seg) - 1;
1719 }
1720
1721 FDEV(i).bdev = blkdev_get_by_path(FDEV(i).path,
1722 sbi->sb->s_mode, sbi->sb->s_type);
1723 if (IS_ERR(FDEV(i).bdev))
1724 return PTR_ERR(FDEV(i).bdev);
1725
1726 /* to release errored devices */
1727 sbi->s_ndevs = i + 1;
1728
1729#ifdef CONFIG_BLK_DEV_ZONED
1730 if (bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HM &&
1731 !f2fs_sb_mounted_blkzoned(sbi->sb)) {
1732 f2fs_msg(sbi->sb, KERN_ERR,
1733 "Zoned block device feature not enabled\n");
1734 return -EINVAL;
1735 }
1736 if (bdev_zoned_model(FDEV(i).bdev) != BLK_ZONED_NONE) {
1737 if (init_blkz_info(sbi, i)) {
1738 f2fs_msg(sbi->sb, KERN_ERR,
1739 "Failed to initialize F2FS blkzone information");
1740 return -EINVAL;
1741 }
1742 f2fs_msg(sbi->sb, KERN_INFO,
1743 "Mount Device [%2d]: %20s, %8u, %8x - %8x (zone: %s)",
1744 i, FDEV(i).path,
1745 FDEV(i).total_segments,
1746 FDEV(i).start_blk, FDEV(i).end_blk,
1747 bdev_zoned_model(FDEV(i).bdev) == BLK_ZONED_HA ?
1748 "Host-aware" : "Host-managed");
1749 continue;
1750 }
1751#endif
1752 f2fs_msg(sbi->sb, KERN_INFO,
1753 "Mount Device [%2d]: %20s, %8u, %8x - %8x",
1754 i, FDEV(i).path,
1755 FDEV(i).total_segments,
1756 FDEV(i).start_blk, FDEV(i).end_blk);
1757 }
1758 return 0;
1759}
1760
1669static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
1670{
1671 struct f2fs_sb_info *sbi;
1672 struct f2fs_super_block *raw_super;
1673 struct inode *root;
1674 int err;
1675 bool retry = true, need_fsck = false;
1676 char *options = NULL;

--- 42 unchanged lines hidden (view full) ---

1719 * devices, but mandatory for host-managed zoned block devices.
1720 */
1721#ifndef CONFIG_BLK_DEV_ZONED
1722 if (f2fs_sb_mounted_blkzoned(sb)) {
1723 f2fs_msg(sb, KERN_ERR,
1724 "Zoned block device support is not enabled\n");
1725 goto free_sb_buf;
1726 }
1761static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
1762{
1763 struct f2fs_sb_info *sbi;
1764 struct f2fs_super_block *raw_super;
1765 struct inode *root;
1766 int err;
1767 bool retry = true, need_fsck = false;
1768 char *options = NULL;

--- 42 unchanged lines hidden (view full) ---

1811 * devices, but mandatory for host-managed zoned block devices.
1812 */
1813#ifndef CONFIG_BLK_DEV_ZONED
1814 if (f2fs_sb_mounted_blkzoned(sb)) {
1815 f2fs_msg(sb, KERN_ERR,
1816 "Zoned block device support is not enabled\n");
1817 goto free_sb_buf;
1818 }
1727#else
1728 if (bdev_zoned_model(sb->s_bdev) == BLK_ZONED_HM &&
1729 !f2fs_sb_mounted_blkzoned(sb)) {
1730 f2fs_msg(sb, KERN_ERR,
1731 "Zoned block device feature not enabled\n");
1732 goto free_sb_buf;
1733 }
1734#endif
1819#endif
1735
1736 default_options(sbi);
1737 /* parse mount options */
1738 options = kstrdup((const char *)data, GFP_KERNEL);
1739 if (data && !options) {
1740 err = -ENOMEM;
1741 goto free_sb_buf;
1742 }
1743

--- 53 unchanged lines hidden (view full) ---

1797 }
1798
1799 err = get_valid_checkpoint(sbi);
1800 if (err) {
1801 f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
1802 goto free_meta_inode;
1803 }
1804
1820 default_options(sbi);
1821 /* parse mount options */
1822 options = kstrdup((const char *)data, GFP_KERNEL);
1823 if (data && !options) {
1824 err = -ENOMEM;
1825 goto free_sb_buf;
1826 }
1827

--- 53 unchanged lines hidden (view full) ---

1881 }
1882
1883 err = get_valid_checkpoint(sbi);
1884 if (err) {
1885 f2fs_msg(sb, KERN_ERR, "Failed to get valid F2FS checkpoint");
1886 goto free_meta_inode;
1887 }
1888
1889 /* Initialize device list */
1890 err = f2fs_scan_devices(sbi);
1891 if (err) {
1892 f2fs_msg(sb, KERN_ERR, "Failed to find devices");
1893 goto free_devices;
1894 }
1895
1805 sbi->total_valid_node_count =
1806 le32_to_cpu(sbi->ckpt->valid_node_count);
1807 percpu_counter_set(&sbi->total_valid_inode_count,
1808 le32_to_cpu(sbi->ckpt->valid_inode_count));
1809 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
1810 sbi->total_valid_block_count =
1811 le64_to_cpu(sbi->ckpt->valid_block_count);
1812 sbi->last_valid_block_count = sbi->total_valid_block_count;
1813
1814 for (i = 0; i < NR_INODE_TYPE; i++) {
1815 INIT_LIST_HEAD(&sbi->inode_list[i]);
1816 spin_lock_init(&sbi->inode_lock[i]);
1817 }
1818
1819 init_extent_cache_info(sbi);
1820
1821 init_ino_entry_info(sbi);
1822
1896 sbi->total_valid_node_count =
1897 le32_to_cpu(sbi->ckpt->valid_node_count);
1898 percpu_counter_set(&sbi->total_valid_inode_count,
1899 le32_to_cpu(sbi->ckpt->valid_inode_count));
1900 sbi->user_block_count = le64_to_cpu(sbi->ckpt->user_block_count);
1901 sbi->total_valid_block_count =
1902 le64_to_cpu(sbi->ckpt->valid_block_count);
1903 sbi->last_valid_block_count = sbi->total_valid_block_count;
1904
1905 for (i = 0; i < NR_INODE_TYPE; i++) {
1906 INIT_LIST_HEAD(&sbi->inode_list[i]);
1907 spin_lock_init(&sbi->inode_lock[i]);
1908 }
1909
1910 init_extent_cache_info(sbi);
1911
1912 init_ino_entry_info(sbi);
1913
1823#ifdef CONFIG_BLK_DEV_ZONED
1824 err = init_blkz_info(sbi);
1825 if (err) {
1826 f2fs_msg(sb, KERN_ERR,
1827 "Failed to initialize F2FS blkzone information");
1828 goto free_blkz;
1829 }
1830#endif
1831
1832 /* setup f2fs internal modules */
1833 err = build_segment_manager(sbi);
1834 if (err) {
1835 f2fs_msg(sb, KERN_ERR,
1836 "Failed to initialize F2FS segment manager");
1837 goto free_sm;
1838 }
1839 err = build_node_manager(sbi);

--- 162 unchanged lines hidden (view full) ---

2002 */
2003 truncate_inode_pages_final(META_MAPPING(sbi));
2004 iput(sbi->node_inode);
2005 mutex_unlock(&sbi->umount_mutex);
2006free_nm:
2007 destroy_node_manager(sbi);
2008free_sm:
2009 destroy_segment_manager(sbi);
1914 /* setup f2fs internal modules */
1915 err = build_segment_manager(sbi);
1916 if (err) {
1917 f2fs_msg(sb, KERN_ERR,
1918 "Failed to initialize F2FS segment manager");
1919 goto free_sm;
1920 }
1921 err = build_node_manager(sbi);

--- 162 unchanged lines hidden (view full) ---

2084 */
2085 truncate_inode_pages_final(META_MAPPING(sbi));
2086 iput(sbi->node_inode);
2087 mutex_unlock(&sbi->umount_mutex);
2088free_nm:
2089 destroy_node_manager(sbi);
2090free_sm:
2091 destroy_segment_manager(sbi);
2010#ifdef CONFIG_BLK_DEV_ZONED
2011free_blkz:
2012 kfree(sbi->blkz_type);
2013#endif
2092free_devices:
2093 destroy_device_list(sbi);
2014 kfree(sbi->ckpt);
2015free_meta_inode:
2016 make_bad_inode(sbi->meta_inode);
2017 iput(sbi->meta_inode);
2018free_options:
2019 destroy_percpu_info(sbi);
2020 kfree(options);
2021free_sb_buf:

--- 138 unchanged lines hidden ---
2094 kfree(sbi->ckpt);
2095free_meta_inode:
2096 make_bad_inode(sbi->meta_inode);
2097 iput(sbi->meta_inode);
2098free_options:
2099 destroy_percpu_info(sbi);
2100 kfree(options);
2101free_sb_buf:

--- 138 unchanged lines hidden ---