@@ -705,7 +705,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
705705
706706 printk (KERN_DEBUG "(pid %d) Dumping LEB %d\n" , current -> pid , lnum );
707707
708- sleb = ubifs_scan (c , lnum , 0 , c -> dbg_buf );
708+ sleb = ubifs_scan (c , lnum , 0 , c -> dbg -> buf );
709709 if (IS_ERR (sleb )) {
710710 ubifs_err ("scan error %d" , (int )PTR_ERR (sleb ));
711711 return ;
@@ -2097,7 +2097,7 @@ static int simple_rand(void)
20972097 return (next >> 16 ) & 32767 ;
20982098}
20992099
2100- void dbg_failure_mode_registration (struct ubifs_info * c )
2100+ static void failure_mode_init (struct ubifs_info * c )
21012101{
21022102 struct failure_mode_info * fmi ;
21032103
@@ -2112,7 +2112,7 @@ void dbg_failure_mode_registration(struct ubifs_info *c)
21122112 spin_unlock (& fmi_lock );
21132113}
21142114
2115- void dbg_failure_mode_deregistration (struct ubifs_info * c )
2115+ static void failure_mode_exit (struct ubifs_info * c )
21162116{
21172117 struct failure_mode_info * fmi , * tmp ;
21182118
@@ -2146,42 +2146,44 @@ static int in_failure_mode(struct ubi_volume_desc *desc)
21462146 struct ubifs_info * c = dbg_find_info (desc );
21472147
21482148 if (c && dbg_failure_mode )
2149- return c -> failure_mode ;
2149+ return c -> dbg -> failure_mode ;
21502150 return 0 ;
21512151}
21522152
21532153static int do_fail (struct ubi_volume_desc * desc , int lnum , int write )
21542154{
21552155 struct ubifs_info * c = dbg_find_info (desc );
2156+ struct ubifs_debug_info * d ;
21562157
21572158 if (!c || !dbg_failure_mode )
21582159 return 0 ;
2159- if (c -> failure_mode )
2160+ d = c -> dbg ;
2161+ if (d -> failure_mode )
21602162 return 1 ;
2161- if (!c -> fail_cnt ) {
2163+ if (!d -> fail_cnt ) {
21622164 /* First call - decide delay to failure */
21632165 if (chance (1 , 2 )) {
21642166 unsigned int delay = 1 << (simple_rand () >> 11 );
21652167
21662168 if (chance (1 , 2 )) {
2167- c -> fail_delay = 1 ;
2168- c -> fail_timeout = jiffies +
2169+ d -> fail_delay = 1 ;
2170+ d -> fail_timeout = jiffies +
21692171 msecs_to_jiffies (delay );
21702172 dbg_rcvry ("failing after %ums" , delay );
21712173 } else {
2172- c -> fail_delay = 2 ;
2173- c -> fail_cnt_max = delay ;
2174+ d -> fail_delay = 2 ;
2175+ d -> fail_cnt_max = delay ;
21742176 dbg_rcvry ("failing after %u calls" , delay );
21752177 }
21762178 }
2177- c -> fail_cnt += 1 ;
2179+ d -> fail_cnt += 1 ;
21782180 }
21792181 /* 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 ))
21822184 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 )
21852187 return 0 ;
21862188 if (lnum == UBIFS_SB_LNUM ) {
21872189 if (write ) {
@@ -2239,7 +2241,7 @@ static int do_fail(struct ubi_volume_desc *desc, int lnum, int write)
22392241 dbg_rcvry ("failing in bud LEB %d commit not running" , lnum );
22402242 }
22412243 ubifs_err ("*** SETTING FAILURE MODE ON (LEB %d) ***" , lnum );
2242- c -> failure_mode = 1 ;
2244+ d -> failure_mode = 1 ;
22432245 dump_stack ();
22442246 return 1 ;
22452247}
@@ -2344,4 +2346,41 @@ int dbg_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
23442346 return 0 ;
23452347}
23462348
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+ */
2357+ int 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+
2370+ out :
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+ */
2379+ void ubifs_debugging_exit (struct ubifs_info * c )
2380+ {
2381+ failure_mode_exit (c );
2382+ vfree (c -> dbg -> buf );
2383+ kfree (c -> dbg );
2384+ }
2385+
23472386#endif /* CONFIG_UBIFS_FS_DEBUG */
0 commit comments