Skip to contentSkip to conversation

NFS support for inter and async COPY

RFC Superseded Olga Kornievskaia 5 participants 48 messages Mar 2, 2017 – Mar 9, 2017 1 message not in the archive

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover NFS support for inter and async COPY

This patch series provides support for NFSv4.2 COPY featuring support for asynchronous copy and inter SSC copy.

In case, of the "inter" SSC copy files reside on different servers and thus under different superblocks and require that VFS removes the restriction that src and dst files must be on the same superblock.

NFS's copy_file_range() determines if the copy is "intra" or "inter" and for "inter" it sends the COPY_NOTIFY to the source server. Then, it would send of an asynchronous COPY to the server (destination in case of "inter"). If server errs with ERR_OFFLOAD_NOREQS the copy will be re-sent as a synchronous COPY. If application cancels an in-flight COPY, OFFLOAD_CANCEL is sent to the source server.

If server replies to the COPY with the copy stateid, client will go wait on the CB_OFFLOAD. To fend off the race between CB_OFFLOAD and COPY reply, we check the list of pending callbacks before going to wait. Client adds the copy to the global list of copy stateids for the callback to look thru and signal the waiting copy.

If application cancels async COPY after reply is received, wait will be interrupted and client will send OFFLOAD_CANCEL to the source and destination servers (sending it as an async RPC in the context of the nfsiod_workqueue).

When the client receives reply from the CB_OFFLOAD with some bytes and committed how is UNSTABLE, then COMMIT is sent to the server. The results arep propagated to the VFS and application. Assuming that application will deal with a partial result and continue from the new offset if needed.

Handling reboot of the destination server when client is waiting on the CB_OFFLOAD happens when SEQUENCE discovers that destination server rebooted. The open state initially is marked to be NFS_CLNT_DST_SSC_COPY_STATE during the COPY. Then during the recovery if state is marked as such, then look thru the list of copies for the server and see if any are associated with this recovering open, if so mark the copy rebooted and wake up the waiting copy. Upon wake up the waiting copy, will restart the copy from scratch.

If the source server is rebooted, the destination server will also know about it and it will return the partial result via CB_OFFLOAD, then the result will be propagated back to the application which will initiate the new copy and new COPY_NOTIFY will be sent.

If CB_OFFLOAD returned an error and non negative value of partial copy and error is not ENOSPC, then ignore the error and send the commit and return partial result to the client to start the next copy.

On the destination server, it's now acting as a client and needs to do a special "open" and "close". Since destination server doesn't do an open on the wire, we "fake" create the needed data structures and that's done in the new function nfs42_ssc_open(). To clean up this open but not trigger the CLOSE on the wire, we have a new function nfs42_ssc_close() that accomplishes that.

Anna Schumaker (1):
fs: Don't copy beyond the end of the file

Andy Adamson (4):
VFS permit cross device vfs_copy_file_range
NFS inter ssc open
NFS add COPY_NOTIFY operation
NFS add ca_source_server<> to COPY

Olga Kornievskaia (14):
VFS don't try clone if superblocks are different NFS CB_OFFLOAD xdr
NFS OFFLOAD_STATUS xdr
NFS OFFLOAD_STATUS op
NFS OFFLOAD_CANCEL xdr
NFS COPY xdr handle async reply
NFS add support for asynchronous COPY
NFS handle COPY reply CB_OFFLOAD call race NFS send OFFLOAD_CANCEL when COPY killed
NFS make COPY synchronous xdr configurable NFS handle COPY ERR_OFFLOAD_NO_REQS
NFS skip recovery of copy open on dest server NFS recover from destination server reboot for copies NFS if we got partial copy ignore errors

 fs/nfs/callback.h         |  13 ++
 fs/nfs/callback_proc.c    |  52 +++++++
 fs/nfs/callback_xdr.c     |  80 +++++++++-
 fs/nfs/client.c           |   1 +
 fs/nfs/internal.h         |  10 ++
 fs/nfs/nfs42.h            |   9 +-
 fs/nfs/nfs42proc.c        | 352 ++++++++++++++++++++++++++++++++++++++++--
 fs/nfs/nfs42xdr.c         | 382 ++++++++++++++++++++++++++++++++++++++++++++--
 fs/nfs/nfs4_fs.h          |  12 ++
 fs/nfs/nfs4client.c       |  15 ++
 fs/nfs/nfs4file.c         | 147 +++++++++++++++++-
 fs/nfs/nfs4proc.c         |   8 +-
 fs/nfs/nfs4state.c        |  31 +++-
 fs/nfs/nfs4xdr.c          |   3 +
 fs/read_write.c           |  12 +-
 include/linux/nfs4.h      |  36 +++++
 include/linux/nfs_fs.h    |  11 ++
 include/linux/nfs_fs_sb.h |   5 +
 include/linux/nfs_xdr.h   |  34 +++++
 19 files changed, 1171 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

RFC 1/19 fs: Don't copy beyond the end of the file

From: Anna Schumaker <[email protected]>

---
 fs/read_write.c | 3 +++
 1 file changed, 3 insertions(+)
fs/read_write.c +3 -0
index 5816d4c..1d9e305 100644
@@ -1526,6 +1526,9 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (unlikely(ret))
 		return ret;
 
+	if (pos_in >= i_size_read(inode_in))
+		return -EINVAL;
+
 	if (!(file_in->f_mode & FMODE_READ) ||
 	    !(file_out->f_mode & FMODE_WRITE) ||
 	    (file_out->f_flags & O_APPEND))
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

fs/read_write.c ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · line 1530

Quoted 2 lines · Olga Kornievskaia
fs/read_write.c +2 -0
+	if (pos_in >= i_size_read(inode_in))
+		return -EINVAL;

That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

#3 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 2 lines

On Mar 2, 2017, at 11:22 AM, Christoph Hellwig <[email protected]> =

Quoted 7 lines · wrote:

=20

Review

Quoted 2 lines · Olga Kornievskaia
(quoted diff) +2 -0
+	if (pos_in >=3D i_size_read(inode_in))
+		return -EINVAL;

=20
That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

This is when the offset from which to read is beyond the end of the = file. I=E2=80=99m not sure what kind of short read are you expecting = here.

#4 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

fs/read_write.c ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · line 1530

Quoted 2 lines · Olga Kornievskaia
fs/read_write.c +2 -0
+	if (pos_in >= i_size_read(inode_in))
+		return -EINVAL;

That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

That's what I think too, but then is COPY(2) wrong?:

EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

	ret = -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

--b.

#5 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 2 lines

On Mar 3, 2017, at 3:47 PM, J. Bruce Fields <[email protected]> =

Quoted 17 lines · wrote:

=20

Quoted 6 lines · Christoph Hellwig

Review

Quoted 2 lines · Olga Kornievskaia
(quoted diff) +2 -0
+	if (pos_in >=3D i_size_read(inode_in))
+		return -EINVAL;

=20
That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

=20
That's what I think too, but then is COPY(2) wrong?:
=20
EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.
=20
Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:
=20

Quoted 7 lines
	ret =3D -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

=20
Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use. =20

I=E2=80=99m still rather very confused again by the comment and what it = is proposing.

There are two checks to consider for the validity of the arguments

1. If the offset of the source file is beyond the end of the source = file.
2. If the offset + len is beyond the end of the file.

I read that the man page is talking about #2. This is actually what the = NFSv4.2 spec required for the COPY too but we=E2=80=99ve been discussing = that it should be a short read instead.

This patch address is to address case #1. As far as I can tell it = applies to all file systems.

Are you suggesting that the checks for the validity of the arguments do = not belong in VFS but instead should be in each of the underlying file = systems?

Not all vfs_copy_file_range() are implemented via clone_file_range(). At = least I hope that =E2=80=9Cinter=E2=80=9D NFSv4.2 COPY will also use = vfs_file_copy_range() and it would not be calling clone().

Quoted 1 line

--b.

#6 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 34 lines · Olga Kornievskaia
Quoted 19 lines · J. Bruce Fields
Quoted 6 lines · Christoph Hellwig

fs/read_write.c ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · line 1530

Quoted 2 lines · Olga Kornievskaia
fs/read_write.c +2 -0
+	if (pos_in >= i_size_read(inode_in))
+		return -EINVAL;

That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

That's what I think too, but then is COPY(2) wrong?:

EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

Quoted 7 lines
	ret = -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

I’m still rather very confused again by the comment and what it is proposing.

There are two checks to consider for the validity of the arguments

1. If the offset of the source file is beyond the end of the source file.
2. If the offset + len is beyond the end of the file.

Quoted 7 lines

I read that the man page is talking about #2. This is actually what the NFSv4.2 spec required for the COPY too but we’ve been discussing that it should be a short read instead.

This patch address is to address case #1. As far as I can tell it applies to all file systems.

Are you suggesting that the checks for the validity of the arguments do not belong in VFS but instead should be in each of the underlying file systems?

Not all vfs_copy_file_range() are implemented via clone_file_range(). At least I hope that “inter” NFSv4.2 COPY will also use vfs_file_copy_range() and it would not be calling clone().

I think it'd be acceptable for copy_file_range() to just return 0 even in your case 1. I believe that's what ordinary read and pread does.

You probably can't perform it atomically with the copy, so it's possible that the size will change right after you check it.

I don't see a benefit to the check.

--b.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 55 lines · Olga Kornievskaia
Quoted 46 lines · J. Bruce Fields
Quoted 34 lines · Olga Kornievskaia
Quoted 19 lines · J. Bruce Fields
Quoted 6 lines · Christoph Hellwig

fs/read_write.c ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, · line 1530

Quoted 2 lines · Olga Kornievskaia
fs/read_write.c +2 -0
+	if (pos_in >= i_size_read(inode_in))
+		return -EINVAL;

That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

That's what I think too, but then is COPY(2) wrong?:

EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

Quoted 7 lines
	ret = -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

I’m still rather very confused again by the comment and what it is proposing.

There are two checks to consider for the validity of the arguments

1. If the offset of the source file is beyond the end of the source file.
2. If the offset + len is beyond the end of the file.

Quoted 7 lines

I read that the man page is talking about #2. This is actually what the NFSv4.2 spec required for the COPY too but we’ve been discussing that it should be a short read instead.

This patch address is to address case #1. As far as I can tell it applies to all file systems.

Are you suggesting that the checks for the validity of the arguments do not belong in VFS but instead should be in each of the underlying file systems?

Not all vfs_copy_file_range() are implemented via clone_file_range(). At least I hope that “inter” NFSv4.2 COPY will also use vfs_file_copy_range() and it would not be calling clone().

Quoted 7 lines

I think it'd be acceptable for copy_file_range() to just return 0 even in your case 1. I believe that's what ordinary read and pread does.

You probably can't perform it atomically with the copy, so it's possible that the size will change right after you check it.

I don't see a benefit to the check.

Quoted 6 lines

In read() you don’t specify the offset from which to read. It is read from the current file descriptor offset. I don’t find the comparison equal.

It’s it more fair to compare it to lseek() which does return EINVAL if you specify position beyond the end of the file.

Or pread(), which takes an offset.

But read() can read at an offset at the end of file, or even past that (if the file was truncated), and I believe it just returns 0 in those cases.

--b.

#9 lore raw

Re: [RFC v1 01/19] Don't copy beyond the end of the file

Quoted 2 lines

On Mar 3, 2017, at 9:10 PM, J. Bruce Fields <[email protected]> =

Quoted 4 lines · wrote:

=20

Quoted 2 lines · Olga Kornievskaia

=20

Quoted 1 line

On Mar 3, 2017, at 4:32 PM, J. Bruce Fields <[email protected]> =

Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 4 lines

=20

Quoted 2 lines · Olga Kornievskaia

=20

Quoted 1 line

On Mar 3, 2017, at 3:47 PM, J. Bruce Fields <[email protected]> =

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

=20

Quoted 1 line · Christoph Hellwig

On Thu, Mar 02, 2017 at 11:01:05AM -0500, Olga Kornievskaia =

Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (pos_in >=3D i_size_read(inode_in))
+		return -EINVAL;

=20
That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

=20
That's what I think too, but then is COPY(2) wrong?:
=20
EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.
=20
Also, copy_file_range can be implemented by ->clone_file_range, =

where

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines

these kinds of checks make more sense, I think; e.g. from btrfs:
=20

	ret =3D -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

=20
Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use. =20

=20
I=E2=80=99m still rather very confused again by the comment and =

what it is proposing.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

=20
There are two checks to consider for the validity of the arguments =20
1. If the offset of the source file is beyond the end of the source =

file.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

2. If the offset + len is beyond the end of the file. =20
I read that the man page is talking about #2. This is actually =

what the NFSv4.2 spec required for the COPY too but we=E2=80=99ve been = discussing that it should be a short read instead.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

=20
This patch address is to address case #1. As far as I can tell it =

applies to all file systems.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

=20
Are you suggesting that the checks for the validity of the =

arguments do not belong in VFS but instead should be in each of the = underlying file systems?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

=20
Not all vfs_copy_file_range() are implemented via =

clone_file_range(). At least I hope that =E2=80=9Cinter=E2=80=9D NFSv4.2 = COPY will also use vfs_file_copy_range() and it would not be calling = clone().

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

=20
I think it'd be acceptable for copy_file_range() to just return 0 =

even

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

in your case 1. I believe that's what ordinary read and pread does. =20
You probably can't perform it atomically with the copy, so it's =

possible

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

that the size will change right after you check it. =20
I don't see a benefit to the check.

=20

=20

Quoted 1 line

In read() you don=E2=80=99t specify the offset from which to read. It =

is read

Quoted 1 line
Quoted 1 line

from the current file descriptor offset. I don=E2=80=99t find the =

comparison

Quoted 3 lines
Quoted 3 lines

equal.=20
=20
It=E2=80=99s it more fair to compare it to lseek() which does return =

EINVAL if

Quoted 8 lines
Quoted 1 line

you specify position beyond the end of the file.=20

=20
Or pread(), which takes an offset.
=20
But read() can read at an offset at the end of file, or even past that (if the file was truncated), and I believe it just returns 0 in those cases.
=20

I don=E2=80=99t see copy_file_range() specifying that 0 means end of the = file. Are you arguing to add that meaning to the function call? I guess = in that case we=E2=80=99d need to take extra care to never return 0bytes = to the client as a =E2=80=9Cpartial=E2=80=9D copy (say due to server = rebooting).

Unless changed, NFS4.2 mandates the two checks that I=E2=80=99ve = specified. I can add the checks in the NFS implementation itself. = However, we thought at least this check belonged in the VFS layer. I=E2=80= =99m really not super attached to getting into VFS. Actually the 2nd = check is something that copy_file_range() man pages say should return = EINVAL but the VFS code doesn=E2=80=99t enforce it.=20

#10 lore raw

Re: [RFC v1 01/19] Don't copy beyond the end of the file

Quoted 85 lines · Olga Kornievskaia
Quoted 85 lines

On Mar 3, 2017, at 9:10 PM, J. Bruce Fields <[email protected]> wrote:

Quoted 71 lines · Olga Kornievskaia
Quoted 61 lines

On Mar 3, 2017, at 4:32 PM, J. Bruce Fields <[email protected]> wrote:

Quoted 47 lines · Olga Kornievskaia
Quoted 23 lines

On Mar 3, 2017, at 3:47 PM, J. Bruce Fields
<[email protected]> wrote:

Quoted 7 lines · Christoph Hellwig

Review

Quoted 2 lines · Olga Kornievskaia
(quoted diff) +1 -1
+	if (pos_in >= i_size_read(inode_in)) +		return
-EINVAL;

That's not how the syscall is supposed to work, we'd rather do a short read^^^^^copy.

That's what I think too, but then is COPY(2) wrong?:

EINVAL Requested range extends beyond the end of the source file; or the flags argument is not 0.

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

Quoted 6 lines
	ret = -EINVAL; if (off + len > src->i_size || off + len
	< off) goto out_unlock;

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

I’m still rather very confused again by the comment and what it is proposing.

There are two checks to consider for the validity of the arguments

1. If the offset of the source file is beyond the end of the source file. 2. If the offset + len is beyond the end of the file.

I read that the man page is talking about #2. This is actually what the NFSv4.2 spec required for the COPY too but we’ve been discussing that it should be a short read instead.

This patch address is to address case #1. As far as I can tell it applies to all file systems.

Quoted 8 lines

Are you suggesting that the checks for the validity of the arguments do not belong in VFS but instead should be in each of the underlying file systems?

Not all vfs_copy_file_range() are implemented via clone_file_range(). At least I hope that “inter” NFSv4.2 COPY will also use vfs_file_copy_range() and it would not be calling clone().

Quoted 8 lines

I think it'd be acceptable for copy_file_range() to just return 0 even in your case 1. I believe that's what ordinary read and pread does.

You probably can't perform it atomically with the copy, so it's possible that the size will change right after you check it.

I don't see a benefit to the check.

Quoted 6 lines

In read() you don’t specify the offset from which to read. It is read from the current file descriptor offset. I don’t find the comparison equal.

It’s it more fair to compare it to lseek() which does return EINVAL if you specify position beyond the end of the file.

Or pread(), which takes an offset.

Quoted 7 lines
Quoted 4 lines

But read() can read at an offset at the end of file, or even past that (if the file was truncated), and I believe it just returns 0 in those cases.

I don’t see copy_file_range() specifying that 0 means end of the file. Are you arguing to add that meaning to the function call?

Yes.

Quoted 3 lines

I guess in
that case we’d need to take extra care to never return 0bytes to the client as a “partial” copy (say due to server rebooting).

Right.

Quoted 6 lines

Unless changed, NFS4.2 mandates the two checks that I’ve specified. I can add the checks in the NFS implementation itself. However, we thought at least this check belonged in the VFS layer. I’m really not super attached to getting into VFS. Actually the 2nd check is something that copy_file_range() man pages say should return EINVAL but the VFS code doesn’t enforce it.

Please leave those checks out. Let's try to fix the spec.

--b.

#11 lore raw

Re: [RFC v1 01/19] Don't copy beyond the end of the file

In reply to Olga Kornievskaia
Quoted 1 line · Olga Kornievskaia

I don’t see copy_file_range() specifying that 0 means end of the file.

Is there a reason that copy_file_range shouldn't be like read? (From read(2): "On success, the number of bytes read is returned (zero indicates end of file)".

I haven't checked, but suspect that's already true of the implementations we have.

Also, from copy_file_range():

EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.

Some filesystems do this, some don't; I think the man page should make it clear that this behavior is not required.

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#12 lore raw

Re: [RFC v1 01/19] Don't copy beyond the end of the file

Quoted 6 lines · J. Bruce Fields
Quoted 1 line · Olga Kornievskaia

I don’t see copy_file_range() specifying that 0 means end of the file.

Is there a reason that copy_file_range shouldn't be like read? (From read(2): "On success, the number of bytes read is returned (zero indicates end of file)".

The only thing I can think of is the fact that copy_file_range() does write too. And return 0 from the write is not expected/allowed (except when input count was 0)?

Quoted 8 lines

I haven't checked, but suspect that's already true of the implementations we have.

Also, from copy_file_range():

EINVAL Requested range extends beyond the end of the source
file; or the flags argument is not 0.

Quoted 8 lines

Some filesystems do this, some don't; I think the man page should make it clear that this behavior is not required.

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

In reply to J. Bruce Fields
Quoted 1 line · J. Bruce Fields

That's what I think too, but then is COPY(2) wrong?:

Either the current kernel code or the man page is wrong..

Quoted 9 lines

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

	ret = -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

We'll need to stick to one behavior. So between the man page and the clone implementation I guess this patch is fine after all.

#14 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 12 lines · Christoph Hellwig
Quoted 1 line · J. Bruce Fields

That's what I think too, but then is COPY(2) wrong?:

Either the current kernel code or the man page is wrong..

Quoted 7 lines

Also, copy_file_range can be implemented by ->clone_file_range, where these kinds of checks make more sense, I think; e.g. from btrfs:

	ret = -EINVAL;
	if (off + len > src->i_size || off + len < off)
		goto out_unlock;
Quoted 5 lines
Quoted 2 lines

Well, so the caller just has to be prepared for either behavior, I guess, but that may make it more complicated to use.

We'll need to stick to one behavior. So between the man page and the clone implementation I guess this patch is fine after all.

Ugh, please, let's not.

Since copy isn't atomic that check is never going to be reliable.

As long as we allow copy to have either copy-like or clone-like implementations, callers have to be prepared to handle either behavior when the range is past end of file, either a short copy or an EINVAL.

The difference is that if we add this check, then the "short copy" behavior becomes something that only happens when the timing is just right.

--b.

#15 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 1 line · J. Bruce Fields

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does. By that logic we should not implement it at all (a logic that I'd fully support)

#16 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 2 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected]> =

Quoted 6 lines · wrote:

=20

Quoted 1 line · J. Bruce Fields

Since copy isn't atomic that check is never going to be reliable.

=20
That's true for everything that COPY does. By that logic we should not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you=E2=80=99d lose a huge = performance gain you get from server-to-server COPY.=20=

#17 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 4 lines · Olga Kornievskaia
Quoted 4 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines · J. Bruce Fields
Quoted 1 line

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does. By that logic we should not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you’d lose a huge performance gain you get from server-to-server COPY.

Yes. Also, I think copy-like copy implementations have reasonable semantics that are basically the same as read:

- copy can return successfully with less copied than requested.
- it's fine for the copied range to start and/or end past end of file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're at end of file.

The particular problem here is that that doesn't fit how clone works at all.

It feels like what happened is that copy_file_range() was made mainly for the clone case, with the idea that copy might be reluctantly accepted as a second-class implementation.

But the performance gain of copy offload is too big to just ignore, and in fact it's what copy_file_range does on every filesystem but btrfs and ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

If we had separate copy_file_range and clone_file_range, I *think* it could all be made sensible. Am I missing something?

--b.

#18 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 33 lines · J. Bruce Fields
Quoted 4 lines · Olga Kornievskaia
Quoted 4 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines · J. Bruce Fields
Quoted 1 line

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does. By that logic we should not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you’d lose a huge performance gain you get from server-to-server COPY.

Yes. Also, I think copy-like copy implementations have reasonable semantics that are basically the same as read:

- copy can return successfully with less copied than requested.
- it's fine for the copied range to start and/or end past end of file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're at end of file.

The particular problem here is that that doesn't fit how clone works at all.

It feels like what happened is that copy_file_range() was made mainly for the clone case, with the idea that copy might be reluctantly accepted as a second-class implementation.

Quoted 7 lines

But the performance gain of copy offload is too big to just ignore, and in fact it's what copy_file_range does on every filesystem but btrfs and ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

If we had separate copy_file_range and clone_file_range, I *think* it could all be made sensible. Am I missing something?

How would the application (cp) know when to call the clone_file_range and when to call copy_file_range?

#19 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 33 lines · Olga Kornievskaia
Quoted 33 lines

On Mar 8, 2017, at 2:53 PM, J. Bruce Fields <[email protected]> wrote:

Quoted 10 lines · Olga Kornievskaia
Quoted 10 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected] rg>
wrote:

Quoted 2 lines · J. Bruce Fields

Since copy isn't atomic that check is never going to be reliable.

Quoted 7 lines
Quoted 3 lines

That's true for everything that COPY does.  By that logic we should
not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you’d lose a huge performance gain
you get from server-to-server COPY.

Yes.  Also, I think copy-like copy implementations have reasonable semantics that are basically the same as read:

- copy can return successfully with less copied than requested.
- it's fine for the copied range to start and/or end past end
of
  file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're at end
of
  file.

Quoted 8 lines
Quoted 8 lines

The particular problem here is that that doesn't fit how clone works at
all.

It feels like what happened is that copy_file_range() was made mainly
for the clone case, with the idea that copy might be reluctantly accepted as a second-class implementation.

Historically? No... Christoph added clone as a valid implementation of copy_file_range() almost a year after Zach and Anna defined the semantics of vfs_copy_file_range(). git blame is your friend...

Quoted 7 lines
Quoted 7 lines

But the performance gain of copy offload is too big to just ignore, and
in fact it's what copy_file_range does on every filesystem but btrfs and
ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

Quoted 7 lines
Quoted 4 lines

If we had separate copy_file_range and clone_file_range, I *think* it
could all be made sensible.  Am I missing something?

How would the application (cp) know when to call the clone_file_range and when to call copy_file_range?

cp can probably call copy_file_range(), but any application that needs atomic semantics (i.e. a binary operation success/fail) must call clone_file_range().

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]
#20 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 38 lines · Trond Myklebust
Quoted 37 lines · Olga Kornievskaia
Quoted 37 lines

On Mar 8, 2017, at 2:53 PM, J. Bruce Fields <[email protected]> wrote:

Quoted 10 lines · Olga Kornievskaia
Quoted 10 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected] rg>
wrote:

Quoted 2 lines · J. Bruce Fields

Since copy isn't atomic that check is never going to be reliable.

Quoted 7 lines
Quoted 3 lines

That's true for everything that COPY does.  By that logic we should
not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you’d lose a huge performance gain
you get from server-to-server COPY.

Yes.  Also, I think copy-like copy implementations have reasonable semantics that are basically the same as read:

- copy can return successfully with less copied than requested.
- it's fine for the copied range to start and/or end past end
of
  file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're at end
of
  file.

The particular problem here is that that doesn't fit how clone works at
all.

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

It feels like what happened is that copy_file_range() was made mainly
for the clone case, with the idea that copy might be reluctantly accepted as a second-class implementation.

Historically? No... Christoph added clone as a valid implementation of copy_file_range() almost a year after Zach and Anna defined the semantics of vfs_copy_file_range(). git blame is your friend...

Yeah, I know. It still feels to me like the interface was originally designed with clone in mind, but that's my vague impression from the man pages and half-remembered conversations.

Though the lack of a "just copy the whole file regardless of size" case is weird for clone. All you can do is stat the file and then hope it doesn't change before you issue the copy_file_range. But I'd think it'd be easy for an atomic clone implementation to handle, say, getting a snapshot of a log file while it's getting continuously appended to.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

But the performance gain of copy offload is too big to just ignore, and
in fact it's what copy_file_range does on every filesystem but btrfs and
ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

If we had separate copy_file_range and clone_file_range, I *think* it
could all be made sensible.  Am I missing something?

Quoted 6 lines
Quoted 2 lines

How would the application (cp) know when to call the clone_file_range and when to call copy_file_range?

cp can probably call copy_file_range(), but any application that needs atomic semantics (i.e. a binary operation success/fail) must call clone_file_range().

I don't believe there's a clone_file_range(). I see the vfs interface, but no system call.

And implementing a simple cp is harder than it should be when you don't know whether it's implemented as copy or clone. You have to stat for the file size first, retry if you got it wrong, and also retry if you get a short read. The example in the clone_file_range() man page is incomplete.

--b.

#21 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 64 lines · On Wed, 2017-03-08 at 15:32 -0500, [email protected] wrote:
Quoted 53 lines · Trond Myklebust
Quoted 46 lines · Olga Kornievskaia
Quoted 46 lines

On Mar 8, 2017, at 2:53 PM, J. Bruce Fields <[email protected] rg>
wrote:

Quoted 16 lines · Olga Kornievskaia
Quoted 8 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <hch@infrade ad.o
rg>
wrote:

On Wed, Mar 08, 2017 at 12:05:21PM -0500, J. Bruce Fields wrote:

Quoted 7 lines
Quoted 2 lines

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does.  By that logic we
should
not implement it at all (a logic that I'd fully support)

Quoted 4 lines

If you were to only keep CLONE then you’d lose a huge performance
gain
you get from server-to-server COPY.

Yes.  Also, I think copy-like copy implementations have reasonable
semantics that are basically the same as read:

- copy can return successfully with less copied than
requested.
- it's fine for the copied range to start and/or end
past end
of
  file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're
at end
of
  file.

The particular problem here is that that doesn't fit how clone works at
all.

Quoted 5 lines
Quoted 5 lines

It feels like what happened is that copy_file_range() was made mainly
for the clone case, with the idea that copy might be reluctantly
accepted as a second-class implementation.

Quoted 4 lines

Historically? No... Christoph added clone as a valid implementation of
copy_file_range() almost a year after Zach and Anna defined the semantics of vfs_copy_file_range(). git blame is your friend...

Yeah, I know.  It still feels to me like the interface was originally designed with clone in mind, but that's my vague impression from the man
pages and half-remembered conversations.

Quoted 7 lines

Though the lack of a "just copy the whole file regardless of size" case
is weird for clone.  All you can do is stat the file and then hope it doesn't change before you issue the copy_file_range.  But I'd think it'd
be easy for an atomic clone implementation to handle, say, getting a snapshot of a log file while it's getting continuously appended to.

It really isn't that interesting in the continuously appended case (what difference does it make if you only get data from just a few moments ago), but I can see it being an issue in the case of random writes where the file size is being extended.

The thing is that in both those cases, the copy_file_range() semantics are worse, since they don't even guarantee a time-consistent copy.

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 8 lines

But the performance gain of copy offload is too big to just ignore,
and
in fact it's what copy_file_range does on every filesystem but btrfs and
ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

Quoted 5 lines

If we had separate copy_file_range and clone_file_range, I *think*
it
could all be made sensible.  Am I missing something?

How would the application (cp) know when to call the clone_file_range
and when to call copy_file_range?

Quoted 8 lines
Quoted 4 lines

cp can probably call copy_file_range(), but any application that needs
atomic semantics (i.e. a binary operation success/fail) must call clone_file_range().

I don't believe there's a clone_file_range().  I see the vfs interface,
but no system call.

There is a standard FICLONERANGE ioctl() that can be used on all filesystems that support the vfs interface.

Quoted 6 lines

And implementing a simple cp is harder than it should be when you don't
know whether it's implemented as copy or clone.  You have to stat for the file size first, retry if you got it wrong, and also retry if you get a short read.  The example in the clone_file_range() man page is incomplete.

As I said, you shouldn't be using copy_file_range() either in the case where the file is being modified.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, PrimaryData
[email protected]
#22 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 73 lines · Trond Myklebust
Quoted 64 lines · On Wed, 2017-03-08 at 15:32 -0500, [email protected] wrote:
Quoted 53 lines · Trond Myklebust
Quoted 46 lines · Olga Kornievskaia
Quoted 46 lines

On Mar 8, 2017, at 2:53 PM, J. Bruce Fields <[email protected] rg>
wrote:

Quoted 16 lines · Olga Kornievskaia
Quoted 8 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <hch@infrade ad.o
rg>
wrote:

On Wed, Mar 08, 2017 at 12:05:21PM -0500, J. Bruce Fields wrote:

Quoted 7 lines
Quoted 2 lines

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does.  By that logic we
should
not implement it at all (a logic that I'd fully support)

Quoted 4 lines

If you were to only keep CLONE then you’d lose a huge performance
gain
you get from server-to-server COPY.

Yes.  Also, I think copy-like copy implementations have reasonable
semantics that are basically the same as read:

- copy can return successfully with less copied than
requested.
- it's fine for the copied range to start and/or end
past end
of
  file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're
at end
of
  file.

The particular problem here is that that doesn't fit how clone works at
all.

Quoted 5 lines
Quoted 5 lines

It feels like what happened is that copy_file_range() was made mainly
for the clone case, with the idea that copy might be reluctantly
accepted as a second-class implementation.

Quoted 4 lines

Historically? No... Christoph added clone as a valid implementation of
copy_file_range() almost a year after Zach and Anna defined the semantics of vfs_copy_file_range(). git blame is your friend...

Yeah, I know.  It still feels to me like the interface was originally designed with clone in mind, but that's my vague impression from the man
pages and half-remembered conversations.

Quoted 7 lines

Though the lack of a "just copy the whole file regardless of size" case
is weird for clone.  All you can do is stat the file and then hope it doesn't change before you issue the copy_file_range.  But I'd think it'd
be easy for an atomic clone implementation to handle, say, getting a snapshot of a log file while it's getting continuously appended to.

Quoted 4 lines

It really isn't that interesting in the continuously appended case (what difference does it make if you only get data from just a few moments ago), but I can see it being an issue in the case of random writes where the file size is being extended.

Bah, yes, apologies for the bad example.

Quoted 26 lines

The thing is that in both those cases, the copy_file_range() semantics are worse, since they don't even guarantee a time-consistent copy.

Quoted 23 lines
Quoted 22 lines
Quoted 14 lines
Quoted 8 lines

But the performance gain of copy offload is too big to just ignore,
and
in fact it's what copy_file_range does on every filesystem but btrfs and
ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

Quoted 5 lines

If we had separate copy_file_range and clone_file_range, I *think*
it
could all be made sensible.  Am I missing something?

Quoted 3 lines

How would the application (cp) know when to call the clone_file_range
and when to call copy_file_range?

cp can probably call copy_file_range(), but any application that needs
atomic semantics (i.e. a binary operation success/fail) must call clone_file_range().

Quoted 6 lines
Quoted 3 lines

I don't believe there's a clone_file_range().  I see the vfs interface,
but no system call.

There is a standard FICLONERANGE ioctl() that can be used on all filesystems that support the vfs interface.

Oh, thanks, I forgot about that.

So I don't understand why it needed to be added to copy_file_range(). The copy and clone semantics are different enough that I think callers want to know which they're getting.

Quoted 9 lines
Quoted 6 lines

And implementing a simple cp is harder than it should be when you don't
know whether it's implemented as copy or clone.  You have to stat for the file size first, retry if you got it wrong, and also retry if you get a short read.  The example in the clone_file_range() man page is incomplete.

As I said, you shouldn't be using copy_file_range() either in the case where the file is being modified.

Don't we want it to have more or less the same behavior as a read-write loop? People are probably running backup programs that depend on just simple copies, and maybe the results are good enough for their purposes, or maybe they're actually corrupting parts of their backups and don't know, but we can't suddenly start aborting their backups with errors and tell users it's for their own good. So copy_file_range() callers will need to handle EINVAL on changing files somehow.

--b.

#23 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

[please trim your replies instead of this giant unreadable garbage,
thanks!]

Quoted 3 lines · On Thu, Mar 09, 2017 at 10:29:48AM -0500, [email protected] wrote:

So I don't understand why it needed to be added to copy_file_range(). The copy and clone semantics are different enough that I think callers want to know which they're getting.

Because if a file systems implements clone is literally is always better than doing a copy loop, so using it is an absolute non-brainer.

Quoted 7 lines

Don't we want it to have more or less the same behavior as a read-write loop? People are probably running backup programs that depend on just simple copies, and maybe the results are good enough for their purposes, or maybe they're actually corrupting parts of their backups and don't know, but we can't suddenly start aborting their backups with errors and tell users it's for their own good. So copy_file_range() callers will need to handle EINVAL on changing files somehow.

They do, and the system call has been in the tree for almost a year and a half, so we can't simply change it. Fortunately we do have a flags argument that can be used to implement your preferred semantics if you care deeply enough about them.

#24 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 7 lines · On Thu, Mar 09, 2017 at 07:35:59AM -0800, [email protected] wrote:
Quoted 3 lines · On Thu, Mar 09, 2017 at 10:29:48AM -0500, [email protected] wrote:

So I don't understand why it needed to be added to copy_file_range(). The copy and clone semantics are different enough that I think callers want to know which they're getting.

Because if a file systems implements clone is literally is always better than doing a copy loop, so using it is an absolute non-brainer.

I guess I'm just hung up on the EINVAL vs. short copy behavior. It seems more annoying and error-prone to be prepared for both, as opposed to trying clone and then explicitly falling back to copy if that doesn't work. Maybe it's not that big a deal.

Quoted 4 lines

They do, and the system call has been in the tree for almost a year and a half, so we can't simply change it. Fortunately we do have a flags argument that can be used to implement your preferred semantics if you care deeply enough about them.

Yeah.

There are also some other offset, length combinations that currently return -EINVAL, I wonder if any of those could be repurposed e.g. for a "keep copying to end of file" call.

--b.

#25 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 4 lines · On Thu, Mar 09, 2017 at 11:16:01AM -0500, [email protected] wrote:

I guess I'm just hung up on the EINVAL vs. short copy behavior. It seems more annoying and error-prone to be prepared for both, as opposed to trying clone and then explicitly falling back to copy if that doesn't work. Maybe it's not that big a deal.

We can do short copies^H^H^H^H^Hclones for clone just as easily, at least for local filesystems (NFS would require some tweaks due to the protocol).

#26 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 12 lines · On Mar 9, 2017, at 11:17 AM, [email protected] wrote:
Quoted 4 lines · On Thu, Mar 09, 2017 at 11:16:01AM -0500, [email protected] wrote:

I guess I'm just hung up on the EINVAL vs. short copy behavior. It seems more annoying and error-prone to be prepared for both, as opposed to trying clone and then explicitly falling back to copy if that doesn't work. Maybe it's not that big a deal.

We can do short copies^H^H^H^H^Hclones for clone just as easily, at least for local filesystems (NFS would require some tweaks due to the protocol).

I’m confused by the wording of “we can do … easily” . Is “can” = in the future? Currently, testing copy_file_range() on a btfs with argument of offset+len beyond the end of the file fail with EINVAL. Is NFS tweaking = revert the “MUST” in the spec for the check?

#27 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

Quoted 10 lines · Olga Kornievskaia
Quoted 10 lines · On Mar 9, 2017, at 11:17 AM, [email protected] wrote:
Quoted 4 lines · On Thu, Mar 09, 2017 at 11:16:01AM -0500, [email protected] wrote:

I guess I'm just hung up on the EINVAL vs. short copy behavior. It seems more annoying and error-prone to be prepared for both, as opposed to trying clone and then explicitly falling back to copy if that doesn't work. Maybe it's not that big a deal.

Quoted 8 lines
Quoted 3 lines

We can do short copies^H^H^H^H^Hclones for clone just as easily, at least for local filesystems (NFS would require some tweaks due to the protocol).

I’m confused by the wording of “we can do … easily” . Is “can” = in the future? Currently, testing copy_file_range() on a btfs with argument of offset+len beyond the end of the file fail with EINVAL. Is NFS tweaking = revert the “MUST” in the spec for the check?

Checking https://tools.ietf.org/html/draft-ietf-nfsv4-minorversion2-41
... looks like the CLONE result doesn't even have a length.

Most users are probably cloning the whole file, so I guess it only matters in the case the file's changing (so that the size returned from stat might not be correct by the time you do the clone).

Allowing short copies would be one way to handle that--I think it'd work then to just always request a clone to the maximum length.

Alternatively if the linux interface just had a way to say "clone to end of file", that'd solve most of the problem and be a nice fit for the existing NFS protocol (which special-cases length 0 to mean "to end of file").

Maybe we could special-case the maximum size_t to mean that. (What is that, 2^63-1?.)

--b.

#28 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

In reply to Olga Kornievskaia
Quoted 1 line · Olga Kornievskaia

I’m confused by the wording of “we can do … easily” . Is “can” = in the future? Currently, testing copy_file_range() on a btfs with argument of offset+len beyond the end of the file fail with EINVAL. Is NFS tweaking = revert the “MUST” in the spec for the check?

The current clone and copy documents (which are our specs) require this behavior, so that is expected. But if we decided we want a variant of copy / clone that doesn't do this it would be very easy to implement in the local file systems. Only for NFS we'd get a failure back and would have to retry the clone based on the updated file size.

#29 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

In reply to [email protected]
Quoted 9 lines · On Mar 9, 2017, at 11:16 AM, [email protected] wrote:
Quoted 5 lines · On Thu, Mar 09, 2017 at 07:35:59AM -0800, [email protected] wrote:
Quoted 3 lines · On Thu, Mar 09, 2017 at 10:29:48AM -0500, [email protected] wrote:

So I don't understand why it needed to be added to copy_file_range(). The copy and clone semantics are different enough that I think callers want to know which they're getting.

Quoted 7 lines
Quoted 2 lines

Because if a file systems implements clone is literally is always better than doing a copy loop, so using it is an absolute non-brainer.

I guess I'm just hung up on the EINVAL vs. short copy behavior. It seems more annoying and error-prone to be prepared for both, as opposed to trying clone and then explicitly falling back to copy if that doesn't work. Maybe it's not that big a deal.

I’m confused at which layer are we calling clone() and if we get EINVAL we call copy()? In VFS? Or are we talking about the case where there are two different system calls clone_file_range() and copy_file_range() that are provided to the “cp” and it calls one and then falls back onto another?

Quoted 13 lines
Quoted 5 lines

They do, and the system call has been in the tree for almost a year and a half, so we can't simply change it. Fortunately we do have a flags argument that can be used to implement your preferred semantics if you care deeply enough about them.

Yeah.

There are also some other offset, length combinations that currently return -EINVAL, I wonder if any of those could be repurposed e.g. for a "keep copying to end of file" call.

--b.

#30 lore raw

Re: [RFC v1 01/19] fs: Don't copy beyond the end of the file

In reply to Olga Kornievskaia
Quoted 33 lines · Olga Kornievskaia
Quoted 33 lines · J. Bruce Fields
Quoted 4 lines · Olga Kornievskaia
Quoted 4 lines

On Mar 8, 2017, at 12:25 PM, Christoph Hellwig <[email protected]> wrote:

Quoted 8 lines
Quoted 5 lines · J. Bruce Fields
Quoted 1 line

Since copy isn't atomic that check is never going to be reliable.

That's true for everything that COPY does. By that logic we should not implement it at all (a logic that I'd fully support)

If you were to only keep CLONE then you’d lose a huge performance gain you get from server-to-server COPY.

Yes. Also, I think copy-like copy implementations have reasonable semantics that are basically the same as read:

- copy can return successfully with less copied than requested.
- it's fine for the copied range to start and/or end past end of file, it'll just return a short read.
- A copy of more than 0 bytes returning 0 means you're at end of file.

The particular problem here is that that doesn't fit how clone works at all.

It feels like what happened is that copy_file_range() was made mainly for the clone case, with the idea that copy might be reluctantly accepted as a second-class implementation.

Quoted 8 lines
Quoted 6 lines

But the performance gain of copy offload is too big to just ignore, and in fact it's what copy_file_range does on every filesystem but btrfs and ocfs2 (and maybe cifs?), so I don't think we can just ignore it.

If we had separate copy_file_range and clone_file_range, I *think* it could all be made sensible. Am I missing something?

How would the application (cp) know when to call the clone_file_range and when to call copy_file_range?

Try clone and then fall back on copy if that's not available?

Which is the same thing vfs_copy_file_range() is doing now, but it'd seem less confusing if that logic was in the application.

--b.

#31 lore raw

RFC 2/19 VFS permit cross device vfs_copy_file_range

In reply to Olga Kornievskaia

Allow nfs_copy_file_range to copy across devices.
NFSv4.2 inter server to server copy always copies across devices, and NFSv4.2 intra server to server copy can copy across devices on the same server.

If a file system's fileoperations copy_file_range operation prohibits cross-device copies, fall back to do_splice_direct. This is needed for nfsd_copy_file_range() which is called by the inter server to server destination server acting as an NFS client, and reading the file from the source server.

---
 fs/read_write.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/read_write.c +1 -5
index 1d9e305..75084cd 100644
@@ -1534,10 +1534,6 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	    (file_out->f_flags & O_APPEND))
 		return -EBADF;
 
-	/* this could be relaxed once a method supports cross-fs copies */
-	if (inode_in->i_sb != inode_out->i_sb)
-		return -EXDEV;
-
 	if (len == 0)
 		return 0;
 
@@ -1559,7 +1555,7 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (file_out->f_op->copy_file_range) {
 		ret = file_out->f_op->copy_file_range(file_in, pos_in, file_out,
 						      pos_out, len, flags);
-		if (ret != -EOPNOTSUPP)
+		if (ret != -EOPNOTSUPP && ret != -EXDEV)
 			goto done;
 	}
 
Signature · 1 line
1.8.3.1
#32 lore raw

RFC 3/19 VFS don't try clone if superblocks are different

In reply to Olga Kornievskaia

Only try clone_file_range if superblocks are the same.

---
 fs/read_write.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/read_write.c +2 -1
index 75084cd..00161bd 100644
@@ -1543,7 +1543,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in,
 	 * Try cloning first, this is supported by more file systems, and
 	 * more efficient if both clone and copy are supported (e.g. NFS).
 	 */
-	if (file_in->f_op->clone_file_range) {
+	if (inode_in->i_sb == inode_out->i_sb &&
+			file_in->f_op->clone_file_range) {
 		ret = file_in->f_op->clone_file_range(file_in, pos_in,
 				file_out, pos_out, len);
 		if (ret == 0) {
Signature · 1 line
1.8.3.1
#33 lore raw

RFC 4/19 NFS inter ssc open

In reply to Olga Kornievskaia

NFSv4.2 inter server to server copy requires the destination server to READ the data from the source server using the provided stateid and file handle.

Given an NFSv4 stateid and filehandle from the COPY operaion, provide the destination server with an NFS client function to create a struct file suitable for the destiniation server to READ the data to be copied.

---
 fs/nfs/nfs4_fs.h  |   7 ++++
 fs/nfs/nfs4file.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs4proc.c |   5 ++-
 3 files changed, 115 insertions(+), 3 deletions(-)
fs/nfs/nfs4_fs.h +7 -0
index af285cc..ced3431 100644
@@ -271,6 +271,13 @@ extern int nfs4_set_rw_stateid(nfs4_stateid *stateid,
 		const struct nfs_open_context *ctx,
 		const struct nfs_lock_context *l_ctx,
 		fmode_t fmode);
+extern int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
+				struct nfs_fattr *fattr,
+				struct nfs4_label *label);
+extern int update_open_stateid(struct nfs4_state *state,
+				const nfs4_stateid *open_stateid,
+				const nfs4_stateid *deleg_stateid,
+				fmode_t fmode);
 
 #if defined(CONFIG_NFS_V4_1)
 extern int nfs41_sequence_done(struct rpc_task *, struct nfs4_sequence_res *);
fs/nfs/nfs4file.c +106 -0

118 lines not on this page · raw message

fs/nfs/nfs4proc.c +2 -3
index 1b18368..fbe2452 100644
@@ -89,7 +89,6 @@
 static int _nfs4_recover_proc_open(struct nfs4_opendata *data);
 static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinfo *);
 static void nfs_fixup_referral_attributes(struct nfs_fattr *fattr);
-static int nfs4_proc_getattr(struct nfs_server *, struct nfs_fh *, struct nfs_fattr *, struct nfs4_label *label);
 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr, struct nfs4_label *label);
 static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 			    struct nfs_fattr *fattr, struct iattr *sattr,
@@ -1459,7 +1458,7 @@ static void __update_open_stateid(struct nfs4_state *state,
 	spin_unlock(&state->owner->so_lock);
 }
 
-static int update_open_stateid(struct nfs4_state *state,
+int update_open_stateid(struct nfs4_state *state,
 		const nfs4_stateid *open_stateid,
 		const nfs4_stateid *delegation,
 		fmode_t fmode)
@@ -3609,7 +3608,7 @@ static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
 	return nfs4_call_sync(server->client, server, &msg, &args.seq_args, &res.seq_res, 0);
 }
 
-static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
+int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
 				struct nfs_fattr *fattr, struct nfs4_label *label)
 {
 	struct nfs4_exception exception = { };
Signature · 1 line
1.8.3.1
#34 lore raw

RFC 5/19 NFS add COPY_NOTIFY operation

In reply to Olga Kornievskaia

Try using the delegation stateid, then the open stateid.

Only NL4_NETATTR, No support for NL4_NAME and NL4_URL. Allow only one source server address to be returned for now.

---
 fs/nfs/internal.h         |  10 +++
 fs/nfs/nfs42.h            |   4 +
 fs/nfs/nfs42proc.c        | 101 +++++++++++++++++++++++++
 fs/nfs/nfs42xdr.c         | 186 ++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs4_fs.h          |   1 +
 fs/nfs/nfs4file.c         |  33 +++++++-
 fs/nfs/nfs4proc.c         |   1 +
 fs/nfs/nfs4state.c        |   2 +-
 fs/nfs/nfs4xdr.c          |   1 +
 include/linux/nfs4.h      |  34 +++++++++
 include/linux/nfs_fs_sb.h |   1 +
 include/linux/nfs_xdr.h   |  18 +++++
 12 files changed, 390 insertions(+), 2 deletions(-)
fs/nfs/internal.h +10 -0
index 09ca509..c006f73 100644
@@ -7,6 +7,7 @@
 #include <linux/security.h>
 #include <linux/crc32.h>
 #include <linux/nfs_page.h>
+#include <linux/sunrpc/addr.h>
 
 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
 
@@ -763,3 +764,12 @@ static inline bool nfs_error_is_fatal(int err)
 		return false;
 	}
 }
+
+static inline bool nfs42_intra_ssc(struct file *in, struct file *out)
+{
+	struct nfs_client *c_in = (NFS_SERVER(file_inode(in)))->nfs_client;
+	struct nfs_client *c_out = (NFS_SERVER(file_inode(out)))->nfs_client;
+
+	return rpc_cmp_addr((struct sockaddr *)&c_in->cl_addr,
+				(struct sockaddr *)&c_out->cl_addr);
+}
fs/nfs/nfs42.h +4 -0
index b6cd153..2f780d2 100644
@@ -12,6 +12,7 @@
 #define PNFS_LAYOUTSTATS_MAXDEV (4)
 
 /* nfs4.2proc.c */
+#if defined(CONFIG_NFS_V4_2)
 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);
@@ -19,5 +20,8 @@
 int nfs42_proc_layoutstats_generic(struct nfs_server *,
 				   struct nfs42_layoutstat_data *);
 int nfs42_proc_clone(struct file *, struct file *, loff_t, loff_t, loff_t);
+int nfs42_proc_copy_notify(struct file *, struct file *,
+			   struct nfs42_copy_notify_res *);
+#endif /* CONFIG_NFS_V4_2 */
 
 #endif /* __LINUX_FS_NFS_NFS4_2_H */
fs/nfs/nfs42proc.c +101 -0

122 lines not on this page · raw message

fs/nfs/nfs42xdr.c +186 -0

234 lines not on this page · raw message

fs/nfs/nfs4_fs.h +1 -0
index ced3431..c23089e 100644
@@ -453,6 +453,7 @@ extern void nfs41_handle_server_scope(struct nfs_client *,
 extern int nfs4_select_rw_stateid(struct nfs4_state *, fmode_t,
 		const struct nfs_lock_context *, nfs4_stateid *,
 		struct rpc_cred **);
+extern void nfs4_copy_open_stateid(nfs4_stateid *, struct nfs4_state *);
 
 extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
 extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
fs/nfs/nfs4file.c +32 -1
index 0730c62..dc6cab3 100644
@@ -134,10 +134,41 @@ 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 nfs42_copy_notify_res *cn_resp = NULL;
+	ssize_t ret;
+
 	if (file_inode(file_in) == file_inode(file_out))
 		return -EINVAL;
 
-	return nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count);
+	if (nfs42_intra_ssc(file_in, file_out)) {  /* Intra-ssc */
+		if (file_in->f_op != file_out->f_op)
+			return -EXDEV;
+	} else {  /* Inter-ssc */
+		cn_resp = kzalloc(sizeof(struct nfs42_copy_notify_res),
+				  GFP_NOFS);
+		if (unlikely(cn_resp == NULL))
+			return -ENOMEM;
+
+		cn_resp->cnr_src.nl_svr = kzalloc(NFS42_MAX_SSC_SRC *
+						sizeof(struct nl4_server),
+						GFP_NOFS);
+		if (unlikely(cn_resp->cnr_src.nl_svr == NULL)) {
+			kfree(cn_resp);
+			return -ENOMEM;
+		}
+
+		ret = nfs42_proc_copy_notify(file_in, file_out, cn_resp);
+		if (ret)
+			goto out;
+	}
+	ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count);
+
+out:
+	if (cn_resp) {
+		kfree(cn_resp->cnr_src.nl_svr);
+		kfree(cn_resp);
+	}
+	return ret;
 }
 
 static loff_t nfs4_file_llseek(struct file *filep, loff_t offset, int whence)
fs/nfs/nfs4proc.c +1 -0
index fbe2452..4633b26 100644
@@ -9244,6 +9244,7 @@ static bool nfs4_match_stateid(const nfs4_stateid *s1,
 		| NFS_CAP_ATOMIC_OPEN_V1
 		| NFS_CAP_ALLOCATE
 		| NFS_CAP_COPY
+		| NFS_CAP_COPY_NOTIFY
 		| NFS_CAP_DEALLOCATE
 		| NFS_CAP_SEEK
 		| NFS_CAP_LAYOUTSTATS
fs/nfs/nfs4state.c +1 -1
index 8156bad..5827d95 100644
@@ -979,7 +979,7 @@ static int nfs4_copy_lock_stateid(nfs4_stateid *dst,
 	return ret;
 }
 
-static void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
+void nfs4_copy_open_stateid(nfs4_stateid *dst, struct nfs4_state *state)
 {
 	const nfs4_stateid *src;
 	int seq;
fs/nfs/nfs4xdr.c +1 -0
index f0369e3..9def5c6 100644
@@ -7573,6 +7573,7 @@ struct rpc_procinfo	nfs4_procedures[] = {
 	PROC(LAYOUTSTATS,	enc_layoutstats,	dec_layoutstats),
 	PROC(CLONE,		enc_clone,		dec_clone),
 	PROC(COPY,		enc_copy,		dec_copy),
+	PROC(COPY_NOTIFY,	enc_copy_notify,	dec_copy_notify),
 #endif /* CONFIG_NFS_V4_2 */
 };
 
include/linux/nfs4.h +34 -0
index 1b1ca04..e4be278 100644
@@ -15,6 +15,7 @@
 #include <linux/list.h>
 #include <linux/uidgid.h>
 #include <uapi/linux/nfs4.h>
+#include <linux/sunrpc/msg_prot.h>
 
 enum nfs4_acl_whotype {
 	NFS4_ACL_WHO_NAMED = 0,
@@ -523,6 +524,7 @@ enum {
 	NFSPROC4_CLNT_LAYOUTSTATS,
 	NFSPROC4_CLNT_CLONE,
 	NFSPROC4_CLNT_COPY,
+	NFSPROC4_CLNT_COPY_NOTIFY,
 };
 
 /* nfs41 types */
@@ -657,4 +659,36 @@ struct nfs4_op_map {
 	} u;
 };
 
+struct nfs42_netaddr {
+	unsigned int	na_netid_len;
+	char		na_netid[RPCBIND_MAXNETIDLEN + 1];
+	unsigned int	na_uaddr_len;
+	char		na_uaddr[RPCBIND_MAXUADDRLEN + 1];
+};
+
+enum netloc_type4 {
+	NL4_NAME		= 1,
+	NL4_URL			= 2,
+	NL4_NETADDR		= 3,
+};
+
+struct nl4_server {
+	enum netloc_type4	nl4_type;
+	union {
+		struct { /* NL4_NAME, NL4_URL */
+			int	nl4_str_sz;
+			char	nl4_str[NFS4_OPAQUE_LIMIT + 1];
+		};
+		struct nfs42_netaddr	nl4_addr; /* NL4_NETADDR */
+	} u;
+};
+
+/*  support 1 nl4_server for now */
+#define NFS42_MAX_SSC_SRC       1
+
+struct nl4_servers {
+	int			nl_nsvr;
+	struct nl4_server	*nl_svr;
+};
+
 #endif
include/linux/nfs_fs_sb.h +1 -0
index b34097c..a538b69 100644
@@ -250,5 +250,6 @@ struct nfs_server {
 #define NFS_CAP_LAYOUTSTATS	(1U << 22)
 #define NFS_CAP_CLONE		(1U << 23)
 #define NFS_CAP_COPY		(1U << 24)
+#define NFS_CAP_COPY_NOTIFY	(1U << 25)
 
 #endif
include/linux/nfs_xdr.h +18 -0
index 348f7c1..1af723f 100644
@@ -1385,6 +1385,24 @@ struct nfs42_copy_res {
 	bool				synchronous;
 };
 
+struct nfs42_copy_notify_args {
+	struct nfs4_sequence_args	cna_seq_args;
+
+	struct nfs_fh		*cna_src_fh;
+	nfs4_stateid		cna_src_stateid;
+	/* cna_destiniation_server */
+	struct nl4_server	cna_dst;
+};
+
+struct nfs42_copy_notify_res {
+	struct nfs4_sequence_res	cnr_seq_res;
+
+	struct nfstime4		cnr_lease_time;
+	nfs4_stateid		cnr_stateid;
+	/* cnr_source_server, for now, always 1 */
+	struct nl4_servers	cnr_src;
+};
+
 struct nfs42_seek_args {
 	struct nfs4_sequence_args	seq_args;
 
Signature · 1 line
1.8.3.1
#35 lore raw

RFC 6/19 NFS add ca_source_server<> to COPY

In reply to Olga Kornievskaia

Support only one source server address: the same address that the client and source server use.

---
 fs/nfs/nfs42.h          |  3 ++-
 fs/nfs/nfs42proc.c      | 26 +++++++++++++++++---------
 fs/nfs/nfs42xdr.c       | 19 +++++++++++++++++--
 fs/nfs/nfs4file.c       |  7 ++++++-
 include/linux/nfs_xdr.h |  2 ++
 5 files changed, 44 insertions(+), 13 deletions(-)
fs/nfs/nfs42.h +2 -1
index 2f780d2..820fd63 100644
@@ -14,7 +14,8 @@
 /* nfs4.2proc.c */
 #if defined(CONFIG_NFS_V4_2)
 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);
+ssize_t nfs42_proc_copy(struct file *, loff_t, struct file *, loff_t, size_t,
+			struct nl4_servers *, nfs4_stateid *);
 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 *,
fs/nfs/nfs42proc.c +17 -9
index a28d828..ade2938 100644
@@ -174,7 +174,9 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 				struct file *dst,
 				struct nfs_lock_context *dst_lock,
 				struct nfs42_copy_args *args,
-				struct nfs42_copy_res *res)
+				struct nfs42_copy_res *res,
+				struct nl4_servers *nss,
+				nfs4_stateid *cnr_stateid)
 {
 	struct rpc_message msg = {
 		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],
@@ -188,11 +190,15 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	size_t count = args->count;
 	int status;
 
-	status = nfs4_set_rw_stateid(&args->src_stateid, src_lock->open_context,
-				     src_lock, FMODE_READ);
-	if (status)
-		return status;
-
+	if (nss) {
+		args->cp_src = nss;
+		nfs4_stateid_copy(&args->src_stateid, cnr_stateid);
+	} else {
+		status = nfs4_set_rw_stateid(&args->src_stateid,
+				src_lock->open_context, src_lock, FMODE_READ);
+		if (status)
+			return status;
+	}
 	status = nfs_filemap_write_and_wait_range(file_inode(src)->i_mapping,
 			pos_src, pos_src + (loff_t)count - 1);
 	if (status)
@@ -227,8 +233,9 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 }
 
 ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
-			struct file *dst, loff_t pos_dst,
-			size_t count)
+			struct file *dst, loff_t pos_dst, size_t count,
+			struct nl4_servers *nss,
+			nfs4_stateid *cnr_stateid)
 {
 	struct nfs_server *server = NFS_SERVER(file_inode(dst));
 	struct nfs_lock_context *src_lock;
@@ -272,7 +279,8 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
 		inode_lock(file_inode(dst));
 		err = _nfs42_proc_copy(src, src_lock,
 				dst, dst_lock,
-				&args, &res);
+				&args, &res,
+				nss, cnr_stateid);
 		inode_unlock(file_inode(dst));
 
 		if (err >= 0)
fs/nfs/nfs42xdr.c +17 -2
index aad2b08..fa0daaa 100644
@@ -20,7 +20,10 @@
 #define encode_copy_maxsz		(op_encode_hdr_maxsz +          \
 					 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
 					 XDR_QUADLEN(NFS4_STATEID_SIZE) + \
-					 2 + 2 + 2 + 1 + 1 + 1)
+					 2 + 2 + 2 + 1 + 1 + 1 +\
+					 1 + /* One cnr_source_server */\
+					 1 + /* nl4_type */ \
+					 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
 #define decode_copy_maxsz		(op_decode_hdr_maxsz + \
 					 NFS42_WRITE_RES_SIZE + \
 					 1 /* cr_consecutive */ + \
@@ -164,6 +167,9 @@ static void encode_copy(struct xdr_stream *xdr,
 			struct nfs42_copy_args *args,
 			struct compound_hdr *hdr)
 {
+	struct nl4_server *ns;
+	int i;
+
 	encode_op_hdr(xdr, OP_COPY, decode_copy_maxsz, hdr);
 	encode_nfs4_stateid(xdr, &args->src_stateid);
 	encode_nfs4_stateid(xdr, &args->dst_stateid);
@@ -174,7 +180,16 @@ static void encode_copy(struct xdr_stream *xdr,
 
 	encode_uint32(xdr, 1); /* consecutive = true */
 	encode_uint32(xdr, 1); /* synchronous = true */
-	encode_uint32(xdr, 0); /* src server list */
+	if (args->cp_src == NULL) { /* intra-ssc */
+		encode_uint32(xdr, 0); /* no src server list */
+		return;
+	}
+	encode_uint32(xdr, args->cp_src->nl_nsvr);
+	ns = args->cp_src->nl_svr;
+	for (i = 0; i < args->cp_src->nl_nsvr; i++) {
+		encode_nl4_server(xdr, args->cp_src->nl_svr);
+		ns++;
+	}
 }
 
 static void encode_copy_notify(struct xdr_stream *xdr,
fs/nfs/nfs4file.c +6 -1
index dc6cab3..43a2346 100644
@@ -135,6 +135,8 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 				    size_t count, unsigned int flags)
 {
 	struct nfs42_copy_notify_res *cn_resp = NULL;
+	struct nl4_servers *nss = NULL;
+	nfs4_stateid *cnrs = NULL;
 	ssize_t ret;
 
 	if (file_inode(file_in) == file_inode(file_out))
@@ -160,8 +162,11 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 		ret = nfs42_proc_copy_notify(file_in, file_out, cn_resp);
 		if (ret)
 			goto out;
+		nss = &cn_resp->cnr_src;
+		cnrs = &cn_resp->cnr_stateid;
 	}
-	ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count);
+	ret = nfs42_proc_copy(file_in, pos_in, file_out, pos_out, count, nss,
+				cnrs);
 
 out:
 	if (cn_resp) {
include/linux/nfs_xdr.h +2 -0
index 1af723f..9d4ea77 100644
@@ -1371,6 +1371,8 @@ struct nfs42_copy_args {
 	u64				dst_pos;
 
 	u64				count;
+	/* Support one source server */
+	struct nl4_servers		*cp_src;
 };
 
 struct nfs42_write_res {
Signature · 1 line
1.8.3.1
#36 lore raw

RFC 7/19 NFS CB_OFFLOAD xdr

In reply to Olga Kornievskaia
---
 fs/nfs/callback.h      | 13 ++++++++
 fs/nfs/callback_proc.c |  7 +++++
 fs/nfs/callback_xdr.c  | 80 +++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 99 insertions(+), 1 deletion(-)
fs/nfs/callback.h +13 -0
index c701c30..e4ab65d 100644
@@ -189,6 +189,19 @@ extern __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args,
 					 void *dummy,
 					 struct cb_process_state *cps);
 #endif /* CONFIG_NFS_V4_1 */
+#ifdef CONFIG_NFS_V4_2
+struct cb_offloadargs {
+	struct nfs_fh		coa_fh;
+	nfs4_stateid		coa_stateid;
+	uint32_t		error;
+	uint64_t		wr_count;
+	struct nfs_writeverf	wr_writeverf;
+};
+
+extern __be32 nfs4_callback_offload(
+	struct cb_offloadargs *args,
+	void *dummy, struct cb_process_state *cps);
+#endif /* CONFIG_NFS_V4_2 */
 extern int check_gss_callback_principal(struct nfs_client *, struct svc_rqst *);
 extern __be32 nfs4_callback_getattr(struct cb_getattrargs *args,
 				    struct cb_getattrres *res,
fs/nfs/callback_proc.c +7 -0
index f073a6d2c..b68b803 100644
@@ -680,3 +680,10 @@ __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args, void *dummy,
 	return htonl(NFS4_OK);
 }
 #endif /* CONFIG_NFS_V4_1 */
+#ifdef CONFIG_NFS_V4_2
+__be32 nfs4_callback_offload(struct cb_offloadargs *args, void *dummy,
+				struct cb_process_state *cps)
+{
+	return 0;
+}
+#endif /* CONFIG_NFS_V4_2 */
fs/nfs/callback_xdr.c +79 -1

105 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#37 lore raw

RFC 8/19 NFS OFFLOAD_STATUS xdr

In reply to Olga Kornievskaia
---
 fs/nfs/nfs42xdr.c         | 87 +++++++++++++++++++++++++++++++++++++++++++++++
 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   | 12 +++++++
 6 files changed, 103 insertions(+)
fs/nfs/nfs42xdr.c +87 -0
index fa0daaa..352af86 100644
@@ -38,6 +38,11 @@
 					 1 + /* Support 1 cnr_source_server */\
 					 1 + /* nl4_type */ \
 					 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
+#define encode_offload_status_maxsz	(op_encode_hdr_maxsz + \
+					 XDR_QUADLEN(NFS4_STATEID_SIZE))
+#define decode_offload_status_maxsz	(op_decode_hdr_maxsz + \
+					 2 /* osr_count */ + \
+					 1 + 1 /* osr_complete<1> */)
 #define encode_deallocate_maxsz		(op_encode_hdr_maxsz + \
 					 encode_fallocate_maxsz)
 #define decode_deallocate_maxsz		(op_decode_hdr_maxsz)
@@ -91,6 +96,12 @@
 #define NFS4_dec_copy_notify_sz		(compound_decode_hdr_maxsz + \
 					 decode_putfh_maxsz + \
 					 decode_copy_notify_maxsz)
+#define NFS4_enc_offload_status_sz	(compound_encode_hdr_maxsz + \
+					 encode_putfh_maxsz + \
+					 encode_offload_status_maxsz)
+#define NFS4_dec_offload_status_sz	(compound_decode_hdr_maxsz + \
+					 decode_putfh_maxsz + \
+					 decode_offload_status_maxsz)
 #define NFS4_enc_deallocate_sz		(compound_encode_hdr_maxsz + \
 					 encode_putfh_maxsz + \
 					 encode_deallocate_maxsz + \
@@ -201,6 +212,14 @@ static void encode_copy_notify(struct xdr_stream *xdr,
 	encode_nl4_server(xdr, &args->cna_dst);
 }
 
+static void encode_offload_status(struct xdr_stream *xdr,
+				  struct nfs42_offload_status_args *args,
+				  struct compound_hdr *hdr)
+{
+	encode_op_hdr(xdr, OP_OFFLOAD_STATUS, decode_offload_status_maxsz, hdr);
+	encode_nfs4_stateid(xdr, &args->osa_stateid);
+}
+
 static void encode_deallocate(struct xdr_stream *xdr,
 			      struct nfs42_falloc_args *args,
 			      struct compound_hdr *hdr)
@@ -320,6 +339,24 @@ static void nfs4_xdr_enc_copy_notify(struct rpc_rqst *req,
 }
 
 /*
+ * Encode OFFLOAD_STATUS request
+ */
+static void nfs4_xdr_enc_offload_status(struct rpc_rqst *req,
+					struct xdr_stream *xdr,
+					struct nfs42_offload_status_args *args)
+{
+	struct compound_hdr hdr = {
+		.minorversion = nfs4_xdr_minorversion(&args->osa_seq_args),
+	};
+
+	encode_compound_hdr(xdr, req, &hdr);
+	encode_sequence(xdr, &args->osa_seq_args, &hdr);
+	encode_putfh(xdr, args->osa_src_fh, &hdr);
+	encode_offload_status(xdr, args, &hdr);
+	encode_nops(&hdr);
+}
+
+/*
  * Encode DEALLOCATE request
  */
 static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
@@ -567,6 +604,31 @@ static int decode_copy_notify(struct xdr_stream *xdr,
 	return -EIO;
 }
 
+static int decode_offload_status(struct xdr_stream *xdr,
+				 struct nfs42_offload_status_res *res)
+{
+	__be32 *p;
+	uint32_t count;
+	int status;
+
+	status = decode_op_hdr(xdr, OP_OFFLOAD_STATUS);
+	if (status)
+		return status;
+	p = xdr_inline_decode(xdr, 8 + 4);
+	if (unlikely(!p))
+		goto out_overflow;
+	p = xdr_decode_hyper(p, &res->osr_count);
+	count = be32_to_cpup(p++);
+	if (count) {
+		p = xdr_inline_decode(xdr, 4);
+		res->osr_status = be32_to_cpup(p);
+	}
+	return 0;
+out_overflow:
+	print_overflow_msg(__func__, xdr);
+	return -EIO;
+}
+
 static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
 {
 	return decode_op_hdr(xdr, OP_DEALLOCATE);
@@ -687,6 +749,31 @@ static int nfs4_xdr_dec_copy_notify(struct rpc_rqst *rqstp,
 }
 
 /*
+ * Decode OFFLOAD_STATUS response
+ */
+static int nfs4_xdr_dec_offload_status(struct rpc_rqst *rqstp,
+				       struct xdr_stream *xdr,
+				       struct nfs42_offload_status_res *res)
+{
+	struct compound_hdr hdr;
+	int status;
+
+	status = decode_compound_hdr(xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_sequence(xdr, &res->osr_seq_res, rqstp);
+	if (status)
+		goto out;
+	status = decode_putfh(xdr);
+	if (status)
+		goto out;
+	status = decode_offload_status(xdr, res);
+
+out:
+	return status;
+}
+
+/*
  * Decode DEALLOCATE request
  */
 static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
fs/nfs/nfs4proc.c +1 -0
index 4633b26..9071652 100644
@@ -9245,6 +9245,7 @@ static bool nfs4_match_stateid(const nfs4_stateid *s1,
 		| NFS_CAP_ALLOCATE
 		| NFS_CAP_COPY
 		| NFS_CAP_COPY_NOTIFY
+		| NFS_CAP_OFFLOAD_STATUS
 		| NFS_CAP_DEALLOCATE
 		| NFS_CAP_SEEK
 		| NFS_CAP_LAYOUTSTATS
fs/nfs/nfs4xdr.c +1 -0
index 9def5c6..a01ff49 100644
@@ -7574,6 +7574,7 @@ struct rpc_procinfo	nfs4_procedures[] = {
 	PROC(CLONE,		enc_clone,		dec_clone),
 	PROC(COPY,		enc_copy,		dec_copy),
 	PROC(COPY_NOTIFY,	enc_copy_notify,	dec_copy_notify),
+	PROC(OFFLOAD_STATUS,	enc_offload_status,	dec_offload_status),
 #endif /* CONFIG_NFS_V4_2 */
 };
 
include/linux/nfs4.h +1 -0
index e4be278..0ed1026 100644
@@ -525,6 +525,7 @@ enum {
 	NFSPROC4_CLNT_CLONE,
 	NFSPROC4_CLNT_COPY,
 	NFSPROC4_CLNT_COPY_NOTIFY,
+	NFSPROC4_CLNT_OFFLOAD_STATUS,
 };
 
 /* nfs41 types */
include/linux/nfs_fs_sb.h +1 -0
index a538b69..4bc9a13 100644
@@ -251,5 +251,6 @@ struct nfs_server {
 #define NFS_CAP_CLONE		(1U << 23)
 #define NFS_CAP_COPY		(1U << 24)
 #define NFS_CAP_COPY_NOTIFY	(1U << 25)
+#define NFS_CAP_OFFLOAD_STATUS	(1U << 26)
 
 #endif
include/linux/nfs_xdr.h +12 -0
index 9d4ea77..65b4323 100644
@@ -1405,6 +1405,18 @@ struct nfs42_copy_notify_res {
 	struct nl4_servers	cnr_src;
 };
 
+struct nfs42_offload_status_args {
+	struct nfs4_sequence_args	osa_seq_args;
+	struct nfs_fh			*osa_src_fh;
+	nfs4_stateid			osa_stateid;
+};
+
+struct nfs42_offload_status_res {
+	struct nfs4_sequence_res	osr_seq_res;
+	uint64_t			osr_count;
+	int				osr_status;
+};
+
 struct nfs42_seek_args {
 	struct nfs4_sequence_args	seq_args;
 
Signature · 1 line
1.8.3.1
#38 lore raw

RFC 9/19 NFS OFFLOAD_STATUS op

In reply to Olga Kornievskaia
---
 fs/nfs/nfs42.h     |  2 ++
 fs/nfs/nfs42proc.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
fs/nfs/nfs42.h +2 -0
index 820fd63..47ffbb0 100644
@@ -23,6 +23,8 @@ int nfs42_proc_layoutstats_generic(struct nfs_server *,
 int nfs42_proc_clone(struct file *, struct file *, loff_t, loff_t, loff_t);
 int nfs42_proc_copy_notify(struct file *, struct file *,
 			   struct nfs42_copy_notify_res *);
+int nfs42_proc_offload_status(struct file *, nfs4_stateid *,
+			      struct nfs42_offload_status_res *);
 #endif /* CONFIG_NFS_V4_2 */
 
 #endif /* __LINUX_FS_NFS_NFS4_2_H */
fs/nfs/nfs42proc.c +42 -0

48 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#39 lore raw

RFC 10/19 NFS OFFLOAD_CANCEL xdr

In reply to Olga Kornievskaia
---
 fs/nfs/nfs42xdr.c         | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs4proc.c         |  1 +
 fs/nfs/nfs4xdr.c          |  1 +
 include/linux/nfs4.h      |  1 +
 include/linux/nfs_fs_sb.h |  1 +
 5 files changed, 70 insertions(+)
fs/nfs/nfs42xdr.c +66 -0
index 352af86..d782606 100644
@@ -43,6 +43,9 @@
 #define decode_offload_status_maxsz	(op_decode_hdr_maxsz + \
 					 2 /* osr_count */ + \
 					 1 + 1 /* osr_complete<1> */)
+#define encode_offload_cancel_maxsz	(op_encode_hdr_maxsz + \
+					 XDR_QUADLEN(NFS4_STATEID_SIZE))
+#define decode_offload_cancel_maxsz	(op_decode_hdr_maxsz)
 #define encode_deallocate_maxsz		(op_encode_hdr_maxsz + \
 					 encode_fallocate_maxsz)
 #define decode_deallocate_maxsz		(op_decode_hdr_maxsz)
@@ -102,6 +105,12 @@
 #define NFS4_dec_offload_status_sz	(compound_decode_hdr_maxsz + \
 					 decode_putfh_maxsz + \
 					 decode_offload_status_maxsz)
+#define NFS4_enc_offload_cancel_sz	(compound_encode_hdr_maxsz + \
+					 encode_putfh_maxsz + \
+					 encode_offload_cancel_maxsz)
+#define NFS4_dec_offload_cancel_sz	(compound_decode_hdr_maxsz + \
+					 decode_putfh_maxsz + \
+					 decode_offload_cancel_maxsz)
 #define NFS4_enc_deallocate_sz		(compound_encode_hdr_maxsz + \
 					 encode_putfh_maxsz + \
 					 encode_deallocate_maxsz + \
@@ -220,6 +229,14 @@ static void encode_offload_status(struct xdr_stream *xdr,
 	encode_nfs4_stateid(xdr, &args->osa_stateid);
 }
 
+static void encode_offload_cancel(struct xdr_stream *xdr,
+				  struct nfs42_offload_status_args *args,
+				  struct compound_hdr *hdr)
+{
+	encode_op_hdr(xdr, OP_OFFLOAD_CANCEL, decode_offload_cancel_maxsz, hdr);
+	encode_nfs4_stateid(xdr, &args->osa_stateid);
+}
+
 static void encode_deallocate(struct xdr_stream *xdr,
 			      struct nfs42_falloc_args *args,
 			      struct compound_hdr *hdr)
@@ -357,6 +374,24 @@ static void nfs4_xdr_enc_offload_status(struct rpc_rqst *req,
 }
 
 /*
+ * Encode OFFLOAD_CANEL request
+ */
+static void nfs4_xdr_enc_offload_cancel(struct rpc_rqst *req,
+					struct xdr_stream *xdr,
+					struct nfs42_offload_status_args *args)
+{
+	struct compound_hdr hdr = {
+		.minorversion = nfs4_xdr_minorversion(&args->osa_seq_args),
+	};
+
+	encode_compound_hdr(xdr, req, &hdr);
+	encode_sequence(xdr, &args->osa_seq_args, &hdr);
+	encode_putfh(xdr, args->osa_src_fh, &hdr);
+	encode_offload_cancel(xdr, args, &hdr);
+	encode_nops(&hdr);
+}
+
+/*
  * Encode DEALLOCATE request
  */
 static void nfs4_xdr_enc_deallocate(struct rpc_rqst *req,
@@ -629,6 +664,12 @@ static int decode_offload_status(struct xdr_stream *xdr,
 	return -EIO;
 }
 
+static int decode_offload_cancel(struct xdr_stream *xdr,
+				 struct nfs42_offload_status_res *res)
+{
+	return decode_op_hdr(xdr, OP_OFFLOAD_CANCEL);
+}
+
 static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *res)
 {
 	return decode_op_hdr(xdr, OP_DEALLOCATE);
@@ -774,6 +815,31 @@ static int nfs4_xdr_dec_offload_status(struct rpc_rqst *rqstp,
 }
 
 /*
+ * Decode OFFLOAD_CANCEL response
+ */
+static int nfs4_xdr_dec_offload_cancel(struct rpc_rqst *rqstp,
+				       struct xdr_stream *xdr,
+				       struct nfs42_offload_status_res *res)
+{
+	struct compound_hdr hdr;
+	int status;
+
+	status = decode_compound_hdr(xdr, &hdr);
+	if (status)
+		goto out;
+	status = decode_sequence(xdr, &res->osr_seq_res, rqstp);
+	if (status)
+		goto out;
+	status = decode_putfh(xdr);
+	if (status)
+		goto out;
+	status = decode_offload_cancel(xdr, res);
+
+out:
+	return status;
+}
+
+/*
  * Decode DEALLOCATE request
  */
 static int nfs4_xdr_dec_deallocate(struct rpc_rqst *rqstp,
fs/nfs/nfs4proc.c +1 -0
index 9071652..59be0f7 100644
@@ -9246,6 +9246,7 @@ static bool nfs4_match_stateid(const nfs4_stateid *s1,
 		| NFS_CAP_COPY
 		| NFS_CAP_COPY_NOTIFY
 		| NFS_CAP_OFFLOAD_STATUS
+		| NFS_CAP_OFFLOAD_CANCEL
 		| NFS_CAP_DEALLOCATE
 		| NFS_CAP_SEEK
 		| NFS_CAP_LAYOUTSTATS
fs/nfs/nfs4xdr.c +1 -0
index a01ff49..697edf3 100644
@@ -7575,6 +7575,7 @@ struct rpc_procinfo	nfs4_procedures[] = {
 	PROC(COPY,		enc_copy,		dec_copy),
 	PROC(COPY_NOTIFY,	enc_copy_notify,	dec_copy_notify),
 	PROC(OFFLOAD_STATUS,	enc_offload_status,	dec_offload_status),
+	PROC(OFFLOAD_CANCEL,    enc_offload_cancel,     dec_offload_cancel),
 #endif /* CONFIG_NFS_V4_2 */
 };
 
include/linux/nfs4.h +1 -0
index 0ed1026..e43c106 100644
@@ -526,6 +526,7 @@ enum {
 	NFSPROC4_CLNT_COPY,
 	NFSPROC4_CLNT_COPY_NOTIFY,
 	NFSPROC4_CLNT_OFFLOAD_STATUS,
+	NFSPROC4_CLNT_OFFLOAD_CANCEL,
 };
 
 /* nfs41 types */
include/linux/nfs_fs_sb.h +1 -0
index 4bc9a13..488ff40 100644
@@ -252,5 +252,6 @@ struct nfs_server {
 #define NFS_CAP_COPY		(1U << 24)
 #define NFS_CAP_COPY_NOTIFY	(1U << 25)
 #define NFS_CAP_OFFLOAD_STATUS	(1U << 26)
+#define NFS_CAP_OFFLOAD_CANCEL	(1U << 27)
 
 #endif
Signature · 1 line
1.8.3.1
#40 lore raw

RFC 11/19 NFS COPY xdr handle async reply

In reply to Olga Kornievskaia

If server returns async reply, it must include a callback stateid, wr_callback_id in the write_response4.

---
 fs/nfs/nfs42xdr.c       | 22 ++++++++++++----------
 include/linux/nfs_xdr.h |  1 +
 2 files changed, 13 insertions(+), 10 deletions(-)
fs/nfs/nfs42xdr.c +12 -10
index d782606..d5393ef 100644
@@ -480,21 +480,23 @@ static int decode_write_response(struct xdr_stream *xdr,
 				 struct nfs42_write_res *res)
 {
 	__be32 *p;
+	int status, count;
 
-	p = xdr_inline_decode(xdr, 4 + 8 + 4);
+	p = xdr_inline_decode(xdr, 4);
 	if (unlikely(!p))
 		goto out_overflow;
-
-	/*
-	 * We never use asynchronous mode, so warn if a server returns
-	 * a stateid.
-	 */
-	if (unlikely(*p != 0)) {
-		pr_err_once("%s: server has set unrequested "
-				"asynchronous mode\n", __func__);
+	count = be32_to_cpup(p);
+	if (count > 1)
 		return -EREMOTEIO;
+	else if (count == 1) {
+		status = decode_opaque_fixed(xdr, &res->stateid,
+				NFS4_STATEID_SIZE);
+		if (unlikely(status))
+			goto out_overflow;
 	}
-	p++;
+	p = xdr_inline_decode(xdr, 8 + 4);
+	if (unlikely(!p))
+		goto out_overflow;
 	p = xdr_decode_hyper(p, &res->count);
 	res->verifier.committed = be32_to_cpup(p);
 	return decode_verifier(xdr, &res->verifier.verifier);
include/linux/nfs_xdr.h +1 -0
index 65b4323..2ed335e 100644
@@ -1376,6 +1376,7 @@ struct nfs42_copy_args {
 };
 
 struct nfs42_write_res {
+	nfs4_stateid		stateid;
 	u64			count;
 	struct nfs_writeverf	verifier;
 };
Signature · 1 line
1.8.3.1
#41 lore raw

RFC 12/19 NFS add support for asynchronous COPY

In reply to Olga Kornievskaia

Change xdr to always send COPY asynchronously.

Keep the list copies send in a list under a server structure. Once copy is sent, it waits on a completion structure that will be signalled by the callback thread that receives CB_OFFLOAD.

---
 fs/nfs/callback_proc.c    | 34 ++++++++++++++++++++++++++++++++++
 fs/nfs/client.c           |  1 +
 fs/nfs/nfs42proc.c        | 46 ++++++++++++++++++++++++++++++++++++++++++----
 fs/nfs/nfs42xdr.c         |  2 +-
 include/linux/nfs_fs.h    |  9 +++++++++
 include/linux/nfs_fs_sb.h |  1 +
 6 files changed, 88 insertions(+), 5 deletions(-)
fs/nfs/callback_proc.c +34 -0
index b68b803..c1b081c 100644
@@ -681,9 +681,43 @@ __be32 nfs4_callback_notify_lock(struct cb_notify_lock_args *args, void *dummy,
 }
 #endif /* CONFIG_NFS_V4_1 */
 #ifdef CONFIG_NFS_V4_2
+static void nfs4_copy_cb_args(struct nfs4_copy_state *cp_state,
+				struct cb_offloadargs *args)
+{
+	cp_state->count = args->wr_count;
+	cp_state->error = args->error;
+	if (!args->error) {
+		cp_state->verf.committed = args->wr_writeverf.committed;
+		memcpy(&cp_state->verf.verifier.data[0],
+			&args->wr_writeverf.verifier.data[0],
+			NFS4_VERIFIER_SIZE);
+	}
+}
+
 __be32 nfs4_callback_offload(struct cb_offloadargs *args, void *dummy,
 				struct cb_process_state *cps)
 {
+	struct nfs_server *server;
+	struct nfs4_copy_state *copy;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
+				client_link) {
+		spin_lock(&server->nfs_client->cl_lock);
+		list_for_each_entry(copy, &server->ss_copies, copies) {
+			if (memcmp(args->coa_stateid.other,
+					copy->stateid.other,
+					sizeof(args->coa_stateid.other)))
+				continue;
+			nfs4_copy_cb_args(copy, args);
+			complete(&copy->completion);
+			spin_unlock(&server->nfs_client->cl_lock);
+			goto out;
+		}
+		spin_unlock(&server->nfs_client->cl_lock);
+	}
+out:
+	rcu_read_unlock();
 	return 0;
 }
 #endif /* CONFIG_NFS_V4_2 */
fs/nfs/client.c +1 -0
index 91a8d61..a72cd1d 100644
@@ -885,6 +885,7 @@ struct nfs_server *nfs_alloc_server(void)
 	INIT_LIST_HEAD(&server->delegations);
 	INIT_LIST_HEAD(&server->layouts);
 	INIT_LIST_HEAD(&server->state_owners_lru);
+	INIT_LIST_HEAD(&server->ss_copies);
 
 	atomic_set(&server->active, 0);
 
fs/nfs/nfs42proc.c +42 -4

70 lines not on this page · raw message

fs/nfs/nfs42xdr.c +1 -1
index d5393ef..9e388e1 100644
@@ -199,7 +199,7 @@ static void encode_copy(struct xdr_stream *xdr,
 	encode_uint64(xdr, args->count);
 
 	encode_uint32(xdr, 1); /* consecutive = true */
-	encode_uint32(xdr, 1); /* synchronous = true */
+	encode_uint32(xdr, 0); /* synchronous = false */
 	if (args->cp_src == NULL) { /* intra-ssc */
 		encode_uint32(xdr, 0); /* no src server list */
 		return;
include/linux/nfs_fs.h +9 -0
index f1da8c8..e174cba 100644
@@ -182,6 +182,15 @@ struct nfs_inode {
 	struct inode		vfs_inode;
 };
 
+struct nfs4_copy_state {
+	struct list_head	copies;
+	nfs4_stateid		stateid;
+	struct completion	completion;
+	uint64_t		count;
+	struct nfs_writeverf	verf;
+	int			error;
+};
+
 /*
  * Cache validity bit flags
  */
include/linux/nfs_fs_sb.h +1 -0
index 488ff40..d2c33a8 100644
@@ -206,6 +206,7 @@ struct nfs_server {
 	struct list_head	state_owners_lru;
 	struct list_head	layouts;
 	struct list_head	delegations;
+	struct list_head	ss_copies;
 
 	unsigned long		mig_gen;
 	unsigned long		mig_status;
Signature · 1 line
1.8.3.1
#42 lore raw

RFC 13/19 NFS handle COPY reply CB_OFFLOAD call race

In reply to Olga Kornievskaia

It's possible that server replies back with CB_OFFLOAD call and COPY reply at the same time such that client will process CB_OFFLOAD before reply to COPY. For that keep a list of pending callback stateids received and them before waiting on completion check the pending list.

Cleanup any pending copies on the client shutdown.

---
 fs/nfs/callback_proc.c    | 17 ++++++++++++++---
 fs/nfs/nfs42proc.c        | 22 ++++++++++++++++++++--
 fs/nfs/nfs4client.c       | 15 +++++++++++++++
 include/linux/nfs_fs_sb.h |  1 +
 4 files changed, 50 insertions(+), 5 deletions(-)
fs/nfs/callback_proc.c +14 -3
index c1b081c..01bcb4b 100644
@@ -699,11 +699,12 @@ __be32 nfs4_callback_offload(struct cb_offloadargs *args, void *dummy,
 {
 	struct nfs_server *server;
 	struct nfs4_copy_state *copy;
+	bool found = false;
 
+	spin_lock(&cps->clp->cl_lock);
 	rcu_read_lock();
 	list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
 				client_link) {
-		spin_lock(&server->nfs_client->cl_lock);
 		list_for_each_entry(copy, &server->ss_copies, copies) {
 			if (memcmp(args->coa_stateid.other,
 					copy->stateid.other,
@@ -711,13 +712,23 @@ __be32 nfs4_callback_offload(struct cb_offloadargs *args, void *dummy,
 				continue;
 			nfs4_copy_cb_args(copy, args);
 			complete(&copy->completion);
-			spin_unlock(&server->nfs_client->cl_lock);
+			found = true;
 			goto out;
 		}
-		spin_unlock(&server->nfs_client->cl_lock);
 	}
 out:
 	rcu_read_unlock();
+	if (!found) {
+		copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
+		if (!copy) {
+			spin_unlock(&cps->clp->cl_lock);
+			return -ENOMEM;
+		}
+		memcpy(&copy->stateid, &args->coa_stateid, NFS4_STATEID_SIZE);
+		nfs4_copy_cb_args(copy, args);
+		list_add_tail(&copy->copies, &cps->clp->pending_cb_stateids);
+	}
+	spin_unlock(&cps->clp->cl_lock);
 	return 0;
 }
 #endif /* CONFIG_NFS_V4_2 */
fs/nfs/nfs42proc.c +20 -2
index e45e554..cd9d955 100644
@@ -178,14 +178,31 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 {
 	struct nfs4_copy_state *copy;
 	int status;
+	bool found_pending = false;
+
+	spin_lock(&server->nfs_client->cl_lock);
+	list_for_each_entry(copy, &server->nfs_client->pending_cb_stateids,
+				copies) {
+		if (memcmp(&res->write_res.stateid, &copy->stateid,
+				NFS4_STATEID_SIZE))
+			continue;
+		found_pending = true;
+		list_del(&copy->copies);
+		break;
+	}
+	if (found_pending) {
+		spin_unlock(&server->nfs_client->cl_lock);
+		goto out;
+	}
 
 	copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
-	if (!copy)
+	if (!copy) {
+		spin_unlock(&server->nfs_client->cl_lock);
 		return -ENOMEM;
+	}
 	memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
 	init_completion(&copy->completion);
 
-	spin_lock(&server->nfs_client->cl_lock);
 	list_add_tail(&copy->copies, &server->ss_copies);
 	spin_unlock(&server->nfs_client->cl_lock);
 
@@ -193,6 +210,7 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	spin_lock(&server->nfs_client->cl_lock);
 	list_del_init(&copy->copies);
 	spin_unlock(&server->nfs_client->cl_lock);
+out:
 	*ret_count = copy->count;
 	status = -copy->error;
 	if (copy->count && copy->verf.committed != NFS_FILE_SYNC)
fs/nfs/nfs4client.c +15 -0
index 5ae9d64..bebb97e1 100644
@@ -156,9 +156,23 @@ struct rpc_clnt *
 	}
 }
 
+static void
+nfs4_cleanup_callback(struct nfs_client *clp)
+{
+	struct nfs4_copy_state *cp_state;
+
+	while (!list_empty(&clp->pending_cb_stateids)) {
+		cp_state = list_entry(clp->pending_cb_stateids.next,
+					struct nfs4_copy_state, copies);
+		list_del(&cp_state->copies);
+		kfree(cp_state);
+	}
+}
+
 void nfs41_shutdown_client(struct nfs_client *clp)
 {
 	if (nfs4_has_session(clp)) {
+		nfs4_cleanup_callback(clp);
 		nfs4_shutdown_ds_clients(clp);
 		nfs4_destroy_session(clp->cl_session);
 		nfs4_destroy_clientid(clp);
@@ -202,6 +216,7 @@ struct nfs_client *nfs4_alloc_client(const struct nfs_client_initdata *cl_init)
 #if IS_ENABLED(CONFIG_NFS_V4_1)
 	init_waitqueue_head(&clp->cl_lock_waitq);
 #endif
+	INIT_LIST_HEAD(&clp->pending_cb_stateids);
 	return clp;
 
 error:
include/linux/nfs_fs_sb.h +1 -0
index d2c33a8..6a35498 100644
@@ -118,6 +118,7 @@ struct nfs_client {
 #endif
 
 	struct net		*cl_net;
+	struct list_head	pending_cb_stateids;
 };
 
 /*
Signature · 1 line
1.8.3.1
#43 lore raw

RFC 14/19 NFS send OFFLOAD_CANCEL when COPY killed

In reply to Olga Kornievskaia

When COPY is killed send OFFLOAD_CANCEL to both destination and source servers.

---
 fs/nfs/nfs42proc.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 93 insertions(+), 2 deletions(-)
fs/nfs/nfs42proc.c +93 -2
index cd9d955..7a1b2ae 100644
@@ -19,6 +19,8 @@
 
 #define NFSDBG_FACILITY NFSDBG_PROC
 
+static int nfs42_do_offload_cancel_async(struct file *dst,
+				nfs4_stateid *stateid);
 static int nfs42_set_open_stateid(nfs4_stateid *dst, struct file *file)
 {
 	struct nfs_open_context *ctx;
@@ -206,10 +208,16 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	list_add_tail(&copy->copies, &server->ss_copies);
 	spin_unlock(&server->nfs_client->cl_lock);
 
-	wait_for_completion_interruptible(&copy->completion);
+	status = wait_for_completion_interruptible(&copy->completion);
 	spin_lock(&server->nfs_client->cl_lock);
 	list_del_init(&copy->copies);
 	spin_unlock(&server->nfs_client->cl_lock);
+	if (status == -ERESTARTSYS) {
+		nfs42_do_offload_cancel_async(dst, &copy->stateid);
+		nfs42_do_offload_cancel_async(src, src_stateid);
+		kfree(copy);
+		return status;
+	}
 out:
 	*ret_count = copy->count;
 	status = -copy->error;
@@ -266,8 +274,13 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 
 	status = nfs4_call_sync(server->client, server, &msg,
 				&args->seq_args, &res->seq_res, 0);
-	if (status == -ENOTSUPP)
+	switch (status) {
+	case -ENOTSUPP:
 		server->caps &= ~NFS_CAP_COPY;
+		break;
+	case -ERESTARTSYS:
+		nfs42_do_offload_cancel_async(src, &args->src_stateid);
+	}
 	if (status)
 		return status;
 
@@ -419,6 +432,84 @@ int nfs42_proc_copy_notify(struct file *src, struct file *dst,
 	return status;
 }
 
+struct nfs42_offloadcancel_data {
+	struct nfs_server *seq_server;
+	struct nfs42_offload_status_args args;
+	struct nfs42_offload_status_res res;
+};
+
+static void nfs42_offload_cancel_prepare(struct rpc_task *task, void *calldata)
+{
+	struct nfs42_offloadcancel_data *data = calldata;
+	struct nfs4_session *session = nfs4_get_session(data->seq_server);
+
+	nfs41_setup_sequence(session, &data->args.osa_seq_args,
+				&data->res.osr_seq_res, task);
+}
+
+static void nfs42_offload_cancel_done(struct rpc_task *task, void *calldata)
+{
+	struct nfs42_offloadcancel_data *data = calldata;
+
+	nfs41_sequence_done(task, &data->res.osr_seq_res);
+	kfree(data);
+}
+
+static void nfs42_free_offloadcancel_data(void *data)
+{
+	kfree(data);
+}
+
+static const struct rpc_call_ops nfs42_offload_cancel_ops = {
+	.rpc_call_prepare = nfs42_offload_cancel_prepare,
+	.rpc_call_done = nfs42_offload_cancel_done,
+	.rpc_release = nfs42_free_offloadcancel_data,
+};
+
+static int nfs42_do_offload_cancel_async(struct file *dst,
+				nfs4_stateid *stateid)
+{
+	struct nfs_server *dst_server = NFS_SERVER(file_inode(dst));
+	struct nfs42_offloadcancel_data *data = NULL;
+	struct nfs_open_context *ctx = nfs_file_open_context(dst);
+	struct rpc_task *task;
+	struct rpc_message msg = {
+		.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OFFLOAD_CANCEL],
+		.rpc_cred = ctx->cred,
+	};
+	struct rpc_task_setup task_setup_data = {
+		.rpc_client = dst_server->client,
+		.rpc_message = &msg,
+		.callback_ops = &nfs42_offload_cancel_ops,
+		.workqueue = nfsiod_workqueue,
+		.flags = RPC_TASK_ASYNC,
+	};
+	int status;
+
+	if (!(dst_server->caps & NFS_CAP_OFFLOAD_CANCEL))
+		return -EOPNOTSUPP;
+
+	data = kzalloc(sizeof(struct nfs42_offloadcancel_data), GFP_NOFS);
+	if (data == NULL)
+		return -ENOMEM;
+	data->seq_server = dst_server;
+	data->args.osa_src_fh = NFS_FH(file_inode(dst));
+	memcpy(&data->args.osa_stateid, stateid,
+		sizeof(data->args.osa_stateid));
+	msg.rpc_argp = &data->args;
+	msg.rpc_resp = &data->res;
+	task_setup_data.callback_data = data;
+	nfs4_init_sequence(&data->args.osa_seq_args, &data->res.osr_seq_res, 1);
+	task = rpc_run_task(&task_setup_data);
+	if (IS_ERR(task))
+		return PTR_ERR(task);
+	status = rpc_wait_for_completion_task(task);
+	if (status == -ENOTSUPP)
+		dst_server->caps &= ~NFS_CAP_OFFLOAD_CANCEL;
+	rpc_put_task(task);
+	return status;
+}
+
 int _nfs42_proc_offload_status(struct file *dst, nfs4_stateid *stateid,
 				struct nfs42_offload_status_res *res)
 {
Signature · 1 line
1.8.3.1
#44 lore raw

RFC 15/19 NFS make COPY synchronous xdr configurable

In reply to Olga Kornievskaia

Instead of hardcoding always sending async copy, make it configurable. In case, we get ERR_OFFLOAD_NO_REQS and we need to resend the operation as synchronous.

---
 fs/nfs/nfs42proc.c      | 2 ++
 fs/nfs/nfs42xdr.c       | 2 +-
 include/linux/nfs_xdr.h | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +2 -0
index 7a1b2ae..b29f2c9 100644
@@ -248,6 +248,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	size_t count = args->count;
 	int status;
 	uint64_t ret_count;
+	bool sync = false;
 
 	if (nss) {
 		args->cp_src = nss;
@@ -272,6 +273,7 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	if (status)
 		return status;
 
+	args->sync = sync;
 	status = nfs4_call_sync(server->client, server, &msg,
 				&args->seq_args, &res->seq_res, 0);
 	switch (status) {
fs/nfs/nfs42xdr.c +1 -1
index 9e388e1..d300b77 100644
@@ -199,7 +199,7 @@ static void encode_copy(struct xdr_stream *xdr,
 	encode_uint64(xdr, args->count);
 
 	encode_uint32(xdr, 1); /* consecutive = true */
-	encode_uint32(xdr, 0); /* synchronous = false */
+	encode_uint32(xdr, args->sync);
 	if (args->cp_src == NULL) { /* intra-ssc */
 		encode_uint32(xdr, 0); /* no src server list */
 		return;
include/linux/nfs_xdr.h +1 -0
index 2ed335e..c210e93 100644
@@ -1373,6 +1373,7 @@ struct nfs42_copy_args {
 	u64				count;
 	/* Support one source server */
 	struct nl4_servers		*cp_src;
+	bool				sync;
 };
 
 struct nfs42_write_res {
Signature · 1 line
1.8.3.1
#45 lore raw

RFC 16/19 NFS handle COPY ERR_OFFLOAD_NO_REQS

In reply to Olga Kornievskaia

If client sent async COPY and server replied with ERR_OFFLOAD_NO_REQS, client should retry with a synchronous copy.

---
 fs/nfs/nfs42proc.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/nfs/nfs42proc.c +7 -0
index b29f2c9..c9d8d7a 100644
@@ -273,10 +273,17 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	if (status)
 		return status;
 
+retry:
 	args->sync = sync;
 	status = nfs4_call_sync(server->client, server, &msg,
 				&args->seq_args, &res->seq_res, 0);
 	switch (status) {
+	case -NFS4ERR_OFFLOAD_NO_REQS:
+		if (!sync) {
+			sync = true;
+			goto retry;
+		}
+		break;
 	case -ENOTSUPP:
 		server->caps &= ~NFS_CAP_COPY;
 		break;
Signature · 1 line
1.8.3.1
#46 lore raw

RFC 17/19 NFS skip recovery of copy open on dest server

In reply to Olga Kornievskaia

Mark the open created for the source file on the destination server. Then if this open is going thru a recovery, then fail the recovery as we don't need to be recoving a "fake" open. We need to fail the ongoing READs and vfs_copy_file_range().

---
 fs/nfs/nfs4_fs.h   |  3 +++
 fs/nfs/nfs4file.c  |  2 +-
 fs/nfs/nfs4state.c | 14 ++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
fs/nfs/nfs4_fs.h +3 -0
index c23089e..07b93fde 100644
@@ -161,6 +161,9 @@ enum {
 	NFS_STATE_POSIX_LOCKS,		/* Posix locks are supported */
 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
 	NFS_STATE_MAY_NOTIFY_LOCK,	/* server may CB_NOTIFY_LOCK */
+#ifdef CONFIG_NFS_V4_2
+	NFS_SRV_SSC_COPY_STATE,		/* ssc state on the dst server */
+#endif /* CONFIG_NFS_V4_2 */
 };
 
 struct nfs4_state {
fs/nfs/nfs4file.c +1 -1
index 43a2346..f6ccc6f 100644
@@ -347,7 +347,7 @@ struct file *
 	ctx->state = nfs4_get_open_state(r_ino, sp);
 	if (ctx->state == NULL)
 		goto out_stateowner;
-
+	set_bit(NFS_SRV_SSC_COPY_STATE, &ctx->state->flags);
 	update_open_stateid(ctx->state, stateid, NULL, filep->f_mode);
 
 	nfs_file_set_open_context(filep, ctx);
fs/nfs/nfs4state.c +14 -0
index 5827d95..af5d8d7 100644
@@ -1501,6 +1501,9 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
 	struct nfs4_state *state;
 	struct nfs4_lock_state *lock;
 	int status = 0;
+#ifdef CONFIG_NFS_V4_2
+	bool found_ssc_copy_state = false;
+#endif /* CONFIG_NFS_V4_2 */
 
 	/* Note: we rely on the sp->so_states list being ordered 
 	 * so that we always reclaim open(O_RDWR) and/or open(O_WRITE)
@@ -1520,6 +1523,13 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
 			continue;
 		if (state->state == 0)
 			continue;
+#ifdef CONFIG_NFS_V4_2
+		if (test_bit(NFS_SRV_SSC_COPY_STATE, &state->flags)) {
+			nfs4_state_mark_recovery_failed(state, -EIO);
+			found_ssc_copy_state = true;
+			continue;
+		}
+#endif /* CONFIG_NFS_V4_2 */
 		atomic_inc(&state->count);
 		spin_unlock(&sp->so_lock);
 		status = ops->recover_open(sp, state);
@@ -1582,6 +1592,10 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
 	}
 	raw_write_seqcount_end(&sp->so_reclaim_seqcount);
 	spin_unlock(&sp->so_lock);
+#ifdef CONFIG_NFS_V4_2
+	if (found_ssc_copy_state)
+		return -EIO;
+#endif /* CONFIG_NFS_V4_2 */
 	return 0;
 out_err:
 	nfs4_put_open_state(state);
Signature · 1 line
1.8.3.1
#47 lore raw

RFC 18/19 NFS recover from destination server reboot for copies

In reply to Olga Kornievskaia

Mark the destination state to indicate a server-side copy is happening. On detecting a reboot and recovering open state check if any state is engaged in a server-side copy, if so, find the copy and mark it and then signal the waiting thread. Upon wakeup, if copy was marked then propage EAGAIN to the nfsd_copy_file_range and restart the copy from scratch (no partial state is being queried at this point).

---
 fs/nfs/nfs42proc.c     | 22 +++++++++++++++++-----
 fs/nfs/nfs4_fs.h       |  1 +
 fs/nfs/nfs4file.c      |  3 +++
 fs/nfs/nfs4state.c     | 15 +++++++++++++++
 include/linux/nfs_fs.h |  2 ++
 5 files changed, 38 insertions(+), 5 deletions(-)
fs/nfs/nfs42proc.c +17 -5
index c9d8d7a..232447d 100644
@@ -181,6 +181,7 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	struct nfs4_copy_state *copy;
 	int status;
 	bool found_pending = false;
+	struct nfs_open_context *ctx = nfs_file_open_context(dst);
 
 	spin_lock(&server->nfs_client->cl_lock);
 	list_for_each_entry(copy, &server->nfs_client->pending_cb_stateids,
@@ -204,6 +205,7 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	}
 	memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
 	init_completion(&copy->completion);
+	copy->parent_state = ctx->state;
 
 	list_add_tail(&copy->copies, &server->ss_copies);
 	spin_unlock(&server->nfs_client->cl_lock);
@@ -213,10 +215,10 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	list_del_init(&copy->copies);
 	spin_unlock(&server->nfs_client->cl_lock);
 	if (status == -ERESTARTSYS) {
-		nfs42_do_offload_cancel_async(dst, &copy->stateid);
-		nfs42_do_offload_cancel_async(src, src_stateid);
-		kfree(copy);
-		return status;
+		goto out_cancel;
+	} else if (copy->flags) {
+		status = -EAGAIN;
+		goto out_cancel;
 	}
 out:
 	*ret_count = copy->count;
@@ -225,6 +227,11 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 		status = nfs_commit_file(dst, &copy->verf.verifier);
 	kfree(copy);
 	return status;
+out_cancel:
+	nfs42_do_offload_cancel_async(dst, &copy->stateid);
+	nfs42_do_offload_cancel_async(src, src_stateid);
+	kfree(copy);
+	return status;
 }
 
 static ssize_t _nfs42_proc_copy(struct file *src,
@@ -273,6 +280,8 @@ static ssize_t _nfs42_proc_copy(struct file *src,
 	if (status)
 		return status;
 
+	set_bit(NFS_CLNT_DST_SSC_COPY_STATE,
+		&dst_lock->open_context->state->flags);
 retry:
 	args->sync = sync;
 	status = nfs4_call_sync(server->client, server, &msg,
@@ -363,9 +372,12 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src,
 
 		if (err >= 0)
 			break;
-		if (err == -ENOTSUPP) {
+		switch (err) {
+		case -ENOTSUPP:
 			err = -EOPNOTSUPP;
 			break;
+		case -EAGAIN:
+			break;
 		}
 
 		err2 = nfs4_handle_exception(server, err, &src_exception);
fs/nfs/nfs4_fs.h +1 -0
index 07b93fde..8037ec3 100644
@@ -162,6 +162,7 @@ enum {
 	NFS_STATE_RECOVERY_FAILED,	/* OPEN stateid state recovery failed */
 	NFS_STATE_MAY_NOTIFY_LOCK,	/* server may CB_NOTIFY_LOCK */
 #ifdef CONFIG_NFS_V4_2
+	NFS_CLNT_DST_SSC_COPY_STATE,    /* dst server open state on client*/
 	NFS_SRV_SSC_COPY_STATE,		/* ssc state on the dst server */
 #endif /* CONFIG_NFS_V4_2 */
 };
fs/nfs/nfs4file.c +3 -0
index f6ccc6f..92822c4 100644
@@ -142,6 +142,7 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 	if (file_inode(file_in) == file_inode(file_out))
 		return -EINVAL;
 
+retry:
 	if (nfs42_intra_ssc(file_in, file_out)) {  /* Intra-ssc */
 		if (file_in->f_op != file_out->f_op)
 			return -EXDEV;
@@ -173,6 +174,8 @@ static ssize_t nfs4_copy_file_range(struct file *file_in, loff_t pos_in,
 		kfree(cn_resp->cnr_src.nl_svr);
 		kfree(cn_resp);
 	}
+	if (ret == -EAGAIN)
+		goto retry;
 	return ret;
 }
 
fs/nfs/nfs4state.c +15 -0
index af5d8d7..47ece10 100644
@@ -1550,6 +1550,21 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
 					&state->flags);
 				nfs4_put_open_state(state);
 				spin_lock(&sp->so_lock);
+#ifdef CONFIG_NFS_V4_2
+				if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
+					struct nfs4_copy_state *copy;
+
+					spin_lock(&sp->so_server->nfs_client->cl_lock);
+					list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
+						if (memcmp(&state->stateid.other, &copy->parent_state->stateid.other, NFS4_STATEID_SIZE))
+							continue;
+						copy->flags = 1;
+						complete(&copy->completion);
+						break;
+					}
+					spin_unlock(&sp->so_server->nfs_client->cl_lock);
+				}
+#endif /* CONFIG_NFS_V4_2 */
 				goto restart;
 			}
 		}
include/linux/nfs_fs.h +2 -0
index e174cba..7d60a0a 100644
@@ -189,6 +189,8 @@ struct nfs4_copy_state {
 	uint64_t		count;
 	struct nfs_writeverf	verf;
 	int			error;
+	int			flags;
+	struct nfs4_state	*parent_state;
 };
 
 /*
Signature · 1 line
1.8.3.1
#48 lore raw

RFC 19/19 NFS if we got partial copy ignore errors

In reply to Olga Kornievskaia

Don't ignore ENOSPC. Otherwise, try next copy chunk

---
 fs/nfs/nfs42proc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfs/nfs42proc.c +2 -1
index 232447d..7a8f770 100644
@@ -222,7 +222,8 @@ static int handle_async_copy(struct nfs42_copy_res *res,
 	}
 out:
 	*ret_count = copy->count;
-	status = -copy->error;
+	if (copy->count < 0 || copy->error == ENOSPC)
+		status = -copy->error;
 	if (copy->count && copy->verf.committed != NFS_FILE_SYNC)
 		status = nfs_commit_file(dst, &copy->verf.verifier);
 	kfree(copy);
Signature · 1 line
1.8.3.1