Skip to content

Commit

Permalink
nbd: add function to convert blk req op to nbd cmd
Browse files Browse the repository at this point in the history
This adds a helper function to convert a block req op to a nbd cmd type.
It will be used in the last patch to log the type in the timeout
handler.

Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Mike Christie authored and Jens Axboe committed Aug 20, 2019
1 parent 55313e9 commit 0051467
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions drivers/block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ static void sock_shutdown(struct nbd_device *nbd)
dev_warn(disk_to_dev(nbd->disk), "shutting down sockets\n");
}

static u32 req_to_nbd_cmd_type(struct request *req)
{
switch (req_op(req)) {
case REQ_OP_DISCARD:
return NBD_CMD_TRIM;
case REQ_OP_FLUSH:
return NBD_CMD_FLUSH;
case REQ_OP_WRITE:
return NBD_CMD_WRITE;
case REQ_OP_READ:
return NBD_CMD_READ;
default:
return U32_MAX;
}
}

static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
bool reserved)
{
Expand Down Expand Up @@ -480,22 +496,9 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)

iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));

switch (req_op(req)) {
case REQ_OP_DISCARD:
type = NBD_CMD_TRIM;
break;
case REQ_OP_FLUSH:
type = NBD_CMD_FLUSH;
break;
case REQ_OP_WRITE:
type = NBD_CMD_WRITE;
break;
case REQ_OP_READ:
type = NBD_CMD_READ;
break;
default:
type = req_to_nbd_cmd_type(req);
if (type == U32_MAX)
return -EIO;
}

if (rq_data_dir(req) == WRITE &&
(config->flags & NBD_FLAG_READ_ONLY)) {
Expand Down

0 comments on commit 0051467

Please sign in to comment.