* [PATCH 0/1] bcache: first wave for Linux v5.11
@ 2020-12-07 16:39 Coly Li
2020-12-07 16:39 ` [PATCH 1/1] bcache: fix race between setting bdev state to none and new write request direct to backing Coly Li
2020-12-07 20:25 ` [PATCH 0/1] bcache: first wave for Linux v5.11 Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Coly Li @ 2020-12-07 16:39 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Coly Li
Hi Jens,
The first wave bcache change for Linux v5.11 is quite silent. Most of
the development is not ready for this merge window. The only change in
this submission is from Dongsheng Yang, this is his second contribution
which catches a very implict bug and provides a fix. The patch runs on
his environment for a while and takes effect.
Please take it for v5.11. Thank you in advance.
Coly Li
---
Dongsheng Yang (1):
bcache: fix race between setting bdev state to none and new write
request direct to backing
drivers/md/bcache/super.c | 9 ---------
drivers/md/bcache/writeback.c | 9 +++++++++
2 files changed, 9 insertions(+), 9 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] bcache: fix race between setting bdev state to none and new write request direct to backing
2020-12-07 16:39 [PATCH 0/1] bcache: first wave for Linux v5.11 Coly Li
@ 2020-12-07 16:39 ` Coly Li
2020-12-07 20:25 ` [PATCH 0/1] bcache: first wave for Linux v5.11 Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Coly Li @ 2020-12-07 16:39 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Dongsheng Yang, Coly Li
From: Dongsheng Yang <dongsheng.yang@easystack.cn>
There is a race condition in detaching as below:
A. detaching B. Write request
(1) writing back
(2) write back done, set bdev
state to clean.
(3) cached_dev_put() and
schedule_work(&dc->detach);
(4) write data [0 - 4K] directly
into backing and ack to user.
(5) power-failure...
When we restart this bcache device, this bdev is clean but not detached,
and read [0 - 4K], we will get unexpected old data from cache device.
To fix this problem, set the bdev state to none when we writeback done
in detaching, and then if power-failure happened as above, the data in
cache will not be used in next bcache device starting, it's detached, we
will read the correct data from backing derectly.
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/super.c | 9 ---------
drivers/md/bcache/writeback.c | 9 +++++++++
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 46a00134a36a..b1a6ba9a5adb 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1114,9 +1114,6 @@ static void cancel_writeback_rate_update_dwork(struct cached_dev *dc)
static void cached_dev_detach_finish(struct work_struct *w)
{
struct cached_dev *dc = container_of(w, struct cached_dev, detach);
- struct closure cl;
-
- closure_init_stack(&cl);
BUG_ON(!test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags));
BUG_ON(refcount_read(&dc->count));
@@ -1130,12 +1127,6 @@ static void cached_dev_detach_finish(struct work_struct *w)
dc->writeback_thread = NULL;
}
- memset(&dc->sb.set_uuid, 0, 16);
- SET_BDEV_STATE(&dc->sb, BDEV_STATE_NONE);
-
- bch_write_bdev_super(dc, &cl);
- closure_sync(&cl);
-
mutex_lock(&bch_register_lock);
calc_cached_dev_sectors(dc->disk.c);
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 3c74996978da..a129e4d2707c 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -705,6 +705,15 @@ static int bch_writeback_thread(void *arg)
* bch_cached_dev_detach().
*/
if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)) {
+ struct closure cl;
+
+ closure_init_stack(&cl);
+ memset(&dc->sb.set_uuid, 0, 16);
+ SET_BDEV_STATE(&dc->sb, BDEV_STATE_NONE);
+
+ bch_write_bdev_super(dc, &cl);
+ closure_sync(&cl);
+
up_write(&dc->writeback_lock);
break;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 0/1] bcache: first wave for Linux v5.11
2020-12-07 16:39 [PATCH 0/1] bcache: first wave for Linux v5.11 Coly Li
2020-12-07 16:39 ` [PATCH 1/1] bcache: fix race between setting bdev state to none and new write request direct to backing Coly Li
@ 2020-12-07 20:25 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-12-07 20:25 UTC (permalink / raw)
To: Coly Li; +Cc: linux-bcache, linux-block
On 12/7/20 9:39 AM, Coly Li wrote:
> Hi Jens,
>
> The first wave bcache change for Linux v5.11 is quite silent. Most of
> the development is not ready for this merge window. The only change in
> this submission is from Dongsheng Yang, this is his second contribution
> which catches a very implict bug and provides a fix. The patch runs on
> his environment for a while and takes effect.
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-07 20:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 16:39 [PATCH 0/1] bcache: first wave for Linux v5.11 Coly Li
2020-12-07 16:39 ` [PATCH 1/1] bcache: fix race between setting bdev state to none and new write request direct to backing Coly Li
2020-12-07 20:25 ` [PATCH 0/1] bcache: first wave for Linux v5.11 Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).