Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/proc.c |
| 3 | * |
| 4 | * Copyright (C) 1992, 1993, 1994 Rick Sladkey |
| 5 | * |
| 6 | * OS-independent nfs remote procedure call functions |
| 7 | * |
| 8 | * Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers |
| 9 | * so at last we can have decent(ish) throughput off a |
| 10 | * Sun server. |
| 11 | * |
| 12 | * Coding optimized and cleaned up by Florian La Roche. |
| 13 | * Note: Error returns are optimized for NFS_OK, which isn't translated via |
| 14 | * nfs_stat_to_errno(), but happens to be already the right return code. |
| 15 | * |
| 16 | * Also, the code currently doesn't check the size of the packet, when |
| 17 | * it decodes the packet. |
| 18 | * |
| 19 | * Feel free to fix it and mail me the diffs if it worries you. |
| 20 | * |
| 21 | * Completely rewritten to support the new RPC call interface; |
| 22 | * rewrote and moved the entire XDR stuff to xdr.c |
| 23 | * --Olaf Kirch June 1996 |
| 24 | * |
| 25 | * The code below initializes all auto variables explicitly, otherwise |
| 26 | * it will fail to work as a module (gcc generates a memset call for an |
| 27 | * incomplete struct). |
| 28 | */ |
| 29 | |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/param.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/time.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/utsname.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/string.h> |
| 38 | #include <linux/in.h> |
| 39 | #include <linux/pagemap.h> |
| 40 | #include <linux/sunrpc/clnt.h> |
| 41 | #include <linux/nfs.h> |
| 42 | #include <linux/nfs2.h> |
| 43 | #include <linux/nfs_fs.h> |
| 44 | #include <linux/nfs_page.h> |
| 45 | #include <linux/lockd/bind.h> |
| 46 | #include <linux/smp_lock.h> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 47 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Bare-bones access to getattr: this is for nfs_read_super. |
| 53 | */ |
| 54 | static int |
| 55 | nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 56 | struct nfs_fsinfo *info) |
| 57 | { |
| 58 | struct nfs_fattr *fattr = info->fattr; |
| 59 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 60 | struct rpc_message msg = { |
| 61 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], |
| 62 | .rpc_argp = fhandle, |
| 63 | .rpc_resp = fattr, |
| 64 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int status; |
| 66 | |
| 67 | dprintk("%s: call getattr\n", __FUNCTION__); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 68 | nfs_fattr_init(fattr); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame^] | 69 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | dprintk("%s: reply getattr: %d\n", __FUNCTION__, status); |
| 71 | if (status) |
| 72 | return status; |
| 73 | dprintk("%s: call statfs\n", __FUNCTION__); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 74 | msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS]; |
| 75 | msg.rpc_resp = &fsinfo; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame^] | 76 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | dprintk("%s: reply statfs: %d\n", __FUNCTION__, status); |
| 78 | if (status) |
| 79 | return status; |
| 80 | info->rtmax = NFS_MAXDATA; |
| 81 | info->rtpref = fsinfo.tsize; |
| 82 | info->rtmult = fsinfo.bsize; |
| 83 | info->wtmax = NFS_MAXDATA; |
| 84 | info->wtpref = fsinfo.tsize; |
| 85 | info->wtmult = fsinfo.bsize; |
| 86 | info->dtpref = fsinfo.tsize; |
| 87 | info->maxfilesize = 0x7FFFFFFF; |
| 88 | info->lease_time = 0; |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * One function for each procedure in the NFS protocol. |
| 94 | */ |
| 95 | static int |
| 96 | nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 97 | struct nfs_fattr *fattr) |
| 98 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 99 | struct rpc_message msg = { |
| 100 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], |
| 101 | .rpc_argp = fhandle, |
| 102 | .rpc_resp = fattr, |
| 103 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | int status; |
| 105 | |
| 106 | dprintk("NFS call getattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 107 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 108 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | dprintk("NFS reply getattr: %d\n", status); |
| 110 | return status; |
| 111 | } |
| 112 | |
| 113 | static int |
| 114 | nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 115 | struct iattr *sattr) |
| 116 | { |
| 117 | struct inode *inode = dentry->d_inode; |
| 118 | struct nfs_sattrargs arg = { |
| 119 | .fh = NFS_FH(inode), |
| 120 | .sattr = sattr |
| 121 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 122 | struct rpc_message msg = { |
| 123 | .rpc_proc = &nfs_procedures[NFSPROC_SETATTR], |
| 124 | .rpc_argp = &arg, |
| 125 | .rpc_resp = fattr, |
| 126 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int status; |
| 128 | |
Trond Myklebust | cf3fff5 | 2006-01-03 09:55:53 +0100 | [diff] [blame] | 129 | /* Mask out the non-modebit related stuff from attr->ia_mode */ |
| 130 | sattr->ia_mode &= S_IALLUGO; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | dprintk("NFS call setattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 133 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 134 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 135 | if (status == 0) |
| 136 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | dprintk("NFS reply setattr: %d\n", status); |
| 138 | return status; |
| 139 | } |
| 140 | |
| 141 | static int |
| 142 | nfs_proc_lookup(struct inode *dir, struct qstr *name, |
| 143 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 144 | { |
| 145 | struct nfs_diropargs arg = { |
| 146 | .fh = NFS_FH(dir), |
| 147 | .name = name->name, |
| 148 | .len = name->len |
| 149 | }; |
| 150 | struct nfs_diropok res = { |
| 151 | .fh = fhandle, |
| 152 | .fattr = fattr |
| 153 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 154 | struct rpc_message msg = { |
| 155 | .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP], |
| 156 | .rpc_argp = &arg, |
| 157 | .rpc_resp = &res, |
| 158 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | int status; |
| 160 | |
| 161 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 162 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 163 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | dprintk("NFS reply lookup: %d\n", status); |
| 165 | return status; |
| 166 | } |
| 167 | |
| 168 | static int nfs_proc_readlink(struct inode *inode, struct page *page, |
| 169 | unsigned int pgbase, unsigned int pglen) |
| 170 | { |
| 171 | struct nfs_readlinkargs args = { |
| 172 | .fh = NFS_FH(inode), |
| 173 | .pgbase = pgbase, |
| 174 | .pglen = pglen, |
| 175 | .pages = &page |
| 176 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 177 | struct rpc_message msg = { |
| 178 | .rpc_proc = &nfs_procedures[NFSPROC_READLINK], |
| 179 | .rpc_argp = &args, |
| 180 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | int status; |
| 182 | |
| 183 | dprintk("NFS call readlink\n"); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 184 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | dprintk("NFS reply readlink: %d\n", status); |
| 186 | return status; |
| 187 | } |
| 188 | |
| 189 | static int nfs_proc_read(struct nfs_read_data *rdata) |
| 190 | { |
| 191 | int flags = rdata->flags; |
| 192 | struct inode * inode = rdata->inode; |
| 193 | struct nfs_fattr * fattr = rdata->res.fattr; |
| 194 | struct rpc_message msg = { |
| 195 | .rpc_proc = &nfs_procedures[NFSPROC_READ], |
| 196 | .rpc_argp = &rdata->args, |
| 197 | .rpc_resp = &rdata->res, |
| 198 | .rpc_cred = rdata->cred, |
| 199 | }; |
| 200 | int status; |
| 201 | |
| 202 | dprintk("NFS call read %d @ %Ld\n", rdata->args.count, |
| 203 | (long long) rdata->args.offset); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 204 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); |
| 206 | if (status >= 0) { |
| 207 | nfs_refresh_inode(inode, fattr); |
| 208 | /* Emulate the eof flag, which isn't normally needed in NFSv2 |
| 209 | * as it is guaranteed to always return the file attributes |
| 210 | */ |
| 211 | if (rdata->args.offset + rdata->args.count >= fattr->size) |
| 212 | rdata->res.eof = 1; |
| 213 | } |
| 214 | dprintk("NFS reply read: %d\n", status); |
| 215 | return status; |
| 216 | } |
| 217 | |
| 218 | static int nfs_proc_write(struct nfs_write_data *wdata) |
| 219 | { |
| 220 | int flags = wdata->flags; |
| 221 | struct inode * inode = wdata->inode; |
| 222 | struct nfs_fattr * fattr = wdata->res.fattr; |
| 223 | struct rpc_message msg = { |
| 224 | .rpc_proc = &nfs_procedures[NFSPROC_WRITE], |
| 225 | .rpc_argp = &wdata->args, |
| 226 | .rpc_resp = &wdata->res, |
| 227 | .rpc_cred = wdata->cred, |
| 228 | }; |
| 229 | int status; |
| 230 | |
| 231 | dprintk("NFS call write %d @ %Ld\n", wdata->args.count, |
| 232 | (long long) wdata->args.offset); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 233 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, flags); |
| 235 | if (status >= 0) { |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 236 | nfs_post_op_update_inode(inode, fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | wdata->res.count = wdata->args.count; |
| 238 | wdata->verf.committed = NFS_FILE_SYNC; |
| 239 | } |
| 240 | dprintk("NFS reply write: %d\n", status); |
| 241 | return status < 0? status : wdata->res.count; |
| 242 | } |
| 243 | |
| 244 | static int |
| 245 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 246 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | struct nfs_fh fhandle; |
| 249 | struct nfs_fattr fattr; |
| 250 | struct nfs_createargs arg = { |
| 251 | .fh = NFS_FH(dir), |
| 252 | .name = dentry->d_name.name, |
| 253 | .len = dentry->d_name.len, |
| 254 | .sattr = sattr |
| 255 | }; |
| 256 | struct nfs_diropok res = { |
| 257 | .fh = &fhandle, |
| 258 | .fattr = &fattr |
| 259 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 260 | struct rpc_message msg = { |
| 261 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], |
| 262 | .rpc_argp = &arg, |
| 263 | .rpc_resp = &res, |
| 264 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | int status; |
| 266 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 267 | nfs_fattr_init(&fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | dprintk("NFS call create %s\n", dentry->d_name.name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 269 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (status == 0) |
| 271 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 272 | dprintk("NFS reply create: %d\n", status); |
| 273 | return status; |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * In NFSv2, mknod is grafted onto the create call. |
| 278 | */ |
| 279 | static int |
| 280 | nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 281 | dev_t rdev) |
| 282 | { |
| 283 | struct nfs_fh fhandle; |
| 284 | struct nfs_fattr fattr; |
| 285 | struct nfs_createargs arg = { |
| 286 | .fh = NFS_FH(dir), |
| 287 | .name = dentry->d_name.name, |
| 288 | .len = dentry->d_name.len, |
| 289 | .sattr = sattr |
| 290 | }; |
| 291 | struct nfs_diropok res = { |
| 292 | .fh = &fhandle, |
| 293 | .fattr = &fattr |
| 294 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 295 | struct rpc_message msg = { |
| 296 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], |
| 297 | .rpc_argp = &arg, |
| 298 | .rpc_resp = &res, |
| 299 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | int status, mode; |
| 301 | |
| 302 | dprintk("NFS call mknod %s\n", dentry->d_name.name); |
| 303 | |
| 304 | mode = sattr->ia_mode; |
| 305 | if (S_ISFIFO(mode)) { |
| 306 | sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR; |
| 307 | sattr->ia_valid &= ~ATTR_SIZE; |
| 308 | } else if (S_ISCHR(mode) || S_ISBLK(mode)) { |
| 309 | sattr->ia_valid |= ATTR_SIZE; |
| 310 | sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */ |
| 311 | } |
| 312 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 313 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 314 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 315 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
| 317 | if (status == -EINVAL && S_ISFIFO(mode)) { |
| 318 | sattr->ia_mode = mode; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 319 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 320 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | if (status == 0) |
| 323 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 324 | dprintk("NFS reply mknod: %d\n", status); |
| 325 | return status; |
| 326 | } |
| 327 | |
| 328 | static int |
| 329 | nfs_proc_remove(struct inode *dir, struct qstr *name) |
| 330 | { |
| 331 | struct nfs_diropargs arg = { |
| 332 | .fh = NFS_FH(dir), |
| 333 | .name = name->name, |
| 334 | .len = name->len |
| 335 | }; |
| 336 | struct rpc_message msg = { |
| 337 | .rpc_proc = &nfs_procedures[NFSPROC_REMOVE], |
| 338 | .rpc_argp = &arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | }; |
| 340 | int status; |
| 341 | |
| 342 | dprintk("NFS call remove %s\n", name->name); |
| 343 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 344 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | dprintk("NFS reply remove: %d\n", status); |
| 347 | return status; |
| 348 | } |
| 349 | |
| 350 | static int |
| 351 | nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name) |
| 352 | { |
| 353 | struct nfs_diropargs *arg; |
| 354 | |
| 355 | arg = (struct nfs_diropargs *)kmalloc(sizeof(*arg), GFP_KERNEL); |
| 356 | if (!arg) |
| 357 | return -ENOMEM; |
| 358 | arg->fh = NFS_FH(dir->d_inode); |
| 359 | arg->name = name->name; |
| 360 | arg->len = name->len; |
| 361 | msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; |
| 362 | msg->rpc_argp = arg; |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int |
| 367 | nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task) |
| 368 | { |
| 369 | struct rpc_message *msg = &task->tk_msg; |
| 370 | |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 371 | if (msg->rpc_argp) { |
| 372 | nfs_mark_for_revalidate(dir->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | kfree(msg->rpc_argp); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int |
| 379 | nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 380 | struct inode *new_dir, struct qstr *new_name) |
| 381 | { |
| 382 | struct nfs_renameargs arg = { |
| 383 | .fromfh = NFS_FH(old_dir), |
| 384 | .fromname = old_name->name, |
| 385 | .fromlen = old_name->len, |
| 386 | .tofh = NFS_FH(new_dir), |
| 387 | .toname = new_name->name, |
| 388 | .tolen = new_name->len |
| 389 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 390 | struct rpc_message msg = { |
| 391 | .rpc_proc = &nfs_procedures[NFSPROC_RENAME], |
| 392 | .rpc_argp = &arg, |
| 393 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | int status; |
| 395 | |
| 396 | dprintk("NFS call rename %s -> %s\n", old_name->name, new_name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 397 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 398 | nfs_mark_for_revalidate(old_dir); |
| 399 | nfs_mark_for_revalidate(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | dprintk("NFS reply rename: %d\n", status); |
| 401 | return status; |
| 402 | } |
| 403 | |
| 404 | static int |
| 405 | nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 406 | { |
| 407 | struct nfs_linkargs arg = { |
| 408 | .fromfh = NFS_FH(inode), |
| 409 | .tofh = NFS_FH(dir), |
| 410 | .toname = name->name, |
| 411 | .tolen = name->len |
| 412 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 413 | struct rpc_message msg = { |
| 414 | .rpc_proc = &nfs_procedures[NFSPROC_LINK], |
| 415 | .rpc_argp = &arg, |
| 416 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | int status; |
| 418 | |
| 419 | dprintk("NFS call link %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 420 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 5ba7cc4 | 2005-12-03 15:20:17 -0500 | [diff] [blame] | 421 | nfs_mark_for_revalidate(inode); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 422 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | dprintk("NFS reply link: %d\n", status); |
| 424 | return status; |
| 425 | } |
| 426 | |
| 427 | static int |
| 428 | nfs_proc_symlink(struct inode *dir, struct qstr *name, struct qstr *path, |
| 429 | struct iattr *sattr, struct nfs_fh *fhandle, |
| 430 | struct nfs_fattr *fattr) |
| 431 | { |
| 432 | struct nfs_symlinkargs arg = { |
| 433 | .fromfh = NFS_FH(dir), |
| 434 | .fromname = name->name, |
| 435 | .fromlen = name->len, |
| 436 | .topath = path->name, |
| 437 | .tolen = path->len, |
| 438 | .sattr = sattr |
| 439 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 440 | struct rpc_message msg = { |
| 441 | .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK], |
| 442 | .rpc_argp = &arg, |
| 443 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | int status; |
| 445 | |
| 446 | if (path->len > NFS2_MAXPATHLEN) |
| 447 | return -ENAMETOOLONG; |
| 448 | dprintk("NFS call symlink %s -> %s\n", name->name, path->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 449 | nfs_fattr_init(fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | fhandle->size = 0; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 451 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 452 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | dprintk("NFS reply symlink: %d\n", status); |
| 454 | return status; |
| 455 | } |
| 456 | |
| 457 | static int |
| 458 | nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 459 | { |
| 460 | struct nfs_fh fhandle; |
| 461 | struct nfs_fattr fattr; |
| 462 | struct nfs_createargs arg = { |
| 463 | .fh = NFS_FH(dir), |
| 464 | .name = dentry->d_name.name, |
| 465 | .len = dentry->d_name.len, |
| 466 | .sattr = sattr |
| 467 | }; |
| 468 | struct nfs_diropok res = { |
| 469 | .fh = &fhandle, |
| 470 | .fattr = &fattr |
| 471 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 472 | struct rpc_message msg = { |
| 473 | .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], |
| 474 | .rpc_argp = &arg, |
| 475 | .rpc_resp = &res, |
| 476 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | int status; |
| 478 | |
| 479 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 480 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 481 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 482 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | if (status == 0) |
| 484 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 485 | dprintk("NFS reply mkdir: %d\n", status); |
| 486 | return status; |
| 487 | } |
| 488 | |
| 489 | static int |
| 490 | nfs_proc_rmdir(struct inode *dir, struct qstr *name) |
| 491 | { |
| 492 | struct nfs_diropargs arg = { |
| 493 | .fh = NFS_FH(dir), |
| 494 | .name = name->name, |
| 495 | .len = name->len |
| 496 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 497 | struct rpc_message msg = { |
| 498 | .rpc_proc = &nfs_procedures[NFSPROC_RMDIR], |
| 499 | .rpc_argp = &arg, |
| 500 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | int status; |
| 502 | |
| 503 | dprintk("NFS call rmdir %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 504 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 505 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | dprintk("NFS reply rmdir: %d\n", status); |
| 507 | return status; |
| 508 | } |
| 509 | |
| 510 | /* |
| 511 | * The READDIR implementation is somewhat hackish - we pass a temporary |
| 512 | * buffer to the encode function, which installs it in the receive |
| 513 | * the receive iovec. The decode function just parses the reply to make |
| 514 | * sure it is syntactically correct; the entries itself are decoded |
| 515 | * from nfs_readdir by calling the decode_entry function directly. |
| 516 | */ |
| 517 | static int |
| 518 | nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 519 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 520 | { |
| 521 | struct inode *dir = dentry->d_inode; |
| 522 | struct nfs_readdirargs arg = { |
| 523 | .fh = NFS_FH(dir), |
| 524 | .cookie = cookie, |
| 525 | .count = count, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 526 | .pages = &page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | }; |
| 528 | struct rpc_message msg = { |
| 529 | .rpc_proc = &nfs_procedures[NFSPROC_READDIR], |
| 530 | .rpc_argp = &arg, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 531 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | }; |
| 533 | int status; |
| 534 | |
| 535 | lock_kernel(); |
| 536 | |
| 537 | dprintk("NFS call readdir %d\n", (unsigned int)cookie); |
| 538 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 539 | |
| 540 | dprintk("NFS reply readdir: %d\n", status); |
| 541 | unlock_kernel(); |
| 542 | return status; |
| 543 | } |
| 544 | |
| 545 | static int |
| 546 | nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 547 | struct nfs_fsstat *stat) |
| 548 | { |
| 549 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 550 | struct rpc_message msg = { |
| 551 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 552 | .rpc_argp = fhandle, |
| 553 | .rpc_resp = &fsinfo, |
| 554 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | int status; |
| 556 | |
| 557 | dprintk("NFS call statfs\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 558 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 559 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | dprintk("NFS reply statfs: %d\n", status); |
| 561 | if (status) |
| 562 | goto out; |
| 563 | stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize; |
| 564 | stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize; |
| 565 | stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize; |
| 566 | stat->tfiles = 0; |
| 567 | stat->ffiles = 0; |
| 568 | stat->afiles = 0; |
| 569 | out: |
| 570 | return status; |
| 571 | } |
| 572 | |
| 573 | static int |
| 574 | nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 575 | struct nfs_fsinfo *info) |
| 576 | { |
| 577 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 578 | struct rpc_message msg = { |
| 579 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 580 | .rpc_argp = fhandle, |
| 581 | .rpc_resp = &fsinfo, |
| 582 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | int status; |
| 584 | |
| 585 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 586 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 587 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | dprintk("NFS reply fsinfo: %d\n", status); |
| 589 | if (status) |
| 590 | goto out; |
| 591 | info->rtmax = NFS_MAXDATA; |
| 592 | info->rtpref = fsinfo.tsize; |
| 593 | info->rtmult = fsinfo.bsize; |
| 594 | info->wtmax = NFS_MAXDATA; |
| 595 | info->wtpref = fsinfo.tsize; |
| 596 | info->wtmult = fsinfo.bsize; |
| 597 | info->dtpref = fsinfo.tsize; |
| 598 | info->maxfilesize = 0x7FFFFFFF; |
| 599 | info->lease_time = 0; |
| 600 | out: |
| 601 | return status; |
| 602 | } |
| 603 | |
| 604 | static int |
| 605 | nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 606 | struct nfs_pathconf *info) |
| 607 | { |
| 608 | info->max_link = 0; |
| 609 | info->max_namelen = NFS2_MAXNAMLEN; |
| 610 | return 0; |
| 611 | } |
| 612 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 613 | static int nfs_read_done(struct rpc_task *task, struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if (task->tk_status >= 0) { |
| 616 | nfs_refresh_inode(data->inode, data->res.fattr); |
| 617 | /* Emulate the eof flag, which isn't normally needed in NFSv2 |
| 618 | * as it is guaranteed to always return the file attributes |
| 619 | */ |
| 620 | if (data->args.offset + data->args.count >= data->res.fattr->size) |
| 621 | data->res.eof = 1; |
| 622 | } |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 623 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 626 | static void nfs_proc_read_setup(struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | struct rpc_message msg = { |
| 629 | .rpc_proc = &nfs_procedures[NFSPROC_READ], |
| 630 | .rpc_argp = &data->args, |
| 631 | .rpc_resp = &data->res, |
| 632 | .rpc_cred = data->cred, |
| 633 | }; |
| 634 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 635 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 638 | static int nfs_write_done(struct rpc_task *task, struct nfs_write_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 641 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 642 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 645 | static void nfs_proc_write_setup(struct nfs_write_data *data, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | struct rpc_message msg = { |
| 648 | .rpc_proc = &nfs_procedures[NFSPROC_WRITE], |
| 649 | .rpc_argp = &data->args, |
| 650 | .rpc_resp = &data->res, |
| 651 | .rpc_cred = data->cred, |
| 652 | }; |
| 653 | |
| 654 | /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */ |
| 655 | data->args.stable = NFS_FILE_SYNC; |
| 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* Finalize the task. */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 658 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | static void |
| 662 | nfs_proc_commit_setup(struct nfs_write_data *data, int how) |
| 663 | { |
| 664 | BUG(); |
| 665 | } |
| 666 | |
| 667 | static int |
| 668 | nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 669 | { |
| 670 | return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl); |
| 671 | } |
| 672 | |
| 673 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 674 | const struct nfs_rpc_ops nfs_v2_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | .version = 2, /* protocol version */ |
| 676 | .dentry_ops = &nfs_dentry_operations, |
| 677 | .dir_inode_ops = &nfs_dir_inode_operations, |
J. Bruce Fields | 92cfc62 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 678 | .file_inode_ops = &nfs_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | .getroot = nfs_proc_get_root, |
| 680 | .getattr = nfs_proc_getattr, |
| 681 | .setattr = nfs_proc_setattr, |
| 682 | .lookup = nfs_proc_lookup, |
| 683 | .access = NULL, /* access */ |
| 684 | .readlink = nfs_proc_readlink, |
| 685 | .read = nfs_proc_read, |
| 686 | .write = nfs_proc_write, |
| 687 | .commit = NULL, /* commit */ |
| 688 | .create = nfs_proc_create, |
| 689 | .remove = nfs_proc_remove, |
| 690 | .unlink_setup = nfs_proc_unlink_setup, |
| 691 | .unlink_done = nfs_proc_unlink_done, |
| 692 | .rename = nfs_proc_rename, |
| 693 | .link = nfs_proc_link, |
| 694 | .symlink = nfs_proc_symlink, |
| 695 | .mkdir = nfs_proc_mkdir, |
| 696 | .rmdir = nfs_proc_rmdir, |
| 697 | .readdir = nfs_proc_readdir, |
| 698 | .mknod = nfs_proc_mknod, |
| 699 | .statfs = nfs_proc_statfs, |
| 700 | .fsinfo = nfs_proc_fsinfo, |
| 701 | .pathconf = nfs_proc_pathconf, |
| 702 | .decode_dirent = nfs_decode_dirent, |
| 703 | .read_setup = nfs_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 704 | .read_done = nfs_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | .write_setup = nfs_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 706 | .write_done = nfs_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | .commit_setup = nfs_proc_commit_setup, |
| 708 | .file_open = nfs_open, |
| 709 | .file_release = nfs_release, |
| 710 | .lock = nfs_proc_lock, |
| 711 | }; |