Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6953996rwb; Tue, 22 Nov 2022 23:16:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf7UMniaWsVRap0+HDVek4rZ5937f5GZ8hjC3wMR844cvlFn0A88WqyBQC1eTFo100BCkBCi X-Received: by 2002:a62:1ec2:0:b0:572:7b49:4f48 with SMTP id e185-20020a621ec2000000b005727b494f48mr8161465pfe.33.1669187798787; Tue, 22 Nov 2022 23:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669187798; cv=none; d=google.com; s=arc-20160816; b=RqubZPJ4fhVhkBTjR0wgbfm0qZrSIZeN2Pp2SarR/8feBBRMJ/7Et8f6zH354w4fzG Q3rKlUKUdnNH+iT00GcD5nP9BYXJWzGNywWbQ7iJ+ybAavyCKT2vDlsmkzfRngCrx42C im4BGW3/vtjxxxip3CfUMJEKh0eB60azOV5E5akxUGNnY4CB9ZTUX3WAix3/zZuUdehP hYf4/cC9HSFTg0m+W06Z/K4x6YmkiiQCRAvSwoEZ3OXWW1kvmClzpG2zPJT86ECSPfDo IlyHGzhJLgl8BF5YVLcHZdY0KlD/XqthuejxEscFogrLePwPOhoPRb1IxCNyT1+JGAnY G5Dw== 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=kSJ3dOFoktYoCaNlIORYzBMHiA2ANyobnZ0zDKBDF0g=; b=uyyjxes6iNgoBW0fxm91ZVbiKYjQTQzsKtV27k0533vPvFL1OJpq3hzWgNeqSK3C/q /Lici3c34vWQFHI409a/FzKQoZL7xLICXCIKY+C66lgROUvoYoC2ZNtQMI7ktiPiK7yk 6GoJg5OR6HnRTyMZFd9qefFVlde/VM+1JqyWhaxKCK1Auz+6U1lKsibJKAkQ9Xbf5/tk BB+0JtGAx/OW6kfw0+p8NZpBpKyFbgpgdn7+mDNxjt+KkWp2pxNxRZhUNaMSfjWPuGwr iUYCbHPEsw+K2+ol/NCDSi7B6gaTuDG/6E45IdEpvsfpOlM5hpJTQaNmsEBEDZJEMIiC d5kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=irJJ08Zs; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a17090a8b0900b0021870b9d3c7si995778pjn.45.2022.11.22.23.16.27; Tue, 22 Nov 2022 23:16:38 -0800 (PST) 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=irJJ08Zs; 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 S229479AbiKWGNz (ORCPT + 89 others); Wed, 23 Nov 2022 01:13:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235665AbiKWGNs (ORCPT ); Wed, 23 Nov 2022 01:13:48 -0500 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A19F2C39 for ; Tue, 22 Nov 2022 22:13:28 -0800 (PST) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20221123061327epoutp043ba03990302b904638fdbb1b0f48e75f~qIgLGhzHC2398123981epoutp04K for ; Wed, 23 Nov 2022 06:13:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20221123061327epoutp043ba03990302b904638fdbb1b0f48e75f~qIgLGhzHC2398123981epoutp04K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1669184007; bh=kSJ3dOFoktYoCaNlIORYzBMHiA2ANyobnZ0zDKBDF0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=irJJ08ZsN3oEw9hD9aN4LE/GRqVev9eqr5PfEF0Qrhglj/x9CtN4ASUwmM+oRznwc C4dg1nN1KdYHhnawh+88tmfa8g+WRIDTsQlg1tWdlwd0IxOGFqL/PimqlJUU2t0lPf ff4h8pRJcAy62beqThmpoLTr2RgVGQPll2UKiS/c= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20221123061326epcas5p1885bf1308a88e8eff224df73c203fb5d~qIgKc2Z0n0806708067epcas5p1V; Wed, 23 Nov 2022 06:13:26 +0000 (GMT) Received: from epsmges5p3new.samsung.com (unknown [182.195.38.180]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4NH9mN24Txz4x9Pp; Wed, 23 Nov 2022 06:13:24 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id AC.17.56352.40ABD736; Wed, 23 Nov 2022 15:13:24 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20221123061024epcas5p28fd0296018950d722b5a97e2875cf391~qIdhHT_sF0604106041epcas5p2s; Wed, 23 Nov 2022 06:10:24 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20221123061024epsmtrp256f8d5870cea901380bcaafd9741ed60~qIdhGOQih0451404514epsmtrp2V; Wed, 23 Nov 2022 06:10:24 +0000 (GMT) X-AuditID: b6c32a4b-383ff7000001dc20-db-637dba0497f2 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id FA.B2.18644.059BD736; Wed, 23 Nov 2022 15:10:24 +0900 (KST) Received: from test-zns.sa.corp.samsungelectronics.net (unknown [107.110.206.5]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20221123061021epsmtip1ff00839ccb85553e37f8279ede1fac88~qIdd9k6Z32063320633epsmtip1C; Wed, 23 Nov 2022 06:10:21 +0000 (GMT) From: Nitesh Shetty To: axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com, kbusch@kernel.org, hch@lst.de, sagi@grimberg.me, james.smart@broadcom.com, kch@nvidia.com, damien.lemoal@opensource.wdc.com, naohiro.aota@wdc.com, jth@kernel.org, viro@zeniv.linux.org.uk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org, linux-fsdevel@vger.kernel.org, anuj20.g@samsung.com, joshi.k@samsung.com, p.raghav@samsung.com, nitheshshetty@gmail.com, gost.dev@samsung.com, Nitesh Shetty , Hannes Reinecke , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH v5 04/10] block: Introduce a new ioctl for copy Date: Wed, 23 Nov 2022 11:28:21 +0530 Message-Id: <20221123055827.26996-5-nj.shetty@samsung.com> X-Mailer: git-send-email 2.35.1.500.gb896f729e2 In-Reply-To: <20221123055827.26996-1-nj.shetty@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA01Te1BUZRT3u/fu3QWkLo/0A8PWTWuAeCws8EEQTVJewwhoDMUmXOEGDMvu ug/FiHFNGBaK58SjhQkS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P31NmVVg385ebXH9RNuh0q fbN0y5cz0We92IIXMbIc7Y8oVGk/K3Gh87DslpkPJ6x+snL9lRzrBR4b66XZpvF/2PhIXfxO pM0USe/z+Yr6SyRmb1A4G62UUrnC1jd855nV4k9DlDZ4zpiq59wSsui6f+zKQ3vn23MY7Kr8 v/LmkuYsYc/wdbw5jye5O8g9TA3IZ18VU3o8VEX0z4RrFhsE/+/uWpRd/t+X59ZGz0v8UwVj xPh3ZrpGufRlnxLvW7RYwvP91t7lxfOzi38qTWPbtnEtw4kbrFVv43aozf108k3+FFmmwwGi R6Kbmr5z8nNceCpReTrraEyXzJ31fmeWTMgNetcRnt1lM1OJpTgj0VCLuag4EQDA19x3dQMA AA== X-CMS-MailID: 20221123061024epcas5p28fd0296018950d722b5a97e2875cf391 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20221123061024epcas5p28fd0296018950d722b5a97e2875cf391 References: <20221123055827.26996-1-nj.shetty@samsung.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 Add new BLKCOPY ioctl that offloads copying of one or more sources ranges to one or more destination in a device. COPY ioctl accepts a 'copy_range' structure that contains no of range, a reserved field , followed by an array of ranges. Each source range is represented by 'range_entry' that contains source start offset, destination start offset and length of source ranges (in bytes) MAX_COPY_NR_RANGE, limits the number of entries for the IOCTL and MAX_COPY_TOTAL_LENGTH limits the total copy length, IOCTL can handle. Example code, to issue BLKCOPY: /* Sample example to copy three entries with [dest,src,len], * [32768, 0, 4096] [36864, 4096, 4096] [40960,8192,4096] on same device */ int main(void) { int i, ret, fd; unsigned long src = 0, dst = 32768, len = 4096; struct copy_range *cr; cr = (struct copy_range *)malloc(sizeof(*cr)+ (sizeof(struct range_entry)*3)); cr->nr_range = 3; cr->reserved = 0; for (i = 0; i< cr->nr_range; i++, src += len, dst += len) { cr->ranges[i].dst = dst; cr->ranges[i].src = src; cr->ranges[i].len = len; cr->ranges[i].comp_len = 0; } fd = open("/dev/nvme0n1", O_RDWR); if (fd < 0) return 1; ret = ioctl(fd, BLKCOPY, cr); if (ret != 0) printf("copy failed, ret= %d\n", ret); for (i=0; i< cr->nr_range; i++) if (cr->ranges[i].len != cr->ranges[i].comp_len) printf("Partial copy for entry %d: requested %llu, completed %llu\n", i, cr->ranges[i].len, cr->ranges[i].comp_len); close(fd); free(cr); return ret; } Reviewed-by: Hannes Reinecke Signed-off-by: Nitesh Shetty Signed-off-by: Javier González Signed-off-by: Anuj Gupta --- block/ioctl.c | 36 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/fs.h | 9 +++++++++ 2 files changed, 45 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index 60121e89052b..7daf76199161 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -120,6 +120,40 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode, return err; } +static int blk_ioctl_copy(struct block_device *bdev, fmode_t mode, + unsigned long arg) +{ + struct copy_range ucopy_range, *kcopy_range = NULL; + size_t payload_size = 0; + int ret; + + if (!(mode & FMODE_WRITE)) + return -EBADF; + + if (copy_from_user(&ucopy_range, (void __user *)arg, + sizeof(ucopy_range))) + return -EFAULT; + + if (unlikely(!ucopy_range.nr_range || ucopy_range.reserved || + ucopy_range.nr_range >= MAX_COPY_NR_RANGE)) + return -EINVAL; + + payload_size = (ucopy_range.nr_range * sizeof(struct range_entry)) + + sizeof(ucopy_range); + + kcopy_range = memdup_user((void __user *)arg, payload_size); + if (IS_ERR(kcopy_range)) + return PTR_ERR(kcopy_range); + + ret = blkdev_issue_copy(bdev, bdev, kcopy_range->ranges, + kcopy_range->nr_range, NULL, NULL, GFP_KERNEL); + if (copy_to_user((void __user *)arg, kcopy_range, payload_size)) + ret = -EFAULT; + + kfree(kcopy_range); + return ret; +} + static int blk_ioctl_secure_erase(struct block_device *bdev, fmode_t mode, void __user *argp) { @@ -481,6 +515,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, return blk_ioctl_discard(bdev, mode, arg); case BLKSECDISCARD: return blk_ioctl_secure_erase(bdev, mode, argp); + case BLKCOPY: + return blk_ioctl_copy(bdev, mode, arg); case BLKZEROOUT: return blk_ioctl_zeroout(bdev, mode, arg); case BLKGETDISKSEQ: diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 9248b6d259de..8af10b926a6f 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -82,6 +82,14 @@ struct range_entry { __u64 comp_len; }; +struct copy_range { + __u64 nr_range; + __u64 reserved; + + /* Ranges always must be at the end */ + struct range_entry ranges[]; +}; + /* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */ #define FILE_DEDUPE_RANGE_SAME 0 #define FILE_DEDUPE_RANGE_DIFFERS 1 @@ -203,6 +211,7 @@ struct fsxattr { #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) #define BLKGETDISKSEQ _IOR(0x12,128,__u64) +#define BLKCOPY _IOWR(0x12, 129, struct copy_range) /* * A jump here: 130-136 are reserved for zoned block devices * (see uapi/linux/blkzoned.h) -- 2.35.1.500.gb896f729e2