123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include <linux/mm.h>
- #include <linux/pagemap.h>
- #include <linux/sunrpc/sched.h>
- #include <linux/sunrpc/clnt.h>
- #include <linux/nfs.h>
- #include <linux/nfs4.h>
- #include <linux/nfs_fs.h>
- #include "nfs4_fs.h"
- #include "delegation.h"
- #define NFSDBG_FACILITY NFSDBG_PROC
- void
- nfs4_renew_state(struct work_struct *work)
- {
- const struct nfs4_state_maintenance_ops *ops;
- struct nfs_client *clp =
- container_of(work, struct nfs_client, cl_renewd.work);
- struct rpc_cred *cred;
- long lease;
- unsigned long last, now;
- unsigned renew_flags = 0;
- ops = clp->cl_mvops->state_renewal_ops;
- dprintk("%s: start\n", __func__);
- if (test_bit(NFS_CS_STOP_RENEW, &clp->cl_res_state))
- goto out;
- spin_lock(&clp->cl_lock);
- lease = clp->cl_lease_time;
- last = clp->cl_last_renewal;
- now = jiffies;
-
- if (time_after(now, last + lease/3))
- renew_flags |= NFS4_RENEW_TIMEOUT;
- if (nfs_delegations_present(clp))
- renew_flags |= NFS4_RENEW_DELEGATION_CB;
- if (renew_flags != 0) {
- cred = ops->get_state_renewal_cred_locked(clp);
- spin_unlock(&clp->cl_lock);
- 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;
-
- ret = ops->sched_state_renewal(clp, cred, renew_flags);
- put_rpccred(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__);
- spin_unlock(&clp->cl_lock);
- }
- 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);
- cancel_delayed_work(&clp->cl_renewd);
- schedule_delayed_work(&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);
- }
|