From patchwork Mon Jan 30 09:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13120636 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 EFC53C54EED for ; Mon, 30 Jan 2023 09:24:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C6DD6B0078; Mon, 30 Jan 2023 04:24:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 373566B0082; Mon, 30 Jan 2023 04:24:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01FB46B0078; Mon, 30 Jan 2023 04:24:02 -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 BC5A36B0078 for ; Mon, 30 Jan 2023 04:24:02 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6DF6F1A098B for ; Mon, 30 Jan 2023 09:24:02 +0000 (UTC) X-FDA: 80410928724.08.97788F7 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id B43B18001F for ; Mon, 30 Jan 2023 09:24:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=i9AYlKAO; spf=temperror (imf30.hostedemail.com: error in processing during lookup of BATV+3ca177389f0c7d0d5156+7099+infradead.org+hch@bombadil.srs.infradead.org: DNS error) smtp.mailfrom=BATV+3ca177389f0c7d0d5156+7099+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675070640; 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=p+yCA75hP3xTA4z0JqY98N90poOlsvGyo37k4Ap2woM=; b=SruPbInsX06SkZMnKGtp+iQw32Q2RqfqzaeKrHkp/0ZMRl99E5AS0hVT4IkjDGB4h9ogcE fTiGhMndvr7smYT+/j6LUDOstndIGZjE1mbif/Ikw2wNyG0BoXZ5OtPCK/DLGbIW02kMiN roh5LOTDDklvZnfsaJDFYKIecZrN2lg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=i9AYlKAO; spf=temperror (imf30.hostedemail.com: error in processing during lookup of BATV+3ca177389f0c7d0d5156+7099+infradead.org+hch@bombadil.srs.infradead.org: DNS error) smtp.mailfrom=BATV+3ca177389f0c7d0d5156+7099+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675070640; a=rsa-sha256; cv=none; b=iK7HOtFqqpOVGIkMb5C4RqF1YXvdmfPZHd5e7PvWLlKU+2xJP08WwxBE7Lz7Rux2zF/S8Z POvl2TWo03sAS3J+EWsS1W37bFceaiFZ6IljWPD0sIhaBXekQhN/LO5JaYFkSWw0kES5X5 HPbjkTAkIrT+B8o9TCHPF6a7vrd5B/E= 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=p+yCA75hP3xTA4z0JqY98N90poOlsvGyo37k4Ap2woM=; b=i9AYlKAOZ43/SsWyYnAWPiWAuH wOnzstLTu84haohS93R+b3+/PFUtyvvWWjhOliCemb0tZtB/BvukLBGtdd3Qfn4AztHpMr5gPDiv9 pykYVq16zioFYfJbJUqVapz/0j7Z9lIwlzAc3goAfS8/li6bXevI3m2oMuDgPE3R0eRL87akyah+L YP8S0UqhRwqk0u2hAa7aNsgUMmQdiU8H7GdpecxVRrtK2g0PJyMvxAcj0GHEEGiFPHkZlYN3Xcgrb Zg+hSn9E/U6Bt1mWTQkkWWRFPXtWhjWXN8hIQicH7S0OvZO+ZxtpZxRzB/wDZ4j0GKY2wY9iOJUXC VOKko6ag==; Received: from [2001:4bb8:19a:272a:732e:e417:47d7:2f4a] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMQMj-002o2F-W8; Mon, 30 Jan 2023 09:22:18 +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: Mon, 30 Jan 2023 10:21:38 +0100 Message-Id: <20230130092157.1759539-5-hch@lst.de> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230130092157.1759539-1-hch@lst.de> References: <20230130092157.1759539-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: rspam03 X-Stat-Signature: ufe3wio54gm544im6oi9tk86dgb43a8k X-Rspamd-Queue-Id: B43B18001F X-HE-Tag: 1675070640-673912 X-HE-Meta: U2FsdGVkX1+6b3P7iAAsyC+eEjnzZ3ce7N9l3pcikeNAiaUxn2Qt1m9WlDLRTB3COz6/r802ONXNQsXweH6csY0xqiiuAg3h3rleXT0vf2LLQ+E4j+K3enRjUPYA4L+9Qm8x3du5eCf7DIp4t2A8dm6urORAnPtqPQ9+lR6DqEAr6N+GSdNSdVIelMZouepsFR7YmZeNKBHcyyU2oHUFkxJbU+ofabgxgVC8xxKES3QV89crWpemGOavFd3BFMlINHnQ1A+lRpbcEzkPA/Mq1TdhPmfMNlmPIrxhS5CzDvYgu+jyRQ8/Y6sa1uGIo1DNTGDTgpOyBUHbvptV0wust4h6oYnj1+ZANIng4FY2Niv7WrXuiZPC1WTaayH39HnBclVGYY0+whWVZBaff/7FtnHhzi2mOVHPwM8YUPCcREVJME2yFYezwVQKhQePN03PH03zfN/u5QkZbDUi5lMbgp/tobk/h40YtOGw3DR0WcsxWZudV0i25pLyOXv61E9tkqfvhw/r7gPMEwib8Ssc2P8NEL9Y6/91vgBZCjKwLfhOIPtNy6lEB7zmxL2rw3orj4PzBzNcHNkY5g+U+pmjliGuMT+XjtyJeh6T1RexP5Vk+VZ0BLAndjfpvVvJDUFt2C/KcG6Gbqh/PxCQiG8KWbP5uytnCadf6IZcUslUrym2M0ZeRynkXyYUOS7NPr8Hdm9zsrdyINy1T5P4i71E+7gMvzONqM29p9LP37n9ViHqXroGwG4eCUo1KOXrzaddlfyqIVrhvYsvAyZcO03WxwAHZvVqZEP6MBxho2oHxaHkEyH+OjW71k55kkrMkhpFZC+QvmedJtZNA7FcJsJJ9fVRwjBsEtojvCcsfh4F+nVC2I5U5LcfVZFU8449ejCnNzTcEsXksOpR57sC1L9LJaTOSGRAr7rdSO+v8yYK9fJ7woh0fL4yNz+ignLHLnOu5Hrg42i1KZk7Llic6A4 kyj2A1lk bu+1w7GqHQiYg4ZvQHoLQV7h0cQzRHJ+b2/l3XpNPs2ZyYpj7fQ6XFqmkrg2bzuIht6sJA/oaAmXvpADW6OPkJeN5gOazdnE2xmijW0QYDlDr1CHR23MNy0GgFmtQBnA36AUequUH8wuMO066LYZAVdfnLsIX6HBBsclu2YRoe8XlgUbzHcRwSpskKb7KGHRq76tPMi9IZItkG+2/idjgJOTlyk6TrDq8iHG9ZIDTQWwMVMYSY5NNzvwHNrUunpZlJZNw7A9eP7k469W/R/dE/xubghY8lBCNzkznj3HnKC0uhlNi104gouIGOSYMHCGi6yC4LFmU0WpVuObiVsORZp7s1yGcr0AY6hqyXREbnp2wlsk/staV0MK7+xXdR/eGY2iH1dtnJvT5dlinIaiTn4Feoq0sZuvgMHhW00j9krHfx3g9/0wtVahpZZXap60I5bliQHgytJxNJTR6vMZb07xgQ3FExQ12zKH80vl9oWESD7U= 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;