UBIFS: fix false assertion warning in case of I/O failures
Subsystems (2)
PATCH 1/3 UBIFS: fix false assertion warning in case of I/O failures
From: Artem Bityutskiy <[email protected]>
When UBIFS switches to R/O mode because it detects I/O failures, then when we unmount, we still may have allocated budget, and the assertions which verify that we have not budget will fire. But it is expected to have the budget in case of I/O failures, so the assertion warnings will be false. Suppress them for the I/O failure case.
--- fs/ubifs/super.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/ubifs/super.c +6 -4
@@ -1773,10 +1773,12 @@ static void ubifs_put_super(struct super_block *sb)* of the media. For example, there will be dirty inodes if we failed * to write them back because of I/O errors. */ -ubifs_assert (atomic_long_read (&c->dirty_pg_cnt) ==0 ); -ubifs_assert (c->bi.idx_growth ==0 ); -ubifs_assert (c->bi.dd_growth ==0 ); -ubifs_assert (c->bi.data_growth ==0 ); +if (!c->ro_error) { +ubifs_assert (atomic_long_read (&c->dirty_pg_cnt) ==0 ); +ubifs_assert (c->bi.idx_growth ==0 ); +ubifs_assert (c->bi.dd_growth ==0 ); +ubifs_assert (c->bi.data_growth ==0 ); + }/* * The 'c->umount_lock' prevents races between UBIFS memory shrinker
Signature · 1 line
1.7.2.3
PATCH 3/3 UBIFS: use ro_mount instead of MS_RDONLY
From: Artem Bityutskiy <[email protected]>
We have our own flags indicating R/O mode, and c->ro_mode is equivalent to MS_RDONLY. Let's be consistent and use UBIFS flags everywhere. This patch is just a minor cleanup.
Additionally, add a comment that we are surprised with VFS behavior - as a reminder to look at this some day.
--- fs/ubifs/file.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
fs/ubifs/file.c +5 -1
@@ -1312,7 +1312,11 @@ int ubifs_fsync(struct file *file, int datasync)dbg_gen ("syncing inode %lu" , inode->i_ino); -if (inode->i_sb->s_flags &MS_RDONLY ) +if (c->ro_mount) +/* +* For some really strange reasons VFS does not filter out +* 'fsync()' for R/O mounted file-systems as per 2.6.39. +*/ return 0 ;/*
Signature · 1 line
1.7.2.3
PATCH 2/3 UBIFS: fix master node recovery
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
This patch fixes the following symptoms:
1. Unmount UBIFS cleanly.
2. Start mounting UBIFS R/W and have a power cut immediately
3. Start mounting UBIFS R/O, this succeeds
4. Try to re-mount UBIFS R/W - this fails immediately or later on, because UBIFS will write the master node to the flash area which has been written before.
The analysis of the problem:
1. UBIFS is unmounted cleanly, both copies of the master node are clean.
2. UBIFS is being mounter R/W, starts changing master node copy 1, and a power cut happens. The copy N1 becomes corrupted.
3. UBIFS is being mounted R/O. It notices the copy N1 is corrupted and reads copy N2. Copy N2 is clean.
4. Because of R/O mode, UBIFS cannot recover copy 1.
5. The mount code (ubifs_mount()) sees that the master node is clean, so it decides that no recovery is needed.
6. We are re-mounting R/W. UBIFS believes no recovery is needed and starts updating the master node, but copy N1 is still corrupted and was not recovered!
Fix this problem by marking the master node as dirty every time we recover it and we are in R/O mode. This forces further recovery and the UBIFS cleans-up the corruptions and recovers the copy N1 when re-mounting R/W later.
--- fs/ubifs/recovery.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
fs/ubifs/recovery.c +26 -0
@@ -317,6 +317,32 @@ int ubifs_recover_master_node(struct ubifs_info *c) goto out_free; }memcpy (c->rcvrd_mst_node, c->mst_node,UBIFS_MST_NODE_SZ ); + +/* +* We had to recover the master node, which means there was an +* unclean reboot. However, it is possible that the master node +* is clean at this point, i.e., %UBIFS_MST_DIRTY is not set. +* E.g., consider the following chain of events: +* +* 1. UBIFS was cleanly unmounted, so the master node is clean +* 2. UBIFS is being mounted R/W and starts changing the master +* node in the first (%UBIFS_MST_LNUM). A power cut happens, +* so this LEB ends up with some amount of garbage at the +* end. +* 3. UBIFS is being mounted R/O. We reach this place and +* recover the master node from the second LEB +* (%UBIFS_MST_LNUM + 1). But we cannot update the media +* because we are being mounted R/O. We have to defer the +* operation. +* 4. However, this master node (@c->mst_node) is marked as +* clean (since the step 1). And if we just return, the +* mount code will be confused and won't recover the master +* node when it is re-mounter R/W later. +* +* Thus, to force the recovery by marking the master node as +* dirty. +*/ + c->mst_node->flags |=cpu_to_le32 (UBIFS_MST_DIRTY ); }else {/* Write the recovered master node */ c->max_sqnum =le64_to_cpu (mst->ch.sqnum) -1 ;
Signature · 1 line
1.7.2.3