fs/nfs/nfs4renewd.c

Source file repositories/reference/linux-study-clean/fs/nfs/nfs4renewd.c

File Facts

System
Linux kernel
Corpus path
fs/nfs/nfs4renewd.c
Extension
.c
Size
4802 bytes
Lines
161
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

if (cred == NULL) {
			if (!(renew_flags & NFS4_RENEW_DELEGATION_CB)) {
				set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
				goto out;
			}
			nfs_expire_all_delegations(clp);
		} else {
			int ret;

			/* Queue an asynchronous RENEW. */
			ret = ops->sched_state_renewal(clp, cred, renew_flags);
			put_cred(cred);
			switch (ret) {
			default:
				goto out_exp;
			case -EAGAIN:
			case -ENOMEM:
				break;
			}
		}
	} else {
		dprintk("%s: failed to call renewd. Reason: lease not expired \n",
				__func__);
	}
	nfs4_schedule_state_renewal(clp);
out_exp:
	nfs_expire_unreferenced_delegations(clp);
out:
	dprintk("%s: done\n", __func__);
}

void
nfs4_schedule_state_renewal(struct nfs_client *clp)
{
	long timeout;

	spin_lock(&clp->cl_lock);
	timeout = (2 * clp->cl_lease_time) / 3 + (long)clp->cl_last_renewal
		- (long)jiffies;
	if (timeout < 5 * HZ)
		timeout = 5 * HZ;
	dprintk("%s: requeueing work. Lease period = %ld\n",
			__func__, (timeout + HZ - 1) / HZ);
	mod_delayed_work(system_percpu_wq, &clp->cl_renewd, timeout);
	set_bit(NFS_CS_RENEWD, &clp->cl_res_state);
	spin_unlock(&clp->cl_lock);
}

void
nfs4_kill_renewd(struct nfs_client *clp)
{
	cancel_delayed_work_sync(&clp->cl_renewd);
}

#define MAX_LEASE_PERIOD (60 * 60)	/* 1 hour */

/**
 * nfs4_set_lease_period - Sets the lease period on a nfs_client
 *
 * @clp: pointer to nfs_client
 * @period: new value for lease period (in seconds)
 */
void nfs4_set_lease_period(struct nfs_client *clp, u32 period)
{
	unsigned long lease;

	/* Limit the lease period */
	if (period < MAX_LEASE_PERIOD)
		lease = period * HZ;
	else
		lease = MAX_LEASE_PERIOD * HZ;

	spin_lock(&clp->cl_lock);
	clp->cl_lease_time = lease;
	spin_unlock(&clp->cl_lock);

	/* Cap maximum reconnect timeout at 1/2 lease period */
	rpc_set_connect_timeout(clp->cl_rpcclient, lease, lease >> 1);
}

Annotation

Implementation Notes