nfsd: fix horrible indentation in nfsd_setattr
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index e431e93..3f55970 100644 (file)
 #include <linux/nfsd/state.h>
 #include <linux/nfsd/xdr4.h>
 #include <linux/namei.h>
+#include <linux/swap.h>
 #include <linux/mutex.h>
+#include <linux/lockd/bind.h>
+#include <linux/module.h>
 
 #define NFSDDBG_FACILITY                NFSDDBG_PROC
 
@@ -84,10 +87,10 @@ static void nfs4_set_recdir(char *recdir);
  */
 static DEFINE_MUTEX(client_mutex);
 
-static kmem_cache_t *stateowner_slab = NULL;
-static kmem_cache_t *file_slab = NULL;
-static kmem_cache_t *stateid_slab = NULL;
-static kmem_cache_t *deleg_slab = NULL;
+static struct kmem_cache *stateowner_slab = NULL;
+static struct kmem_cache *file_slab = NULL;
+static struct kmem_cache *stateid_slab = NULL;
+static struct kmem_cache *deleg_slab = NULL;
 
 void
 nfs4_lock_state(void)
@@ -148,6 +151,7 @@ get_nfs4_file(struct nfs4_file *fi)
 }
 
 static int num_delegations;
+unsigned int max_delegations;
 
 /*
  * Open owner state (share locks)
@@ -191,7 +195,9 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
        struct nfs4_callback *cb = &stp->st_stateowner->so_client->cl_callback;
 
        dprintk("NFSD alloc_init_deleg\n");
-       if (num_delegations > STATEID_HASH_SIZE * 4)
+       if (fp->fi_had_conflict)
+               return NULL;
+       if (num_delegations > max_delegations)
                return NULL;
        dp = kmem_cache_alloc(deleg_slab, GFP_KERNEL);
        if (dp == NULL)
@@ -250,7 +256,7 @@ nfs4_close_delegation(struct nfs4_delegation *dp)
        /* The following nfsd_close may not actually close the file,
         * but we want to remove the lease in any case. */
        if (dp->dl_flock)
-               setlease(filp, F_UNLCK, &dp->dl_flock);
+               vfs_setlease(filp, F_UNLCK, &dp->dl_flock);
        nfsd_close(filp);
 }
 
@@ -377,7 +383,6 @@ shutdown_callback_client(struct nfs4_client *clp)
        if (clnt) {
                clp->cl_callback.cb_client = NULL;
                rpc_shutdown_client(clnt);
-               rpciod_down();
        }
 }
 
@@ -711,9 +716,10 @@ out_err:
  *
  */
 __be32
-nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
+nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+                 struct nfsd4_setclientid *setclid)
 {
-       __be32                  ip_addr = rqstp->rq_addr.sin_addr.s_addr;
+       struct sockaddr_in      *sin = svc_addr_in(rqstp);
        struct xdr_netobj       clname = { 
                .len = setclid->se_namelen,
                .data = setclid->se_name,
@@ -748,10 +754,9 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
                 */
                status = nfserr_clid_inuse;
                if (!cmp_creds(&conf->cl_cred, &rqstp->rq_cred)
-                               || conf->cl_addr != ip_addr) {
-                       printk("NFSD: setclientid: string in use by client"
-                       "(clientid %08x/%08x)\n",
-                       conf->cl_clientid.cl_boot, conf->cl_clientid.cl_id);
+                               || conf->cl_addr != sin->sin_addr.s_addr) {
+                       dprintk("NFSD: setclientid: string in use by client"
+                               "at %u.%u.%u.%u\n", NIPQUAD(conf->cl_addr));
                        goto out;
                }
        }
@@ -768,7 +773,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
                if (new == NULL)
                        goto out;
                copy_verf(new, &clverifier);
-               new->cl_addr = ip_addr;
+               new->cl_addr = sin->sin_addr.s_addr;
                copy_cred(&new->cl_cred,&rqstp->rq_cred);
                gen_clid(new);
                gen_confirm(new);
@@ -800,7 +805,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
                if (new == NULL)
                        goto out;
                copy_verf(new,&conf->cl_verifier);
-               new->cl_addr = ip_addr;
+               new->cl_addr = sin->sin_addr.s_addr;
                copy_cred(&new->cl_cred,&rqstp->rq_cred);
                copy_clid(new, conf);
                gen_confirm(new);
@@ -819,7 +824,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
                if (new == NULL)
                        goto out;
                copy_verf(new,&clverifier);
-               new->cl_addr = ip_addr;
+               new->cl_addr = sin->sin_addr.s_addr;
                copy_cred(&new->cl_cred,&rqstp->rq_cred);
                gen_clid(new);
                gen_confirm(new);
@@ -846,7 +851,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_setclientid *setclid)
                if (new == NULL)
                        goto out;
                copy_verf(new,&clverifier);
-               new->cl_addr = ip_addr;
+               new->cl_addr = sin->sin_addr.s_addr;
                copy_cred(&new->cl_cred,&rqstp->rq_cred);
                gen_clid(new);
                gen_confirm(new);
@@ -876,9 +881,11 @@ out:
  * NOTE: callback information will be processed here in a future patch
  */
 __be32
-nfsd4_setclientid_confirm(struct svc_rqst *rqstp, struct nfsd4_setclientid_confirm *setclientid_confirm)
+nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
+                        struct nfsd4_compound_state *cstate,
+                        struct nfsd4_setclientid_confirm *setclientid_confirm)
 {
-       __be32 ip_addr = rqstp->rq_addr.sin_addr.s_addr;
+       struct sockaddr_in *sin = svc_addr_in(rqstp);
        struct nfs4_client *conf, *unconf;
        nfs4_verifier confirm = setclientid_confirm->sc_confirm; 
        clientid_t * clid = &setclientid_confirm->sc_clientid;
@@ -897,9 +904,9 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp, struct nfsd4_setclientid_confi
        unconf = find_unconfirmed_client(clid);
 
        status = nfserr_clid_inuse;
-       if (conf && conf->cl_addr != ip_addr)
+       if (conf && conf->cl_addr != sin->sin_addr.s_addr)
                goto out;
-       if (unconf && unconf->cl_addr != ip_addr)
+       if (unconf && unconf->cl_addr != sin->sin_addr.s_addr)
                goto out;
 
        if ((conf && unconf) && 
@@ -997,13 +1004,14 @@ alloc_init_file(struct inode *ino)
                list_add(&fp->fi_hash, &file_hashtbl[hashval]);
                fp->fi_inode = igrab(ino);
                fp->fi_id = current_fileid++;
+               fp->fi_had_conflict = false;
                return fp;
        }
        return NULL;
 }
 
 static void
-nfsd4_free_slab(kmem_cache_t **slab)
+nfsd4_free_slab(struct kmem_cache **slab)
 {
        if (*slab == NULL)
                return;
@@ -1024,19 +1032,19 @@ static int
 nfsd4_init_slabs(void)
 {
        stateowner_slab = kmem_cache_create("nfsd4_stateowners",
-                       sizeof(struct nfs4_stateowner), 0, 0, NULL, NULL);
+                       sizeof(struct nfs4_stateowner), 0, 0, NULL);
        if (stateowner_slab == NULL)
                goto out_nomem;
        file_slab = kmem_cache_create("nfsd4_files",
-                       sizeof(struct nfs4_file), 0, 0, NULL, NULL);
+                       sizeof(struct nfs4_file), 0, 0, NULL);
        if (file_slab == NULL)
                goto out_nomem;
        stateid_slab = kmem_cache_create("nfsd4_stateids",
-                       sizeof(struct nfs4_stateid), 0, 0, NULL, NULL);
+                       sizeof(struct nfs4_stateid), 0, 0, NULL);
        if (stateid_slab == NULL)
                goto out_nomem;
        deleg_slab = kmem_cache_create("nfsd4_delegations",
-                       sizeof(struct nfs4_delegation), 0, 0, NULL, NULL);
+                       sizeof(struct nfs4_delegation), 0, 0, NULL);
        if (deleg_slab == NULL)
                goto out_nomem;
        return 0;
@@ -1310,7 +1318,7 @@ static inline void
 nfs4_file_downgrade(struct file *filp, unsigned int share_access)
 {
        if (share_access & NFS4_SHARE_ACCESS_WRITE) {
-               put_write_access(filp->f_dentry->d_inode);
+               put_write_access(filp->f_path.dentry->d_inode);
                filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE;
        }
 }
@@ -1323,8 +1331,7 @@ do_recall(void *__dp)
 {
        struct nfs4_delegation *dp = __dp;
 
-       daemonize("nfsv4-recall");
-
+       dp->dl_file->fi_had_conflict = true;
        nfsd4_cb_recall(dp);
        return 0;
 }
@@ -1395,7 +1402,7 @@ void nfsd_release_deleg_cb(struct file_lock *fl)
 /*
  * Set the delegation file_lock back pointer.
  *
- * Called from __setlease() with lock_kernel() held.
+ * Called from setlease() with lock_kernel() held.
  */
 static
 void nfsd_copy_lock_deleg_cb(struct file_lock *new, struct file_lock *fl)
@@ -1409,7 +1416,7 @@ void nfsd_copy_lock_deleg_cb(struct file_lock *new, struct file_lock *fl)
 }
 
 /*
- * Called from __setlease() with lock_kernel() held
+ * Called from setlease() with lock_kernel() held
  */
 static
 int nfsd_same_client_deleg_cb(struct file_lock *onlist, struct file_lock *try)
@@ -1623,7 +1630,7 @@ static __be32
 nfs4_upgrade_open(struct svc_rqst *rqstp, struct svc_fh *cur_fh, struct nfs4_stateid *stp, struct nfsd4_open *open)
 {
        struct file *filp = stp->st_vfs_file;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        unsigned int share_access, new_writer;
        __be32 status;
 
@@ -1709,10 +1716,10 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
        fl.fl_file = stp->st_vfs_file;
        fl.fl_pid = current->tgid;
 
-       /* setlease checks to see if delegation should be handed out.
+       /* vfs_setlease checks to see if delegation should be handed out.
         * the lock_manager callbacks fl_mylease and fl_change are used
         */
-       if ((status = setlease(stp->st_vfs_file,
+       if ((status = vfs_setlease(stp->st_vfs_file,
                flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK, &flp))) {
                dprintk("NFSD: setlease failed [%d], no delegation\n", status);
                unhash_delegation(dp);
@@ -1833,7 +1840,8 @@ static void laundromat_main(struct work_struct *);
 static DECLARE_DELAYED_WORK(laundromat_work, laundromat_main);
 
 __be32
-nfsd4_renew(clientid_t *clid)
+nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+           clientid_t *clid)
 {
        struct nfs4_client *clp;
        __be32 status;
@@ -1965,7 +1973,7 @@ search_close_lru(u32 st_id, int flags)
 static inline int
 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
 {
-       return fhp->fh_dentry->d_inode != stp->st_vfs_file->f_dentry->d_inode;
+       return fhp->fh_dentry->d_inode != stp->st_vfs_file->f_path.dentry->d_inode;
 }
 
 static int
@@ -2241,24 +2249,25 @@ check_replay:
 }
 
 __be32
-nfsd4_open_confirm(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open_confirm *oc, struct nfs4_stateowner **replay_owner)
+nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+                  struct nfsd4_open_confirm *oc)
 {
        __be32 status;
        struct nfs4_stateowner *sop;
        struct nfs4_stateid *stp;
 
        dprintk("NFSD: nfsd4_open_confirm on file %.*s\n",
-                       (int)current_fh->fh_dentry->d_name.len,
-                       current_fh->fh_dentry->d_name.name);
+                       (int)cstate->current_fh.fh_dentry->d_name.len,
+                       cstate->current_fh.fh_dentry->d_name.name);
 
-       status = fh_verify(rqstp, current_fh, S_IFREG, 0);
+       status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0);
        if (status)
                return status;
 
        nfs4_lock_state();
 
-       if ((status = nfs4_preprocess_seqid_op(current_fh, oc->oc_seqid,
-                                       &oc->oc_req_stateid,
+       if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
+                                       oc->oc_seqid, &oc->oc_req_stateid,
                                        CHECK_FH | CONFIRM | OPEN_STATE,
                                        &oc->oc_stateowner, &stp, NULL)))
                goto out; 
@@ -2278,7 +2287,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfs
 out:
        if (oc->oc_stateowner) {
                nfs4_get_stateowner(oc->oc_stateowner);
-               *replay_owner = oc->oc_stateowner;
+               cstate->replay_owner = oc->oc_stateowner;
        }
        nfs4_unlock_state();
        return status;
@@ -2310,22 +2319,25 @@ reset_union_bmap_deny(unsigned long deny, unsigned long *bmap)
 }
 
 __be32
-nfsd4_open_downgrade(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open_downgrade *od, struct nfs4_stateowner **replay_owner)
+nfsd4_open_downgrade(struct svc_rqst *rqstp,
+                    struct nfsd4_compound_state *cstate,
+                    struct nfsd4_open_downgrade *od)
 {
        __be32 status;
        struct nfs4_stateid *stp;
        unsigned int share_access;
 
        dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", 
-                       (int)current_fh->fh_dentry->d_name.len,
-                       current_fh->fh_dentry->d_name.name);
+                       (int)cstate->current_fh.fh_dentry->d_name.len,
+                       cstate->current_fh.fh_dentry->d_name.name);
 
        if (!access_valid(od->od_share_access)
                        || !deny_valid(od->od_share_deny))
                return nfserr_inval;
 
        nfs4_lock_state();
-       if ((status = nfs4_preprocess_seqid_op(current_fh, od->od_seqid, 
+       if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
+                                       od->od_seqid,
                                        &od->od_stateid, 
                                        CHECK_FH | OPEN_STATE, 
                                        &od->od_stateowner, &stp, NULL)))
@@ -2355,7 +2367,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct n
 out:
        if (od->od_stateowner) {
                nfs4_get_stateowner(od->od_stateowner);
-               *replay_owner = od->od_stateowner;
+               cstate->replay_owner = od->od_stateowner;
        }
        nfs4_unlock_state();
        return status;
@@ -2365,18 +2377,20 @@ out:
  * nfs4_unlock_state() called after encode
  */
 __be32
-nfsd4_close(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_close *close, struct nfs4_stateowner **replay_owner)
+nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+           struct nfsd4_close *close)
 {
        __be32 status;
        struct nfs4_stateid *stp;
 
        dprintk("NFSD: nfsd4_close on file %.*s\n", 
-                       (int)current_fh->fh_dentry->d_name.len,
-                       current_fh->fh_dentry->d_name.name);
+                       (int)cstate->current_fh.fh_dentry->d_name.len,
+                       cstate->current_fh.fh_dentry->d_name.name);
 
        nfs4_lock_state();
        /* check close_lru for replay */
-       if ((status = nfs4_preprocess_seqid_op(current_fh, close->cl_seqid, 
+       if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
+                                       close->cl_seqid,
                                        &close->cl_stateid, 
                                        CHECK_FH | OPEN_STATE | CLOSE_STATE,
                                        &close->cl_stateowner, &stp, NULL)))
@@ -2397,22 +2411,24 @@ nfsd4_close(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_clos
 out:
        if (close->cl_stateowner) {
                nfs4_get_stateowner(close->cl_stateowner);
-               *replay_owner = close->cl_stateowner;
+               cstate->replay_owner = close->cl_stateowner;
        }
        nfs4_unlock_state();
        return status;
 }
 
 __be32
-nfsd4_delegreturn(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_delegreturn *dr)
+nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+                 struct nfsd4_delegreturn *dr)
 {
        __be32 status;
 
-       if ((status = fh_verify(rqstp, current_fh, S_IFREG, 0)))
+       if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
                goto out;
 
        nfs4_lock_state();
-       status = nfs4_preprocess_stateid_op(current_fh, &dr->dr_stateid, DELEG_RET, NULL);
+       status = nfs4_preprocess_stateid_op(&cstate->current_fh,
+                                           &dr->dr_stateid, DELEG_RET, NULL);
        nfs4_unlock_state();
 out:
        return status;
@@ -2635,7 +2651,8 @@ check_lock_length(u64 offset, u64 length)
  *  LOCK operation 
  */
 __be32
-nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock *lock, struct nfs4_stateowner **replay_owner)
+nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+          struct nfsd4_lock *lock)
 {
        struct nfs4_stateowner *open_sop = NULL;
        struct nfs4_stateowner *lock_sop = NULL;
@@ -2645,6 +2662,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
        struct file_lock conflock;
        __be32 status = 0;
        unsigned int strhashval;
+       unsigned int cmd;
        int err;
 
        dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
@@ -2654,7 +2672,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
        if (check_lock_length(lock->lk_offset, lock->lk_length))
                 return nfserr_inval;
 
-       if ((status = fh_verify(rqstp, current_fh, S_IFREG, MAY_LOCK))) {
+       if ((status = fh_verify(rqstp, &cstate->current_fh,
+                               S_IFREG, MAY_LOCK))) {
                dprintk("NFSD: nfsd4_lock: permission denied!\n");
                return status;
        }
@@ -2675,7 +2694,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
                        goto out;
 
                /* validate and update open stateid and open seqid */
-               status = nfs4_preprocess_seqid_op(current_fh, 
+               status = nfs4_preprocess_seqid_op(&cstate->current_fh,
                                        lock->lk_new_open_seqid,
                                        &lock->lk_new_open_stateid,
                                        CHECK_FH | OPEN_STATE,
@@ -2702,7 +2721,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
                        goto out;
        } else {
                /* lock (lock owner + lock stateid) already exists */
-               status = nfs4_preprocess_seqid_op(current_fh,
+               status = nfs4_preprocess_seqid_op(&cstate->current_fh,
                                       lock->lk_old_lock_seqid, 
                                       &lock->lk_old_lock_stateid, 
                                       CHECK_FH | LOCK_STATE, 
@@ -2726,10 +2745,12 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
                case NFS4_READ_LT:
                case NFS4_READW_LT:
                        file_lock.fl_type = F_RDLCK;
+                       cmd = F_SETLK;
                break;
                case NFS4_WRITE_LT:
                case NFS4_WRITEW_LT:
                        file_lock.fl_type = F_WRLCK;
+                       cmd = F_SETLK;
                break;
                default:
                        status = nfserr_inval;
@@ -2756,10 +2777,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
 
        /* XXX?: Just to divert the locks_release_private at the start of
         * locks_copy_lock: */
-       conflock.fl_ops = NULL;
-       conflock.fl_lmops = NULL;
-       err = posix_lock_file_conf(filp, &file_lock, &conflock);
-       dprintk("NFSD: nfsd4_lock: posix_lock_file_conf status %d\n",status);
+       locks_init_lock(&conflock);
+       err = vfs_lock_file(filp, cmd, &file_lock, &conflock);
        switch (-err) {
        case 0: /* success! */
                update_stateid(&lock_stp->st_stateid);
@@ -2776,7 +2795,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
                status = nfserr_deadlock;
                break;
        default:        
-               dprintk("NFSD: nfsd4_lock: posix_lock_file_conf() failed! status %d\n",err);
+               dprintk("NFSD: nfsd4_lock: vfs_lock_file() failed! status %d\n",err);
                status = nfserr_resource;
                break;
        }
@@ -2785,7 +2804,7 @@ out:
                release_stateowner(lock_sop);
        if (lock->lk_replay_owner) {
                nfs4_get_stateowner(lock->lk_replay_owner);
-               *replay_owner = lock->lk_replay_owner;
+               cstate->replay_owner = lock->lk_replay_owner;
        }
        nfs4_unlock_state();
        return status;
@@ -2795,12 +2814,13 @@ out:
  * LOCKT operation
  */
 __be32
-nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lockt *lockt)
+nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+           struct nfsd4_lockt *lockt)
 {
        struct inode *inode;
        struct file file;
        struct file_lock file_lock;
-       struct file_lock conflock;
+       int error;
        __be32 status;
 
        if (nfs4_in_grace())
@@ -2816,14 +2836,14 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
        if (STALE_CLIENTID(&lockt->lt_clientid))
                goto out;
 
-       if ((status = fh_verify(rqstp, current_fh, S_IFREG, 0))) {
+       if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0))) {
                dprintk("NFSD: nfsd4_lockt: fh_verify() failed!\n");
                if (status == nfserr_symlink)
                        status = nfserr_inval;
                goto out;
        }
 
-       inode = current_fh->fh_dentry->d_inode;
+       inode = cstate->current_fh.fh_dentry->d_inode;
        locks_init_lock(&file_lock);
        switch (lockt->lt_type) {
                case NFS4_READ_LT:
@@ -2856,18 +2876,23 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
 
        nfs4_transform_lock_offset(&file_lock);
 
-       /* posix_test_lock uses the struct file _only_ to resolve the inode.
+       /* vfs_test_lock uses the struct file _only_ to resolve the inode.
         * since LOCKT doesn't require an OPEN, and therefore a struct
-        * file may not exist, pass posix_test_lock a struct file with
+        * file may not exist, pass vfs_test_lock a struct file with
         * only the dentry:inode set.
         */
        memset(&file, 0, sizeof (struct file));
-       file.f_dentry = current_fh->fh_dentry;
+       file.f_path.dentry = cstate->current_fh.fh_dentry;
 
        status = nfs_ok;
-       if (posix_test_lock(&file, &file_lock, &conflock)) {
+       error = vfs_test_lock(&file, &file_lock);
+       if (error) {
+               status = nfserrno(error);
+               goto out;
+       }
+       if (file_lock.fl_type != F_UNLCK) {
                status = nfserr_denied;
-               nfs4_set_lock_denied(&conflock, &lockt->lt_denied);
+               nfs4_set_lock_denied(&file_lock, &lockt->lt_denied);
        }
 out:
        nfs4_unlock_state();
@@ -2875,7 +2900,8 @@ out:
 }
 
 __be32
-nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_locku *locku, struct nfs4_stateowner **replay_owner)
+nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
+           struct nfsd4_locku *locku)
 {
        struct nfs4_stateid *stp;
        struct file *filp = NULL;
@@ -2892,7 +2918,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
 
        nfs4_lock_state();
                                                                                
-       if ((status = nfs4_preprocess_seqid_op(current_fh, 
+       if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
                                        locku->lu_seqid, 
                                        &locku->lu_stateid, 
                                        CHECK_FH | LOCK_STATE, 
@@ -2919,9 +2945,9 @@ nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
        /*
        *  Try to unlock the file in the VFS.
        */
-       err = posix_lock_file(filp, &file_lock);
+       err = vfs_lock_file(filp, F_SETLK, &file_lock, NULL);
        if (err) {
-               dprintk("NFSD: nfs4_locku: posix_lock_file failed!\n");
+               dprintk("NFSD: nfs4_locku: vfs_lock_file failed!\n");
                goto out_nfserr;
        }
        /*
@@ -2933,7 +2959,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
 out:
        if (locku->lu_stateowner) {
                nfs4_get_stateowner(locku->lu_stateowner);
-               *replay_owner = locku->lu_stateowner;
+               cstate->replay_owner = locku->lu_stateowner;
        }
        nfs4_unlock_state();
        return status;
@@ -2952,7 +2978,7 @@ static int
 check_for_locks(struct file *filp, struct nfs4_stateowner *lowner)
 {
        struct file_lock **flpp;
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        int status = 0;
 
        lock_kernel();
@@ -2968,7 +2994,9 @@ out:
 }
 
 __be32
-nfsd4_release_lockowner(struct svc_rqst *rqstp, struct nfsd4_release_lockowner *rlockowner)
+nfsd4_release_lockowner(struct svc_rqst *rqstp,
+                       struct nfsd4_compound_state *cstate,
+                       struct nfsd4_release_lockowner *rlockowner)
 {
        clientid_t *clid = &rlockowner->rl_clientid;
        struct nfs4_stateowner *sop;
@@ -3169,20 +3197,49 @@ nfsd4_load_reboot_recovery_data(void)
                printk("NFSD: Failure reading reboot recovery data\n");
 }
 
+unsigned long
+get_nfs4_grace_period(void)
+{
+       return max(user_lease_time, lease_time) * HZ;
+}
+
+/*
+ * Since the lifetime of a delegation isn't limited to that of an open, a
+ * client may quite reasonably hang on to a delegation as long as it has
+ * the inode cached.  This becomes an obvious problem the first time a
+ * client's inode cache approaches the size of the server's total memory.
+ *
+ * For now we avoid this problem by imposing a hard limit on the number
+ * of delegations, which varies according to the server's memory size.
+ */
+static void
+set_max_delegations(void)
+{
+       /*
+        * Allow at most 4 delegations per megabyte of RAM.  Quick
+        * estimates suggest that in the worst case (where every delegation
+        * is for a different inode), a delegation could take about 1.5K,
+        * giving a worst case usage of about 6% of memory.
+        */
+       max_delegations = nr_free_buffer_pages() >> (20 - 2 - PAGE_SHIFT);
+}
+
 /* initialization to perform when the nfsd service is started: */
 
 static void
 __nfs4_state_start(void)
 {
-       time_t grace_time;
+       unsigned long grace_time;
 
        boot_time = get_seconds();
-       grace_time = max(user_lease_time, lease_time);
+       grace_time = get_nfs_grace_period();
        lease_time = user_lease_time;
        in_grace = 1;
-       printk("NFSD: starting %ld-second grace period\n", grace_time);
+       printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
+              grace_time/HZ);
        laundry_wq = create_singlethread_workqueue("nfsd4");
-       queue_delayed_work(laundry_wq, &laundromat_work, grace_time*HZ);
+       queue_delayed_work(laundry_wq, &laundromat_work, grace_time);
+       set_max_delegations();
 }
 
 int
@@ -3244,7 +3301,6 @@ __nfs4_state_shutdown(void)
                unhash_delegation(dp);
        }
 
-       cancel_delayed_work(&laundromat_work);
        nfsd4_shutdown_recdir();
        nfs4_init = 0;
 }