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