Message ID | 20220623062116.15976-7-guoqing.jiang@linux.dev (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | reduce the size of rnbd_clt_dev | expand |
On Thu, Jun 23, 2022 at 8:22 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote: > > Currently, process_msg_open_rsp checks if capacity changed or not before > call rnbd_clt_change_capacity while the checking also make sense for > rnbd_clt_resize_dev_store, let's move the checking into the function. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> Acked-by: Jack Wang <jinpu.wang@ionos.com> > --- > drivers/block/rnbd/rnbd-clt.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) > > diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c > index da2ba9477b1e..a9bfab53bbf7 100644 > --- a/drivers/block/rnbd/rnbd-clt.c > +++ b/drivers/block/rnbd/rnbd-clt.c > @@ -71,6 +71,12 @@ static inline bool rnbd_clt_get_dev(struct rnbd_clt_dev *dev) > static int rnbd_clt_change_capacity(struct rnbd_clt_dev *dev, > size_t new_nsectors) > { > + if (get_capacity(dev->gd) == new_nsectors) > + return 0; > + > + /* > + * If the size changed, we need to revalidate it > + */ > rnbd_clt_info(dev, "Device size changed from %llu to %zu sectors\n", > get_capacity(dev->gd), new_nsectors); > set_capacity_and_notify(dev->gd, new_nsectors); > @@ -93,12 +99,7 @@ static int process_msg_open_rsp(struct rnbd_clt_dev *dev, > if (dev->dev_state == DEV_STATE_MAPPED_DISCONNECTED) { > u64 nsectors = le64_to_cpu(rsp->nsectors); > > - /* > - * If the device was remapped and the size changed in the > - * meantime we need to revalidate it > - */ > - if (get_capacity(dev->gd) != nsectors) > - rnbd_clt_change_capacity(dev, nsectors); > + rnbd_clt_change_capacity(dev, nsectors); > gd_kobj = &disk_to_dev(dev->gd)->kobj; > kobject_uevent(gd_kobj, KOBJ_ONLINE); > rnbd_clt_info(dev, "Device online, device remapped successfully\n"); > -- > 2.34.1 >
diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index da2ba9477b1e..a9bfab53bbf7 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -71,6 +71,12 @@ static inline bool rnbd_clt_get_dev(struct rnbd_clt_dev *dev) static int rnbd_clt_change_capacity(struct rnbd_clt_dev *dev, size_t new_nsectors) { + if (get_capacity(dev->gd) == new_nsectors) + return 0; + + /* + * If the size changed, we need to revalidate it + */ rnbd_clt_info(dev, "Device size changed from %llu to %zu sectors\n", get_capacity(dev->gd), new_nsectors); set_capacity_and_notify(dev->gd, new_nsectors); @@ -93,12 +99,7 @@ static int process_msg_open_rsp(struct rnbd_clt_dev *dev, if (dev->dev_state == DEV_STATE_MAPPED_DISCONNECTED) { u64 nsectors = le64_to_cpu(rsp->nsectors); - /* - * If the device was remapped and the size changed in the - * meantime we need to revalidate it - */ - if (get_capacity(dev->gd) != nsectors) - rnbd_clt_change_capacity(dev, nsectors); + rnbd_clt_change_capacity(dev, nsectors); gd_kobj = &disk_to_dev(dev->gd)->kobj; kobject_uevent(gd_kobj, KOBJ_ONLINE); rnbd_clt_info(dev, "Device online, device remapped successfully\n");
Currently, process_msg_open_rsp checks if capacity changed or not before call rnbd_clt_change_capacity while the checking also make sense for rnbd_clt_resize_dev_store, let's move the checking into the function. Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> --- drivers/block/rnbd/rnbd-clt.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)