gfs2: Don't withdraw under a spin lock
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Don't withdraw under a spin lock
In two places, the gfs2_io_error_bh macro is called while holding the sd_ail_lock spin lock. This isn't allowed because gfs2_io_error_bh withdraws the filesystem, which can sleep because it issues a uevent. To fix that, add a __gfs2_io_error_bh macro that doesn't withdraw the filesystem, and withdraw the filesystem after releasing sd_ail_lock where necessary.
--- fs/gfs2/log.c | 30 +++++++++++++++++++++--------- fs/gfs2/util.c | 38 ++++++++++++++++++++------------------ fs/gfs2/util.h | 10 +++++++--- 3 files changed, 48 insertions(+), 30 deletions(-)
fs/gfs2/log.c +21 -9
@@ -92,7 +92,8 @@ static void gfs2_remove_from_ail(struct gfs2_bufdata *bd)static int gfs2_ail1_start_one (struct gfs2_sbd *sdp,struct writeback_control *wbc, -struct gfs2_trans *tr) +struct gfs2_trans *tr, +bool *withdraw) __releases(&sdp->sd_ail_lock) __acquires(&sdp->sd_ail_lock) {
@@ -107,8 +108,10 @@ __acquires(&sdp->sd_ail_lock)gfs2_assert (sdp, bd->bd_tr == tr);if (!buffer_busy (bh)) { -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list);continue ; }
@@ -148,6 +151,7 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)struct list_head *head = &sdp->sd_ail1_list;struct gfs2_trans *tr;struct blk_plug plug; +bool withdraw = false;trace_gfs2_ail_flush (sdp, wbc,1 );blk_start_plug (&plug);
@@ -156,11 +160,13 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)list_for_each_entry_reverse (tr, head, tr_list) {if (wbc->nr_to_write <=0 )break ; -if (gfs2_ail1_start_one (sdp, wbc, tr)) +if (gfs2_ail1_start_one (sdp, wbc, tr, &withdraw)) goto restart; }spin_unlock (&sdp->sd_ail_lock);blk_finish_plug (&plug); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL );trace_gfs2_ail_flush (sdp, wbc,0 ); }
@@ -188,7 +194,8 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)* */ -static void gfs2_ail1_empty_one (struct gfs2_sbd *sdp,struct gfs2_trans *tr) +static void gfs2_ail1_empty_one (struct gfs2_sbd *sdp,struct gfs2_trans *tr, +bool *withdraw) {struct gfs2_bufdata *bd, *s;struct buffer_head *bh;
@@ -199,11 +206,12 @@ static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)gfs2_assert (sdp, bd->bd_tr == tr);if (buffer_busy (bh))continue ; -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list); } - }/**
@@ -218,10 +226,11 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp)struct gfs2_trans *tr, *s;int oldest_tr =1 ;int ret; +bool withdraw = false;spin_lock (&sdp->sd_ail_lock);list_for_each_entry_safe_reverse (tr, s, &sdp->sd_ail1_list, tr_list) { -gfs2_ail1_empty_one (sdp, tr); +gfs2_ail1_empty_one (sdp, tr, &withdraw);if (list_empty (&tr->tr_ail1_list) && oldest_tr)list_move (&tr->tr_list, &sdp->sd_ail2_list);else
@@ -230,6 +239,9 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp) ret =list_empty (&sdp->sd_ail1_list);spin_unlock (&sdp->sd_ail_lock); +if (withdraw) +gfs2_lm_withdraw (sdp,"fatal: I/O error(s)\n" ); +return ret; }
fs/gfs2/util.c +20 -18
@@ -46,14 +46,16 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...) test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))return 0 ; -va_start (args, fmt); +if (fmt) { +va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; + vaf.fmt = fmt; + vaf.va = &args; -fs_err (sdp,"%pV" , &vaf); +fs_err (sdp,"%pV" , &vaf); -va_end (args); +va_end (args); + }if (sdp->sd_args.ar_errors ==GFS2_ERRORS_WITHDRAW ) {fs_err (sdp,"about to withdraw this file system\n" );
@@ -246,21 +248,21 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, }/** -* gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw -* Returns: -1 if this call withdrew the machine, -* 0 if it was already withdrawn +* gfs2_io_error_bh_i - Flag a buffer I/O error +* @withdraw: withdraw the filesystem */ -int gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *function,char *file,unsigned int line) +void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, +const char *function,char *file,unsigned int line, +bool withdraw) { -int rv; - rv =gfs2_lm_withdraw (sdp, -"fatal: I/O error\n" -" block = %llu\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, - function, file, line); -return rv; +fs_err (sdp, +"fatal: I/O error\n" +" block = %llu\n" +" function = %s, file = %s, line = %u\n" , + (unsigned long long )bh->b_blocknr, + function, file, line); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL ); }
fs/gfs2/util.h +7 -3
@@ -136,11 +136,15 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,gfs2_io_error_i ((sdp), __func__, __FILE__, __LINE__); -int gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *function,char *file,unsigned int line); +void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, +const char *function,char *file,unsigned int line, +bool withdraw);#define gfs2_io_error_bh (sdp, bh) \ -gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__); +gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true); + +#define __gfs2_io_error_bh (sdp, bh) \ +gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);extern struct kmem_cache *gfs2_glock_cachep;
Signature · 1 line
2.17.0
PATCH 1/1 gfs2: Don't withdraw under a spin lock
Quoted 184 lines · Andreas Gruenbacher
In two places, the
gfs2_io_error_bhmacro is called while holding thesd_ail_lockspin lock. This isn't allowed becausegfs2_io_error_bhwithdraws the filesystem, which can sleep because it issues a uevent. To fix that, add a__gfs2_io_error_bhmacro that doesn't withdraw the filesystem, and withdraw the filesystem after releasingsd_ail_lockwhere necessary.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/gfs2/log.c | 30 +++++++++++++++++++++--------- fs/gfs2/util.c | 38 ++++++++++++++++++++------------------ fs/gfs2/util.h | 10 +++++++--- 3 files changed, 48 insertions(+), 30 deletions(-)fs/gfs2/log.c +21
-9@@ -92,7 +92,8 @@ static void gfs2_remove_from_ail(struct gfs2_bufdata *bd)static int gfs2_ail1_start_one (struct gfs2_sbd *sdp,struct writeback_control *wbc, -struct gfs2_trans *tr) +struct gfs2_trans *tr, +bool *withdraw) __releases(&sdp->sd_ail_lock) __acquires(&sdp->sd_ail_lock) {@@ -107,8 +108,10 @@ __acquires(&sdp->sd_ail_lock)gfs2_assert (sdp, bd->bd_tr == tr);if (!buffer_busy (bh)) { -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list);continue ; }@@ -148,6 +151,7 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)struct list_head *head = &sdp->sd_ail1_list;struct gfs2_trans *tr;struct blk_plug plug; +bool withdraw = false;trace_gfs2_ail_flush (sdp, wbc,1 );blk_start_plug (&plug);@@ -156,11 +160,13 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)list_for_each_entry_reverse (tr, head, tr_list) {if (wbc->nr_to_write <=0 )break ; -if (gfs2_ail1_start_one (sdp, wbc, tr)) +if (gfs2_ail1_start_one (sdp, wbc, tr, &withdraw)) goto restart; }spin_unlock (&sdp->sd_ail_lock);blk_finish_plug (&plug); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL );trace_gfs2_ail_flush (sdp, wbc,0 ); }@@ -188,7 +194,8 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)* */ -static void gfs2_ail1_empty_one (struct gfs2_sbd *sdp,struct gfs2_trans *tr) +static void gfs2_ail1_empty_one (struct gfs2_sbd *sdp,struct gfs2_trans *tr, +bool *withdraw) {struct gfs2_bufdata *bd, *s;struct buffer_head *bh;@@ -199,11 +206,12 @@ static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)gfs2_assert (sdp, bd->bd_tr == tr);if (buffer_busy (bh))continue ; -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list); } - }/** @@ -218,10 +226,11 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp)struct gfs2_trans *tr, *s;int oldest_tr =1 ;int ret; +bool withdraw = false;spin_lock (&sdp->sd_ail_lock);list_for_each_entry_safe_reverse (tr, s, &sdp->sd_ail1_list, tr_list) { -gfs2_ail1_empty_one (sdp, tr); +gfs2_ail1_empty_one (sdp, tr, &withdraw);if (list_empty (&tr->tr_ail1_list) && oldest_tr)list_move (&tr->tr_list, &sdp->sd_ail2_list);else @@ -230,6 +239,9 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp) ret =list_empty (&sdp->sd_ail1_list);spin_unlock (&sdp->sd_ail_lock); +if (withdraw) +gfs2_lm_withdraw (sdp,"fatal: I/O error(s)\n" ); +return ret; }fs/gfs2/util.c +20
-18@@ -46,14 +46,16 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...) test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))return 0 ; -va_start (args, fmt); +if (fmt) { +va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; + vaf.fmt = fmt; + vaf.va = &args; -fs_err (sdp,"%pV" , &vaf); +fs_err (sdp,"%pV" , &vaf); -va_end (args); +va_end (args); + }if (sdp->sd_args.ar_errors ==GFS2_ERRORS_WITHDRAW ) {fs_err (sdp,"about to withdraw this file system\n" );@@ -246,21 +248,21 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, }/** -* gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw -* Returns: -1 if this call withdrew the machine, -* 0 if it was already withdrawn +* gfs2_io_error_bh_i - Flag a buffer I/O error +* @withdraw: withdraw the filesystem */ -int gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *function,char *file,unsigned int line) +void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, +const char *function,char *file,unsigned int line, +bool withdraw) { -int rv; - rv =gfs2_lm_withdraw (sdp, -"fatal: I/O error\n" -" block = %llu\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, - function, file, line); -return rv; +fs_err (sdp, +"fatal: I/O error\n" +" block = %llu\n" +" function = %s, file = %s, line = %u\n" , + (unsigned long long )bh->b_blocknr, + function, file, line); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL ); }fs/gfs2/util.h +0
-2@@ -136,11 +136,15 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,gfs2_io_error_i ((sdp), __func__, __FILE__, __LINE__); -int gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, -const char *function,char *file,unsigned int line);
fs/gfs2/util.h int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, · line 147
Quoted 10 lines
fs/gfs2/util.h +7
-1+void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, +const char *function,char *file,unsigned int line, +bool withdraw);#define gfs2_io_error_bh (sdp, bh) \ -gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__); +gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, true); + +#define __gfs2_io_error_bh (sdp, bh) \ +gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);
Perhaps these could be named something like gfs2_io_error_bh_wd and gfs2_io_error_bh to indicate the difference.
Otherwise, this looks good to me.
Andy
Quoted 4 lines
fs/gfs2/util.h +0
-0extern struct kmem_cache *gfs2_glock_cachep;
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Don't withdraw under a spin lock
Quoted 186 lines · Andrew Price
Quoted 185 lines · Andreas Gruenbacher
In two places, the
gfs2_io_error_bhmacro is called while holding thesd_ail_lockspin lock. This isn't allowed becausegfs2_io_error_bhwithdraws the filesystem, which can sleep because it issues a uevent. To fix that, add a__gfs2_io_error_bhmacro that doesn't withdraw the filesystem, and withdraw the filesystem after releasingsd_ail_lockwhere necessary.Signed-off-by Andreas Gruenbacher <[email protected]>--- fs/gfs2/log.c | 30 +++++++++++++++++++++--------- fs/gfs2/util.c | 38 ++++++++++++++++++++------------------ fs/gfs2/util.h | 10 +++++++--- 3 files changed, 48 insertions(+), 30 deletions(-)fs/gfs2/log.c +10
-4@@ -92,7 +92,8 @@ static void gfs2_remove_from_ail(struct gfs2_bufdata *bd)static int gfs2_ail1_start_one (struct gfs2_sbd *sdp,struct writeback_control *wbc, - struct gfs2_trans *tr) +struct gfs2_trans *tr, +bool *withdraw) __releases(&sdp->sd_ail_lock) __acquires(&sdp->sd_ail_lock) {@@ -107,8 +108,10 @@ __acquires(&sdp->sd_ail_lock)gfs2_assert (sdp, bd->bd_tr == tr);if (!buffer_busy (bh)) { -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list);continue ; }@@ -148,6 +151,7 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc)struct list_head *head = &sdp->sd_ail1_list;struct gfs2_trans *tr;struct blk_plug plug; +bool withdraw = false;trace_gfs2_ail_flush (sdp, wbc,1 );blk_start_plug (&plug);@@ -156,11 +160,13 @@ void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc) list_for_each_entry_reverse(tr, head, tr_list) {if (wbc->nr_to_write <=0 )break ; -if (gfs2_ail1_start_one (sdp, wbc, tr)) +if (gfs2_ail1_start_one (sdp, wbc, tr, &withdraw)) goto restart; }spin_unlock (&sdp->sd_ail_lock);blk_finish_plug (&plug); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL );trace_gfs2_ail_flush (sdp, wbc,0 ); }@@ -188,7 +194,8 @@ static void
gfs2_ail1_start(struct gfs2_sbd *sdp)
*
*/
-static void gfs2_ail1_empty_one(structgfs2_sbd*sdp, structgfs2_trans
*tr)
+static void gfs2_ail1_empty_one(structgfs2_sbd*sdp, structgfs2_trans*tr,fs/gfs2/log.c +9
-4+ bool *withdraw) {struct gfs2_bufdata *bd, *s;struct buffer_head *bh;@@ -199,11 +206,12 @@ static void gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr)gfs2_assert (sdp, bd->bd_tr == tr);if (buffer_busy (bh))continue ; -if (!buffer_uptodate (bh)) -gfs2_io_error_bh (sdp, bh); +if (!buffer_uptodate (bh)) { +__gfs2_io_error_bh (sdp, bh); + *withdraw = true; + }list_move (&bd->bd_ail_st_list, &tr->tr_ail2_list); } - }/** @@ -218,10 +226,11 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp)struct gfs2_trans *tr, *s;int oldest_tr =1 ;int ret; +bool withdraw = false;spin_lock (&sdp->sd_ail_lock);list_for_each_entry_safe_reverse (tr, s, &sdp->sd_ail1_list, tr_list) { -gfs2_ail1_empty_one (sdp, tr); +gfs2_ail1_empty_one (sdp, tr, &withdraw);if (list_empty (&tr->tr_ail1_list) && oldest_tr)list_move (&tr->tr_list, &sdp->sd_ail2_list);else @@ -230,6 +239,9 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp) ret =list_empty (&sdp->sd_ail1_list);spin_unlock (&sdp->sd_ail_lock); + if (withdraw) +gfs2_lm_withdraw (sdp,"fatal: I/O error(s)\n" ); +return ret; } diff --git a/fs/gfs2/util.c b/fs/gfs2/util.cindex
763d659db91b..59c811de0dc7100644fs/gfs2/util.c +20
-13@@ -46,14 +46,16 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, const char *fmt, ...) test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))return 0 ; -va_start (args, fmt); +if (fmt) { +va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; + vaf.fmt = fmt; + vaf.va = &args; -fs_err (sdp,"%pV" , &vaf); +fs_err (sdp,"%pV" , &vaf); -va_end (args); +va_end (args); + }if (sdp->sd_args.ar_errors ==GFS2_ERRORS_WITHDRAW ) {fs_err (sdp,"about to withdraw this file system\n" );@@ -246,21 +248,21 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, char *file, }/** -* gfs2_io_error_bh_i - Flag a buffer I/O error and withdraw -* Returns: -1 if this call withdrew the machine, -* 0 if it was already withdrawn +* gfs2_io_error_bh_i - Flag a buffer I/O error +* @withdraw: withdraw the filesystem */ -int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *function, char *file, unsigned int line) +void gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, + const char *function, char *file, unsigned int line, + bool withdraw) { - int rv; - rv =gfs2_lm_withdraw (sdp, -"fatal: I/O error\n" -" block = %llu\n" -" function = %s, file = %s, line = %u\n" , - (unsigned long long )bh->b_blocknr, - function, file, line); -return rv; + fs_err(sdp, + "fatal: I/O error\n" + " block = %llu\n" +" function = %s, file = %s, line = %u\n" , + (unsigned long long )bh->b_blocknr, + function, file, line); +if (withdraw) +gfs2_lm_withdraw (sdp,NULL ); } diff --git a/fs/gfs2/util.h b/fs/gfs2/util.hindex
3926f95a6eb7..9d9583e842ac100644fs/gfs2/util.h +3
-2@@ -136,11 +136,15 @@ int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function,gfs2_io_error_i ((sdp), __func__, __FILE__, __LINE__); -int gfs2_io_error_bh_i(struct gfs2_sbd *sdp, struct buffer_head *bh, - const char *function, char *file, unsigned int line); +void gfs2_io_error_bh_i (struct gfs2_sbd *sdp,struct buffer_head *bh, +const char *function,char *file,unsigned int line, +bool withdraw);#define gfs2_io_error_bh (sdp, bh) \ -gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__);
Quoted 8 lines
fs/gfs2/util.h int gfs2_io_error_i(struct gfs2_sbd *sdp, const char *function, · line 147
Quoted 4 lines
fs/gfs2/util.h +4
-0+gfs2_io_error_bh_i ((sdp), (bh), __func__, __FILE__, __LINE__, true); + +#define __gfs2_io_error_bh (sdp, bh) \ +gfs2_io_error_bh_i((sdp), (bh), __func__, __FILE__, __LINE__, false);Perhaps these could be named something like
gfs2_io_error_bh_wdandgfs2_io_error_bhto indicate the difference.
Yes, makes sense. I've pushed this to the new for-later branch on kernel.org now.
Thanks,
Andreas