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