super.c (ea77f7a2e8561012cf100c530170f12351c3b53e) super.c (aa38572954ade525817fe88c54faebf85e5a61c0)
1/*
2 * This file is part of UBIFS.
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.

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

370 ubifs_err("can't delete inode %lu, error %d",
371 inode->i_ino, err);
372
373out:
374 if (ui->dirty)
375 ubifs_release_dirty_inode_budget(c, ui);
376 else {
377 /* We've deleted something - clean the "no space" flags */
1/*
2 * This file is part of UBIFS.
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.

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

370 ubifs_err("can't delete inode %lu, error %d",
371 inode->i_ino, err);
372
373out:
374 if (ui->dirty)
375 ubifs_release_dirty_inode_budget(c, ui);
376 else {
377 /* We've deleted something - clean the "no space" flags */
378 c->nospace = c->nospace_rp = 0;
378 c->bi.nospace = c->bi.nospace_rp = 0;
379 smp_wmb();
380 }
381done:
382 end_writeback(inode);
383}
384
379 smp_wmb();
380 }
381done:
382 end_writeback(inode);
383}
384
385static void ubifs_dirty_inode(struct inode *inode)
385static void ubifs_dirty_inode(struct inode *inode, int flags)
386{
387 struct ubifs_inode *ui = ubifs_inode(inode);
388
389 ubifs_assert(mutex_is_locked(&ui->ui_mutex));
390 if (!ui->dirty) {
391 ui->dirty = 1;
392 dbg_gen("inode %lu", inode->i_ino);
393 }

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

689 return -EINVAL;
690 }
691
692 /*
693 * When budgeting we assume worst-case scenarios when the pages are not
694 * be compressed and direntries are of the maximum size.
695 *
696 * Note, data, which may be stored in inodes is budgeted separately, so
386{
387 struct ubifs_inode *ui = ubifs_inode(inode);
388
389 ubifs_assert(mutex_is_locked(&ui->ui_mutex));
390 if (!ui->dirty) {
391 ui->dirty = 1;
392 dbg_gen("inode %lu", inode->i_ino);
393 }

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

689 return -EINVAL;
690 }
691
692 /*
693 * When budgeting we assume worst-case scenarios when the pages are not
694 * be compressed and direntries are of the maximum size.
695 *
696 * Note, data, which may be stored in inodes is budgeted separately, so
697 * it is not included into 'c->inode_budget'.
697 * it is not included into 'c->bi.inode_budget'.
698 */
698 */
699 c->page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE;
700 c->inode_budget = UBIFS_INO_NODE_SZ;
701 c->dent_budget = UBIFS_MAX_DENT_NODE_SZ;
699 c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE;
700 c->bi.inode_budget = UBIFS_INO_NODE_SZ;
701 c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ;
702
703 /*
704 * When the amount of flash space used by buds becomes
705 * 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit.
706 * The writers are unblocked when the commit is finished. To avoid
707 * writers to be blocked UBIFS initiates background commit in advance,
708 * when number of bud bytes becomes above the limit defined below.
709 */

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

737 * This is a helper function which initializes various UBIFS constants after
738 * the master node has been read. It also checks various UBIFS parameters and
739 * makes sure they are all right.
740 */
741static void init_constants_master(struct ubifs_info *c)
742{
743 long long tmp64;
744
702
703 /*
704 * When the amount of flash space used by buds becomes
705 * 'c->max_bud_bytes', UBIFS just blocks all writers and starts commit.
706 * The writers are unblocked when the commit is finished. To avoid
707 * writers to be blocked UBIFS initiates background commit in advance,
708 * when number of bud bytes becomes above the limit defined below.
709 */

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

737 * This is a helper function which initializes various UBIFS constants after
738 * the master node has been read. It also checks various UBIFS parameters and
739 * makes sure they are all right.
740 */
741static void init_constants_master(struct ubifs_info *c)
742{
743 long long tmp64;
744
745 c->min_idx_lebs = ubifs_calc_min_idx_lebs(c);
745 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
746 c->report_rp_size = ubifs_reported_space(c, c->rp_size);
747
748 /*
749 * Calculate total amount of FS blocks. This number is not used
750 * internally because it does not make much sense for UBIFS, but it is
751 * necessary to report something for the 'statfs()' call.
752 *
753 * Subtract the LEB reserved for GC, the LEB which is reserved for

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

1139 *
1140 * This function makes sure UBIFS has enough free space to be mounted in
1141 * read/write mode. UBIFS must always have some free space to allow deletions.
1142 */
1143static int check_free_space(struct ubifs_info *c)
1144{
1145 ubifs_assert(c->dark_wm > 0);
1146 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
746 c->report_rp_size = ubifs_reported_space(c, c->rp_size);
747
748 /*
749 * Calculate total amount of FS blocks. This number is not used
750 * internally because it does not make much sense for UBIFS, but it is
751 * necessary to report something for the 'statfs()' call.
752 *
753 * Subtract the LEB reserved for GC, the LEB which is reserved for

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

1139 *
1140 * This function makes sure UBIFS has enough free space to be mounted in
1141 * read/write mode. UBIFS must always have some free space to allow deletions.
1142 */
1143static int check_free_space(struct ubifs_info *c)
1144{
1145 ubifs_assert(c->dark_wm > 0);
1146 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) {
1147 ubifs_err("insufficient free space to mount in read/write mode");
1148 dbg_dump_budg(c);
1147 ubifs_err("insufficient free space to mount in R/W mode");
1148 dbg_dump_budg(c, &c->bi);
1149 dbg_dump_lprops(c);
1150 return -ENOSPC;
1151 }
1152 return 0;
1153}
1154
1155/**
1156 * mount_ubifs - mount UBIFS file-system.

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

1299 if (err)
1300 goto out_master;
1301 }
1302
1303 err = ubifs_lpt_init(c, 1, !c->ro_mount);
1304 if (err)
1305 goto out_lpt;
1306
1149 dbg_dump_lprops(c);
1150 return -ENOSPC;
1151 }
1152 return 0;
1153}
1154
1155/**
1156 * mount_ubifs - mount UBIFS file-system.

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

1299 if (err)
1300 goto out_master;
1301 }
1302
1303 err = ubifs_lpt_init(c, 1, !c->ro_mount);
1304 if (err)
1305 goto out_lpt;
1306
1307 err = dbg_check_idx_size(c, c->old_idx_sz);
1307 err = dbg_check_idx_size(c, c->bi.old_idx_sz);
1308 if (err)
1309 goto out_lpt;
1310
1311 err = ubifs_replay_journal(c);
1312 if (err)
1313 goto out_journal;
1314
1315 /* Calculate 'min_idx_lebs' after journal replay */
1308 if (err)
1309 goto out_lpt;
1310
1311 err = ubifs_replay_journal(c);
1312 if (err)
1313 goto out_journal;
1314
1315 /* Calculate 'min_idx_lebs' after journal replay */
1316 c->min_idx_lebs = ubifs_calc_min_idx_lebs(c);
1316 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
1317
1318 err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
1319 if (err)
1320 goto out_orphans;
1321
1322 if (!c->ro_mount) {
1323 int lnum;
1324

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

1391 * the journal head LEBs may also be accounted as
1392 * "empty taken" if they are empty.
1393 */
1394 ubifs_assert(c->lst.taken_empty_lebs > 0);
1395 }
1396 } else
1397 ubifs_assert(c->lst.taken_empty_lebs > 0);
1398
1317
1318 err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount);
1319 if (err)
1320 goto out_orphans;
1321
1322 if (!c->ro_mount) {
1323 int lnum;
1324

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

1391 * the journal head LEBs may also be accounted as
1392 * "empty taken" if they are empty.
1393 */
1394 ubifs_assert(c->lst.taken_empty_lebs > 0);
1395 }
1396 } else
1397 ubifs_assert(c->lst.taken_empty_lebs > 0);
1398
1399 if (!c->ro_mount && c->space_fixup) {
1400 err = ubifs_fixup_free_space(c);
1401 if (err)
1402 goto out_infos;
1403 }
1404
1399 err = dbg_check_filesystem(c);
1400 if (err)
1401 goto out_infos;
1402
1403 err = dbg_debugfs_init_fs(c);
1404 if (err)
1405 goto out_infos;
1406

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

1437 dbg_msg("LPT area LEBs: %d (%d - %d)",
1438 c->lpt_lebs, c->lpt_first, c->lpt_last);
1439 dbg_msg("orphan area LEBs: %d (%d - %d)",
1440 c->orph_lebs, c->orph_first, c->orph_last);
1441 dbg_msg("main area LEBs: %d (%d - %d)",
1442 c->main_lebs, c->main_first, c->leb_cnt - 1);
1443 dbg_msg("index LEBs: %d", c->lst.idx_lebs);
1444 dbg_msg("total index bytes: %lld (%lld KiB, %lld MiB)",
1405 err = dbg_check_filesystem(c);
1406 if (err)
1407 goto out_infos;
1408
1409 err = dbg_debugfs_init_fs(c);
1410 if (err)
1411 goto out_infos;
1412

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

1443 dbg_msg("LPT area LEBs: %d (%d - %d)",
1444 c->lpt_lebs, c->lpt_first, c->lpt_last);
1445 dbg_msg("orphan area LEBs: %d (%d - %d)",
1446 c->orph_lebs, c->orph_first, c->orph_last);
1447 dbg_msg("main area LEBs: %d (%d - %d)",
1448 c->main_lebs, c->main_first, c->leb_cnt - 1);
1449 dbg_msg("index LEBs: %d", c->lst.idx_lebs);
1450 dbg_msg("total index bytes: %lld (%lld KiB, %lld MiB)",
1445 c->old_idx_sz, c->old_idx_sz >> 10, c->old_idx_sz >> 20);
1451 c->bi.old_idx_sz, c->bi.old_idx_sz >> 10,
1452 c->bi.old_idx_sz >> 20);
1446 dbg_msg("key hash type: %d", c->key_hash_type);
1447 dbg_msg("tree fanout: %d", c->fanout);
1448 dbg_msg("reserved GC LEB: %d", c->gc_lnum);
1449 dbg_msg("first main LEB: %d", c->main_first);
1450 dbg_msg("max. znode size %d", c->max_znode_sz);
1451 dbg_msg("max. index node size %d", c->max_idx_node_sz);
1452 dbg_msg("node sizes: data %zu, inode %zu, dentry %zu",
1453 UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
1454 dbg_msg("node sizes: trun %zu, sb %zu, master %zu",
1455 UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
1456 dbg_msg("node sizes: ref %zu, cmt. start %zu, orph %zu",
1457 UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
1458 dbg_msg("max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
1453 dbg_msg("key hash type: %d", c->key_hash_type);
1454 dbg_msg("tree fanout: %d", c->fanout);
1455 dbg_msg("reserved GC LEB: %d", c->gc_lnum);
1456 dbg_msg("first main LEB: %d", c->main_first);
1457 dbg_msg("max. znode size %d", c->max_znode_sz);
1458 dbg_msg("max. index node size %d", c->max_idx_node_sz);
1459 dbg_msg("node sizes: data %zu, inode %zu, dentry %zu",
1460 UBIFS_DATA_NODE_SZ, UBIFS_INO_NODE_SZ, UBIFS_DENT_NODE_SZ);
1461 dbg_msg("node sizes: trun %zu, sb %zu, master %zu",
1462 UBIFS_TRUN_NODE_SZ, UBIFS_SB_NODE_SZ, UBIFS_MST_NODE_SZ);
1463 dbg_msg("node sizes: ref %zu, cmt. start %zu, orph %zu",
1464 UBIFS_REF_NODE_SZ, UBIFS_CS_NODE_SZ, UBIFS_ORPH_NODE_SZ);
1465 dbg_msg("max. node sizes: data %zu, inode %zu dentry %zu, idx %d",
1459 UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
1466 UBIFS_MAX_DATA_NODE_SZ, UBIFS_MAX_INO_NODE_SZ,
1460 UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
1461 dbg_msg("dead watermark: %d", c->dead_wm);
1462 dbg_msg("dark watermark: %d", c->dark_wm);
1463 dbg_msg("LEB overhead: %d", c->leb_overhead);
1464 x = (long long)c->main_lebs * c->dark_wm;
1465 dbg_msg("max. dark space: %lld (%lld KiB, %lld MiB)",
1466 x, x >> 10, x >> 20);
1467 dbg_msg("maximum bud bytes: %lld (%lld KiB, %lld MiB)",

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

1579
1580 sup = ubifs_read_sb_node(c);
1581 if (IS_ERR(sup)) {
1582 err = PTR_ERR(sup);
1583 goto out;
1584 }
1585 sup->leb_cnt = cpu_to_le32(c->leb_cnt);
1586 err = ubifs_write_sb_node(c, sup);
1467 UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout));
1468 dbg_msg("dead watermark: %d", c->dead_wm);
1469 dbg_msg("dark watermark: %d", c->dark_wm);
1470 dbg_msg("LEB overhead: %d", c->leb_overhead);
1471 x = (long long)c->main_lebs * c->dark_wm;
1472 dbg_msg("max. dark space: %lld (%lld KiB, %lld MiB)",
1473 x, x >> 10, x >> 20);
1474 dbg_msg("maximum bud bytes: %lld (%lld KiB, %lld MiB)",

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

1586
1587 sup = ubifs_read_sb_node(c);
1588 if (IS_ERR(sup)) {
1589 err = PTR_ERR(sup);
1590 goto out;
1591 }
1592 sup->leb_cnt = cpu_to_le32(c->leb_cnt);
1593 err = ubifs_write_sb_node(c, sup);
1594 kfree(sup);
1587 if (err)
1588 goto out;
1589 }
1590
1591 if (c->need_recovery) {
1592 ubifs_msg("completing deferred recovery");
1593 err = ubifs_write_rcvrd_mst_node(c);
1594 if (err)

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

1679 * modified in memory, but all the I/O operations (including a
1680 * commit) were deferred. So the file-system was in
1681 * "non-committed" state. Now the file-system is in committed
1682 * state, and of course the amount of free space will change
1683 * because, for example, the old index size was imprecise.
1684 */
1685 err = dbg_check_space_info(c);
1686 }
1595 if (err)
1596 goto out;
1597 }
1598
1599 if (c->need_recovery) {
1600 ubifs_msg("completing deferred recovery");
1601 err = ubifs_write_rcvrd_mst_node(c);
1602 if (err)

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

1687 * modified in memory, but all the I/O operations (including a
1688 * commit) were deferred. So the file-system was in
1689 * "non-committed" state. Now the file-system is in committed
1690 * state, and of course the amount of free space will change
1691 * because, for example, the old index size was imprecise.
1692 */
1693 err = dbg_check_space_info(c);
1694 }
1695
1696 if (c->space_fixup) {
1697 err = ubifs_fixup_free_space(c);
1698 if (err)
1699 goto out;
1700 }
1701
1687 mutex_unlock(&c->umount_mutex);
1688 return err;
1689
1690out:
1691 c->ro_mount = 1;
1692 vfree(c->orph_buf);
1693 c->orph_buf = NULL;
1694 if (c->bgt) {

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

1761 c->vi.vol_id);
1762
1763 /*
1764 * The following asserts are only valid if there has not been a failure
1765 * of the media. For example, there will be dirty inodes if we failed
1766 * to write them back because of I/O errors.
1767 */
1768 if (!c->ro_error) {
1702 mutex_unlock(&c->umount_mutex);
1703 return err;
1704
1705out:
1706 c->ro_mount = 1;
1707 vfree(c->orph_buf);
1708 c->orph_buf = NULL;
1709 if (c->bgt) {

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

1776 c->vi.vol_id);
1777
1778 /*
1779 * The following asserts are only valid if there has not been a failure
1780 * of the media. For example, there will be dirty inodes if we failed
1781 * to write them back because of I/O errors.
1782 */
1783 if (!c->ro_error) {
1769 ubifs_assert(atomic_long_read(&c->dirty_pg_cnt) == 0);
1770 ubifs_assert(c->budg_idx_growth == 0);
1771 ubifs_assert(c->budg_dd_growth == 0);
1772 ubifs_assert(c->budg_data_growth == 0);
1784 ubifs_assert(c->bi.idx_growth == 0);
1785 ubifs_assert(c->bi.dd_growth == 0);
1786 ubifs_assert(c->bi.data_growth == 0);
1773 }
1774
1775 /*
1776 * The 'c->umount_lock' prevents races between UBIFS memory shrinker
1777 * and file system un-mount. Namely, it prevents the shrinker from
1778 * picking this superblock for shrinking - it will be just skipped if
1779 * the mutex is locked.
1780 */

--- 505 unchanged lines hidden ---
1787 }
1788
1789 /*
1790 * The 'c->umount_lock' prevents races between UBIFS memory shrinker
1791 * and file system un-mount. Namely, it prevents the shrinker from
1792 * picking this superblock for shrinking - it will be just skipped if
1793 * the mutex is locked.
1794 */

--- 505 unchanged lines hidden ---