linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation
@ 2015-12-18 21:05 Anna Schumaker
  2015-12-18 21:05 ` [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Anna Schumaker @ 2015-12-18 21:05 UTC (permalink / raw)
  To: linux-nfs, Trond.Myklebust, bfields, hch

These patches add client and server support for the NFS v4.2 COPY operation,
and depend on the new copy_file_range() system call currently scheduled for
Linux 4.5.

Changes in v2:
- Preprocess filehandle op can choose between current_fh and save_fh
- NFSD doesnt' need to fsync() after vfs_copy_file_range() call
- Mark file as NFS_UNSTABLE in the copy return
- The client should send a commit if the file is copied with anything other
  than NFS_FILE_SYNC
- Fix conflicts with CLONE

Questions, comments, and other testing ideas would be greatly appreciated!

Thanks,
Anna


Anna Schumaker (4):
  NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op()
  NFSD: Implement the COPY call
  NFS: Add COPY nfs operation
  vfs_copy_range() test program

 fs/nfs/nfs42.h            |   1 +
 fs/nfs/nfs42proc.c        | 100 +++++++++++++++++++++++++++++++
 fs/nfs/nfs42xdr.c         | 146 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs4file.c         |  23 ++++++++
 fs/nfs/nfs4proc.c         |   1 +
 fs/nfs/nfs4xdr.c          |   1 +
 fs/nfs/objlayout/Makefile |   0
 fs/nfsd/nfs4proc.c        | 110 +++++++++++++++++++++++++++-------
 fs/nfsd/nfs4state.c       |  10 +++-
 fs/nfsd/nfs4xdr.c         |  62 +++++++++++++++++++-
 fs/nfsd/state.h           |   7 ++-
 fs/nfsd/vfs.c             |  20 +++++++
 fs/nfsd/vfs.h             |   1 +
 fs/nfsd/xdr4.h            |  23 ++++++++
 include/linux/nfs4.h      |   1 +
 include/linux/nfs_fs_sb.h |   1 +
 include/linux/nfs_xdr.h   |  27 +++++++++
 nfscopy.c                 |  59 +++++++++++++++++++
 18 files changed, 563 insertions(+), 30 deletions(-)
 create mode 100644 fs/nfs/objlayout/Makefile
 create mode 100644 nfscopy.c

-- 
2.6.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op()
  2015-12-18 21:05 [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation Anna Schumaker
@ 2015-12-18 21:05 ` Anna Schumaker
  2015-12-20 15:45   ` Christoph Hellwig
  2015-12-18 21:05 ` [PATCH v2 2/3] NFSD: Implement the COPY call Anna Schumaker
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Anna Schumaker @ 2015-12-18 21:05 UTC (permalink / raw)
  To: linux-nfs, Trond.Myklebust, bfields, hch

This reverts commit 3679e4c1ef1c00ea30d15b9ae59089b44dfe4137.

We either pass the current_fh or save_fh from the cstate structure, and
not some generic filehandle.  Let's just add a flag to pick between these
two filehandles instead.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 fs/nfs/objlayout/Makefile |  0
 fs/nfsd/nfs4proc.c        | 24 +++++++++++-------------
 fs/nfsd/nfs4state.c       | 10 +++++++---
 fs/nfsd/state.h           |  7 ++++---
 4 files changed, 22 insertions(+), 19 deletions(-)
 create mode 100644 fs/nfs/objlayout/Makefile

diff --git a/fs/nfs/objlayout/Makefile b/fs/nfs/objlayout/Makefile
new file mode 100644
index 0000000..e69de29
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 819ad81..4fbc86b 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -774,9 +774,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
 
 	/* check stateid */
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
-					&read->rd_stateid, RD_STATE,
-					&read->rd_filp, &read->rd_tmp_file);
+	status = nfs4_preprocess_stateid_op(rqstp, cstate, &read->rd_stateid,
+			RD_STATE, &read->rd_filp, &read->rd_tmp_file);
 	if (status) {
 		dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
 		goto out;
@@ -922,8 +921,7 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
 	if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
 		status = nfs4_preprocess_stateid_op(rqstp, cstate,
-				&cstate->current_fh, &setattr->sa_stateid,
-				WR_STATE, NULL, NULL);
+			&setattr->sa_stateid, WR_STATE, NULL, NULL);
 		if (status) {
 			dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
 			return status;
@@ -987,8 +985,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	if (write->wr_offset >= OFFSET_MAX)
 		return nfserr_inval;
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
-						stateid, WR_STATE, &filp, NULL);
+	status = nfs4_preprocess_stateid_op(rqstp, cstate, stateid, WR_STATE,
+			&filp, NULL);
 	if (status) {
 		dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
 		return status;
@@ -1018,15 +1016,15 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	struct file *src, *dst;
 	__be32 status;
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
-					    &clone->cl_src_stateid, RD_STATE,
-					    &src, NULL);
+	status = nfs4_preprocess_stateid_op(rqstp, cstate,
+					    &clone->cl_src_stateid,
+					    RD_STATE | SAVED_STATE, &src, NULL);
 	if (status) {
 		dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
 		goto out;
 	}
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
+	status = nfs4_preprocess_stateid_op(rqstp, cstate,
 					    &clone->cl_dst_stateid, WR_STATE,
 					    &dst, NULL);
 	if (status) {
@@ -1059,7 +1057,7 @@ nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	__be32 status = nfserr_notsupp;
 	struct file *file;
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
+	status = nfs4_preprocess_stateid_op(rqstp, cstate,
 					    &fallocate->falloc_stateid,
 					    WR_STATE, &file, NULL);
 	if (status != nfs_ok) {
@@ -1098,7 +1096,7 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	__be32 status;
 	struct file *file;
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
+	status = nfs4_preprocess_stateid_op(rqstp, cstate,
 					    &seek->seek_stateid,
 					    RD_STATE, &file, NULL);
 	if (status) {
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index df5dba6..aea9504 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4797,10 +4797,11 @@ nfs4_check_file(struct svc_rqst *rqstp, struct svc_fh *fhp, struct nfs4_stid *s,
  */
 __be32
 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
-		struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
-		stateid_t *stateid, int flags, struct file **filpp, bool *tmp_file)
+		struct nfsd4_compound_state *cstate, stateid_t *stateid,
+		int flags, struct file **filpp, bool *tmp_file)
 {
-	struct inode *ino = d_inode(fhp->fh_dentry);
+	struct svc_fh *fhp = &cstate->current_fh;
+	struct inode *ino;
 	struct net *net = SVC_NET(rqstp);
 	struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 	struct nfs4_stid *s = NULL;
@@ -4810,6 +4811,9 @@ nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
 		*filpp = NULL;
 	if (tmp_file)
 		*tmp_file = false;
+	if (flags & SAVED_STATE)
+		fhp = &cstate->save_fh;
+	ino = d_inode(fhp->fh_dentry);
 
 	if (grace_disallows_io(net, ino))
 		return nfserr_grace;
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index 99432b7..c6c92bc 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -562,9 +562,10 @@ static inline struct nfs4_layout_stateid *layoutstateid(struct nfs4_stid *s)
 	return container_of(s, struct nfs4_layout_stateid, ls_stid);
 }
 
-/* flags for preprocess_seqid_op() */
+/* flags for preprocess_seqid_op() and preprocess_stateid_op() */
 #define RD_STATE	        0x00000010
 #define WR_STATE	        0x00000020
+#define SAVED_STATE	        0x00000040
 
 enum nfsd4_cb_op {
 	NFSPROC4_CLNT_CB_NULL = 0,
@@ -578,8 +579,8 @@ struct nfsd4_compound_state;
 struct nfsd_net;
 
 extern __be32 nfs4_preprocess_stateid_op(struct svc_rqst *rqstp,
-		struct nfsd4_compound_state *cstate, struct svc_fh *fhp,
-		stateid_t *stateid, int flags, struct file **filp, bool *tmp_file);
+		struct nfsd4_compound_state *cstate, stateid_t *stateid,
+		int flags, struct file **filp, bool *tmp_file);
 __be32 nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
 		     stateid_t *stateid, unsigned char typemask,
 		     struct nfs4_stid **s, struct nfsd_net *nn);
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/3] NFSD: Implement the COPY call
  2015-12-18 21:05 [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation Anna Schumaker
  2015-12-18 21:05 ` [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
@ 2015-12-18 21:05 ` Anna Schumaker
  2015-12-20 15:50   ` Christoph Hellwig
  2015-12-18 21:05 ` [PATCH v2 3/3] NFS: Add COPY nfs operation Anna Schumaker
  2015-12-18 21:05 ` [RFC v2 4/3] vfs_copy_range() test program Anna Schumaker
  3 siblings, 1 reply; 11+ messages in thread
From: Anna Schumaker @ 2015-12-18 21:05 UTC (permalink / raw)
  To: linux-nfs, Trond.Myklebust, bfields, hch

From: Anna Schumaker <Anna.Schumaker@netapp.com>

I only implemented the sync version of this call, since it's the
easiest.  I can simply call vfs_copy_range() and have the vfs do the
right thing for the filesystem being exported.

Signed-off-by: Anna Schumaker <bjschuma@netapp.com>
---
v2:
- Don't fsync() after copy
- Tell client that the result is NFS_UNSTABLE
- Fix conflicts with clone
---
 fs/nfsd/nfs4proc.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++--------
 fs/nfsd/nfs4xdr.c  | 62 +++++++++++++++++++++++++++++++++--
 fs/nfsd/vfs.c      | 20 ++++++++++++
 fs/nfsd/vfs.h      |  1 +
 fs/nfsd/xdr4.h     | 23 +++++++++++++
 5 files changed, 185 insertions(+), 15 deletions(-)

diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 4fbc86b..4a76ba1 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -1010,47 +1010,97 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 }
 
 static __be32
-nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
-		struct nfsd4_clone *clone)
+nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+		  stateid_t *src_stateid, struct file **src,
+		  stateid_t *dst_stateid, struct file **dst)
 {
-	struct file *src, *dst;
 	__be32 status;
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate,
-					    &clone->cl_src_stateid,
-					    RD_STATE | SAVED_STATE, &src, NULL);
+	status = nfs4_preprocess_stateid_op(rqstp, cstate, src_stateid,
+					    RD_STATE | SAVED_STATE, src, NULL);
 	if (status) {
 		dprintk("NFSD: %s: couldn't process src stateid!\n", __func__);
 		goto out;
 	}
 
-	status = nfs4_preprocess_stateid_op(rqstp, cstate,
-					    &clone->cl_dst_stateid, WR_STATE,
-					    &dst, NULL);
+	status = nfs4_preprocess_stateid_op(rqstp, cstate, dst_stateid,
+					    WR_STATE, dst, NULL);
 	if (status) {
 		dprintk("NFSD: %s: couldn't process dst stateid!\n", __func__);
 		goto out_put_src;
 	}
 
 	/* fix up for NFS-specific error code */
-	if (!S_ISREG(file_inode(src)->i_mode) ||
-	    !S_ISREG(file_inode(dst)->i_mode)) {
+	if (!S_ISREG(file_inode(*src)->i_mode) ||
+	    !S_ISREG(file_inode(*dst)->i_mode)) {
 		status = nfserr_wrong_type;
 		goto out_put_dst;
 	}
 
+out:
+	return status;
+out_put_dst:
+	fput(*dst);
+out_put_src:
+	fput(*src);
+	goto out;
+}
+
+static __be32
+nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+		struct nfsd4_clone *clone)
+{
+	struct file *src, *dst;
+	__be32 status;
+
+	status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
+				   &clone->cl_dst_stateid, &dst);
+	if (status)
+		goto out;
+
 	status = nfsd4_clone_file_range(src, clone->cl_src_pos,
 			dst, clone->cl_dst_pos, clone->cl_count);
 
-out_put_dst:
 	fput(dst);
-out_put_src:
 	fput(src);
 out:
 	return status;
 }
 
 static __be32
+nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+		struct nfsd4_copy *copy)
+{
+	struct file *src, *dst;
+	__be32 status;
+	ssize_t bytes;
+
+	status = nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid, &src,
+				   &copy->cp_dst_stateid, &dst);
+	if (status)
+		goto out;
+
+	bytes = nfsd_copy_range(src, copy->cp_src_pos, dst, copy->cp_dst_pos,
+				copy->cp_count);
+
+	if (bytes < 0)
+		status = nfserrno(bytes);
+	else {
+		copy->cp_res.wr_bytes_written = bytes;
+		copy->cp_res.wr_stable_how = NFS_UNSTABLE;
+		copy->cp_consecutive = 1;
+		copy->cp_synchronous = 1;
+		gen_boot_verifier(&copy->cp_res.wr_verifier, SVC_NET(rqstp));
+		status = nfs_ok;
+	}
+
+	fput(src);
+	fput(dst);
+out:
+	return status;
+}
+
+static __be32
 nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		struct nfsd4_fallocate *fallocate, int flags)
 {
@@ -1964,6 +2014,18 @@ static inline u32 nfsd4_create_session_rsize(struct svc_rqst *rqstp, struct nfsd
 		op_encode_channel_attrs_maxsz) * sizeof(__be32);
 }
 
+static inline u32 nfsd4_copy_rsize(struct svc_rqst *rqstp, struct nfsd4_op *op)
+{
+	return (op_encode_hdr_size +
+		1 /* wr_callback */ +
+		op_encode_stateid_maxsz /* wr_callback */ +
+		2 /* wr_count */ +
+		1 /* wr_committed */ +
+		op_encode_verifier_maxsz +
+		1 /* cr_consecutive */ +
+		1 /* cr_synchronous */) * sizeof(__be32);
+}
+
 #ifdef CONFIG_NFSD_PNFS
 /*
  * At this stage we don't really know what layout driver will handle the request,
@@ -2326,6 +2388,12 @@ static struct nfsd4_operation nfsd4_ops[] = {
 		.op_name = "OP_CLONE",
 		.op_rsize_bop = (nfsd4op_rsize)nfsd4_only_status_rsize,
 	},
+	[OP_COPY] = {
+		.op_func = (nfsd4op_func)nfsd4_copy,
+		.op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
+		.op_name = "OP_COPY",
+		.op_rsize_bop = (nfsd4op_rsize)nfsd4_copy_rsize,
+	},
 	[OP_SEEK] = {
 		.op_func = (nfsd4op_func)nfsd4_seek,
 		.op_name = "OP_SEEK",
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 924416f..21a8e6b 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1694,6 +1694,30 @@ nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone)
 }
 
 static __be32
+nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
+{
+	DECODE_HEAD;
+	unsigned int tmp;
+
+	status = nfsd4_decode_stateid(argp, &copy->cp_src_stateid);
+	if (status)
+		return status;
+	status = nfsd4_decode_stateid(argp, &copy->cp_dst_stateid);
+	if (status)
+		return status;
+
+	READ_BUF(8 + 8 + 8 + 4 + 4 + 4);
+	p = xdr_decode_hyper(p, &copy->cp_src_pos);
+	p = xdr_decode_hyper(p, &copy->cp_dst_pos);
+	p = xdr_decode_hyper(p, &copy->cp_count);
+	copy->cp_consecutive = be32_to_cpup(p++);
+	copy->cp_synchronous = be32_to_cpup(p++);
+	tmp = be32_to_cpup(p); /* Source server list not supported */
+
+	DECODE_TAIL;
+}
+
+static __be32
 nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek)
 {
 	DECODE_HEAD;
@@ -1793,7 +1817,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
 
 	/* new operations for NFSv4.2 */
 	[OP_ALLOCATE]		= (nfsd4_dec)nfsd4_decode_fallocate,
-	[OP_COPY]		= (nfsd4_dec)nfsd4_decode_notsupp,
+	[OP_COPY]		= (nfsd4_dec)nfsd4_decode_copy,
 	[OP_COPY_NOTIFY]	= (nfsd4_dec)nfsd4_decode_notsupp,
 	[OP_DEALLOCATE]		= (nfsd4_dec)nfsd4_decode_fallocate,
 	[OP_IO_ADVISE]		= (nfsd4_dec)nfsd4_decode_notsupp,
@@ -4203,6 +4227,40 @@ nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr,
 #endif /* CONFIG_NFSD_PNFS */
 
 static __be32
+nfsd42_encode_write_res(struct nfsd4_compoundres *resp, struct nfsd42_write_res *write)
+{
+	__be32 *p;
+
+	p = xdr_reserve_space(&resp->xdr, 4 + 8 + 4 + NFS4_VERIFIER_SIZE);
+	if (!p)
+		return nfserr_resource;
+
+	*p++ = cpu_to_be32(0);
+	p = xdr_encode_hyper(p, write->wr_bytes_written);
+	*p++ = cpu_to_be32(write->wr_stable_how);
+	p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, NFS4_VERIFIER_SIZE);
+	return nfs_ok;
+}
+
+static __be32
+nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
+		  struct nfsd4_copy *copy)
+{
+	__be32 *p, err;
+
+	if (!nfserr) {
+		err = nfsd42_encode_write_res(resp, &copy->cp_res);
+		if (err)
+			return err;
+
+		p = xdr_reserve_space(&resp->xdr, 4 + 4);
+		*p++ = cpu_to_be32(copy->cp_consecutive);
+		*p++ = cpu_to_be32(copy->cp_synchronous);
+	}
+	return nfserr;
+}
+
+static __be32
 nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr,
 		  struct nfsd4_seek *seek)
 {
@@ -4301,7 +4359,7 @@ static nfsd4_enc nfsd4_enc_ops[] = {
 
 	/* NFSv4.2 operations */
 	[OP_ALLOCATE]		= (nfsd4_enc)nfsd4_encode_noop,
-	[OP_COPY]		= (nfsd4_enc)nfsd4_encode_noop,
+	[OP_COPY]		= (nfsd4_enc)nfsd4_encode_copy,
 	[OP_COPY_NOTIFY]	= (nfsd4_enc)nfsd4_encode_noop,
 	[OP_DEALLOCATE]		= (nfsd4_enc)nfsd4_encode_noop,
 	[OP_IO_ADVISE]		= (nfsd4_enc)nfsd4_encode_noop,
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 5411bf0..d25aeed 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -506,6 +506,26 @@ __be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst,
 			count));
 }
 
+ssize_t nfsd_copy_range(struct file *src, u64 src_pos,
+		        struct file *dst, u64 dst_pos,
+		        u64 count)
+{
+	//u64 limit = 0x800000; /* 4 MB */
+	//u64 limit = 0x1000000; /* 8 MB */
+	//u64 limit = 0x2000000; /* 16 MB */
+	//u64 limit = 0x4000000; /* 32 MB */
+	//u64 limit = 0x8000000; /* 64 MB */
+	//u64 limit = 0x10000000; /* 128 MB */
+	//u64 limit = 0x10000000; /* 256 MB */
+	//u64 limit = 0x20000000; /* 512 MB */
+	//u64 limit = 0x40000000; /* 1024 MB */
+	//u64 limit = 0x80000000; /* 2048 MB */
+
+	//if (count > limit)
+	//	count = limit;
+	return vfs_copy_file_range(src, src_pos, dst, dst_pos, count, 0);
+}
+
 __be32 nfsd4_vfs_fallocate(struct svc_rqst *rqstp, struct svc_fh *fhp,
 			   struct file *file, loff_t offset, loff_t len,
 			   int flags)
diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h
index c11ba31..e36c497 100644
--- a/fs/nfsd/vfs.h
+++ b/fs/nfsd/vfs.h
@@ -93,6 +93,7 @@ __be32		nfsd_symlink(struct svc_rqst *, struct svc_fh *,
 				struct svc_fh *res);
 __be32		nfsd_link(struct svc_rqst *, struct svc_fh *,
 				char *, int, struct svc_fh *);
+ssize_t		nfsd_copy_range(struct file *, u64, struct file *, u64, u64);
 __be32		nfsd_rename(struct svc_rqst *,
 				struct svc_fh *, char *, int,
 				struct svc_fh *, char *, int);
diff --git a/fs/nfsd/xdr4.h b/fs/nfsd/xdr4.h
index d955481..2cad349 100644
--- a/fs/nfsd/xdr4.h
+++ b/fs/nfsd/xdr4.h
@@ -500,6 +500,28 @@ struct nfsd4_clone {
 	u64		cl_count;
 };
 
+struct nfsd42_write_res {
+	u64			wr_bytes_written;
+	u32			wr_stable_how;
+	nfs4_verifier		wr_verifier;
+};
+
+struct nfsd4_copy {
+	/* request */
+	stateid_t	cp_src_stateid;
+	stateid_t	cp_dst_stateid;
+	u64		cp_src_pos;
+	u64		cp_dst_pos;
+	u64		cp_count;
+
+	/* both */
+	bool		cp_consecutive;
+	bool		cp_synchronous;
+
+	/* response */
+	struct nfsd42_write_res	cp_res;
+};
+
 struct nfsd4_seek {
 	/* request */
 	stateid_t	seek_stateid;
@@ -565,6 +587,7 @@ struct nfsd4_op {
 		struct nfsd4_fallocate		allocate;
 		struct nfsd4_fallocate		deallocate;
 		struct nfsd4_clone		clone;
+		struct nfsd4_copy		copy;
 		struct nfsd4_seek		seek;
 	} u;
 	struct nfs4_replay *			replay;
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/3] NFS: Add COPY nfs operation
  2015-12-18 21:05 [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation Anna Schumaker
  2015-12-18 21:05 ` [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
  2015-12-18 21:05 ` [PATCH v2 2/3] NFSD: Implement the COPY call Anna Schumaker
@ 2015-12-18 21:05 ` Anna Schumaker
  2015-12-20 15:53   ` Christoph Hellwig
  2015-12-18 21:05 ` [RFC v2 4/3] vfs_copy_range() test program Anna Schumaker
  3 siblings, 1 reply; 11+ messages in thread
From: Anna Schumaker @ 2015-12-18 21:05 UTC (permalink / raw)
  To: linux-nfs, Trond.Myklebust, bfields, hch

From: Anna Schumaker <Anna.Schumaker@netapp.com>

This adds the copy_range file_ops function pointer used by the
sys_copy_range() function call.  This patch only implements sync copies,
so if an async copy happens we decode the stateid and ignore it.

Signed-off-by: Anna Schumaker <bjschuma@netapp.com>
---
v2:
- Send a commit if the server tells us anything except NFS_FILE_SYNC
- Truncate the pagecache of the destination file
---
 fs/nfs/nfs42.h            |   1 +
 fs/nfs/nfs42proc.c        | 100 +++++++++++++++++++++++++++++++
 fs/nfs/nfs42xdr.c         | 146 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs4file.c         |  23 ++++++++
 fs/nfs/nfs4proc.c         |   1 +
 fs/nfs/nfs4xdr.c          |   1 +
 include/linux/nfs4.h      |   1 +
 include/linux/nfs_fs_sb.h |   1 +
 include/linux/nfs_xdr.h   |  27 +++++++++
 9 files changed, 301 insertions(+)

diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h
index b587ccd..b6cd153 100644
--- a/fs/nfs/nfs42.h
+++ b/fs/nfs/nfs42.h
@@ -13,6 +13,7 @@
 
 /* nfs4.2proc.c */
 int nfs42_proc_allocate(struct file *, loff_t, loff_t);
+ssize_t nfs42_proc_copy(struct file *, loff_t, struct file *, loff_t, size_t);
 int nfs42_proc_deallocate(struct file *, loff_t, loff_t);
 loff_t nfs42_proc_llseek(struct file *, loff_t, int);
 int nfs42_proc_layoutstats_generic(struct nfs_server *,
diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c
index 6b1ce98..fb1531b 100644
--- a/fs/nfs/nfs42proc.c
+++ b/fs/nfs/nfs42proc.c
@@ -135,6 +135,106 @@ int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len)
 	return err;
 }
 
+static int nfs42_proc_commit(struct file *file, loff_t pos, size_t count)
+{
+	struct nfs_server *server = NFS_SERVER(file_inode(file));
+	struct nfs_fattr *fattr   = nfs_alloc_fattr();
+	struct nfs_writeverf verf;
+	struct nfs_commitargs args = {
+		.fh     = NFS_FH(file_inode(file)),
+		.offset = pos,
+		.count  = count,
+	};
+	struct nfs_commitres res = {
+		.server = server,
+		.fattr  = fattr,
+		.verf   = &verf,
+	};
+	struct rpc_message msg = {
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
+		.rpc_argp = &args,
+		.rpc_resp = &res,
+	};
+	unsigned int status;
+
+	status = nfs4_call_sync(server->client, server, &msg, &args.seq_args,
+			      &res.seq_res, 0);
+	nfs_free_fattr(fattr);
+	return status;
+}
+
+static ssize_t _nfs42_proc_copy(struct file *src, loff_t pos_src,
+				struct file *dst, loff_t pos_dst,
+				size_t count)
+{
+	struct nfs42_copy_args args = {
+		.src_fh		= NFS_FH(file_inode(src)),
+		.src_pos	= pos_src,
+		.dst_fh		= NFS_FH(file_inode(dst)),
+		.dst_pos	= pos_dst,
+		.count		= count,
+	};
+	struct nfs42_copy_res res;
+	struct rpc_message msg = {
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],
+		.rpc_argp = &args,
+		.rpc_resp = &res,
+	};
+	struct inode *dst_inode = file_inode(dst);
+	struct nfs_server *server = NFS_SERVER(dst_inode);
+	int status;
+
+	status = nfs42_set_rw_stateid(&args.src_stateid, src, FMODE_READ);
+	if (status)
+		return status;
+
+	status = nfs42_set_rw_stateid(&args.dst_stateid, dst, FMODE_WRITE);
+	if (status)
+		return status;
+
+	status = nfs4_call_sync(server->client, server, &msg,
+				&args.seq_args, &res.seq_res, 0);
+	if (status == -ENOTSUPP)
+		server->caps &= ~NFS_CAP_COPY;
+	if (status)
+		return status;
+
+	truncate_pagecache_range(dst_inode, pos_dst,
+				 pos_dst + res.write_res.count);
+
+	if (res.write_res.committed != NFS_FILE_SYNC) {
+		status = nfs42_proc_commit(dst, pos_dst, res.write_res.count);
+		if (status)
+			return status;
+	}
+
+	return res.write_res.count;
+}
+
+ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
+			struct file *dst, loff_t pos_dst,
+			size_t count)
+{
+	struct nfs_server *server = NFS_SERVER(file_inode(dst));
+	struct nfs4_exception exception = { };
+	ssize_t err;
+
+	if (!nfs_server_capable(file_inode(dst), NFS_CAP_COPY))
+		return -EOPNOTSUPP;
+
+	do {
+		mutex_lock(&file_inode(dst)->i_mutex);
+		err = _nfs42_proc_copy(src, pos_src, dst, pos_dst, count);
+		mutex_unlock(&file_inode(dst)->i_mutex);
+
+		if (err == -ENOTSUPP)
+			return -EOPNOTSUPP;
+		err = nfs4_handle_exception(server, err, &exception);
+	} while (exception.retry);
+
+	return err;
+}
+
 static loff_t _nfs42_proc_llseek(struct file *filep, loff_t offset, int whence)
 {
 	struct inode *inode = file_inode(filep);
diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
index 0ca482a..dd4a974 100644
--- a/fs/nfs/nfs42xdr.c
+++ b/fs/nfs/nfs42xdr.c
@@ -9,9 +9,22 @@
 #define encode_fallocate_maxsz		(encode_stateid_maxsz + \
 					 2 /* offset */ + \
 					 2 /* length */)
+#define NFS42_WRITE_RES_SIZE		(1 /* wr_callback_id size */ +\
+					 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
+					 2 /* wr_count */ + \
+					 1 /* wr_committed */ + \
+					 XDR_QUADLEN(NFS4_VERIFIER_SIZE))
 #define encode_allocate_maxsz		(op_encode_hdr_maxsz + \
 					 encode_fallocate_maxsz)
 #define decode_allocate_maxsz		(op_decode_hdr_maxsz)
+#define encode_copy_maxsz		(op_encode_hdr_maxsz +          \
+					 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
+					 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
+					 2 + 2 + 2 + 1 + 1 + 1)
+#define decode_copy_maxsz		(op_decode_hdr_maxsz + \
+					 NFS42_WRITE_RES_SIZE + \
+					 1 /* cr_consecutive */ + \
+					 1 /* cr_synchronous */)
 #define encode_deallocate_maxsz		(op_encode_hdr_maxsz + \
 					 encode_fallocate_maxsz)
 #define decode_deallocate_maxsz		(op_decode_hdr_maxsz)
@@ -49,6 +62,16 @@
 					 decode_putfh_maxsz + \
 					 decode_allocate_maxsz + \
 					 decode_getattr_maxsz)
+#define NFS4_enc_copy_sz		(compound_encode_hdr_maxsz + \
+					 encode_putfh_maxsz + \
+					 encode_savefh_maxsz + \
+					 encode_putfh_maxsz + \
+					 encode_copy_maxsz)
+#define NFS4_dec_copy_sz		(compound_decode_hdr_maxsz + \
+					 decode_putfh_maxsz + \
+					 decode_savefh_maxsz + \
+					 decode_putfh_maxsz + \
+					 decode_copy_maxsz)
 #define NFS4_enc_deallocate_sz		(compound_encode_hdr_maxsz + \
 					 encode_putfh_maxsz + \
 					 encode_deallocate_maxsz + \
@@ -102,6 +125,23 @@ static void encode_allocate(struct xdr_stream *xdr,
 	encode_fallocate(xdr, args);
 }
 
+static void encode_copy(struct xdr_stream *xdr,
+			struct nfs42_copy_args *args,
+			struct compound_hdr *hdr)
+{
+	encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
+	encode_nfs4_stateid(xdr, &args->src_stateid);
+	encode_nfs4_stateid(xdr, &args->dst_stateid);
+
+	encode_uint64(xdr, args->src_pos);
+	encode_uint64(xdr, args->dst_pos);
+	encode_uint64(xdr, args->count);
+
+	encode_uint32(xdr, 1); /* consecutive = true */
+	encode_uint32(xdr, 1); /* synchronous = true */
+	encode_uint32(xdr, 0); /* src server list */
+}
+
 static void encode_deallocate(struct xdr_stream *xdr,
 			      struct nfs42_falloc_args *args,
 			      struct compound_hdr *hdr)
@@ -182,6 +222,26 @@ static void nfs4_xdr_enc_allocate(struct rpc_rqst *req,
 }
 
 /*
+ * Encode COPY request
+ */
+static void nfs4_xdr_enc_copy(struct rpc_rqst *req,
+			      struct xdr_stream *xdr,
+			      struct nfs42_copy_args *args)
+{
+	struct compound_hdr hdr = {
+		.minorversion = nfs4_xdr_minorversion(&args->seq_args),
+	};
+
+	encode_compound_hdr(xdr, req, &hdr);
+	encode_sequence(xdr, &args->seq_args, &hdr);
+	encode_putfh(xdr, args->src_fh, &hdr);
+	encode_savefh(xdr, &hdr);
+	encode_putfh(xdr, args->dst_fh, &hdr);
+	encode_copy(xdr, args, &hdr);
+	encode_nops(&hdr);
+}
+
+/*
  * Encode DEALLOCATE request
  */
 static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
@@ -266,6 +326,62 @@ static int decode_allocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
 	return decode_op_hdr(xdr, OP_ALLOCATE);
 }
 
+static int decode_write_response(struct xdr_stream *xdr,
+				 struct nfs42_write_res *res)
+{
+	__be32 *p;
+	int stateids;
+
+	p = xdr_inline_decode(xdr, 4 + 8 + 4);
+	if (unlikely(!p))
+		goto out_overflow;
+
+	stateids = be32_to_cpup(p++);
+	p = xdr_decode_hyper(p, &res->count);
+	res->committed = be32_to_cpup(p);
+	return decode_verifier(xdr, &res->verifier);
+
+out_overflow:
+	print_overflow_msg(__func__, xdr);
+	return -EIO;
+}
+
+static int decode_copy_requirements(struct xdr_stream *xdr,
+				    struct nfs42_copy_res *res) {
+	__be32 *p;
+
+	p = xdr_inline_decode(xdr, 4 + 4);
+	if (unlikely(!p))
+		goto out_overflow;
+
+	res->consecutive = be32_to_cpup(p++);
+	res->synchronous = be32_to_cpup(p++);
+	return 0;
+out_overflow:
+	print_overflow_msg(__func__, xdr);
+	return -EIO;
+}
+
+static int decode_copy(struct xdr_stream *xdr, struct nfs42_copy_res *res)
+{
+	int status;
+
+	status = decode_op_hdr(xdr, OP_COPY);
+	if (status == NFS4ERR_OFFLOAD_NO_REQS) {
+		status = decode_copy_requirements(xdr, res);
+		if (status)
+			return status;
+		return NFS4ERR_OFFLOAD_NO_REQS;
+	} else if (status)
+		return status;
+
+	status = decode_write_response(xdr, &res->write_res);
+	if (status)
+		return status;
+
+	return decode_copy_requirements(xdr, res);
+}
+
 static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
 {
 	return decode_op_hdr(xdr, OP_DEALLOCATE);
@@ -331,6 +447,36 @@ out:
 }
 
 /*
+ * Decode COPY response
+ */
+static int nfs4_xdr_dec_copy(struct rpc_rqst *rqstp,
+			     struct xdr_stream *xdr,
+			     struct nfs42_copy_res *res)
+{
+	struct compound_hdr hdr;
+	int status;
+
+	status = decode_compound_hdr(xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_sequence(xdr, &res->seq_res, rqstp);
+	if (status)
+		goto out;
+	status = decode_putfh(xdr);
+	if (status)
+		goto out;
+	status = decode_savefh(xdr);
+	if (status)
+		goto out;
+	status = decode_putfh(xdr);
+	if (status)
+		goto out;
+	status = decode_copy(xdr, res);
+out:
+	return status;
+}
+
+/*
  * Decode DEALLOCATE request
  */
 static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
index 26f9a23..f3b4783 100644
--- a/fs/nfs/nfs4file.c
+++ b/fs/nfs/nfs4file.c
@@ -160,6 +160,28 @@ nfs4_file_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 }
 
 #ifdef CONFIG_NFS_V4_2
+static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
+				    struct file *file_out, loff_t pos_out,
+				    size_t count, unsigned int flags)
+{
+	struct inode *in_inode = file_inode(file_in);
+	struct inode *out_inode = file_inode(file_out);
+	int ret;
+
+	if (in_inode == out_inode)
+		return -EINVAL;
+
+	/* flush any pending writes */
+	ret = nfs_sync_inode(in_inode);
+	if (ret)
+		return ret;
+	ret = nfs_sync_inode(out_inode);
+	if (ret)
+		return ret;
+
+	return nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count);
+}
+
 static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence)
 {
 	loff_t ret;
@@ -274,6 +296,7 @@ const struct file_operations nfs4_file_operations = {
 	.check_flags	= nfs_check_flags,
 	.setlease	= simple_nosetlease,
 #ifdef CONFIG_NFS_V4_2
+	.copy_file_range = nfs4_copy_file_range,
 	.llseek		= nfs4_file_llseek,
 	.fallocate	= nfs42_fallocate,
 	.clone_file_range = nfs42_clone_file_range,
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index c57d133..03ac2ea 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -8706,6 +8706,7 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
 		| NFS_CAP_STATEID_NFSV41
 		| NFS_CAP_ATOMIC_OPEN_V1
 		| NFS_CAP_ALLOCATE
+		| NFS_CAP_COPY
 		| NFS_CAP_DEALLOCATE
 		| NFS_CAP_SEEK
 		| NFS_CAP_LAYOUTSTATS
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index 4e44412..bc3a3f5 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -7515,6 +7515,7 @@ struct rpc_procinfo	nfs4_procedures[] = {
 	PROC(DEALLOCATE,	enc_deallocate,		dec_deallocate),
 	PROC(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
 	PROC(CLONE,		enc_clone,		dec_clone),
+	PROC(COPY,		enc_copy,		dec_copy),
 #endif /* CONFIG_NFS_V4_2 */
 };
 
diff --git a/include/linux/nfs4.h b/include/linux/nfs4.h
index 43aeabd..3cddc5e 100644
--- a/include/linux/nfs4.h
+++ b/include/linux/nfs4.h
@@ -504,6 +504,7 @@ enum {
 	NFSPROC4_CLNT_DEALLOCATE,
 	NFSPROC4_CLNT_LAYOUTSTATS,
 	NFSPROC4_CLNT_CLONE,
+	NFSPROC4_CLNT_COPY,
 };
 
 /* nfs41 types */
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 2469ab0..8b772ca 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -245,5 +245,6 @@ struct nfs_server {
 #define NFS_CAP_DEALLOCATE	(1U << 21)
 #define NFS_CAP_LAYOUTSTATS	(1U << 22)
 #define NFS_CAP_CLONE		(1U << 23)
+#define NFS_CAP_COPY		(1U << 24)
 
 #endif
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 11bbae4..304b8e4 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -1342,6 +1342,33 @@ struct nfs42_falloc_res {
 	const struct nfs_server		*falloc_server;
 };
 
+struct nfs42_copy_args {
+	struct nfs4_sequence_args	seq_args;
+
+	struct nfs_fh			*src_fh;
+	nfs4_stateid			src_stateid;
+	u64				src_pos;
+
+	struct nfs_fh			*dst_fh;
+	nfs4_stateid			dst_stateid;
+	u64				dst_pos;
+
+	u64				count;
+};
+
+struct nfs42_write_res {
+	u64		count;
+	u32		committed;
+	nfs4_verifier	verifier;
+};
+
+struct nfs42_copy_res {
+	struct nfs4_sequence_res	seq_res;
+	struct nfs42_write_res		write_res;
+	bool				consecutive;
+	bool				synchronous;
+};
+
 struct nfs42_seek_args {
 	struct nfs4_sequence_args	seq_args;
 
-- 
2.6.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC v2 4/3] vfs_copy_range() test program
  2015-12-18 21:05 [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation Anna Schumaker
                   ` (2 preceding siblings ...)
  2015-12-18 21:05 ` [PATCH v2 3/3] NFS: Add COPY nfs operation Anna Schumaker
@ 2015-12-18 21:05 ` Anna Schumaker
  3 siblings, 0 replies; 11+ messages in thread
From: Anna Schumaker @ 2015-12-18 21:05 UTC (permalink / raw)
  To: linux-nfs, Trond.Myklebust, bfields, hch

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.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op()
  2015-12-18 21:05 ` [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
@ 2015-12-20 15:45   ` Christoph Hellwig
  2016-01-04 19:01     ` Anna Schumaker
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2015-12-20 15:45 UTC (permalink / raw)
  To: Anna Schumaker; +Cc: linux-nfs, Trond.Myklebust, bfields, hch

On Fri, Dec 18, 2015 at 04:05:24PM -0500, Anna Schumaker wrote:
> This reverts commit 3679e4c1ef1c00ea30d15b9ae59089b44dfe4137.
> 
> We either pass the current_fh or save_fh from the cstate structure, and
> not some generic filehandle.  Let's just add a flag to pick between these
> two filehandles instead.
> 
> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>

I don't really find this much cleaner to be honest.

>  fs/nfs/objlayout/Makefile |  0

how did this end up in the diffstat, btw?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] NFSD: Implement the COPY call
  2015-12-18 21:05 ` [PATCH v2 2/3] NFSD: Implement the COPY call Anna Schumaker
@ 2015-12-20 15:50   ` Christoph Hellwig
  2016-01-04 19:39     ` Anna Schumaker
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2015-12-20 15:50 UTC (permalink / raw)
  To: Anna Schumaker; +Cc: linux-nfs, Trond.Myklebust, bfields, hch

> +nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
> +		  stateid_t *src_stateid, struct file **src,
> +		  stateid_t *dst_stateid, struct file **dst)

I'm not really sold on a helper for two function calls and a simple
conditional.  I'm also not totally against it, though.

> +	p = xdr_encode_hyper(p, write->wr_bytes_written);
> +	*p++ = cpu_to_be32(write->wr_stable_how);
> +	p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, NFS4_VERIFIER_SIZE);

please stick to 80 characters per line.

> +
> +static __be32
> +nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
> +		  struct nfsd4_copy *copy)
> +{
> +	__be32 *p, err;
> +
> +	if (!nfserr) {
> +		err = nfsd42_encode_write_res(resp, &copy->cp_res);
> +		if (err)
> +			return err;
> +
> +		p = xdr_reserve_space(&resp->xdr, 4 + 4);
> +		*p++ = cpu_to_be32(copy->cp_consecutive);
> +		*p++ = cpu_to_be32(copy->cp_synchronous);
> +	}
> +	return nfserr;

seems lke the err variable is redundant and you could just use nfserr.

> +ssize_t nfsd_copy_range(struct file *src, u64 src_pos,
> +		        struct file *dst, u64 dst_pos,
> +		        u64 count)

the prototype would easily fit on two lines.

> +{
> +	//u64 limit = 0x800000; /* 4 MB */
> +	//u64 limit = 0x1000000; /* 8 MB */
> +	//u64 limit = 0x2000000; /* 16 MB */
> +	//u64 limit = 0x4000000; /* 32 MB */
> +	//u64 limit = 0x8000000; /* 64 MB */
> +	//u64 limit = 0x10000000; /* 128 MB */
> +	//u64 limit = 0x10000000; /* 256 MB */
> +	//u64 limit = 0x20000000; /* 512 MB */
> +	//u64 limit = 0x40000000; /* 1024 MB */
> +	//u64 limit = 0x80000000; /* 2048 MB */
> +
> +	//if (count > limit)
> +	//	count = limit;

This looks like odd left over debug code.  Note that vfs_copy_file_range
has a size_t limit, so we might need some explicit handling here instead
of silent truncation.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/3] NFS: Add COPY nfs operation
  2015-12-18 21:05 ` [PATCH v2 3/3] NFS: Add COPY nfs operation Anna Schumaker
@ 2015-12-20 15:53   ` Christoph Hellwig
  2016-01-04 20:05     ` Anna Schumaker
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2015-12-20 15:53 UTC (permalink / raw)
  To: Anna Schumaker; +Cc: linux-nfs, Trond.Myklebust, bfields, hch

> +	if (res.write_res.committed != NFS_FILE_SYNC) {
> +		status = nfs42_proc_commit(dst, pos_dst, res.write_res.count);
> +		if (status)
> +			return status;
> +	}

Do we really expect data to be stabe on disk after a copy_file_range?
Seems like the page cache variant doesn't guarantee that, and it would
also be different from all other I/O syscalls.

Either way we will probably need to document the assumptions in the man
page.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op()
  2015-12-20 15:45   ` Christoph Hellwig
@ 2016-01-04 19:01     ` Anna Schumaker
  0 siblings, 0 replies; 11+ messages in thread
From: Anna Schumaker @ 2016-01-04 19:01 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-nfs, Trond.Myklebust, bfields

On 12/20/2015 10:45 AM, Christoph Hellwig wrote:
> On Fri, Dec 18, 2015 at 04:05:24PM -0500, Anna Schumaker wrote:
>> This reverts commit 3679e4c1ef1c00ea30d15b9ae59089b44dfe4137.
>>
>> We either pass the current_fh or save_fh from the cstate structure, and
>> not some generic filehandle.  Let's just add a flag to pick between these
>> two filehandles instead.
>>
>> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
> 
> I don't really find this much cleaner to be honest.

Okay, I'll drop this patch.

> 
>>  fs/nfs/objlayout/Makefile |  0
> 
> how did this end up in the diffstat, btw?

My git trees just really wanted to make sure that it's there?  This change should go away when I remove the patch.

Anna
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/3] NFSD: Implement the COPY call
  2015-12-20 15:50   ` Christoph Hellwig
@ 2016-01-04 19:39     ` Anna Schumaker
  0 siblings, 0 replies; 11+ messages in thread
From: Anna Schumaker @ 2016-01-04 19:39 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-nfs, Trond.Myklebust, bfields

On 12/20/2015 10:50 AM, Christoph Hellwig wrote:
>> +nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>> +		  stateid_t *src_stateid, struct file **src,
>> +		  stateid_t *dst_stateid, struct file **dst)
> 
> I'm not really sold on a helper for two function calls and a simple
> conditional.  I'm also not totally against it, though.

I'm planning to keep the helper, since it's still a big chunk of code that would otherwise need to be duplicated.

> 
>> +	p = xdr_encode_hyper(p, write->wr_bytes_written);
>> +	*p++ = cpu_to_be32(write->wr_stable_how);
>> +	p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, NFS4_VERIFIER_SIZE);
> 
> please stick to 80 characters per line.

Okay.

> 
>> +
>> +static __be32
>> +nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
>> +		  struct nfsd4_copy *copy)
>> +{
>> +	__be32 *p, err;
>> +
>> +	if (!nfserr) {
>> +		err = nfsd42_encode_write_res(resp, &copy->cp_res);
>> +		if (err)
>> +			return err;
>> +
>> +		p = xdr_reserve_space(&resp->xdr, 4 + 4);
>> +		*p++ = cpu_to_be32(copy->cp_consecutive);
>> +		*p++ = cpu_to_be32(copy->cp_synchronous);
>> +	}
>> +	return nfserr;
> 
> seems lke the err variable is redundant and you could just use nfserr.

Sure.

> 
>> +ssize_t nfsd_copy_range(struct file *src, u64 src_pos,
>> +		        struct file *dst, u64 dst_pos,
>> +		        u64 count)
> 
> the prototype would easily fit on two lines.

Fixed.

> 
>> +{
>> +	//u64 limit = 0x800000; /* 4 MB */
>> +	//u64 limit = 0x1000000; /* 8 MB */
>> +	//u64 limit = 0x2000000; /* 16 MB */
>> +	//u64 limit = 0x4000000; /* 32 MB */
>> +	//u64 limit = 0x8000000; /* 64 MB */
>> +	//u64 limit = 0x10000000; /* 128 MB */
>> +	//u64 limit = 0x10000000; /* 256 MB */
>> +	//u64 limit = 0x20000000; /* 512 MB */
>> +	//u64 limit = 0x40000000; /* 1024 MB */
>> +	//u64 limit = 0x80000000; /* 2048 MB */
>> +
>> +	//if (count > limit)
>> +	//	count = limit;
> 
> This looks like odd left over debug code.  Note that vfs_copy_file_range
> has a size_t limit, so we might need some explicit handling here instead
> of silent truncation.

Yeah, I meant to remove that before submitting.  I think an unstable reply works better than a silent (and arbitrary) truncate.

Anna

> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 3/3] NFS: Add COPY nfs operation
  2015-12-20 15:53   ` Christoph Hellwig
@ 2016-01-04 20:05     ` Anna Schumaker
  0 siblings, 0 replies; 11+ messages in thread
From: Anna Schumaker @ 2016-01-04 20:05 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-nfs, Trond.Myklebust, bfields

On 12/20/2015 10:53 AM, Christoph Hellwig wrote:
>> +	if (res.write_res.committed != NFS_FILE_SYNC) {
>> +		status = nfs42_proc_commit(dst, pos_dst, res.write_res.count);
>> +		if (status)
>> +			return status;
>> +	}
> 
> Do we really expect data to be stabe on disk after a copy_file_range?
> Seems like the page cache variant doesn't guarantee that, and it would
> also be different from all other I/O syscalls.

It doesn't have to be, I just couldn't figure out how to mark the range as "needs commit" for the next time somebody runs fsync().

Anna

> 
> Either way we will probably need to document the assumptions in the man
> page.
> 


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-01-04 20:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-18 21:05 [PATCH v2 0/3] NFSv4.2: Add support for the COPY operation Anna Schumaker
2015-12-18 21:05 ` [PATCH v2 1/3] NFSD: Don't pass filehandle to nfs4_preprocess_stateid_op() Anna Schumaker
2015-12-20 15:45   ` Christoph Hellwig
2016-01-04 19:01     ` Anna Schumaker
2015-12-18 21:05 ` [PATCH v2 2/3] NFSD: Implement the COPY call Anna Schumaker
2015-12-20 15:50   ` Christoph Hellwig
2016-01-04 19:39     ` Anna Schumaker
2015-12-18 21:05 ` [PATCH v2 3/3] NFS: Add COPY nfs operation Anna Schumaker
2015-12-20 15:53   ` Christoph Hellwig
2016-01-04 20:05     ` Anna Schumaker
2015-12-18 21:05 ` [RFC v2 4/3] vfs_copy_range() test program Anna Schumaker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).