/*
* Queue up a lock for blocking so that the GRANTED request can see it
*/
-struct nlm_wait *nlmclnt_prepare_block(struct nlm_host *host, struct file_lock *fl)
+int nlmclnt_prepare_block(struct nlm_rqst *req, struct nlm_host *host, struct file_lock *fl)
{
struct nlm_wait *block;
+ BUG_ON(req->a_block != NULL);
block = kmalloc(sizeof(*block), GFP_KERNEL);
- if (block != NULL) {
- block->b_host = host;
- block->b_lock = fl;
- init_waitqueue_head(&block->b_wait);
- block->b_status = NLM_LCK_BLOCKED;
- list_add(&block->b_list, &nlm_blocked);
- }
- return block;
+ if (block == NULL)
+ return -ENOMEM;
+ block->b_host = host;
+ block->b_lock = fl;
+ init_waitqueue_head(&block->b_wait);
+ block->b_status = NLM_LCK_BLOCKED;
+
+ list_add(&block->b_list, &nlm_blocked);
+ req->a_block = block;
+
+ return 0;
}
-void nlmclnt_finish_block(struct nlm_wait *block)
+void nlmclnt_finish_block(struct nlm_rqst *req)
{
+ struct nlm_wait *block = req->a_block;
+
if (block == NULL)
return;
+ req->a_block = NULL;
list_del(&block->b_list);
kfree(block);
}
/*
* Block on a lock
*/
-int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout)
+long nlmclnt_block(struct nlm_rqst *req, long timeout)
{
+ struct nlm_wait *block = req->a_block;
long ret;
/* A borken server might ask us to block even if we didn't
* request it. Just say no!
*/
- if (block == NULL)
+ if (!req->a_args.block)
return -EAGAIN;
/* Go to sleep waiting for GRANT callback. Some servers seem
ret = wait_event_interruptible_timeout(block->b_wait,
block->b_status != NLM_LCK_BLOCKED,
timeout);
- if (ret < 0)
- return -ERESTARTSYS;
- req->a_res.status = block->b_status;
- return 0;
+
+ if (block->b_status != NLM_LCK_BLOCKED) {
+ req->a_res.status = block->b_status;
+ block->b_status = NLM_LCK_BLOCKED;
+ }
+
+ return ret;
}
/*
list_for_each_entry(block, &nlm_blocked, b_list) {
struct file_lock *fl_blocked = block->b_lock;
- if (fl_blocked->fl_start != fl->fl_start)
- continue;
- if (fl_blocked->fl_end != fl->fl_end)
- continue;
- /*
- * Careful! The NLM server will return the 32-bit "pid" that
- * we put on the wire: in this case the lockowner "pid".
- */
- if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
+ if (!nlm_compare_locks(fl_blocked, fl))
continue;
if (!nlm_cmp_addr(&block->b_host->h_addr, addr))
continue;
* server crash.
*/
+/*
+ * Mark the locks for reclaiming.
+ * FIXME: In 2.5 we don't want to iterate through any global file_lock_list.
+ * Maintain NLM lock reclaiming lists in the nlm_host instead.
+ */
+static
+void nlmclnt_mark_reclaim(struct nlm_host *host)
+{
+ struct file_lock *fl;
+ struct inode *inode;
+ struct list_head *tmp;
+
+ list_for_each(tmp, &file_lock_list) {
+ fl = list_entry(tmp, struct file_lock, fl_link);
+
+ inode = fl->fl_file->f_dentry->d_inode;
+ if (inode->i_sb->s_magic != NFS_SUPER_MAGIC)
+ continue;
+ if (fl->fl_u.nfs_fl.owner == NULL)
+ continue;
+ if (fl->fl_u.nfs_fl.owner->host != host)
+ continue;
+ if (!(fl->fl_u.nfs_fl.flags & NFS_LCK_GRANTED))
+ continue;
+ fl->fl_u.nfs_fl.flags |= NFS_LCK_RECLAIM;
+ }
+}
+
/*
* Someone has sent us an SM_NOTIFY. Ensure we bind to the new port number,
* that we mark locks for reclaiming, and that we bump the pseudo NSM state.
*/
-static void nlmclnt_prepare_reclaim(struct nlm_host *host)
+static inline
+void nlmclnt_prepare_reclaim(struct nlm_host *host, u32 newstate)
{
- down_write(&host->h_rwsem);
host->h_monitored = 0;
+ host->h_nsmstate = newstate;
host->h_state++;
host->h_nextrebind = 0;
nlm_rebind_host(host);
-
- /*
- * Mark the locks for reclaiming.
- */
- list_splice_init(&host->h_granted, &host->h_reclaim);
-
+ nlmclnt_mark_reclaim(host);
dprintk("NLM: reclaiming locks for host %s", host->h_name);
}
-static void nlmclnt_finish_reclaim(struct nlm_host *host)
-{
- host->h_reclaiming = 0;
- up_write(&host->h_rwsem);
- dprintk("NLM: done reclaiming locks for host %s", host->h_name);
-}
-
/*
* Reclaim all locks on server host. We do this by spawning a separate
* reclaimer thread.
void
nlmclnt_recovery(struct nlm_host *host, u32 newstate)
{
- if (host->h_nsmstate == newstate)
- return;
- host->h_nsmstate = newstate;
- if (!host->h_reclaiming++) {
+ if (host->h_reclaiming++) {
+ if (host->h_nsmstate == newstate)
+ return;
+ nlmclnt_prepare_reclaim(host, newstate);
+ } else {
+ nlmclnt_prepare_reclaim(host, newstate);
nlm_get_host(host);
__module_get(THIS_MODULE);
if (kernel_thread(reclaimer, host, CLONE_KERNEL) < 0)
{
struct nlm_host *host = (struct nlm_host *) ptr;
struct nlm_wait *block;
- struct file_lock *fl, *next;
- u32 nsmstate;
+ struct list_head *tmp;
+ struct file_lock *fl;
+ struct inode *inode;
daemonize("%s-reclaim", host->h_name);
allow_signal(SIGKILL);
lock_kernel();
lockd_up();
- nlmclnt_prepare_reclaim(host);
/* First, reclaim all locks that have been marked. */
restart:
- nsmstate = host->h_nsmstate;
- list_for_each_entry_safe(fl, next, &host->h_reclaim, fl_u.nfs_fl.list) {
- list_del_init(&fl->fl_u.nfs_fl.list);
+ list_for_each(tmp, &file_lock_list) {
+ fl = list_entry(tmp, struct file_lock, fl_link);
- if (signalled())
+ inode = fl->fl_file->f_dentry->d_inode;
+ if (inode->i_sb->s_magic != NFS_SUPER_MAGIC)
continue;
- if (nlmclnt_reclaim(host, fl) != 0)
+ if (fl->fl_u.nfs_fl.owner == NULL)
continue;
- list_add_tail(&fl->fl_u.nfs_fl.list, &host->h_granted);
- if (host->h_nsmstate != nsmstate) {
- /* Argh! The server rebooted again! */
- list_splice_init(&host->h_granted, &host->h_reclaim);
- goto restart;
- }
+ if (fl->fl_u.nfs_fl.owner->host != host)
+ continue;
+ if (!(fl->fl_u.nfs_fl.flags & NFS_LCK_RECLAIM))
+ continue;
+
+ fl->fl_u.nfs_fl.flags &= ~NFS_LCK_RECLAIM;
+ nlmclnt_reclaim(host, fl);
+ if (signalled())
+ break;
+ goto restart;
}
- nlmclnt_finish_reclaim(host);
+
+ host->h_reclaiming = 0;
/* Now, wake up all processes that sleep on a blocked lock */
list_for_each_entry(block, &nlm_blocked, b_list) {