Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Xie Yongji and committed by
Jens Axboe
435c2acb 19f553db

+3 -9
+3 -9
drivers/block/nbd.c
··· 310 310 nsock->sent = 0; 311 311 } 312 312 313 - static void nbd_size_clear(struct nbd_device *nbd) 314 - { 315 - if (nbd->config->bytesize) { 316 - set_capacity(nbd->disk, 0); 317 - kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); 318 - } 319 - } 320 - 321 313 static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, 322 314 loff_t blksize) 323 315 { ··· 1229 1237 &nbd->config_lock)) { 1230 1238 struct nbd_config *config = nbd->config; 1231 1239 nbd_dev_dbg_close(nbd); 1232 - nbd_size_clear(nbd); 1240 + invalidate_disk(nbd->disk); 1241 + if (nbd->config->bytesize) 1242 + kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); 1233 1243 if (test_and_clear_bit(NBD_RT_HAS_PID_FILE, 1234 1244 &config->runtime_flags)) 1235 1245 device_remove_file(disk_to_dev(nbd->disk), &pid_attr);