nbd: add function to convert blk req op to nbd cmd
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>
This commit is contained in:
parent
55313e92bd
commit
00514677ed
|
@ -344,6 +344,22 @@ static void sock_shutdown(struct nbd_device *nbd)
|
||||||
dev_warn(disk_to_dev(nbd->disk), "shutting down sockets\n");
|
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,
|
static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req,
|
||||||
bool reserved)
|
bool reserved)
|
||||||
{
|
{
|
||||||
|
@ -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));
|
iov_iter_kvec(&from, WRITE, &iov, 1, sizeof(request));
|
||||||
|
|
||||||
switch (req_op(req)) {
|
type = req_to_nbd_cmd_type(req);
|
||||||
case REQ_OP_DISCARD:
|
if (type == U32_MAX)
|
||||||
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:
|
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
if (rq_data_dir(req) == WRITE &&
|
if (rq_data_dir(req) == WRITE &&
|
||||||
(config->flags & NBD_FLAG_READ_ONLY)) {
|
(config->flags & NBD_FLAG_READ_ONLY)) {
|
||||||
|
|
Loading…
Reference in New Issue