Skip to content

Commit 2e52eb7

Browse files
ubifs: Rework ubifs_assert()
With having access to struct ubifs_info in ubifs_assert() we can give more information when an assert is failing. By using ubifs_err() we can tell which UBIFS instance failed. Also multiple actions can be taken now. We support: - report: This is what UBIFS did so far, just report the failure and go on. - read-only: Switch to read-only mode. - panic: shoot the kernel in the head. Signed-off-by: Richard Weinberger <[email protected]>
1 parent 6eb61d5 commit 2e52eb7

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

fs/ubifs/debug.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,6 +3081,28 @@ void dbg_debugfs_exit(void)
30813081
debugfs_remove_recursive(dfs_rootdir);
30823082
}
30833083

3084+
void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
3085+
const char *file, int line)
3086+
{
3087+
ubifs_err(c, "UBIFS assert failed: %s, in %s:%u", expr, file, line);
3088+
3089+
switch (c->assert_action) {
3090+
case ASSACT_PANIC:
3091+
BUG();
3092+
break;
3093+
3094+
case ASSACT_RO:
3095+
ubifs_ro_mode(c, -EINVAL);
3096+
break;
3097+
3098+
case ASSACT_REPORT:
3099+
default:
3100+
dump_stack();
3101+
break;
3102+
3103+
}
3104+
}
3105+
30843106
/**
30853107
* ubifs_debugging_init - initialize UBIFS debugging.
30863108
* @c: UBIFS file-system description object

fs/ubifs/debug.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,20 @@ struct ubifs_global_debug_info {
148148
unsigned int tst_rcvry:1;
149149
};
150150

151+
void ubifs_assert_failed(struct ubifs_info *c, const char *expr,
152+
const char *file, int line);
153+
151154
#define ubifs_assert(c, expr) do { \
152155
if (unlikely(!(expr))) { \
153-
pr_crit("UBIFS assert failed in %s at %u (pid %d)\n", \
154-
__func__, __LINE__, current->pid); \
155-
dump_stack(); \
156+
ubifs_assert_failed((struct ubifs_info *)c, #expr, __FILE__, \
157+
__LINE__); \
156158
} \
157159
} while (0)
158160

159161
#define ubifs_assert_cmt_locked(c) do { \
160162
if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
161163
up_write(&(c)->commit_sem); \
162-
pr_crit("commit lock is not locked!\n"); \
164+
ubifs_err(c, "commit lock is not locked!\n"); \
163165
ubifs_assert(c, 0); \
164166
} \
165167
} while (0)

fs/ubifs/ubifs.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ enum {
258258
LEB_RETAINED,
259259
};
260260

261+
/*
262+
* Action taken upon a failed ubifs_assert().
263+
* @ASSACT_REPORT: just report the failed assertion
264+
* @ASSACT_RO: switch to read-only mode
265+
* @ASSACT_PANIC: call BUG() and possible panic the kernel
266+
*/
267+
enum {
268+
ASSACT_REPORT = 0,
269+
ASSACT_RO,
270+
ASSACT_PANIC,
271+
};
272+
261273
/**
262274
* struct ubifs_old_idx - index node obsoleted since last commit start.
263275
* @rb: rb-tree node
@@ -1015,6 +1027,7 @@ struct ubifs_debug_info;
10151027
* @bulk_read: enable bulk-reads
10161028
* @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
10171029
* @rw_incompat: the media is not R/W compatible
1030+
* @assert_action: action to take when a ubifs_assert() fails
10181031
*
10191032
* @tnc_mutex: protects the Tree Node Cache (TNC), @zroot, @cnext, @enext, and
10201033
* @calc_idx_sz
@@ -1256,6 +1269,7 @@ struct ubifs_info {
12561269
unsigned int bulk_read:1;
12571270
unsigned int default_compr:2;
12581271
unsigned int rw_incompat:1;
1272+
unsigned int assert_action:2;
12591273

12601274
struct mutex tnc_mutex;
12611275
struct ubifs_zbranch zroot;

0 commit comments

Comments
 (0)