akpm at linux-foundation.org
2015-Aug-26 22:11 UTC
[Ocfs2-devel] [patch 01/28] ocfs2: set filesytem read-only when ocfs2_delete_entry failed.
From: jiangyiwen <jiangyiwen at huawei.com>
Subject: ocfs2: set filesytem read-only when ocfs2_delete_entry failed.
In ocfs2_rename, it will lead to an inode with two entried(old and new) if
ocfs2_delete_entry(old) failed. Thus, filesystem will be inconsistent.
The case is described below:
ocfs2_rename
-> ocfs2_start_trans
-> ocfs2_add_entry(new)
-> ocfs2_delete_entry(old)
-> __ocfs2_journal_access *failed* because of -ENOMEM
-> ocfs2_commit_trans
So filesystem should be set to read-only at the moment.
Signed-off-by: Yiwen Jiang <jiangyiwen at huawei.com>
Cc: Joseph Qi <joseph.qi at huawei.com>
Cc: Joel Becker <jlbec at evilplan.org>
Cc: Mark Fasheh <mfasheh at suse.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
---
fs/ocfs2/namei.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff -puN
fs/ocfs2/namei.c~ocfs2-set-filesytem-read-only-when-ocfs2_delete_entry-failed
fs/ocfs2/namei.c
---
a/fs/ocfs2/namei.c~ocfs2-set-filesytem-read-only-when-ocfs2_delete_entry-failed
+++ a/fs/ocfs2/namei.c
@@ -1544,12 +1544,25 @@ static int ocfs2_rename(struct inode *ol
status = ocfs2_find_entry(old_dentry->d_name.name,
old_dentry->d_name.len, old_dir,
&old_entry_lookup);
- if (status)
+ if (status) {
+ if (!is_journal_aborted(osb->journal->j_journal)) {
+ ocfs2_error(osb->sb, "new entry %.*s is added, but old entry %.*s
"
+ "is not deleted.",
+ new_dentry->d_name.len, new_dentry->d_name.name,
+ old_dentry->d_name.len, old_dentry->d_name.name);
+ }
goto bail;
+ }
status = ocfs2_delete_entry(handle, old_dir, &old_entry_lookup);
if (status < 0) {
mlog_errno(status);
+ if (!is_journal_aborted(osb->journal->j_journal)) {
+ ocfs2_error(osb->sb, "new entry %.*s is added, but old entry %.*s
"
+ "is not deleted.",
+ new_dentry->d_name.len, new_dentry->d_name.name,
+ old_dentry->d_name.len, old_dentry->d_name.name);
+ }
goto bail;
}
_
Mark Fasheh
2015-Aug-28 23:03 UTC
[Ocfs2-devel] [patch 01/28] ocfs2: set filesytem read-only when ocfs2_delete_entry failed.
On Wed, Aug 26, 2015 at 03:11:21PM -0700, Andrew Morton wrote:> From: jiangyiwen <jiangyiwen at huawei.com> > Subject: ocfs2: set filesytem read-only when ocfs2_delete_entry failed. > > In ocfs2_rename, it will lead to an inode with two entried(old and new) if > ocfs2_delete_entry(old) failed. Thus, filesystem will be inconsistent. > > The case is described below: > > ocfs2_rename > -> ocfs2_start_trans > -> ocfs2_add_entry(new) > -> ocfs2_delete_entry(old) > -> __ocfs2_journal_access *failed* because of -ENOMEM > -> ocfs2_commit_trans > > So filesystem should be set to read-only at the moment. > > Signed-off-by: Yiwen Jiang <jiangyiwen at huawei.com> > Cc: Joseph Qi <joseph.qi at huawei.com> > Cc: Joel Becker <jlbec at evilplan.org> > Cc: Mark Fasheh <mfasheh at suse.com> > Signed-off-by: Andrew Morton <akpm at linux-foundation.org>Reviewed-by: Mark Fasheh <mfasheh at suse.de> -- Mark Fasheh