]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/nfs/nfs4state.c
nfs: include ratelimit.h, fix nfs4state build error
[net-next-2.6.git] / fs / nfs / nfs4state.c
index 34acf5926fdc3e4ec73e2a531f0e61166f26c0c0..e0dc06d74b6a52de98306f06876797ba5fe7db87 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/kthread.h>
 #include <linux/module.h>
 #include <linux/random.h>
+#include <linux/ratelimit.h>
 #include <linux/workqueue.h>
 #include <linux/bitops.h>
 
@@ -145,7 +146,9 @@ static void nfs4_end_drain_session(struct nfs_client *clp)
        struct nfs4_session *ses = clp->cl_session;
        int max_slots;
 
-       if (test_and_clear_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state)) {
+       if (ses == NULL)
+               return;
+       if (test_and_clear_bit(NFS4_SESSION_DRAINING, &ses->session_state)) {
                spin_lock(&ses->fc_slot_table.slot_tbl_lock);
                max_slots = ses->fc_slot_table.max_slots;
                while (max_slots--) {
@@ -167,7 +170,7 @@ static int nfs4_begin_drain_session(struct nfs_client *clp)
        struct nfs4_slot_table *tbl = &ses->fc_slot_table;
 
        spin_lock(&tbl->slot_tbl_lock);
-       set_bit(NFS4CLNT_SESSION_DRAINING, &clp->cl_state);
+       set_bit(NFS4_SESSION_DRAINING, &ses->session_state);
        if (tbl->highest_used_slotid != -1) {
                INIT_COMPLETION(ses->complete);
                spin_unlock(&tbl->slot_tbl_lock);
@@ -371,7 +374,6 @@ nfs4_alloc_state_owner(void)
                return NULL;
        spin_lock_init(&sp->so_lock);
        INIT_LIST_HEAD(&sp->so_states);
-       INIT_LIST_HEAD(&sp->so_delegations);
        rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
        sp->so_seqid.sequence = &sp->so_sequence;
        spin_lock_init(&sp->so_sequence.lock);
@@ -384,7 +386,7 @@ static void
 nfs4_drop_state_owner(struct nfs4_state_owner *sp)
 {
        if (!RB_EMPTY_NODE(&sp->so_client_node)) {
-               struct nfs_client *clp = sp->so_client;
+               struct nfs_client *clp = sp->so_server->nfs_client;
 
                spin_lock(&clp->cl_lock);
                rb_erase(&sp->so_client_node, &clp->cl_state_owners);
@@ -406,7 +408,6 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
        new = nfs4_alloc_state_owner();
        if (new == NULL)
                return NULL;
-       new->so_client = clp;
        new->so_server = server;
        new->so_cred = cred;
        spin_lock(&clp->cl_lock);
@@ -423,7 +424,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
 
 void nfs4_put_state_owner(struct nfs4_state_owner *sp)
 {
-       struct nfs_client *clp = sp->so_client;
+       struct nfs_client *clp = sp->so_server->nfs_client;
        struct rpc_cred *cred = sp->so_cred;
 
        if (!atomic_dec_and_lock(&sp->so_count, &clp->cl_lock))
@@ -602,12 +603,21 @@ void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
  * that is compatible with current->files
  */
 static struct nfs4_lock_state *
-__nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
+__nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
 {
        struct nfs4_lock_state *pos;
        list_for_each_entry(pos, &state->lock_states, ls_locks) {
-               if (pos->ls_owner != fl_owner)
+               if (type != NFS4_ANY_LOCK_TYPE && pos->ls_owner.lo_type != type)
                        continue;
+               switch (pos->ls_owner.lo_type) {
+               case NFS4_POSIX_LOCK_TYPE:
+                       if (pos->ls_owner.lo_u.posix_owner != fl_owner)
+                               continue;
+                       break;
+               case NFS4_FLOCK_LOCK_TYPE:
+                       if (pos->ls_owner.lo_u.flock_owner != fl_pid)
+                               continue;
+               }
                atomic_inc(&pos->ls_count);
                return pos;
        }
@@ -619,10 +629,10 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
  * exists, return an uninitialized one.
  *
  */
-static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
+static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid, unsigned int type)
 {
        struct nfs4_lock_state *lsp;
-       struct nfs_client *clp = state->owner->so_client;
+       struct nfs_client *clp = state->owner->so_server->nfs_client;
 
        lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
        if (lsp == NULL)
@@ -633,7 +643,18 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
        lsp->ls_seqid.sequence = &lsp->ls_sequence;
        atomic_set(&lsp->ls_count, 1);
        lsp->ls_state = state;
-       lsp->ls_owner = fl_owner;
+       lsp->ls_owner.lo_type = type;
+       switch (lsp->ls_owner.lo_type) {
+       case NFS4_FLOCK_LOCK_TYPE:
+               lsp->ls_owner.lo_u.flock_owner = fl_pid;
+               break;
+       case NFS4_POSIX_LOCK_TYPE:
+               lsp->ls_owner.lo_u.posix_owner = fl_owner;
+               break;
+       default:
+               kfree(lsp);
+               return NULL;
+       }
        spin_lock(&clp->cl_lock);
        nfs_alloc_unique_id(&clp->cl_lockowner_id, &lsp->ls_id, 1, 64);
        spin_unlock(&clp->cl_lock);
@@ -643,7 +664,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
 
 static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
 {
-       struct nfs_client *clp = lsp->ls_state->owner->so_client;
+       struct nfs_client *clp = lsp->ls_state->owner->so_server->nfs_client;
 
        spin_lock(&clp->cl_lock);
        nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id);
@@ -657,13 +678,13 @@ static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
  * exists, return an uninitialized one.
  *
  */
-static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
+static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner, pid_t pid, unsigned int type)
 {
        struct nfs4_lock_state *lsp, *new = NULL;
        
        for(;;) {
                spin_lock(&state->state_lock);
-               lsp = __nfs4_find_lock_state(state, owner);
+               lsp = __nfs4_find_lock_state(state, owner, pid, type);
                if (lsp != NULL)
                        break;
                if (new != NULL) {
@@ -674,7 +695,7 @@ static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_
                        break;
                }
                spin_unlock(&state->state_lock);
-               new = nfs4_alloc_lock_state(state, owner);
+               new = nfs4_alloc_lock_state(state, owner, pid, type);
                if (new == NULL)
                        return NULL;
        }
@@ -701,6 +722,8 @@ void nfs4_put_lock_state(struct nfs4_lock_state *lsp)
        if (list_empty(&state->lock_states))
                clear_bit(LK_STATE_IN_USE, &state->flags);
        spin_unlock(&state->state_lock);
+       if (lsp->ls_flags & NFS_LOCK_INITIALIZED)
+               nfs4_release_lockowner(lsp);
        nfs4_free_lock_state(lsp);
 }
 
@@ -728,7 +751,12 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
 
        if (fl->fl_ops != NULL)
                return 0;
-       lsp = nfs4_get_lock_state(state, fl->fl_owner);
+       if (fl->fl_flags & FL_POSIX)
+               lsp = nfs4_get_lock_state(state, fl->fl_owner, 0, NFS4_POSIX_LOCK_TYPE);
+       else if (fl->fl_flags & FL_FLOCK)
+               lsp = nfs4_get_lock_state(state, 0, fl->fl_pid, NFS4_FLOCK_LOCK_TYPE);
+       else
+               return -EINVAL;
        if (lsp == NULL)
                return -ENOMEM;
        fl->fl_u.nfs4_fl.owner = lsp;
@@ -740,7 +768,7 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
  * Byte-range lock aware utility to initialize the stateid of read/write
  * requests.
  */
-void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner)
+void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner, pid_t fl_pid)
 {
        struct nfs4_lock_state *lsp;
        int seq;
@@ -753,7 +781,7 @@ void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t f
                return;
 
        spin_lock(&state->state_lock);
-       lsp = __nfs4_find_lock_state(state, fl_owner);
+       lsp = __nfs4_find_lock_state(state, fl_owner, fl_pid, NFS4_ANY_LOCK_TYPE);
        if (lsp != NULL && (lsp->ls_flags & NFS_LOCK_INITIALIZED) != 0)
                memcpy(dst, &lsp->ls_stateid, sizeof(*dst));
        spin_unlock(&state->state_lock);
@@ -1036,16 +1064,24 @@ restart:
                                /* Mark the file as being 'closed' */
                                state->state = 0;
                                break;
+                       case -EKEYEXPIRED:
+                               /*
+                                * User RPCSEC_GSS context has expired.
+                                * We cannot recover this stateid now, so
+                                * skip it and allow recovery thread to
+                                * proceed.
+                                */
+                               break;
                        case -NFS4ERR_ADMIN_REVOKED:
                        case -NFS4ERR_STALE_STATEID:
                        case -NFS4ERR_BAD_STATEID:
                        case -NFS4ERR_RECLAIM_BAD:
                        case -NFS4ERR_RECLAIM_CONFLICT:
-                               nfs4_state_mark_reclaim_nograce(sp->so_client, state);
+                               nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
                                break;
                        case -NFS4ERR_EXPIRED:
                        case -NFS4ERR_NO_GRACE:
-                               nfs4_state_mark_reclaim_nograce(sp->so_client, state);
+                               nfs4_state_mark_reclaim_nograce(sp->so_server->nfs_client, state);
                        case -NFS4ERR_STALE_CLIENTID:
                        case -NFS4ERR_BADSESSION:
                        case -NFS4ERR_BADSLOT:
@@ -1111,17 +1147,14 @@ static void nfs4_reclaim_complete(struct nfs_client *clp,
                (void)ops->reclaim_complete(clp);
 }
 
-static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
+static int nfs4_state_clear_reclaim_reboot(struct nfs_client *clp)
 {
        struct nfs4_state_owner *sp;
        struct rb_node *pos;
        struct nfs4_state *state;
 
        if (!test_and_clear_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))
-               return;
-
-       nfs4_reclaim_complete(clp,
-               nfs4_reboot_recovery_ops[clp->cl_minorversion]);
+               return 0;
 
        for (pos = rb_first(&clp->cl_state_owners); pos != NULL; pos = rb_next(pos)) {
                sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
@@ -1135,6 +1168,14 @@ static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
        }
 
        nfs_delegation_reap_unclaimed(clp);
+       return 1;
+}
+
+static void nfs4_state_end_reclaim_reboot(struct nfs_client *clp)
+{
+       if (!nfs4_state_clear_reclaim_reboot(clp))
+               return;
+       nfs4_reclaim_complete(clp, clp->cl_mvops->reboot_recovery_ops);
 }
 
 static void nfs_delegation_clear_all(struct nfs_client *clp)
@@ -1149,6 +1190,14 @@ static void nfs4_state_start_reclaim_nograce(struct nfs_client *clp)
        nfs4_state_mark_reclaim_helper(clp, nfs4_state_mark_reclaim_nograce);
 }
 
+static void nfs4_warn_keyexpired(const char *s)
+{
+       printk_ratelimited(KERN_WARNING "Error: state manager"
+                       " encountered RPCSEC_GSS session"
+                       " expired against NFSv4 server %s.\n",
+                       s);
+}
+
 static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
 {
        switch (error) {
@@ -1161,7 +1210,7 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
                case -NFS4ERR_STALE_CLIENTID:
                case -NFS4ERR_LEASE_MOVED:
                        set_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state);
-                       nfs4_state_end_reclaim_reboot(clp);
+                       nfs4_state_clear_reclaim_reboot(clp);
                        nfs4_state_start_reclaim_reboot(clp);
                        break;
                case -NFS4ERR_EXPIRED:
@@ -1178,6 +1227,10 @@ static int nfs4_recovery_handle_error(struct nfs_client *clp, int error)
                        set_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state);
                        /* Zero session reset errors */
                        return 0;
+               case -EKEYEXPIRED:
+                       /* Nothing we can do */
+                       nfs4_warn_keyexpired(clp->cl_hostname);
+                       return 0;
        }
        return error;
 }
@@ -1211,8 +1264,8 @@ restart:
 static int nfs4_check_lease(struct nfs_client *clp)
 {
        struct rpc_cred *cred;
-       struct nfs4_state_maintenance_ops *ops =
-               nfs4_state_renewal_ops[clp->cl_minorversion];
+       const struct nfs4_state_maintenance_ops *ops =
+               clp->cl_mvops->state_renewal_ops;
        int status = -NFS4ERR_EXPIRED;
 
        /* Is the client already known to have an expired lease? */
@@ -1235,8 +1288,8 @@ out:
 static int nfs4_reclaim_lease(struct nfs_client *clp)
 {
        struct rpc_cred *cred;
-       struct nfs4_state_recovery_ops *ops =
-               nfs4_reboot_recovery_ops[clp->cl_minorversion];
+       const struct nfs4_state_recovery_ops *ops =
+               clp->cl_mvops->reboot_recovery_ops;
        int status = -ENOENT;
 
        cred = ops->get_clid_cred(clp);
@@ -1388,9 +1441,10 @@ static void nfs4_set_lease_expired(struct nfs_client *clp, int status)
                case -NFS4ERR_DELAY:
                case -NFS4ERR_CLID_INUSE:
                case -EAGAIN:
-               case -EKEYEXPIRED:
                        break;
 
+               case -EKEYEXPIRED:
+                       nfs4_warn_keyexpired(clp->cl_hostname);
                case -NFS4ERR_NOT_SAME: /* FixMe: implement recovery
                                         * in nfs4_exchange_id */
                default:
@@ -1444,7 +1498,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
                /* First recover reboot state... */
                if (test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state)) {
                        status = nfs4_do_reclaim(clp,
-                               nfs4_reboot_recovery_ops[clp->cl_minorversion]);
+                               clp->cl_mvops->reboot_recovery_ops);
                        if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
                            test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
                                continue;
@@ -1458,7 +1512,7 @@ static void nfs4_state_manager(struct nfs_client *clp)
                /* Now recover expired state... */
                if (test_and_clear_bit(NFS4CLNT_RECLAIM_NOGRACE, &clp->cl_state)) {
                        status = nfs4_do_reclaim(clp,
-                               nfs4_nograce_recovery_ops[clp->cl_minorversion]);
+                               clp->cl_mvops->nograce_recovery_ops);
                        if (test_bit(NFS4CLNT_LEASE_EXPIRED, &clp->cl_state) ||
                            test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state) ||
                            test_bit(NFS4CLNT_RECLAIM_REBOOT, &clp->cl_state))