aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Layton <jlayton@kernel.org>2024-03-12 10:24:09 -0400
committerJeff Layton <jlayton@kernel.org>2024-04-23 07:24:30 -0400
commit6b72f46707c12ce663fc98e4610c3f4fdd33db84 (patch)
tree21f959cb37a348651a50df95c008325503838e8d
parente60f9278e94dbced25a1f07bf7faeca4cc1fdc6c (diff)
downloadlinux-6b72f46707c12ce663fc98e4610c3f4fdd33db84.tar.gz
nfsd: check for delegation conflicts vs. the same client
RFC 8881 requires that the server reply with GDD_UNAVAIL when the client requests a directory delegation that it already holds. When setting a directory delegation, check that the client assocated with the stateid doesn't match an existing delegation. If it does, reject the setlease attempt. Signed-off-by: Jeff Layton <jlayton@kernel.org>
-rw-r--r--fs/nfsd/nfs4state.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 14389fa02a2bb8..8f0e5f4e1b8f1b 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -88,6 +88,7 @@ void nfsd4_end_grace(struct nfsd_net *nn);
static void _free_cpntf_state_locked(struct nfsd_net *nn, struct nfs4_cpntf_state *cps);
static void nfsd4_file_hash_remove(struct nfs4_file *fi);
static void deleg_reaper(struct nfsd_net *nn);
+static bool nfsd_dir_deleg_conflict(struct file_lease *new, struct file_lease *old);
/* Locking: */
@@ -5305,6 +5306,31 @@ static const struct lease_manager_operations nfsd_lease_mng_ops = {
.lm_change = nfsd_change_deleg_cb,
};
+static const struct lease_manager_operations nfsd_dir_lease_mng_ops = {
+ .lm_breaker_owns_lease = nfsd_breaker_owns_lease,
+ .lm_break = nfsd_break_deleg_cb,
+ .lm_change = nfsd_change_deleg_cb,
+ .lm_set_conflict = nfsd_dir_deleg_conflict,
+};
+
+static bool
+nfsd_dir_deleg_conflict(struct file_lease *new, struct file_lease *old)
+{
+ struct nfs4_delegation *od, *nd;
+
+ /* Only conflicts with other nfsd dir delegs */
+ if (old->fl_lmops != &nfsd_dir_lease_mng_ops)
+ return false;
+
+ od = old->c.flc_owner;
+ nd = new->c.flc_owner;
+
+ /* Are these for the same client? No bueno if so */
+ if (od->dl_stid.sc_client == nd->dl_stid.sc_client)
+ return true;
+ return false;
+}
+
static __be32 nfsd4_check_seqid(struct nfsd4_compound_state *cstate, struct nfs4_stateowner *so, u32 seqid)
{
if (nfsd4_has_session(cstate))
@@ -5644,12 +5670,13 @@ static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp,
fl = locks_alloc_lease();
if (!fl)
return NULL;
- fl->fl_lmops = &nfsd_lease_mng_ops;
fl->c.flc_flags = FL_DELEG;
fl->c.flc_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK;
fl->c.flc_owner = (fl_owner_t)dp;
fl->c.flc_pid = current->tgid;
fl->c.flc_file = dp->dl_stid.sc_file->fi_deleg_file->nf_file;
+ fl->fl_lmops = S_ISDIR(file_inode(fl->c.flc_file)->i_mode) ?
+ &nfsd_dir_lease_mng_ops : &nfsd_lease_mng_ops;
return fl;
}