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) 74dc730e17SJ. Bruce Fields accmode |= MAY_READ; 759801d8a3SJ. Bruce Fields if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE) 761da177e4SLinus Torvalds accmode |= (MAY_WRITE | MAY_TRUNC); 779801d8a3SJ. Bruce Fields if (open->op_share_deny & NFS4_SHARE_DENY_WRITE) 789801d8a3SJ. Bruce Fields accmode |= 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 106749997e5SJeff Layton /* If we ever decide to use different attrs to store the 107749997e5SJeff Layton * verifier in nfsd_create_v3, then we'll need to change this 108749997e5SJeff Layton */ 109749997e5SJeff Layton if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0) 110749997e5SJeff Layton open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS | 111749997e5SJeff Layton FATTR4_WORD1_TIME_MODIFY); 112af85852dSJ. Bruce Fields } else { 1131da177e4SLinus Torvalds status = nfsd_lookup(rqstp, current_fh, 1141da177e4SLinus Torvalds open->op_fname.data, open->op_fname.len, &resfh); 1151da177e4SLinus Torvalds fh_unlock(current_fh); 1161da177e4SLinus Torvalds } 117af85852dSJ. Bruce Fields if (status) 118af85852dSJ. Bruce Fields goto out; 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds set_change_info(&open->op_cinfo, current_fh); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds /* set reply cache */ 1231da177e4SLinus Torvalds fh_dup2(current_fh, &resfh); 124af85852dSJ. Bruce Fields open->op_stateowner->so_replay.rp_openfh_len = resfh.fh_handle.fh_size; 1251da177e4SLinus Torvalds memcpy(open->op_stateowner->so_replay.rp_openfh, 126af85852dSJ. Bruce Fields &resfh.fh_handle.fh_base, resfh.fh_handle.fh_size); 1271da177e4SLinus Torvalds 12881ac95c5SJ. Bruce Fields if (!created) 129dc730e17SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, MAY_NOP); 1301da177e4SLinus Torvalds 131af85852dSJ. Bruce Fields out: 1321da177e4SLinus Torvalds fh_put(&resfh); 1331da177e4SLinus Torvalds return status; 1341da177e4SLinus Torvalds } 1351da177e4SLinus Torvalds 136b37ad28bSAl Viro static __be32 1371da177e4SLinus Torvalds do_open_fhandle(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open) 1381da177e4SLinus Torvalds { 139b37ad28bSAl Viro __be32 status; 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds /* Only reclaims from previously confirmed clients are valid */ 1421da177e4SLinus Torvalds if ((status = nfs4_check_open_reclaim(&open->op_clientid))) 1431da177e4SLinus Torvalds return status; 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /* We don't know the target directory, and therefore can not 1461da177e4SLinus Torvalds * set the change info 1471da177e4SLinus Torvalds */ 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info)); 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds /* set replay cache */ 1521da177e4SLinus Torvalds open->op_stateowner->so_replay.rp_openfh_len = current_fh->fh_handle.fh_size; 1531da177e4SLinus Torvalds memcpy(open->op_stateowner->so_replay.rp_openfh, 1541da177e4SLinus Torvalds ¤t_fh->fh_handle.fh_base, 1551da177e4SLinus Torvalds current_fh->fh_handle.fh_size); 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) && 1581da177e4SLinus Torvalds (open->op_iattr.ia_size == 0); 1591da177e4SLinus Torvalds 160dc730e17SJ. Bruce Fields status = do_open_permission(rqstp, current_fh, open, MAY_OWNER_OVERRIDE); 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds return status; 1631da177e4SLinus Torvalds } 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds 1667191155bSJ.Bruce Fields static __be32 167ca364317SJ.Bruce Fields nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 168a4f1706aSJ.Bruce Fields struct nfsd4_open *open) 1691da177e4SLinus Torvalds { 170b37ad28bSAl Viro __be32 status; 1711da177e4SLinus Torvalds dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n", 1721da177e4SLinus Torvalds (int)open->op_fname.len, open->op_fname.data, 1731da177e4SLinus Torvalds open->op_stateowner); 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds /* This check required by spec. */ 1761da177e4SLinus Torvalds if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL) 1771da177e4SLinus Torvalds return nfserr_inval; 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds nfs4_lock_state(); 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds /* check seqid for replay. set nfs4_owner */ 1821da177e4SLinus Torvalds status = nfsd4_process_open1(open); 183a90b061cSAl Viro if (status == nfserr_replay_me) { 1841da177e4SLinus Torvalds struct nfs4_replay *rp = &open->op_stateowner->so_replay; 185ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 186ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = rp->rp_openfh_len; 187ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, rp->rp_openfh, 1881da177e4SLinus Torvalds rp->rp_openfh_len); 189ca364317SJ.Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, 0, MAY_NOP); 1901da177e4SLinus Torvalds if (status) 1911da177e4SLinus Torvalds dprintk("nfsd4_open: replay failed" 1921da177e4SLinus Torvalds " restoring previous filehandle\n"); 1931da177e4SLinus Torvalds else 194a90b061cSAl Viro status = nfserr_replay_me; 1951da177e4SLinus Torvalds } 1961da177e4SLinus Torvalds if (status) 1971da177e4SLinus Torvalds goto out; 198fb553c0fSJ. Bruce Fields 199fb553c0fSJ. Bruce Fields /* Openowner is now set, so sequence id will get bumped. Now we need 200fb553c0fSJ. Bruce Fields * these checks before we do any creates: */ 201cbd0d51aSJ. Bruce Fields status = nfserr_grace; 202fb553c0fSJ. Bruce Fields if (nfs4_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS) 203cbd0d51aSJ. Bruce Fields goto out; 204cbd0d51aSJ. Bruce Fields status = nfserr_no_grace; 205fb553c0fSJ. Bruce Fields if (!nfs4_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS) 206cbd0d51aSJ. Bruce Fields goto out; 207fb553c0fSJ. Bruce Fields 2081da177e4SLinus Torvalds switch (open->op_claim_type) { 2090dd3c192SNeilBrown case NFS4_OPEN_CLAIM_DELEGATE_CUR: 2100dd3c192SNeilBrown status = nfserr_inval; 2110dd3c192SNeilBrown if (open->op_create) 2120dd3c192SNeilBrown goto out; 2130dd3c192SNeilBrown /* fall through */ 2141da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL: 2151da177e4SLinus Torvalds /* 2161da177e4SLinus Torvalds * (1) set CURRENT_FH to the file being opened, 2171da177e4SLinus Torvalds * creating it if necessary, (2) set open->op_cinfo, 2181da177e4SLinus Torvalds * (3) set open->op_truncate if the file is to be 2191da177e4SLinus Torvalds * truncated after opening, (4) do permission checking. 2201da177e4SLinus Torvalds */ 221ca364317SJ.Bruce Fields status = do_open_lookup(rqstp, &cstate->current_fh, 222ca364317SJ.Bruce Fields open); 2231da177e4SLinus Torvalds if (status) 2241da177e4SLinus Torvalds goto out; 2251da177e4SLinus Torvalds break; 2261da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS: 227a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 2281da177e4SLinus Torvalds /* 2291da177e4SLinus Torvalds * The CURRENT_FH is already set to the file being 2301da177e4SLinus Torvalds * opened. (1) set open->op_cinfo, (2) set 2311da177e4SLinus Torvalds * open->op_truncate if the file is to be truncated 2321da177e4SLinus Torvalds * after opening, (3) do permission checking. 2331da177e4SLinus Torvalds */ 234ca364317SJ.Bruce Fields status = do_open_fhandle(rqstp, &cstate->current_fh, 235ca364317SJ.Bruce Fields open); 2361da177e4SLinus Torvalds if (status) 2371da177e4SLinus Torvalds goto out; 2381da177e4SLinus Torvalds break; 2391da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_PREV: 240a525825dSJ. Bruce Fields open->op_stateowner->so_confirmed = 1; 2412fdada03SJ. Bruce Fields dprintk("NFSD: unsupported OPEN claim type %d\n", 2421da177e4SLinus Torvalds open->op_claim_type); 2431da177e4SLinus Torvalds status = nfserr_notsupp; 2441da177e4SLinus Torvalds goto out; 2451da177e4SLinus Torvalds default: 2462fdada03SJ. Bruce Fields dprintk("NFSD: Invalid OPEN claim type %d\n", 2471da177e4SLinus Torvalds open->op_claim_type); 2481da177e4SLinus Torvalds status = nfserr_inval; 2491da177e4SLinus Torvalds goto out; 2501da177e4SLinus Torvalds } 2511da177e4SLinus Torvalds /* 2521da177e4SLinus Torvalds * nfsd4_process_open2() does the actual opening of the file. If 2531da177e4SLinus Torvalds * successful, it (1) truncates the file if open->op_truncate was 2541da177e4SLinus Torvalds * set, (2) sets open->op_stateid, (3) sets open->op_delegation. 2551da177e4SLinus Torvalds */ 256ca364317SJ.Bruce Fields status = nfsd4_process_open2(rqstp, &cstate->current_fh, open); 2571da177e4SLinus Torvalds out: 258f2327d9aSNeil Brown if (open->op_stateowner) { 2591da177e4SLinus Torvalds nfs4_get_stateowner(open->op_stateowner); 260a4f1706aSJ.Bruce Fields cstate->replay_owner = open->op_stateowner; 261f2327d9aSNeil Brown } 2621da177e4SLinus Torvalds nfs4_unlock_state(); 2631da177e4SLinus Torvalds return status; 2641da177e4SLinus Torvalds } 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds /* 2671da177e4SLinus Torvalds * filehandle-manipulating ops. 2681da177e4SLinus Torvalds */ 2697191155bSJ.Bruce Fields static __be32 270b591480bSJ.Bruce Fields nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 271b591480bSJ.Bruce Fields struct svc_fh **getfh) 2721da177e4SLinus Torvalds { 273ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 2741da177e4SLinus Torvalds return nfserr_nofilehandle; 2751da177e4SLinus Torvalds 276ca364317SJ.Bruce Fields *getfh = &cstate->current_fh; 2771da177e4SLinus Torvalds return nfs_ok; 2781da177e4SLinus Torvalds } 2791da177e4SLinus Torvalds 2807191155bSJ.Bruce Fields static __be32 281ca364317SJ.Bruce Fields nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 282ca364317SJ.Bruce Fields struct nfsd4_putfh *putfh) 2831da177e4SLinus Torvalds { 284ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 285ca364317SJ.Bruce Fields cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen; 286ca364317SJ.Bruce Fields memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval, 287ca364317SJ.Bruce Fields putfh->pf_fhlen); 288ca364317SJ.Bruce Fields return fh_verify(rqstp, &cstate->current_fh, 0, MAY_NOP); 2891da177e4SLinus Torvalds } 2901da177e4SLinus Torvalds 2917191155bSJ.Bruce Fields static __be32 292b591480bSJ.Bruce Fields nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 293b591480bSJ.Bruce Fields void *arg) 2941da177e4SLinus Torvalds { 295b37ad28bSAl Viro __be32 status; 2961da177e4SLinus Torvalds 297ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 298df547efbSJ. Bruce Fields status = exp_pseudoroot(rqstp, &cstate->current_fh); 2991da177e4SLinus Torvalds return status; 3001da177e4SLinus Torvalds } 3011da177e4SLinus Torvalds 3027191155bSJ.Bruce Fields static __be32 303b591480bSJ.Bruce Fields nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 304b591480bSJ.Bruce Fields void *arg) 3051da177e4SLinus Torvalds { 306ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 3071da177e4SLinus Torvalds return nfserr_restorefh; 3081da177e4SLinus Torvalds 309ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &cstate->save_fh); 3101da177e4SLinus Torvalds return nfs_ok; 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds 3137191155bSJ.Bruce Fields static __be32 314b591480bSJ.Bruce Fields nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 315b591480bSJ.Bruce Fields void *arg) 3161da177e4SLinus Torvalds { 317ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) 3181da177e4SLinus Torvalds return nfserr_nofilehandle; 3191da177e4SLinus Torvalds 320ca364317SJ.Bruce Fields fh_dup2(&cstate->save_fh, &cstate->current_fh); 3211da177e4SLinus Torvalds return nfs_ok; 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds /* 3251da177e4SLinus Torvalds * misc nfsv4 ops 3261da177e4SLinus Torvalds */ 3277191155bSJ.Bruce Fields static __be32 328ca364317SJ.Bruce Fields nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 329ca364317SJ.Bruce Fields struct nfsd4_access *access) 3301da177e4SLinus Torvalds { 3311da177e4SLinus Torvalds if (access->ac_req_access & ~NFS3_ACCESS_FULL) 3321da177e4SLinus Torvalds return nfserr_inval; 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds access->ac_resp_access = access->ac_req_access; 335ca364317SJ.Bruce Fields return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access, 336ca364317SJ.Bruce Fields &access->ac_supported); 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds 3397191155bSJ.Bruce Fields static __be32 340ca364317SJ.Bruce Fields nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 341ca364317SJ.Bruce Fields struct nfsd4_commit *commit) 3421da177e4SLinus Torvalds { 343b37ad28bSAl Viro __be32 status; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds u32 *p = (u32 *)commit->co_verf.data; 3461da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 3471da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 3481da177e4SLinus Torvalds 349ca364317SJ.Bruce Fields status = nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset, 350ca364317SJ.Bruce Fields commit->co_count); 3511da177e4SLinus Torvalds if (status == nfserr_symlink) 3521da177e4SLinus Torvalds status = nfserr_inval; 3531da177e4SLinus Torvalds return status; 3541da177e4SLinus Torvalds } 3551da177e4SLinus Torvalds 356b37ad28bSAl Viro static __be32 357ca364317SJ.Bruce Fields nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 358ca364317SJ.Bruce Fields struct nfsd4_create *create) 3591da177e4SLinus Torvalds { 3601da177e4SLinus Torvalds struct svc_fh resfh; 361b37ad28bSAl Viro __be32 status; 3621da177e4SLinus Torvalds dev_t rdev; 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds fh_init(&resfh, NFS4_FHSIZE); 3651da177e4SLinus Torvalds 366ca364317SJ.Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, MAY_CREATE); 3671da177e4SLinus Torvalds if (status == nfserr_symlink) 3681da177e4SLinus Torvalds status = nfserr_notdir; 3691da177e4SLinus Torvalds if (status) 3701da177e4SLinus Torvalds return status; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds switch (create->cr_type) { 3731da177e4SLinus Torvalds case NF4LNK: 3741da177e4SLinus Torvalds /* ugh! we have to null-terminate the linktext, or 3751da177e4SLinus Torvalds * vfs_symlink() will choke. it is always safe to 3761da177e4SLinus Torvalds * null-terminate by brute force, since at worst we 3771da177e4SLinus Torvalds * will overwrite the first byte of the create namelen 3781da177e4SLinus Torvalds * in the XDR buffer, which has already been extracted 3791da177e4SLinus Torvalds * during XDR decode. 3801da177e4SLinus Torvalds */ 3811da177e4SLinus Torvalds create->cr_linkname[create->cr_linklen] = 0; 3821da177e4SLinus Torvalds 383ca364317SJ.Bruce Fields status = nfsd_symlink(rqstp, &cstate->current_fh, 384ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 385ca364317SJ.Bruce Fields create->cr_linkname, create->cr_linklen, 386ca364317SJ.Bruce Fields &resfh, &create->cr_iattr); 3871da177e4SLinus Torvalds break; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds case NF4BLK: 3901da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 3911da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 3921da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 3931da177e4SLinus Torvalds return nfserr_inval; 394ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 395ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 396ca364317SJ.Bruce Fields &create->cr_iattr, S_IFBLK, rdev, &resfh); 3971da177e4SLinus Torvalds break; 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds case NF4CHR: 4001da177e4SLinus Torvalds rdev = MKDEV(create->cr_specdata1, create->cr_specdata2); 4011da177e4SLinus Torvalds if (MAJOR(rdev) != create->cr_specdata1 || 4021da177e4SLinus Torvalds MINOR(rdev) != create->cr_specdata2) 4031da177e4SLinus Torvalds return nfserr_inval; 404ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 405ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 406ca364317SJ.Bruce Fields &create->cr_iattr,S_IFCHR, rdev, &resfh); 4071da177e4SLinus Torvalds break; 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds case NF4SOCK: 410ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 411ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 412ca364317SJ.Bruce Fields &create->cr_iattr, S_IFSOCK, 0, &resfh); 4131da177e4SLinus Torvalds break; 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds case NF4FIFO: 416ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 417ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 418ca364317SJ.Bruce Fields &create->cr_iattr, S_IFIFO, 0, &resfh); 4191da177e4SLinus Torvalds break; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds case NF4DIR: 4221da177e4SLinus Torvalds create->cr_iattr.ia_valid &= ~ATTR_SIZE; 423ca364317SJ.Bruce Fields status = nfsd_create(rqstp, &cstate->current_fh, 424ca364317SJ.Bruce Fields create->cr_name, create->cr_namelen, 425ca364317SJ.Bruce Fields &create->cr_iattr, S_IFDIR, 0, &resfh); 4261da177e4SLinus Torvalds break; 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds default: 4291da177e4SLinus Torvalds status = nfserr_badtype; 4301da177e4SLinus Torvalds } 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds if (!status) { 433ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 434ca364317SJ.Bruce Fields set_change_info(&create->cr_cinfo, &cstate->current_fh); 435ca364317SJ.Bruce Fields fh_dup2(&cstate->current_fh, &resfh); 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds fh_put(&resfh); 4391da177e4SLinus Torvalds return status; 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds 4427191155bSJ.Bruce Fields static __be32 443ca364317SJ.Bruce Fields nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 444ca364317SJ.Bruce Fields struct nfsd4_getattr *getattr) 4451da177e4SLinus Torvalds { 446b37ad28bSAl Viro __be32 status; 4471da177e4SLinus Torvalds 448ca364317SJ.Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, 0, MAY_NOP); 4491da177e4SLinus Torvalds if (status) 4501da177e4SLinus Torvalds return status; 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 4531da177e4SLinus Torvalds return nfserr_inval; 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds getattr->ga_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0; 4561da177e4SLinus Torvalds getattr->ga_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1; 4571da177e4SLinus Torvalds 458ca364317SJ.Bruce Fields getattr->ga_fhp = &cstate->current_fh; 4591da177e4SLinus Torvalds return nfs_ok; 4601da177e4SLinus Torvalds } 4611da177e4SLinus Torvalds 4627191155bSJ.Bruce Fields static __be32 463ca364317SJ.Bruce Fields nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 464ca364317SJ.Bruce Fields struct nfsd4_link *link) 4651da177e4SLinus Torvalds { 466b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 4671da177e4SLinus Torvalds 468ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 4691da177e4SLinus Torvalds return status; 470ca364317SJ.Bruce Fields status = nfsd_link(rqstp, &cstate->current_fh, 471ca364317SJ.Bruce Fields link->li_name, link->li_namelen, &cstate->save_fh); 4721da177e4SLinus Torvalds if (!status) 473ca364317SJ.Bruce Fields set_change_info(&link->li_cinfo, &cstate->current_fh); 4741da177e4SLinus Torvalds return status; 4751da177e4SLinus Torvalds } 4761da177e4SLinus Torvalds 477b37ad28bSAl Viro static __be32 478b591480bSJ.Bruce Fields nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 479b591480bSJ.Bruce Fields void *arg) 4801da177e4SLinus Torvalds { 4811da177e4SLinus Torvalds struct svc_fh tmp_fh; 482b37ad28bSAl Viro __be32 ret; 4831da177e4SLinus Torvalds 4841da177e4SLinus Torvalds fh_init(&tmp_fh, NFS4_FHSIZE); 485df547efbSJ. Bruce Fields ret = exp_pseudoroot(rqstp, &tmp_fh); 486df547efbSJ. Bruce Fields if (ret) 4871da177e4SLinus Torvalds return ret; 488ca364317SJ.Bruce Fields if (tmp_fh.fh_dentry == cstate->current_fh.fh_dentry) { 4891da177e4SLinus Torvalds fh_put(&tmp_fh); 4901da177e4SLinus Torvalds return nfserr_noent; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds fh_put(&tmp_fh); 493ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 494ca364317SJ.Bruce Fields "..", 2, &cstate->current_fh); 4951da177e4SLinus Torvalds } 4961da177e4SLinus Torvalds 4977191155bSJ.Bruce Fields static __be32 498ca364317SJ.Bruce Fields nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 499ca364317SJ.Bruce Fields struct nfsd4_lookup *lookup) 5001da177e4SLinus Torvalds { 501ca364317SJ.Bruce Fields return nfsd_lookup(rqstp, &cstate->current_fh, 502ca364317SJ.Bruce Fields lookup->lo_name, lookup->lo_len, 503ca364317SJ.Bruce Fields &cstate->current_fh); 5041da177e4SLinus Torvalds } 5051da177e4SLinus Torvalds 5067191155bSJ.Bruce Fields static __be32 507ca364317SJ.Bruce Fields nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 508ca364317SJ.Bruce Fields struct nfsd4_read *read) 5091da177e4SLinus Torvalds { 510b37ad28bSAl Viro __be32 status; 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_read() */ 5131da177e4SLinus Torvalds 5147e06b7f9SNeilBrown read->rd_filp = NULL; 5151da177e4SLinus Torvalds if (read->rd_offset >= OFFSET_MAX) 5161da177e4SLinus Torvalds return nfserr_inval; 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds nfs4_lock_state(); 5191da177e4SLinus Torvalds /* check stateid */ 520ca364317SJ.Bruce Fields if ((status = nfs4_preprocess_stateid_op(&cstate->current_fh, 521ca364317SJ.Bruce Fields &read->rd_stateid, 5227e06b7f9SNeilBrown CHECK_FH | RD_STATE, &read->rd_filp))) { 5231da177e4SLinus Torvalds dprintk("NFSD: nfsd4_read: couldn't process stateid!\n"); 5241da177e4SLinus Torvalds goto out; 5251da177e4SLinus Torvalds } 5267e06b7f9SNeilBrown if (read->rd_filp) 5277e06b7f9SNeilBrown get_file(read->rd_filp); 5281da177e4SLinus Torvalds status = nfs_ok; 5291da177e4SLinus Torvalds out: 5301da177e4SLinus Torvalds nfs4_unlock_state(); 5311da177e4SLinus Torvalds read->rd_rqstp = rqstp; 532ca364317SJ.Bruce Fields read->rd_fhp = &cstate->current_fh; 5331da177e4SLinus Torvalds return status; 5341da177e4SLinus Torvalds } 5351da177e4SLinus Torvalds 5367191155bSJ.Bruce Fields static __be32 537ca364317SJ.Bruce Fields nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 538ca364317SJ.Bruce Fields struct nfsd4_readdir *readdir) 5391da177e4SLinus Torvalds { 5401da177e4SLinus Torvalds u64 cookie = readdir->rd_cookie; 5411da177e4SLinus Torvalds static const nfs4_verifier zeroverf; 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_readdir() */ 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1) 5461da177e4SLinus Torvalds return nfserr_inval; 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds readdir->rd_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0; 5491da177e4SLinus Torvalds readdir->rd_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1; 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds if ((cookie > ~(u32)0) || (cookie == 1) || (cookie == 2) || 5521da177e4SLinus Torvalds (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE))) 5531da177e4SLinus Torvalds return nfserr_bad_cookie; 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds readdir->rd_rqstp = rqstp; 556ca364317SJ.Bruce Fields readdir->rd_fhp = &cstate->current_fh; 5571da177e4SLinus Torvalds return nfs_ok; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 5607191155bSJ.Bruce Fields static __be32 561ca364317SJ.Bruce Fields nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 562ca364317SJ.Bruce Fields struct nfsd4_readlink *readlink) 5631da177e4SLinus Torvalds { 5641da177e4SLinus Torvalds readlink->rl_rqstp = rqstp; 565ca364317SJ.Bruce Fields readlink->rl_fhp = &cstate->current_fh; 5661da177e4SLinus Torvalds return nfs_ok; 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 5697191155bSJ.Bruce Fields static __be32 570ca364317SJ.Bruce Fields nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 571ca364317SJ.Bruce Fields struct nfsd4_remove *remove) 5721da177e4SLinus Torvalds { 573b37ad28bSAl Viro __be32 status; 5741da177e4SLinus Torvalds 575c815afc7SNeilBrown if (nfs4_in_grace()) 576c815afc7SNeilBrown return nfserr_grace; 577ca364317SJ.Bruce Fields status = nfsd_unlink(rqstp, &cstate->current_fh, 0, 578ca364317SJ.Bruce Fields remove->rm_name, remove->rm_namelen); 5791da177e4SLinus Torvalds if (status == nfserr_symlink) 5801da177e4SLinus Torvalds return nfserr_notdir; 5811da177e4SLinus Torvalds if (!status) { 582ca364317SJ.Bruce Fields fh_unlock(&cstate->current_fh); 583ca364317SJ.Bruce Fields set_change_info(&remove->rm_cinfo, &cstate->current_fh); 5841da177e4SLinus Torvalds } 5851da177e4SLinus Torvalds return status; 5861da177e4SLinus Torvalds } 5871da177e4SLinus Torvalds 5887191155bSJ.Bruce Fields static __be32 589ca364317SJ.Bruce Fields nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 590ca364317SJ.Bruce Fields struct nfsd4_rename *rename) 5911da177e4SLinus Torvalds { 592b37ad28bSAl Viro __be32 status = nfserr_nofilehandle; 5931da177e4SLinus Torvalds 594ca364317SJ.Bruce Fields if (!cstate->save_fh.fh_dentry) 5951da177e4SLinus Torvalds return status; 596ca364317SJ.Bruce Fields if (nfs4_in_grace() && !(cstate->save_fh.fh_export->ex_flags 597c815afc7SNeilBrown & NFSEXP_NOSUBTREECHECK)) 598c815afc7SNeilBrown return nfserr_grace; 599ca364317SJ.Bruce Fields status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname, 600ca364317SJ.Bruce Fields rename->rn_snamelen, &cstate->current_fh, 6011da177e4SLinus Torvalds rename->rn_tname, rename->rn_tnamelen); 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds /* the underlying filesystem returns different error's than required 6041da177e4SLinus Torvalds * by NFSv4. both save_fh and current_fh have been verified.. */ 6051da177e4SLinus Torvalds if (status == nfserr_isdir) 6061da177e4SLinus Torvalds status = nfserr_exist; 6071da177e4SLinus Torvalds else if ((status == nfserr_notdir) && 608ca364317SJ.Bruce Fields (S_ISDIR(cstate->save_fh.fh_dentry->d_inode->i_mode) && 609ca364317SJ.Bruce Fields S_ISDIR(cstate->current_fh.fh_dentry->d_inode->i_mode))) 6101da177e4SLinus Torvalds status = nfserr_exist; 6111da177e4SLinus Torvalds else if (status == nfserr_symlink) 6121da177e4SLinus Torvalds status = nfserr_notdir; 6131da177e4SLinus Torvalds 6141da177e4SLinus Torvalds if (!status) { 615ca364317SJ.Bruce Fields set_change_info(&rename->rn_sinfo, &cstate->current_fh); 616ca364317SJ.Bruce Fields set_change_info(&rename->rn_tinfo, &cstate->save_fh); 6171da177e4SLinus Torvalds } 6181da177e4SLinus Torvalds return status; 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds 6217191155bSJ.Bruce Fields static __be32 622dcb488a3SAndy Adamson nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 623dcb488a3SAndy Adamson struct nfsd4_secinfo *secinfo) 624dcb488a3SAndy Adamson { 625dcb488a3SAndy Adamson struct svc_fh resfh; 626dcb488a3SAndy Adamson struct svc_export *exp; 627dcb488a3SAndy Adamson struct dentry *dentry; 628dcb488a3SAndy Adamson __be32 err; 629dcb488a3SAndy Adamson 630dcb488a3SAndy Adamson fh_init(&resfh, NFS4_FHSIZE); 631dcb488a3SAndy Adamson err = nfsd_lookup_dentry(rqstp, &cstate->current_fh, 632dcb488a3SAndy Adamson secinfo->si_name, secinfo->si_namelen, 633dcb488a3SAndy Adamson &exp, &dentry); 634dcb488a3SAndy Adamson if (err) 635dcb488a3SAndy Adamson return err; 636dcb488a3SAndy Adamson if (dentry->d_inode == NULL) { 637dcb488a3SAndy Adamson exp_put(exp); 638dcb488a3SAndy Adamson err = nfserr_noent; 639dcb488a3SAndy Adamson } else 640dcb488a3SAndy Adamson secinfo->si_exp = exp; 641dcb488a3SAndy Adamson dput(dentry); 642dcb488a3SAndy Adamson return err; 643dcb488a3SAndy Adamson } 644dcb488a3SAndy Adamson 645dcb488a3SAndy Adamson static __be32 646ca364317SJ.Bruce Fields nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 647ca364317SJ.Bruce Fields struct nfsd4_setattr *setattr) 6481da177e4SLinus Torvalds { 649b37ad28bSAl Viro __be32 status = nfs_ok; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds if (setattr->sa_iattr.ia_valid & ATTR_SIZE) { 6521da177e4SLinus Torvalds nfs4_lock_state(); 653ca364317SJ.Bruce Fields status = nfs4_preprocess_stateid_op(&cstate->current_fh, 654375c5547SJ. Bruce Fields &setattr->sa_stateid, CHECK_FH | WR_STATE, NULL); 6551da177e4SLinus Torvalds nfs4_unlock_state(); 656375c5547SJ. Bruce Fields if (status) { 6573e3b4800SGreg Banks dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n"); 658375c5547SJ. Bruce Fields return status; 659375c5547SJ. Bruce Fields } 6601da177e4SLinus Torvalds } 661*18f335afSDave Hansen status = mnt_want_write(cstate->current_fh.fh_export->ex_path.mnt); 662*18f335afSDave Hansen if (status) 663*18f335afSDave Hansen return status; 6641da177e4SLinus Torvalds status = nfs_ok; 6651da177e4SLinus Torvalds if (setattr->sa_acl != NULL) 666ca364317SJ.Bruce Fields status = nfsd4_set_nfs4_acl(rqstp, &cstate->current_fh, 667ca364317SJ.Bruce Fields setattr->sa_acl); 6681da177e4SLinus Torvalds if (status) 669*18f335afSDave Hansen goto out; 670ca364317SJ.Bruce Fields status = nfsd_setattr(rqstp, &cstate->current_fh, &setattr->sa_iattr, 6711da177e4SLinus Torvalds 0, (time_t)0); 672*18f335afSDave Hansen out: 673*18f335afSDave Hansen mnt_drop_write(cstate->current_fh.fh_export->ex_path.mnt); 6741da177e4SLinus Torvalds return status; 6751da177e4SLinus Torvalds } 6761da177e4SLinus Torvalds 6777191155bSJ.Bruce Fields static __be32 678ca364317SJ.Bruce Fields nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 679ca364317SJ.Bruce Fields struct nfsd4_write *write) 6801da177e4SLinus Torvalds { 6811da177e4SLinus Torvalds stateid_t *stateid = &write->wr_stateid; 6821da177e4SLinus Torvalds struct file *filp = NULL; 6831da177e4SLinus Torvalds u32 *p; 684b37ad28bSAl Viro __be32 status = nfs_ok; 6851da177e4SLinus Torvalds 6861da177e4SLinus Torvalds /* no need to check permission - this will be done in nfsd_write() */ 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds if (write->wr_offset >= OFFSET_MAX) 6891da177e4SLinus Torvalds return nfserr_inval; 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds nfs4_lock_state(); 692ca364317SJ.Bruce Fields status = nfs4_preprocess_stateid_op(&cstate->current_fh, stateid, 693375c5547SJ. Bruce Fields CHECK_FH | WR_STATE, &filp); 6947e06b7f9SNeilBrown if (filp) 6957e06b7f9SNeilBrown get_file(filp); 6961da177e4SLinus Torvalds nfs4_unlock_state(); 6971da177e4SLinus Torvalds 698375c5547SJ. Bruce Fields if (status) { 699375c5547SJ. Bruce Fields dprintk("NFSD: nfsd4_write: couldn't process stateid!\n"); 700375c5547SJ. Bruce Fields return status; 701375c5547SJ. Bruce Fields } 702375c5547SJ. Bruce Fields 7031da177e4SLinus Torvalds write->wr_bytes_written = write->wr_buflen; 7041da177e4SLinus Torvalds write->wr_how_written = write->wr_stable_how; 7051da177e4SLinus Torvalds p = (u32 *)write->wr_verifier.data; 7061da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_sec; 7071da177e4SLinus Torvalds *p++ = nfssvc_boot.tv_usec; 7081da177e4SLinus Torvalds 709ca364317SJ.Bruce Fields status = nfsd_write(rqstp, &cstate->current_fh, filp, 710ca364317SJ.Bruce Fields write->wr_offset, rqstp->rq_vec, write->wr_vlen, 711ca364317SJ.Bruce Fields write->wr_buflen, &write->wr_how_written); 7127e06b7f9SNeilBrown if (filp) 7137e06b7f9SNeilBrown fput(filp); 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds if (status == nfserr_symlink) 7161da177e4SLinus Torvalds status = nfserr_inval; 7171da177e4SLinus Torvalds return status; 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds /* This routine never returns NFS_OK! If there are no other errors, it 7211da177e4SLinus Torvalds * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the 7221da177e4SLinus Torvalds * attributes matched. VERIFY is implemented by mapping NFSERR_SAME 7231da177e4SLinus Torvalds * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK. 7241da177e4SLinus Torvalds */ 725b37ad28bSAl Viro static __be32 726c954e2a5SJ.Bruce Fields _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 727ca364317SJ.Bruce Fields struct nfsd4_verify *verify) 7281da177e4SLinus Torvalds { 7292ebbc012SAl Viro __be32 *buf, *p; 7301da177e4SLinus Torvalds int count; 731b37ad28bSAl Viro __be32 status; 7321da177e4SLinus Torvalds 733ca364317SJ.Bruce Fields status = fh_verify(rqstp, &cstate->current_fh, 0, MAY_NOP); 7341da177e4SLinus Torvalds if (status) 7351da177e4SLinus Torvalds return status; 7361da177e4SLinus Torvalds 7371da177e4SLinus Torvalds if ((verify->ve_bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0) 7381da177e4SLinus Torvalds || (verify->ve_bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1)) 7391da177e4SLinus Torvalds return nfserr_attrnotsupp; 7401da177e4SLinus Torvalds if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR) 7411da177e4SLinus Torvalds || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)) 7421da177e4SLinus Torvalds return nfserr_inval; 7431da177e4SLinus Torvalds if (verify->ve_attrlen & 3) 7441da177e4SLinus Torvalds return nfserr_inval; 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds /* count in words: 7471da177e4SLinus Torvalds * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 7481da177e4SLinus Torvalds */ 7491da177e4SLinus Torvalds count = 4 + (verify->ve_attrlen >> 2); 7501da177e4SLinus Torvalds buf = kmalloc(count << 2, GFP_KERNEL); 7511da177e4SLinus Torvalds if (!buf) 7521da177e4SLinus Torvalds return nfserr_resource; 7531da177e4SLinus Torvalds 754ca364317SJ.Bruce Fields status = nfsd4_encode_fattr(&cstate->current_fh, 755ca364317SJ.Bruce Fields cstate->current_fh.fh_export, 756ca364317SJ.Bruce Fields cstate->current_fh.fh_dentry, buf, 7571da177e4SLinus Torvalds &count, verify->ve_bmval, 758406a7ea9SFrank Filz rqstp, 0); 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds /* this means that nfsd4_encode_fattr() ran out of space */ 7611da177e4SLinus Torvalds if (status == nfserr_resource && count == 0) 7621da177e4SLinus Torvalds status = nfserr_not_same; 7631da177e4SLinus Torvalds if (status) 7641da177e4SLinus Torvalds goto out_kfree; 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds p = buf + 3; 7671da177e4SLinus Torvalds status = nfserr_not_same; 7681da177e4SLinus Torvalds if (ntohl(*p++) != verify->ve_attrlen) 7691da177e4SLinus Torvalds goto out_kfree; 7701da177e4SLinus Torvalds if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen)) 7711da177e4SLinus Torvalds status = nfserr_same; 7721da177e4SLinus Torvalds 7731da177e4SLinus Torvalds out_kfree: 7741da177e4SLinus Torvalds kfree(buf); 7751da177e4SLinus Torvalds return status; 7761da177e4SLinus Torvalds } 7771da177e4SLinus Torvalds 778c954e2a5SJ.Bruce Fields static __be32 779c954e2a5SJ.Bruce Fields nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 780c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 781c954e2a5SJ.Bruce Fields { 782c954e2a5SJ.Bruce Fields __be32 status; 783c954e2a5SJ.Bruce Fields 784c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 785c954e2a5SJ.Bruce Fields return status == nfserr_not_same ? nfs_ok : status; 786c954e2a5SJ.Bruce Fields } 787c954e2a5SJ.Bruce Fields 788c954e2a5SJ.Bruce Fields static __be32 789c954e2a5SJ.Bruce Fields nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 790c954e2a5SJ.Bruce Fields struct nfsd4_verify *verify) 791c954e2a5SJ.Bruce Fields { 792c954e2a5SJ.Bruce Fields __be32 status; 793c954e2a5SJ.Bruce Fields 794c954e2a5SJ.Bruce Fields status = _nfsd4_verify(rqstp, cstate, verify); 795c954e2a5SJ.Bruce Fields return status == nfserr_same ? nfs_ok : status; 796c954e2a5SJ.Bruce Fields } 797c954e2a5SJ.Bruce Fields 7981da177e4SLinus Torvalds /* 7991da177e4SLinus Torvalds * NULL call. 8001da177e4SLinus Torvalds */ 8017111c66eSAl Viro static __be32 8021da177e4SLinus Torvalds nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) 8031da177e4SLinus Torvalds { 8041da177e4SLinus Torvalds return nfs_ok; 8051da177e4SLinus Torvalds } 8061da177e4SLinus Torvalds 807e2b20950SShankar Anand static inline void nfsd4_increment_op_stats(u32 opnum) 808e2b20950SShankar Anand { 809e2b20950SShankar Anand if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP) 810e2b20950SShankar Anand nfsdstats.nfs4_opcount[opnum]++; 811e2b20950SShankar Anand } 812e2b20950SShankar Anand 813ca364317SJ.Bruce Fields static void cstate_free(struct nfsd4_compound_state *cstate) 814ca364317SJ.Bruce Fields { 815ca364317SJ.Bruce Fields if (cstate == NULL) 816ca364317SJ.Bruce Fields return; 817ca364317SJ.Bruce Fields fh_put(&cstate->current_fh); 818ca364317SJ.Bruce Fields fh_put(&cstate->save_fh); 819a4f1706aSJ.Bruce Fields BUG_ON(cstate->replay_owner); 820ca364317SJ.Bruce Fields kfree(cstate); 821ca364317SJ.Bruce Fields } 822ca364317SJ.Bruce Fields 823ca364317SJ.Bruce Fields static struct nfsd4_compound_state *cstate_alloc(void) 824ca364317SJ.Bruce Fields { 825ca364317SJ.Bruce Fields struct nfsd4_compound_state *cstate; 826ca364317SJ.Bruce Fields 827ca364317SJ.Bruce Fields cstate = kmalloc(sizeof(struct nfsd4_compound_state), GFP_KERNEL); 828ca364317SJ.Bruce Fields if (cstate == NULL) 829ca364317SJ.Bruce Fields return NULL; 830ca364317SJ.Bruce Fields fh_init(&cstate->current_fh, NFS4_FHSIZE); 831ca364317SJ.Bruce Fields fh_init(&cstate->save_fh, NFS4_FHSIZE); 832a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 833ca364317SJ.Bruce Fields return cstate; 834ca364317SJ.Bruce Fields } 8351da177e4SLinus Torvalds 836b591480bSJ.Bruce Fields typedef __be32(*nfsd4op_func)(struct svc_rqst *, struct nfsd4_compound_state *, 837b591480bSJ.Bruce Fields void *); 838b591480bSJ.Bruce Fields 839b591480bSJ.Bruce Fields struct nfsd4_operation { 840b591480bSJ.Bruce Fields nfsd4op_func op_func; 841b591480bSJ.Bruce Fields u32 op_flags; 84227d630ecSJ.Bruce Fields /* Most ops require a valid current filehandle; a few don't: */ 84327d630ecSJ.Bruce Fields #define ALLOWED_WITHOUT_FH 1 844eeac294eSJ.Bruce Fields /* GETATTR and ops not listed as returning NFS4ERR_MOVED: */ 84527d630ecSJ.Bruce Fields #define ALLOWED_ON_ABSENT_FS 2 846b591480bSJ.Bruce Fields }; 847b591480bSJ.Bruce Fields 848b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[]; 849b591480bSJ.Bruce Fields 8501da177e4SLinus Torvalds /* 8511da177e4SLinus Torvalds * COMPOUND call. 8521da177e4SLinus Torvalds */ 8537111c66eSAl Viro static __be32 8541da177e4SLinus Torvalds nfsd4_proc_compound(struct svc_rqst *rqstp, 8551da177e4SLinus Torvalds struct nfsd4_compoundargs *args, 8561da177e4SLinus Torvalds struct nfsd4_compoundres *resp) 8571da177e4SLinus Torvalds { 8581da177e4SLinus Torvalds struct nfsd4_op *op; 859b591480bSJ.Bruce Fields struct nfsd4_operation *opdesc; 860ca364317SJ.Bruce Fields struct nfsd4_compound_state *cstate = NULL; 861e5710199SJ.Bruce Fields int slack_bytes; 862b37ad28bSAl Viro __be32 status; 8631da177e4SLinus Torvalds 8641da177e4SLinus Torvalds status = nfserr_resource; 865ca364317SJ.Bruce Fields cstate = cstate_alloc(); 866ca364317SJ.Bruce Fields if (cstate == NULL) 8671da177e4SLinus Torvalds goto out; 8681da177e4SLinus Torvalds 8691da177e4SLinus Torvalds resp->xbuf = &rqstp->rq_res; 8701da177e4SLinus Torvalds resp->p = rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len; 8711da177e4SLinus Torvalds resp->tagp = resp->p; 8721da177e4SLinus Torvalds /* reserve space for: taglen, tag, and opcnt */ 8731da177e4SLinus Torvalds resp->p += 2 + XDR_QUADLEN(args->taglen); 8741da177e4SLinus Torvalds resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE; 8751da177e4SLinus Torvalds resp->taglen = args->taglen; 8761da177e4SLinus Torvalds resp->tag = args->tag; 8771da177e4SLinus Torvalds resp->opcnt = 0; 8781da177e4SLinus Torvalds resp->rqstp = rqstp; 8791da177e4SLinus Torvalds 8801da177e4SLinus Torvalds /* 8811da177e4SLinus Torvalds * According to RFC3010, this takes precedence over all other errors. 8821da177e4SLinus Torvalds */ 8831da177e4SLinus Torvalds status = nfserr_minor_vers_mismatch; 8841da177e4SLinus Torvalds if (args->minorversion > NFSD_SUPPORTED_MINOR_VERSION) 8851da177e4SLinus Torvalds goto out; 8861da177e4SLinus Torvalds 8871da177e4SLinus Torvalds status = nfs_ok; 8881da177e4SLinus Torvalds while (!status && resp->opcnt < args->opcnt) { 8891da177e4SLinus Torvalds op = &args->ops[resp->opcnt++]; 8901da177e4SLinus Torvalds 891fd445277SJ. Bruce Fields dprintk("nfsv4 compound op #%d: %d\n", resp->opcnt, op->opnum); 892fd445277SJ. Bruce Fields 8931da177e4SLinus Torvalds /* 8941da177e4SLinus Torvalds * The XDR decode routines may have pre-set op->status; 8951da177e4SLinus Torvalds * for example, if there is a miscellaneous XDR error 8961da177e4SLinus Torvalds * it will be set to nfserr_bad_xdr. 8971da177e4SLinus Torvalds */ 8981da177e4SLinus Torvalds if (op->status) 8991da177e4SLinus Torvalds goto encode_op; 9001da177e4SLinus Torvalds 9011da177e4SLinus Torvalds /* We must be able to encode a successful response to 9021da177e4SLinus Torvalds * this operation, with enough room left over to encode a 9031da177e4SLinus Torvalds * failed response to the next operation. If we don't 9041da177e4SLinus Torvalds * have enough room, fail with ERR_RESOURCE. 9051da177e4SLinus Torvalds */ 906e5710199SJ.Bruce Fields slack_bytes = (char *)resp->end - (char *)resp->p; 907e5710199SJ.Bruce Fields if (slack_bytes < COMPOUND_SLACK_SPACE 908e5710199SJ.Bruce Fields + COMPOUND_ERR_SLACK_SPACE) { 909e5710199SJ.Bruce Fields BUG_ON(slack_bytes < COMPOUND_ERR_SLACK_SPACE); 9101da177e4SLinus Torvalds op->status = nfserr_resource; 9111da177e4SLinus Torvalds goto encode_op; 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds 914b591480bSJ.Bruce Fields opdesc = &nfsd4_ops[op->opnum]; 915b591480bSJ.Bruce Fields 916ca364317SJ.Bruce Fields if (!cstate->current_fh.fh_dentry) { 91727d630ecSJ.Bruce Fields if (!(opdesc->op_flags & ALLOWED_WITHOUT_FH)) { 9181da177e4SLinus Torvalds op->status = nfserr_nofilehandle; 9191da177e4SLinus Torvalds goto encode_op; 9201da177e4SLinus Torvalds } 921eeac294eSJ.Bruce Fields } else if (cstate->current_fh.fh_export->ex_fslocs.migrated && 922eeac294eSJ.Bruce Fields !(opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) { 92342ca0993SJ.Bruce Fields op->status = nfserr_moved; 92442ca0993SJ.Bruce Fields goto encode_op; 92542ca0993SJ.Bruce Fields } 926b591480bSJ.Bruce Fields 927b591480bSJ.Bruce Fields if (opdesc->op_func) 928b591480bSJ.Bruce Fields op->status = opdesc->op_func(rqstp, cstate, &op->u); 929b591480bSJ.Bruce Fields else 9301da177e4SLinus Torvalds BUG_ON(op->status == nfs_ok); 9311da177e4SLinus Torvalds 9321da177e4SLinus Torvalds encode_op: 933a90b061cSAl Viro if (op->status == nfserr_replay_me) { 934a4f1706aSJ.Bruce Fields op->replay = &cstate->replay_owner->so_replay; 9351da177e4SLinus Torvalds nfsd4_encode_replay(resp, op); 9361da177e4SLinus Torvalds status = op->status = op->replay->rp_status; 9371da177e4SLinus Torvalds } else { 9381da177e4SLinus Torvalds nfsd4_encode_operation(resp, op); 9391da177e4SLinus Torvalds status = op->status; 9401da177e4SLinus Torvalds } 941a4f1706aSJ.Bruce Fields if (cstate->replay_owner) { 942a4f1706aSJ.Bruce Fields nfs4_put_stateowner(cstate->replay_owner); 943a4f1706aSJ.Bruce Fields cstate->replay_owner = NULL; 9441da177e4SLinus Torvalds } 9457e06b7f9SNeilBrown /* XXX Ugh, we need to get rid of this kind of special case: */ 9467e06b7f9SNeilBrown if (op->opnum == OP_READ && op->u.read.rd_filp) 9477e06b7f9SNeilBrown fput(op->u.read.rd_filp); 948e2b20950SShankar Anand 949e2b20950SShankar Anand nfsd4_increment_op_stats(op->opnum); 9501da177e4SLinus Torvalds } 9511da177e4SLinus Torvalds 9521da177e4SLinus Torvalds out: 9531da177e4SLinus Torvalds nfsd4_release_compoundargs(args); 954ca364317SJ.Bruce Fields cstate_free(cstate); 9551da177e4SLinus Torvalds return status; 9561da177e4SLinus Torvalds } 9571da177e4SLinus Torvalds 958b591480bSJ.Bruce Fields static struct nfsd4_operation nfsd4_ops[OP_RELEASE_LOCKOWNER+1] = { 959b591480bSJ.Bruce Fields [OP_ACCESS] = { 960b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_access, 961b591480bSJ.Bruce Fields }, 962b591480bSJ.Bruce Fields [OP_CLOSE] = { 963b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_close, 964b591480bSJ.Bruce Fields }, 965b591480bSJ.Bruce Fields [OP_COMMIT] = { 966b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_commit, 967b591480bSJ.Bruce Fields }, 968b591480bSJ.Bruce Fields [OP_CREATE] = { 969b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_create, 970b591480bSJ.Bruce Fields }, 971b591480bSJ.Bruce Fields [OP_DELEGRETURN] = { 972b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_delegreturn, 973b591480bSJ.Bruce Fields }, 974b591480bSJ.Bruce Fields [OP_GETATTR] = { 975b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getattr, 976eeac294eSJ.Bruce Fields .op_flags = ALLOWED_ON_ABSENT_FS, 977b591480bSJ.Bruce Fields }, 978b591480bSJ.Bruce Fields [OP_GETFH] = { 979b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_getfh, 980b591480bSJ.Bruce Fields }, 981b591480bSJ.Bruce Fields [OP_LINK] = { 982b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_link, 983b591480bSJ.Bruce Fields }, 984b591480bSJ.Bruce Fields [OP_LOCK] = { 985b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lock, 986b591480bSJ.Bruce Fields }, 987b591480bSJ.Bruce Fields [OP_LOCKT] = { 988b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lockt, 989b591480bSJ.Bruce Fields }, 990b591480bSJ.Bruce Fields [OP_LOCKU] = { 991b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_locku, 992b591480bSJ.Bruce Fields }, 993b591480bSJ.Bruce Fields [OP_LOOKUP] = { 994b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookup, 995b591480bSJ.Bruce Fields }, 996b591480bSJ.Bruce Fields [OP_LOOKUPP] = { 997b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_lookupp, 998b591480bSJ.Bruce Fields }, 999b591480bSJ.Bruce Fields [OP_NVERIFY] = { 1000b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_nverify, 1001b591480bSJ.Bruce Fields }, 1002b591480bSJ.Bruce Fields [OP_OPEN] = { 1003b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open, 1004b591480bSJ.Bruce Fields }, 1005b591480bSJ.Bruce Fields [OP_OPEN_CONFIRM] = { 1006b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_confirm, 1007b591480bSJ.Bruce Fields }, 1008b591480bSJ.Bruce Fields [OP_OPEN_DOWNGRADE] = { 1009b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_open_downgrade, 1010b591480bSJ.Bruce Fields }, 1011b591480bSJ.Bruce Fields [OP_PUTFH] = { 1012b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putfh, 101327d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1014b591480bSJ.Bruce Fields }, 1015eeac294eSJ.Bruce Fields [OP_PUTPUBFH] = { 1016eeac294eSJ.Bruce Fields /* unsupported; just for future reference: */ 101727d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1018eeac294eSJ.Bruce Fields }, 1019b591480bSJ.Bruce Fields [OP_PUTROOTFH] = { 1020b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_putrootfh, 102127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1022b591480bSJ.Bruce Fields }, 1023b591480bSJ.Bruce Fields [OP_READ] = { 1024b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_read, 1025b591480bSJ.Bruce Fields }, 1026b591480bSJ.Bruce Fields [OP_READDIR] = { 1027b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readdir, 1028b591480bSJ.Bruce Fields }, 1029b591480bSJ.Bruce Fields [OP_READLINK] = { 1030b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_readlink, 1031b591480bSJ.Bruce Fields }, 1032b591480bSJ.Bruce Fields [OP_REMOVE] = { 1033b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_remove, 1034b591480bSJ.Bruce Fields }, 1035b591480bSJ.Bruce Fields [OP_RENAME] = { 1036b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_rename, 1037b591480bSJ.Bruce Fields }, 1038b591480bSJ.Bruce Fields [OP_RENEW] = { 1039b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_renew, 104027d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1041b591480bSJ.Bruce Fields }, 1042b591480bSJ.Bruce Fields [OP_RESTOREFH] = { 1043b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_restorefh, 104427d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1045b591480bSJ.Bruce Fields }, 1046b591480bSJ.Bruce Fields [OP_SAVEFH] = { 1047b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_savefh, 1048b591480bSJ.Bruce Fields }, 1049dcb488a3SAndy Adamson [OP_SECINFO] = { 1050dcb488a3SAndy Adamson .op_func = (nfsd4op_func)nfsd4_secinfo, 1051dcb488a3SAndy Adamson }, 1052b591480bSJ.Bruce Fields [OP_SETATTR] = { 1053b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setattr, 1054b591480bSJ.Bruce Fields }, 1055b591480bSJ.Bruce Fields [OP_SETCLIENTID] = { 1056b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid, 105727d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1058b591480bSJ.Bruce Fields }, 1059b591480bSJ.Bruce Fields [OP_SETCLIENTID_CONFIRM] = { 1060b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_setclientid_confirm, 106127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1062b591480bSJ.Bruce Fields }, 1063b591480bSJ.Bruce Fields [OP_VERIFY] = { 1064b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_verify, 1065b591480bSJ.Bruce Fields }, 1066b591480bSJ.Bruce Fields [OP_WRITE] = { 1067b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_write, 1068b591480bSJ.Bruce Fields }, 1069b591480bSJ.Bruce Fields [OP_RELEASE_LOCKOWNER] = { 1070b591480bSJ.Bruce Fields .op_func = (nfsd4op_func)nfsd4_release_lockowner, 107127d630ecSJ.Bruce Fields .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS, 1072b591480bSJ.Bruce Fields }, 1073b591480bSJ.Bruce Fields }; 1074b591480bSJ.Bruce Fields 10751da177e4SLinus Torvalds #define nfs4svc_decode_voidargs NULL 10761da177e4SLinus Torvalds #define nfs4svc_release_void NULL 10771da177e4SLinus Torvalds #define nfsd4_voidres nfsd4_voidargs 10781da177e4SLinus Torvalds #define nfs4svc_release_compound NULL 10791da177e4SLinus Torvalds struct nfsd4_voidargs { int dummy; }; 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds #define PROC(name, argt, rest, relt, cache, respsize) \ 10821da177e4SLinus Torvalds { (svc_procfunc) nfsd4_proc_##name, \ 10831da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_decode_##argt##args, \ 10841da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_encode_##rest##res, \ 10851da177e4SLinus Torvalds (kxdrproc_t) nfs4svc_release_##relt, \ 10861da177e4SLinus Torvalds sizeof(struct nfsd4_##argt##args), \ 10871da177e4SLinus Torvalds sizeof(struct nfsd4_##rest##res), \ 10881da177e4SLinus Torvalds 0, \ 10891da177e4SLinus Torvalds cache, \ 10901da177e4SLinus Torvalds respsize, \ 10911da177e4SLinus Torvalds } 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvalds /* 10941da177e4SLinus Torvalds * TODO: At the present time, the NFSv4 server does not do XID caching 10951da177e4SLinus Torvalds * of requests. Implementing XID caching would not be a serious problem, 10961da177e4SLinus Torvalds * although it would require a mild change in interfaces since one 10971da177e4SLinus Torvalds * doesn't know whether an NFSv4 request is idempotent until after the 10981da177e4SLinus Torvalds * XDR decode. However, XID caching totally confuses pynfs (Peter 10991da177e4SLinus Torvalds * Astrand's regression testsuite for NFSv4 servers), which reuses 11001da177e4SLinus Torvalds * XID's liberally, so I've left it unimplemented until pynfs generates 11011da177e4SLinus Torvalds * better XID's. 11021da177e4SLinus Torvalds */ 11031da177e4SLinus Torvalds static struct svc_procedure nfsd_procedures4[2] = { 11041da177e4SLinus Torvalds PROC(null, void, void, void, RC_NOCACHE, 1), 11057775f4c8SNeilBrown PROC(compound, compound, compound, compound, RC_NOCACHE, NFSD_BUFSIZE/4) 11061da177e4SLinus Torvalds }; 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvalds struct svc_version nfsd_version4 = { 11091da177e4SLinus Torvalds .vs_vers = 4, 11101da177e4SLinus Torvalds .vs_nproc = 2, 11111da177e4SLinus Torvalds .vs_proc = nfsd_procedures4, 11121da177e4SLinus Torvalds .vs_dispatch = nfsd_dispatch, 11131da177e4SLinus Torvalds .vs_xdrsize = NFS4_SVC_XDRSIZE, 11141da177e4SLinus Torvalds }; 11151da177e4SLinus Torvalds 11161da177e4SLinus Torvalds /* 11171da177e4SLinus Torvalds * Local variables: 11181da177e4SLinus Torvalds * c-basic-offset: 8 11191da177e4SLinus Torvalds * End: 11201da177e4SLinus Torvalds */ 1121