aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/lpt_commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ubifs/lpt_commit.c')
-rw-r--r--fs/ubifs/lpt_commit.c86
1 files changed, 39 insertions, 47 deletions
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
index cddd6bd214f4..4fa70734e6e7 100644
--- a/fs/ubifs/lpt_commit.c
+++ b/fs/ubifs/lpt_commit.c
@@ -30,11 +30,7 @@
30#include <linux/random.h> 30#include <linux/random.h>
31#include "ubifs.h" 31#include "ubifs.h"
32 32
33#ifdef CONFIG_UBIFS_FS_DEBUG
34static int dbg_populate_lsave(struct ubifs_info *c); 33static int dbg_populate_lsave(struct ubifs_info *c);
35#else
36#define dbg_populate_lsave(c) 0
37#endif
38 34
39/** 35/**
40 * first_dirty_cnode - find first dirty cnode. 36 * first_dirty_cnode - find first dirty cnode.
@@ -324,11 +320,10 @@ static int layout_cnodes(struct ubifs_info *c)
324 return 0; 320 return 0;
325 321
326no_space: 322no_space:
327 ubifs_err("LPT out of space"); 323 ubifs_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, "
328 dbg_err("LPT out of space at LEB %d:%d needing %d, done_ltab %d, " 324 "done_lsave %d", lnum, offs, len, done_ltab, done_lsave);
329 "done_lsave %d", lnum, offs, len, done_ltab, done_lsave); 325 ubifs_dump_lpt_info(c);
330 dbg_dump_lpt_info(c); 326 ubifs_dump_lpt_lebs(c);
331 dbg_dump_lpt_lebs(c);
332 dump_stack(); 327 dump_stack();
333 return err; 328 return err;
334} 329}
@@ -421,7 +416,7 @@ static int write_cnodes(struct ubifs_info *c)
421 alen = ALIGN(wlen, c->min_io_size); 416 alen = ALIGN(wlen, c->min_io_size);
422 memset(buf + offs, 0xff, alen - wlen); 417 memset(buf + offs, 0xff, alen - wlen);
423 err = ubifs_leb_write(c, lnum, buf + from, from, 418 err = ubifs_leb_write(c, lnum, buf + from, from,
424 alen, UBI_SHORTTERM); 419 alen);
425 if (err) 420 if (err)
426 return err; 421 return err;
427 } 422 }
@@ -479,8 +474,7 @@ static int write_cnodes(struct ubifs_info *c)
479 wlen = offs - from; 474 wlen = offs - from;
480 alen = ALIGN(wlen, c->min_io_size); 475 alen = ALIGN(wlen, c->min_io_size);
481 memset(buf + offs, 0xff, alen - wlen); 476 memset(buf + offs, 0xff, alen - wlen);
482 err = ubifs_leb_write(c, lnum, buf + from, from, alen, 477 err = ubifs_leb_write(c, lnum, buf + from, from, alen);
483 UBI_SHORTTERM);
484 if (err) 478 if (err)
485 return err; 479 return err;
486 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); 480 dbg_chk_lpt_sz(c, 2, c->leb_size - offs);
@@ -506,8 +500,7 @@ static int write_cnodes(struct ubifs_info *c)
506 wlen = offs - from; 500 wlen = offs - from;
507 alen = ALIGN(wlen, c->min_io_size); 501 alen = ALIGN(wlen, c->min_io_size);
508 memset(buf + offs, 0xff, alen - wlen); 502 memset(buf + offs, 0xff, alen - wlen);
509 err = ubifs_leb_write(c, lnum, buf + from, from, alen, 503 err = ubifs_leb_write(c, lnum, buf + from, from, alen);
510 UBI_SHORTTERM);
511 if (err) 504 if (err)
512 return err; 505 return err;
513 dbg_chk_lpt_sz(c, 2, c->leb_size - offs); 506 dbg_chk_lpt_sz(c, 2, c->leb_size - offs);
@@ -531,7 +524,7 @@ static int write_cnodes(struct ubifs_info *c)
531 wlen = offs - from; 524 wlen = offs - from;
532 alen = ALIGN(wlen, c->min_io_size); 525 alen = ALIGN(wlen, c->min_io_size);
533 memset(buf + offs, 0xff, alen - wlen); 526 memset(buf + offs, 0xff, alen - wlen);
534 err = ubifs_leb_write(c, lnum, buf + from, from, alen, UBI_SHORTTERM); 527 err = ubifs_leb_write(c, lnum, buf + from, from, alen);
535 if (err) 528 if (err)
536 return err; 529 return err;
537 530
@@ -552,11 +545,10 @@ static int write_cnodes(struct ubifs_info *c)
552 return 0; 545 return 0;
553 546
554no_space: 547no_space:
555 ubifs_err("LPT out of space mismatch"); 548 ubifs_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab "
556 dbg_err("LPT out of space mismatch at LEB %d:%d needing %d, done_ltab " 549 "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave);
557 "%d, done_lsave %d", lnum, offs, len, done_ltab, done_lsave); 550 ubifs_dump_lpt_info(c);
558 dbg_dump_lpt_info(c); 551 ubifs_dump_lpt_lebs(c);
559 dbg_dump_lpt_lebs(c);
560 dump_stack(); 552 dump_stack();
561 return err; 553 return err;
562} 554}
@@ -1497,7 +1489,9 @@ void ubifs_lpt_free(struct ubifs_info *c, int wr_only)
1497 kfree(c->lpt_nod_buf); 1489 kfree(c->lpt_nod_buf);
1498} 1490}
1499 1491
1500#ifdef CONFIG_UBIFS_FS_DEBUG 1492/*
1493 * Everything below is related to debugging.
1494 */
1501 1495
1502/** 1496/**
1503 * dbg_is_all_ff - determine if a buffer contains only 0xFF bytes. 1497 * dbg_is_all_ff - determine if a buffer contains only 0xFF bytes.
@@ -1735,7 +1729,7 @@ int dbg_check_ltab(struct ubifs_info *c)
1735 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { 1729 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) {
1736 err = dbg_check_ltab_lnum(c, lnum); 1730 err = dbg_check_ltab_lnum(c, lnum);
1737 if (err) { 1731 if (err) {
1738 dbg_err("failed at LEB %d", lnum); 1732 ubifs_err("failed at LEB %d", lnum);
1739 return err; 1733 return err;
1740 } 1734 }
1741 } 1735 }
@@ -1767,10 +1761,10 @@ int dbg_chk_lpt_free_spc(struct ubifs_info *c)
1767 free += c->leb_size; 1761 free += c->leb_size;
1768 } 1762 }
1769 if (free < c->lpt_sz) { 1763 if (free < c->lpt_sz) {
1770 dbg_err("LPT space error: free %lld lpt_sz %lld", 1764 ubifs_err("LPT space error: free %lld lpt_sz %lld",
1771 free, c->lpt_sz); 1765 free, c->lpt_sz);
1772 dbg_dump_lpt_info(c); 1766 ubifs_dump_lpt_info(c);
1773 dbg_dump_lpt_lebs(c); 1767 ubifs_dump_lpt_lebs(c);
1774 dump_stack(); 1768 dump_stack();
1775 return -EINVAL; 1769 return -EINVAL;
1776 } 1770 }
@@ -1807,13 +1801,13 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1807 d->chk_lpt_lebs = 0; 1801 d->chk_lpt_lebs = 0;
1808 d->chk_lpt_wastage = 0; 1802 d->chk_lpt_wastage = 0;
1809 if (c->dirty_pn_cnt > c->pnode_cnt) { 1803 if (c->dirty_pn_cnt > c->pnode_cnt) {
1810 dbg_err("dirty pnodes %d exceed max %d", 1804 ubifs_err("dirty pnodes %d exceed max %d",
1811 c->dirty_pn_cnt, c->pnode_cnt); 1805 c->dirty_pn_cnt, c->pnode_cnt);
1812 err = -EINVAL; 1806 err = -EINVAL;
1813 } 1807 }
1814 if (c->dirty_nn_cnt > c->nnode_cnt) { 1808 if (c->dirty_nn_cnt > c->nnode_cnt) {
1815 dbg_err("dirty nnodes %d exceed max %d", 1809 ubifs_err("dirty nnodes %d exceed max %d",
1816 c->dirty_nn_cnt, c->nnode_cnt); 1810 c->dirty_nn_cnt, c->nnode_cnt);
1817 err = -EINVAL; 1811 err = -EINVAL;
1818 } 1812 }
1819 return err; 1813 return err;
@@ -1830,23 +1824,23 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1830 chk_lpt_sz *= d->chk_lpt_lebs; 1824 chk_lpt_sz *= d->chk_lpt_lebs;
1831 chk_lpt_sz += len - c->nhead_offs; 1825 chk_lpt_sz += len - c->nhead_offs;
1832 if (d->chk_lpt_sz != chk_lpt_sz) { 1826 if (d->chk_lpt_sz != chk_lpt_sz) {
1833 dbg_err("LPT wrote %lld but space used was %lld", 1827 ubifs_err("LPT wrote %lld but space used was %lld",
1834 d->chk_lpt_sz, chk_lpt_sz); 1828 d->chk_lpt_sz, chk_lpt_sz);
1835 err = -EINVAL; 1829 err = -EINVAL;
1836 } 1830 }
1837 if (d->chk_lpt_sz > c->lpt_sz) { 1831 if (d->chk_lpt_sz > c->lpt_sz) {
1838 dbg_err("LPT wrote %lld but lpt_sz is %lld", 1832 ubifs_err("LPT wrote %lld but lpt_sz is %lld",
1839 d->chk_lpt_sz, c->lpt_sz); 1833 d->chk_lpt_sz, c->lpt_sz);
1840 err = -EINVAL; 1834 err = -EINVAL;
1841 } 1835 }
1842 if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) { 1836 if (d->chk_lpt_sz2 && d->chk_lpt_sz != d->chk_lpt_sz2) {
1843 dbg_err("LPT layout size %lld but wrote %lld", 1837 ubifs_err("LPT layout size %lld but wrote %lld",
1844 d->chk_lpt_sz, d->chk_lpt_sz2); 1838 d->chk_lpt_sz, d->chk_lpt_sz2);
1845 err = -EINVAL; 1839 err = -EINVAL;
1846 } 1840 }
1847 if (d->chk_lpt_sz2 && d->new_nhead_offs != len) { 1841 if (d->chk_lpt_sz2 && d->new_nhead_offs != len) {
1848 dbg_err("LPT new nhead offs: expected %d was %d", 1842 ubifs_err("LPT new nhead offs: expected %d was %d",
1849 d->new_nhead_offs, len); 1843 d->new_nhead_offs, len);
1850 err = -EINVAL; 1844 err = -EINVAL;
1851 } 1845 }
1852 lpt_sz = (long long)c->pnode_cnt * c->pnode_sz; 1846 lpt_sz = (long long)c->pnode_cnt * c->pnode_sz;
@@ -1855,13 +1849,13 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1855 if (c->big_lpt) 1849 if (c->big_lpt)
1856 lpt_sz += c->lsave_sz; 1850 lpt_sz += c->lsave_sz;
1857 if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) { 1851 if (d->chk_lpt_sz - d->chk_lpt_wastage > lpt_sz) {
1858 dbg_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld", 1852 ubifs_err("LPT chk_lpt_sz %lld + waste %lld exceeds %lld",
1859 d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz); 1853 d->chk_lpt_sz, d->chk_lpt_wastage, lpt_sz);
1860 err = -EINVAL; 1854 err = -EINVAL;
1861 } 1855 }
1862 if (err) { 1856 if (err) {
1863 dbg_dump_lpt_info(c); 1857 ubifs_dump_lpt_info(c);
1864 dbg_dump_lpt_lebs(c); 1858 ubifs_dump_lpt_lebs(c);
1865 dump_stack(); 1859 dump_stack();
1866 } 1860 }
1867 d->chk_lpt_sz2 = d->chk_lpt_sz; 1861 d->chk_lpt_sz2 = d->chk_lpt_sz;
@@ -1880,7 +1874,7 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
1880} 1874}
1881 1875
1882/** 1876/**
1883 * dbg_dump_lpt_leb - dump an LPT LEB. 1877 * ubifs_dump_lpt_leb - dump an LPT LEB.
1884 * @c: UBIFS file-system description object 1878 * @c: UBIFS file-system description object
1885 * @lnum: LEB number to dump 1879 * @lnum: LEB number to dump
1886 * 1880 *
@@ -1986,13 +1980,13 @@ out:
1986} 1980}
1987 1981
1988/** 1982/**
1989 * dbg_dump_lpt_lebs - dump LPT lebs. 1983 * ubifs_dump_lpt_lebs - dump LPT lebs.
1990 * @c: UBIFS file-system description object 1984 * @c: UBIFS file-system description object
1991 * 1985 *
1992 * This function dumps all LPT LEBs. The caller has to make sure the LPT is 1986 * This function dumps all LPT LEBs. The caller has to make sure the LPT is
1993 * locked. 1987 * locked.
1994 */ 1988 */
1995void dbg_dump_lpt_lebs(const struct ubifs_info *c) 1989void ubifs_dump_lpt_lebs(const struct ubifs_info *c)
1996{ 1990{
1997 int i; 1991 int i;
1998 1992
@@ -2046,5 +2040,3 @@ static int dbg_populate_lsave(struct ubifs_info *c)
2046 2040
2047 return 1; 2041 return 1;
2048} 2042}
2049
2050#endif /* CONFIG_UBIFS_FS_DEBUG */