Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfsd/nfs3proc.c |
| 3 | * |
| 4 | * Process version 3 NFS requests. |
| 5 | * |
| 6 | * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/linkage.h> |
| 10 | #include <linux/time.h> |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/fs.h> |
| 13 | #include <linux/ext2_fs.h> |
| 14 | #include <linux/stat.h> |
| 15 | #include <linux/fcntl.h> |
| 16 | #include <linux/net.h> |
| 17 | #include <linux/in.h> |
| 18 | #include <linux/unistd.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/major.h> |
| 21 | |
| 22 | #include <linux/sunrpc/svc.h> |
| 23 | #include <linux/nfsd/nfsd.h> |
| 24 | #include <linux/nfsd/cache.h> |
| 25 | #include <linux/nfsd/xdr3.h> |
| 26 | #include <linux/nfs3.h> |
| 27 | |
| 28 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 29 | |
| 30 | #define RETURN_STATUS(st) { resp->status = (st); return (st); } |
| 31 | |
| 32 | static int nfs3_ftypes[] = { |
| 33 | 0, /* NF3NON */ |
| 34 | S_IFREG, /* NF3REG */ |
| 35 | S_IFDIR, /* NF3DIR */ |
| 36 | S_IFBLK, /* NF3BLK */ |
| 37 | S_IFCHR, /* NF3CHR */ |
| 38 | S_IFLNK, /* NF3LNK */ |
| 39 | S_IFSOCK, /* NF3SOCK */ |
| 40 | S_IFIFO, /* NF3FIFO */ |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * NULL call. |
| 45 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 46 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) |
| 48 | { |
| 49 | return nfs_ok; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Get a file's attributes |
| 54 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 55 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp, |
| 57 | struct nfsd3_attrstat *resp) |
| 58 | { |
David Shaw | a334de2 | 2006-01-06 00:19:58 -0800 | [diff] [blame] | 59 | int err, nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | dprintk("nfsd: GETATTR(3) %s\n", |
David Shaw | a334de2 | 2006-01-06 00:19:58 -0800 | [diff] [blame] | 62 | SVCFH_fmt(&argp->fh)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | fh_copy(&resp->fh, &argp->fh); |
| 65 | nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP); |
David Shaw | a334de2 | 2006-01-06 00:19:58 -0800 | [diff] [blame] | 66 | if (nfserr) |
| 67 | RETURN_STATUS(nfserr); |
| 68 | |
| 69 | err = vfs_getattr(resp->fh.fh_export->ex_mnt, |
| 70 | resp->fh.fh_dentry, &resp->stat); |
| 71 | nfserr = nfserrno(err); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | RETURN_STATUS(nfserr); |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * Set a file's attributes |
| 78 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 79 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | nfsd3_proc_setattr(struct svc_rqst *rqstp, struct nfsd3_sattrargs *argp, |
| 81 | struct nfsd3_attrstat *resp) |
| 82 | { |
| 83 | int nfserr; |
| 84 | |
| 85 | dprintk("nfsd: SETATTR(3) %s\n", |
| 86 | SVCFH_fmt(&argp->fh)); |
| 87 | |
| 88 | fh_copy(&resp->fh, &argp->fh); |
| 89 | nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs, |
| 90 | argp->check_guard, argp->guardtime); |
| 91 | RETURN_STATUS(nfserr); |
| 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Look up a path name component |
| 96 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 97 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | nfsd3_proc_lookup(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp, |
| 99 | struct nfsd3_diropres *resp) |
| 100 | { |
| 101 | int nfserr; |
| 102 | |
| 103 | dprintk("nfsd: LOOKUP(3) %s %.*s\n", |
| 104 | SVCFH_fmt(&argp->fh), |
| 105 | argp->len, |
| 106 | argp->name); |
| 107 | |
| 108 | fh_copy(&resp->dirfh, &argp->fh); |
| 109 | fh_init(&resp->fh, NFS3_FHSIZE); |
| 110 | |
| 111 | nfserr = nfsd_lookup(rqstp, &resp->dirfh, |
| 112 | argp->name, |
| 113 | argp->len, |
| 114 | &resp->fh); |
| 115 | RETURN_STATUS(nfserr); |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * Check file access |
| 120 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 121 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | nfsd3_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp, |
| 123 | struct nfsd3_accessres *resp) |
| 124 | { |
| 125 | int nfserr; |
| 126 | |
| 127 | dprintk("nfsd: ACCESS(3) %s 0x%x\n", |
| 128 | SVCFH_fmt(&argp->fh), |
| 129 | argp->access); |
| 130 | |
| 131 | fh_copy(&resp->fh, &argp->fh); |
| 132 | resp->access = argp->access; |
| 133 | nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL); |
| 134 | RETURN_STATUS(nfserr); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Read a symlink. |
| 139 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 140 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | nfsd3_proc_readlink(struct svc_rqst *rqstp, struct nfsd3_readlinkargs *argp, |
| 142 | struct nfsd3_readlinkres *resp) |
| 143 | { |
| 144 | int nfserr; |
| 145 | |
| 146 | dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh)); |
| 147 | |
| 148 | /* Read the symlink. */ |
| 149 | fh_copy(&resp->fh, &argp->fh); |
| 150 | resp->len = NFS3_MAXPATHLEN; |
| 151 | nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len); |
| 152 | RETURN_STATUS(nfserr); |
| 153 | } |
| 154 | |
| 155 | /* |
| 156 | * Read a portion of a file. |
| 157 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 158 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp, |
| 160 | struct nfsd3_readres *resp) |
| 161 | { |
| 162 | int nfserr; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 163 | u32 max_blocksize = svc_max_payload(rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | dprintk("nfsd: READ(3) %s %lu bytes at %lu\n", |
| 166 | SVCFH_fmt(&argp->fh), |
| 167 | (unsigned long) argp->count, |
| 168 | (unsigned long) argp->offset); |
| 169 | |
| 170 | /* Obtain buffer pointer for payload. |
| 171 | * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof) |
| 172 | * + 1 (xdr opaque byte count) = 26 |
| 173 | */ |
| 174 | |
| 175 | resp->count = argp->count; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 176 | if (max_blocksize < resp->count) |
| 177 | resp->count = max_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | svc_reserve(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4); |
| 180 | |
| 181 | fh_copy(&resp->fh, &argp->fh); |
| 182 | nfserr = nfsd_read(rqstp, &resp->fh, NULL, |
| 183 | argp->offset, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 184 | rqstp->rq_vec, argp->vlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | &resp->count); |
| 186 | if (nfserr == 0) { |
| 187 | struct inode *inode = resp->fh.fh_dentry->d_inode; |
| 188 | |
| 189 | resp->eof = (argp->offset + resp->count) >= inode->i_size; |
| 190 | } |
| 191 | |
| 192 | RETURN_STATUS(nfserr); |
| 193 | } |
| 194 | |
| 195 | /* |
| 196 | * Write data to a file |
| 197 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 198 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp, |
| 200 | struct nfsd3_writeres *resp) |
| 201 | { |
| 202 | int nfserr; |
| 203 | |
| 204 | dprintk("nfsd: WRITE(3) %s %d bytes at %ld%s\n", |
| 205 | SVCFH_fmt(&argp->fh), |
| 206 | argp->len, |
| 207 | (unsigned long) argp->offset, |
| 208 | argp->stable? " stable" : ""); |
| 209 | |
| 210 | fh_copy(&resp->fh, &argp->fh); |
| 211 | resp->committed = argp->stable; |
| 212 | nfserr = nfsd_write(rqstp, &resp->fh, NULL, |
| 213 | argp->offset, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 214 | rqstp->rq_vec, argp->vlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | argp->len, |
| 216 | &resp->committed); |
| 217 | resp->count = argp->count; |
| 218 | RETURN_STATUS(nfserr); |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * With NFSv3, CREATE processing is a lot easier than with NFSv2. |
| 223 | * At least in theory; we'll see how it fares in practice when the |
| 224 | * first reports about SunOS compatibility problems start to pour in... |
| 225 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 226 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | nfsd3_proc_create(struct svc_rqst *rqstp, struct nfsd3_createargs *argp, |
| 228 | struct nfsd3_diropres *resp) |
| 229 | { |
| 230 | svc_fh *dirfhp, *newfhp = NULL; |
| 231 | struct iattr *attr; |
| 232 | u32 nfserr; |
| 233 | |
| 234 | dprintk("nfsd: CREATE(3) %s %.*s\n", |
| 235 | SVCFH_fmt(&argp->fh), |
| 236 | argp->len, |
| 237 | argp->name); |
| 238 | |
| 239 | dirfhp = fh_copy(&resp->dirfh, &argp->fh); |
| 240 | newfhp = fh_init(&resp->fh, NFS3_FHSIZE); |
| 241 | attr = &argp->attrs; |
| 242 | |
| 243 | /* Get the directory inode */ |
| 244 | nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, MAY_CREATE); |
| 245 | if (nfserr) |
| 246 | RETURN_STATUS(nfserr); |
| 247 | |
| 248 | /* Unfudge the mode bits */ |
| 249 | attr->ia_mode &= ~S_IFMT; |
| 250 | if (!(attr->ia_valid & ATTR_MODE)) { |
| 251 | attr->ia_valid |= ATTR_MODE; |
| 252 | attr->ia_mode = S_IFREG; |
| 253 | } else { |
| 254 | attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG; |
| 255 | } |
| 256 | |
| 257 | /* Now create the file and set attributes */ |
| 258 | nfserr = nfsd_create_v3(rqstp, dirfhp, argp->name, argp->len, |
| 259 | attr, newfhp, |
| 260 | argp->createmode, argp->verf, NULL); |
| 261 | |
| 262 | RETURN_STATUS(nfserr); |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Make directory. This operation is not idempotent. |
| 267 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 268 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | nfsd3_proc_mkdir(struct svc_rqst *rqstp, struct nfsd3_createargs *argp, |
| 270 | struct nfsd3_diropres *resp) |
| 271 | { |
| 272 | int nfserr; |
| 273 | |
| 274 | dprintk("nfsd: MKDIR(3) %s %.*s\n", |
| 275 | SVCFH_fmt(&argp->fh), |
| 276 | argp->len, |
| 277 | argp->name); |
| 278 | |
| 279 | argp->attrs.ia_valid &= ~ATTR_SIZE; |
| 280 | fh_copy(&resp->dirfh, &argp->fh); |
| 281 | fh_init(&resp->fh, NFS3_FHSIZE); |
| 282 | nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len, |
| 283 | &argp->attrs, S_IFDIR, 0, &resp->fh); |
| 284 | |
| 285 | RETURN_STATUS(nfserr); |
| 286 | } |
| 287 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 288 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | nfsd3_proc_symlink(struct svc_rqst *rqstp, struct nfsd3_symlinkargs *argp, |
| 290 | struct nfsd3_diropres *resp) |
| 291 | { |
| 292 | int nfserr; |
| 293 | |
| 294 | dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n", |
| 295 | SVCFH_fmt(&argp->ffh), |
| 296 | argp->flen, argp->fname, |
| 297 | argp->tlen, argp->tname); |
| 298 | |
| 299 | fh_copy(&resp->dirfh, &argp->ffh); |
| 300 | fh_init(&resp->fh, NFS3_FHSIZE); |
| 301 | nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen, |
| 302 | argp->tname, argp->tlen, |
| 303 | &resp->fh, &argp->attrs); |
| 304 | RETURN_STATUS(nfserr); |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * Make socket/fifo/device. |
| 309 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 310 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | nfsd3_proc_mknod(struct svc_rqst *rqstp, struct nfsd3_mknodargs *argp, |
| 312 | struct nfsd3_diropres *resp) |
| 313 | { |
| 314 | int nfserr, type; |
| 315 | dev_t rdev = 0; |
| 316 | |
| 317 | dprintk("nfsd: MKNOD(3) %s %.*s\n", |
| 318 | SVCFH_fmt(&argp->fh), |
| 319 | argp->len, |
| 320 | argp->name); |
| 321 | |
| 322 | fh_copy(&resp->dirfh, &argp->fh); |
| 323 | fh_init(&resp->fh, NFS3_FHSIZE); |
| 324 | |
| 325 | if (argp->ftype == 0 || argp->ftype >= NF3BAD) |
| 326 | RETURN_STATUS(nfserr_inval); |
| 327 | if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) { |
| 328 | rdev = MKDEV(argp->major, argp->minor); |
| 329 | if (MAJOR(rdev) != argp->major || |
| 330 | MINOR(rdev) != argp->minor) |
| 331 | RETURN_STATUS(nfserr_inval); |
| 332 | } else |
| 333 | if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO) |
| 334 | RETURN_STATUS(nfserr_inval); |
| 335 | |
| 336 | type = nfs3_ftypes[argp->ftype]; |
| 337 | nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len, |
| 338 | &argp->attrs, type, rdev, &resp->fh); |
| 339 | |
| 340 | RETURN_STATUS(nfserr); |
| 341 | } |
| 342 | |
| 343 | /* |
| 344 | * Remove file/fifo/socket etc. |
| 345 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 346 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | nfsd3_proc_remove(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp, |
| 348 | struct nfsd3_attrstat *resp) |
| 349 | { |
| 350 | int nfserr; |
| 351 | |
| 352 | dprintk("nfsd: REMOVE(3) %s %.*s\n", |
| 353 | SVCFH_fmt(&argp->fh), |
| 354 | argp->len, |
| 355 | argp->name); |
| 356 | |
| 357 | /* Unlink. -S_IFDIR means file must not be a directory */ |
| 358 | fh_copy(&resp->fh, &argp->fh); |
| 359 | nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len); |
| 360 | RETURN_STATUS(nfserr); |
| 361 | } |
| 362 | |
| 363 | /* |
| 364 | * Remove a directory |
| 365 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 366 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | nfsd3_proc_rmdir(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp, |
| 368 | struct nfsd3_attrstat *resp) |
| 369 | { |
| 370 | int nfserr; |
| 371 | |
| 372 | dprintk("nfsd: RMDIR(3) %s %.*s\n", |
| 373 | SVCFH_fmt(&argp->fh), |
| 374 | argp->len, |
| 375 | argp->name); |
| 376 | |
| 377 | fh_copy(&resp->fh, &argp->fh); |
| 378 | nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len); |
| 379 | RETURN_STATUS(nfserr); |
| 380 | } |
| 381 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 382 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | nfsd3_proc_rename(struct svc_rqst *rqstp, struct nfsd3_renameargs *argp, |
| 384 | struct nfsd3_renameres *resp) |
| 385 | { |
| 386 | int nfserr; |
| 387 | |
| 388 | dprintk("nfsd: RENAME(3) %s %.*s ->\n", |
| 389 | SVCFH_fmt(&argp->ffh), |
| 390 | argp->flen, |
| 391 | argp->fname); |
| 392 | dprintk("nfsd: -> %s %.*s\n", |
| 393 | SVCFH_fmt(&argp->tfh), |
| 394 | argp->tlen, |
| 395 | argp->tname); |
| 396 | |
| 397 | fh_copy(&resp->ffh, &argp->ffh); |
| 398 | fh_copy(&resp->tfh, &argp->tfh); |
| 399 | nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen, |
| 400 | &resp->tfh, argp->tname, argp->tlen); |
| 401 | RETURN_STATUS(nfserr); |
| 402 | } |
| 403 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 404 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | nfsd3_proc_link(struct svc_rqst *rqstp, struct nfsd3_linkargs *argp, |
| 406 | struct nfsd3_linkres *resp) |
| 407 | { |
| 408 | int nfserr; |
| 409 | |
| 410 | dprintk("nfsd: LINK(3) %s ->\n", |
| 411 | SVCFH_fmt(&argp->ffh)); |
| 412 | dprintk("nfsd: -> %s %.*s\n", |
| 413 | SVCFH_fmt(&argp->tfh), |
| 414 | argp->tlen, |
| 415 | argp->tname); |
| 416 | |
| 417 | fh_copy(&resp->fh, &argp->ffh); |
| 418 | fh_copy(&resp->tfh, &argp->tfh); |
| 419 | nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen, |
| 420 | &resp->fh); |
| 421 | RETURN_STATUS(nfserr); |
| 422 | } |
| 423 | |
| 424 | /* |
| 425 | * Read a portion of a directory. |
| 426 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 427 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | nfsd3_proc_readdir(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp, |
| 429 | struct nfsd3_readdirres *resp) |
| 430 | { |
| 431 | int nfserr, count; |
| 432 | |
| 433 | dprintk("nfsd: READDIR(3) %s %d bytes at %d\n", |
| 434 | SVCFH_fmt(&argp->fh), |
| 435 | argp->count, (u32) argp->cookie); |
| 436 | |
| 437 | /* Make sure we've room for the NULL ptr & eof flag, and shrink to |
| 438 | * client read size */ |
| 439 | count = (argp->count >> 2) - 2; |
| 440 | |
| 441 | /* Read directory and encode entries on the fly */ |
| 442 | fh_copy(&resp->fh, &argp->fh); |
| 443 | |
| 444 | resp->buflen = count; |
| 445 | resp->common.err = nfs_ok; |
| 446 | resp->buffer = argp->buffer; |
| 447 | resp->rqstp = rqstp; |
| 448 | nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie, |
| 449 | &resp->common, nfs3svc_encode_entry); |
| 450 | memcpy(resp->verf, argp->verf, 8); |
| 451 | resp->count = resp->buffer - argp->buffer; |
| 452 | if (resp->offset) |
| 453 | xdr_encode_hyper(resp->offset, argp->cookie); |
| 454 | |
| 455 | RETURN_STATUS(nfserr); |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Read a portion of a directory, including file handles and attrs. |
| 460 | * For now, we choose to ignore the dircount parameter. |
| 461 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 462 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | nfsd3_proc_readdirplus(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp, |
| 464 | struct nfsd3_readdirres *resp) |
| 465 | { |
| 466 | int nfserr, count = 0; |
| 467 | loff_t offset; |
| 468 | int i; |
| 469 | caddr_t page_addr = NULL; |
| 470 | |
| 471 | dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n", |
| 472 | SVCFH_fmt(&argp->fh), |
| 473 | argp->count, (u32) argp->cookie); |
| 474 | |
| 475 | /* Convert byte count to number of words (i.e. >> 2), |
| 476 | * and reserve room for the NULL ptr & eof flag (-2 words) */ |
| 477 | resp->count = (argp->count >> 2) - 2; |
| 478 | |
| 479 | /* Read directory and encode entries on the fly */ |
| 480 | fh_copy(&resp->fh, &argp->fh); |
| 481 | |
| 482 | resp->common.err = nfs_ok; |
| 483 | resp->buffer = argp->buffer; |
| 484 | resp->buflen = resp->count; |
| 485 | resp->rqstp = rqstp; |
| 486 | offset = argp->cookie; |
| 487 | nfserr = nfsd_readdir(rqstp, &resp->fh, |
| 488 | &offset, |
| 489 | &resp->common, |
| 490 | nfs3svc_encode_entry_plus); |
| 491 | memcpy(resp->verf, argp->verf, 8); |
| 492 | for (i=1; i<rqstp->rq_resused ; i++) { |
| 493 | page_addr = page_address(rqstp->rq_respages[i]); |
| 494 | |
| 495 | if (((caddr_t)resp->buffer >= page_addr) && |
| 496 | ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) { |
| 497 | count += (caddr_t)resp->buffer - page_addr; |
| 498 | break; |
| 499 | } |
| 500 | count += PAGE_SIZE; |
| 501 | } |
| 502 | resp->count = count >> 2; |
| 503 | if (resp->offset) { |
| 504 | if (unlikely(resp->offset1)) { |
| 505 | /* we ended up with offset on a page boundary */ |
| 506 | *resp->offset = htonl(offset >> 32); |
| 507 | *resp->offset1 = htonl(offset & 0xffffffff); |
| 508 | resp->offset1 = NULL; |
| 509 | } else { |
| 510 | xdr_encode_hyper(resp->offset, offset); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | RETURN_STATUS(nfserr); |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Get file system stats |
| 519 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 520 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, |
| 522 | struct nfsd3_fsstatres *resp) |
| 523 | { |
| 524 | int nfserr; |
| 525 | |
| 526 | dprintk("nfsd: FSSTAT(3) %s\n", |
| 527 | SVCFH_fmt(&argp->fh)); |
| 528 | |
| 529 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats); |
| 530 | fh_put(&argp->fh); |
| 531 | RETURN_STATUS(nfserr); |
| 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Get file system info |
| 536 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 537 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, |
| 539 | struct nfsd3_fsinfores *resp) |
| 540 | { |
| 541 | int nfserr; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 542 | u32 max_blocksize = svc_max_payload(rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | dprintk("nfsd: FSINFO(3) %s\n", |
| 545 | SVCFH_fmt(&argp->fh)); |
| 546 | |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 547 | resp->f_rtmax = max_blocksize; |
| 548 | resp->f_rtpref = max_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | resp->f_rtmult = PAGE_SIZE; |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 550 | resp->f_wtmax = max_blocksize; |
| 551 | resp->f_wtpref = max_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | resp->f_wtmult = PAGE_SIZE; |
| 553 | resp->f_dtpref = PAGE_SIZE; |
| 554 | resp->f_maxfilesize = ~(u32) 0; |
| 555 | resp->f_properties = NFS3_FSF_DEFAULT; |
| 556 | |
| 557 | nfserr = fh_verify(rqstp, &argp->fh, 0, MAY_NOP); |
| 558 | |
| 559 | /* Check special features of the file system. May request |
| 560 | * different read/write sizes for file systems known to have |
| 561 | * problems with large blocks */ |
| 562 | if (nfserr == 0) { |
| 563 | struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb; |
| 564 | |
| 565 | /* Note that we don't care for remote fs's here */ |
| 566 | if (sb->s_magic == 0x4d44 /* MSDOS_SUPER_MAGIC */) { |
| 567 | resp->f_properties = NFS3_FSF_BILLYBOY; |
| 568 | } |
| 569 | resp->f_maxfilesize = sb->s_maxbytes; |
| 570 | } |
| 571 | |
| 572 | fh_put(&argp->fh); |
| 573 | RETURN_STATUS(nfserr); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Get pathconf info for the specified file |
| 578 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 579 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | nfsd3_proc_pathconf(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, |
| 581 | struct nfsd3_pathconfres *resp) |
| 582 | { |
| 583 | int nfserr; |
| 584 | |
| 585 | dprintk("nfsd: PATHCONF(3) %s\n", |
| 586 | SVCFH_fmt(&argp->fh)); |
| 587 | |
| 588 | /* Set default pathconf */ |
| 589 | resp->p_link_max = 255; /* at least */ |
| 590 | resp->p_name_max = 255; /* at least */ |
| 591 | resp->p_no_trunc = 0; |
| 592 | resp->p_chown_restricted = 1; |
| 593 | resp->p_case_insensitive = 0; |
| 594 | resp->p_case_preserving = 1; |
| 595 | |
| 596 | nfserr = fh_verify(rqstp, &argp->fh, 0, MAY_NOP); |
| 597 | |
| 598 | if (nfserr == 0) { |
| 599 | struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb; |
| 600 | |
| 601 | /* Note that we don't care for remote fs's here */ |
| 602 | switch (sb->s_magic) { |
| 603 | case EXT2_SUPER_MAGIC: |
| 604 | resp->p_link_max = EXT2_LINK_MAX; |
| 605 | resp->p_name_max = EXT2_NAME_LEN; |
| 606 | break; |
| 607 | case 0x4d44: /* MSDOS_SUPER_MAGIC */ |
| 608 | resp->p_case_insensitive = 1; |
| 609 | resp->p_case_preserving = 0; |
| 610 | break; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | fh_put(&argp->fh); |
| 615 | RETURN_STATUS(nfserr); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | /* |
| 620 | * Commit a file (range) to stable storage. |
| 621 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame^] | 622 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | nfsd3_proc_commit(struct svc_rqst * rqstp, struct nfsd3_commitargs *argp, |
| 624 | struct nfsd3_commitres *resp) |
| 625 | { |
| 626 | int nfserr; |
| 627 | |
| 628 | dprintk("nfsd: COMMIT(3) %s %u@%Lu\n", |
| 629 | SVCFH_fmt(&argp->fh), |
| 630 | argp->count, |
| 631 | (unsigned long long) argp->offset); |
| 632 | |
| 633 | if (argp->offset > NFS_OFFSET_MAX) |
| 634 | RETURN_STATUS(nfserr_inval); |
| 635 | |
| 636 | fh_copy(&resp->fh, &argp->fh); |
| 637 | nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count); |
| 638 | |
| 639 | RETURN_STATUS(nfserr); |
| 640 | } |
| 641 | |
| 642 | |
| 643 | /* |
| 644 | * NFSv3 Server procedures. |
| 645 | * Only the results of non-idempotent operations are cached. |
| 646 | */ |
| 647 | #define nfs3svc_decode_voidargs NULL |
| 648 | #define nfs3svc_release_void NULL |
| 649 | #define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle |
| 650 | #define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat |
| 651 | #define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat |
| 652 | #define nfsd3_mkdirargs nfsd3_createargs |
| 653 | #define nfsd3_readdirplusargs nfsd3_readdirargs |
| 654 | #define nfsd3_fhandleargs nfsd_fhandle |
| 655 | #define nfsd3_fhandleres nfsd3_attrstat |
| 656 | #define nfsd3_attrstatres nfsd3_attrstat |
| 657 | #define nfsd3_wccstatres nfsd3_attrstat |
| 658 | #define nfsd3_createres nfsd3_diropres |
| 659 | #define nfsd3_voidres nfsd3_voidargs |
| 660 | struct nfsd3_voidargs { int dummy; }; |
| 661 | |
| 662 | #define PROC(name, argt, rest, relt, cache, respsize) \ |
| 663 | { (svc_procfunc) nfsd3_proc_##name, \ |
| 664 | (kxdrproc_t) nfs3svc_decode_##argt##args, \ |
| 665 | (kxdrproc_t) nfs3svc_encode_##rest##res, \ |
| 666 | (kxdrproc_t) nfs3svc_release_##relt, \ |
| 667 | sizeof(struct nfsd3_##argt##args), \ |
| 668 | sizeof(struct nfsd3_##rest##res), \ |
| 669 | 0, \ |
| 670 | cache, \ |
| 671 | respsize, \ |
| 672 | } |
| 673 | |
| 674 | #define ST 1 /* status*/ |
| 675 | #define FH 17 /* filehandle with length */ |
| 676 | #define AT 21 /* attributes */ |
| 677 | #define pAT (1+AT) /* post attributes - conditional */ |
| 678 | #define WC (7+pAT) /* WCC attributes */ |
| 679 | |
| 680 | static struct svc_procedure nfsd_procedures3[22] = { |
| 681 | PROC(null, void, void, void, RC_NOCACHE, ST), |
| 682 | PROC(getattr, fhandle, attrstat, fhandle, RC_NOCACHE, ST+AT), |
| 683 | PROC(setattr, sattr, wccstat, fhandle, RC_REPLBUFF, ST+WC), |
| 684 | PROC(lookup, dirop, dirop, fhandle2, RC_NOCACHE, ST+FH+pAT+pAT), |
| 685 | PROC(access, access, access, fhandle, RC_NOCACHE, ST+pAT+1), |
| 686 | PROC(readlink, readlink, readlink, fhandle, RC_NOCACHE, ST+pAT+1+NFS3_MAXPATHLEN/4), |
NeilBrown | 7775f4c | 2006-04-10 22:55:20 -0700 | [diff] [blame] | 687 | PROC(read, read, read, fhandle, RC_NOCACHE, ST+pAT+4+NFSSVC_MAXBLKSIZE/4), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | PROC(write, write, write, fhandle, RC_REPLBUFF, ST+WC+4), |
| 689 | PROC(create, create, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC), |
| 690 | PROC(mkdir, mkdir, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC), |
| 691 | PROC(symlink, symlink, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC), |
| 692 | PROC(mknod, mknod, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC), |
| 693 | PROC(remove, dirop, wccstat, fhandle, RC_REPLBUFF, ST+WC), |
| 694 | PROC(rmdir, dirop, wccstat, fhandle, RC_REPLBUFF, ST+WC), |
| 695 | PROC(rename, rename, rename, fhandle2, RC_REPLBUFF, ST+WC+WC), |
| 696 | PROC(link, link, link, fhandle2, RC_REPLBUFF, ST+pAT+WC), |
| 697 | PROC(readdir, readdir, readdir, fhandle, RC_NOCACHE, 0), |
| 698 | PROC(readdirplus,readdirplus, readdir, fhandle, RC_NOCACHE, 0), |
| 699 | PROC(fsstat, fhandle, fsstat, void, RC_NOCACHE, ST+pAT+2*6+1), |
| 700 | PROC(fsinfo, fhandle, fsinfo, void, RC_NOCACHE, ST+pAT+12), |
| 701 | PROC(pathconf, fhandle, pathconf, void, RC_NOCACHE, ST+pAT+6), |
| 702 | PROC(commit, commit, commit, fhandle, RC_NOCACHE, ST+WC+2), |
| 703 | }; |
| 704 | |
| 705 | struct svc_version nfsd_version3 = { |
| 706 | .vs_vers = 3, |
| 707 | .vs_nproc = 22, |
| 708 | .vs_proc = nfsd_procedures3, |
| 709 | .vs_dispatch = nfsd_dispatch, |
| 710 | .vs_xdrsize = NFS3_SVC_XDRSIZE, |
| 711 | }; |