NFS: Convert printk's to dprintk's in fs/nfs/nfs?xdr.c
[safe/jmp/linux-2.6] / fs / nfs / nfs4state.c
index 4f78c0d..3e4adf8 100644 (file)
@@ -38,6 +38,7 @@
  * subsequent patch.
  */
 
+#include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/smp_lock.h>
 #include <linux/nfs_fs.h>
@@ -155,8 +156,9 @@ static void nfs_free_unique_id(struct rb_root *root, struct nfs_unique_id *id)
 }
 
 static struct nfs4_state_owner *
-nfs4_find_state_owner(struct nfs_client *clp, struct rpc_cred *cred)
+nfs4_find_state_owner(struct nfs_server *server, struct rpc_cred *cred)
 {
+       struct nfs_client *clp = server->nfs_client;
        struct rb_node **p = &clp->cl_state_owners.rb_node,
                       *parent = NULL;
        struct nfs4_state_owner *sp, *res = NULL;
@@ -165,6 +167,14 @@ nfs4_find_state_owner(struct nfs_client *clp, struct rpc_cred *cred)
                parent = *p;
                sp = rb_entry(parent, struct nfs4_state_owner, so_client_node);
 
+               if (server < sp->so_server) {
+                       p = &parent->rb_left;
+                       continue;
+               }
+               if (server > sp->so_server) {
+                       p = &parent->rb_right;
+                       continue;
+               }
                if (cred < sp->so_cred)
                        p = &parent->rb_left;
                else if (cred > sp->so_cred)
@@ -189,6 +199,14 @@ nfs4_insert_state_owner(struct nfs_client *clp, struct nfs4_state_owner *new)
                parent = *p;
                sp = rb_entry(parent, struct nfs4_state_owner, so_client_node);
 
+               if (new->so_server < sp->so_server) {
+                       p = &parent->rb_left;
+                       continue;
+               }
+               if (new->so_server > sp->so_server) {
+                       p = &parent->rb_right;
+                       continue;
+               }
                if (new->so_cred < sp->so_cred)
                        p = &parent->rb_left;
                else if (new->so_cred > sp->so_cred)
@@ -259,7 +277,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
        struct nfs4_state_owner *sp, *new;
 
        spin_lock(&clp->cl_lock);
-       sp = nfs4_find_state_owner(clp, cred);
+       sp = nfs4_find_state_owner(server, cred);
        spin_unlock(&clp->cl_lock);
        if (sp != NULL)
                return sp;
@@ -267,6 +285,7 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
        if (new == NULL)
                return NULL;
        new->so_client = clp;
+       new->so_server = server;
        new->so_cred = cred;
        spin_lock(&clp->cl_lock);
        sp = nfs4_insert_state_owner(clp, new);
@@ -306,6 +325,7 @@ nfs4_alloc_open_state(void)
        atomic_set(&state->count, 1);
        INIT_LIST_HEAD(&state->lock_states);
        spin_lock_init(&state->state_lock);
+       seqlock_init(&state->seqlock);
        return state;
 }
 
@@ -321,8 +341,6 @@ nfs4_state_set_mode_locked(struct nfs4_state *state, mode_t mode)
                else
                        list_move_tail(&state->open_states, &state->owner->so_states);
        }
-       if (mode == 0)
-               list_del_init(&state->inode_states);
        state->state = mode;
 }
 
@@ -395,8 +413,7 @@ void nfs4_put_open_state(struct nfs4_state *state)
        if (!atomic_dec_and_lock(&state->count, &owner->so_lock))
                return;
        spin_lock(&inode->i_lock);
-       if (!list_empty(&state->inode_states))
-               list_del(&state->inode_states);
+       list_del(&state->inode_states);
        list_del(&state->open_states);
        spin_unlock(&inode->i_lock);
        spin_unlock(&owner->so_lock);
@@ -410,7 +427,6 @@ void nfs4_put_open_state(struct nfs4_state *state)
  */
 void nfs4_close_state(struct path *path, struct nfs4_state *state, mode_t mode)
 {
-       struct inode *inode = state->inode;
        struct nfs4_state_owner *owner = state->owner;
        int call_close = 0;
        int newstate;
@@ -418,7 +434,6 @@ void nfs4_close_state(struct path *path, struct nfs4_state *state, mode_t mode)
        atomic_inc(&owner->so_count);
        /* Protect against nfs4_find_state() */
        spin_lock(&owner->so_lock);
-       spin_lock(&inode->i_lock);
        switch (mode & (FMODE_READ | FMODE_WRITE)) {
                case FMODE_READ:
                        state->n_rdonly--;
@@ -445,7 +460,6 @@ void nfs4_close_state(struct path *path, struct nfs4_state *state, mode_t mode)
                        clear_bit(NFS_DELEGATED_STATE, &state->flags);
        }
        nfs4_state_set_mode_locked(state, newstate);
-       spin_unlock(&inode->i_lock);
        spin_unlock(&owner->so_lock);
 
        if (!call_close) {
@@ -598,8 +612,12 @@ int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl)
 void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t fl_owner)
 {
        struct nfs4_lock_state *lsp;
+       int seq;
 
-       memcpy(dst, &state->stateid, sizeof(*dst));
+       do {
+               seq = read_seqbegin(&state->seqlock);
+               memcpy(dst, &state->stateid, sizeof(*dst));
+       } while (read_seqretry(&state->seqlock, seq));
        if (test_bit(LK_STATE_IN_USE, &state->flags) == 0)
                return;
 
@@ -648,6 +666,12 @@ static void nfs_increment_seqid(int status, struct nfs_seqid *seqid)
                case 0:
                        break;
                case -NFS4ERR_BAD_SEQID:
+                       if (seqid->sequence->flags & NFS_SEQID_CONFIRMED)
+                               return;
+                       printk(KERN_WARNING "NFS: v4 server returned a bad"
+                                       "sequence-id error on an"
+                                       "unconfirmed sequence %p!\n",
+                                       seqid->sequence);
                case -NFS4ERR_STALE_CLIENTID:
                case -NFS4ERR_STALE_STATEID:
                case -NFS4ERR_BAD_STATEID: