Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp870144rdb; Wed, 6 Dec 2023 02:12:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHadbwU1LO0itY3a8R6nyjBoeRMO0i8xQZ7+ozBPecCARR4mKOGGlzyKL9IRxL+FXUA1AKp X-Received: by 2002:a17:90b:1b0e:b0:286:e436:4aca with SMTP id nu14-20020a17090b1b0e00b00286e4364acamr425521pjb.92.1701857529773; Wed, 06 Dec 2023 02:12:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701857529; cv=none; d=google.com; s=arc-20160816; b=mdHBJKFtkie+SYBfVUqJIukqSasRr6ThVg2B82cocfCFKELAKg3iau23/ELQ2oEdVx xWiHFIriZ+HkiVy4g0rSwccwEMHtHOwuNPEaynentFLYp/cx1szoTTHrtNDkmexYFjHo mbr3IXEroHk0jtwv3yKDEKi/T9vCQZi+Ruuxnq7iftlPgUQ8vPJ1ue7tHptC1Y/XU/I1 /kO+FZgGHbqQ9TkealvCI+fdFZMq4MqYhTawkrUgyD0DGC9qGzEunFt1zHLU6FNU8uDV lE7Re/kNj6ilIpG9SH7IlPMe3yXsSEt+7vsyz3Cci7OY2BR0ogIHxuuJLRZyttc72JAI F+dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=AOfFIjYI2wLqNYIL53RS+cLCGUBaMkDlBy8uIvV9EEU=; fh=ynswjdvCI3+z3c9qNEmqaETRdNjcpsTGSRuF33qVHus=; b=S1XOZex5MtfCbTBEAu7WMRULwIauTGKR97p0saGunzEg7VSaLcR+C87T03wZZebNX/ OU5MZATZTd1j1mI+D221h9DD+lH9GDdUOv+W7RSLCGsFzKrvsjLBy+I7A7qJMV/CNIQU yu3lByOZZPPT7G6FBksK5njGMAP5OXJSvLhrui+5Ug26bfNdsIHyUDwtIOBjk3JJnoEy 0gK3a9D73dz4I78yT6UH7xZER9rIU7uTbJM5lhK/sRVMoAs2Irq/qNMz9ZPz77ZmFmoY PdTf0E3qK8wBH50DqONXueNZh06f72qxfrhI9MB+p86P2jkBZLsoAtfd7LEnN+gCc+Z7 8MCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cd1wParl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h8-20020a170902ac8800b001d060d48fb3si8074601plr.460.2023.12.06.02.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:12:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=cd1wParl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 85A21807C75B; Wed, 6 Dec 2023 02:12:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377423AbjLFKLv (ORCPT + 99 others); Wed, 6 Dec 2023 05:11:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377371AbjLFKLs (ORCPT ); Wed, 6 Dec 2023 05:11:48 -0500 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02D47D5F for ; Wed, 6 Dec 2023 02:11:53 -0800 (PST) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231206101152epoutp0322c6ccfdb09d309eb514868f8ff251f1~eNmP_4rPu2449624496epoutp03Y for ; Wed, 6 Dec 2023 10:11:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231206101152epoutp0322c6ccfdb09d309eb514868f8ff251f1~eNmP_4rPu2449624496epoutp03Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1701857512; bh=AOfFIjYI2wLqNYIL53RS+cLCGUBaMkDlBy8uIvV9EEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cd1wParlIHUxsUbfkdHucKN5S4B108SkOdn2UE2QFoT5CT9a09J5xJIjTgbgMYLNr GB9uAp0SLhK6JPqS7QZJLg/pb3xUUY2nBJoUOm/6KxXmJT5Sa3lfEHj4R+WXWGWJoI 0X04DP+lwYEmhwwR1JG2g98PfxOo6mJC0L7NNfjE= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20231206101151epcas5p13faeb3c54d5e6e95672f50b1041fd65d~eNmPQdroJ1468514685epcas5p1B; Wed, 6 Dec 2023 10:11:51 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.176]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4SlY915zhlz4x9Pv; Wed, 6 Dec 2023 10:11:49 +0000 (GMT) Received: from epcas5p1.samsung.com ( [182.195.41.39]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 80.D6.10009.5E840756; Wed, 6 Dec 2023 19:11:49 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231206101149epcas5p429e2a328af02819c71fa48ad01308a89~eNmNLRqTM2528425284epcas5p40; Wed, 6 Dec 2023 10:11:49 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231206101149epsmtrp14047bbe569c539379849c452b0a67208~eNmNKMzPF1112611126epsmtrp1H; Wed, 6 Dec 2023 10:11:49 +0000 (GMT) X-AuditID: b6c32a4a-261fd70000002719-67-657048e52afe Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 89.52.08817.5E840756; Wed, 6 Dec 2023 19:11:49 +0900 (KST) Received: from localhost.localdomain (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231206101141epsmtip2611ca7ae3531b6917df9b8dbc3213075~eNmF_pEh-1181011810epsmtip2G; Wed, 6 Dec 2023 10:11:41 +0000 (GMT) From: Kanchan Joshi To: Jens Axboe , Jonathan Corbet , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , dm-devel@lists.linux.dev, Keith Busch , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Alexander Viro , Christian Brauner Cc: martin.petersen@oracle.com, linux-scsi@vger.kernel.org, nitheshshetty@gmail.com, anuj1072538@gmail.com, gost.dev@samsung.com, mcgrof@kernel.org, Nitesh Shetty , Hannes Reinecke , Anuj Gupta , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v18 06/12] fs, block: copy_file_range for def_blk_ops for direct block device Date: Wed, 6 Dec 2023 15:32:38 +0530 Message-Id: <20231206100253.13100-7-joshi.k@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206100253.13100-1-joshi.k@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Tf1CTdRzu+76v2zCWbwOPr+sHMEODDtgWG18UqDu13iuvSKs7oZrvsbdB G9vaD81+EKQCWvw+L5jyI0AtJAgGArIJQoBQAsGhAuEBskAoSIS4JKWNzfK/5/P9PM899zzf +3BwXhabz4lXGxidmlYJWOuJ823+WwNtlJYR/n3GH1V1d+Do9tIKgb7Iuoejc6OZLDTbtgDQ ZEsqQMUlBQQaamnEkKUkB0PfnWvHUE7rVYBsgyYMWYefQ9+klBHIYu0i0MCFUyxUdMbGRl9e a2Chs533MXQ9ywZQdtoghhomkwE6v1KEo8rZeQJdHn4C9d7rXPcin2o0jbKp3hvVBDVwxUjV lB9jUeayz6lpcz6gmoaSWFRpRu46Kv3wHIu6bRsmqPmLgywqo7YcUOafPqHu1DxN1Uz+gUVt iFaGxzG0nNH5MOpYjTxerYgQvLpXtkMmkQpFgaIwFCrwUdMJTIRg5+6owJfiVfZKBD4HaJXR /hRF6/WC4MhwncZoYHziNHpDhIDRylXaEG2Qnk7QG9WKIDVj2CYSCsUSO3G/Mu5E9i+YdmbD RxOtA3gSmHc/Dtw4kAyBtSbbuuNgPYdHNgGY8lsT4RwWAFy4aHFt/gKw8u4S+4GkLs/Kdi6s ACb3VGDO4Q6A1Uea7QOHwyL9YV+u0SHwJCtw2FgtcnBwshCH5olOzLHwIGVwdXUCd2CC9IO1 q8uEA3NJBK/MNRNON2+Y37+85uxGhsHcqRLcyXkcduVPrnFwO+dw3UncYQDJejdY3lXlEu+E fc0dmBN7wJnOWlcEPryVmeLCsbA/v8fFMcCblksu/AI82p2JO8Lg9jBVF4KdXo/B9JXJtYyQ 5MK0FJ6T7Qtv5Dh6dGAvOJ5X5sIUnM8vcPXzFYDT31eys4C36aEIpocimP53KwZ4OdjEaPUJ CkYv0YrVzMH/fjZWk1AD1k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nXOB2q XlDi5MwnLBDz5SWat85mnsAoMAtJahaS1AJGplWMkqkFxbnpucWGBUZ5qeV6xYm5xaV56XrJ +bmbGMHxrqW1g3HPqg96hxiZOBgPMUpwMCuJ8Oacz08V4k1JrKxKLcqPLyrNSS0+xCjNwaIk zvvtdW+KkEB6YklqdmpqQWoRTJaJg1OqgclTvuZhtd+36MK4Yx08wR//CWft7HOoLxMyuXZ0 n63VJG2hzbLm6hPiVIsSKmx/cM3omPOFiSE29HqO3/KIecJskSu7X1jyCTQ65vT1nXhxeUZZ 6OaDO9TcYlvyy5Ztaz6YtvtbkMuq/T3Mtt9e2DfYLtaUNFu6RXHP7oDUORscJ8xev4XLOfzI Kcdw97z4hrxvD7O3CIXMr+lM9Hfclaj05I5Qy7YPAkV2v1YyLn17JVo6tiLndspbtitdjg8e 9LzTsy26GbN3q9Klme+t405e9VrpNut4FlOE9iuxmWJpjVsZXoacWKEifLu83WPR72TL0PB5 y5PzJ53837N63b/Fb660NpuxzDp8tc9cV4mlOCPRUIu5qDgRAAqih8RmAwAA X-CMS-MailID: 20231206101149epcas5p429e2a328af02819c71fa48ad01308a89 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231206101149epcas5p429e2a328af02819c71fa48ad01308a89 References: <20231206100253.13100-1-joshi.k@samsung.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:12:06 -0800 (PST) From: Nitesh Shetty For direct block device opened with O_DIRECT, use copy_file_range to issue device copy offload, or use generic_copy_file_range in case device copy offload capability is absent or the device files are not open with O_DIRECT. Reviewed-by: Hannes Reinecke Signed-off-by: Anuj Gupta Signed-off-by: Nitesh Shetty --- block/fops.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/block/fops.c b/block/fops.c index 0bdad1e8d514..08b652788e55 100644 --- a/block/fops.c +++ b/block/fops.c @@ -747,6 +747,30 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) return ret; } +static ssize_t blkdev_copy_file_range(struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + struct block_device *in_bdev = I_BDEV(bdev_file_inode(file_in)); + struct block_device *out_bdev = I_BDEV(bdev_file_inode(file_out)); + ssize_t copied = 0; + + if ((in_bdev == out_bdev) && bdev_max_copy_sectors(in_bdev) && + (file_in->f_iocb_flags & IOCB_DIRECT) && + (file_out->f_iocb_flags & IOCB_DIRECT)) { + copied = blkdev_copy_offload(in_bdev, pos_in, pos_out, len, + NULL, NULL, GFP_KERNEL); + if (copied < 0) + copied = 0; + } else { + copied = generic_copy_file_range(file_in, pos_in + copied, + file_out, pos_out + copied, + len - copied, flags); + } + + return copied; +} + #define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ FALLOC_FL_ZERO_RANGE | FALLOC_FL_NO_HIDE_STALE) @@ -851,6 +875,7 @@ const struct file_operations def_blk_fops = { .splice_read = filemap_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, + .copy_file_range = blkdev_copy_file_range, }; static __init int blkdev_init(void) -- 2.35.1.500.gb896f729e2