11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * fs/nfsd/nfs4proc.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Server-side procedures for NFSv4. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan. 71da177e4SLinus Torvalds * All rights reserved. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu> 101da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu> 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without 131da177e4SLinus Torvalds * modification, are permitted provided that the following conditions 141da177e4SLinus Torvalds * are met: 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright 171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer. 181da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright 191da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the 201da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution. 211da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its 221da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived 231da177e4SLinus Torvalds * from this software without specific prior written permission. 241da177e4SLinus Torvalds * 251da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 261da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 271da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 281da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 291da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 301da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 311da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 321da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 331da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 341da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 351da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #include <linux/param.h> 391da177e4SLinus Torvalds #include <linux/major.h> 401da177e4SLinus Torvalds #include <linux/slab.h> 417e06b7f9SNeilBrown #include <linux/file.h> 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds #include <linux/sunrpc/svc.h> 441da177e4SLinus Torvalds #include <linux/nfsd/nfsd.h> 451da177e4SLinus Torvalds #include <linux/nfsd/cache.h> 461da177e4SLinus Torvalds #include <linux/nfs4.h> 471da177e4SLinus Torvalds #include <linux/nfsd/state.h> 481da177e4SLinus Torvalds #include <linux/nfsd/xdr4.h> 491da177e4SLinus Torvalds #include <linux/nfs4_acl.h> 50dcb488a3SAndy Adamson #include <linux/sunrpc/gss_api.h> 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #define NFSDDBG_FACILITY NFSDDBG_PROC 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static inline void 551da177e4SLinus Torvalds fh_dup2(struct svc_fh *dst, struct svc_fh *src) 561da177e4SLinus Torvalds { 571da177e4SLinus Torvalds fh_put(dst); 581da177e4SLinus Torvalds dget(src->fh_dentry); 591da177e4SLinus Torvalds if (src->fh_export) 601da177e4SLinus Torvalds cache_get(&src->fh_export->h); 611da177e4SLinus Torvalds *dst = *src; 621da177e4SLinus Torvalds } 631da177e4SLinus Torvalds 64b37ad28bSAl Viro static __be32 65dc730e17SJ. Bruce Fields do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode) 661da177e4SLinus Torvalds { 67b37ad28bSAl Viro __be32 status; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds if (open->op_truncate && 701da177e4SLinus Torvalds !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE)) 711da177e4SLinus Torvalds return nfserr_inval; 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds if (open->op_share_access & NFS4_SHARE_ACCESS_READ) 748837abcaSMiklos Szeredi accmode |= NFSD_MAY_READ; 759801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 768837abcaSMiklos Szeredi accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC); 779801d8a3SJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_WRITE) 788837abcaSMiklos Szeredi accmode |= NFSD_MAY_WRITE; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds status = fh_verify(rqstp, current_fh, S_IFREG, accmode); 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds return status; 831da177e4SLinus Torvalds } 841da177e4SLinus Torvalds 85b37ad28bSAl Viro static __be32 861da177e4SLinus Torvalds do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) 871da177e4SLinus Torvalds { 881da177e4SLinus Torvalds struct svc_fh resfh; 89b37ad28bSAl Viro __be32 status; 9081ac95c5SJ. Bruce Fields int created = 0; 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 931da177e4SLinus Torvalds open->op_truncate = 0; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds if (open->op_create) { 961da177e4SLinus Torvalds /* 971da177e4SLinus Torvalds * Note: create modes (UNCHECKED,GUARDED...) are the same 981da177e4SLinus Torvalds * in NFSv4 as in v3. 991da177e4SLinus Torvalds */ 1001da177e4SLinus Torvalds status = nfsd_create_v3(rqstp, current_fh, open->op_fname.data, 1011da177e4SLinus Torvalds open->op_fname.len, &open->op_iattr, 1021da177e4SLinus Torvalds &resfh, open->op_createmode, 103749997e5SJeff Layton (u32 *)open->op_verf.data, 104749997e5SJeff Layton &open->op_truncate, &created); 105749997e5SJeff Layton 10699f88726SJ. Bruce Fields /* 10799f88726SJ. Bruce Fields * Following rfc 3530 14.2.16, use the returned bitmask 10899f88726SJ. Bruce Fields * to indicate which attributes we used to store the 10999f88726SJ. Bruce Fields * verifier: 110749997e5SJeff Layton */ 111749997e5SJeff Layton if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 11299f88726SJ. Bruce Fields open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS | 113749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 114af85852dSJ. Bruce Fields } else { 1151da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 1161da177e4SLinus Torvalds open->op_fname.data, open->op_fname.len, &resfh); 1171da177e4SLinus Torvalds fh_unlock(current_fh); 1181da177e4SLinus Torvalds } 119af85852dSJ. Bruce Fields if (status) 120af85852dSJ. Bruce Fields goto out; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds set_change_info(&open->op_cinfo, current_fh); 12313024b7bSJ. Bruce Fields fh_dup2(current_fh, &resfh); 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds /* set reply cache */ 126a4773c08SJ. Bruce Fields fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh, 127a4773c08SJ. Bruce Fields &resfh.fh_handle); 12881ac95c5SJ. Bruce Fields if (!created) 1298837abcaSMiklos Szeredi status = do_open_permission(rqstp, current_fh, open, 1308837abcaSMiklos Szeredi NFSD_MAY_NOP); 1311da177e4SLinus Torvalds 132af85852dSJ. Bruce Fields out: 1331da177e4SLinus Torvalds fh_put(&resfh); 1341da177e4SLinus Torvalds return status; 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds 137b37ad28bSAl Viro static __be32 1381da177e4SLinus Torvalds do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) 1391da177e4SLinus Torvalds { 140b37ad28bSAl Viro __be32 status; 1411da177e4SLinus Torvalds 1421da177e4SLinus Torvalds /* Only reclaims from previously confirmed clients are valid */ 1431da177e4SLinus Torvalds if ((status = nfs4_check_open_reclaim(&open->op_clientid))) 1441da177e4SLinus Torvalds return status; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 1471da177e4SLinus Torvalds * set the change info 1481da177e4SLinus Torvalds */ 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds /* set replay cache */ 153a4773c08SJ. Bruce Fields fh_copy_shallow(&open->op_stateowner->so_replay.rp_openfh, 154a4773c08SJ. Bruce Fields ¤t_fh->fh_handle); 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 1571da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 1581da177e4SLinus Torvalds 1598837abcaSMiklos Szeredi status = do_open_permission(rqstp, current_fh, open, 1608837abcaSMiklos Szeredi NFSD_MAY_OWNER_OVERRIDE); 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds return status; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds 16560adfc50SAndy Adamson static void 16660adfc50SAndy Adamson copy_clientid(clientid_t *clid, struct nfsd4_session *session) 16760adfc50SAndy Adamson { 16860adfc50SAndy Adamson struct nfsd4_sessionid *sid = 16960adfc50SAndy Adamson (struct nfsd4_sessionid *)session->se_sessionid.data; 17060adfc50SAndy Adamson 17160adfc50SAndy Adamson clid->cl_boot = sid->clientid.cl_boot; 17260adfc50SAndy Adamson clid->cl_id = sid->clientid.cl_id; 17360adfc50SAndy Adamson } 1741da177e4SLinus Torvalds 1757191155bSJ.Bruce Fields static __be32 176ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 177a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 1781da177e4SLinus Torvalds { 179b37ad28bSAl Viro __be32 status; 1806668958fSAndy Adamson struct nfsd4_compoundres *resp; 1816668958fSAndy Adamson 1821da177e4SLinus Torvalds dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n", 1831da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 1841da177e4SLinus Torvalds open->op_stateowner); 1851da177e4SLinus Torvalds 1861da177e4SLinus Torvalds /* This check required by spec. */ 1871da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 1881da177e4SLinus Torvalds return nfserr_inval; 1891da177e4SLinus Torvalds 19060adfc50SAndy Adamson if (nfsd4_has_session(cstate)) 19160adfc50SAndy Adamson copy_clientid(&open->op_clientid, cstate->session); 19260adfc50SAndy Adamson 1931da177e4SLinus Torvalds nfs4_lock_state(); 1941da177e4SLinus Torvalds 1951da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 1966668958fSAndy Adamson resp = rqstp->rq_resp; 1976668958fSAndy Adamson status = nfsd4_process_open1(&resp->cstate, open); 198a90b061cSAl Viro if (status == nfserr_replay_me) { 1991da177e4SLinus Torvalds struct nfs4_replay *rp = &open->op_stateowner->so_replay; 200ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 201a4773c08SJ. Bruce Fields fh_copy_shallow(&cstate->current_fh.fh_handle, 202a4773c08SJ. Bruce Fields &rp->rp_openfh); 2038837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 2041da177e4SLinus Torvalds if (status) 2051da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 2061da177e4SLinus Torvalds " restoring previous filehandle\n"); 2071da177e4SLinus Torvalds else 208a90b061cSAl Viro status = nfserr_replay_me; 2091da177e4SLinus Torvalds } 2101da177e4SLinus Torvalds if (status) 2111da177e4SLinus Torvalds goto out; 212fb553c0fSJ. Bruce Fields 213fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 214fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 215cbd0d51aSJ. Bruce Fields status = nfserr_grace; 216af558e33SJ. Bruce Fields if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 217cbd0d51aSJ. Bruce Fields goto out; 218cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 219af558e33SJ. Bruce Fields if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 220cbd0d51aSJ. Bruce Fields goto out; 221fb553c0fSJ. Bruce Fields 2221da177e4SLinus Torvalds switch (open->op_claim_type) { 2230dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 2241da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 2251da177e4SLinus Torvalds /* 2261da177e4SLinus Torvalds * (1) set CURRENT_FH to the file being opened, 2271da177e4SLinus Torvalds * creating it if necessary, (2) set open->op_cinfo, 2281da177e4SLinus Torvalds * (3) set open->op_truncate if the file is to be 2291da177e4SLinus Torvalds * truncated after opening, (4) do permission checking. 2301da177e4SLinus Torvalds */ 231ca364317SJ.Bruce Fields status = do_open_lookup(rqstp, &cstate->current_fh, 232ca364317SJ.Bruce Fields open); 2331da177e4SLinus Torvalds if (status) 2341da177e4SLinus Torvalds goto out; 2351da177e4SLinus Torvalds break; 2361da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 237a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 2381da177e4SLinus Torvalds /* 2391da177e4SLinus Torvalds * The CURRENT_FH is already set to the file being 2401da177e4SLinus Torvalds * opened. (1) set open->op_cinfo, (2) set 2411da177e4SLinus Torvalds * open->op_truncate if the file is to be truncated 2421da177e4SLinus Torvalds * after opening, (3) do permission checking. 2431da177e4SLinus Torvalds */ 244ca364317SJ.Bruce Fields status = do_open_fhandle(rqstp, &cstate->current_fh, 245ca364317SJ.Bruce Fields open); 2461da177e4SLinus Torvalds if (status) 2471da177e4SLinus Torvalds goto out; 2481da177e4SLinus Torvalds break; 2491da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 250a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 2512fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 2521da177e4SLinus Torvalds open->op_claim_type); 2531da177e4SLinus Torvalds status = nfserr_notsupp; 2541da177e4SLinus Torvalds goto out; 2551da177e4SLinus Torvalds default: 2562fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 2571da177e4SLinus Torvalds open->op_claim_type); 2581da177e4SLinus Torvalds status = nfserr_inval; 2591da177e4SLinus Torvalds goto out; 2601da177e4SLinus Torvalds } 2611da177e4SLinus Torvalds /* 2621da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 2631da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 2641da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 2651da177e4SLinus Torvalds */ 266ca364317SJ.Bruce Fields status = nfsd4_process_open2(rqstp, &cstate->current_fh, open); 2671da177e4SLinus Torvalds out: 268f2327d9aSNeil Brown if (open->op_stateowner) { 2691da177e4SLinus Torvalds nfs4_get_stateowner(open->op_stateowner); 270a4f1706aSJ.Bruce Fields cstate->replay_owner = open->op_stateowner; 271f2327d9aSNeil Brown } 2721da177e4SLinus Torvalds nfs4_unlock_state(); 2731da177e4SLinus Torvalds return status; 2741da177e4SLinus Torvalds } 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds /* 2771da177e4SLinus Torvalds * filehandle-manipulating ops. 2781da177e4SLinus Torvalds */ 2797191155bSJ.Bruce Fields static __be32 280b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 281b591480bSJ.Bruce Fields struct svc_fh **getfh) 2821da177e4SLinus Torvalds { 283ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 2841da177e4SLinus Torvalds return nfserr_nofilehandle; 2851da177e4SLinus Torvalds 286ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 2871da177e4SLinus Torvalds return nfs_ok; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2907191155bSJ.Bruce Fields static __be32 291ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 292ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 2931da177e4SLinus Torvalds { 294ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 295ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 296ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 297ca364317SJ.Bruce Fields putfh->pf_fhlen); 2988837abcaSMiklos Szeredi return fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3017191155bSJ.Bruce Fields static __be32 302b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 303b591480bSJ.Bruce Fields void *arg) 3041da177e4SLinus Torvalds { 305b37ad28bSAl Viro __be32 status; 3061da177e4SLinus Torvalds 307ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 308df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 3091da177e4SLinus Torvalds return status; 3101da177e4SLinus Torvalds } 3111da177e4SLinus Torvalds 3127191155bSJ.Bruce Fields static __be32 313b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 314b591480bSJ.Bruce Fields void *arg) 3151da177e4SLinus Torvalds { 316ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 3171da177e4SLinus Torvalds return nfserr_restorefh; 3181da177e4SLinus Torvalds 319ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 3201da177e4SLinus Torvalds return nfs_ok; 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3237191155bSJ.Bruce Fields static __be32 324b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 325b591480bSJ.Bruce Fields void *arg) 3261da177e4SLinus Torvalds { 327ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 3281da177e4SLinus Torvalds return nfserr_nofilehandle; 3291da177e4SLinus Torvalds 330ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 3311da177e4SLinus Torvalds return nfs_ok; 3321da177e4SLinus Torvalds } 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds /* 3351da177e4SLinus Torvalds * misc nfsv4 ops 3361da177e4SLinus Torvalds */ 3377191155bSJ.Bruce Fields static __be32 338ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 339ca364317SJ.Bruce Fields struct nfsd4_access *access) 3401da177e4SLinus Torvalds { 3411da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 3421da177e4SLinus Torvalds return nfserr_inval; 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 345ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 346ca364317SJ.Bruce Fields &access->ac_supported); 3471da177e4SLinus Torvalds } 3481da177e4SLinus Torvalds 3497191155bSJ.Bruce Fields static __be32 350ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 351ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 3521da177e4SLinus Torvalds { 353b37ad28bSAl Viro __be32 status; 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds u32 *p = (u32 *)commit->co_verf.data; 3561da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 3571da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 3581da177e4SLinus Torvalds 359ca364317SJ.Bruce Fields status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 360ca364317SJ.Bruce Fields commit->co_count); 3611da177e4SLinus Torvalds if (status == nfserr_symlink) 3621da177e4SLinus Torvalds status = nfserr_inval; 3631da177e4SLinus Torvalds return status; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 366b37ad28bSAl Viro static __be32 367ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 368ca364317SJ.Bruce Fields struct nfsd4_create *create) 3691da177e4SLinus Torvalds { 3701da177e4SLinus Torvalds struct svc_fh resfh; 371b37ad28bSAl Viro __be32 status; 3721da177e4SLinus Torvalds dev_t rdev; 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 3751da177e4SLinus Torvalds 3768837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, 3778837abcaSMiklos Szeredi NFSD_MAY_CREATE); 3781da177e4SLinus Torvalds if (status == nfserr_symlink) 3791da177e4SLinus Torvalds status = nfserr_notdir; 3801da177e4SLinus Torvalds if (status) 3811da177e4SLinus Torvalds return status; 3821da177e4SLinus Torvalds 3831da177e4SLinus Torvalds switch (create->cr_type) { 3841da177e4SLinus Torvalds case NF4LNK: 3851da177e4SLinus Torvalds /* ugh! we have to null-terminate the linktext, or 3861da177e4SLinus Torvalds * vfs_symlink() will choke. it is always safe to 3871da177e4SLinus Torvalds * null-terminate by brute force, since at worst we 3881da177e4SLinus Torvalds * will overwrite the first byte of the create namelen 3891da177e4SLinus Torvalds * in the XDR buffer, which has already been extracted 3901da177e4SLinus Torvalds * during XDR decode. 3911da177e4SLinus Torvalds */ 3921da177e4SLinus Torvalds create->cr_linkname[create->cr_linklen] = 0; 3931da177e4SLinus Torvalds 394ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 395ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 396ca364317SJ.Bruce Fields create->cr_linkname, create->cr_linklen, 397ca364317SJ.Bruce Fields &resfh, &create->cr_iattr); 3981da177e4SLinus Torvalds break; 3991da177e4SLinus Torvalds 4001da177e4SLinus Torvalds case NF4BLK: 4011da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 4021da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 4031da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 4041da177e4SLinus Torvalds return nfserr_inval; 405ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 406ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 407ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 4081da177e4SLinus Torvalds break; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds case NF4CHR: 4111da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 4121da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 4131da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 4141da177e4SLinus Torvalds return nfserr_inval; 415ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 416ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 417ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 4181da177e4SLinus Torvalds break; 4191da177e4SLinus Torvalds 4201da177e4SLinus Torvalds case NF4SOCK: 421ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 422ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 423ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 4241da177e4SLinus Torvalds break; 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvalds case NF4FIFO: 427ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 428ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 429ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 4301da177e4SLinus Torvalds break; 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds case NF4DIR: 4331da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 434ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 435ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 436ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 4371da177e4SLinus Torvalds break; 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds default: 4401da177e4SLinus Torvalds status = nfserr_badtype; 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds if (!status) { 444ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 445ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 446ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 4471da177e4SLinus Torvalds } 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds fh_put(&resfh); 4501da177e4SLinus Torvalds return status; 4511da177e4SLinus Torvalds } 4521da177e4SLinus Torvalds 4537191155bSJ.Bruce Fields static __be32 454ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 455ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 4561da177e4SLinus Torvalds { 457b37ad28bSAl Viro __be32 status; 4581da177e4SLinus Torvalds 4598837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 4601da177e4SLinus Torvalds if (status) 4611da177e4SLinus Torvalds return status; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 4641da177e4SLinus Torvalds return nfserr_inval; 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds getattr->ga_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0; 4671da177e4SLinus Torvalds getattr->ga_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1; 4681da177e4SLinus Torvalds 469ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 4701da177e4SLinus Torvalds return nfs_ok; 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds 4737191155bSJ.Bruce Fields static __be32 474ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 475ca364317SJ.Bruce Fields struct nfsd4_link *link) 4761da177e4SLinus Torvalds { 477b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 4781da177e4SLinus Torvalds 479ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 4801da177e4SLinus Torvalds return status; 481ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 482ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 4831da177e4SLinus Torvalds if (!status) 484ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 4851da177e4SLinus Torvalds return status; 4861da177e4SLinus Torvalds } 4871da177e4SLinus Torvalds 488b37ad28bSAl Viro static __be32 489b591480bSJ.Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 490b591480bSJ.Bruce Fields void *arg) 4911da177e4SLinus Torvalds { 4921da177e4SLinus Torvalds struct svc_fh tmp_fh; 493b37ad28bSAl Viro __be32 ret; 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 496df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 497df547efbSJ. Bruce Fields if (ret) 4981da177e4SLinus Torvalds return ret; 499ca364317SJ.Bruce Fields if (tmp_fh.fh_dentry == cstate->current_fh.fh_dentry) { 5001da177e4SLinus Torvalds fh_put(&tmp_fh); 5011da177e4SLinus Torvalds return nfserr_noent; 5021da177e4SLinus Torvalds } 5031da177e4SLinus Torvalds fh_put(&tmp_fh); 504ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 505ca364317SJ.Bruce Fields "..", 2, &cstate->current_fh); 5061da177e4SLinus Torvalds } 5071da177e4SLinus Torvalds 5087191155bSJ.Bruce Fields static __be32 509ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 510ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 5111da177e4SLinus Torvalds { 512ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 513ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 514ca364317SJ.Bruce Fields &cstate->current_fh); 5151da177e4SLinus Torvalds } 5161da177e4SLinus Torvalds 5177191155bSJ.Bruce Fields static __be32 518ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 519ca364317SJ.Bruce Fields struct nfsd4_read *read) 5201da177e4SLinus Torvalds { 521b37ad28bSAl Viro __be32 status; 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 5241da177e4SLinus Torvalds 5257e06b7f9SNeilBrown read->rd_filp = NULL; 5261da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 5271da177e4SLinus Torvalds return nfserr_inval; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds nfs4_lock_state(); 5301da177e4SLinus Torvalds /* check stateid */ 531dd453dfdSBenny Halevy if ((status = nfs4_preprocess_stateid_op(cstate, &read->rd_stateid, 5326150ef0dSJ. Bruce Fields RD_STATE, &read->rd_filp))) { 5331da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 5341da177e4SLinus Torvalds goto out; 5351da177e4SLinus Torvalds } 5367e06b7f9SNeilBrown if (read->rd_filp) 5377e06b7f9SNeilBrown get_file(read->rd_filp); 5381da177e4SLinus Torvalds status = nfs_ok; 5391da177e4SLinus Torvalds out: 5401da177e4SLinus Torvalds nfs4_unlock_state(); 5411da177e4SLinus Torvalds read->rd_rqstp = rqstp; 542ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 5431da177e4SLinus Torvalds return status; 5441da177e4SLinus Torvalds } 5451da177e4SLinus Torvalds 5467191155bSJ.Bruce Fields static __be32 547ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 548ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 5491da177e4SLinus Torvalds { 5501da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 5511da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 5561da177e4SLinus Torvalds return nfserr_inval; 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds readdir->rd_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0; 5591da177e4SLinus Torvalds readdir->rd_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1; 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) || 5621da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 5631da177e4SLinus Torvalds return nfserr_bad_cookie; 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 566ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 5671da177e4SLinus Torvalds return nfs_ok; 5681da177e4SLinus Torvalds } 5691da177e4SLinus Torvalds 5707191155bSJ.Bruce Fields static __be32 571ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 572ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 5731da177e4SLinus Torvalds { 5741da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 575ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 5761da177e4SLinus Torvalds return nfs_ok; 5771da177e4SLinus Torvalds } 5781da177e4SLinus Torvalds 5797191155bSJ.Bruce Fields static __be32 580ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 581ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 5821da177e4SLinus Torvalds { 583b37ad28bSAl Viro __be32 status; 5841da177e4SLinus Torvalds 585af558e33SJ. Bruce Fields if (locks_in_grace()) 586c815afc7SNeilBrown return nfserr_grace; 587ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 588ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 5891da177e4SLinus Torvalds if (status == nfserr_symlink) 5901da177e4SLinus Torvalds return nfserr_notdir; 5911da177e4SLinus Torvalds if (!status) { 592ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 593ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds return status; 5961da177e4SLinus Torvalds } 5971da177e4SLinus Torvalds 5987191155bSJ.Bruce Fields static __be32 599ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 600ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 6011da177e4SLinus Torvalds { 602b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 6031da177e4SLinus Torvalds 604ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 6051da177e4SLinus Torvalds return status; 606af558e33SJ. Bruce Fields if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags 607c815afc7SNeilBrown & NFSEXP_NOSUBTREECHECK)) 608c815afc7SNeilBrown return nfserr_grace; 609ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 610ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 6111da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds /* the underlying filesystem returns different error's than required 6141da177e4SLinus Torvalds * by NFSv4. both save_fh and current_fh have been verified.. */ 6151da177e4SLinus Torvalds if (status == nfserr_isdir) 6161da177e4SLinus Torvalds status = nfserr_exist; 6171da177e4SLinus Torvalds else if ((status == nfserr_notdir) && 618ca364317SJ.Bruce Fields (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) && 619ca364317SJ.Bruce Fields S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode))) 6201da177e4SLinus Torvalds status = nfserr_exist; 6211da177e4SLinus Torvalds else if (status == nfserr_symlink) 6221da177e4SLinus Torvalds status = nfserr_notdir; 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds if (!status) { 625ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 626ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 6271da177e4SLinus Torvalds } 6281da177e4SLinus Torvalds return status; 6291da177e4SLinus Torvalds } 6301da177e4SLinus Torvalds 6317191155bSJ.Bruce Fields static __be32 632dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 633dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 634dcb488a3SAndy Adamson { 635dcb488a3SAndy Adamson struct svc_fh resfh; 636dcb488a3SAndy Adamson struct svc_export *exp; 637dcb488a3SAndy Adamson struct dentry *dentry; 638dcb488a3SAndy Adamson __be32 err; 639dcb488a3SAndy Adamson 640dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 641dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 642dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 643dcb488a3SAndy Adamson &exp, &dentry); 644dcb488a3SAndy Adamson if (err) 645dcb488a3SAndy Adamson return err; 646dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 647dcb488a3SAndy Adamson exp_put(exp); 648dcb488a3SAndy Adamson err = nfserr_noent; 649dcb488a3SAndy Adamson } else 650dcb488a3SAndy Adamson secinfo->si_exp = exp; 651dcb488a3SAndy Adamson dput(dentry); 652dcb488a3SAndy Adamson return err; 653dcb488a3SAndy Adamson } 654dcb488a3SAndy Adamson 655dcb488a3SAndy Adamson static __be32 656ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 657ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 6581da177e4SLinus Torvalds { 659b37ad28bSAl Viro __be32 status = nfs_ok; 6601da177e4SLinus Torvalds 6611da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 6621da177e4SLinus Torvalds nfs4_lock_state(); 663dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, 6646150ef0dSJ. Bruce Fields &setattr->sa_stateid, WR_STATE, NULL); 6651da177e4SLinus Torvalds nfs4_unlock_state(); 666375c5547SJ. Bruce Fields if (status) { 6673e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 668375c5547SJ. Bruce Fields return status; 669375c5547SJ. Bruce Fields } 6701da177e4SLinus Torvalds } 67118f335afSDave Hansen status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt); 67218f335afSDave Hansen if (status) 67318f335afSDave Hansen return status; 6741da177e4SLinus Torvalds status = nfs_ok; 6751da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 676ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 677ca364317SJ.Bruce Fields setattr->sa_acl); 6781da177e4SLinus Torvalds if (status) 67918f335afSDave Hansen goto out; 680ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 6811da177e4SLinus Torvalds 0, (time_t)0); 68218f335afSDave Hansen out: 68318f335afSDave Hansen mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt); 6841da177e4SLinus Torvalds return status; 6851da177e4SLinus Torvalds } 6861da177e4SLinus Torvalds 6877191155bSJ.Bruce Fields static __be32 688ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 689ca364317SJ.Bruce Fields struct nfsd4_write *write) 6901da177e4SLinus Torvalds { 6911da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 6921da177e4SLinus Torvalds struct file *filp = NULL; 6931da177e4SLinus Torvalds u32 *p; 694b37ad28bSAl Viro __be32 status = nfs_ok; 69531dec253SDavid Shaw unsigned long cnt; 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 7001da177e4SLinus Torvalds return nfserr_inval; 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds nfs4_lock_state(); 703dd453dfdSBenny Halevy status = nfs4_preprocess_stateid_op(cstate, stateid, WR_STATE, &filp); 7047e06b7f9SNeilBrown if (filp) 7057e06b7f9SNeilBrown get_file(filp); 7061da177e4SLinus Torvalds nfs4_unlock_state(); 7071da177e4SLinus Torvalds 708375c5547SJ. Bruce Fields if (status) { 709375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 710375c5547SJ. Bruce Fields return status; 711375c5547SJ. Bruce Fields } 712375c5547SJ. Bruce Fields 71331dec253SDavid Shaw cnt = write->wr_buflen; 7141da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 7151da177e4SLinus Torvalds p = (u32 *)write->wr_verifier.data; 7161da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 7171da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 7181da177e4SLinus Torvalds 719ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 720ca364317SJ.Bruce Fields write->wr_offset, rqstp->rq_vec, write->wr_vlen, 72131dec253SDavid Shaw &cnt, &write->wr_how_written); 7227e06b7f9SNeilBrown if (filp) 7237e06b7f9SNeilBrown fput(filp); 7241da177e4SLinus Torvalds 72531dec253SDavid Shaw write->wr_bytes_written = cnt; 72631dec253SDavid Shaw 7271da177e4SLinus Torvalds if (status == nfserr_symlink) 7281da177e4SLinus Torvalds status = nfserr_inval; 7291da177e4SLinus Torvalds return status; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 7331da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 7341da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 7351da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 7361da177e4SLinus Torvalds */ 737b37ad28bSAl Viro static __be32 738c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 739ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 7401da177e4SLinus Torvalds { 7412ebbc012SAl Viro __be32 *buf, *p; 7421da177e4SLinus Torvalds int count; 743b37ad28bSAl Viro __be32 status; 7441da177e4SLinus Torvalds 7458837abcaSMiklos Szeredi status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP); 7461da177e4SLinus Torvalds if (status) 7471da177e4SLinus Torvalds return status; 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds if ((verify->ve_bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0) 7501da177e4SLinus Torvalds || (verify->ve_bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1)) 7511da177e4SLinus Torvalds return nfserr_attrnotsupp; 7521da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 7531da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 7541da177e4SLinus Torvalds return nfserr_inval; 7551da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 7561da177e4SLinus Torvalds return nfserr_inval; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds /* count in words: 7591da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 7601da177e4SLinus Torvalds */ 7611da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 7621da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 7631da177e4SLinus Torvalds if (!buf) 7641da177e4SLinus Torvalds return nfserr_resource; 7651da177e4SLinus Torvalds 766ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 767ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 768ca364317SJ.Bruce Fields cstate->current_fh.fh_dentry, buf, 7691da177e4SLinus Torvalds &count, verify->ve_bmval, 770406a7ea9SFrank Filz rqstp, 0); 7711da177e4SLinus Torvalds 7721da177e4SLinus Torvalds /* this means that nfsd4_encode_fattr() ran out of space */ 7731da177e4SLinus Torvalds if (status == nfserr_resource && count == 0) 7741da177e4SLinus Torvalds status = nfserr_not_same; 7751da177e4SLinus Torvalds if (status) 7761da177e4SLinus Torvalds goto out_kfree; 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds p = buf + 3; 7791da177e4SLinus Torvalds status = nfserr_not_same; 7801da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 7811da177e4SLinus Torvalds goto out_kfree; 7821da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 7831da177e4SLinus Torvalds status = nfserr_same; 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds out_kfree: 7861da177e4SLinus Torvalds kfree(buf); 7871da177e4SLinus Torvalds return status; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds 790c954e2a5SJ.Bruce Fields static __be32 791c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 792c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 793c954e2a5SJ.Bruce Fields { 794c954e2a5SJ.Bruce Fields __be32 status; 795c954e2a5SJ.Bruce Fields 796c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 797c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 798c954e2a5SJ.Bruce Fields } 799c954e2a5SJ.Bruce Fields 800c954e2a5SJ.Bruce Fields static __be32 801c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 802c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 803c954e2a5SJ.Bruce Fields { 804c954e2a5SJ.Bruce Fields __be32 status; 805c954e2a5SJ.Bruce Fields 806c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 807c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 808c954e2a5SJ.Bruce Fields } 809c954e2a5SJ.Bruce Fields 8101da177e4SLinus Torvalds /* 8111da177e4SLinus Torvalds * NULL call. 8121da177e4SLinus Torvalds */ 8137111c66eSAl Viro static __be32 8141da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 8151da177e4SLinus Torvalds { 8161da177e4SLinus Torvalds return nfs_ok; 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 819e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 820e2b20950SShankar Anand { 821e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 822e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 823e2b20950SShankar Anand } 824e2b20950SShankar Anand 825b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 826b591480bSJ.Bruce Fields void *); 827f9bb94c4SAndy Adamson enum nfsd4_op_flags { 828f9bb94c4SAndy Adamson ALLOWED_WITHOUT_FH = 1 << 0, /* No current filehandle required */ 829f9bb94c4SAndy Adamson ALLOWED_ON_ABSENT_FS = 2 << 0, /* ops processed on absent fs */ 830f9bb94c4SAndy Adamson ALLOWED_AS_FIRST_OP = 3 << 0, /* ops reqired first in compound */ 831f9bb94c4SAndy Adamson }; 832b591480bSJ.Bruce Fields 833b591480bSJ.Bruce Fields struct nfsd4_operation { 834b591480bSJ.Bruce Fields nfsd4op_func op_func; 835b591480bSJ.Bruce Fields u32 op_flags; 836b001a1b6SBenny Halevy char *op_name; 837b591480bSJ.Bruce Fields }; 838b591480bSJ.Bruce Fields 839b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 840b591480bSJ.Bruce Fields 841f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum); 842b001a1b6SBenny Halevy 8431da177e4SLinus Torvalds /* 844bf864a31SAndy Adamson * This is a replay of a compound for which no cache entry pages 845bf864a31SAndy Adamson * were used. Encode the sequence operation, and if cachethis is FALSE 846bf864a31SAndy Adamson * encode the uncache rep error on the next operation. 847bf864a31SAndy Adamson */ 848bf864a31SAndy Adamson static __be32 849bf864a31SAndy Adamson nfsd4_enc_uncached_replay(struct nfsd4_compoundargs *args, 850bf864a31SAndy Adamson struct nfsd4_compoundres *resp) 851bf864a31SAndy Adamson { 852bf864a31SAndy Adamson struct nfsd4_op *op; 853bf864a31SAndy Adamson 854bf864a31SAndy Adamson dprintk("--> %s resp->opcnt %d ce_cachethis %u \n", __func__, 855bf864a31SAndy Adamson resp->opcnt, resp->cstate.slot->sl_cache_entry.ce_cachethis); 856bf864a31SAndy Adamson 857bf864a31SAndy Adamson /* Encode the replayed sequence operation */ 858bf864a31SAndy Adamson BUG_ON(resp->opcnt != 1); 859bf864a31SAndy Adamson op = &args->ops[resp->opcnt - 1]; 860bf864a31SAndy Adamson nfsd4_encode_operation(resp, op); 861bf864a31SAndy Adamson 862bf864a31SAndy Adamson /*return nfserr_retry_uncached_rep in next operation. */ 863bf864a31SAndy Adamson if (resp->cstate.slot->sl_cache_entry.ce_cachethis == 0) { 864bf864a31SAndy Adamson op = &args->ops[resp->opcnt++]; 865bf864a31SAndy Adamson op->status = nfserr_retry_uncached_rep; 866bf864a31SAndy Adamson nfsd4_encode_operation(resp, op); 867bf864a31SAndy Adamson } 868bf864a31SAndy Adamson return op->status; 869bf864a31SAndy Adamson } 870bf864a31SAndy Adamson 871bf864a31SAndy Adamson /* 872f9bb94c4SAndy Adamson * Enforce NFSv4.1 COMPOUND ordering rules. 873f9bb94c4SAndy Adamson * 874f9bb94c4SAndy Adamson * TODO: 875f9bb94c4SAndy Adamson * - enforce NFS4ERR_NOT_ONLY_OP, 876f9bb94c4SAndy Adamson * - DESTROY_SESSION MUST be the final operation in the COMPOUND request. 877f9bb94c4SAndy Adamson */ 878f9bb94c4SAndy Adamson static bool nfs41_op_ordering_ok(struct nfsd4_compoundargs *args) 879f9bb94c4SAndy Adamson { 880f9bb94c4SAndy Adamson if (args->minorversion && args->opcnt > 0) { 881f9bb94c4SAndy Adamson struct nfsd4_op *op = &args->ops[0]; 882f9bb94c4SAndy Adamson return (op->status == nfserr_op_illegal) || 883f9bb94c4SAndy Adamson (nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP); 884f9bb94c4SAndy Adamson } 885f9bb94c4SAndy Adamson return true; 886f9bb94c4SAndy Adamson } 887f9bb94c4SAndy Adamson 888f9bb94c4SAndy Adamson /* 8891da177e4SLinus Torvalds * COMPOUND call. 8901da177e4SLinus Torvalds */ 8917111c66eSAl Viro static __be32 8921da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 8931da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 8941da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 8951da177e4SLinus Torvalds { 8961da177e4SLinus Torvalds struct nfsd4_op *op; 897b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 898e354d571SAndy Adamson struct nfsd4_compound_state *cstate = &resp->cstate; 899e5710199SJ.Bruce Fields int slack_bytes; 900b37ad28bSAl Viro __be32 status; 9011da177e4SLinus Torvalds 9021da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 903e354d571SAndy Adamson resp->p = rqstp->rq_res.head[0].iov_base + 904e354d571SAndy Adamson rqstp->rq_res.head[0].iov_len; 9051da177e4SLinus Torvalds resp->tagp = resp->p; 9061da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 9071da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 9081da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 9091da177e4SLinus Torvalds resp->taglen = args->taglen; 9101da177e4SLinus Torvalds resp->tag = args->tag; 9111da177e4SLinus Torvalds resp->opcnt = 0; 9121da177e4SLinus Torvalds resp->rqstp = rqstp; 913d87a8adeSAndy Adamson resp->cstate.minorversion = args->minorversion; 914e354d571SAndy Adamson resp->cstate.replay_owner = NULL; 915e354d571SAndy Adamson fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); 916e354d571SAndy Adamson fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); 9172f425878SAndy Adamson /* Use the deferral mechanism only for NFSv4.0 compounds */ 9182f425878SAndy Adamson rqstp->rq_usedeferral = (args->minorversion == 0); 9191da177e4SLinus Torvalds 9201da177e4SLinus Torvalds /* 9211da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 9221da177e4SLinus Torvalds */ 9231da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 924*8daf220aSBenny Halevy if (args->minorversion > nfsd_supported_minorversion) 9251da177e4SLinus Torvalds goto out; 9261da177e4SLinus Torvalds 927f9bb94c4SAndy Adamson if (!nfs41_op_ordering_ok(args)) { 928f9bb94c4SAndy Adamson op = &args->ops[0]; 929f9bb94c4SAndy Adamson op->status = nfserr_sequence_pos; 930f9bb94c4SAndy Adamson goto encode_op; 931f9bb94c4SAndy Adamson } 932f9bb94c4SAndy Adamson 9331da177e4SLinus Torvalds status = nfs_ok; 9341da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 9351da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 9361da177e4SLinus Torvalds 937b001a1b6SBenny Halevy dprintk("nfsv4 compound op #%d/%d: %d (%s)\n", 938b001a1b6SBenny Halevy resp->opcnt, args->opcnt, op->opnum, 939b001a1b6SBenny Halevy nfsd4_op_name(op->opnum)); 9401da177e4SLinus Torvalds /* 9411da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 9421da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 9431da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 9441da177e4SLinus Torvalds */ 9451da177e4SLinus Torvalds if (op->status) 9461da177e4SLinus Torvalds goto encode_op; 9471da177e4SLinus Torvalds 9481da177e4SLinus Torvalds /* We must be able to encode a successful response to 9491da177e4SLinus Torvalds * this operation, with enough room left over to encode a 9501da177e4SLinus Torvalds * failed response to the next operation. If we don't 9511da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 9521da177e4SLinus Torvalds */ 953e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 954e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 955e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 956e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 9571da177e4SLinus Torvalds op->status = nfserr_resource; 9581da177e4SLinus Torvalds goto encode_op; 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds 961b591480bSJ.Bruce Fields opdesc = &nfsd4_ops[op->opnum]; 962b591480bSJ.Bruce Fields 963ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) { 96427d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 9651da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 9661da177e4SLinus Torvalds goto encode_op; 9671da177e4SLinus Torvalds } 968eeac294eSJ.Bruce Fields } else if (cstate->current_fh.fh_export->ex_fslocs.migrated && 969eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 97042ca0993SJ.Bruce Fields op->status = nfserr_moved; 97142ca0993SJ.Bruce Fields goto encode_op; 97242ca0993SJ.Bruce Fields } 973b591480bSJ.Bruce Fields 974b591480bSJ.Bruce Fields if (opdesc->op_func) 975b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 976b591480bSJ.Bruce Fields else 9771da177e4SLinus Torvalds BUG_ON(op->status == nfs_ok); 9781da177e4SLinus Torvalds 9791da177e4SLinus Torvalds encode_op: 980da3846a2SAndy Adamson /* Only from SEQUENCE or CREATE_SESSION */ 981da3846a2SAndy Adamson if (resp->cstate.status == nfserr_replay_cache) { 982da3846a2SAndy Adamson dprintk("%s NFS4.1 replay from cache\n", __func__); 983bf864a31SAndy Adamson if (nfsd4_not_cached(resp)) 984bf864a31SAndy Adamson status = nfsd4_enc_uncached_replay(args, resp); 985bf864a31SAndy Adamson else 986da3846a2SAndy Adamson status = op->status; 987da3846a2SAndy Adamson goto out; 988da3846a2SAndy Adamson } 989a90b061cSAl Viro if (op->status == nfserr_replay_me) { 990a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 9911da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 9921da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 9931da177e4SLinus Torvalds } else { 9941da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 9951da177e4SLinus Torvalds status = op->status; 9961da177e4SLinus Torvalds } 9970407717dSBenny Halevy 9980407717dSBenny Halevy dprintk("nfsv4 compound op %p opcnt %d #%d: %d: status %d\n", 9990407717dSBenny Halevy args->ops, args->opcnt, resp->opcnt, op->opnum, 10000407717dSBenny Halevy be32_to_cpu(status)); 10010407717dSBenny Halevy 1002a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 1003a4f1706aSJ.Bruce Fields nfs4_put_stateowner(cstate->replay_owner); 1004a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 10051da177e4SLinus Torvalds } 10067e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 10077e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 10087e06b7f9SNeilBrown fput(op->u.read.rd_filp); 1009e2b20950SShankar Anand 1010e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 10111da177e4SLinus Torvalds } 10122f425878SAndy Adamson if (!rqstp->rq_usedeferral && status == nfserr_dropit) { 10132f425878SAndy Adamson dprintk("%s Dropit - send NFS4ERR_DELAY\n", __func__); 10142f425878SAndy Adamson status = nfserr_jukebox; 10152f425878SAndy Adamson } 10161da177e4SLinus Torvalds 1017da3846a2SAndy Adamson resp->cstate.status = status; 1018e354d571SAndy Adamson fh_put(&resp->cstate.current_fh); 1019e354d571SAndy Adamson fh_put(&resp->cstate.save_fh); 1020e354d571SAndy Adamson BUG_ON(resp->cstate.replay_owner); 10211da177e4SLinus Torvalds out: 10221da177e4SLinus Torvalds nfsd4_release_compoundargs(args); 10232f425878SAndy Adamson /* Reset deferral mechanism for RPC deferrals */ 10242f425878SAndy Adamson rqstp->rq_usedeferral = 1; 10253b12cd98SJ. Bruce Fields dprintk("nfsv4 compound returned %d\n", ntohl(status)); 10261da177e4SLinus Torvalds return status; 10271da177e4SLinus Torvalds } 10281da177e4SLinus Torvalds 102920766016SBenny Halevy static struct nfsd4_operation nfsd4_ops[] = { 1030b591480bSJ.Bruce Fields [OP_ACCESS] = { 1031b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 1032b001a1b6SBenny Halevy .op_name = "OP_ACCESS", 1033b591480bSJ.Bruce Fields }, 1034b591480bSJ.Bruce Fields [OP_CLOSE] = { 1035b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 1036b001a1b6SBenny Halevy .op_name = "OP_CLOSE", 1037b591480bSJ.Bruce Fields }, 1038b591480bSJ.Bruce Fields [OP_COMMIT] = { 1039b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 1040b001a1b6SBenny Halevy .op_name = "OP_COMMIT", 1041b591480bSJ.Bruce Fields }, 1042b591480bSJ.Bruce Fields [OP_CREATE] = { 1043b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 1044b001a1b6SBenny Halevy .op_name = "OP_CREATE", 1045b591480bSJ.Bruce Fields }, 1046b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 1047b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 1048b001a1b6SBenny Halevy .op_name = "OP_DELEGRETURN", 1049b591480bSJ.Bruce Fields }, 1050b591480bSJ.Bruce Fields [OP_GETATTR] = { 1051b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 1052eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 1053b001a1b6SBenny Halevy .op_name = "OP_GETATTR", 1054b591480bSJ.Bruce Fields }, 1055b591480bSJ.Bruce Fields [OP_GETFH] = { 1056b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 1057b001a1b6SBenny Halevy .op_name = "OP_GETFH", 1058b591480bSJ.Bruce Fields }, 1059b591480bSJ.Bruce Fields [OP_LINK] = { 1060b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 1061b001a1b6SBenny Halevy .op_name = "OP_LINK", 1062b591480bSJ.Bruce Fields }, 1063b591480bSJ.Bruce Fields [OP_LOCK] = { 1064b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 1065b001a1b6SBenny Halevy .op_name = "OP_LOCK", 1066b591480bSJ.Bruce Fields }, 1067b591480bSJ.Bruce Fields [OP_LOCKT] = { 1068b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 1069b001a1b6SBenny Halevy .op_name = "OP_LOCKT", 1070b591480bSJ.Bruce Fields }, 1071b591480bSJ.Bruce Fields [OP_LOCKU] = { 1072b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 1073b001a1b6SBenny Halevy .op_name = "OP_LOCKU", 1074b591480bSJ.Bruce Fields }, 1075b591480bSJ.Bruce Fields [OP_LOOKUP] = { 1076b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 1077b001a1b6SBenny Halevy .op_name = "OP_LOOKUP", 1078b591480bSJ.Bruce Fields }, 1079b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 1080b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 1081b001a1b6SBenny Halevy .op_name = "OP_LOOKUPP", 1082b591480bSJ.Bruce Fields }, 1083b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1084b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1085b001a1b6SBenny Halevy .op_name = "OP_NVERIFY", 1086b591480bSJ.Bruce Fields }, 1087b591480bSJ.Bruce Fields [OP_OPEN] = { 1088b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 1089b001a1b6SBenny Halevy .op_name = "OP_OPEN", 1090b591480bSJ.Bruce Fields }, 1091b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1092b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 1093b001a1b6SBenny Halevy .op_name = "OP_OPEN_CONFIRM", 1094b591480bSJ.Bruce Fields }, 1095b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1096b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 1097b001a1b6SBenny Halevy .op_name = "OP_OPEN_DOWNGRADE", 1098b591480bSJ.Bruce Fields }, 1099b591480bSJ.Bruce Fields [OP_PUTFH] = { 1100b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 110127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1102b001a1b6SBenny Halevy .op_name = "OP_PUTFH", 1103b591480bSJ.Bruce Fields }, 1104eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1105a1c8c4d1SJ. Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 110627d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1107b001a1b6SBenny Halevy .op_name = "OP_PUTPUBFH", 1108eeac294eSJ.Bruce Fields }, 1109b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1110b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 111127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1112b001a1b6SBenny Halevy .op_name = "OP_PUTROOTFH", 1113b591480bSJ.Bruce Fields }, 1114b591480bSJ.Bruce Fields [OP_READ] = { 1115b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1116b001a1b6SBenny Halevy .op_name = "OP_READ", 1117b591480bSJ.Bruce Fields }, 1118b591480bSJ.Bruce Fields [OP_READDIR] = { 1119b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1120b001a1b6SBenny Halevy .op_name = "OP_READDIR", 1121b591480bSJ.Bruce Fields }, 1122b591480bSJ.Bruce Fields [OP_READLINK] = { 1123b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1124b001a1b6SBenny Halevy .op_name = "OP_READLINK", 1125b591480bSJ.Bruce Fields }, 1126b591480bSJ.Bruce Fields [OP_REMOVE] = { 1127b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1128b001a1b6SBenny Halevy .op_name = "OP_REMOVE", 1129b591480bSJ.Bruce Fields }, 1130b591480bSJ.Bruce Fields [OP_RENAME] = { 1131b001a1b6SBenny Halevy .op_name = "OP_RENAME", 1132b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 1133b591480bSJ.Bruce Fields }, 1134b591480bSJ.Bruce Fields [OP_RENEW] = { 1135b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 113627d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1137b001a1b6SBenny Halevy .op_name = "OP_RENEW", 1138b591480bSJ.Bruce Fields }, 1139b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1140b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 114127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1142b001a1b6SBenny Halevy .op_name = "OP_RESTOREFH", 1143b591480bSJ.Bruce Fields }, 1144b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1145b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 1146b001a1b6SBenny Halevy .op_name = "OP_SAVEFH", 1147b591480bSJ.Bruce Fields }, 1148dcb488a3SAndy Adamson [OP_SECINFO] = { 1149dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 1150b001a1b6SBenny Halevy .op_name = "OP_SECINFO", 1151dcb488a3SAndy Adamson }, 1152b591480bSJ.Bruce Fields [OP_SETATTR] = { 1153b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1154b001a1b6SBenny Halevy .op_name = "OP_SETATTR", 1155b591480bSJ.Bruce Fields }, 1156b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1157b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 115827d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1159b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID", 1160b591480bSJ.Bruce Fields }, 1161b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1162b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 116327d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1164b001a1b6SBenny Halevy .op_name = "OP_SETCLIENTID_CONFIRM", 1165b591480bSJ.Bruce Fields }, 1166b591480bSJ.Bruce Fields [OP_VERIFY] = { 1167b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1168b001a1b6SBenny Halevy .op_name = "OP_VERIFY", 1169b591480bSJ.Bruce Fields }, 1170b591480bSJ.Bruce Fields [OP_WRITE] = { 1171b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1172b001a1b6SBenny Halevy .op_name = "OP_WRITE", 1173b591480bSJ.Bruce Fields }, 1174b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1175b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 117627d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1177b001a1b6SBenny Halevy .op_name = "OP_RELEASE_LOCKOWNER", 1178b591480bSJ.Bruce Fields }, 1179069b6ad4SAndy Adamson 1180069b6ad4SAndy Adamson /* NFSv4.1 operations */ 1181069b6ad4SAndy Adamson [OP_EXCHANGE_ID] = { 1182069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_exchange_id, 1183f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1184069b6ad4SAndy Adamson .op_name = "OP_EXCHANGE_ID", 1185069b6ad4SAndy Adamson }, 1186069b6ad4SAndy Adamson [OP_CREATE_SESSION] = { 1187069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_create_session, 1188f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1189069b6ad4SAndy Adamson .op_name = "OP_CREATE_SESSION", 1190069b6ad4SAndy Adamson }, 1191069b6ad4SAndy Adamson [OP_DESTROY_SESSION] = { 1192069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_destroy_session, 1193f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1194069b6ad4SAndy Adamson .op_name = "OP_DESTROY_SESSION", 1195069b6ad4SAndy Adamson }, 1196069b6ad4SAndy Adamson [OP_SEQUENCE] = { 1197069b6ad4SAndy Adamson .op_func = (nfsd4op_func)nfsd4_sequence, 1198f9bb94c4SAndy Adamson .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP, 1199069b6ad4SAndy Adamson .op_name = "OP_SEQUENCE", 1200069b6ad4SAndy Adamson }, 1201b591480bSJ.Bruce Fields }; 1202b591480bSJ.Bruce Fields 1203f1c7f79bSAdrian Bunk static const char *nfsd4_op_name(unsigned opnum) 1204b001a1b6SBenny Halevy { 1205b001a1b6SBenny Halevy if (opnum < ARRAY_SIZE(nfsd4_ops)) 1206b001a1b6SBenny Halevy return nfsd4_ops[opnum].op_name; 1207b001a1b6SBenny Halevy return "unknown_operation"; 1208b001a1b6SBenny Halevy } 1209b001a1b6SBenny Halevy 12101da177e4SLinus Torvalds #define nfs4svc_decode_voidargs NULL 12111da177e4SLinus Torvalds #define nfs4svc_release_void NULL 12121da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 12131da177e4SLinus Torvalds #define nfs4svc_release_compound NULL 12141da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 12151da177e4SLinus Torvalds 12161da177e4SLinus Torvalds #define PROC(name, argt, rest, relt, cache, respsize) \ 12171da177e4SLinus Torvalds { (svc_procfunc) nfsd4_proc_##name, \ 12181da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_decode_##argt##args, \ 12191da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_encode_##rest##res, \ 12201da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_release_##relt, \ 12211da177e4SLinus Torvalds sizeof(struct nfsd4_##argt##args), \ 12221da177e4SLinus Torvalds sizeof(struct nfsd4_##rest##res), \ 12231da177e4SLinus Torvalds 0, \ 12241da177e4SLinus Torvalds cache, \ 12251da177e4SLinus Torvalds respsize, \ 12261da177e4SLinus Torvalds } 12271da177e4SLinus Torvalds 12281da177e4SLinus Torvalds /* 12291da177e4SLinus Torvalds * TODO: At the present time, the NFSv4 server does not do XID caching 12301da177e4SLinus Torvalds * of requests. Implementing XID caching would not be a serious problem, 12311da177e4SLinus Torvalds * although it would require a mild change in interfaces since one 12321da177e4SLinus Torvalds * doesn't know whether an NFSv4 request is idempotent until after the 12331da177e4SLinus Torvalds * XDR decode. However, XID caching totally confuses pynfs (Peter 12341da177e4SLinus Torvalds * Astrand's regression testsuite for NFSv4 servers), which reuses 12351da177e4SLinus Torvalds * XID's liberally, so I've left it unimplemented until pynfs generates 12361da177e4SLinus Torvalds * better XID's. 12371da177e4SLinus Torvalds */ 12381da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 12391da177e4SLinus Torvalds PROC(null, void, void, void, RC_NOCACHE, 1), 12407775f4c8SNeilBrown PROC(compound, compound, compound, compound, RC_NOCACHE, NFSD_BUFSIZE/4) 12411da177e4SLinus Torvalds }; 12421da177e4SLinus Torvalds 12431da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 12441da177e4SLinus Torvalds .vs_vers = 4, 12451da177e4SLinus Torvalds .vs_nproc = 2, 12461da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 12471da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 12481da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 12491da177e4SLinus Torvalds }; 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds /* 12521da177e4SLinus Torvalds * Local variables: 12531da177e4SLinus Torvalds * c-basic-offset: 8 12541da177e4SLinus Torvalds * End: 12551da177e4SLinus Torvalds */ 1256