NFSv4: Add a recovery marking scheme for state owners
authorTrond Myklebust <Trond.Myklebust@netapp.com>
Tue, 23 Dec 2008 20:21:43 +0000 (15:21 -0500)
committerTrond Myklebust <Trond.Myklebust@netapp.com>
Tue, 23 Dec 2008 20:21:43 +0000 (15:21 -0500)
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
fs/nfs/nfs4_fs.h
fs/nfs/nfs4proc.c
fs/nfs/nfs4state.c

index 76eda46b5a173a126d3f123d60ebdc8de0b5496a..a4e7b3feef8f6dc6feabf363afd5c61981ab38a1 100644 (file)
@@ -94,12 +94,18 @@ struct nfs4_state_owner {
 
        spinlock_t           so_lock;
        atomic_t             so_count;
+       unsigned long        so_flags;
        struct list_head     so_states;
        struct list_head     so_delegations;
        struct nfs_seqid_counter so_seqid;
        struct rpc_sequence  so_sequence;
 };
 
+enum {
+       NFS_OWNER_RECLAIM_REBOOT,
+       NFS_OWNER_RECLAIM_NOGRACE
+};
+
 /*
  * struct nfs4_state maintains the client-side state for a given
  * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
@@ -166,6 +172,7 @@ struct nfs4_exception {
 };
 
 struct nfs4_state_recovery_ops {
+       int owner_flag_bit;
        int state_flag_bit;
        int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
        int (*recover_lock)(struct nfs4_state *, struct file_lock *);
index 780ba004b3ddfd391dbbe1e5a2a95b9b6f6e31dc..019c8d67e145af2baeb6b23b6ec06912943dd5af 100644 (file)
@@ -3690,12 +3690,14 @@ int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
 }
 
 struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops = {
+       .owner_flag_bit = NFS_OWNER_RECLAIM_REBOOT,
        .state_flag_bit = NFS_STATE_RECLAIM_REBOOT,
        .recover_open   = nfs4_open_reclaim,
        .recover_lock   = nfs4_lock_reclaim,
 };
 
 struct nfs4_state_recovery_ops nfs4_nograce_recovery_ops = {
+       .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
        .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
        .recover_open   = nfs4_open_expired,
        .recover_lock   = nfs4_lock_expired,
index a780518c5c3fb68ab00c6cddcc9bf303279e9e57..7dcca23167ddaf7712e3dbf384671f53f9906d82 100644 (file)
@@ -832,6 +832,7 @@ static int nfs4_state_mark_reclaim_reboot(struct nfs_client *clp, struct nfs4_st
                clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
                return 0;
        }
+       set_bit(NFS_OWNER_RECLAIM_REBOOT, &state->owner->so_flags);
        set_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state);
        return 1;
 }
@@ -840,6 +841,7 @@ static int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_s
 {
        set_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
        clear_bit(NFS_STATE_RECLAIM_REBOOT, &state->flags);
+       set_bit(NFS_OWNER_RECLAIM_NOGRACE, &state->owner->so_flags);
        set_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state);
        return 1;
 }
@@ -1043,14 +1045,25 @@ static int nfs4_do_reclaim(struct nfs_client *clp, const struct nfs4_state_recov
        struct rb_node *pos;
        int status = 0;
 
-       /* Note: list is protected by exclusive lock on cl->cl_sem */
+restart:
+       spin_lock(&clp->cl_lock);
        for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
                struct nfs4_state_owner *sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
+               if (!test_and_clear_bit(ops->owner_flag_bit, &sp->so_flags))
+                       continue;
+               atomic_inc(&sp->so_count);
+               spin_unlock(&clp->cl_lock);
                status = nfs4_reclaim_open_state(sp, ops);
-               if (status < 0)
-                       break;
+               if (status < 0) {
+                       set_bit(ops->owner_flag_bit, &sp->so_flags);
+                       nfs4_put_state_owner(sp);
+                       nfs4_recovery_handle_error(clp, status);
+                       return status;
+               }
+               nfs4_put_state_owner(sp);
+               goto restart;
        }
-       nfs4_recovery_handle_error(clp, status);
+       spin_unlock(&clp->cl_lock);
        return status;
 }