From patchwork Tue Mar 8 21:55:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schumaker, Anna" X-Patchwork-Id: 8538011 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 707E1C0554 for ; Tue, 8 Mar 2016 21:56:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9AD852020F for ; Tue, 8 Mar 2016 21:56:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.kernel.org 9AD852020F Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC055201FA for ; Tue, 8 Mar 2016 21:56:24 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.kernel.org AC055201FA Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750974AbcCHV4X (ORCPT ); Tue, 8 Mar 2016 16:56:23 -0500 Received: from mx141.netapp.com ([216.240.21.12]:13231 "EHLO mx141.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750984AbcCHV4W (ORCPT ); Tue, 8 Mar 2016 16:56:22 -0500 X-IronPort-AV: E=Sophos;i="5.22,558,1449561600"; d="scan'208";a="105066532" Received: from vmwexchts01-prd.hq.netapp.com ([10.122.105.12]) by mx141-out.netapp.com with ESMTP; 08 Mar 2016 13:56:05 -0800 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCHTS01-PRD.hq.netapp.com (10.122.105.12) with Microsoft SMTP Server id 15.0.1156.6; Tue, 8 Mar 2016 13:56:05 -0800 Received: from davros.com ([10.63.232.73]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id u28Lu0pO024619; Tue, 8 Mar 2016 13:56:04 -0800 (PST) From: Anna Schumaker To: , , , Subject: [PATCH v3 4/3] vfs_copy_range() test program Date: Tue, 8 Mar 2016 16:55:58 -0500 Message-ID: <1457474158-16050-5-git-send-email-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.7.2 In-Reply-To: <1457474158-16050-1-git-send-email-Anna.Schumaker@Netapp.com> References: <1457474158-16050-1-git-send-email-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a simple C program that I used for calling the copy system call. Usage: ./nfscopy /nfs/original.txt /nfs/copy.txt --- nfscopy.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 nfscopy.c diff --git a/nfscopy.c b/nfscopy.c new file mode 100644 index 0000000..3417a14 --- /dev/null +++ b/nfscopy.c @@ -0,0 +1,59 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +loff_t copy_file_range(int fd_in, loff_t *off_in, int fd_out, + loff_t *off_out, size_t len, unsigned int flags) +{ + return syscall(__NR_copy_file_range, fd_in, off_in, fd_out, + off_out, len, flags); +} + +int main(int argc, char **argv) +{ + int fd_in, fd_out; + struct stat stat; + loff_t len, ret; + char buf[2]; + + if (argc != 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(EXIT_FAILURE); + } + + fd_in = open(argv[1], O_RDONLY); + if (fd_in == -1) { + perror("open (argv[1])"); + exit(EXIT_FAILURE); + } + + if (fstat(fd_in, &stat) == -1) { + perror("fstat"); + exit(EXIT_FAILURE); + } + len = stat.st_size; + + fd_out = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC, 0644); + if (fd_out == -1) { + perror("open (argv[2])"); + exit(EXIT_FAILURE); + } + + do { + ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0); + if (ret == -1) { + perror("copy_file_range"); + exit(EXIT_FAILURE); + } + + len -= ret; + } while (len > 0); + + close(fd_in); + close(fd_out); + exit(EXIT_SUCCESS); +}