cregit-Linux how code gets into the kernel

Release 4.11 fs/jffs2/debug.c

Directory: fs/jffs2
/*
 * JFFS2 -- Journalling Flash File System, Version 2.
 *
 * Copyright © 2001-2007 Red Hat, Inc.
 * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
 *
 * Created by David Woodhouse <dwmw2@infradead.org>
 *
 * For licensing information, see the file 'LICENCE' in this directory.
 *
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/pagemap.h>
#include <linux/crc32.h>
#include <linux/jffs2.h>
#include <linux/mtd/mtd.h>
#include <linux/slab.h>
#include "nodelist.h"
#include "debug.h"

#ifdef JFFS2_DBG_SANITY_CHECKS


void __jffs2_dbg_acct_sanity_check_nolock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { if (unlikely(jeb && jeb->used_size + jeb->dirty_size + jeb->free_size + jeb->wasted_size + jeb->unchecked_size != c->sector_size)) { JFFS2_ERROR("eeep, space accounting for block at 0x%08x is screwed.\n", jeb->offset); JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n", jeb->free_size, jeb->dirty_size, jeb->used_size, jeb->wasted_size, jeb->unchecked_size, c->sector_size); BUG(); } if (unlikely(c->used_size + c->dirty_size + c->free_size + c->erasing_size + c->bad_size + c->wasted_size + c->unchecked_size != c->flash_size)) { JFFS2_ERROR("eeep, space accounting superblock info is screwed.\n"); JFFS2_ERROR("free %#08x + dirty %#08x + used %#08x + erasing %#08x + bad %#08x + wasted %#08x + unchecked %#08x != total %#08x.\n", c->free_size, c->dirty_size, c->used_size, c->erasing_size, c->bad_size, c->wasted_size, c->unchecked_size, c->flash_size); BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy173100.00%2100.00%
Total173100.00%2100.00%


void __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { spin_lock(&c->erase_completion_lock); jffs2_dbg_acct_sanity_check_nolock(c, jeb); spin_unlock(&c->erase_completion_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy38100.00%1100.00%
Total38100.00%1100.00%

#endif /* JFFS2_DBG_SANITY_CHECKS */ #ifdef JFFS2_DBG_PARANOIA_CHECKS /* * Check the fragtree. */
void __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f) { mutex_lock(&f->sem); __jffs2_dbg_fragtree_paranoia_check_nolock(f); mutex_unlock(&f->sem); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy2993.55%150.00%
David Woodhouse26.45%150.00%
Total31100.00%2100.00%


void __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f) { struct jffs2_node_frag *frag; int bitched = 0; for (frag = frag_first(&f->fragtree); frag; frag = frag_next(frag)) { struct jffs2_full_dnode *fn = frag->node; if (!fn || !fn->raw) continue; if (ref_flags(fn->raw) == REF_PRISTINE) { if (fn->frags > 1) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x had %d frags. Tell dwmw2.\n", ref_offset(fn->raw), fn->frags); bitched = 1; } /* A hole node which isn't multi-page should be garbage-collected and merged anyway, so we just check for the frag size here, rather than mucking around with actually reading the node and checking the compression type, which is the real way to tell a hole node. */ if (frag->ofs & (PAGE_SIZE-1) && frag_prev(frag) && frag_prev(frag)->size < PAGE_SIZE && frag_prev(frag)->node) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x had a previous non-hole frag in the same page. Tell dwmw2.\n", ref_offset(fn->raw)); bitched = 1; } if ((frag->ofs+frag->size) & (PAGE_SIZE-1) && frag_next(frag) && frag_next(frag)->size < PAGE_SIZE && frag_next(frag)->node) { JFFS2_ERROR("REF_PRISTINE node at 0x%08x (%08x-%08x) had a following non-hole frag in the same page. Tell dwmw2.\n", ref_offset(fn->raw), frag->ofs, frag->ofs+frag->size); bitched = 1; } } } if (bitched) { JFFS2_ERROR("fragtree is corrupted.\n"); __jffs2_dbg_dump_fragtree_nolock(f); BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy24298.37%375.00%
Kirill A. Shutemov41.63%125.00%
Total246100.00%4100.00%

/* * Check if the flash contains all 0xFF before we start writing. */
void __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c, uint32_t ofs, int len) { size_t retlen; int ret, i; unsigned char *buf; buf = kmalloc(len, GFP_KERNEL); if (!buf) return; ret = jffs2_flash_read(c, ofs, len, &retlen, buf); if (ret || (retlen != len)) { JFFS2_WARNING("read %d bytes failed or short. ret %d, retlen %zd.\n", len, ret, retlen); kfree(buf); return; } ret = 0; for (i = 0; i < len; i++) if (buf[i] != 0xff) ret = 1; if (ret) { JFFS2_ERROR("argh, about to write node to %#08x on flash, but there are data already there. The first corrupted byte is at %#08x offset.\n", ofs, ofs + i); __jffs2_dbg_dump_buffer(buf, len, ofs); kfree(buf); BUG(); } kfree(buf); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy158100.00%3100.00%
Total158100.00%3100.00%


void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c) { struct jffs2_eraseblock *jeb; uint32_t free = 0, dirty = 0, used = 0, wasted = 0, erasing = 0, bad = 0, unchecked = 0; int nr_counted = 0; int dump = 0; if (c->gcblock) { nr_counted++; free += c->gcblock->free_size; dirty += c->gcblock->dirty_size; used += c->gcblock->used_size; wasted += c->gcblock->wasted_size; unchecked += c->gcblock->unchecked_size; } if (c->nextblock) { nr_counted++; free += c->nextblock->free_size; dirty += c->nextblock->dirty_size; used += c->nextblock->used_size; wasted += c->nextblock->wasted_size; unchecked += c->nextblock->unchecked_size; } list_for_each_entry(jeb, &c->clean_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->very_dirty_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->dirty_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->erasable_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->erasable_pending_wbuf_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->erase_pending_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->free_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->bad_used_list, list) { nr_counted++; free += jeb->free_size; dirty += jeb->dirty_size; used += jeb->used_size; wasted += jeb->wasted_size; unchecked += jeb->unchecked_size; } list_for_each_entry(jeb, &c->erasing_list, list) { nr_counted++; erasing += c->sector_size; } list_for_each_entry(jeb, &c->erase_checking_list, list) { nr_counted++; erasing += c->sector_size; } list_for_each_entry(jeb, &c->erase_complete_list, list) { nr_counted++; erasing += c->sector_size; } list_for_each_entry(jeb, &c->bad_list, list) { nr_counted++; bad += c->sector_size; } #define check(sz) \ do { \ if (sz != c->sz##_size) { \ pr_warn("%s_size mismatch counted 0x%x, c->%s_size 0x%x\n", \ #sz, sz, #sz, c->sz##_size); \ dump = 1; \ } \ } while (0) check(free); check(dirty); check(used); check(wasted); check(unchecked); check(bad); check(erasing); #undef check if (nr_counted != c->nr_blocks) { pr_warn("%s counted only 0x%x blocks of 0x%x. Where are the others?\n", __func__, nr_counted, c->nr_blocks); dump = 1; } if (dump) { __jffs2_dbg_dump_block_lists_nolock(c); BUG(); } }

Contributors

PersonTokensPropCommitsCommitProp
David Woodhouse66199.70%250.00%
Joe Perches20.30%250.00%
Total663100.00%4100.00%

/* * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'. */
void __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { spin_lock(&c->erase_completion_lock); __jffs2_dbg_acct_paranoia_check_nolock(c, jeb); spin_unlock(&c->erase_completion_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy38100.00%2100.00%
Total38100.00%2100.00%


void __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { uint32_t my_used_size = 0; uint32_t my_unchecked_size = 0; uint32_t my_dirty_size = 0; struct jffs2_raw_node_ref *ref2 = jeb->first_node; while (ref2) { uint32_t totlen = ref_totlen(c, jeb, ref2); if (ref_offset(ref2) < jeb->offset || ref_offset(ref2) > jeb->offset + c->sector_size) { JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n", ref_offset(ref2), jeb->offset); goto error; } if (ref_flags(ref2) == REF_UNCHECKED) my_unchecked_size += totlen; else if (!ref_obsolete(ref2)) my_used_size += totlen; else my_dirty_size += totlen; if ((!ref_next(ref2)) != (ref2 == jeb->last_node)) { JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next at %#08x (mem %p), last_node is at %#08x (mem %p).\n", ref_offset(ref2), ref2, ref_offset(ref_next(ref2)), ref_next(ref2), ref_offset(jeb->last_node), jeb->last_node); goto error; } ref2 = ref_next(ref2); } if (my_used_size != jeb->used_size) { JFFS2_ERROR("Calculated used size %#08x != stored used size %#08x.\n", my_used_size, jeb->used_size); goto error; } if (my_unchecked_size != jeb->unchecked_size) { JFFS2_ERROR("Calculated unchecked size %#08x != stored unchecked size %#08x.\n", my_unchecked_size, jeb->unchecked_size); goto error; } #if 0 /* This should work when we implement ref->__totlen elemination */ if (my_dirty_size != jeb->dirty_size + jeb->wasted_size) { JFFS2_ERROR("Calculated dirty+wasted size %#08x != stored dirty + wasted size %#08x\n", my_dirty_size, jeb->dirty_size + jeb->wasted_size); goto error; } if (jeb->free_size == 0 && my_used_size + my_unchecked_size + my_dirty_size != c->sector_size) { JFFS2_ERROR("The sum of all nodes in block (%#x) != size of block (%#x)\n", my_used_size + my_unchecked_size + my_dirty_size, c->sector_size); goto error; } #endif if (!(c->flags & (JFFS2_SB_FLAG_BUILDING|JFFS2_SB_FLAG_SCANNING))) __jffs2_dbg_superblock_counts(c); return; error: __jffs2_dbg_dump_node_refs_nolock(c, jeb); __jffs2_dbg_dump_jeb_nolock(jeb); __jffs2_dbg_dump_block_lists_nolock(c); BUG(); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy25686.78%240.00%
David Woodhouse3311.19%240.00%
Kyungmin Park62.03%120.00%
Total295100.00%5100.00%

#endif /* JFFS2_DBG_PARANOIA_CHECKS */ #if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS) /* * Dump the node_refs of the 'jeb' JFFS2 eraseblock. */
void __jffs2_dbg_dump_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { spin_lock(&c->erase_completion_lock); __jffs2_dbg_dump_node_refs_nolock(c, jeb); spin_unlock(&c->erase_completion_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy38100.00%2100.00%
Total38100.00%2100.00%


void __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { struct jffs2_raw_node_ref *ref; int i = 0; printk(JFFS2_DBG_MSG_PREFIX " Dump node_refs of the eraseblock %#08x\n", jeb->offset); if (!jeb->first_node) { printk(JFFS2_DBG_MSG_PREFIX " no nodes in the eraseblock %#08x\n", jeb->offset); return; } printk(JFFS2_DBG); for (ref = jeb->first_node; ; ref = ref_next(ref)) { printk("%#08x", ref_offset(ref)); #ifdef TEST_TOTLEN printk("(%x)", ref->__totlen); #endif if (ref_next(ref)) printk("->"); else break; if (++i == 4) { i = 0; printk("\n" JFFS2_DBG); } } printk("\n"); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy12387.86%360.00%
David Woodhouse1712.14%240.00%
Total140100.00%5100.00%

/* * Dump an eraseblock's space accounting. */
void __jffs2_dbg_dump_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) { spin_lock(&c->erase_completion_lock); __jffs2_dbg_dump_jeb_nolock(jeb); spin_unlock(&c->erase_completion_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy36100.00%1100.00%
Total36100.00%1100.00%


void __jffs2_dbg_dump_jeb_nolock(struct jffs2_eraseblock *jeb) { if (!jeb) return; printk(JFFS2_DBG_MSG_PREFIX " dump space accounting for the eraseblock at %#08x:\n", jeb->offset); printk(JFFS2_DBG "used_size: %#08x\n", jeb->used_size); printk(JFFS2_DBG "dirty_size: %#08x\n", jeb->dirty_size); printk(JFFS2_DBG "wasted_size: %#08x\n", jeb->wasted_size); printk(JFFS2_DBG "unchecked_size: %#08x\n", jeb->unchecked_size); printk(JFFS2_DBG "free_size: %#08x\n", jeb->free_size); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy76100.00%2100.00%
Total76100.00%2100.00%


void __jffs2_dbg_dump_block_lists(struct jffs2_sb_info *c) { spin_lock(&c->erase_completion_lock); __jffs2_dbg_dump_block_lists_nolock(c); spin_unlock(&c->erase_completion_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Artem B. Bityutskiy31100.00%1100.00%
Total31100.00%1100.00%


void __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c) { printk(JFFS2_DBG_MSG_PREFIX " dump JFFS2 blocks lists:\n"); printk(JFFS2_DBG "flash_size: %#08x\n", c->flash_size); printk(JFFS2_DBG "used_size: %#08x\n", c->used_size); printk(JFFS2_DBG "dirty_size: %#08x\n", c->dirty_size); printk(JFFS2_DBG "wasted_size: %#08x\n", c->wasted_size); printk(JFFS2_DBG "unchecked_size: %#08x\n", c->unchecked_size); printk(JFFS2_DBG "free_size: %#08x\n", c->free_size); printk(JFFS2_DBG "erasing_size: %#08x\n", c->erasing_size); printk(JFFS2_DBG "bad_size: %#08x\n", c->bad_size); printk(JFFS2_DBG "sector_size: %#08x\n", c->sector_size); printk(JFFS2_DBG "jffs2_reserved_blocks size: %#08x\n", c->sector_size * c->resv_blocks_write); if (c->nextblock) printk(JFFS2_DBG "nextblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", c->nextblock->offset, c->nextblock->used_size, c->nextblock->dirty_size, c->nextblock->wasted_size, c->nextblock->unchecked_size, c->nextblock->free_size); else printk(JFFS2_DBG "nextblock: NULL\n"); if (c->gcblock) printk(JFFS2_DBG "gcblock: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", c->gcblock->offset, c->gcblock->used_size, c->gcblock->dirty_size, c->gcblock->wasted_size, c->gcblock->unchecked_size, c->gcblock->free_size); else printk(JFFS2_DBG "gcblock: NULL\n"); if (list_empty(&c->clean_list)) { printk(JFFS2_DBG "clean_list: empty\n"); } else { struct list_head *this; int numblocks = 0; uint32_t dirty = 0; list_for_each(this, &c->clean_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); numblocks ++; dirty += jeb->wasted_size; if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "clean_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } printk (JFFS2_DBG "Contains %d blocks with total wasted size %u, average wasted size: %u\n", numblocks, dirty, dirty / numblocks); } if (list_empty(&c->very_dirty_list)) { printk(JFFS2_DBG "very_dirty_list: empty\n"); } else { struct list_head *this; int numblocks = 0; uint32_t dirty = 0; list_for_each(this, &c->very_dirty_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); numblocks ++; dirty += jeb->dirty_size; if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "very_dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } printk (JFFS2_DBG "Contains %d blocks with total dirty size %u, average dirty size: %u\n", numblocks, dirty, dirty / numblocks); } if (list_empty(&c->dirty_list)) { printk(JFFS2_DBG "dirty_list: empty\n"); } else { struct list_head *this; int numblocks = 0; uint32_t dirty = 0; list_for_each(this, &c->dirty_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); numblocks ++; dirty += jeb->dirty_size; if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "dirty_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } printk (JFFS2_DBG "contains %d blocks with total dirty size %u, average dirty size: %u\n", numblocks, dirty, dirty / numblocks); } if (list_empty(&c->erasable_list)) { printk(JFFS2_DBG "erasable_list: empty\n"); } else { struct list_head *this; list_for_each(this, &c->erasable_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "erasable_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } } if (list_empty(&c->erasing_list)) { printk(JFFS2_DBG "erasing_list: empty\n"); } else { struct list_head *this; list_for_each(this, &c->erasing_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "erasing_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } } if (list_empty(&c->erase_checking_list)) { printk(JFFS2_DBG "erase_checking_list: empty\n"); } else { struct list_head *this; list_for_each(this, &c->erase_checking_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) { printk(JFFS2_DBG "erase_checking_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n", jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size, jeb->unchecked_size, jeb->free_size); } } } if (list_empty(&c->erase_pending_list)) { printk(JFFS2_DBG "erase_pending_list: empty\n"); } else { struct list_head *this; list_for_each(this, &c->erase_pending_list) { struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list); if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {