debug.c (527491885554002837b5742202adc0ab5f536e54) debug.c (17c2f9f85c896b48a5d74a9155d99ec5b241a0e6)
1/*
2 * This file is part of UBIFS.
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.

--- 691 unchanged lines hidden (view full) ---

700 struct ubifs_scan_leb *sleb;
701 struct ubifs_scan_node *snod;
702
703 if (dbg_failure_mode)
704 return;
705
706 printk(KERN_DEBUG "(pid %d) Dumping LEB %d\n", current->pid, lnum);
707
1/*
2 * This file is part of UBIFS.
3 *
4 * Copyright (C) 2006-2008 Nokia Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.

--- 691 unchanged lines hidden (view full) ---

700 struct ubifs_scan_leb *sleb;
701 struct ubifs_scan_node *snod;
702
703 if (dbg_failure_mode)
704 return;
705
706 printk(KERN_DEBUG "(pid %d) Dumping LEB %d\n", current->pid, lnum);
707
708 sleb = ubifs_scan(c, lnum, 0, c->dbg_buf);
708 sleb = ubifs_scan(c, lnum, 0, c->dbg->buf);
709 if (IS_ERR(sleb)) {
710 ubifs_err("scan error %d", (int)PTR_ERR(sleb));
711 return;
712 }
713
714 printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum,
715 sleb->nodes_cnt, sleb->endpt);
716

--- 1375 unchanged lines hidden (view full) ---

2092static int simple_rand(void)
2093{
2094 if (next == 0)
2095 next = current->pid;
2096 next = next * 1103515245 + 12345;
2097 return (next >> 16) & 32767;
2098}
2099
709 if (IS_ERR(sleb)) {
710 ubifs_err("scan error %d", (int)PTR_ERR(sleb));
711 return;
712 }
713
714 printk(KERN_DEBUG "LEB %d has %d nodes ending at %d\n", lnum,
715 sleb->nodes_cnt, sleb->endpt);
716

--- 1375 unchanged lines hidden (view full) ---

2092static int simple_rand(void)
2093{
2094 if (next == 0)
2095 next = current->pid;
2096 next = next * 1103515245 + 12345;
2097 return (next >> 16) & 32767;
2098}
2099
2100void dbg_failure_mode_registration(struct ubifs_info *c)
2100static void failure_mode_init(struct ubifs_info *c)
2101{
2102 struct failure_mode_info *fmi;
2103
2104 fmi = kmalloc(sizeof(struct failure_mode_info), GFP_NOFS);
2105 if (!fmi) {
2106 dbg_err("Failed to register failure mode - no memory");
2107 return;
2108 }
2109 fmi->c = c;
2110 spin_lock(&fmi_lock);
2111 list_add_tail(&fmi->list, &fmi_list);
2112 spin_unlock(&fmi_lock);
2113}
2114
2101{
2102 struct failure_mode_info *fmi;
2103
2104 fmi = kmalloc(sizeof(struct failure_mode_info), GFP_NOFS);
2105 if (!fmi) {
2106 dbg_err("Failed to register failure mode - no memory");
2107 return;
2108 }
2109 fmi->c = c;
2110 spin_lock(&fmi_lock);
2111 list_add_tail(&fmi->list, &fmi_list);
2112 spin_unlock(&fmi_lock);
2113}
2114
2115void dbg_failure_mode_deregistration(struct ubifs_info *c)
2115static void failure_mode_exit(struct ubifs_info *c)
2116{
2117 struct failure_mode_info *fmi, *tmp;
2118
2119 spin_lock(&fmi_lock);
2120 list_for_each_entry_safe(fmi, tmp, &fmi_list, list)
2121 if (fmi->c == c) {
2122 list_del(&fmi->list);
2123 kfree(fmi);

--- 17 unchanged lines hidden (view full) ---

2141 return NULL;
2142}
2143
2144static int in_failure_mode(struct ubi_volume_desc *desc)
2145{
2146 struct ubifs_info *c = dbg_find_info(desc);
2147
2148 if (c && dbg_failure_mode)
2116{
2117 struct failure_mode_info *fmi, *tmp;
2118
2119 spin_lock(&fmi_lock);
2120 list_for_each_entry_safe(fmi, tmp, &fmi_list, list)
2121 if (fmi->c == c) {
2122 list_del(&fmi->list);
2123 kfree(fmi);

--- 17 unchanged lines hidden (view full) ---

2141 return NULL;
2142}
2143
2144static int in_failure_mode(struct ubi_volume_desc *desc)
2145{
2146 struct ubifs_info *c = dbg_find_info(desc);
2147
2148 if (c && dbg_failure_mode)
2149 return c->failure_mode;
2149 return c->dbg->failure_mode;
2150 return 0;
2151}
2152
2153static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
2154{
2155 struct ubifs_info *c = dbg_find_info(desc);
2150 return 0;
2151}
2152
2153static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
2154{
2155 struct ubifs_info *c = dbg_find_info(desc);
2156 struct ubifs_debug_info *d;
2156
2157 if (!c || !dbg_failure_mode)
2158 return 0;
2157
2158 if (!c || !dbg_failure_mode)
2159 return 0;
2159 if (c->failure_mode)
2160 d = c->dbg;
2161 if (d->failure_mode)
2160 return 1;
2162 return 1;
2161 if (!c->fail_cnt) {
2163 if (!d->fail_cnt) {
2162 /* First call - decide delay to failure */
2163 if (chance(1, 2)) {
2164 unsigned int delay = 1 << (simple_rand() >> 11);
2165
2166 if (chance(1, 2)) {
2164 /* First call - decide delay to failure */
2165 if (chance(1, 2)) {
2166 unsigned int delay = 1 << (simple_rand() >> 11);
2167
2168 if (chance(1, 2)) {
2167 c->fail_delay = 1;
2168 c->fail_timeout = jiffies +
2169 d->fail_delay = 1;
2170 d->fail_timeout = jiffies +
2169 msecs_to_jiffies(delay);
2170 dbg_rcvry("failing after %ums", delay);
2171 } else {
2171 msecs_to_jiffies(delay);
2172 dbg_rcvry("failing after %ums", delay);
2173 } else {
2172 c->fail_delay = 2;
2173 c->fail_cnt_max = delay;
2174 d->fail_delay = 2;
2175 d->fail_cnt_max = delay;
2174 dbg_rcvry("failing after %u calls", delay);
2175 }
2176 }
2176 dbg_rcvry("failing after %u calls", delay);
2177 }
2178 }
2177 c->fail_cnt += 1;
2179 d->fail_cnt += 1;
2178 }
2179 /* Determine if failure delay has expired */
2180 }
2181 /* Determine if failure delay has expired */
2180 if (c->fail_delay == 1) {
2181 if (time_before(jiffies, c->fail_timeout))
2182 if (d->fail_delay == 1) {
2183 if (time_before(jiffies, d->fail_timeout))
2182 return 0;
2184 return 0;
2183 } else if (c->fail_delay == 2)
2184 if (c->fail_cnt++ < c->fail_cnt_max)
2185 } else if (d->fail_delay == 2)
2186 if (d->fail_cnt++ < d->fail_cnt_max)
2185 return 0;
2186 if (lnum == UBIFS_SB_LNUM) {
2187 if (write) {
2188 if (chance(1, 2))
2189 return 0;
2190 } else if (chance(19, 20))
2191 return 0;
2192 dbg_rcvry("failing in super block LEB %d", lnum);

--- 41 unchanged lines hidden (view full) ---

2234 return 0;
2235 dbg_rcvry("failing in bud LEB %d commit running", lnum);
2236 } else {
2237 if (chance(9999, 10000))
2238 return 0;
2239 dbg_rcvry("failing in bud LEB %d commit not running", lnum);
2240 }
2241 ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum);
2187 return 0;
2188 if (lnum == UBIFS_SB_LNUM) {
2189 if (write) {
2190 if (chance(1, 2))
2191 return 0;
2192 } else if (chance(19, 20))
2193 return 0;
2194 dbg_rcvry("failing in super block LEB %d", lnum);

--- 41 unchanged lines hidden (view full) ---

2236 return 0;
2237 dbg_rcvry("failing in bud LEB %d commit running", lnum);
2238 } else {
2239 if (chance(9999, 10000))
2240 return 0;
2241 dbg_rcvry("failing in bud LEB %d commit not running", lnum);
2242 }
2243 ubifs_err("*** SETTING FAILURE MODE ON (LEB %d) ***", lnum);
2242 c->failure_mode = 1;
2244 d->failure_mode = 1;
2243 dump_stack();
2244 return 1;
2245}
2246
2247static void cut_data(const void *buf, int len)
2248{
2249 int flen, i;
2250 unsigned char *p = (void *)buf;

--- 88 unchanged lines hidden (view full) ---

2339 err = ubi_leb_map(desc, lnum, dtype);
2340 if (err)
2341 return err;
2342 if (do_fail(desc, lnum, 0))
2343 return -EIO;
2344 return 0;
2345}
2346
2245 dump_stack();
2246 return 1;
2247}
2248
2249static void cut_data(const void *buf, int len)
2250{
2251 int flen, i;
2252 unsigned char *p = (void *)buf;

--- 88 unchanged lines hidden (view full) ---

2341 err = ubi_leb_map(desc, lnum, dtype);
2342 if (err)
2343 return err;
2344 if (do_fail(desc, lnum, 0))
2345 return -EIO;
2346 return 0;
2347}
2348
2349/**
2350 * ubifs_debugging_init - initialize UBIFS debugging.
2351 * @c: UBIFS file-system description object
2352 *
2353 * This function initializes debugging-related data for the file system.
2354 * Returns zero in case of success and a negative error code in case of
2355 * failure.
2356 */
2357int ubifs_debugging_init(struct ubifs_info *c)
2358{
2359 c->dbg = kzalloc(sizeof(struct ubifs_debug_info), GFP_KERNEL);
2360 if (!c->dbg)
2361 return -ENOMEM;
2362
2363 c->dbg->buf = vmalloc(c->leb_size);
2364 if (!c->dbg->buf)
2365 goto out;
2366
2367 failure_mode_init(c);
2368 return 0;
2369
2370out:
2371 kfree(c->dbg);
2372 return -ENOMEM;
2373}
2374
2375/**
2376 * ubifs_debugging_exit - free debugging data.
2377 * @c: UBIFS file-system description object
2378 */
2379void ubifs_debugging_exit(struct ubifs_info *c)
2380{
2381 failure_mode_exit(c);
2382 vfree(c->dbg->buf);
2383 kfree(c->dbg);
2384}
2385
2347#endif /* CONFIG_UBIFS_FS_DEBUG */
2386#endif /* CONFIG_UBIFS_FS_DEBUG */