hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9724 ---------------------------------------- Before commit 2ebcabf3dba5 ("nbd: use set_capacity_and_notify"), nbd setup called nbd_set_size() to update the size and did not print "detected capacity change". On the release path nbd_config_put() calls invalidate_disk(), which calls set_capacity(), and that path did not print either. For a genuine size change like size1 -> size2 this printk should remain, but for nbd setup or release it should not be printed, especially since it adds latency to the setup path. Skip set_capacity_and_notify() and use the silent set_capacity() when either side of the change is 0, i.e. on bringup (0 -> size) . Runtime resizes keep set_capacity_and_notify() for the message and uevent, and the explicit kobject_uevent() preserves a uevent on every call as blktests expects. Fixes: 2ebcabf3dba5 ("nbd: use set_capacity_and_notify") Signed-off-by: Yang Erkun <yangerkun@huawei.com> --- drivers/block/nbd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index f9b51b09730a..be2191f7c4c1 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -355,7 +355,11 @@ static int nbd_set_size(struct nbd_device *nbd, loff_t bytesize, if (max_part) set_bit(GD_NEED_PART_SCAN, &nbd->disk->state); - if (!set_capacity_and_notify(nbd->disk, bytesize >> 9)) + /* Avoid the capacity-change printk on probe (0 -> size) */ + if (!get_capacity(nbd->disk)) { + set_capacity(nbd->disk, bytesize >> 9); + kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); + } else if (!set_capacity_and_notify(nbd->disk, bytesize >> 9)) kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE); return 0; } -- 2.52.0