Skip to content

Commit

Permalink
block/rnbd-clt: Replace {NO_WAIT,WAIT} with RTRS_PERMIT_{WAIT,NOWAIT}
Browse files Browse the repository at this point in the history
They are defined with the same value and similar meaning, let's remove
one of them, then we can remove {WAIT,NOWAIT}.

Also change the type of 'wait' from 'int' to 'enum wait_type' to make
it clear.

Cc: Leon Romanovsky <[email protected]>
Cc: [email protected]
Signed-off-by: Guoqing Jiang <[email protected]>
Reviewed-by: Md Haris Iqbal <[email protected]>
Signed-off-by: Gioh Kim <[email protected]>
Signed-off-by: Jack Wang <[email protected]>
Reviewed-by: Chaitanya Kulkarni <[email protected]>
Acked-by: Jason Gunthorpe <[email protected]>
Reviewed-by: Leon Romanovsky <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Gioh Kim authored and axboe committed Apr 20, 2021
1 parent d16b5ac commit 9f455ee
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
42 changes: 17 additions & 25 deletions drivers/block/rnbd/rnbd-clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,11 @@ static void rnbd_rerun_all_if_idle(struct rnbd_clt_session *sess)

static struct rtrs_permit *rnbd_get_permit(struct rnbd_clt_session *sess,
enum rtrs_clt_con_type con_type,
int wait)
enum wait_type wait)
{
struct rtrs_permit *permit;

permit = rtrs_clt_get_permit(sess->rtrs, con_type,
wait ? RTRS_PERMIT_WAIT :
RTRS_PERMIT_NOWAIT);
permit = rtrs_clt_get_permit(sess->rtrs, con_type, wait);
if (likely(permit))
/* We have a subtle rare case here, when all permits can be
* consumed before busy counter increased. This is safe,
Expand All @@ -344,7 +342,7 @@ static void rnbd_put_permit(struct rnbd_clt_session *sess,

static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess,
enum rtrs_clt_con_type con_type,
int wait)
enum wait_type wait)
{
struct rnbd_iu *iu;
struct rtrs_permit *permit;
Expand All @@ -354,9 +352,7 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess,
return NULL;
}

permit = rnbd_get_permit(sess, con_type,
wait ? RTRS_PERMIT_WAIT :
RTRS_PERMIT_NOWAIT);
permit = rnbd_get_permit(sess, con_type, wait);
if (unlikely(!permit)) {
kfree(iu);
return NULL;
Expand Down Expand Up @@ -435,16 +431,11 @@ static void msg_conf(void *priv, int errno)
schedule_work(&iu->work);
}

enum wait_type {
NO_WAIT = 0,
WAIT = 1
};

static int send_usr_msg(struct rtrs_clt *rtrs, int dir,
struct rnbd_iu *iu, struct kvec *vec,
size_t len, struct scatterlist *sg, unsigned int sg_len,
void (*conf)(struct work_struct *work),
int *errno, enum wait_type wait)
int *errno, int wait)
{
int err;
struct rtrs_clt_req_ops req_ops;
Expand Down Expand Up @@ -476,7 +467,8 @@ static void msg_close_conf(struct work_struct *work)
rnbd_clt_put_dev(dev);
}

static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait)
static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id,
enum wait_type wait)
{
struct rnbd_clt_session *sess = dev->sess;
struct rnbd_msg_close msg;
Expand Down Expand Up @@ -530,7 +522,7 @@ static void msg_open_conf(struct work_struct *work)
* If server thinks its fine, but we fail to process
* then be nice and send a close to server.
*/
(void)send_msg_close(dev, device_id, NO_WAIT);
send_msg_close(dev, device_id, RTRS_PERMIT_NOWAIT);
}
}
kfree(rsp);
Expand All @@ -554,7 +546,7 @@ static void msg_sess_info_conf(struct work_struct *work)
rnbd_clt_put_sess(sess);
}

static int send_msg_open(struct rnbd_clt_dev *dev, bool wait)
static int send_msg_open(struct rnbd_clt_dev *dev, enum wait_type wait)
{
struct rnbd_clt_session *sess = dev->sess;
struct rnbd_msg_open_rsp *rsp;
Expand Down Expand Up @@ -601,7 +593,7 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait)
return err;
}

static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait)
static int send_msg_sess_info(struct rnbd_clt_session *sess, enum wait_type wait)
{
struct rnbd_msg_sess_info_rsp *rsp;
struct rnbd_msg_sess_info msg;
Expand Down Expand Up @@ -687,7 +679,7 @@ static void remap_devs(struct rnbd_clt_session *sess)
* be asynchronous.
*/

err = send_msg_sess_info(sess, NO_WAIT);
err = send_msg_sess_info(sess, RTRS_PERMIT_NOWAIT);
if (err) {
pr_err("send_msg_sess_info(\"%s\"): %d\n", sess->sessname, err);
return;
Expand All @@ -711,7 +703,7 @@ static void remap_devs(struct rnbd_clt_session *sess)
continue;

rnbd_clt_info(dev, "session reconnected, remapping device\n");
err = send_msg_open(dev, NO_WAIT);
err = send_msg_open(dev, RTRS_PERMIT_NOWAIT);
if (err) {
rnbd_clt_err(dev, "send_msg_open(): %d\n", err);
break;
Expand Down Expand Up @@ -1242,7 +1234,7 @@ find_and_get_or_create_sess(const char *sessname,
if (err)
goto close_rtrs;

err = send_msg_sess_info(sess, WAIT);
err = send_msg_sess_info(sess, RTRS_PERMIT_WAIT);
if (err)
goto close_rtrs;

Expand Down Expand Up @@ -1525,7 +1517,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
ret = -EEXIST;
goto put_dev;
}
ret = send_msg_open(dev, WAIT);
ret = send_msg_open(dev, RTRS_PERMIT_WAIT);
if (ret) {
rnbd_clt_err(dev,
"map_device: failed, can't open remote device, err: %d\n",
Expand Down Expand Up @@ -1559,7 +1551,7 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
return dev;

send_close:
send_msg_close(dev, dev->device_id, WAIT);
send_msg_close(dev, dev->device_id, RTRS_PERMIT_WAIT);
del_dev:
delete_dev(dev);
put_dev:
Expand Down Expand Up @@ -1619,7 +1611,7 @@ int rnbd_clt_unmap_device(struct rnbd_clt_dev *dev, bool force,
destroy_sysfs(dev, sysfs_self);
destroy_gen_disk(dev);
if (was_mapped && sess->rtrs)
send_msg_close(dev, dev->device_id, WAIT);
send_msg_close(dev, dev->device_id, RTRS_PERMIT_WAIT);

rnbd_clt_info(dev, "Device is unmapped\n");

Expand Down Expand Up @@ -1653,7 +1645,7 @@ int rnbd_clt_remap_device(struct rnbd_clt_dev *dev)
mutex_unlock(&dev->lock);
if (!err) {
rnbd_clt_info(dev, "Remapping device.\n");
err = send_msg_open(dev, WAIT);
err = send_msg_open(dev, RTRS_PERMIT_WAIT);
if (err)
rnbd_clt_err(dev, "remap_device: %d\n", err);
}
Expand Down
4 changes: 2 additions & 2 deletions drivers/infiniband/ulp/rtrs/rtrs-clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ static inline void __rtrs_put_permit(struct rtrs_clt *clt,
* up earlier.
*
* Context:
* Can sleep if @wait == RTRS_TAG_WAIT
* Can sleep if @wait == RTRS_PERMIT_WAIT
*/
struct rtrs_permit *rtrs_clt_get_permit(struct rtrs_clt *clt,
enum rtrs_clt_con_type con_type,
int can_wait)
enum wait_type can_wait)
{
struct rtrs_permit *permit;
DEFINE_WAIT(wait);
Expand Down
6 changes: 3 additions & 3 deletions drivers/infiniband/ulp/rtrs/rtrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops,

void rtrs_clt_close(struct rtrs_clt *sess);

enum {
enum wait_type {
RTRS_PERMIT_NOWAIT = 0,
RTRS_PERMIT_WAIT = 1,
RTRS_PERMIT_WAIT = 1
};

/**
Expand All @@ -81,7 +81,7 @@ enum rtrs_clt_con_type {

struct rtrs_permit *rtrs_clt_get_permit(struct rtrs_clt *sess,
enum rtrs_clt_con_type con_type,
int wait);
enum wait_type wait);

void rtrs_clt_put_permit(struct rtrs_clt *sess, struct rtrs_permit *permit);

Expand Down

0 comments on commit 9f455ee

Please sign in to comment.