From patchwork Fri Feb 3 15:06:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13127840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A45CC64ED6 for ; Fri, 3 Feb 2023 15:07:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4FD66B0075; Fri, 3 Feb 2023 10:07:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD0996B0080; Fri, 3 Feb 2023 10:07:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2EFB6B0075; Fri, 3 Feb 2023 10:07:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8C1006B0072 for ; Fri, 3 Feb 2023 10:07:48 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5D1F51A1178 for ; Fri, 3 Feb 2023 15:07:48 +0000 (UTC) X-FDA: 80426310216.21.E6A492A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf11.hostedemail.com (Postfix) with ESMTP id CEC1D40018 for ; Fri, 3 Feb 2023 15:07:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VvdE+ZMN; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+416129e804eec9e75a33+7103+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+416129e804eec9e75a33+7103+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675436866; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nFCgusCGETcddag92jej4sXk0TvWuHs0ZPKsULSCPb4=; b=YN0IDB9QXIH9O22e+fJkavzdTm9mZdN8MvZvdj//xUW92KR2zVTn5iActbMD9VkIaK6i9X GbC2VHoPnCpSFu11DiYraHFBj2pmaBkK115p7Ji4BMt7b7EVDMQIa8l0ck25NDC5IUJUbh Fm7Vzx8YWxMFyGvJ/Ba6fsVY+WsJAm8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VvdE+ZMN; dmarc=none; spf=none (imf11.hostedemail.com: domain of BATV+416129e804eec9e75a33+7103+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+416129e804eec9e75a33+7103+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675436866; a=rsa-sha256; cv=none; b=bKIWd2iCGDUJ3f+sHDmYaonGVY6uuUxxjJmUP3szsHPUmKx7e0fPD8L/cQZp498afoUL7y U141lnvGyrt+svnl3M69kOKBXwPy6xSbzKM+S5jGwwt7QZhaVckCD0BcyuQJcMUAwl56hy r08gBa0mkXRgTxEZywRs1H2fim6ueAQ= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nFCgusCGETcddag92jej4sXk0TvWuHs0ZPKsULSCPb4=; b=VvdE+ZMNDitBJaDdEp8YyznFtB iN9Z/tIQLsz5kAYFso0Gnb29VhMIMMjq0Xa52Hg2oAwra3qYJ8leh61xv2WRAmp6eYYEnF9rPB0hn CGP4sJszmLXtbIu3oxAhBi+tVJRqU5ijKNzXBSeXgn0S5/8UNYECoUx1AT2C6CQWflLpHcHO3elmk uhkrh15eFLQWZt0+lFjCIzywMB3BS5yrZHdPmDhECnToZPgve299mjDhwNv3YpUc90wJVBRSay8qM 5KPFXtBhcrG0zPARc13WWewfCF4RKRRehkdJ7hfXkiFxiBJGOoWmbWiCdqrOOO2VdL9nKra4pLm23 DC1xa06w==; Received: from [2001:4bb8:19a:272a:910:bb67:7287:f956] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNxeL-002afR-1b; Fri, 03 Feb 2023 15:06:49 +0000 From: Christoph Hellwig To: Jens Axboe Cc: Ilya Dryomov , "Michael S. Tsirkin" , Jason Wang , Minchan Kim , Sergey Senozhatsky , Keith Busch , Sagi Grimberg , Chaitanya Kulkarni , "Martin K. Petersen" , David Howells , Marc Dionne , Xiubo Li , Steve French , Trond Myklebust , Anna Schumaker , Mike Marshall , Andrew Morton , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Chuck Lever , 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 Message-Id: <20230203150634.3199647-5-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230203150634.3199647-1-hch@lst.de> References: <20230203150634.3199647-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CEC1D40018 X-Stat-Signature: rxxeuj8bsuq6dwoxxa8k479oak9ukyug X-HE-Tag: 1675436865-844802 X-HE-Meta: U2FsdGVkX18YMWqdeN8zYj4z3pHT0U58nYEirRoyCMuq4WACWqV08zDP7GOIW9fifmc4TbpVByCPbT4xXDO0DIIEUwHgtdRrqWqZsu+ROwjuOVdZJe1aAtPXpoPgdiPpF1rzSE2fQBwZA1IA4Vo1ZBzEK+Ru3g2uR0kiWVz4sv21A4YYpSyttt9TPS8OmHEqwdXFGfbjcm67oKSxQeC7/dcQb+T1cFYLShQ/kYfkwCVx7hxo9oBaWkMIx1vtE1X9HrGWdhynDIhi8nBKzaOTFLah9l6iI14LNrX7/GrMXda25F4/Ol4/kQblgdXz/nAXOpMwgdeLG+0UTSsWFdQCUxKp9nIHhexJDHZ2+0hqeXVXsO7myg3fENjIVc2lDJDndRjxY2YPNQBz1/QnHDm+WnL+NC/lVbyPz2bdvD5GzPHSBg9wabc7bZtWKgpIuNiSB1SRhKIYRFcRlZA2R5uPStZMVKzlhvpBIT82LdgPxUAh2Ow2o73fG/APVIR7jn6aRFs4giyAKKj3kkWMheDDmA+iQyAniPgoOHuhztknBEFMkQLwp6w0XcvPIT/C5x7emz14s2TenPfagUHEzIEdJF8oRjXe1f50KCTbxcxuIeQM/Xyr8RgqriWFAOdqQMDaddYRpCexOupVi3hPjNjD57tqtPZnAEtJvs2HXROoT89RvJS9nC1N9S0B8XIuqSwO7M00QEYI6136Ar0AGzasnWz3A5ySXM3uxiUbwq3MQVWf2UYVWsLZ1lONBkMaCknMh482P9kMRbsTUNtlhkGLztPnmgJKiz0/KpJRgloFoT0BIafiHRK12SpXkmOC6zDKC/KZkPzWS9jtUft/3fcFN4HfawQl2D8gDcn2WvMDi0EzZ7n3nOmKzj2l3vAUyDKwLpwiKUuZ7TuZpOEZtAoYY0dtHWRFLA+KaszaMh7D/zdg8ByVAEl5+Ak/6xiMe+W8YB/NcguyeRiGomnhwkS WzqQ7o2r ReOy+BW/bkDVUwy+nKGqndL6mDsA6cfKy+rvYyFR3AHbcVslhtj+vKHEy2JQFnHpfWFv9eVlV0n3k3ZVgATpRn1Yf1WDU3nEGVyZQnrXoJNy1xMYGxywdMHseKryy1SIVh6ylG6XwLeDMAZz22Jhcaay5+FQY4DE6k7Vbp/VsTMZXzEEvX2kk+a1VKhzJ4OaOpyM8D32BVPvL6q261xqWBAH4xhiYWO8m33vFTtktQg6KSMg5R3mGVnoNvwtDNdwza6Lb02vvIRMdOF8TbCVUOy/NvoFWOogTNbS/meEzMJqMaJpFa7HBLsH+gtr/g/qQmD11fqljOya1zJl2v80fCbfEbUchI+w27kv+PLlbA27kWJzFbEgLPyGDvoAOmsXAS4yoZv4bWB/l+aBmdSobVKR2TPjTQs4Ncs+sdcqw4eD90DU2AmBDCzYI7yrep//1uQ0YOdYRv5guHta2628kea5yIYTW0pVYcpkDLAwGar0wZkhiC0M1qOCzUQKuMVRVTWjV X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Chaitanya Kulkarni --- 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;