gfs2: misc withdraw patch fixes
cover gfs2: misc withdraw patch fixes
Hi,
Further recovery testing revealed some problems with the withdraw code, especially related to single-node (lock_nolock) withdraws. This patch set fixes some of the recent issues.
Bob Peterson (4):
gfs2: fix withdraw sequence deadlock
gfs2: Fix error exit in do_xmote
gfs2: Fix BUG during unmount after file system withdraw
gfs2: Fix use-after-free in gfs2_logd after withdraw
fs/gfs2/glock.c | 2 +- fs/gfs2/log.c | 5 +++++ fs/gfs2/meta_io.c | 2 +- fs/gfs2/util.c | 10 ++++++---- 4 files changed, 13 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/4 gfs2: fix withdraw sequence deadlock
After a gfs2 file system withdraw, any attempt to read metadata is automatically rejected by function gfs2_meta_read() except for reads of the journal inode. This turns out to be a problem because function signal_our_withdraw() repeatedly calls check_journal_clean() which reads the metadata (both its dinode and indirect blocks) to see if the entire journal is mapped. The dinode read works, but reading the indirect blocks returns -EIO which gets sent back up and causes a consistency error. This results in withdraw-from-withdraw, which becomes a deadlock.
This patch changes the test in gfs2_meta_read() to allow all metadata reads for the journal. Instead of checking the journal block, it now checks for the journal inode glock which is the same for all blocks in the journal. This allows check_journal_clean() to properly check the journal without trying to withdraw recursively.
--- fs/gfs2/meta_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/meta_io.c +1 -1
@@ -252,7 +252,7 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,int num =0 ;if (unlikely (gfs2_withdrawn (sdp)) && - (!sdp->sd_jdesc || (blkno != sdp->sd_jdesc->jd_no_addr))) { + (!sdp->sd_jdesc || gl != sdp->sd_jinode_gl)) { *bhp =NULL ;return -EIO ; }
Signature · 1 line
2.25.1
PATCH 2/4 gfs2: Fix error exit in do_xmote
In reply to Bob PetersonBefore this patch , if an error was detected from glock function go_sync by function do_xmote, it would return. But the function had temporarily unlocked the gl_lockref spin_lock, and it never re-locked it. When the caller of do_xmote tried to unlock it again, it was already unlocked, which resulted in a corrupted spin_lock value.
This patch changes the "return" to "goto out" so the spin_lock gets proper re-locked upon exit.
--- fs/gfs2/glock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/glock.c +1 -1
@@ -613,7 +613,7 @@ __acquires(&gl->gl_lockref.lock)fs_err (sdp,"Error %d syncing glock \n" , ret);gfs2_dump_glock (NULL , gl, true); } -return ; + goto out; } }if (test_bit (GLF_INVALIDATE_IN_PROGRESS , &gl->gl_flags)) {
Signature · 1 line
2.25.1
PATCH 3/4 gfs2: Fix BUG during unmount after file system withdraw
In reply to Bob PetersonBefore this patch, when the logd daemon was forced to withdraw, it would try to request its journal be recovered by another cluster node. However, in single-user cases with lock_nolock, there are no other nodes to recover the journal. Function signal_our_withdraw() was recognizing the lock_nolock situation, but not until after it had evicted its journal inode. Since the journal descriptor that points to the inode was never removed from the master list, when the unmount occurred, it did another iput on the evicted inode, which resulted in a BUG from fs/inode.c (BUG_ON(inode->i_state & I_CLEAR);).
This patch moves the check for this situation earlier in function signal_our_withdraw(), which avoids the extra iput, so the unmount may happen normally.
--- fs/gfs2/util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/gfs2/util.c +6 -4
@@ -119,6 +119,12 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp)if (!sb_rdonly (sdp->sd_vfs)) ret =gfs2_make_fs_ro (sdp); +if (sdp->sd_lockstruct.ls_ops->lm_lock ==NULL ) {/* lock_nolock */ +if (!ret) + ret = -EIO ; +clear_bit (SDF_WITHDRAW_RECOVERY , &sdp->sd_flags); + goto skip_recovery; + }/* * Drop the glock for our journal so another node can recover it. */
@@ -159,10 +165,6 @@ static void signal_our_withdraw(struct gfs2_sbd *sdp)wait_on_bit (&gl->gl_flags,GLF_FREEING ,TASK_UNINTERRUPTIBLE ); } -if (sdp->sd_lockstruct.ls_ops->lm_lock ==NULL ) {/* lock_nolock */ -clear_bit (SDF_WITHDRAW_RECOVERY , &sdp->sd_flags); - goto skip_recovery; - }/* * Dequeue the "live" glock, but keep a reference so it's never freed. */
Signature · 1 line
2.25.1
PATCH 4/4 gfs2: Fix use-after-free in gfs2_logd after withdraw
In reply to Bob PetersonWhen the gfs2_logd daemon withdrew, the withdraw sequence called into make_fs_ro() to make the file system read-only. That caused the journal descriptors to be freed. However, those journal descriptors were used by gfs2_logd's call to gfs2_ail_flush_reqd(). This caused a use-after free and NULL pointer dereference.
This patch changes function gfs2_logd() so that it stops all logd work until the thread is told to stop. Once a withdraw is done, it only does an interruptible sleep.
--- fs/gfs2/log.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/gfs2/log.c +5 -0
@@ -1131,6 +1131,10 @@ int gfs2_logd(void *data)while (!kthread_should_stop ()) { +if (gfs2_withdrawn (sdp)) { +msleep_interruptible (HZ ); +continue ; + }/* Check for errors writing to the journal */ if (sdp->sd_log_error) { gfs2_lm(sdp,
@@ -1139,6 +1143,7 @@ int gfs2_logd(void *data)"prevent further damage.\n" , sdp->sd_fsname, sdp->sd_log_error);gfs2_withdraw (sdp); +continue ; } did_flush = false;
Signature · 1 line
2.25.1
cover gfs2: misc withdraw patch fixes
In reply to Bob PetersonQuoted 12 lines · Bob Peterson
Hi,
Further recovery testing revealed some problems with the withdraw code, especially related to single-node (
lock_nolock) withdraws. This patch set fixes some of the recent issues.Bob Peterson (4):
gfs2: fix withdraw sequence deadlock
gfs2: Fix error exit indo_xmote
gfs2: Fix BUG during unmount after file system withdraw
gfs2: Fix use-after-free ingfs2_logdafter withdraw
Quoted 6 lines
fs/gfs2/glock.c | 2 +- fs/gfs2/log.c | 5 +++++ fs/gfs2/meta_io.c | 2 +- fs/gfs2/util.c | 10 ++++++---- 4 files changed, 13 insertions(+), 6 deletions(-)
This patch series fixes the issue I reported last week regarding the BUG during unmount and my testcase now passes.
Thanks!
Signature · 1 line
Ross Lagerwall