NFS: Implement NFSv4.2's OFFLOAD_STATUS operation

Enable the Linux NFS client to observe the progress of an offloaded
asynchronous COPY operation. This new operation will be put to use
in a subsequent patch.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Link: https://lore.kernel.org/r/20250113153235.48706-14-cel@kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
This commit is contained in:
Chuck Lever 2025-01-13 10:32:40 -05:00 committed by Trond Myklebust
parent 8955e7ce61
commit 77dd8a302f
3 changed files with 106 additions and 1 deletions

View File

@ -21,6 +21,8 @@
#define NFSDBG_FACILITY NFSDBG_PROC
static int nfs42_do_offload_cancel_async(struct file *dst, nfs4_stateid *std);
static int nfs42_proc_offload_status(struct file *file, nfs4_stateid *stateid,
u64 *copied);
static void nfs42_set_netaddr(struct file *filep, struct nfs42_netaddr *naddr)
{
@ -582,6 +584,107 @@ static int nfs42_do_offload_cancel_async(struct file *dst,
return status;
}
static int
_nfs42_proc_offload_status(struct nfs_server *server, struct file *file,
struct nfs42_offload_data *data)
{
struct nfs_open_context *ctx = nfs_file_open_context(file);
struct rpc_message msg = {
.rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OFFLOAD_STATUS],
.rpc_argp = &data->args,
.rpc_resp = &data->res,
.rpc_cred = ctx->cred,
};
int status;
status = nfs4_call_sync(server->client, server, &msg,
&data->args.osa_seq_args,
&data->res.osr_seq_res, 1);
switch (status) {
case 0:
break;
case -NFS4ERR_ADMIN_REVOKED:
case -NFS4ERR_BAD_STATEID:
case -NFS4ERR_OLD_STATEID:
/*
* Server does not recognize the COPY stateid. CB_OFFLOAD
* could have purged it, or server might have rebooted.
* Since COPY stateids don't have an associated inode,
* avoid triggering state recovery.
*/
status = -EBADF;
break;
case -NFS4ERR_NOTSUPP:
case -ENOTSUPP:
case -EOPNOTSUPP:
server->caps &= ~NFS_CAP_OFFLOAD_STATUS;
status = -EOPNOTSUPP;
break;
}
return status;
}
/**
* nfs42_proc_offload_status - Poll completion status of an async copy operation
* @dst: handle of file being copied into
* @stateid: copy stateid (from async COPY result)
* @copied: OUT: number of bytes copied so far
*
* Return values:
* %0: Server returned an NFS4_OK completion status
* %-EINPROGRESS: Server returned no completion status
* %-EREMOTEIO: Server returned an error completion status
* %-EBADF: Server did not recognize the copy stateid
* %-EOPNOTSUPP: Server does not support OFFLOAD_STATUS
* %-ERESTARTSYS: Wait interrupted by signal
*
* Other negative errnos indicate the client could not complete the
* request.
*/
static int __maybe_unused
nfs42_proc_offload_status(struct file *dst, nfs4_stateid *stateid, u64 *copied)
{
struct inode *inode = file_inode(dst);
struct nfs_server *server = NFS_SERVER(inode);
struct nfs4_exception exception = {
.inode = inode,
};
struct nfs42_offload_data *data;
int status;
if (!(server->caps & NFS_CAP_OFFLOAD_STATUS))
return -EOPNOTSUPP;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->seq_server = server;
data->args.osa_src_fh = NFS_FH(inode);
memcpy(&data->args.osa_stateid, stateid,
sizeof(data->args.osa_stateid));
exception.stateid = &data->args.osa_stateid;
do {
status = _nfs42_proc_offload_status(server, dst, data);
if (status == -EOPNOTSUPP)
goto out;
status = nfs4_handle_exception(server, status, &exception);
} while (exception.retry);
if (status)
goto out;
*copied = data->res.osr_count;
if (!data->res.complete_count)
status = -EINPROGRESS;
else if (data->res.osr_complete != NFS_OK)
status = -EREMOTEIO;
out:
kfree(data);
return status;
}
static int _nfs42_proc_copy_notify(struct file *src, struct file *dst,
struct nfs42_copy_notify_args *args,
struct nfs42_copy_notify_res *res)

View File

@ -10781,7 +10781,8 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
| NFS_CAP_CLONE
| NFS_CAP_LAYOUTERROR
| NFS_CAP_READ_PLUS
| NFS_CAP_MOVEABLE,
| NFS_CAP_MOVEABLE
| NFS_CAP_OFFLOAD_STATUS,
.init_client = nfs41_init_client,
.shutdown_client = nfs41_shutdown_client,
.match_stateid = nfs41_match_stateid,

View File

@ -293,6 +293,7 @@ struct nfs_server {
#define NFS_CAP_CASE_INSENSITIVE (1U << 6)
#define NFS_CAP_CASE_PRESERVING (1U << 7)
#define NFS_CAP_REBOOT_LAYOUTRETURN (1U << 8)
#define NFS_CAP_OFFLOAD_STATUS (1U << 9)
#define NFS_CAP_OPEN_XOR (1U << 12)
#define NFS_CAP_DELEGTIME (1U << 13)
#define NFS_CAP_POSIX_LOCK (1U << 14)