From 549c999a768a7a144c60a0faa58f34c48f39112b Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 26 May 2011 16:57:14 +0300 Subject: UBIFS: return EROFS in case of broken commit If commit failed and it is in broken state, UBIFS switches to R/O mode. Most operations return -EROFS in this case, except of commit which returns -EINVAL. Make it return -EROFS too for consistency. This is also important for our power cut emulation testing. Signed-off-by: Artem Bityutskiy --- fs/ubifs/commit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'fs/ubifs/commit.c') diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c index 87cd0ead863..8ab03d12d5c 100644 --- a/fs/ubifs/commit.c +++ b/fs/ubifs/commit.c @@ -418,7 +418,7 @@ int ubifs_run_commit(struct ubifs_info *c) spin_lock(&c->cs_lock); if (c->cmt_state == COMMIT_BROKEN) { - err = -EINVAL; + err = -EROFS; goto out; } @@ -444,7 +444,7 @@ int ubifs_run_commit(struct ubifs_info *c) * re-check it. */ if (c->cmt_state == COMMIT_BROKEN) { - err = -EINVAL; + err = -EROFS; goto out_cmt_unlock; } -- cgit v1.2.3-70-g09d2 From f42eed7cba7f83197b0ffbb023e7d89a0b2fd71d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Mon, 30 May 2011 14:45:30 +0300 Subject: UBIFS: harmonize znode flag helpers We have 3 znode flags: cow, obsolete, dirty. For the last flag we have a 'ubifs_zn_dirty()' helper function, but for the other 2 flags we use 'test_bit()' directly. This patch makes the situation more consistent and introduces helpers for the other 2 flags: 'ubifs_zn_cow()' and 'ubifs_zn_obsolete()'. Signed-off-by: Artem Bityutskiy --- fs/ubifs/commit.c | 2 +- fs/ubifs/misc.h | 23 +++++++++++++++++++++++ fs/ubifs/tnc.c | 13 ++++++------- fs/ubifs/tnc_commit.c | 8 ++++---- 4 files changed, 34 insertions(+), 12 deletions(-) (limited to 'fs/ubifs/commit.c') diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c index 8ab03d12d5c..637e07673c3 100644 --- a/fs/ubifs/commit.c +++ b/fs/ubifs/commit.c @@ -78,7 +78,7 @@ static int nothing_to_commit(struct ubifs_info *c) * If the root TNC node is dirty, we definitely have something to * commit. */ - if (c->zroot.znode && test_bit(DIRTY_ZNODE, &c->zroot.znode->flags)) + if (c->zroot.znode && ubifs_zn_dirty(c->zroot.znode)) return 0; /* diff --git a/fs/ubifs/misc.h b/fs/ubifs/misc.h index 0b5296a9a4c..160cd909e95 100644 --- a/fs/ubifs/misc.h +++ b/fs/ubifs/misc.h @@ -38,6 +38,29 @@ static inline int ubifs_zn_dirty(const struct ubifs_znode *znode) return !!test_bit(DIRTY_ZNODE, &znode->flags); } +/** + * ubifs_zn_obsolete - check if znode is obsolete. + * @znode: znode to check + * + * This helper function returns %1 if @znode is obsolete and %0 otherwise. + */ +static inline int ubifs_zn_obsolete(const struct ubifs_znode *znode) +{ + return !!test_bit(OBSOLETE_ZNODE, &znode->flags); +} + +/** + * ubifs_zn_cow - check if znode has to be copied on write. + * @znode: znode to check + * + * This helper function returns %1 if @znode is has COW flag set and %0 + * otherwise. + */ +static inline int ubifs_zn_cow(const struct ubifs_znode *znode) +{ + return !!test_bit(COW_ZNODE, &znode->flags); +} + /** * ubifs_wake_up_bgt - wake up background thread. * @c: UBIFS file-system description object diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index 48b6ee6fa84..b32a5376b7b 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c @@ -223,7 +223,7 @@ static struct ubifs_znode *copy_znode(struct ubifs_info *c, __set_bit(DIRTY_ZNODE, &zn->flags); __clear_bit(COW_ZNODE, &zn->flags); - ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags)); + ubifs_assert(!ubifs_zn_obsolete(znode)); __set_bit(OBSOLETE_ZNODE, &znode->flags); if (znode->level != 0) { @@ -271,7 +271,7 @@ static struct ubifs_znode *dirty_cow_znode(struct ubifs_info *c, struct ubifs_znode *zn; int err; - if (!test_bit(COW_ZNODE, &znode->flags)) { + if (!ubifs_zn_cow(znode)) { /* znode is not being committed */ if (!test_and_set_bit(DIRTY_ZNODE, &znode->flags)) { atomic_long_inc(&c->dirty_zn_cnt); @@ -2423,7 +2423,7 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n) */ do { - ubifs_assert(!test_bit(OBSOLETE_ZNODE, &znode->flags)); + ubifs_assert(!ubifs_zn_obsolete(znode)); ubifs_assert(ubifs_zn_dirty(znode)); zp = znode->parent; @@ -2479,9 +2479,8 @@ static int tnc_delete(struct ubifs_info *c, struct ubifs_znode *znode, int n) c->zroot.offs = zbr->offs; c->zroot.len = zbr->len; c->zroot.znode = znode; - ubifs_assert(!test_bit(OBSOLETE_ZNODE, - &zp->flags)); - ubifs_assert(test_bit(DIRTY_ZNODE, &zp->flags)); + ubifs_assert(!ubifs_zn_obsolete(zp)); + ubifs_assert(ubifs_zn_dirty(zp)); atomic_long_dec(&c->dirty_zn_cnt); if (zp->cnext) { @@ -2865,7 +2864,7 @@ static void tnc_destroy_cnext(struct ubifs_info *c) struct ubifs_znode *znode = cnext; cnext = cnext->cnext; - if (test_bit(OBSOLETE_ZNODE, &znode->flags)) + if (ubifs_zn_obsolete(znode)) kfree(znode); } while (cnext && cnext != c->cnext); } diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c index 8315387be3f..f50c3e5da26 100644 --- a/fs/ubifs/tnc_commit.c +++ b/fs/ubifs/tnc_commit.c @@ -87,7 +87,7 @@ static int make_idx_node(struct ubifs_info *c, struct ubifs_idx_node *idx, atomic_long_dec(&c->dirty_zn_cnt); ubifs_assert(ubifs_zn_dirty(znode)); - ubifs_assert(test_bit(COW_ZNODE, &znode->flags)); + ubifs_assert(ubifs_zn_cow(znode)); __clear_bit(DIRTY_ZNODE, &znode->flags); __clear_bit(COW_ZNODE, &znode->flags); @@ -639,7 +639,7 @@ static int get_znodes_to_commit(struct ubifs_info *c) } cnt += 1; while (1) { - ubifs_assert(!test_bit(COW_ZNODE, &znode->flags)); + ubifs_assert(!ubifs_zn_cow(znode)); __set_bit(COW_ZNODE, &znode->flags); znode->alt = 0; cnext = find_next_dirty(znode); @@ -888,7 +888,7 @@ static int write_index(struct ubifs_info *c) cnext = znode->cnext; ubifs_assert(ubifs_zn_dirty(znode)); - ubifs_assert(test_bit(COW_ZNODE, &znode->flags)); + ubifs_assert(ubifs_zn_cow(znode)); /* * It is important that other threads should see %DIRTY_ZNODE @@ -983,7 +983,7 @@ static void free_obsolete_znodes(struct ubifs_info *c) do { znode = cnext; cnext = znode->cnext; - if (test_bit(OBSOLETE_ZNODE, &znode->flags)) + if (ubifs_zn_obsolete(znode)) kfree(znode); else { znode->cnext = NULL; -- cgit v1.2.3-70-g09d2 From 2b1844a8c934723134ee1ff313e51d0d281cdef1 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 3 Jun 2011 08:31:29 +0300 Subject: UBIFS: introduce helper functions for debugging checks and tests This patch introduces helper functions for all debugging checks, so instead of doing if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) we now do if (!dbg_is_chk_gen(c)) This is a preparation to further changes where the flags will go away, and we'll need to only change the helper functions, but the code which utilizes them won't be touched. At the same time this patch removes 'dbg_force_in_the_gaps()', 'dbg_force_in_the_gaps_enabled()', and dbg_failure_mode helpers for consistency. Signed-off-by: Artem Bityutskiy --- fs/ubifs/commit.c | 2 +- fs/ubifs/debug.c | 30 +++++++++-------------- fs/ubifs/debug.h | 66 +++++++++++++++++++++++++++++++++++---------------- fs/ubifs/dir.c | 2 +- fs/ubifs/log.c | 2 +- fs/ubifs/lprops.c | 6 ++--- fs/ubifs/lpt.c | 2 +- fs/ubifs/lpt_commit.c | 10 ++++---- fs/ubifs/orphan.c | 2 +- fs/ubifs/scan.c | 2 +- fs/ubifs/tnc.c | 2 +- fs/ubifs/tnc_commit.c | 5 ++-- 12 files changed, 75 insertions(+), 56 deletions(-) (limited to 'fs/ubifs/commit.c') diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c index 637e07673c3..63c4e447f97 100644 --- a/fs/ubifs/commit.c +++ b/fs/ubifs/commit.c @@ -576,7 +576,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot) struct idx_node *i; size_t sz; - if (!(ubifs_chk_flags & UBIFS_CHK_OLD_IDX)) + if (!dbg_is_chk_old_idx(c)) return 0; INIT_LIST_HEAD(&list); diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 7adf9fe9181..79d8924aca5 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c @@ -330,7 +330,7 @@ void dbg_dump_node(const struct ubifs_info *c, const void *node) union ubifs_key key; const struct ubifs_ch *ch = node; - if (dbg_failure_mode) + if (dbg_is_tst_rcvry(c)) return; /* If the magic is incorrect, just hexdump the first bytes */ @@ -886,7 +886,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum) struct ubifs_scan_node *snod; void *buf; - if (dbg_failure_mode) + if (dbg_is_tst_rcvry(c)) return; printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n", @@ -1145,7 +1145,7 @@ int dbg_check_synced_i_size(const struct ubifs_info *c, struct inode *inode) int err = 0; struct ubifs_inode *ui = ubifs_inode(inode); - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; if (!S_ISREG(inode->i_mode)) return 0; @@ -1186,7 +1186,7 @@ int dbg_check_dir(struct ubifs_info *c, const struct inode *dir) struct qstr nm = { .name = NULL }; loff_t size = UBIFS_INO_NODE_SZ; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; if (!S_ISDIR(dir->i_mode)) @@ -1544,7 +1544,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra) long clean_cnt = 0, dirty_cnt = 0; int err, last; - if (!(ubifs_chk_flags & UBIFS_CHK_TNC)) + if (!dbg_is_chk_tnc(c)) return 0; ubifs_assert(mutex_is_locked(&c->tnc_mutex)); @@ -1791,7 +1791,7 @@ int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) int err; long long calc = 0; - if (!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ)) + if (!dbg_is_chk_idx_sz(c)) return 0; err = dbg_walk_index(c, NULL, add_size, &calc); @@ -2367,7 +2367,7 @@ int dbg_check_filesystem(struct ubifs_info *c) int err; struct fsck_data fsckd; - if (!(ubifs_chk_flags & UBIFS_CHK_FS)) + if (!dbg_is_chk_fs(c)) return 0; fsckd.inodes = RB_ROOT; @@ -2402,7 +2402,7 @@ int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head) struct list_head *cur; struct ubifs_scan_node *sa, *sb; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; for (cur = head->next; cur->next != head; cur = cur->next) { @@ -2469,7 +2469,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) struct list_head *cur; struct ubifs_scan_node *sa, *sb; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; for (cur = head->next; cur->next != head; cur = cur->next) { @@ -2546,14 +2546,6 @@ error_dump: return 0; } -int dbg_force_in_the_gaps(void) -{ - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) - return 0; - - return !(random32() & 7); -} - /* Failure mode for recovery testing */ #define chance(n, d) (simple_rand() <= (n) * 32768LL / (d)) @@ -2624,7 +2616,7 @@ static int in_failure_mode(struct ubi_volume_desc *desc) { struct ubifs_info *c = dbg_find_info(desc); - if (c && dbg_failure_mode) + if (c && dbg_is_tst_rcvry(c)) return c->dbg->failure_mode; return 0; } @@ -2634,7 +2626,7 @@ static int do_fail(struct ubi_volume_desc *desc, int lnum, int write) struct ubifs_info *c = dbg_find_info(desc); struct ubifs_debug_info *d; - if (!c || !dbg_failure_mode) + if (!c || !dbg_is_tst_rcvry(c)) return 0; d = c->dbg; if (d->failure_mode) diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h index 90805bd4945..c3d1ffd0610 100644 --- a/fs/ubifs/debug.h +++ b/fs/ubifs/debug.h @@ -31,8 +31,6 @@ typedef int (*dbg_znode_callback)(struct ubifs_info *c, #ifdef CONFIG_UBIFS_FS_DEBUG -#include - /* * The UBIFS debugfs directory name pattern and maximum name length (3 for "ubi" * + 1 for "_" and plus 2x2 for 2 UBI numbers and 1 for the trailing zero byte. @@ -169,6 +167,8 @@ const char *dbg_key_str1(const struct ubifs_info *c, /* Additional recovery messages */ #define dbg_rcvry(fmt, ...) ubifs_dbg_msg("rcvry", fmt, ##__VA_ARGS__) +extern spinlock_t dbg_lock; + /* * Debugging check flags. * @@ -199,12 +199,43 @@ enum { UBIFS_TST_RCVRY = 0x4, }; -extern spinlock_t dbg_lock; - extern unsigned int ubifs_msg_flags; extern unsigned int ubifs_chk_flags; extern unsigned int ubifs_tst_flags; +static inline int dbg_is_chk_gen(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_GEN); +} +static inline int dbg_is_chk_tnc(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_TNC); +} +static inline int dbg_is_chk_idx_sz(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ); +} +static inline int dbg_is_chk_orph(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_ORPH); +} +static inline int dbg_is_chk_old_idx(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_OLD_IDX); +} +static inline int dbg_is_chk_lprops(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_LPROPS); +} +static inline int dbg_is_chk_fs(const struct ubifs_info *c) +{ + return !!(ubifs_chk_flags & UBIFS_CHK_FS); +} +static inline int dbg_is_tst_rcvry(const struct ubifs_info *c) +{ + return !!(ubifs_tst_flags & UBIFS_TST_RCVRY); +} + int ubifs_debugging_init(struct ubifs_info *c); void ubifs_debugging_exit(struct ubifs_info *c); @@ -261,16 +292,6 @@ int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode, int dbg_check_data_nodes_order(struct ubifs_info *c, struct list_head *head); int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head); -/* Force the use of in-the-gaps method for testing */ -static inline int dbg_force_in_the_gaps_enabled(void) -{ - return ubifs_chk_flags & UBIFS_CHK_GEN; -} -int dbg_force_in_the_gaps(void); - -/* Failure mode for recovery testing */ -#define dbg_failure_mode (ubifs_tst_flags & UBIFS_TST_RCVRY) - #ifndef UBIFS_DBG_PRESERVE_UBI #define ubi_leb_read dbg_leb_read #define ubi_leb_write dbg_leb_write @@ -330,6 +351,9 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c); ubifs_err(fmt, ##__VA_ARGS__); \ } while (0) +#define DBGKEY(key) ((char *)(key)) +#define DBGKEY1(key) ((char *)(key)) + #define ubifs_dbg_msg(fmt, ...) do { \ if (0) \ pr_debug(fmt "\n", ##__VA_ARGS__); \ @@ -353,9 +377,6 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c); #define dbg_scan(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) #define dbg_rcvry(fmt, ...) ubifs_dbg_msg(fmt, ##__VA_ARGS__) -#define DBGKEY(key) ((char *)(key)) -#define DBGKEY1(key) ((char *)(key)) - static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; } static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; } static inline const char *dbg_ntype(int type) { return ""; } @@ -440,9 +461,14 @@ static inline int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) { return 0; } -static inline int dbg_force_in_the_gaps(void) { return 0; } -#define dbg_force_in_the_gaps_enabled() 0 -#define dbg_failure_mode 0 +static inline int dbg_is_chk_gen(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_tnc(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_idx_sz(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_orph(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_old_idx(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_lprops(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_fs(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_tst_rcvry(const struct ubifs_info *c) { return 0; } static inline int dbg_debugfs_init(void) { return 0; } static inline void dbg_debugfs_exit(void) { return; } diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 98014bf1d8b..68349204331 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -176,7 +176,7 @@ static int dbg_check_name(const struct ubifs_info *c, const struct ubifs_dent_node *dent, const struct qstr *nm) { - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; if (le16_to_cpu(dent->nlen) != nm->len) return -EINVAL; diff --git a/fs/ubifs/log.c b/fs/ubifs/log.c index affea9494ae..fabfb53c4fe 100644 --- a/fs/ubifs/log.c +++ b/fs/ubifs/log.c @@ -752,7 +752,7 @@ static int dbg_check_bud_bytes(struct ubifs_info *c) struct ubifs_bud *bud; long long bud_bytes = 0; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; spin_lock(&c->buds_lock); diff --git a/fs/ubifs/lprops.c b/fs/ubifs/lprops.c index 98b8e73c454..f8a181e647c 100644 --- a/fs/ubifs/lprops.c +++ b/fs/ubifs/lprops.c @@ -860,7 +860,7 @@ int dbg_check_cats(struct ubifs_info *c) struct list_head *pos; int i, cat; - if (!(ubifs_chk_flags & (UBIFS_CHK_GEN | UBIFS_CHK_LPROPS))) + if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c)) return 0; list_for_each_entry(lprops, &c->empty_list, list) { @@ -958,7 +958,7 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, { int i = 0, j, err = 0; - if (!(ubifs_chk_flags & (UBIFS_CHK_GEN | UBIFS_CHK_LPROPS))) + if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c)) return; for (i = 0; i < heap->cnt; i++) { @@ -1262,7 +1262,7 @@ int dbg_check_lprops(struct ubifs_info *c) int i, err; struct ubifs_lp_stats lst; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; /* diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c index 04713cd2267..ab91ca62845 100644 --- a/fs/ubifs/lpt.c +++ b/fs/ubifs/lpt.c @@ -2226,7 +2226,7 @@ int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, struct ubifs_cnode *cn; int num, iip = 0, err; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; while (cnode) { diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c index 254e8d32fc6..f8e286ba809 100644 --- a/fs/ubifs/lpt_commit.c +++ b/fs/ubifs/lpt_commit.c @@ -1640,7 +1640,7 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) int ret; void *buf, *p; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; buf = p = __vmalloc(c->leb_size, GFP_NOFS, PAGE_KERNEL); @@ -1711,7 +1711,7 @@ int dbg_check_ltab(struct ubifs_info *c) { int lnum, err, i, cnt; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; /* Bring the entire tree into memory */ @@ -1754,7 +1754,7 @@ int dbg_chk_lpt_free_spc(struct ubifs_info *c) long long free = 0; int i; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; for (i = 0; i < c->lpt_lebs; i++) { @@ -1796,7 +1796,7 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) long long chk_lpt_sz, lpt_sz; int err = 0; - if (!(ubifs_chk_flags & UBIFS_CHK_LPROPS)) + if (!dbg_is_chk_lprops(c)) return 0; switch (action) { @@ -2019,7 +2019,7 @@ static int dbg_populate_lsave(struct ubifs_info *c) struct ubifs_lpt_heap *heap; int i; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; if (random32() & 3) return 0; diff --git a/fs/ubifs/orphan.c b/fs/ubifs/orphan.c index a5422fffbd6..c542c73cfa3 100644 --- a/fs/ubifs/orphan.c +++ b/fs/ubifs/orphan.c @@ -929,7 +929,7 @@ static int dbg_check_orphans(struct ubifs_info *c) struct check_info ci; int err; - if (!(ubifs_chk_flags & UBIFS_CHK_ORPH)) + if (!dbg_is_chk_orph(c)) return 0; ci.last_ino = 0; diff --git a/fs/ubifs/scan.c b/fs/ubifs/scan.c index 36216b46f77..c7df916dce9 100644 --- a/fs/ubifs/scan.c +++ b/fs/ubifs/scan.c @@ -240,7 +240,7 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, int len; ubifs_err("corruption at LEB %d:%d", lnum, offs); - if (dbg_failure_mode) + if (dbg_is_tst_rcvry(c)) return; len = c->leb_size - offs; if (len > 8192) diff --git a/fs/ubifs/tnc.c b/fs/ubifs/tnc.c index b32a5376b7b..526b63cd333 100644 --- a/fs/ubifs/tnc.c +++ b/fs/ubifs/tnc.c @@ -3300,7 +3300,7 @@ int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode, if (!S_ISREG(inode->i_mode)) return 0; - if (!(ubifs_chk_flags & UBIFS_CHK_GEN)) + if (!dbg_is_chk_gen(c)) return 0; block = (size + UBIFS_BLOCK_SIZE - 1) >> UBIFS_BLOCK_SHIFT; diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c index d6fab1a9986..8959c726b02 100644 --- a/fs/ubifs/tnc_commit.c +++ b/fs/ubifs/tnc_commit.c @@ -23,6 +23,7 @@ /* This file implements TNC functions for committing */ #include "ubifs.h" +#include /** * make_idx_node - make an index node for fill-the-gaps method of TNC commit. @@ -381,7 +382,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt) c->gap_lebs = NULL; return err; } - if (dbg_force_in_the_gaps_enabled()) { + if (!dbg_is_chk_gen(c)) { /* * Do not print scary warnings if the debugging * option which forces in-the-gaps is enabled. @@ -689,7 +690,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt) c->ilebs[c->ileb_cnt++] = lnum; dbg_cmt("LEB %d", lnum); } - if (dbg_force_in_the_gaps()) + if (dbg_is_chk_gen(c) && !(random32() & 7)) return -ENOSPC; return 0; } -- cgit v1.2.3-70-g09d2 From 8d7819b4af697eec45339cc24db7c3fe45fea0e7 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 3 Jun 2011 08:53:35 +0300 Subject: UBIFS: lessen amount of debugging check types We have too many different debugging checks - lessen the amount by merging all index-related checks into one. At the same time, move the "force in-the-gap" test to the "index checks" class, because it is too heavy for the "general" class. This patch merges TNC, Old index, and Index size check and calles this just "index checks". Signed-off-by: Artem Bityutskiy --- Documentation/filesystems/ubifs.txt | 4 +--- fs/ubifs/commit.c | 2 +- fs/ubifs/debug.c | 4 ++-- fs/ubifs/debug.h | 24 +++++------------------- fs/ubifs/lpt_commit.c | 1 + fs/ubifs/tnc_commit.c | 6 +++--- 6 files changed, 13 insertions(+), 28 deletions(-) (limited to 'fs/ubifs/commit.c') diff --git a/Documentation/filesystems/ubifs.txt b/Documentation/filesystems/ubifs.txt index 8e4fab639d9..91ef07652cd 100644 --- a/Documentation/filesystems/ubifs.txt +++ b/Documentation/filesystems/ubifs.txt @@ -123,10 +123,8 @@ debug_chks Selects extra checks that UBIFS can do while running: Check Flag value General checks 1 - Check Tree Node Cache (TNC) 2 - Check indexing tree size 4 + Check the index 2 Check orphan area 8 - Check old indexing tree 16 Check LEB properties (lprops) 32 Check leaf nodes and inodes 64 diff --git a/fs/ubifs/commit.c b/fs/ubifs/commit.c index 63c4e447f97..fb3b5c813a3 100644 --- a/fs/ubifs/commit.c +++ b/fs/ubifs/commit.c @@ -576,7 +576,7 @@ int dbg_check_old_index(struct ubifs_info *c, struct ubifs_zbranch *zroot) struct idx_node *i; size_t sz; - if (!dbg_is_chk_old_idx(c)) + if (!dbg_is_chk_index(c)) return 0; INIT_LIST_HEAD(&list); diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c index 79d8924aca5..a967d6800ea 100644 --- a/fs/ubifs/debug.c +++ b/fs/ubifs/debug.c @@ -1544,7 +1544,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra) long clean_cnt = 0, dirty_cnt = 0; int err, last; - if (!dbg_is_chk_tnc(c)) + if (!dbg_is_chk_index(c)) return 0; ubifs_assert(mutex_is_locked(&c->tnc_mutex)); @@ -1791,7 +1791,7 @@ int dbg_check_idx_size(struct ubifs_info *c, long long idx_size) int err; long long calc = 0; - if (!dbg_is_chk_idx_sz(c)) + if (!dbg_is_chk_index(c)) return 0; err = dbg_walk_index(c, NULL, add_size, &calc); diff --git a/fs/ubifs/debug.h b/fs/ubifs/debug.h index c3d1ffd0610..44265a3a08c 100644 --- a/fs/ubifs/debug.h +++ b/fs/ubifs/debug.h @@ -173,19 +173,15 @@ extern spinlock_t dbg_lock; * Debugging check flags. * * UBIFS_CHK_GEN: general checks - * UBIFS_CHK_TNC: check TNC - * UBIFS_CHK_IDX_SZ: check index size + * UBIFS_CHK_INDEX: check the index * UBIFS_CHK_ORPH: check orphans - * UBIFS_CHK_OLD_IDX: check the old index * UBIFS_CHK_LPROPS: check lprops * UBIFS_CHK_FS: check the file-system */ enum { UBIFS_CHK_GEN = 0x1, - UBIFS_CHK_TNC = 0x2, - UBIFS_CHK_IDX_SZ = 0x4, + UBIFS_CHK_INDEX = 0x2, UBIFS_CHK_ORPH = 0x8, - UBIFS_CHK_OLD_IDX = 0x10, UBIFS_CHK_LPROPS = 0x20, UBIFS_CHK_FS = 0x40, }; @@ -207,22 +203,14 @@ static inline int dbg_is_chk_gen(const struct ubifs_info *c) { return !!(ubifs_chk_flags & UBIFS_CHK_GEN); } -static inline int dbg_is_chk_tnc(const struct ubifs_info *c) +static inline int dbg_is_chk_index(const struct ubifs_info *c) { - return !!(ubifs_chk_flags & UBIFS_CHK_TNC); -} -static inline int dbg_is_chk_idx_sz(const struct ubifs_info *c) -{ - return !!(ubifs_chk_flags & UBIFS_CHK_IDX_SZ); + return !!(ubifs_chk_flags & UBIFS_CHK_INDEX); } static inline int dbg_is_chk_orph(const struct ubifs_info *c) { return !!(ubifs_chk_flags & UBIFS_CHK_ORPH); } -static inline int dbg_is_chk_old_idx(const struct ubifs_info *c) -{ - return !!(ubifs_chk_flags & UBIFS_CHK_OLD_IDX); -} static inline int dbg_is_chk_lprops(const struct ubifs_info *c) { return !!(ubifs_chk_flags & UBIFS_CHK_LPROPS); @@ -462,10 +450,8 @@ dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) { return 0; } static inline int dbg_is_chk_gen(const struct ubifs_info *c) { return 0; } -static inline int dbg_is_chk_tnc(const struct ubifs_info *c) { return 0; } -static inline int dbg_is_chk_idx_sz(const struct ubifs_info *c) { return 0; } +static inline int dbg_is_chk_index(const struct ubifs_info *c) { return 0; } static inline int dbg_is_chk_orph(const struct ubifs_info *c) { return 0; } -static inline int dbg_is_chk_old_idx(const struct ubifs_info *c) { return 0; } static inline int dbg_is_chk_lprops(const struct ubifs_info *c) { return 0; } static inline int dbg_is_chk_fs(const struct ubifs_info *c) { return 0; } static inline int dbg_is_tst_rcvry(const struct ubifs_info *c) { return 0; } diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c index f8e286ba809..f13addf72e8 100644 --- a/fs/ubifs/lpt_commit.c +++ b/fs/ubifs/lpt_commit.c @@ -27,6 +27,7 @@ #include #include +#include #include "ubifs.h" #ifdef CONFIG_UBIFS_FS_DEBUG diff --git a/fs/ubifs/tnc_commit.c b/fs/ubifs/tnc_commit.c index 8959c726b02..4c15f07a8bb 100644 --- a/fs/ubifs/tnc_commit.c +++ b/fs/ubifs/tnc_commit.c @@ -22,8 +22,8 @@ /* This file implements TNC functions for committing */ -#include "ubifs.h" #include +#include "ubifs.h" /** * make_idx_node - make an index node for fill-the-gaps method of TNC commit. @@ -382,7 +382,7 @@ static int layout_in_gaps(struct ubifs_info *c, int cnt) c->gap_lebs = NULL; return err; } - if (!dbg_is_chk_gen(c)) { + if (!dbg_is_chk_index(c)) { /* * Do not print scary warnings if the debugging * option which forces in-the-gaps is enabled. @@ -690,7 +690,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt) c->ilebs[c->ileb_cnt++] = lnum; dbg_cmt("LEB %d", lnum); } - if (dbg_is_chk_gen(c) && !(random32() & 7)) + if (dbg_is_chk_index(c) && !(random32() & 7)) return -ENOSPC; return 0; } -- cgit v1.2.3-70-g09d2