All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Ilya Dryomov <idryomov@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
	Chaitanya Kulkarni <kch@nvidia.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	David Howells <dhowells@redhat.com>,
	Marc Dionne <marc.dionne@auristor.com>,
	Xiubo Li <xiubli@redhat.com>, Steve French <sfrench@samba.org>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	Anna Schumaker <anna@kernel.org>,
	Mike Marshall <hubcap@omnibond.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Chuck Lever <chuck.lever@oracle.com>,
	linux-block@vger.kernel.org, ceph-devel@vger.kernel.org,
	virtualization@lists.linux-foundation.org,
	linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org, kvm@vger.kernel.org,
	netdev@vger.kernel.org, linux-afs@lists.infradead.org,
	linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
	linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org,
	devel@lists.orangefs.org, io-uring@vger.kernel.org,
	linux-mm@kvack.org
Subject: [PATCH 04/23] sd: factor out a sd_set_special_bvec helper
Date: Fri,  3 Feb 2023 16:06:15 +0100	[thread overview]
Message-ID: <20230203150634.3199647-5-hch@lst.de> (raw)
In-Reply-To: <20230203150634.3199647-1-hch@lst.de>

Add a helper for setting up the special_bvec instead of open coding it
in three place, and use the new bvec_set_page helper to initialize
special_vec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/scsi/sd.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 47dafe6b8a66d1..277960decc104b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -831,6 +831,19 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 	blk_queue_max_discard_sectors(q, max_blocks * (logical_block_size >> 9));
 }
 
+static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
+{
+	struct page *page;
+
+	page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
+	if (!page)
+		return NULL;
+	clear_highpage(page);
+	bvec_set_page(&rq->special_vec, page, data_len, 0);
+	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
+	return bvec_virt(&rq->special_vec);
+}
+
 static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 {
 	struct scsi_device *sdp = cmd->device;
@@ -841,19 +854,14 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 	unsigned int data_len = 24;
 	char *buf;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	buf = sd_set_special_bvec(rq, data_len);
+	if (!buf)
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = UNMAP;
 	cmd->cmnd[8] = 24;
 
-	buf = bvec_virt(&rq->special_vec);
 	put_unaligned_be16(6 + 16, &buf[0]);
 	put_unaligned_be16(16, &buf[2]);
 	put_unaligned_be64(lba, &buf[8]);
@@ -876,13 +884,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 16;
 	cmd->cmnd[0] = WRITE_SAME_16;
@@ -908,13 +911,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = WRITE_SAME;
-- 
2.39.0


WARNING: multiple messages have this Message-ID (diff)
From: Christoph Hellwig <hch@lst.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	linux-nvme@lists.infradead.org,
	virtualization@lists.linux-foundation.org,
	David Howells <dhowells@redhat.com>,
	linux-mm@kvack.org, Eric Dumazet <edumazet@google.com>,
	target-devel@vger.kernel.org,
	Marc Dionne <marc.dionne@auristor.com>,
	linux-afs@lists.infradead.org,
	Mike Marshall <hubcap@omnibond.com>,
	linux-cifs@vger.kernel.org, Sagi Grimberg <sagi@grimberg.me>,
	linux-scsi@vger.kernel.org, Minchan Kim <minchan@kernel.org>,
	io-uring@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
	Ilya Dryomov <idryomov@gmail.com>,
	Paolo Abeni <pabeni@redhat.com>,
	devel@lists.orangefs.org, linux-block@vger.kernel.org,
	Keith Busch <kbusch@kernel.org>,
	ceph-devel@vger.kernel.org, Xiubo Li <xiubli@redhat.com>,
	Trond Myklebust <trond.myklebust@hammerspace.com>,
	linux-nfs@vger.kernel.org,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	netdev@vger.kernel.org, samba-technical@lists.samba.org,
	Steve French <sfrench@samba.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	Anna Schumaker <anna@kernel.org>,
	linux-fsdevel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 04/23] sd: factor out a sd_set_special_bvec helper
Date: Fri,  3 Feb 2023 16:06:15 +0100	[thread overview]
Message-ID: <20230203150634.3199647-5-hch@lst.de> (raw)
In-Reply-To: <20230203150634.3199647-1-hch@lst.de>

Add a helper for setting up the special_bvec instead of open coding it
in three place, and use the new bvec_set_page helper to initialize
special_vec.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/scsi/sd.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 47dafe6b8a66d1..277960decc104b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -831,6 +831,19 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
 	blk_queue_max_discard_sectors(q, max_blocks * (logical_block_size >> 9));
 }
 
+static void *sd_set_special_bvec(struct request *rq, unsigned int data_len)
+{
+	struct page *page;
+
+	page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
+	if (!page)
+		return NULL;
+	clear_highpage(page);
+	bvec_set_page(&rq->special_vec, page, data_len, 0);
+	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
+	return bvec_virt(&rq->special_vec);
+}
+
 static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 {
 	struct scsi_device *sdp = cmd->device;
@@ -841,19 +854,14 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 	unsigned int data_len = 24;
 	char *buf;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	buf = sd_set_special_bvec(rq, data_len);
+	if (!buf)
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = UNMAP;
 	cmd->cmnd[8] = 24;
 
-	buf = bvec_virt(&rq->special_vec);
 	put_unaligned_be16(6 + 16, &buf[0]);
 	put_unaligned_be16(16, &buf[2]);
 	put_unaligned_be64(lba, &buf[8]);
@@ -876,13 +884,8 @@ static blk_status_t sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 16;
 	cmd->cmnd[0] = WRITE_SAME_16;
@@ -908,13 +911,8 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd,
 	u32 nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
-	rq->special_vec.bv_page = mempool_alloc(sd_page_pool, GFP_ATOMIC);
-	if (!rq->special_vec.bv_page)
+	if (!sd_set_special_bvec(rq, data_len))
 		return BLK_STS_RESOURCE;
-	clear_highpage(rq->special_vec.bv_page);
-	rq->special_vec.bv_offset = 0;
-	rq->special_vec.bv_len = data_len;
-	rq->rq_flags |= RQF_SPECIAL_PAYLOAD;
 
 	cmd->cmd_len = 10;
 	cmd->cmnd[0] = WRITE_SAME;
-- 
2.39.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2023-02-03 15:07 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 15:06 add bvec initialization helpers v2 Christoph Hellwig
2023-02-03 15:06 ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 01/23] block: factor out a bvec_set_page helper Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 02/23] block: add a bvec_set_folio helper Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 03/23] block: add a bvec_set_virt helper Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` Christoph Hellwig [this message]
2023-02-03 15:06   ` [PATCH 04/23] sd: factor out a sd_set_special_bvec helper Christoph Hellwig
2023-02-03 15:06 ` [PATCH 05/23] target: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 06/23] nvmet: " Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 07/23] nvme: use bvec_set_virt to initialize special_vec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 08/23] rbd: use bvec_set_page to initialize the copy up bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 09/23] virtio_blk: use bvec_set_virt to initialize special_vec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 10/23] zram: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 11/23] afs: use bvec_set_folio to initialize a bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 12/23] ceph: use bvec_set_page " Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 17:14   ` Ilya Dryomov
2023-02-03 15:06 ` [PATCH 13/23] cifs: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 14/23] coredump: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 15/23] nfs: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 16/23] orangefs: use bvec_set_{page,folio} " Christoph Hellwig
2023-02-03 15:06   ` [PATCH 16/23] orangefs: use bvec_set_{page, folio} " Christoph Hellwig
2023-02-03 15:06 ` [PATCH 17/23] splice: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 18/23] io_uring: " Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 19/23] swap: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 20/23] rxrpc: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 21/23] sunrpc: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 22/23] vringh: use bvec_set_page to initialize a bvec Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 15:06 ` [PATCH 23/23] libceph: use bvec_set_page to initialize bvecs Christoph Hellwig
2023-02-03 15:06   ` Christoph Hellwig
2023-02-03 17:18 ` add bvec initialization helpers v2 Jens Axboe
2023-02-03 17:18   ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2023-01-30  9:21 add bvec initialization helpers Christoph Hellwig
2023-01-30  9:21 ` [PATCH 04/23] sd: factor out a sd_set_special_bvec helper Christoph Hellwig
2023-01-30  9:21   ` Christoph Hellwig
2023-01-31  6:56   ` Chaitanya Kulkarni

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=20230203150634.3199647-5-hch@lst.de \
    --to=hch@lst.de \
    --cc=akpm@linux-foundation.org \
    --cc=anna@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=ceph-devel@vger.kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=devel@lists.orangefs.org \
    --cc=dhowells@redhat.com \
    --cc=edumazet@google.com \
    --cc=hubcap@omnibond.com \
    --cc=idryomov@gmail.com \
    --cc=io-uring@vger.kernel.org \
    --cc=jasowang@redhat.com \
    --cc=kbusch@kernel.org \
    --cc=kch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=martin.petersen@oracle.com \
    --cc=minchan@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sagi@grimberg.me \
    --cc=samba-technical@lists.samba.org \
    --cc=senozhatsky@chromium.org \
    --cc=sfrench@samba.org \
    --cc=target-devel@vger.kernel.org \
    --cc=trond.myklebust@hammerspace.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xiubli@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.