Message ID | 20210907121425.91-1-xieyongji@bytedance.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | nbd: clear wb_err in bd_inode on disconnect | expand |
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.
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
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);
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(+)