^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Process version 2 NFS requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "cache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "xdr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "vfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define NFSDDBG_FACILITY NFSDDBG_PROC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) nfsd_proc_null(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Get a file's attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) nfsd_proc_getattr(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct nfsd_fhandle *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) resp->status = fh_verify(rqstp, &resp->fh, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Set a file's attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) nfsd_proc_setattr(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct nfsd_sattrargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct iattr *iap = &argp->attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct svc_fh *fhp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) argp->attrs.ia_valid, (long) argp->attrs.ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) fhp = fh_copy(&resp->fh, &argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * NFSv2 does not differentiate between "set-[ac]time-to-now"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * which only requires access, and "set-[ac]time-to-X" which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * requires ownership.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * So if it looks like it might be "set both to the same time which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * is close to now", and if setattr_prepare fails, then we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * convert to "set to now" instead of "set to explicit time"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * We only call setattr_prepare as the last test as technically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * it is not an interface that we should be using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define MAX_TOUCH_TIME_ERROR (30*60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Looks probable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Now just make sure time is in the right ballpark.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Solaris, at least, doesn't seem to care what the time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * request is. We require it be within 30 minutes of now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) time64_t delta = iap->ia_atime.tv_sec - ktime_get_real_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) resp->status = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (delta < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) delta = -delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (delta < MAX_TOUCH_TIME_ERROR &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) setattr_prepare(fhp->fh_dentry, iap) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * This will cause notify_change to set these times
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * to "now"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) iap->ia_valid &= ~BOTH_TIME_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) resp->status = nfsd_setattr(rqstp, fhp, iap, 0, (time64_t)0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Obsolete, replaced by MNTPROC_MNT. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) nfsd_proc_root(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * Look up a path name component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Note: the dentry in the resp->fh may be negative if the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * doesn't exist yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) nfsd_proc_lookup(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct nfsd_diropargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct nfsd_diropres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) dprintk("nfsd: LOOKUP %s %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) SVCFH_fmt(&argp->fh), argp->len, argp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) fh_init(&resp->fh, NFS_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) resp->status = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) &resp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * Read a symlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) nfsd_proc_readlink(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct nfsd_readlinkargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct nfsd_readlinkres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* Read the symlink. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) resp->len = NFS_MAXPATHLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) resp->status = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * Read a portion of a file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) nfsd_proc_read(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct nfsd_readargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct nfsd_readres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u32 eof;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) dprintk("nfsd: READ %s %d bytes at %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) argp->count, argp->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Obtain buffer pointer for payload. 19 is 1 word for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * status, 17 words for fattr, and 1 word for the byte count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) char buf[RPC_MAX_ADDRBUFLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) printk(KERN_NOTICE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) "oversized read request from %s (%d bytes)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) svc_print_addr(rqstp, buf, sizeof(buf)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) argp->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) argp->count = NFSSVC_MAXBLKSIZE_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) resp->count = argp->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) resp->status = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) argp->offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rqstp->rq_vec, argp->vlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) &resp->count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) &eof);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (resp->status == nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) else if (resp->status == nfserr_jukebox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return rpc_drop_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Reserved */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) nfsd_proc_writecache(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * Write data to a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) nfsd_proc_write(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct nfsd_writeargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct nfsd_attrstat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long cnt = argp->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) unsigned int nvecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) dprintk("nfsd: WRITE %s %u bytes at %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) argp->len, argp->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) &argp->first, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (!nvecs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) resp->status = nfserr_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) resp->status = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) argp->offset, rqstp->rq_vec, nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) &cnt, NFS_DATA_SYNC, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (resp->status == nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) else if (resp->status == nfserr_jukebox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return rpc_drop_reply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * CREATE processing is complicated. The keyword here is `overloaded.'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * The parent directory is kept locked between the check for existence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * and the actual create() call in compliance with VFS protocols.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) nfsd_proc_create(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) struct nfsd_createargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct nfsd_diropres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) svc_fh *dirfhp = &argp->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) svc_fh *newfhp = &resp->fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct iattr *attr = &argp->attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct dentry *dchild;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) int type, mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int hosterr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) dprintk("nfsd: CREATE %s %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) SVCFH_fmt(dirfhp), argp->len, argp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* First verify the parent file handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) resp->status = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) goto done; /* must fh_put dirfhp even on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) resp->status = nfserr_exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (isdotent(argp->name, argp->len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) hosterr = fh_want_write(dirfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (hosterr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) resp->status = nfserrno(hosterr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) fh_lock_nested(dirfhp, I_MUTEX_PARENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (IS_ERR(dchild)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) resp->status = nfserrno(PTR_ERR(dchild));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) fh_init(newfhp, NFS_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) resp->status = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (!resp->status && d_really_is_negative(dchild))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) resp->status = nfserr_noent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) dput(dchild);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (resp->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (resp->status != nfserr_noent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * If the new file handle wasn't verified, we can't tell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * whether the file exists or not. Time to bail ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) resp->status = nfserr_acces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if (!newfhp->fh_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) "nfsd_proc_create: file handle not verified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) inode = d_inode(newfhp->fh_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Unfudge the mode bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (attr->ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) type = attr->ia_mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) mode = attr->ia_mode & ~S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (!type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* no type, so if target exists, assume same as that,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * else assume a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) type = inode->i_mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) switch(type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) /* reserve rdev for later checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) rdev = inode->i_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) attr->ia_valid |= ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /* this is probably a permission check..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * at least IRIX implements perm checking on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * echo thing > device-special-file-or-pipe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * by doing a CREATE with type==0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) resp->status = nfsd_permission(rqstp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) newfhp->fh_export,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) newfhp->fh_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (resp->status && resp->status != nfserr_rofs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) type = S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) } else if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) type = inode->i_mode & S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mode = inode->i_mode & ~S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) type = S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) mode = 0; /* ??? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) attr->ia_valid |= ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) attr->ia_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /* Special treatment for non-regular files according to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * gospel of sun micro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (type != S_IFREG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (type != S_IFBLK && type != S_IFCHR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* If you think you've seen the worst, grok this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) type = S_IFIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* Okay, char or block special */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (!rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) rdev = wanted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* we've used the SIZE information, so discard it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) attr->ia_valid &= ~ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) /* Make sure the type and device matches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) resp->status = nfserr_exist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (inode && inode_wrong_type(inode, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) resp->status = nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /* File doesn't exist. Create it and set attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) resp->status = nfsd_create_locked(rqstp, dirfhp, argp->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) argp->len, attr, type, rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) newfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) } else if (type == S_IFREG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) argp->name, attr->ia_valid, (long) attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* File already exists. We ignore all attributes except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * size, so that creat() behaves exactly like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * open(..., O_CREAT|O_TRUNC|O_WRONLY).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) attr->ia_valid &= ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (attr->ia_valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) resp->status = nfsd_setattr(rqstp, newfhp, attr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) (time64_t)0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* We don't really need to unlock, as fh_put does it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) fh_unlock(dirfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) fh_drop_write(dirfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) fh_put(dirfhp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) nfsd_proc_remove(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct nfsd_diropargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct nfsd_stat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) argp->len, argp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Unlink. -SIFDIR means file must not be a directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) resp->status = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) argp->name, argp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) nfsd_proc_rename(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct nfsd_renameargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct nfsd_stat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) dprintk("nfsd: RENAME %s %.*s -> \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) dprintk("nfsd: -> %s %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) resp->status = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) &argp->tfh, argp->tname, argp->tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) fh_put(&argp->ffh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) fh_put(&argp->tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) nfsd_proc_link(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct nfsd_linkargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) struct nfsd_stat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) dprintk("nfsd: LINK %s ->\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) SVCFH_fmt(&argp->ffh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) dprintk("nfsd: %s %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) SVCFH_fmt(&argp->tfh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) argp->tlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) argp->tname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) resp->status = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) &argp->ffh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) fh_put(&argp->ffh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) fh_put(&argp->tfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) nfsd_proc_symlink(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct nfsd_symlinkargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) struct nfsd_stat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) struct svc_fh newfh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (argp->tlen > NFS_MAXPATHLEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) resp->status = nfserr_nametoolong;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) argp->tname = svc_fill_symlink_pathname(rqstp, &argp->first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) page_address(rqstp->rq_arg.pages[0]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) argp->tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (IS_ERR(argp->tname)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) resp->status = nfserrno(PTR_ERR(argp->tname));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) argp->tlen, argp->tname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) fh_init(&newfh, NFS_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) resp->status = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) argp->tname, &newfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) kfree(argp->tname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) fh_put(&argp->ffh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) fh_put(&newfh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) * Make directory. This operation is not idempotent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * N.B. After this call resp->fh needs an fh_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) nfsd_proc_mkdir(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct nfsd_createargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct nfsd_diropres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (resp->fh.fh_dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) printk(KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) "nfsd_proc_mkdir: response already verified??\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) argp->attrs.ia_valid &= ~ATTR_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) fh_init(&resp->fh, NFS_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) resp->status = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) &argp->attrs, S_IFDIR, 0, &resp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (resp->status != nfs_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) resp->status = fh_getattr(&resp->fh, &resp->stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * Remove a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) nfsd_proc_rmdir(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct nfsd_diropargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) struct nfsd_stat *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) resp->status = nfsd_unlink(rqstp, &argp->fh, S_IFDIR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) argp->name, argp->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * Read a portion of a directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) nfsd_proc_readdir(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct nfsd_readdirargs *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct nfsd_readdirres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) loff_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) dprintk("nfsd: READDIR %s %d bytes at %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) SVCFH_fmt(&argp->fh),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) argp->count, argp->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) /* Shrink to the client read size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) count = (argp->count >> 2) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /* Make sure we've room for the NULL ptr & eof flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) count -= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) if (count < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) resp->buffer = argp->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) resp->offset = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) resp->buflen = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) resp->common.err = nfs_ok;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /* Read directory and encode entries on the fly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) offset = argp->cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) resp->status = nfsd_readdir(rqstp, &argp->fh, &offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) &resp->common, nfssvc_encode_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) resp->count = resp->buffer - argp->buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (resp->offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) *resp->offset = htonl(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * Get file system info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) nfsd_proc_statfs(struct svc_rqst *rqstp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct nfsd_fhandle *argp = rqstp->rq_argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct nfsd_statfsres *resp = rqstp->rq_resp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) resp->status = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) NFSD_MAY_BYPASS_GSS_ON_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) fh_put(&argp->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return rpc_success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * NFSv2 Server procedures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * Only the results of non-idempotent operations are cached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct nfsd_void { int dummy; };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) #define ST 1 /* status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) #define FH 8 /* filehandle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) #define AT 18 /* attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) static const struct svc_procedure nfsd_procedures2[18] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) [NFSPROC_NULL] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) .pc_func = nfsd_proc_null,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) .pc_decode = nfssvc_decode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .pc_encode = nfssvc_encode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) .pc_argsize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) .pc_ressize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .pc_xdrressize = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) [NFSPROC_GETATTR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .pc_func = nfsd_proc_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .pc_decode = nfssvc_decode_fhandle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .pc_encode = nfssvc_encode_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .pc_release = nfssvc_release_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) .pc_argsize = sizeof(struct nfsd_fhandle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) .pc_ressize = sizeof(struct nfsd_attrstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) .pc_xdrressize = ST+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) [NFSPROC_SETATTR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) .pc_func = nfsd_proc_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) .pc_decode = nfssvc_decode_sattrargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) .pc_encode = nfssvc_encode_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) .pc_release = nfssvc_release_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) .pc_argsize = sizeof(struct nfsd_sattrargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) .pc_ressize = sizeof(struct nfsd_attrstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) .pc_cachetype = RC_REPLBUFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) .pc_xdrressize = ST+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) [NFSPROC_ROOT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) .pc_func = nfsd_proc_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) .pc_decode = nfssvc_decode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) .pc_encode = nfssvc_encode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) .pc_argsize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .pc_ressize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) .pc_xdrressize = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) [NFSPROC_LOOKUP] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .pc_func = nfsd_proc_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) .pc_decode = nfssvc_decode_diropargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) .pc_encode = nfssvc_encode_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) .pc_release = nfssvc_release_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) .pc_argsize = sizeof(struct nfsd_diropargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) .pc_ressize = sizeof(struct nfsd_diropres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) .pc_xdrressize = ST+FH+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) [NFSPROC_READLINK] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) .pc_func = nfsd_proc_readlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) .pc_decode = nfssvc_decode_readlinkargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) .pc_encode = nfssvc_encode_readlinkres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) .pc_argsize = sizeof(struct nfsd_readlinkargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) .pc_ressize = sizeof(struct nfsd_readlinkres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) [NFSPROC_READ] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .pc_func = nfsd_proc_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .pc_decode = nfssvc_decode_readargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) .pc_encode = nfssvc_encode_readres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .pc_release = nfssvc_release_readres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .pc_argsize = sizeof(struct nfsd_readargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .pc_ressize = sizeof(struct nfsd_readres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) [NFSPROC_WRITECACHE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .pc_func = nfsd_proc_writecache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) .pc_decode = nfssvc_decode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .pc_encode = nfssvc_encode_void,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .pc_argsize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .pc_ressize = sizeof(struct nfsd_void),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .pc_xdrressize = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) [NFSPROC_WRITE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) .pc_func = nfsd_proc_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) .pc_decode = nfssvc_decode_writeargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) .pc_encode = nfssvc_encode_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) .pc_release = nfssvc_release_attrstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) .pc_argsize = sizeof(struct nfsd_writeargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) .pc_ressize = sizeof(struct nfsd_attrstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) .pc_cachetype = RC_REPLBUFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) .pc_xdrressize = ST+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) [NFSPROC_CREATE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) .pc_func = nfsd_proc_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) .pc_decode = nfssvc_decode_createargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) .pc_encode = nfssvc_encode_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) .pc_release = nfssvc_release_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) .pc_argsize = sizeof(struct nfsd_createargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) .pc_ressize = sizeof(struct nfsd_diropres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) .pc_cachetype = RC_REPLBUFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) .pc_xdrressize = ST+FH+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) [NFSPROC_REMOVE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) .pc_func = nfsd_proc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) .pc_decode = nfssvc_decode_diropargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) .pc_encode = nfssvc_encode_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) .pc_argsize = sizeof(struct nfsd_diropargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) .pc_ressize = sizeof(struct nfsd_stat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) .pc_cachetype = RC_REPLSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) [NFSPROC_RENAME] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) .pc_func = nfsd_proc_rename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) .pc_decode = nfssvc_decode_renameargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) .pc_encode = nfssvc_encode_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) .pc_argsize = sizeof(struct nfsd_renameargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) .pc_ressize = sizeof(struct nfsd_stat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) .pc_cachetype = RC_REPLSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) [NFSPROC_LINK] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) .pc_func = nfsd_proc_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) .pc_decode = nfssvc_decode_linkargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) .pc_encode = nfssvc_encode_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) .pc_argsize = sizeof(struct nfsd_linkargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) .pc_ressize = sizeof(struct nfsd_stat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) .pc_cachetype = RC_REPLSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) [NFSPROC_SYMLINK] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) .pc_func = nfsd_proc_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) .pc_decode = nfssvc_decode_symlinkargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) .pc_encode = nfssvc_encode_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) .pc_argsize = sizeof(struct nfsd_symlinkargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) .pc_ressize = sizeof(struct nfsd_stat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) .pc_cachetype = RC_REPLSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) [NFSPROC_MKDIR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) .pc_func = nfsd_proc_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) .pc_decode = nfssvc_decode_createargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) .pc_encode = nfssvc_encode_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) .pc_release = nfssvc_release_diropres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) .pc_argsize = sizeof(struct nfsd_createargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) .pc_ressize = sizeof(struct nfsd_diropres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) .pc_cachetype = RC_REPLBUFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) .pc_xdrressize = ST+FH+AT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) [NFSPROC_RMDIR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) .pc_func = nfsd_proc_rmdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) .pc_decode = nfssvc_decode_diropargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) .pc_encode = nfssvc_encode_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) .pc_argsize = sizeof(struct nfsd_diropargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) .pc_ressize = sizeof(struct nfsd_stat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) .pc_cachetype = RC_REPLSTAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) .pc_xdrressize = ST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) [NFSPROC_READDIR] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .pc_func = nfsd_proc_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) .pc_decode = nfssvc_decode_readdirargs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) .pc_encode = nfssvc_encode_readdirres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) .pc_argsize = sizeof(struct nfsd_readdirargs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) .pc_ressize = sizeof(struct nfsd_readdirres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) [NFSPROC_STATFS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) .pc_func = nfsd_proc_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) .pc_decode = nfssvc_decode_fhandle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) .pc_encode = nfssvc_encode_statfsres,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) .pc_argsize = sizeof(struct nfsd_fhandle),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) .pc_ressize = sizeof(struct nfsd_statfsres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) .pc_cachetype = RC_NOCACHE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) .pc_xdrressize = ST+5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) const struct svc_version nfsd_version2 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) .vs_vers = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) .vs_nproc = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) .vs_proc = nfsd_procedures2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) .vs_count = nfsd_count2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) .vs_dispatch = nfsd_dispatch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) .vs_xdrsize = NFS2_SVC_XDRSIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * Map errnos to NFS errnos.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) __be32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) nfserrno (int errno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) __be32 nfserr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) int syserr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) } nfs_errtbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) { nfs_ok, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) { nfserr_perm, -EPERM },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) { nfserr_noent, -ENOENT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) { nfserr_io, -EIO },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) { nfserr_nxio, -ENXIO },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) { nfserr_fbig, -E2BIG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) { nfserr_acces, -EACCES },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) { nfserr_exist, -EEXIST },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) { nfserr_xdev, -EXDEV },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) { nfserr_mlink, -EMLINK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) { nfserr_nodev, -ENODEV },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) { nfserr_notdir, -ENOTDIR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) { nfserr_isdir, -EISDIR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) { nfserr_inval, -EINVAL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) { nfserr_fbig, -EFBIG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) { nfserr_nospc, -ENOSPC },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) { nfserr_rofs, -EROFS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) { nfserr_mlink, -EMLINK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) { nfserr_nametoolong, -ENAMETOOLONG },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) { nfserr_notempty, -ENOTEMPTY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) #ifdef EDQUOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) { nfserr_dquot, -EDQUOT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) { nfserr_stale, -ESTALE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) { nfserr_jukebox, -ETIMEDOUT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) { nfserr_jukebox, -ERESTARTSYS },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) { nfserr_jukebox, -EAGAIN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) { nfserr_jukebox, -EWOULDBLOCK },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) { nfserr_jukebox, -ENOMEM },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) { nfserr_io, -ETXTBSY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) { nfserr_notsupp, -EOPNOTSUPP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) { nfserr_toosmall, -ETOOSMALL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) { nfserr_serverfault, -ESERVERFAULT },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) { nfserr_serverfault, -ENFILE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) { nfserr_io, -EUCLEAN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) { nfserr_perm, -ENOKEY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (nfs_errtbl[i].syserr == errno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return nfs_errtbl[i].nfserr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return nfserr_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)