[RESEND PATCH] Fix sysrq emergency thaw

2016-09-02 Thread Charles Gong
"SYSRQ + J" triggers a call to emergency_thaw_all(). Currently, this
is an infinite loop. Once we trigger it, we'll need to do a hard
power-cycle. There are users reporting this bug from 2012 to 2016, for
example, at https://bugzilla.kernel.org/show_bug.cgi?id=47741.

This happens because thaw_bdev() fails to return -EINVAL in the
non-frozen case, so fix it so that do_one_thaw() can recognize this case
and quit from looping. I checked that none of the other thaw_bdev()
callers check the return value.

The regression was introduced in commit 4504230a7156 ("freeze_bdev: grab
active reference to frozen superblocks").

Reviewed-by: Chris Mason 
Acked-by: Pavel Machek 
Signed-off-by: Charles Gong 
---
 fs/block_dev.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 71ccab1..14f015e 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -301,14 +301,12 @@ int thaw_bdev(struct block_device *bdev, struct 
super_block *sb)
error = sb->s_op->thaw_super(sb);
else
error = thaw_super(sb);
-   if (error) {
+   if (error)
bdev->bd_fsfreeze_count++;
-   mutex_unlock(>bd_fsfreeze_mutex);
-   return error;
-   }
+
 out:
mutex_unlock(>bd_fsfreeze_mutex);
-   return 0;
+   return error;
 }
 EXPORT_SYMBOL(thaw_bdev);
 
-- 
2.8.0.rc2



[RESEND PATCH] Fix sysrq emergency thaw

2016-09-02 Thread Charles Gong
"SYSRQ + J" triggers a call to emergency_thaw_all(). Currently, this
is an infinite loop. Once we trigger it, we'll need to do a hard
power-cycle. There are users reporting this bug from 2012 to 2016, for
example, at https://bugzilla.kernel.org/show_bug.cgi?id=47741.

This happens because thaw_bdev() fails to return -EINVAL in the
non-frozen case, so fix it so that do_one_thaw() can recognize this case
and quit from looping. I checked that none of the other thaw_bdev()
callers check the return value.

The regression was introduced in commit 4504230a7156 ("freeze_bdev: grab
active reference to frozen superblocks").

Reviewed-by: Chris Mason 
Acked-by: Pavel Machek 
Signed-off-by: Charles Gong 
---
 fs/block_dev.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 71ccab1..14f015e 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -301,14 +301,12 @@ int thaw_bdev(struct block_device *bdev, struct 
super_block *sb)
error = sb->s_op->thaw_super(sb);
else
error = thaw_super(sb);
-   if (error) {
+   if (error)
bdev->bd_fsfreeze_count++;
-   mutex_unlock(>bd_fsfreeze_mutex);
-   return error;
-   }
+
 out:
mutex_unlock(>bd_fsfreeze_mutex);
-   return 0;
+   return error;
 }
 EXPORT_SYMBOL(thaw_bdev);
 
-- 
2.8.0.rc2