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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | static int |
| 219 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 220 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
| 222 | struct nfs_fh fhandle; |
| 223 | struct nfs_fattr fattr; |
| 224 | struct nfs_createargs arg = { |
| 225 | .fh = NFS_FH(dir), |
| 226 | .name = dentry->d_name.name, |
| 227 | .len = dentry->d_name.len, |
| 228 | .sattr = sattr |
| 229 | }; |
| 230 | struct nfs_diropok res = { |
| 231 | .fh = &fhandle, |
| 232 | .fattr = &fattr |
| 233 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 234 | struct rpc_message msg = { |
| 235 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], |
| 236 | .rpc_argp = &arg, |
| 237 | .rpc_resp = &res, |
| 238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | int status; |
| 240 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 241 | nfs_fattr_init(&fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | dprintk("NFS call create %s\n", dentry->d_name.name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 243 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if (status == 0) |
| 245 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 246 | dprintk("NFS reply create: %d\n", status); |
| 247 | return status; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * In NFSv2, mknod is grafted onto the create call. |
| 252 | */ |
| 253 | static int |
| 254 | nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
| 255 | dev_t rdev) |
| 256 | { |
| 257 | struct nfs_fh fhandle; |
| 258 | struct nfs_fattr fattr; |
| 259 | struct nfs_createargs arg = { |
| 260 | .fh = NFS_FH(dir), |
| 261 | .name = dentry->d_name.name, |
| 262 | .len = dentry->d_name.len, |
| 263 | .sattr = sattr |
| 264 | }; |
| 265 | struct nfs_diropok res = { |
| 266 | .fh = &fhandle, |
| 267 | .fattr = &fattr |
| 268 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 269 | struct rpc_message msg = { |
| 270 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], |
| 271 | .rpc_argp = &arg, |
| 272 | .rpc_resp = &res, |
| 273 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | int status, mode; |
| 275 | |
| 276 | dprintk("NFS call mknod %s\n", dentry->d_name.name); |
| 277 | |
| 278 | mode = sattr->ia_mode; |
| 279 | if (S_ISFIFO(mode)) { |
| 280 | sattr->ia_mode = (mode & ~S_IFMT) | S_IFCHR; |
| 281 | sattr->ia_valid &= ~ATTR_SIZE; |
| 282 | } else if (S_ISCHR(mode) || S_ISBLK(mode)) { |
| 283 | sattr->ia_valid |= ATTR_SIZE; |
| 284 | sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */ |
| 285 | } |
| 286 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 287 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 288 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 289 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | if (status == -EINVAL && S_ISFIFO(mode)) { |
| 292 | sattr->ia_mode = mode; |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 293 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 294 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | if (status == 0) |
| 297 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 298 | dprintk("NFS reply mknod: %d\n", status); |
| 299 | return status; |
| 300 | } |
| 301 | |
| 302 | static int |
| 303 | nfs_proc_remove(struct inode *dir, struct qstr *name) |
| 304 | { |
| 305 | struct nfs_diropargs arg = { |
| 306 | .fh = NFS_FH(dir), |
| 307 | .name = name->name, |
| 308 | .len = name->len |
| 309 | }; |
| 310 | struct rpc_message msg = { |
| 311 | .rpc_proc = &nfs_procedures[NFSPROC_REMOVE], |
| 312 | .rpc_argp = &arg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | }; |
| 314 | int status; |
| 315 | |
| 316 | dprintk("NFS call remove %s\n", name->name); |
| 317 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 318 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | dprintk("NFS reply remove: %d\n", status); |
| 321 | return status; |
| 322 | } |
| 323 | |
| 324 | static int |
| 325 | nfs_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name) |
| 326 | { |
| 327 | struct nfs_diropargs *arg; |
| 328 | |
Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 329 | arg = kmalloc(sizeof(*arg), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (!arg) |
| 331 | return -ENOMEM; |
| 332 | arg->fh = NFS_FH(dir->d_inode); |
| 333 | arg->name = name->name; |
| 334 | arg->len = name->len; |
| 335 | msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; |
| 336 | msg->rpc_argp = arg; |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int |
| 341 | nfs_proc_unlink_done(struct dentry *dir, struct rpc_task *task) |
| 342 | { |
| 343 | struct rpc_message *msg = &task->tk_msg; |
| 344 | |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 345 | if (msg->rpc_argp) { |
| 346 | nfs_mark_for_revalidate(dir->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | kfree(msg->rpc_argp); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int |
| 353 | nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 354 | struct inode *new_dir, struct qstr *new_name) |
| 355 | { |
| 356 | struct nfs_renameargs arg = { |
| 357 | .fromfh = NFS_FH(old_dir), |
| 358 | .fromname = old_name->name, |
| 359 | .fromlen = old_name->len, |
| 360 | .tofh = NFS_FH(new_dir), |
| 361 | .toname = new_name->name, |
| 362 | .tolen = new_name->len |
| 363 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 364 | struct rpc_message msg = { |
| 365 | .rpc_proc = &nfs_procedures[NFSPROC_RENAME], |
| 366 | .rpc_argp = &arg, |
| 367 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | int status; |
| 369 | |
| 370 | 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] | 371 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 372 | nfs_mark_for_revalidate(old_dir); |
| 373 | nfs_mark_for_revalidate(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | dprintk("NFS reply rename: %d\n", status); |
| 375 | return status; |
| 376 | } |
| 377 | |
| 378 | static int |
| 379 | nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 380 | { |
| 381 | struct nfs_linkargs arg = { |
| 382 | .fromfh = NFS_FH(inode), |
| 383 | .tofh = NFS_FH(dir), |
| 384 | .toname = name->name, |
| 385 | .tolen = name->len |
| 386 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 387 | struct rpc_message msg = { |
| 388 | .rpc_proc = &nfs_procedures[NFSPROC_LINK], |
| 389 | .rpc_argp = &arg, |
| 390 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | int status; |
| 392 | |
| 393 | dprintk("NFS call link %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 394 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 5ba7cc4 | 2005-12-03 15:20:17 -0500 | [diff] [blame] | 395 | nfs_mark_for_revalidate(inode); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 396 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | dprintk("NFS reply link: %d\n", status); |
| 398 | return status; |
| 399 | } |
| 400 | |
| 401 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 402 | nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 403 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 405 | struct nfs_fh fhandle; |
| 406 | struct nfs_fattr fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | struct nfs_symlinkargs arg = { |
| 408 | .fromfh = NFS_FH(dir), |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 409 | .fromname = dentry->d_name.name, |
| 410 | .fromlen = dentry->d_name.len, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 411 | .pages = &page, |
| 412 | .pathlen = len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | .sattr = sattr |
| 414 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 415 | struct rpc_message msg = { |
| 416 | .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK], |
| 417 | .rpc_argp = &arg, |
| 418 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | int status; |
| 420 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 421 | if (len > NFS2_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 423 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 424 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
| 425 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 426 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 427 | nfs_mark_for_revalidate(dir); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 428 | |
| 429 | /* |
| 430 | * V2 SYMLINK requests don't return any attributes. Setting the |
| 431 | * filehandle size to zero indicates to nfs_instantiate that it |
| 432 | * should fill in the data with a LOOKUP call on the wire. |
| 433 | */ |
| 434 | if (status == 0) { |
| 435 | nfs_fattr_init(&fattr); |
| 436 | fhandle.size = 0; |
| 437 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 438 | } |
| 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | dprintk("NFS reply symlink: %d\n", status); |
| 441 | return status; |
| 442 | } |
| 443 | |
| 444 | static int |
| 445 | nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 446 | { |
| 447 | struct nfs_fh fhandle; |
| 448 | struct nfs_fattr fattr; |
| 449 | struct nfs_createargs arg = { |
| 450 | .fh = NFS_FH(dir), |
| 451 | .name = dentry->d_name.name, |
| 452 | .len = dentry->d_name.len, |
| 453 | .sattr = sattr |
| 454 | }; |
| 455 | struct nfs_diropok res = { |
| 456 | .fh = &fhandle, |
| 457 | .fattr = &fattr |
| 458 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 459 | struct rpc_message msg = { |
| 460 | .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], |
| 461 | .rpc_argp = &arg, |
| 462 | .rpc_resp = &res, |
| 463 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | int status; |
| 465 | |
| 466 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 467 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 468 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 469 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (status == 0) |
| 471 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 472 | dprintk("NFS reply mkdir: %d\n", status); |
| 473 | return status; |
| 474 | } |
| 475 | |
| 476 | static int |
| 477 | nfs_proc_rmdir(struct inode *dir, struct qstr *name) |
| 478 | { |
| 479 | struct nfs_diropargs arg = { |
| 480 | .fh = NFS_FH(dir), |
| 481 | .name = name->name, |
| 482 | .len = name->len |
| 483 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 484 | struct rpc_message msg = { |
| 485 | .rpc_proc = &nfs_procedures[NFSPROC_RMDIR], |
| 486 | .rpc_argp = &arg, |
| 487 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | int status; |
| 489 | |
| 490 | dprintk("NFS call rmdir %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 491 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 492 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | dprintk("NFS reply rmdir: %d\n", status); |
| 494 | return status; |
| 495 | } |
| 496 | |
| 497 | /* |
| 498 | * The READDIR implementation is somewhat hackish - we pass a temporary |
| 499 | * buffer to the encode function, which installs it in the receive |
| 500 | * the receive iovec. The decode function just parses the reply to make |
| 501 | * sure it is syntactically correct; the entries itself are decoded |
| 502 | * from nfs_readdir by calling the decode_entry function directly. |
| 503 | */ |
| 504 | static int |
| 505 | nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 506 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 507 | { |
| 508 | struct inode *dir = dentry->d_inode; |
| 509 | struct nfs_readdirargs arg = { |
| 510 | .fh = NFS_FH(dir), |
| 511 | .cookie = cookie, |
| 512 | .count = count, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 513 | .pages = &page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | }; |
| 515 | struct rpc_message msg = { |
| 516 | .rpc_proc = &nfs_procedures[NFSPROC_READDIR], |
| 517 | .rpc_argp = &arg, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 518 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | }; |
| 520 | int status; |
| 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | dprintk("NFS call readdir %d\n", (unsigned int)cookie); |
| 523 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 524 | |
| 525 | dprintk("NFS reply readdir: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | return status; |
| 527 | } |
| 528 | |
| 529 | static int |
| 530 | nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 531 | struct nfs_fsstat *stat) |
| 532 | { |
| 533 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 534 | struct rpc_message msg = { |
| 535 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 536 | .rpc_argp = fhandle, |
| 537 | .rpc_resp = &fsinfo, |
| 538 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | int status; |
| 540 | |
| 541 | dprintk("NFS call statfs\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 542 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 543 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | dprintk("NFS reply statfs: %d\n", status); |
| 545 | if (status) |
| 546 | goto out; |
| 547 | stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize; |
| 548 | stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize; |
| 549 | stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize; |
| 550 | stat->tfiles = 0; |
| 551 | stat->ffiles = 0; |
| 552 | stat->afiles = 0; |
| 553 | out: |
| 554 | return status; |
| 555 | } |
| 556 | |
| 557 | static int |
| 558 | nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 559 | struct nfs_fsinfo *info) |
| 560 | { |
| 561 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 562 | struct rpc_message msg = { |
| 563 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 564 | .rpc_argp = fhandle, |
| 565 | .rpc_resp = &fsinfo, |
| 566 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | int status; |
| 568 | |
| 569 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 570 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 571 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | dprintk("NFS reply fsinfo: %d\n", status); |
| 573 | if (status) |
| 574 | goto out; |
| 575 | info->rtmax = NFS_MAXDATA; |
| 576 | info->rtpref = fsinfo.tsize; |
| 577 | info->rtmult = fsinfo.bsize; |
| 578 | info->wtmax = NFS_MAXDATA; |
| 579 | info->wtpref = fsinfo.tsize; |
| 580 | info->wtmult = fsinfo.bsize; |
| 581 | info->dtpref = fsinfo.tsize; |
| 582 | info->maxfilesize = 0x7FFFFFFF; |
| 583 | info->lease_time = 0; |
| 584 | out: |
| 585 | return status; |
| 586 | } |
| 587 | |
| 588 | static int |
| 589 | nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 590 | struct nfs_pathconf *info) |
| 591 | { |
| 592 | info->max_link = 0; |
| 593 | info->max_namelen = NFS2_MAXNAMLEN; |
| 594 | return 0; |
| 595 | } |
| 596 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 597 | 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] | 598 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (task->tk_status >= 0) { |
| 600 | nfs_refresh_inode(data->inode, data->res.fattr); |
| 601 | /* Emulate the eof flag, which isn't normally needed in NFSv2 |
| 602 | * as it is guaranteed to always return the file attributes |
| 603 | */ |
| 604 | if (data->args.offset + data->args.count >= data->res.fattr->size) |
| 605 | data->res.eof = 1; |
| 606 | } |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 607 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 610 | static void nfs_proc_read_setup(struct nfs_read_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | struct rpc_message msg = { |
| 613 | .rpc_proc = &nfs_procedures[NFSPROC_READ], |
| 614 | .rpc_argp = &data->args, |
| 615 | .rpc_resp = &data->res, |
| 616 | .rpc_cred = data->cred, |
| 617 | }; |
| 618 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 619 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 622 | 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] | 623 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (task->tk_status >= 0) |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 625 | nfs_post_op_update_inode(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 626 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 629 | 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] | 630 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | struct rpc_message msg = { |
| 632 | .rpc_proc = &nfs_procedures[NFSPROC_WRITE], |
| 633 | .rpc_argp = &data->args, |
| 634 | .rpc_resp = &data->res, |
| 635 | .rpc_cred = data->cred, |
| 636 | }; |
| 637 | |
| 638 | /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */ |
| 639 | data->args.stable = NFS_FILE_SYNC; |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | /* Finalize the task. */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 642 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static void |
| 646 | nfs_proc_commit_setup(struct nfs_write_data *data, int how) |
| 647 | { |
| 648 | BUG(); |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 653 | { |
Josef "Jeff" Sipek | 01cce93 | 2006-12-08 02:36:40 -0800 | [diff] [blame] | 654 | return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 658 | const struct nfs_rpc_ops nfs_v2_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | .version = 2, /* protocol version */ |
| 660 | .dentry_ops = &nfs_dentry_operations, |
| 661 | .dir_inode_ops = &nfs_dir_inode_operations, |
J. Bruce Fields | 92cfc62 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 662 | .file_inode_ops = &nfs_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | .getroot = nfs_proc_get_root, |
| 664 | .getattr = nfs_proc_getattr, |
| 665 | .setattr = nfs_proc_setattr, |
| 666 | .lookup = nfs_proc_lookup, |
| 667 | .access = NULL, /* access */ |
| 668 | .readlink = nfs_proc_readlink, |
| 669 | .read = nfs_proc_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | .create = nfs_proc_create, |
| 671 | .remove = nfs_proc_remove, |
| 672 | .unlink_setup = nfs_proc_unlink_setup, |
| 673 | .unlink_done = nfs_proc_unlink_done, |
| 674 | .rename = nfs_proc_rename, |
| 675 | .link = nfs_proc_link, |
| 676 | .symlink = nfs_proc_symlink, |
| 677 | .mkdir = nfs_proc_mkdir, |
| 678 | .rmdir = nfs_proc_rmdir, |
| 679 | .readdir = nfs_proc_readdir, |
| 680 | .mknod = nfs_proc_mknod, |
| 681 | .statfs = nfs_proc_statfs, |
| 682 | .fsinfo = nfs_proc_fsinfo, |
| 683 | .pathconf = nfs_proc_pathconf, |
| 684 | .decode_dirent = nfs_decode_dirent, |
| 685 | .read_setup = nfs_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 686 | .read_done = nfs_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | .write_setup = nfs_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 688 | .write_done = nfs_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | .commit_setup = nfs_proc_commit_setup, |
| 690 | .file_open = nfs_open, |
| 691 | .file_release = nfs_release, |
| 692 | .lock = nfs_proc_lock, |
| 693 | }; |