From: Christoph Hellwig <hch@lst.de>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 07/10] nbd: move request validity checking into nbd_send_cmd
Date: Tue, 31 Jan 2017 16:57:28 +0100 [thread overview]
Message-ID: <1485878251-6107-8-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1485878251-6107-1-git-send-email-hch@lst.de>
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>
---
drivers/block/nbd.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d4c6281..8bce1c7c 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];
--
2.1.4
next prev parent reply other threads:[~2017-01-31 15:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 15:57 remove the cmd_type field from struct request Christoph Hellwig
2017-01-31 15:57 ` [PATCH 01/10] scm_blk: remove unneeded REQ_TYPE_FS check Christoph Hellwig
2017-01-31 15:57 ` [PATCH 02/10] ѕd: remove pointless " Christoph Hellwig
2017-01-31 15:57 ` [PATCH 03/10] mmc: remove pointless request type check in mmc_prep_request Christoph Hellwig
2017-01-31 15:57 ` [PATCH 04/10] ms_block: remove pointless prep_fn Christoph Hellwig
2017-01-31 15:57 ` [PATCH 05/10] mspro_block: " Christoph Hellwig
2017-01-31 15:57 ` [PATCH 06/10] nbd: remove REQ_TYPE_DRV_PRIV leftovers Christoph Hellwig
2017-01-31 15:57 ` Christoph Hellwig [this message]
2017-01-31 15:57 ` [PATCH 08/10] block: introduce blk_rq_is_passthrough Christoph Hellwig
2017-01-31 15:57 ` [PATCH 09/10] ide: don't abuse cmd_type Christoph Hellwig
2017-01-31 16:11 ` David Miller
2017-01-31 15:57 ` [PATCH 10/10] block: fold cmd_type into the REQ_OP_ space Christoph Hellwig
2017-01-31 18:02 ` remove the cmd_type field from struct request Jens Axboe
2017-01-31 18:51 ` James Bottomley
2017-01-31 18:58 ` Sergei Shtylyov
2017-01-31 21:09 ` Jens Axboe
2017-02-01 6:53 ` Hannes Reinecke
2017-02-01 10:55 ` Sergei Shtylyov
[not found] ` <CGME20170201103729epcas1p12708473d0e5257bef65e1d92712af885@epcas1p1.samsung.com>
2017-02-01 10:37 ` Bartlomiej Zolnierkiewicz
2017-01-31 21:07 ` Jens Axboe
2017-02-01 2:58 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1485878251-6107-8-git-send-email-hch@lst.de \
--to=hch@lst.de \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).