aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/debug.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-06-03 08:10:33 -0400
committerArtem Bityutskiy <dedekind1@gmail.com>2011-07-04 03:54:34 -0400
commitd27462a518c31a4b1093ad866229f85b2b765e7e (patch)
treee2663f6294ad516bc3debebf394fc437a84d0de5 /fs/ubifs/debug.c
parentf57cb188ccd9c0242111d99b7283eda7827746c4 (diff)
UBIFS: rename recovery testing variables
Since the recovery testing is effectively about emulating power cuts by UBIFS, use "power cut" as the base term for all the related variables and name them correspondingly. This is just a minor clean-up for the sake of readability. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs/ubifs/debug.c')
-rw-r--r--fs/ubifs/debug.c52
1 files changed, 28 insertions, 24 deletions
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 1e880cedefa4..b801af7837e9 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -2548,39 +2548,36 @@ static int simple_rand(void)
2548 return (next >> 16) & 32767; 2548 return (next >> 16) & 32767;
2549} 2549}
2550 2550
2551static int do_fail(struct ubifs_info *c, int lnum, int write) 2551static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
2552{ 2552{
2553 struct ubifs_debug_info *d = c->dbg; 2553 struct ubifs_debug_info *d = c->dbg;
2554 2554
2555 ubifs_assert(dbg_is_tst_rcvry(c)); 2555 ubifs_assert(dbg_is_tst_rcvry(c));
2556 2556
2557 if (d->failure_mode) 2557 if (!d->pc_cnt) {
2558 return 1; 2558 /* First call - decide delay to the power cut */
2559
2560 if (!d->fail_cnt) {
2561 /* First call - decide delay to failure */
2562 if (chance(1, 2)) { 2559 if (chance(1, 2)) {
2563 unsigned int delay = 1 << (simple_rand() >> 11); 2560 unsigned int delay = 1 << (simple_rand() >> 11);
2564 2561
2565 if (chance(1, 2)) { 2562 if (chance(1, 2)) {
2566 d->fail_delay = 1; 2563 d->pc_delay = 1;
2567 d->fail_timeout = jiffies + 2564 d->pc_timeout = jiffies +
2568 msecs_to_jiffies(delay); 2565 msecs_to_jiffies(delay);
2569 ubifs_warn("failing after %ums", delay); 2566 ubifs_warn("failing after %ums", delay);
2570 } else { 2567 } else {
2571 d->fail_delay = 2; 2568 d->pc_delay = 2;
2572 d->fail_cnt_max = delay; 2569 d->pc_cnt_max = delay;
2573 ubifs_warn("failing after %u calls", delay); 2570 ubifs_warn("failing after %u calls", delay);
2574 } 2571 }
2575 } 2572 }
2576 d->fail_cnt += 1; 2573 d->pc_cnt += 1;
2577 } 2574 }
2578 /* Determine if failure delay has expired */ 2575 /* Determine if failure delay has expired */
2579 if (d->fail_delay == 1) { 2576 if (d->pc_delay == 1) {
2580 if (time_before(jiffies, d->fail_timeout)) 2577 if (time_before(jiffies, d->pc_timeout))
2581 return 0; 2578 return 0;
2582 } else if (d->fail_delay == 2) 2579 } else if (d->pc_delay == 2)
2583 if (d->fail_cnt++ < d->fail_cnt_max) 2580 if (d->pc_cnt++ < d->pc_cnt_max)
2584 return 0; 2581 return 0;
2585 if (lnum == UBIFS_SB_LNUM) { 2582 if (lnum == UBIFS_SB_LNUM) {
2586 if (write) { 2583 if (write) {
@@ -2638,7 +2635,7 @@ static int do_fail(struct ubifs_info *c, int lnum, int write)
2638 ubifs_warn("failing in bud LEB %d commit not running", lnum); 2635 ubifs_warn("failing in bud LEB %d commit not running", lnum);
2639 } 2636 }
2640 2637
2641 d->failure_mode = 1; 2638 d->pc_happened = 1;
2642 dump_stack(); 2639 dump_stack();
2643 return 1; 2640 return 1;
2644} 2641}
@@ -2658,9 +2655,10 @@ int dbg_leb_write(struct ubifs_info *c, int lnum, const void *buf,
2658{ 2655{
2659 int err, failing; 2656 int err, failing;
2660 2657
2661 if (c->dbg->failure_mode) 2658 if (c->dbg->pc_happened)
2662 return -EROFS; 2659 return -EROFS;
2663 failing = do_fail(c, lnum, 1); 2660
2661 failing = power_cut_emulated(c, lnum, 1);
2664 if (failing) 2662 if (failing)
2665 cut_data(buf, len); 2663 cut_data(buf, len);
2666 err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype); 2664 err = ubi_leb_write(c->ubi, lnum, buf, offs, len, dtype);
@@ -2676,12 +2674,14 @@ int dbg_leb_change(struct ubifs_info *c, int lnum, const void *buf,
2676{ 2674{
2677 int err; 2675 int err;
2678 2676
2679 if (do_fail(c, lnum, 1)) 2677 if (c->dbg->pc_happened)
2678 return -EROFS;
2679 if (power_cut_emulated(c, lnum, 1))
2680 return -EROFS; 2680 return -EROFS;
2681 err = ubi_leb_change(c->ubi, lnum, buf, len, dtype); 2681 err = ubi_leb_change(c->ubi, lnum, buf, len, dtype);
2682 if (err) 2682 if (err)
2683 return err; 2683 return err;
2684 if (do_fail(c, lnum, 1)) 2684 if (power_cut_emulated(c, lnum, 1))
2685 return -EROFS; 2685 return -EROFS;
2686 return 0; 2686 return 0;
2687} 2687}
@@ -2690,12 +2690,14 @@ int dbg_leb_unmap(struct ubifs_info *c, int lnum)
2690{ 2690{
2691 int err; 2691 int err;
2692 2692
2693 if (do_fail(c, lnum, 0)) 2693 if (c->dbg->pc_happened)
2694 return -EROFS;
2695 if (power_cut_emulated(c, lnum, 0))
2694 return -EROFS; 2696 return -EROFS;
2695 err = ubi_leb_unmap(c->ubi, lnum); 2697 err = ubi_leb_unmap(c->ubi, lnum);
2696 if (err) 2698 if (err)
2697 return err; 2699 return err;
2698 if (do_fail(c, lnum, 0)) 2700 if (power_cut_emulated(c, lnum, 0))
2699 return -EROFS; 2701 return -EROFS;
2700 return 0; 2702 return 0;
2701} 2703}
@@ -2704,12 +2706,14 @@ int dbg_leb_map(struct ubifs_info *c, int lnum, int dtype)
2704{ 2706{
2705 int err; 2707 int err;
2706 2708
2707 if (do_fail(c, lnum, 0)) 2709 if (c->dbg->pc_happened)
2710 return -EROFS;
2711 if (power_cut_emulated(c, lnum, 0))
2708 return -EROFS; 2712 return -EROFS;
2709 err = ubi_leb_map(c->ubi, lnum, dtype); 2713 err = ubi_leb_map(c->ubi, lnum, dtype);
2710 if (err) 2714 if (err)
2711 return err; 2715 return err;
2712 if (do_fail(c, lnum, 0)) 2716 if (power_cut_emulated(c, lnum, 0))
2713 return -EROFS; 2717 return -EROFS;
2714 return 0; 2718 return 0;
2715} 2719}