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> |
David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 46 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | #define NFSDBG_FACILITY NFSDBG_PROC |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Bare-bones access to getattr: this is for nfs_read_super. |
| 52 | */ |
| 53 | static int |
| 54 | nfs_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, |
| 55 | struct nfs_fsinfo *info) |
| 56 | { |
| 57 | struct nfs_fattr *fattr = info->fattr; |
| 58 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 59 | struct rpc_message msg = { |
| 60 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], |
| 61 | .rpc_argp = fhandle, |
| 62 | .rpc_resp = fattr, |
| 63 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | int status; |
| 65 | |
| 66 | dprintk("%s: call getattr\n", __FUNCTION__); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 67 | nfs_fattr_init(fattr); |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 68 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | dprintk("%s: reply getattr: %d\n", __FUNCTION__, status); |
| 70 | if (status) |
| 71 | return status; |
| 72 | dprintk("%s: call statfs\n", __FUNCTION__); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 73 | msg.rpc_proc = &nfs_procedures[NFSPROC_STATFS]; |
| 74 | msg.rpc_resp = &fsinfo; |
David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 75 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | dprintk("%s: reply statfs: %d\n", __FUNCTION__, status); |
| 77 | if (status) |
| 78 | return status; |
| 79 | info->rtmax = NFS_MAXDATA; |
| 80 | info->rtpref = fsinfo.tsize; |
| 81 | info->rtmult = fsinfo.bsize; |
| 82 | info->wtmax = NFS_MAXDATA; |
| 83 | info->wtpref = fsinfo.tsize; |
| 84 | info->wtmult = fsinfo.bsize; |
| 85 | info->dtpref = fsinfo.tsize; |
| 86 | info->maxfilesize = 0x7FFFFFFF; |
| 87 | info->lease_time = 0; |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * One function for each procedure in the NFS protocol. |
| 93 | */ |
| 94 | static int |
| 95 | nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, |
| 96 | struct nfs_fattr *fattr) |
| 97 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 98 | struct rpc_message msg = { |
| 99 | .rpc_proc = &nfs_procedures[NFSPROC_GETATTR], |
| 100 | .rpc_argp = fhandle, |
| 101 | .rpc_resp = fattr, |
| 102 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | int status; |
| 104 | |
| 105 | dprintk("NFS call getattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 106 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 107 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | dprintk("NFS reply getattr: %d\n", status); |
| 109 | return status; |
| 110 | } |
| 111 | |
| 112 | static int |
| 113 | nfs_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, |
| 114 | struct iattr *sattr) |
| 115 | { |
| 116 | struct inode *inode = dentry->d_inode; |
| 117 | struct nfs_sattrargs arg = { |
| 118 | .fh = NFS_FH(inode), |
| 119 | .sattr = sattr |
| 120 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 121 | struct rpc_message msg = { |
| 122 | .rpc_proc = &nfs_procedures[NFSPROC_SETATTR], |
| 123 | .rpc_argp = &arg, |
| 124 | .rpc_resp = fattr, |
| 125 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | int status; |
| 127 | |
Trond Myklebust | cf3fff5 | 2006-01-03 09:55:53 +0100 | [diff] [blame] | 128 | /* Mask out the non-modebit related stuff from attr->ia_mode */ |
| 129 | sattr->ia_mode &= S_IALLUGO; |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | dprintk("NFS call setattr\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 132 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 133 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 134 | if (status == 0) |
| 135 | nfs_setattr_update_inode(inode, sattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | dprintk("NFS reply setattr: %d\n", status); |
| 137 | return status; |
| 138 | } |
| 139 | |
| 140 | static int |
| 141 | nfs_proc_lookup(struct inode *dir, struct qstr *name, |
| 142 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) |
| 143 | { |
| 144 | struct nfs_diropargs arg = { |
| 145 | .fh = NFS_FH(dir), |
| 146 | .name = name->name, |
| 147 | .len = name->len |
| 148 | }; |
| 149 | struct nfs_diropok res = { |
| 150 | .fh = fhandle, |
| 151 | .fattr = fattr |
| 152 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 153 | struct rpc_message msg = { |
| 154 | .rpc_proc = &nfs_procedures[NFSPROC_LOOKUP], |
| 155 | .rpc_argp = &arg, |
| 156 | .rpc_resp = &res, |
| 157 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | int status; |
| 159 | |
| 160 | dprintk("NFS call lookup %s\n", name->name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 161 | nfs_fattr_init(fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 162 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | dprintk("NFS reply lookup: %d\n", status); |
| 164 | return status; |
| 165 | } |
| 166 | |
| 167 | static int nfs_proc_readlink(struct inode *inode, struct page *page, |
| 168 | unsigned int pgbase, unsigned int pglen) |
| 169 | { |
| 170 | struct nfs_readlinkargs args = { |
| 171 | .fh = NFS_FH(inode), |
| 172 | .pgbase = pgbase, |
| 173 | .pglen = pglen, |
| 174 | .pages = &page |
| 175 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 176 | struct rpc_message msg = { |
| 177 | .rpc_proc = &nfs_procedures[NFSPROC_READLINK], |
| 178 | .rpc_argp = &args, |
| 179 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | int status; |
| 181 | |
| 182 | dprintk("NFS call readlink\n"); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 183 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | dprintk("NFS reply readlink: %d\n", status); |
| 185 | return status; |
| 186 | } |
| 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | static int |
| 189 | nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, |
Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 190 | int flags, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | struct nfs_fh fhandle; |
| 193 | struct nfs_fattr fattr; |
| 194 | struct nfs_createargs arg = { |
| 195 | .fh = NFS_FH(dir), |
| 196 | .name = dentry->d_name.name, |
| 197 | .len = dentry->d_name.len, |
| 198 | .sattr = sattr |
| 199 | }; |
| 200 | struct nfs_diropok res = { |
| 201 | .fh = &fhandle, |
| 202 | .fattr = &fattr |
| 203 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 204 | struct rpc_message msg = { |
| 205 | .rpc_proc = &nfs_procedures[NFSPROC_CREATE], |
| 206 | .rpc_argp = &arg, |
| 207 | .rpc_resp = &res, |
| 208 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | int status; |
| 210 | |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 211 | nfs_fattr_init(&fattr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | dprintk("NFS call create %s\n", dentry->d_name.name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 213 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | bad2a52 | 2007-10-20 13:07:21 -0400 | [diff] [blame] | 214 | nfs_mark_for_revalidate(dir); |
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 | { |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 276 | struct nfs_removeargs arg = { |
| 277 | .fh = NFS_FH(dir), |
| 278 | .name.len = name->len, |
| 279 | .name.name = name->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | }; |
Trond Myklebust | 4fdc17b | 2007-07-14 15:39:57 -0400 | [diff] [blame] | 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 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 295 | static void |
| 296 | nfs_proc_unlink_setup(struct rpc_message *msg, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | msg->rpc_proc = &nfs_procedures[NFSPROC_REMOVE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 301 | static int nfs_proc_unlink_done(struct rpc_task *task, struct inode *dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Trond Myklebust | e4eff1a | 2007-07-14 15:39:58 -0400 | [diff] [blame] | 303 | nfs_mark_for_revalidate(dir); |
| 304 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static int |
| 308 | nfs_proc_rename(struct inode *old_dir, struct qstr *old_name, |
| 309 | struct inode *new_dir, struct qstr *new_name) |
| 310 | { |
| 311 | struct nfs_renameargs arg = { |
| 312 | .fromfh = NFS_FH(old_dir), |
| 313 | .fromname = old_name->name, |
| 314 | .fromlen = old_name->len, |
| 315 | .tofh = NFS_FH(new_dir), |
| 316 | .toname = new_name->name, |
| 317 | .tolen = new_name->len |
| 318 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 319 | struct rpc_message msg = { |
| 320 | .rpc_proc = &nfs_procedures[NFSPROC_RENAME], |
| 321 | .rpc_argp = &arg, |
| 322 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | int status; |
| 324 | |
| 325 | 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] | 326 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 327 | nfs_mark_for_revalidate(old_dir); |
| 328 | nfs_mark_for_revalidate(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | dprintk("NFS reply rename: %d\n", status); |
| 330 | return status; |
| 331 | } |
| 332 | |
| 333 | static int |
| 334 | nfs_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) |
| 335 | { |
| 336 | struct nfs_linkargs arg = { |
| 337 | .fromfh = NFS_FH(inode), |
| 338 | .tofh = NFS_FH(dir), |
| 339 | .toname = name->name, |
| 340 | .tolen = name->len |
| 341 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 342 | struct rpc_message msg = { |
| 343 | .rpc_proc = &nfs_procedures[NFSPROC_LINK], |
| 344 | .rpc_argp = &arg, |
| 345 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | int status; |
| 347 | |
| 348 | dprintk("NFS call link %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 349 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); |
Trond Myklebust | 5ba7cc4 | 2005-12-03 15:20:17 -0500 | [diff] [blame] | 350 | nfs_mark_for_revalidate(inode); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 351 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | dprintk("NFS reply link: %d\n", status); |
| 353 | return status; |
| 354 | } |
| 355 | |
| 356 | static int |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 357 | nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, |
| 358 | unsigned int len, struct iattr *sattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 360 | struct nfs_fh fhandle; |
| 361 | struct nfs_fattr fattr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | struct nfs_symlinkargs arg = { |
| 363 | .fromfh = NFS_FH(dir), |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 364 | .fromname = dentry->d_name.name, |
| 365 | .fromlen = dentry->d_name.len, |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 366 | .pages = &page, |
| 367 | .pathlen = len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | .sattr = sattr |
| 369 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 370 | struct rpc_message msg = { |
| 371 | .rpc_proc = &nfs_procedures[NFSPROC_SYMLINK], |
| 372 | .rpc_argp = &arg, |
| 373 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | int status; |
| 375 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 376 | if (len > NFS2_MAXPATHLEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return -ENAMETOOLONG; |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 378 | |
Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 379 | dprintk("NFS call symlink %s\n", dentry->d_name.name); |
| 380 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 381 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 382 | nfs_mark_for_revalidate(dir); |
Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * V2 SYMLINK requests don't return any attributes. Setting the |
| 386 | * filehandle size to zero indicates to nfs_instantiate that it |
| 387 | * should fill in the data with a LOOKUP call on the wire. |
| 388 | */ |
| 389 | if (status == 0) { |
| 390 | nfs_fattr_init(&fattr); |
| 391 | fhandle.size = 0; |
| 392 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 393 | } |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | dprintk("NFS reply symlink: %d\n", status); |
| 396 | return status; |
| 397 | } |
| 398 | |
| 399 | static int |
| 400 | nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) |
| 401 | { |
| 402 | struct nfs_fh fhandle; |
| 403 | struct nfs_fattr fattr; |
| 404 | struct nfs_createargs arg = { |
| 405 | .fh = NFS_FH(dir), |
| 406 | .name = dentry->d_name.name, |
| 407 | .len = dentry->d_name.len, |
| 408 | .sattr = sattr |
| 409 | }; |
| 410 | struct nfs_diropok res = { |
| 411 | .fh = &fhandle, |
| 412 | .fattr = &fattr |
| 413 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 414 | struct rpc_message msg = { |
| 415 | .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], |
| 416 | .rpc_argp = &arg, |
| 417 | .rpc_resp = &res, |
| 418 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | int status; |
| 420 | |
| 421 | dprintk("NFS call mkdir %s\n", dentry->d_name.name); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 422 | nfs_fattr_init(&fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 423 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 424 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | if (status == 0) |
| 426 | status = nfs_instantiate(dentry, &fhandle, &fattr); |
| 427 | dprintk("NFS reply mkdir: %d\n", status); |
| 428 | return status; |
| 429 | } |
| 430 | |
| 431 | static int |
| 432 | nfs_proc_rmdir(struct inode *dir, struct qstr *name) |
| 433 | { |
| 434 | struct nfs_diropargs arg = { |
| 435 | .fh = NFS_FH(dir), |
| 436 | .name = name->name, |
| 437 | .len = name->len |
| 438 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 439 | struct rpc_message msg = { |
| 440 | .rpc_proc = &nfs_procedures[NFSPROC_RMDIR], |
| 441 | .rpc_argp = &arg, |
| 442 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | int status; |
| 444 | |
| 445 | dprintk("NFS call rmdir %s\n", name->name); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 446 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 447 | nfs_mark_for_revalidate(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | dprintk("NFS reply rmdir: %d\n", status); |
| 449 | return status; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * The READDIR implementation is somewhat hackish - we pass a temporary |
| 454 | * buffer to the encode function, which installs it in the receive |
| 455 | * the receive iovec. The decode function just parses the reply to make |
| 456 | * sure it is syntactically correct; the entries itself are decoded |
| 457 | * from nfs_readdir by calling the decode_entry function directly. |
| 458 | */ |
| 459 | static int |
| 460 | nfs_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, |
| 461 | u64 cookie, struct page *page, unsigned int count, int plus) |
| 462 | { |
| 463 | struct inode *dir = dentry->d_inode; |
| 464 | struct nfs_readdirargs arg = { |
| 465 | .fh = NFS_FH(dir), |
| 466 | .cookie = cookie, |
| 467 | .count = count, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 468 | .pages = &page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | }; |
| 470 | struct rpc_message msg = { |
| 471 | .rpc_proc = &nfs_procedures[NFSPROC_READDIR], |
| 472 | .rpc_argp = &arg, |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 473 | .rpc_cred = cred, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | }; |
| 475 | int status; |
| 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | dprintk("NFS call readdir %d\n", (unsigned int)cookie); |
| 478 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); |
| 479 | |
Trond Myklebust | c481299 | 2007-09-28 17:11:45 -0400 | [diff] [blame] | 480 | nfs_invalidate_atime(dir); |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | dprintk("NFS reply readdir: %d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return status; |
| 484 | } |
| 485 | |
| 486 | static int |
| 487 | nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, |
| 488 | struct nfs_fsstat *stat) |
| 489 | { |
| 490 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 491 | struct rpc_message msg = { |
| 492 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 493 | .rpc_argp = fhandle, |
| 494 | .rpc_resp = &fsinfo, |
| 495 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | int status; |
| 497 | |
| 498 | dprintk("NFS call statfs\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 499 | nfs_fattr_init(stat->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 500 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | dprintk("NFS reply statfs: %d\n", status); |
| 502 | if (status) |
| 503 | goto out; |
| 504 | stat->tbytes = (u64)fsinfo.blocks * fsinfo.bsize; |
| 505 | stat->fbytes = (u64)fsinfo.bfree * fsinfo.bsize; |
| 506 | stat->abytes = (u64)fsinfo.bavail * fsinfo.bsize; |
| 507 | stat->tfiles = 0; |
| 508 | stat->ffiles = 0; |
| 509 | stat->afiles = 0; |
| 510 | out: |
| 511 | return status; |
| 512 | } |
| 513 | |
| 514 | static int |
| 515 | nfs_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, |
| 516 | struct nfs_fsinfo *info) |
| 517 | { |
| 518 | struct nfs2_fsstat fsinfo; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 519 | struct rpc_message msg = { |
| 520 | .rpc_proc = &nfs_procedures[NFSPROC_STATFS], |
| 521 | .rpc_argp = fhandle, |
| 522 | .rpc_resp = &fsinfo, |
| 523 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | int status; |
| 525 | |
| 526 | dprintk("NFS call fsinfo\n"); |
Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 527 | nfs_fattr_init(info->fattr); |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 528 | status = rpc_call_sync(server->client, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | dprintk("NFS reply fsinfo: %d\n", status); |
| 530 | if (status) |
| 531 | goto out; |
| 532 | info->rtmax = NFS_MAXDATA; |
| 533 | info->rtpref = fsinfo.tsize; |
| 534 | info->rtmult = fsinfo.bsize; |
| 535 | info->wtmax = NFS_MAXDATA; |
| 536 | info->wtpref = fsinfo.tsize; |
| 537 | info->wtmult = fsinfo.bsize; |
| 538 | info->dtpref = fsinfo.tsize; |
| 539 | info->maxfilesize = 0x7FFFFFFF; |
| 540 | info->lease_time = 0; |
| 541 | out: |
| 542 | return status; |
| 543 | } |
| 544 | |
| 545 | static int |
| 546 | nfs_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, |
| 547 | struct nfs_pathconf *info) |
| 548 | { |
| 549 | info->max_link = 0; |
| 550 | info->max_namelen = NFS2_MAXNAMLEN; |
| 551 | return 0; |
| 552 | } |
| 553 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 554 | 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] | 555 | { |
Trond Myklebust | 8850df9 | 2007-09-28 17:20:07 -0400 | [diff] [blame] | 556 | nfs_invalidate_atime(data->inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (task->tk_status >= 0) { |
| 558 | nfs_refresh_inode(data->inode, data->res.fattr); |
| 559 | /* Emulate the eof flag, which isn't normally needed in NFSv2 |
| 560 | * as it is guaranteed to always return the file attributes |
| 561 | */ |
| 562 | if (data->args.offset + data->args.count >= data->res.fattr->size) |
| 563 | data->res.eof = 1; |
| 564 | } |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 565 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 568 | static void nfs_proc_read_setup(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 | struct rpc_message msg = { |
| 571 | .rpc_proc = &nfs_procedures[NFSPROC_READ], |
| 572 | .rpc_argp = &data->args, |
| 573 | .rpc_resp = &data->res, |
| 574 | .rpc_cred = data->cred, |
| 575 | }; |
| 576 | |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 577 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 580 | 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] | 581 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | if (task->tk_status >= 0) |
Trond Myklebust | 70ca885 | 2007-09-30 15:21:24 -0400 | [diff] [blame] | 583 | nfs_post_op_update_inode_force_wcc(data->inode, data->res.fattr); |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 584 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 587 | 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] | 588 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | struct rpc_message msg = { |
| 590 | .rpc_proc = &nfs_procedures[NFSPROC_WRITE], |
| 591 | .rpc_argp = &data->args, |
| 592 | .rpc_resp = &data->res, |
| 593 | .rpc_cred = data->cred, |
| 594 | }; |
| 595 | |
| 596 | /* Note: NFSv2 ignores @stable and always uses NFS_FILE_SYNC */ |
| 597 | data->args.stable = NFS_FILE_SYNC; |
| 598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | /* Finalize the task. */ |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 600 | rpc_call_setup(&data->task, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static void |
| 604 | nfs_proc_commit_setup(struct nfs_write_data *data, int how) |
| 605 | { |
| 606 | BUG(); |
| 607 | } |
| 608 | |
| 609 | static int |
| 610 | nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) |
| 611 | { |
Josef "Jeff" Sipek | 01cce93 | 2006-12-08 02:36:40 -0800 | [diff] [blame] | 612 | return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | |
David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 616 | const struct nfs_rpc_ops nfs_v2_clientops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | .version = 2, /* protocol version */ |
| 618 | .dentry_ops = &nfs_dentry_operations, |
| 619 | .dir_inode_ops = &nfs_dir_inode_operations, |
J. Bruce Fields | 92cfc62 | 2005-06-22 17:16:22 +0000 | [diff] [blame] | 620 | .file_inode_ops = &nfs_file_inode_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | .getroot = nfs_proc_get_root, |
| 622 | .getattr = nfs_proc_getattr, |
| 623 | .setattr = nfs_proc_setattr, |
| 624 | .lookup = nfs_proc_lookup, |
| 625 | .access = NULL, /* access */ |
| 626 | .readlink = nfs_proc_readlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | .create = nfs_proc_create, |
| 628 | .remove = nfs_proc_remove, |
| 629 | .unlink_setup = nfs_proc_unlink_setup, |
| 630 | .unlink_done = nfs_proc_unlink_done, |
| 631 | .rename = nfs_proc_rename, |
| 632 | .link = nfs_proc_link, |
| 633 | .symlink = nfs_proc_symlink, |
| 634 | .mkdir = nfs_proc_mkdir, |
| 635 | .rmdir = nfs_proc_rmdir, |
| 636 | .readdir = nfs_proc_readdir, |
| 637 | .mknod = nfs_proc_mknod, |
| 638 | .statfs = nfs_proc_statfs, |
| 639 | .fsinfo = nfs_proc_fsinfo, |
| 640 | .pathconf = nfs_proc_pathconf, |
| 641 | .decode_dirent = nfs_decode_dirent, |
| 642 | .read_setup = nfs_proc_read_setup, |
Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 643 | .read_done = nfs_read_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | .write_setup = nfs_proc_write_setup, |
Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 645 | .write_done = nfs_write_done, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | .commit_setup = nfs_proc_commit_setup, |
| 647 | .file_open = nfs_open, |
| 648 | .file_release = nfs_release, |
| 649 | .lock = nfs_proc_lock, |
| 650 | }; |