linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nbd: clear wb_err in bd_inode on disconnect
@ 2021-09-07 12:14 Xie Yongji
  2021-09-09  6:31 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Xie Yongji @ 2021-09-07 12:14 UTC (permalink / raw)
  To: josef, axboe; +Cc: linux-block, nbd, yixingchen

When a nbd device encounters a writeback error, that error will
get propagated to the bd_inode's wb_err field. Then if this nbd
device's backend is disconnected and another is attached, we will
get back the previous writeback error on fsync, which is unexpected.
To fix it, let's clear out the wb_err on disconnect.

Reported-by: Yi Xingchen <yixingchen@bytedance.com>
Signed-off-by: Xie Yongji <xieyongji@bytedance.com>
---
 drivers/block/nbd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 5170a630778d..e6aa804db541 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1233,6 +1233,7 @@ static void nbd_config_put(struct nbd_device *nbd)
 		struct nbd_config *config = nbd->config;
 		nbd_dev_dbg_close(nbd);
 		nbd_size_clear(nbd);
+		nbd->disk->part0->bd_inode->i_mapping->wb_err = 0;
 		if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
 				       &config->runtime_flags))
 			device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] nbd: clear wb_err in bd_inode on disconnect
  2021-09-07 12:14 [PATCH] nbd: clear wb_err in bd_inode on disconnect Xie Yongji
@ 2021-09-09  6:31 ` Christoph Hellwig
  2021-09-09 12:34   ` Yongji Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2021-09-09  6:31 UTC (permalink / raw)
  To: Xie Yongji; +Cc: josef, axboe, linux-block, nbd, yixingchen

On Tue, Sep 07, 2021 at 08:14:25PM +0800, Xie Yongji wrote:
> When a nbd device encounters a writeback error, that error will
> get propagated to the bd_inode's wb_err field. Then if this nbd
> device's backend is disconnected and another is attached, we will
> get back the previous writeback error on fsync, which is unexpected.
> To fix it, let's clear out the wb_err on disconnect.

I really do not like how internals of the implementation like into
drivers here.  Can you add a block layer helper to clear any state
instead? This should incude e.g. the size just cleared above and should
also be used by the loop driver as well.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nbd: clear wb_err in bd_inode on disconnect
  2021-09-09  6:31 ` Christoph Hellwig
@ 2021-09-09 12:34   ` Yongji Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Yongji Xie @ 2021-09-09 12:34 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Josef Bacik, Jens Axboe, linux-block, nbd, yixingchen

On Thu, Sep 9, 2021 at 2:31 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Tue, Sep 07, 2021 at 08:14:25PM +0800, Xie Yongji wrote:
> > When a nbd device encounters a writeback error, that error will
> > get propagated to the bd_inode's wb_err field. Then if this nbd
> > device's backend is disconnected and another is attached, we will
> > get back the previous writeback error on fsync, which is unexpected.
> > To fix it, let's clear out the wb_err on disconnect.
>
> I really do not like how internals of the implementation like into
> drivers here.  Can you add a block layer helper to clear any state
> instead? This should incude e.g. the size just cleared above and should
> also be used by the loop driver as well.

Sure, will do it.

Thanks,
Yongji

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-09 14:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 12:14 [PATCH] nbd: clear wb_err in bd_inode on disconnect Xie Yongji
2021-09-09  6:31 ` Christoph Hellwig
2021-09-09 12:34   ` Yongji Xie

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).