Linux NFS development
 help / color / mirror / Atom feed
From: Anna Schumaker <Anna.Schumaker@netapp.com>
To: <linux-nfs@vger.kernel.org>, <Trond.Myklebust@primarydata.com>,
	<bfields@fieldses.org>, <hch@infradead.org>
Subject: [RFC v1 4/3] vfs_copy_range() test program
Date: Thu, 3 Dec 2015 15:55:37 -0500	[thread overview]
Message-ID: <1449176137-4940-5-git-send-email-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <1449176137-4940-1-git-send-email-Anna.Schumaker@Netapp.com>

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 <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+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 <source> <destination>\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);
+}
-- 
2.6.3


  parent reply	other threads:[~2015-12-03 20:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-03 20:55 [PATCH v1 0/4] NFSv4.2: Add support for the COPY operation Anna Schumaker
2015-12-03 20:55 ` [PATCH v1 1/3] NFSD: Pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
2015-12-03 20:55 ` [PATCH v1 2/3] NFSD: Implement the COPY call Anna Schumaker
2015-12-04 15:45   ` J. Bruce Fields
2015-12-04 15:49     ` Anna Schumaker
2015-12-04 16:49       ` J. Bruce Fields
2015-12-04 17:05         ` Anna Schumaker
2015-12-04 17:14           ` J. Bruce Fields
2015-12-07 19:26   ` Christoph Hellwig
2015-12-07 21:03     ` Anna Schumaker
2015-12-03 20:55 ` [PATCH v1 3/3] NFS: Add COPY nfs operation Anna Schumaker
2015-12-07 19:28   ` Christoph Hellwig
2015-12-03 20:55 ` Anna Schumaker [this message]
2015-12-07 19:23 ` [PATCH v1 0/4] NFSv4.2: Add support for the COPY operation Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1449176137-4940-5-git-send-email-Anna.Schumaker@Netapp.com \
    --to=anna.schumaker@netapp.com \
    --cc=Trond.Myklebust@primarydata.com \
    --cc=bfields@fieldses.org \
    --cc=hch@infradead.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox