]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - fs/nfsd/nfs4state.c
Merge git://github.com/rustyrussell/linux
[karo-tx-linux.git] / fs / nfsd / nfs4state.c
index 1f8c781c2a28198addbaa220406494cf40abc0af..47e94e33a975d801ddefbf36d4ed793333ff141b 100644 (file)
@@ -268,6 +268,11 @@ static struct nfs4_stid *nfs4_alloc_stid(struct nfs4_client *cl, struct kmem_cac
        return kmem_cache_alloc(slab, GFP_KERNEL);
 }
 
+static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
+{
+       return openlockstateid(nfs4_alloc_stid(clp, stateid_slab));
+}
+
 static struct nfs4_delegation *
 alloc_init_deleg(struct nfs4_client *clp, struct nfs4_ol_stateid *stp, struct svc_fh *current_fh, u32 type)
 {
@@ -1940,8 +1945,16 @@ out:
 
                nfsd4_get_session(cstate->session);
                atomic_inc(&clp->cl_refcount);
-               if (clp->cl_cb_state == NFSD4_CB_DOWN)
-                       seq->status_flags |= SEQ4_STATUS_CB_PATH_DOWN;
+               switch (clp->cl_cb_state) {
+               case NFSD4_CB_DOWN:
+                       seq->status_flags = SEQ4_STATUS_CB_PATH_DOWN;
+                       break;
+               case NFSD4_CB_FAULT:
+                       seq->status_flags = SEQ4_STATUS_BACKCHANNEL_FAULT;
+                       break;
+               default:
+                       seq->status_flags = 0;
+               }
        }
        kfree(conn);
        spin_unlock(&client_lock);
@@ -1949,6 +1962,50 @@ out:
        return status;
 }
 
+static inline bool has_resources(struct nfs4_client *clp)
+{
+       return !list_empty(&clp->cl_openowners)
+               || !list_empty(&clp->cl_delegations)
+               || !list_empty(&clp->cl_sessions);
+}
+
+__be32
+nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_destroy_clientid *dc)
+{
+       struct nfs4_client *conf, *unconf, *clp;
+       int status = 0;
+
+       nfs4_lock_state();
+       unconf = find_unconfirmed_client(&dc->clientid);
+       conf = find_confirmed_client(&dc->clientid);
+
+       if (conf) {
+               clp = conf;
+
+               if (!is_client_expired(conf) && has_resources(conf)) {
+                       status = nfserr_clientid_busy;
+                       goto out;
+               }
+
+               /* rfc5661 18.50.3 */
+               if (cstate->session && conf == cstate->session->se_client) {
+                       status = nfserr_clientid_busy;
+                       goto out;
+               }
+       } else if (unconf)
+               clp = unconf;
+       else {
+               status = nfserr_stale_clientid;
+               goto out;
+       }
+
+       expire_client(clp);
+out:
+       nfs4_unlock_state();
+       dprintk("%s return %d\n", __func__, ntohl(status));
+       return status;
+}
+
 __be32
 nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc)
 {
@@ -2511,6 +2568,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
        struct nfs4_client *clp = NULL;
        unsigned int strhashval;
        struct nfs4_openowner *oo = NULL;
+       __be32 status;
 
        if (STALE_CLIENTID(&open->op_clientid))
                return nfserr_stale_clientid;
@@ -2538,12 +2596,20 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
                open->op_openowner = NULL;
                goto new_owner;
        }
-       return nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid);
+       status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid);
+       if (status)
+               return status;
+       clp = oo->oo_owner.so_client;
+       goto alloc_stateid;
 new_owner:
        oo = alloc_init_open_stateowner(strhashval, clp, open);
        if (oo == NULL)
                return nfserr_jukebox;
        open->op_openowner = oo;
+alloc_stateid:
+       open->op_stp = nfs4_alloc_stateid(clp);
+       if (!open->op_stp)
+               return nfserr_jukebox;
        return nfs_ok;
 }
 
@@ -2573,6 +2639,12 @@ static struct nfs4_delegation *find_deleg_stateid(struct nfs4_client *cl, statei
        return delegstateid(ret);
 }
 
+static bool nfsd4_is_deleg_cur(struct nfsd4_open *open)
+{
+       return open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR ||
+              open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH;
+}
+
 static __be32
 nfs4_check_deleg(struct nfs4_client *cl, struct nfs4_file *fp, struct nfsd4_open *open,
                struct nfs4_delegation **dp)
@@ -2588,7 +2660,7 @@ nfs4_check_deleg(struct nfs4_client *cl, struct nfs4_file *fp, struct nfsd4_open
        if (status)
                *dp = NULL;
 out:
-       if (open->op_claim_type != NFS4_OPEN_CLAIM_DELEGATE_CUR)
+       if (!nfsd4_is_deleg_cur(open))
                return nfs_ok;
        if (status)
                return status;
@@ -2616,11 +2688,6 @@ nfs4_check_open(struct nfs4_file *fp, struct nfsd4_open *open, struct nfs4_ol_st
        return nfs_ok;
 }
 
-static struct nfs4_ol_stateid * nfs4_alloc_stateid(struct nfs4_client *clp)
-{
-       return openlockstateid(nfs4_alloc_stid(clp, stateid_slab));
-}
-
 static void nfs4_free_stateid(struct nfs4_ol_stateid *s)
 {
        kmem_cache_free(stateid_slab, s);
@@ -2644,12 +2711,6 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
        int oflag = nfs4_access_to_omode(open->op_share_access);
        int access = nfs4_access_to_access(open->op_share_access);
 
-       /* CLAIM_DELEGATE_CUR is used in response to a broken lease;
-        * allowing it to break the lease and return EAGAIN leaves the
-        * client unable to make progress in returning the delegation */
-       if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
-               access |= NFSD_MAY_NOT_BREAK_LEASE;
-
        if (!fp->fi_fds[oflag]) {
                status = nfsd_open(rqstp, cur_fh, S_IFREG, access,
                        &fp->fi_fds[oflag]);
@@ -2661,28 +2722,6 @@ static __be32 nfs4_get_vfs_file(struct svc_rqst *rqstp, struct nfs4_file *fp,
        return nfs_ok;
 }
 
-static __be32
-nfs4_new_open(struct svc_rqst *rqstp, struct nfs4_ol_stateid **stpp,
-               struct nfs4_file *fp, struct svc_fh *cur_fh,
-               struct nfsd4_open *open)
-{
-       struct nfs4_ol_stateid *stp;
-       struct nfs4_client *cl = open->op_openowner->oo_owner.so_client;
-       __be32 status;
-
-       stp = nfs4_alloc_stateid(cl);
-       if (stp == NULL)
-               return nfserr_jukebox;
-
-       status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open);
-       if (status) {
-               nfs4_free_stateid(stp);
-               return status;
-       }
-       *stpp = stp;
-       return 0;
-}
-
 static inline __be32
 nfsd4_truncate(struct svc_rqst *rqstp, struct svc_fh *fh,
                struct nfsd4_open *open)
@@ -2898,7 +2937,7 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
                        goto out;
        } else {
                status = nfserr_bad_stateid;
-               if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
+               if (nfsd4_is_deleg_cur(open))
                        goto out;
                status = nfserr_jukebox;
                fp = open->op_file;
@@ -2916,9 +2955,11 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
                if (status)
                        goto out;
        } else {
-               status = nfs4_new_open(rqstp, &stp, fp, current_fh, open);
+               status = nfs4_get_vfs_file(rqstp, fp, current_fh, open);
                if (status)
                        goto out;
+               stp = open->op_stp;
+               open->op_stp = NULL;
                init_open_stateid(stp, fp, open);
                status = nfsd4_truncate(rqstp, current_fh, open);
                if (status) {
@@ -2975,6 +3016,8 @@ void nfsd4_cleanup_open_state(struct nfsd4_open *open, __be32 status)
        }
        if (open->op_file)
                nfsd4_free_file(open->op_file);
+       if (open->op_stp)
+               nfs4_free_stateid(open->op_stp);
 }
 
 __be32