Skip to content

Commit 28df3d1

Browse files
author
J. Bruce Fields
committed
nfsd: clients don't need to break their own delegations
We currently revoke read delegations on any write open or any operation that modifies file data or metadata (including rename, link, and unlink). But if the delegation in question is the only read delegation and is held by the client performing the operation, that's not really necessary. It's not always possible to prevent this in the NFSv4.0 case, because there's not always a way to determine which client an NFSv4.0 delegation came from. (In theory we could try to guess this from the transport layer, e.g., by assuming all traffic on a given TCP connection comes from the same client. But that's not really correct.) In the NFSv4.1 case the session layer always tells us the client. This patch should remove such self-conflicts in all cases where we can reliably determine the client from the compound. To do that we need to track "who" is performing a given (possibly lease-breaking) file operation. We're doing that by storing the information in the svc_rqst and using kthread_data() to map the current task back to a svc_rqst. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent 52782c9 commit 28df3d1

8 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎Documentation/filesystems/locking.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ prototypes::
425425
int (*lm_grant)(struct file_lock *, struct file_lock *, int);
426426
void (*lm_break)(struct file_lock *); /* break_lease callback */
427427
int (*lm_change)(struct file_lock **, int);
428+
bool (*lm_breaker_owns_lease)(struct file_lock *);
428429

429430
locking rules:
430431

@@ -435,6 +436,7 @@ lm_notify: yes yes no
435436
lm_grant: no no no
436437
lm_break: yes no no
437438
lm_change yes no no
439+
lm_breaker_owns_lease: no no no
438440
========== ============= ================= =========
439441

440442
buffer_head

‎fs/locks.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,9 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker)
15571557
{
15581558
bool rc;
15591559

1560+
if (lease->fl_lmops->lm_breaker_owns_lease
1561+
&& lease->fl_lmops->lm_breaker_owns_lease(lease))
1562+
return false;
15601563
if ((breaker->fl_flags & FL_LAYOUT) != (lease->fl_flags & FL_LAYOUT)) {
15611564
rc = false;
15621565
goto trace;

‎fs/nfsd/nfs4proc.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
23022302
}
23032303
check_if_stalefh_allowed(args);
23042304

2305+
rqstp->rq_lease_breaker = (void **)&cstate->clp;
2306+
23052307
trace_nfsd_compound(rqstp, args->opcnt);
23062308
while (!status && resp->opcnt < args->opcnt) {
23072309
op = &args->ops[resp->opcnt++];

‎fs/nfsd/nfs4state.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4579,6 +4579,19 @@ nfsd_break_deleg_cb(struct file_lock *fl)
45794579
return ret;
45804580
}
45814581

4582+
static bool nfsd_breaker_owns_lease(struct file_lock *fl)
4583+
{
4584+
struct nfs4_delegation *dl = fl->fl_owner;
4585+
struct svc_rqst *rqst;
4586+
struct nfs4_client *clp;
4587+
4588+
if (!i_am_nfsd())
4589+
return NULL;
4590+
rqst = kthread_data(current);
4591+
clp = *(rqst->rq_lease_breaker);
4592+
return dl->dl_stid.sc_client == clp;
4593+
}
4594+
45824595
static int
45834596
nfsd_change_deleg_cb(struct file_lock *onlist, int arg,
45844597
struct list_head *dispose)
@@ -4590,6 +4603,7 @@ nfsd_change_deleg_cb(struct file_lock *onlist, int arg,
45904603
}
45914604

45924605
static const struct lock_manager_operations nfsd_lease_mng_ops = {
4606+
.lm_breaker_owns_lease = nfsd_breaker_owns_lease,
45934607
.lm_break = nfsd_break_deleg_cb,
45944608
.lm_change = nfsd_change_deleg_cb,
45954609
};

‎fs/nfsd/nfsd.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ int nfsd_pool_stats_release(struct inode *, struct file *);
8888

8989
void nfsd_destroy(struct net *net);
9090

91+
bool i_am_nfsd(void);
92+
9193
struct nfsdfs_client {
9294
struct kref cl_ref;
9395
void (*cl_release)(struct kref *kref);

‎fs/nfsd/nfssvc.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ static const struct svc_serv_ops nfsd_thread_sv_ops = {
601601
.svo_module = THIS_MODULE,
602602
};
603603

604+
bool i_am_nfsd()
605+
{
606+
return kthread_func(current) == nfsd;
607+
}
608+
604609
int nfsd_create_serv(struct net *net)
605610
{
606611
int error;
@@ -1011,6 +1016,7 @@ nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
10111016
*statp = rpc_garbage_args;
10121017
return 1;
10131018
}
1019+
rqstp->rq_lease_breaker = NULL;
10141020
/*
10151021
* Give the xdr decoder a chance to change this if it wants
10161022
* (necessary in the NFSv4.0 compound case)

‎include/linux/fs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ struct lock_manager_operations {
10451045
bool (*lm_break)(struct file_lock *);
10461046
int (*lm_change)(struct file_lock *, int, struct list_head *);
10471047
void (*lm_setup)(struct file_lock *, void **);
1048+
bool (*lm_breaker_owns_lease)(struct file_lock *);
10481049
};
10491050

10501051
struct lock_manager {

‎include/linux/sunrpc/svc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ struct svc_rqst {
299299
struct net *rq_bc_net; /* pointer to backchannel's
300300
* net namespace
301301
*/
302+
void ** rq_lease_breaker; /* The v4 client breaking a lease */
302303
};
303304

304305
#define SVC_NET(rqst) (rqst->rq_xprt ? rqst->rq_xprt->xpt_net : rqst->rq_bc_net)

0 commit comments

Comments
 (0)