summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-01-31 16:57:28 +0100
committerJens Axboe <axboe@fb.com>2017-01-31 11:12:42 -0700
commit8f6e8d0366b8a6fdbe6325fe3ac6da1c6f31de12 (patch)
tree539f917b366fc7836e6931fda6b7c85412040fd9
parent3f96026b192bb59612ad4a91ec2d98b5e51c73dd (diff)
nbd: move request validity checking into nbd_send_cmd
This is where we do the rest of the request handling, which will become much simpler soon, too. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r--drivers/block/nbd.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d4c6281a181c..8bce1c7c18d5 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -271,6 +271,9 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
u32 type;
u32 tag = blk_mq_unique_tag(req);
+ if (req->cmd_type != REQ_TYPE_FS)
+ return -EIO;
+
if (req_op(req) == REQ_OP_DISCARD)
type = NBD_CMD_TRIM;
else if (req_op(req) == REQ_OP_FLUSH)
@@ -280,6 +283,13 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
else
type = NBD_CMD_READ;
+ if (rq_data_dir(req) == WRITE &&
+ (nbd->flags & NBD_FLAG_READ_ONLY)) {
+ dev_err_ratelimited(disk_to_dev(nbd->disk),
+ "Write on read-only\n");
+ return -EIO;
+ }
+
memset(&request, 0, sizeof(request));
request.magic = htonl(NBD_REQUEST_MAGIC);
request.type = htonl(type);
@@ -503,17 +513,6 @@ static void nbd_handle_cmd(struct nbd_cmd *cmd, int index)
goto error_out;
}
- if (req->cmd_type != REQ_TYPE_FS)
- goto error_out;
-
- if (req->cmd_type == REQ_TYPE_FS &&
- rq_data_dir(req) == WRITE &&
- (nbd->flags & NBD_FLAG_READ_ONLY)) {
- dev_err_ratelimited(disk_to_dev(nbd->disk),
- "Write on read-only\n");
- goto error_out;
- }
-
req->errors = 0;
nsock = nbd->socks[index];