NFSv4: Refactor nfs4_opendata_check_deleg()

JIRA: https://issues.redhat.com/browse/RHEL-59704

commit 7cca0e962eb50b5321317a491d9fe6578ca8419f
Author: Trond Myklebust <trond.myklebust@primarydata.com>
Date:   Sun Jun 16 21:21:20 2024 -0400

    NFSv4: Refactor nfs4_opendata_check_deleg()

    Modify it to no longer depend directly on the struct opendata.
    This will enable sharing with WANT_DELEGATION.

    Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
    Signed-off-by: Lance Shelton <lance.shelton@hammerspace.com>
    Reviewed-by: Jeff Layton <jlayton@kernel.org>
    Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
    Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
This commit is contained in:
Scott Mayhew 2024-09-23 16:32:43 -04:00
parent 524f5464f5
commit 589ebfb9f7
1 changed files with 30 additions and 36 deletions

View File

@ -1954,51 +1954,39 @@ out_return_state:
}
static void
nfs4_opendata_check_deleg(struct nfs4_opendata *data, struct nfs4_state *state)
nfs4_process_delegation(struct inode *inode, const struct cred *cred,
enum open_claim_type4 claim,
const struct nfs4_open_delegation *delegation)
{
struct nfs_client *clp = NFS_SERVER(state->inode)->nfs_client;
struct nfs_delegation *delegation;
int delegation_flags = 0;
switch (data->o_res.delegation.open_delegation_type) {
switch (delegation->open_delegation_type) {
case NFS4_OPEN_DELEGATE_READ:
case NFS4_OPEN_DELEGATE_WRITE:
break;
default:
return;
};
rcu_read_lock();
delegation = rcu_dereference(NFS_I(state->inode)->delegation);
if (delegation)
delegation_flags = delegation->flags;
rcu_read_unlock();
switch (data->o_arg.claim) {
default:
break;
}
switch (claim) {
case NFS4_OPEN_CLAIM_DELEGATE_CUR:
case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
pr_err_ratelimited("NFS: Broken NFSv4 server %s is "
"returning a delegation for "
"OPEN(CLAIM_DELEGATE_CUR)\n",
clp->cl_hostname);
return;
NFS_SERVER(inode)->nfs_client->cl_hostname);
break;
case NFS4_OPEN_CLAIM_PREVIOUS:
nfs_inode_reclaim_delegation(inode, cred,
delegation->type,
&delegation->stateid,
delegation->pagemod_limit);
break;
default:
nfs_inode_set_delegation(inode, cred,
delegation->type,
&delegation->stateid,
delegation->pagemod_limit);
}
if ((delegation_flags & 1UL<<NFS_DELEGATION_NEED_RECLAIM) == 0)
nfs_inode_set_delegation(state->inode,
data->owner->so_cred,
data->o_res.delegation.type,
&data->o_res.delegation.stateid,
data->o_res.delegation.pagemod_limit);
else
nfs_inode_reclaim_delegation(state->inode,
data->owner->so_cred,
data->o_res.delegation.type,
&data->o_res.delegation.stateid,
data->o_res.delegation.pagemod_limit);
if (data->o_res.delegation.do_recall)
nfs_async_inode_return_delegation(state->inode,
&data->o_res.delegation.stateid);
if (delegation->do_recall)
nfs_async_inode_return_delegation(inode, &delegation->stateid);
}
/*
@ -2022,7 +2010,10 @@ _nfs4_opendata_reclaim_to_nfs4_state(struct nfs4_opendata *data)
if (ret)
return ERR_PTR(ret);
nfs4_opendata_check_deleg(data, state);
nfs4_process_delegation(state->inode,
data->owner->so_cred,
data->o_arg.claim,
&data->o_res.delegation);
if (!update_open_stateid(state, &data->o_res.stateid,
NULL, data->o_arg.fmode))
@ -2089,8 +2080,11 @@ _nfs4_opendata_to_nfs4_state(struct nfs4_opendata *data)
if (IS_ERR(state))
goto out;
if (data->o_res.delegation.type != 0)
nfs4_opendata_check_deleg(data, state);
nfs4_process_delegation(state->inode,
data->owner->so_cred,
data->o_arg.claim,
&data->o_res.delegation);
if (!update_open_stateid(state, &data->o_res.stateid,
NULL, data->o_arg.fmode)) {
nfs4_put_open_state(state);