summaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorXie Yongji <xieyongji@bytedance.com>2021-09-22 20:37:11 +0800
committerJens Axboe <axboe@kernel.dk>2021-10-21 10:12:41 -0600
commit435c2acb307f19acc791b4295e29cc53a82bd24d (patch)
tree941a3a4dbb7bd27ce5fa1d71c30cacd72814a465 /drivers/block
parent19f553db2ac03cb8407ec8efb8e140951afdfb87 (diff)
nbd: Use invalidate_disk() helper on disconnect
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 use invalidate_disk() helper to invalidate the disk on disconnect instead of just setting disk's capacity to zero. Signed-off-by: Xie Yongji <xieyongji@bytedance.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20210922123711.187-5-xieyongji@bytedance.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/nbd.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 1183f7872b71..8922b8864487 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -310,14 +310,6 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
nsock->sent = 0;
}
-static void nbd_size_clear(struct nbd_device *nbd)
-{
- if (nbd->config->bytesize) {
- set_capacity(nbd->disk, 0);
- kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
- }
-}
-
static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
loff_t blksize)
{
@@ -1237,7 +1229,9 @@ static void nbd_config_put(struct nbd_device *nbd)
&nbd->config_lock)) {
struct nbd_config *config = nbd->config;
nbd_dev_dbg_close(nbd);
- nbd_size_clear(nbd);
+ invalidate_disk(nbd->disk);
+ if (nbd->config->bytesize)
+ kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
&config->runtime_flags))
device_remove_file(disk_to_dev(nbd->disk), &pid_attr);