linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xie Yongji <xieyongji@bytedance.com>
To: axboe@kernel.dk, josef@toxicpanda.com, hch@infradead.org
Cc: linux-block@vger.kernel.org, nbd@other.debian.org,
	yixingchen@bytedance.com
Subject: [PATCH 3/3] nbd: Use invalidate_gendisk() helper on disconnect
Date: Mon, 13 Sep 2021 19:25:57 +0800	[thread overview]
Message-ID: <20210913112557.191-4-xieyongji@bytedance.com> (raw)
In-Reply-To: <20210913112557.191-1-xieyongji@bytedance.com>

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_gendisk() helper to invalidate the
disk on disconnect instead of just setting disk's capacity to zero.

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

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 5170a630778d..64ae087d8767 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -305,14 +305,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)
 {
@@ -1232,7 +1224,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_gendisk(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);
-- 
2.11.0


  parent reply	other threads:[~2021-09-13 11:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 11:25 [PATCH 0/3] Add invalidate_gendisk() helper for drivers to invalidate the gendisk Xie Yongji
2021-09-13 11:25 ` [PATCH 1/3] block: Add invalidate_gendisk() helper " Xie Yongji
2021-09-13 12:31   ` Christoph Hellwig
2021-09-13 13:16     ` Yongji Xie
2021-09-13 11:25 ` [PATCH 2/3] loop: Use invalidate_gendisk() helper to invalidate gendisk Xie Yongji
2021-09-13 12:34   ` Christoph Hellwig
2021-09-13 13:14     ` Yongji Xie
2021-09-13 11:25 ` Xie Yongji [this message]
2021-09-13 12:41   ` [PATCH 3/3] nbd: Use invalidate_gendisk() helper on disconnect Christoph Hellwig
2021-09-13 13:04     ` Yongji Xie
2021-09-13 15:32       ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210913112557.191-4-xieyongji@bytedance.com \
    --to=xieyongji@bytedance.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=nbd@other.debian.org \
    --cc=yixingchen@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).