From patchwork Fri Aug 11 10:52:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitesh Shetty X-Patchwork-Id: 13350714 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47A09C04FE2 for ; Fri, 11 Aug 2023 11:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236292AbjHKLUp (ORCPT ); Fri, 11 Aug 2023 07:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236352AbjHKLUd (ORCPT ); Fri, 11 Aug 2023 07:20:33 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A25412127 for ; Fri, 11 Aug 2023 04:20:22 -0700 (PDT) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230811112020epoutp01476bdf6df152808276aa8a0018827bc7~6UDoUwW542881128811epoutp01P for ; Fri, 11 Aug 2023 11:20:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230811112020epoutp01476bdf6df152808276aa8a0018827bc7~6UDoUwW542881128811epoutp01P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1691752820; bh=x8qLr8ri6WADzLyMzJJYyA//zxjzixbCr038TulbPXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mU519Yy+ca7sDxzXs9/ycVnhUI+CqGyHcNyPaKc/Mn74nck0E/1/UIxgIs7b+iWYl 6E78guV+eV8+6EazVYacv3oMSJbzbD9hU2QUYiVzEasaxXUB+DZ3ubP6n/aSJEVClv x3JatgWUVu7GFbBGpcI2z6nihoSSyRw5o0bb2GZ8= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20230811112019epcas5p2a57cf2476884422a636a175833c1f083~6UDnpMjsk0511305113epcas5p2o; Fri, 11 Aug 2023 11:20:19 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.175]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4RMhD140ltz4x9Py; Fri, 11 Aug 2023 11:20:17 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id B0.7D.55522.17916D46; Fri, 11 Aug 2023 20:20:17 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20230811105734epcas5p1b465394a301ba85f2c52ed7fde334f52~6TvwrRB2X2729727297epcas5p1n; Fri, 11 Aug 2023 10:57:34 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230811105734epsmtrp1ed176f2233ebaa42c1ef6e00e48f21d4~6TvwqSCzB0371503715epsmtrp1Q; Fri, 11 Aug 2023 10:57:34 +0000 (GMT) X-AuditID: b6c32a49-419ff7000000d8e2-eb-64d6197199e1 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 0D.01.30535.E1416D46; Fri, 11 Aug 2023 19:57:34 +0900 (KST) Received: from green245.sa.corp.samsungelectronics.net (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230811105729epsmtip2ef78d0d5cd04032b7b1ba24b0efdf868~6Tvr-w28T1482714827epsmtip2I; Fri, 11 Aug 2023 10:57:29 +0000 (GMT) From: Nitesh Shetty To: Jens Axboe , Jonathan Corbet , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, Keith Busch , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , Alexander Viro , Christian Brauner Cc: martin.petersen@oracle.com, mcgrof@kernel.org, dlemoal@kernel.org, gost.dev@samsung.com, Nitesh Shetty , 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 v14 06/11] fs, block: copy_file_range for def_blk_ops for direct block device Date: Fri, 11 Aug 2023 16:22:49 +0530 Message-Id: <20230811105300.15889-7-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20230811105300.15889-1-nj.shetty@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Tf1CTdRzH+z7PeBji8nFofIF0c2YJBmw41heDzODyKb2OO7S77Lg12RMg Yxv7IUlyDRxQeGwo5uUWv46ZCQI2lF9rhuOUH+lBcIIgmNk4Q34ZFVYgxTYo/3t93vd5fz8/ vvdh4uy/iUBmqlxDq+QSGY9YxWhsD94amhEwIOVP2QJRffd1HOUWP8FRzaiRQBPtswA52woA uvfdTmSfNnuhobYWDJ2vuYahk44BgMZumTBkH96GKvMtDPStvYuB+lu/JFD5V2Pe6FzHIoZu F48B1DhfjqO6iRkG6hwOQj1POrxef47qufsNg+q/qaWs1Z8RVIPlE8o2pCOoKkOJF1V0bJqg fh0bZlAzV24RlOFSNaB+s26krM4pLH71gbToFFoipVVcWp6kkKbKk2N4exLEseJIEV8QKohC r/C4ckk6HcOL2xsf+maqbGleHvewRKZdkuIlajUv/LVolUKrobkpCrUmhkcrpTKlUBmmlqSr tfLkMDmt2SHg8yMilxI/SEsZ7C0llBVrPnrYrPfWgYurC4EPE5JCONk+CgrBKiabtAFYYrXg nmAWwJacT708wRyA7WWTjBWL8bTFzWzSDuBfp2M9SXk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FfZNZPXqb37F5fHx6i8Xj/b6rbB59W1YxenzeJOex 6clbpgCeKC6blNSczLLUIn27BK6M6xfmshUs4K94taOFvYFxA08XIyeHhICJRP+0JSxdjFwc QgK7GSWO77vEBJGQlFj29wgzhC0ssfLfc3aIomYmiRcn/rJ1MXJwsAloS5z+zwESFxHoYpbo 3PmOBaSBWeAck8TJ2/wgtrBArMTLK1sYQWwWAVWJ9xcOgw3lFbCS+HPiOyvIHAkBfYn++4Ig YU4Ba4n3my6xgdhCQCUflh1khCgXlDg58wnUeHmJ5q2zmScwCsxCkpqFJLWAkWkVo2RqQXFu em6xYYFRXmq5XnFibnFpXrpecn7uJkZwnGpp7WDcs+qD3iFGJg7GQ4wSHMxKIry2wZdShHhT EiurUovy44tKc1KLDzFKc7AoifN+e92bIiSQnliSmp2aWpBaBJNl4uCUamBarm9pmbptUv63 RzuP+zaej/Jaq8F5fe+vz5utDd7rnY1klI15GnV8wlXbaXmdT9e/1kkNmi0tmC1u6ejVptYf rtkW+GZmTf3UvYsEdn3NiXOsmJt0SMioiKMlaOcn0a3+/kynqlfPb9vqZjc7i/fzn39O68/O rd29m2mn0QX2XSefpYaVNiX6iKTsD6m123VtvafcJ60OV6nsg/vOf3gfvilg16LZqzbEN2rc v/6++cccJ4uTd3cp+Ds3yDOmqfM7XJCt/lT26Si/xb4U32zTNl6V29qvrmpkXz0TXKIzWfzM wglhXgwRifd5J9zLfrkuevqcjPv5ixao3jh6pC8o9JvovL/nVv2+6lok/FZWiaU4I9FQi7mo OBEAh25GcEIDAAA= X-CMS-MailID: 20230811105734epcas5p1b465394a301ba85f2c52ed7fde334f52 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230811105734epcas5p1b465394a301ba85f2c52ed7fde334f52 References: <20230811105300.15889-1-nj.shetty@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org For direct block device opened with O_DIRECT, use copy_file_range to issue device copy offload, and fallback to generic_copy_file_range incase device copy offload capability is absent or the device files are not open with O_DIRECT. 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 eaa98a987213..f5cf061ea91b 100644 --- a/block/fops.c +++ b/block/fops.c @@ -738,6 +738,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; + } + if (copied != len) + 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) @@ -831,6 +855,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)