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: 134469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1070133vqi; Fri, 11 Aug 2023 05:56:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENzbYcKIO+HXnPUr+vajoUbFV2hG9ERW8eq9/AX577OHfhHRSs5cokAiOtrgUJCdB316ux X-Received: by 2002:a05:6402:1807:b0:523:100b:70da with SMTP id g7-20020a056402180700b00523100b70damr2278902edy.4.1691758606865; Fri, 11 Aug 2023 05:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691758606; cv=none; d=google.com; s=arc-20160816; b=BzrZ1zkIhs70zDwAwlNr39O29q8pLN+IUndBTS+7yxvdj3uKhGoQ7aX9yD+tRGU/q/ 2xckGLAnQ4h8tP4OGLx1ciSaUGCS1L2ukBw/y2hphW9MUMtDw0pgBHAsJckS05R4pywl RnqIUnV1LZiCkuP/jeg2x4QQDt/9GFGajDcGRB3DWiFjbLyvNKuRo9yc3CG5gn2Z/6lj kS1B06v1z61VDfKiAcVoMEKljzQ2Y2cBDsqmG/PiRANzUZ9ManaX57BMcsGobhZusyJc Hxj6kJ5SJrk/ujmbNYp+AI7oQ3GpJ56e639By0/LOf9o7I9Jpy4uZe/dB0QpT2zfNl86 s2VQ== 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=x8qLr8ri6WADzLyMzJJYyA//zxjzixbCr038TulbPXo=; fh=ngsmI8aE3RpUmoI8tAOm4Z9QFgasCJTxHYub8aR42dk=; b=mehzw3pcITEC7JQ3EfznXtXXAnsxwyjDoLZN9kXhuodp1Y3tMfOkbFZHD0PEqdV2TF EENKKOO+q5+SO+P/qPcvAPf6P0CdZc6Bukf6EuB3OI8uipPB0IU8F0aFmXnsglGwrAMc jsvqN7dxYgFWmtFb+tr0RdBgFiU1YA18DUrIYxi5Zb+zCdA2W0xQUUd/YDYdnlZqj0r0 Y6aRfvnXRcJX7O9FaXIqhLWL/tPRJZ5XsSkyYmaNPjASBNMoevR0451X0KA+PCuoeb+G TbXR5TPKvo37QSEHAMjWstxYXxRHuN6nn/l/PGFT7/7j+o8OAwdY6xElFMuPjnX2FguU UmPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mU519Yy+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a056402181600b00523a48d9983si2678546edy.603.2023.08.11.05.56.23; Fri, 11 Aug 2023 05:56:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=mU519Yy+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236119AbjHKLUp (ORCPT + 99 others); Fri, 11 Aug 2023 07:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236346AbjHKLUd (ORCPT ); Fri, 11 Aug 2023 07:20:33 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E9A2129 for ; Fri, 11 Aug 2023 04:20:22 -0700 (PDT) Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230811112020epoutp0409ede3e870284607565e1cd9bd974e73~6UDoVM9Nt1279312793epoutp04L for ; Fri, 11 Aug 2023 11:20:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230811112020epoutp0409ede3e870284607565e1cd9bd974e73~6UDoVM9Nt1279312793epoutp04L 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: H4s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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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773937472679445315 X-GMAIL-MSGID: 1773937472679445315 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)