Skip to content

Commit

Permalink
UBIFS: add debugfs knob to switch to R/O mode
Browse files Browse the repository at this point in the history
This patch adds another debugfs knob which switches UBIFS to R/O mode.
I needed it while trying to reproduce the 'first log node is not CS node'
bug. Without this debugfs knob you have to perform a power cut to repruduce
the bug. The knob is named 'ro_error' and all it does is it sets the
'ro_error' UBIFS flag which makes UBIFS disallow any further writes - even
write-back will fail with -EROFS. Useful for debugging.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
  • Loading branch information
Artem Bityutskiy committed Jul 20, 2012
1 parent 782759b commit 06bef94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/ubifs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,8 @@ static ssize_t dfs_file_read(struct file *file, char __user *u, size_t count,
val = d->chk_fs;
else if (dent == d->dfs_tst_rcvry)
val = d->tst_rcvry;
else if (dent == d->dfs_ro_error)
val = c->ro_error;
else
return -EINVAL;

Expand Down Expand Up @@ -2885,6 +2887,8 @@ static ssize_t dfs_file_write(struct file *file, const char __user *u,
d->chk_fs = val;
else if (dent == d->dfs_tst_rcvry)
d->tst_rcvry = val;
else if (dent == d->dfs_ro_error)
c->ro_error = !!val;
else
return -EINVAL;

Expand Down Expand Up @@ -2996,6 +3000,13 @@ int dbg_debugfs_init_fs(struct ubifs_info *c)
goto out_remove;
d->dfs_tst_rcvry = dent;

fname = "ro_error";
dent = debugfs_create_file(fname, S_IRUSR | S_IWUSR, d->dfs_dir, c,
&dfs_fops);
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_ro_error = dent;

return 0;

out_remove:
Expand Down
5 changes: 5 additions & 0 deletions fs/ubifs/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ typedef int (*dbg_znode_callback)(struct ubifs_info *c,
* @dfs_chk_lprops: debugfs knob to enable UBIFS LEP properties extra checks
* @dfs_chk_fs: debugfs knob to enable UBIFS contents extra checks
* @dfs_tst_rcvry: debugfs knob to enable UBIFS recovery testing
* @dfs_ro_error: debugfs knob to switch UBIFS to R/O mode (different to
* re-mounting to R/O mode because it does not flush any buffers
* and UBIFS just starts returning -EROFS on all write
* operations)
*/
struct ubifs_debug_info {
struct ubifs_zbranch old_zroot;
Expand Down Expand Up @@ -122,6 +126,7 @@ struct ubifs_debug_info {
struct dentry *dfs_chk_lprops;
struct dentry *dfs_chk_fs;
struct dentry *dfs_tst_rcvry;
struct dentry *dfs_ro_error;
};

/**
Expand Down

0 comments on commit 06bef94

Please sign in to comment.