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