UBI: make self-checks dynamic
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Mon, 14 Mar 2011 16:17:40 +0000 (18:17 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 16 Mar 2011 11:50:16 +0000 (13:50 +0200)
This patch adds a possibility to dynamically switch UBI self-checks
on and off, instead of toggling them compile-time from the configuration
menu. This is much more flexible, and consistent with UBIFS, and this
also simplifies UBI Kconfig menu and the code.

This patch introduces two levels of self-checks - general, which
includes all self-checks which are relatively fast, and I/O, which
includes write-verify checks and erase-verify checks, which are
relatively slow and involve flash I/O.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/Kconfig.debug
drivers/mtd/ubi/debug.c
drivers/mtd/ubi/debug.h
drivers/mtd/ubi/io.c
drivers/mtd/ubi/scan.c
drivers/mtd/ubi/vmt.c
drivers/mtd/ubi/vtbl.c
drivers/mtd/ubi/wl.c

index d40134e9d5720d7129ef3acc404c2486815f4d7f..d8d33ddf567d52df453a4aa3d0624b2513e6ac0b 100644 (file)
@@ -10,12 +10,6 @@ config MTD_UBI_DEBUG
 
 if MTD_UBI_DEBUG
 
-config MTD_UBI_DEBUG_PARANOID
-       bool "Extra self-checks"
-       help
-         This option enables extra checks in UBI code. Note this slows UBI down
-         significantly.
-
 config MTD_UBI_DEBUG_DISABLE_BGT
        bool "Do not enable the UBI background thread"
        help
index 8ae0bc7401ca8ac5b91845cedbd3062509c67123..4c7a3f67156b0f039b00da286c0c0e40702e0c01 100644 (file)
 #include <linux/moduleparam.h>
 
 unsigned int ubi_msg_flags;
+unsigned int ubi_chk_flags;
 
 module_param_named(debug_msgs, ubi_msg_flags, uint, S_IRUGO | S_IWUSR);
+module_param_named(debug_chks, ubi_chk_flags, uint, S_IRUGO | S_IWUSR);
 
 MODULE_PARM_DESC(debug_msgs, "Debug message type flags");
+MODULE_PARM_DESC(debug_chks, "Debug check flags");
 
 /**
  * ubi_dbg_dump_ec_hdr - dump an erase counter header.
index bee6fa1e5147649f1e35b6660ddd524f3f887cd4..2511b586490a155937a382c39beaa037f285e8e6 100644 (file)
@@ -99,14 +99,22 @@ enum {
 /* Initialization and build messages */
 #define dbg_bld(fmt, ...) dbg_do_msg(UBI_MSG_BLD, fmt, ##__VA_ARGS__)
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+extern unsigned int ubi_chk_flags;
+
+/*
+ * Debugging check flags.
+ *
+ * UBI_CHK_GEN: general checks
+ * UBI_CHK_IO: check writes and erases
+ */
+enum {
+       UBI_CHK_GEN = 0x1,
+       UBI_CHK_IO  = 0x2,
+};
+
 int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
 int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
                        int offset, int len);
-#else
-#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
-#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
-#endif
 
 #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
 #define DBG_DISABLE_BGT 1
index b1ad1ec812ada5d16c225e025f54f129cc34e69f..aaa6e1e83b297f6bbbc96e660fb9048d9125dab2 100644 (file)
@@ -91,7 +91,7 @@
 #include <linux/slab.h>
 #include "ubi.h"
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum);
 static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum);
 static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
@@ -1126,7 +1126,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
        return err;
 }
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 
 /**
  * paranoid_check_not_bad - ensure that a physical eraseblock is not bad.
@@ -1140,6 +1140,9 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
 {
        int err;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        err = ubi_io_is_bad(ubi, pnum);
        if (!err)
                return err;
@@ -1164,6 +1167,9 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
        int err;
        uint32_t magic;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        magic = be32_to_cpu(ec_hdr->magic);
        if (magic != UBI_EC_HDR_MAGIC) {
                ubi_err("bad magic %#08x, must be %#08x",
@@ -1199,6 +1205,9 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
        uint32_t crc, hdr_crc;
        struct ubi_ec_hdr *ec_hdr;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
        if (!ec_hdr)
                return -ENOMEM;
@@ -1240,6 +1249,9 @@ static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
        int err;
        uint32_t magic;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        magic = be32_to_cpu(vid_hdr->magic);
        if (magic != UBI_VID_HDR_MAGIC) {
                ubi_err("bad VID header magic %#08x at PEB %d, must be %#08x",
@@ -1278,6 +1290,9 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
        struct ubi_vid_hdr *vid_hdr;
        void *p;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
        if (!vid_hdr)
                return -ENOMEM;
@@ -1327,6 +1342,9 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
        void *buf1;
        loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        buf1 = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
        if (!buf1) {
                ubi_err("cannot allocate memory to check writes");
@@ -1388,6 +1406,9 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
        void *buf;
        loff_t addr = (loff_t)pnum * ubi->peb_size + offset;
 
+       if (!(ubi_chk_flags & UBI_CHK_IO))
+               return 0;
+
        buf = __vmalloc(len, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
        if (!buf) {
                ubi_err("cannot allocate memory to check for 0xFFs");
@@ -1422,4 +1443,4 @@ error:
        return err;
 }
 
-#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+#endif /* CONFIG_MTD_UBI_DEBUG */
index b65cc088fde5bbe5ba7807074801791a252ba9e0..11eb8ef124854e88812b1e1f3203b2019941afc8 100644 (file)
@@ -88,7 +88,7 @@
 #include <linux/random.h>
 #include "ubi.h"
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si);
 #else
 #define paranoid_check_si(ubi, si) 0
@@ -1329,7 +1329,7 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
        kfree(si);
 }
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 
 /**
  * paranoid_check_si - check the scanning information.
@@ -1347,6 +1347,9 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
        struct ubi_scan_leb *seb, *last_seb;
        uint8_t *buf;
 
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return 0;
+
        /*
         * At first, check that scanning information is OK.
         */
@@ -1599,4 +1602,4 @@ out:
        return -EINVAL;
 }
 
-#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+#endif /* CONFIG_MTD_UBI_DEBUG */
index c47620dfc722c33417b33d8f8a1608f1478a0241..b79e0dea36320720f7b931010ae6416b1a177a8d 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/slab.h>
 #include "ubi.h"
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 static int paranoid_check_volumes(struct ubi_device *ubi);
 #else
 #define paranoid_check_volumes(ubi) 0
@@ -711,7 +711,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
        volume_sysfs_close(vol);
 }
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 
 /**
  * paranoid_check_volume - check volume information.
@@ -876,6 +876,9 @@ static int paranoid_check_volumes(struct ubi_device *ubi)
 {
        int i, err = 0;
 
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return 0;
+
        for (i = 0; i < ubi->vtbl_slots; i++) {
                err = paranoid_check_volume(ubi, i);
                if (err)
index fcdb7f65fe0beb3388b60daeab433733d4f1ecc7..0b81c5527357195eaf2aa69bdd67b4bcf6f9ad45 100644 (file)
@@ -62,7 +62,7 @@
 #include <asm/div64.h>
 #include "ubi.h"
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 static void paranoid_vtbl_check(const struct ubi_device *ubi);
 #else
 #define paranoid_vtbl_check(ubi)
@@ -870,7 +870,7 @@ out_free:
        return err;
 }
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 
 /**
  * paranoid_vtbl_check - check volume table.
@@ -878,10 +878,13 @@ out_free:
  */
 static void paranoid_vtbl_check(const struct ubi_device *ubi)
 {
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return;
+
        if (vtbl_check(ubi, ubi->vtbl)) {
                ubi_err("paranoid check failed");
                BUG();
        }
 }
 
-#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+#endif /* CONFIG_MTD_UBI_DEBUG */
index 655bbbe415d99b89074e1344953f8e60f10ac0be..4e5529014c9be6501565f2e22308b16d7a31096b 100644 (file)
@@ -161,7 +161,7 @@ struct ubi_work {
        int torture;
 };
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec);
 static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
                                     struct rb_root *root);
@@ -1561,7 +1561,7 @@ void ubi_wl_close(struct ubi_device *ubi)
        kfree(ubi->lookuptbl);
 }
 
-#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
+#ifdef CONFIG_MTD_UBI_DEBUG
 
 /**
  * paranoid_check_ec - make sure that the erase counter of a PEB is correct.
@@ -1578,6 +1578,9 @@ static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
        long long read_ec;
        struct ubi_ec_hdr *ec_hdr;
 
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return 0;
+
        ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
        if (!ec_hdr)
                return -ENOMEM;
@@ -1614,6 +1617,9 @@ out_free:
 static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
                                     struct rb_root *root)
 {
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return 0;
+
        if (in_wl_tree(e, root))
                return 0;
 
@@ -1636,6 +1642,9 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
        struct ubi_wl_entry *p;
        int i;
 
+       if (!(ubi_chk_flags & UBI_CHK_GEN))
+               return 0;
+
        for (i = 0; i < UBI_PROT_QUEUE_LEN; ++i)
                list_for_each_entry(p, &ubi->pq[i], u.list)
                        if (p == e)
@@ -1646,4 +1655,5 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
        ubi_dbg_dump_stack();
        return -EINVAL;
 }
-#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
+
+#endif /* CONFIG_MTD_UBI_DEBUG */
This page took 0.030849 seconds and 5 git commands to generate.