Skip to content

Commit 6b8d84e

Browse files
olgakorn1amschuma-ntap
authored andcommitted
NFS add a simple sync nfs4_proc_commit after async COPY
A COPY with unstable write data needs a simple sync commit. Filehandle value is gotten as a part of the inner loop so in case of a reboot retry it should get the new value. Signed-off-by: Olga Kornievskaia <kolga@netapp.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 539f57b commit 6b8d84e

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

fs/nfs/nfs42proc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ static int handle_async_copy(struct nfs42_copy_res *res,
185185
return status;
186186
}
187187

188+
static int process_copy_commit(struct file *dst, loff_t pos_dst,
189+
struct nfs42_copy_res *res)
190+
{
191+
struct nfs_commitres cres;
192+
int status = -ENOMEM;
193+
194+
cres.verf = kzalloc(sizeof(struct nfs_writeverf), GFP_NOFS);
195+
if (!cres.verf)
196+
goto out;
197+
198+
status = nfs4_proc_commit(dst, pos_dst, res->write_res.count, &cres);
199+
if (status)
200+
goto out_free;
201+
if (nfs_write_verifier_cmp(&res->write_res.verifier.verifier,
202+
&cres.verf->verifier)) {
203+
dprintk("commit verf differs from copy verf\n");
204+
status = -EAGAIN;
205+
}
206+
out_free:
207+
kfree(cres.verf);
208+
out:
209+
return status;
210+
}
211+
188212
static ssize_t _nfs42_proc_copy(struct file *src,
189213
struct nfs_lock_context *src_lock,
190214
struct file *dst,
@@ -251,6 +275,13 @@ static ssize_t _nfs42_proc_copy(struct file *src,
251275
return status;
252276
}
253277

278+
if ((!res->synchronous || !args->sync) &&
279+
res->write_res.verifier.committed != NFS_FILE_SYNC) {
280+
status = process_copy_commit(dst, pos_dst, res);
281+
if (status)
282+
return status;
283+
}
284+
254285
truncate_pagecache_range(dst_inode, pos_dst,
255286
pos_dst + res->write_res.count);
256287

fs/nfs/nfs4_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ extern int nfs4_sequence_done(struct rpc_task *task,
508508
struct nfs4_sequence_res *res);
509509

510510
extern void nfs4_free_lock_state(struct nfs_server *server, struct nfs4_lock_state *lsp);
511-
511+
extern int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res);
512512
extern const nfs4_stateid zero_stateid;
513513
extern const nfs4_stateid invalid_stateid;
514514

fs/nfs/nfs4proc.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5137,6 +5137,40 @@ static void nfs4_proc_commit_setup(struct nfs_commit_data *data, struct rpc_mess
51375137
nfs4_state_protect(server->nfs_client, NFS_SP4_MACH_CRED_COMMIT, clnt, msg);
51385138
}
51395139

5140+
static int _nfs4_proc_commit(struct file *dst, struct nfs_commitargs *args,
5141+
struct nfs_commitres *res)
5142+
{
5143+
struct inode *dst_inode = file_inode(dst);
5144+
struct nfs_server *server = NFS_SERVER(dst_inode);
5145+
struct rpc_message msg = {
5146+
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT],
5147+
.rpc_argp = args,
5148+
.rpc_resp = res,
5149+
};
5150+
5151+
args->fh = NFS_FH(dst_inode);
5152+
return nfs4_call_sync(server->client, server, &msg,
5153+
&args->seq_args, &res->seq_res, 1);
5154+
}
5155+
5156+
int nfs4_proc_commit(struct file *dst, __u64 offset, __u32 count, struct nfs_commitres *res)
5157+
{
5158+
struct nfs_commitargs args = {
5159+
.offset = offset,
5160+
.count = count,
5161+
};
5162+
struct nfs_server *dst_server = NFS_SERVER(file_inode(dst));
5163+
struct nfs4_exception exception = { };
5164+
int status;
5165+
5166+
do {
5167+
status = _nfs4_proc_commit(dst, &args, res);
5168+
status = nfs4_handle_exception(dst_server, status, &exception);
5169+
} while (exception.retry);
5170+
5171+
return status;
5172+
}
5173+
51405174
struct nfs4_renewdata {
51415175
struct nfs_client *client;
51425176
unsigned long timestamp;

0 commit comments

Comments
 (0)