Skip to content

Commit 435c2ac

Browse files
YongjiXieaxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 19f553d commit 435c2ac

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,6 @@ static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
310310
nsock->sent = 0;
311311
}
312312

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-
321313
static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize,
322314
loff_t blksize)
323315
{
@@ -1237,7 +1229,9 @@ static void nbd_config_put(struct nbd_device *nbd)
12371229
&nbd->config_lock)) {
12381230
struct nbd_config *config = nbd->config;
12391231
nbd_dev_dbg_close(nbd);
1240-
nbd_size_clear(nbd);
1232+
invalidate_disk(nbd->disk);
1233+
if (nbd->config->bytesize)
1234+
kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
12411235
if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
12421236
&config->runtime_flags))
12431237
device_remove_file(disk_to_dev(nbd->disk), &pid_attr);

0 commit comments

Comments
 (0)