Skip to content

Commit eac0b17

Browse files
olgakorn1J. Bruce Fields
authored andcommitted
NFSD add vfs_fsync after async copy is done
Currently, the server does all copies as NFS_UNSTABLE. For synchronous copies linux client will append a COMMIT to the COPY compound but for async copies it does not (because COMMIT needs to be done after all bytes are copied and not as a reply to the COPY operation). However, in order to save the client doing a COMMIT as a separate rpc, the server can reply back with NFS_FILE_SYNC copy. This patch proposed to add vfs_fsync() call at the end of the async copy. Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent eeeadbb commit eac0b17

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

fs/nfsd/nfs4proc.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,8 @@ static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
13751375

13761376
static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
13771377
{
1378-
copy->cp_res.wr_stable_how = NFS_UNSTABLE;
1378+
copy->cp_res.wr_stable_how =
1379+
copy->committed ? NFS_FILE_SYNC : NFS_UNSTABLE;
13791380
copy->cp_synchronous = sync;
13801381
gen_boot_verifier(&copy->cp_res.wr_verifier, copy->cp_clp->net);
13811382
}
@@ -1386,6 +1387,7 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
13861387
u64 bytes_total = copy->cp_count;
13871388
u64 src_pos = copy->cp_src_pos;
13881389
u64 dst_pos = copy->cp_dst_pos;
1390+
__be32 status;
13891391

13901392
/* See RFC 7862 p.67: */
13911393
if (bytes_total == 0)
@@ -1403,6 +1405,16 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy)
14031405
src_pos += bytes_copied;
14041406
dst_pos += bytes_copied;
14051407
} while (bytes_total > 0 && !copy->cp_synchronous);
1408+
/* for a non-zero asynchronous copy do a commit of data */
1409+
if (!copy->cp_synchronous && copy->cp_res.wr_bytes_written > 0) {
1410+
down_write(&copy->nf_dst->nf_rwsem);
1411+
status = vfs_fsync_range(copy->nf_dst->nf_file,
1412+
copy->cp_dst_pos,
1413+
copy->cp_res.wr_bytes_written, 0);
1414+
up_write(&copy->nf_dst->nf_rwsem);
1415+
if (!status)
1416+
copy->committed = true;
1417+
}
14061418
return bytes_copied;
14071419
}
14081420

fs/nfsd/xdr4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,7 @@ struct nfsd4_copy {
567567
struct vfsmount *ss_mnt;
568568
struct nfs_fh c_fh;
569569
nfs4_stateid stateid;
570+
bool committed;
570571
};
571572

572573
struct nfsd4_seek {

0 commit comments

Comments
 (0)