Message ID | 20220620034923.35633-2-guoqing.jiang@linux.dev (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | reduce the size of rnbd_clt_dev | expand |
On Mon, Jun 20, 2022 at 5:49 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote: > > Let's open code it in rnbd_clt_map_device, then we can use information > from rsp to setup gendisk and request_queue in next commits. After that, > we can remove some members (wc, fua and max_hw_sectors etc) from struct > rnbd_clt_dev. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> > --- > drivers/block/rnbd/rnbd-clt.c | 44 +++++++++++++++++++++++++++++++++-- > 1 file changed, 42 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c > index 409c76b81aed..0396532da742 100644 > --- a/drivers/block/rnbd/rnbd-clt.c > +++ b/drivers/block/rnbd/rnbd-clt.c > @@ -1562,7 +1562,14 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, > { > struct rnbd_clt_session *sess; > struct rnbd_clt_dev *dev; > - int ret; > + int ret, errno; > + struct rnbd_msg_open_rsp *rsp; > + struct rnbd_msg_open msg; > + struct rnbd_iu *iu; > + struct kvec vec = { > + .iov_base = &msg, > + .iov_len = sizeof(msg) > + }; > > if (exists_devpath(pathname, sessname)) > return ERR_PTR(-EEXIST); > @@ -1582,13 +1589,46 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, > ret = -EEXIST; > goto put_dev; > } > - ret = send_msg_open(dev, RTRS_PERMIT_WAIT); > + > + rsp = kzalloc(sizeof(*rsp), GFP_KERNEL); > + if (!rsp) { > + ret = -ENOMEM; > + goto del_dev; > + } > + > + iu = rnbd_get_iu(sess, RTRS_ADMIN_CON, RTRS_PERMIT_WAIT); > + if (!iu) { > + ret = -ENOMEM; > + kfree(rsp); > + goto del_dev; > + } > + iu->buf = rsp; > + iu->dev = dev; > + sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); > + > + msg.hdr.type = cpu_to_le16(RNBD_MSG_OPEN); > + msg.access_mode = dev->access_mode; > + strscpy(msg.dev_name, dev->pathname, sizeof(msg.dev_name)); > + > + WARN_ON(!rnbd_clt_get_dev(dev)); > + ret = send_usr_msg(sess->rtrs, READ, iu, > + &vec, sizeof(*rsp), iu->sgt.sgl, 1, > + msg_open_conf, &errno, RTRS_PERMIT_WAIT); > + if (ret) { > + rnbd_clt_put_dev(dev); > + rnbd_put_iu(sess, iu); > + kfree(rsp); > + } else { > + ret = errno; > + } > + rnbd_put_iu(sess, iu); > if (ret) { > rnbd_clt_err(dev, > "map_device: failed, can't open remote device, err: %d\n", > ret); > goto del_dev; > } > + looks ok, except this new line seems not needed. Thx! > mutex_lock(&dev->lock); > pr_debug("Opened remote device: session=%s, path='%s'\n", > sess->sessname, pathname); > -- > 2.34.1 >
On 6/21/22 11:11 PM, Jinpu Wang wrote: > On Mon, Jun 20, 2022 at 5:49 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote: >> Let's open code it in rnbd_clt_map_device, then we can use information >> from rsp to setup gendisk and request_queue in next commits. After that, >> we can remove some members (wc, fua and max_hw_sectors etc) from struct >> rnbd_clt_dev. >> >> Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> >> --- >> drivers/block/rnbd/rnbd-clt.c | 44 +++++++++++++++++++++++++++++++++-- >> 1 file changed, 42 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c >> index 409c76b81aed..0396532da742 100644 >> --- a/drivers/block/rnbd/rnbd-clt.c >> +++ b/drivers/block/rnbd/rnbd-clt.c >> @@ -1562,7 +1562,14 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, >> { >> struct rnbd_clt_session *sess; >> struct rnbd_clt_dev *dev; >> - int ret; >> + int ret, errno; >> + struct rnbd_msg_open_rsp *rsp; >> + struct rnbd_msg_open msg; >> + struct rnbd_iu *iu; >> + struct kvec vec = { >> + .iov_base = &msg, >> + .iov_len = sizeof(msg) >> + }; >> >> if (exists_devpath(pathname, sessname)) >> return ERR_PTR(-EEXIST); >> @@ -1582,13 +1589,46 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, >> ret = -EEXIST; >> goto put_dev; >> } >> - ret = send_msg_open(dev, RTRS_PERMIT_WAIT); >> + >> + rsp = kzalloc(sizeof(*rsp), GFP_KERNEL); >> + if (!rsp) { >> + ret = -ENOMEM; >> + goto del_dev; >> + } >> + >> + iu = rnbd_get_iu(sess, RTRS_ADMIN_CON, RTRS_PERMIT_WAIT); >> + if (!iu) { >> + ret = -ENOMEM; >> + kfree(rsp); >> + goto del_dev; >> + } >> + iu->buf = rsp; >> + iu->dev = dev; >> + sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); >> + >> + msg.hdr.type = cpu_to_le16(RNBD_MSG_OPEN); >> + msg.access_mode = dev->access_mode; >> + strscpy(msg.dev_name, dev->pathname, sizeof(msg.dev_name)); >> + >> + WARN_ON(!rnbd_clt_get_dev(dev)); >> + ret = send_usr_msg(sess->rtrs, READ, iu, >> + &vec, sizeof(*rsp), iu->sgt.sgl, 1, >> + msg_open_conf, &errno, RTRS_PERMIT_WAIT); >> + if (ret) { >> + rnbd_clt_put_dev(dev); >> + rnbd_put_iu(sess, iu); >> + kfree(rsp); >> + } else { >> + ret = errno; >> + } >> + rnbd_put_iu(sess, iu); >> if (ret) { >> rnbd_clt_err(dev, >> "map_device: failed, can't open remote device, err: %d\n", >> ret); >> goto del_dev; >> } >> + > looks ok, except this new line seems not needed. Will remove it in next version. Thanks, Guoqing
diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 409c76b81aed..0396532da742 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -1562,7 +1562,14 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, { struct rnbd_clt_session *sess; struct rnbd_clt_dev *dev; - int ret; + int ret, errno; + struct rnbd_msg_open_rsp *rsp; + struct rnbd_msg_open msg; + struct rnbd_iu *iu; + struct kvec vec = { + .iov_base = &msg, + .iov_len = sizeof(msg) + }; if (exists_devpath(pathname, sessname)) return ERR_PTR(-EEXIST); @@ -1582,13 +1589,46 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, ret = -EEXIST; goto put_dev; } - ret = send_msg_open(dev, RTRS_PERMIT_WAIT); + + rsp = kzalloc(sizeof(*rsp), GFP_KERNEL); + if (!rsp) { + ret = -ENOMEM; + goto del_dev; + } + + iu = rnbd_get_iu(sess, RTRS_ADMIN_CON, RTRS_PERMIT_WAIT); + if (!iu) { + ret = -ENOMEM; + kfree(rsp); + goto del_dev; + } + iu->buf = rsp; + iu->dev = dev; + sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); + + msg.hdr.type = cpu_to_le16(RNBD_MSG_OPEN); + msg.access_mode = dev->access_mode; + strscpy(msg.dev_name, dev->pathname, sizeof(msg.dev_name)); + + WARN_ON(!rnbd_clt_get_dev(dev)); + ret = send_usr_msg(sess->rtrs, READ, iu, + &vec, sizeof(*rsp), iu->sgt.sgl, 1, + msg_open_conf, &errno, RTRS_PERMIT_WAIT); + if (ret) { + rnbd_clt_put_dev(dev); + rnbd_put_iu(sess, iu); + kfree(rsp); + } else { + ret = errno; + } + rnbd_put_iu(sess, iu); if (ret) { rnbd_clt_err(dev, "map_device: failed, can't open remote device, err: %d\n", ret); goto del_dev; } + mutex_lock(&dev->lock); pr_debug("Opened remote device: session=%s, path='%s'\n", sess->sessname, pathname);
Let's open code it in rnbd_clt_map_device, then we can use information from rsp to setup gendisk and request_queue in next commits. After that, we can remove some members (wc, fua and max_hw_sectors etc) from struct rnbd_clt_dev. Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> --- drivers/block/rnbd/rnbd-clt.c | 44 +++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-)