When requesting a directory lease, enable the FL_IGN_DIR_* bits that
correspond to the requested notification types.

Signed-off-by: Jeff Layton <[email protected]>
---
 fs/nfsd/nfs4state.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 35f5c098717e..bd7e4f9cdaa5 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -6040,7 +6040,22 @@ static bool nfsd4_cb_channel_good(struct nfs4_client 
*clp)
        return clp->cl_minorversion && clp->cl_cb_state == NFSD4_CB_UNKNOWN;
 }
 
-static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp)
+static unsigned int
+nfsd_notify_to_ignore(u32 notify)
+{
+       unsigned int mask = 0;
+
+       if (notify & BIT(NOTIFY4_REMOVE_ENTRY))
+               mask |= FL_IGN_DIR_DELETE;
+       if (notify & BIT(NOTIFY4_ADD_ENTRY))
+               mask |= FL_IGN_DIR_CREATE;
+       if (notify & BIT(NOTIFY4_RENAME_ENTRY))
+               mask |= FL_IGN_DIR_RENAME;
+
+       return mask;
+}
+
+static struct file_lease *nfs4_alloc_init_lease(struct nfs4_delegation *dp, 
u32 notify)
 {
        struct file_lease *fl;
 
@@ -6048,7 +6063,7 @@ static struct file_lease *nfs4_alloc_init_lease(struct 
nfs4_delegation *dp)
        if (!fl)
                return NULL;
        fl->fl_lmops = &nfsd_lease_mng_ops;
-       fl->c.flc_flags = FL_DELEG;
+       fl->c.flc_flags = FL_DELEG | nfsd_notify_to_ignore(notify);
        fl->c.flc_type = deleg_is_read(dp->dl_type) ? F_RDLCK : F_WRLCK;
        fl->c.flc_owner = (fl_owner_t)dp;
        fl->c.flc_pid = current->tgid;
@@ -6265,7 +6280,7 @@ nfs4_set_delegation(struct nfsd4_open *open, struct 
nfs4_ol_stateid *stp,
        if (stp->st_stid.sc_export)
                dp->dl_stid.sc_export = exp_get(stp->st_stid.sc_export);
 
-       fl = nfs4_alloc_init_lease(dp);
+       fl = nfs4_alloc_init_lease(dp, 0);
        if (!fl)
                goto out_clnt_odstate;
 
@@ -9634,12 +9649,11 @@ nfsd_get_dir_deleg(struct nfsd4_compound_state *cstate,
                dp->dl_stid.sc_export =
                        exp_get(cstate->current_fh.fh_export);
 
-       fl = nfs4_alloc_init_lease(dp);
+       fl = nfs4_alloc_init_lease(dp, gdd->gddr_notification[0]);
        if (!fl)
                goto out_put_stid;
 
-       status = kernel_setlease(nf->nf_file,
-                                fl->c.flc_type, &fl, NULL);
+       status = kernel_setlease(nf->nf_file, fl->c.flc_type, &fl, NULL);
        if (fl)
                locks_free_lease(fl);
        if (status)

-- 
2.53.0


Reply via email to