~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to fs/ubifs/debug.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <linux/moduleparam.h>
35
35
#include <linux/debugfs.h>
36
36
#include <linux/math64.h>
37
 
#include <linux/slab.h>
38
37
 
39
38
#ifdef CONFIG_UBIFS_FS_DEBUG
40
39
 
43
42
static char dbg_key_buf0[128];
44
43
static char dbg_key_buf1[128];
45
44
 
46
 
unsigned int ubifs_msg_flags;
47
45
unsigned int ubifs_chk_flags;
48
46
unsigned int ubifs_tst_flags;
49
47
 
50
 
module_param_named(debug_msgs, ubifs_msg_flags, uint, S_IRUGO | S_IWUSR);
51
48
module_param_named(debug_chks, ubifs_chk_flags, uint, S_IRUGO | S_IWUSR);
52
49
module_param_named(debug_tsts, ubifs_tst_flags, uint, S_IRUGO | S_IWUSR);
53
50
 
54
 
MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
55
51
MODULE_PARM_DESC(debug_chks, "Debug check flags");
56
52
MODULE_PARM_DESC(debug_tsts, "Debug special test flags");
57
53
 
317
313
                printk(KERN_DEBUG "\tflags          %#x\n", sup_flags);
318
314
                printk(KERN_DEBUG "\t  big_lpt      %u\n",
319
315
                       !!(sup_flags & UBIFS_FLG_BIGLPT));
 
316
                printk(KERN_DEBUG "\t  space_fixup  %u\n",
 
317
                       !!(sup_flags & UBIFS_FLG_SPACE_FIXUP));
320
318
                printk(KERN_DEBUG "\tmin_io_size    %u\n",
321
319
                       le32_to_cpu(sup->min_io_size));
322
320
                printk(KERN_DEBUG "\tleb_size       %u\n",
602
600
        spin_unlock(&dbg_lock);
603
601
}
604
602
 
605
 
void dbg_dump_budg(struct ubifs_info *c)
 
603
void dbg_dump_budg(struct ubifs_info *c, const struct ubifs_budg_info *bi)
606
604
{
607
605
        int i;
608
606
        struct rb_node *rb;
610
608
        struct ubifs_gced_idx_leb *idx_gc;
611
609
        long long available, outstanding, free;
612
610
 
613
 
        ubifs_assert(spin_is_locked(&c->space_lock));
 
611
        spin_lock(&c->space_lock);
614
612
        spin_lock(&dbg_lock);
615
 
        printk(KERN_DEBUG "(pid %d) Budgeting info: budg_data_growth %lld, "
616
 
               "budg_dd_growth %lld, budg_idx_growth %lld\n", current->pid,
617
 
               c->budg_data_growth, c->budg_dd_growth, c->budg_idx_growth);
618
 
        printk(KERN_DEBUG "\tdata budget sum %lld, total budget sum %lld, "
619
 
               "freeable_cnt %d\n", c->budg_data_growth + c->budg_dd_growth,
620
 
               c->budg_data_growth + c->budg_dd_growth + c->budg_idx_growth,
621
 
               c->freeable_cnt);
622
 
        printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %lld, "
623
 
               "calc_idx_sz %lld, idx_gc_cnt %d\n", c->min_idx_lebs,
624
 
               c->old_idx_sz, c->calc_idx_sz, c->idx_gc_cnt);
 
613
        printk(KERN_DEBUG "(pid %d) Budgeting info: data budget sum %lld, "
 
614
               "total budget sum %lld\n", current->pid,
 
615
               bi->data_growth + bi->dd_growth,
 
616
               bi->data_growth + bi->dd_growth + bi->idx_growth);
 
617
        printk(KERN_DEBUG "\tbudg_data_growth %lld, budg_dd_growth %lld, "
 
618
               "budg_idx_growth %lld\n", bi->data_growth, bi->dd_growth,
 
619
               bi->idx_growth);
 
620
        printk(KERN_DEBUG "\tmin_idx_lebs %d, old_idx_sz %llu, "
 
621
               "uncommitted_idx %lld\n", bi->min_idx_lebs, bi->old_idx_sz,
 
622
               bi->uncommitted_idx);
 
623
        printk(KERN_DEBUG "\tpage_budget %d, inode_budget %d, dent_budget %d\n",
 
624
               bi->page_budget, bi->inode_budget, bi->dent_budget);
 
625
        printk(KERN_DEBUG "\tnospace %u, nospace_rp %u\n",
 
626
               bi->nospace, bi->nospace_rp);
 
627
        printk(KERN_DEBUG "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n",
 
628
               c->dark_wm, c->dead_wm, c->max_idx_node_sz);
 
629
 
 
630
        if (bi != &c->bi)
 
631
                /*
 
632
                 * If we are dumping saved budgeting data, do not print
 
633
                 * additional information which is about the current state, not
 
634
                 * the old one which corresponded to the saved budgeting data.
 
635
                 */
 
636
                goto out_unlock;
 
637
 
 
638
        printk(KERN_DEBUG "\tfreeable_cnt %d, calc_idx_sz %lld, idx_gc_cnt %d\n",
 
639
               c->freeable_cnt, c->calc_idx_sz, c->idx_gc_cnt);
625
640
        printk(KERN_DEBUG "\tdirty_pg_cnt %ld, dirty_zn_cnt %ld, "
626
641
               "clean_zn_cnt %ld\n", atomic_long_read(&c->dirty_pg_cnt),
627
642
               atomic_long_read(&c->dirty_zn_cnt),
628
643
               atomic_long_read(&c->clean_zn_cnt));
629
 
        printk(KERN_DEBUG "\tdark_wm %d, dead_wm %d, max_idx_node_sz %d\n",
630
 
               c->dark_wm, c->dead_wm, c->max_idx_node_sz);
631
644
        printk(KERN_DEBUG "\tgc_lnum %d, ihead_lnum %d\n",
632
645
               c->gc_lnum, c->ihead_lnum);
 
646
 
633
647
        /* If we are in R/O mode, journal heads do not exist */
634
648
        if (c->jheads)
635
649
                for (i = 0; i < c->jhead_cnt; i++)
648
662
        printk(KERN_DEBUG "\tcommit state %d\n", c->cmt_state);
649
663
 
650
664
        /* Print budgeting predictions */
651
 
        available = ubifs_calc_available(c, c->min_idx_lebs);
652
 
        outstanding = c->budg_data_growth + c->budg_dd_growth;
 
665
        available = ubifs_calc_available(c, c->bi.min_idx_lebs);
 
666
        outstanding = c->bi.data_growth + c->bi.dd_growth;
653
667
        free = ubifs_get_free_space_nolock(c);
654
668
        printk(KERN_DEBUG "Budgeting predictions:\n");
655
669
        printk(KERN_DEBUG "\tavailable: %lld, outstanding %lld, free %lld\n",
656
670
               available, outstanding, free);
 
671
out_unlock:
657
672
        spin_unlock(&dbg_lock);
 
673
        spin_unlock(&c->space_lock);
658
674
}
659
675
 
660
676
void dbg_dump_lprop(const struct ubifs_info *c, const struct ubifs_lprops *lp)
729
745
                if (bud->lnum == lp->lnum) {
730
746
                        int head = 0;
731
747
                        for (i = 0; i < c->jhead_cnt; i++) {
732
 
                                if (lp->lnum == c->jheads[i].wbuf.lnum) {
 
748
                                /*
 
749
                                 * Note, if we are in R/O mode or in the middle
 
750
                                 * of mounting/re-mounting, the write-buffers do
 
751
                                 * not exist.
 
752
                                 */
 
753
                                if (c->jheads &&
 
754
                                    lp->lnum == c->jheads[i].wbuf.lnum) {
733
755
                                        printk(KERN_CONT ", jhead %s",
734
756
                                               dbg_jhead(i));
735
757
                                        head = 1;
976
998
 
977
999
        spin_lock(&c->space_lock);
978
1000
        memcpy(&d->saved_lst, &c->lst, sizeof(struct ubifs_lp_stats));
 
1001
        memcpy(&d->saved_bi, &c->bi, sizeof(struct ubifs_budg_info));
 
1002
        d->saved_idx_gc_cnt = c->idx_gc_cnt;
979
1003
 
980
1004
        /*
981
1005
         * We use a dirty hack here and zero out @c->freeable_cnt, because it
1042
1066
out:
1043
1067
        ubifs_msg("saved lprops statistics dump");
1044
1068
        dbg_dump_lstats(&d->saved_lst);
1045
 
        ubifs_get_lp_stats(c, &lst);
1046
 
 
 
1069
        ubifs_msg("saved budgeting info dump");
 
1070
        dbg_dump_budg(c, &d->saved_bi);
 
1071
        ubifs_msg("saved idx_gc_cnt %d", d->saved_idx_gc_cnt);
1047
1072
        ubifs_msg("current lprops statistics dump");
 
1073
        ubifs_get_lp_stats(c, &lst);
1048
1074
        dbg_dump_lstats(&lst);
1049
 
 
1050
 
        spin_lock(&c->space_lock);
1051
 
        dbg_dump_budg(c);
1052
 
        spin_unlock(&c->space_lock);
 
1075
        ubifs_msg("current budgeting info dump");
 
1076
        dbg_dump_budg(c, &c->bi);
1053
1077
        dump_stack();
1054
1078
        return -EINVAL;
1055
1079
}
1793
1817
        struct rb_node **p, *parent = NULL;
1794
1818
        struct fsck_inode *fscki;
1795
1819
        ino_t inum = key_inum_flash(c, &ino->key);
 
1820
        struct inode *inode;
 
1821
        struct ubifs_inode *ui;
1796
1822
 
1797
1823
        p = &fsckd->inodes.rb_node;
1798
1824
        while (*p) {
1816
1842
        if (!fscki)
1817
1843
                return ERR_PTR(-ENOMEM);
1818
1844
 
 
1845
        inode = ilookup(c->vfs_sb, inum);
 
1846
 
1819
1847
        fscki->inum = inum;
1820
 
        fscki->nlink = le32_to_cpu(ino->nlink);
1821
 
        fscki->size = le64_to_cpu(ino->size);
1822
 
        fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt);
1823
 
        fscki->xattr_sz = le32_to_cpu(ino->xattr_size);
1824
 
        fscki->xattr_nms = le32_to_cpu(ino->xattr_names);
1825
 
        fscki->mode = le32_to_cpu(ino->mode);
 
1848
        /*
 
1849
         * If the inode is present in the VFS inode cache, use it instead of
 
1850
         * the on-flash inode which might be out-of-date. E.g., the size might
 
1851
         * be out-of-date. If we do not do this, the following may happen, for
 
1852
         * example:
 
1853
         *   1. A power cut happens
 
1854
         *   2. We mount the file-system R/O, the replay process fixes up the
 
1855
         *      inode size in the VFS cache, but on on-flash.
 
1856
         *   3. 'check_leaf()' fails because it hits a data node beyond inode
 
1857
         *      size.
 
1858
         */
 
1859
        if (!inode) {
 
1860
                fscki->nlink = le32_to_cpu(ino->nlink);
 
1861
                fscki->size = le64_to_cpu(ino->size);
 
1862
                fscki->xattr_cnt = le32_to_cpu(ino->xattr_cnt);
 
1863
                fscki->xattr_sz = le32_to_cpu(ino->xattr_size);
 
1864
                fscki->xattr_nms = le32_to_cpu(ino->xattr_names);
 
1865
                fscki->mode = le32_to_cpu(ino->mode);
 
1866
        } else {
 
1867
                ui = ubifs_inode(inode);
 
1868
                fscki->nlink = inode->i_nlink;
 
1869
                fscki->size = inode->i_size;
 
1870
                fscki->xattr_cnt = ui->xattr_cnt;
 
1871
                fscki->xattr_sz = ui->xattr_size;
 
1872
                fscki->xattr_nms = ui->xattr_names;
 
1873
                fscki->mode = inode->i_mode;
 
1874
                iput(inode);
 
1875
        }
 
1876
 
1826
1877
        if (S_ISDIR(fscki->mode)) {
1827
1878
                fscki->calc_sz = UBIFS_INO_NODE_SZ;
1828
1879
                fscki->calc_cnt = 2;
1829
1880
        }
 
1881
 
1830
1882
        rb_link_node(&fscki->rb, parent, p);
1831
1883
        rb_insert_color(&fscki->rb, &fsckd->inodes);
 
1884
 
1832
1885
        return fscki;
1833
1886
}
1834
1887
 
2421
2474
                hashb = key_block(c, &sb->key);
2422
2475
 
2423
2476
                if (hasha > hashb) {
2424
 
                        ubifs_err("larger hash %u goes before %u", hasha, hashb);
 
2477
                        ubifs_err("larger hash %u goes before %u",
 
2478
                                  hasha, hashb);
2425
2479
                        goto error_dump;
2426
2480
                }
2427
2481
        }
2437
2491
        return 0;
2438
2492
}
2439
2493
 
2440
 
static int invocation_cnt;
2441
 
 
2442
2494
int dbg_force_in_the_gaps(void)
2443
2495
{
2444
 
        if (!dbg_force_in_the_gaps_enabled)
 
2496
        if (!(ubifs_chk_flags & UBIFS_CHK_GEN))
2445
2497
                return 0;
2446
 
        /* Force in-the-gaps every 8th commit */
2447
 
        return !((invocation_cnt++) & 0x7);
 
2498
 
 
2499
        return !(random32() & 7);
2448
2500
}
2449
2501
 
2450
2502
/* Failure mode for recovery testing */
2632
2684
                 int len, int check)
2633
2685
{
2634
2686
        if (in_failure_mode(desc))
2635
 
                return -EIO;
 
2687
                return -EROFS;
2636
2688
        return ubi_leb_read(desc, lnum, buf, offset, len, check);
2637
2689
}
2638
2690
 
2642
2694
        int err, failing;
2643
2695
 
2644
2696
        if (in_failure_mode(desc))
2645
 
                return -EIO;
 
2697
                return -EROFS;
2646
2698
        failing = do_fail(desc, lnum, 1);
2647
2699
        if (failing)
2648
2700
                cut_data(buf, len);
2650
2702
        if (err)
2651
2703
                return err;
2652
2704
        if (failing)
2653
 
                return -EIO;
 
2705
                return -EROFS;
2654
2706
        return 0;
2655
2707
}
2656
2708
 
2660
2712
        int err;
2661
2713
 
2662
2714
        if (do_fail(desc, lnum, 1))
2663
 
                return -EIO;
 
2715
                return -EROFS;
2664
2716
        err = ubi_leb_change(desc, lnum, buf, len, dtype);
2665
2717
        if (err)
2666
2718
                return err;
2667
2719
        if (do_fail(desc, lnum, 1))
2668
 
                return -EIO;
 
2720
                return -EROFS;
2669
2721
        return 0;
2670
2722
}
2671
2723
 
2674
2726
        int err;
2675
2727
 
2676
2728
        if (do_fail(desc, lnum, 0))
2677
 
                return -EIO;
 
2729
                return -EROFS;
2678
2730
        err = ubi_leb_erase(desc, lnum);
2679
2731
        if (err)
2680
2732
                return err;
2681
2733
        if (do_fail(desc, lnum, 0))
2682
 
                return -EIO;
 
2734
                return -EROFS;
2683
2735
        return 0;
2684
2736
}
2685
2737
 
2688
2740
        int err;
2689
2741
 
2690
2742
        if (do_fail(desc, lnum, 0))
2691
 
                return -EIO;
 
2743
                return -EROFS;
2692
2744
        err = ubi_leb_unmap(desc, lnum);
2693
2745
        if (err)
2694
2746
                return err;
2695
2747
        if (do_fail(desc, lnum, 0))
2696
 
                return -EIO;
 
2748
                return -EROFS;
2697
2749
        return 0;
2698
2750
}
2699
2751
 
2700
2752
int dbg_is_mapped(struct ubi_volume_desc *desc, int lnum)
2701
2753
{
2702
2754
        if (in_failure_mode(desc))
2703
 
                return -EIO;
 
2755
                return -EROFS;
2704
2756
        return ubi_is_mapped(desc, lnum);
2705
2757
}
2706
2758
 
2709
2761
        int err;
2710
2762
 
2711
2763
        if (do_fail(desc, lnum, 0))
2712
 
                return -EIO;
 
2764
                return -EROFS;
2713
2765
        err = ubi_leb_map(desc, lnum, dtype);
2714
2766
        if (err)
2715
2767
                return err;
2716
2768
        if (do_fail(desc, lnum, 0))
2717
 
                return -EIO;
 
2769
                return -EROFS;
2718
2770
        return 0;
2719
2771
}
2720
2772
 
2784
2836
static int open_debugfs_file(struct inode *inode, struct file *file)
2785
2837
{
2786
2838
        file->private_data = inode->i_private;
2787
 
        return 0;
 
2839
        return nonseekable_open(inode, file);
2788
2840
}
2789
2841
 
2790
2842
static ssize_t write_debugfs_file(struct file *file, const char __user *buf,
2795
2847
 
2796
2848
        if (file->f_path.dentry == d->dfs_dump_lprops)
2797
2849
                dbg_dump_lprops(c);
2798
 
        else if (file->f_path.dentry == d->dfs_dump_budg) {
2799
 
                spin_lock(&c->space_lock);
2800
 
                dbg_dump_budg(c);
2801
 
                spin_unlock(&c->space_lock);
2802
 
        } else if (file->f_path.dentry == d->dfs_dump_tnc) {
 
2850
        else if (file->f_path.dentry == d->dfs_dump_budg)
 
2851
                dbg_dump_budg(c, &c->bi);
 
2852
        else if (file->f_path.dentry == d->dfs_dump_tnc) {
2803
2853
                mutex_lock(&c->tnc_mutex);
2804
2854
                dbg_dump_tnc(c);
2805
2855
                mutex_unlock(&c->tnc_mutex);
2806
2856
        } else
2807
2857
                return -EINVAL;
2808
2858
 
2809
 
        *ppos += count;
2810
2859
        return count;
2811
2860
}
2812
2861
 
2814
2863
        .open = open_debugfs_file,
2815
2864
        .write = write_debugfs_file,
2816
2865
        .owner = THIS_MODULE,
2817
 
        .llseek = default_llseek,
 
2866
        .llseek = no_llseek,
2818
2867
};
2819
2868
 
2820
2869
/**