Subject was: Re: fsync() on read-only RAID triggers BUG On 27.01.2013 17:39, Christoph Hellwig wrote: > On Sat, Jan 26, 2013 at 07:44:40PM +0000, Ben Hutchings wrote: >> I applied this on top of 3.2.37 and it certainly fixes the crash. >> However I wonder whether fsync() should fail or should immediately >> succeed. I don't know whether the installer expects it to succeed. > > It should succeed. O.K., then I hope Neil applies the attached patch. I've changed the return value to success. This is also something for linux-stable and should apply to many kernel versions without an issue.
>From fe0357344877c9b9cc623fd582a4e0670e448317 Mon Sep 17 00:00:00 2001 From: Sebastian Riemer <sebastian.riemer@xxxxxxxxxxxxxxxx> Date: Fri, 25 Jan 2013 12:46:59 +0100 Subject: [PATCH v2] md: protect against crash upon fsync on ro array If an fsync occurrs on a read-only array, we need to send a completion for the IO and may not increment the active IO count. Otherwise, we hit a bug trace and can't stop the MD array anymore. By advice of Christoph Hellwig we silently return success. Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> Cc: Ben Hutchings <ben@xxxxxxxxxxxxxxx> Cc: NeilBrown <neilb@xxxxxxx> Signed-off-by: Sebastian Riemer <sebastian.riemer@xxxxxxxxxxxxxxxx> Reported-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx> --- drivers/md/md.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 3db3d1b..475e0be 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -322,6 +322,11 @@ static void md_make_request(struct request_queue *q, struct bio *bio) } finish_wait(&mddev->sb_wait, &__wait); } + if (mddev->ro == 1 && unlikely(rw == WRITE)) { + rcu_read_unlock(); + bio_endio(bio, 0); + return; + } atomic_inc(&mddev->active_io); rcu_read_unlock(); -- 1.7.1