| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *  linux/fs/nfs/nfs3proc.c | 
|  | 3 | * | 
|  | 4 | *  Client-side NFSv3 procedures stubs. | 
|  | 5 | * | 
|  | 6 | *  Copyright (C) 1997, Olaf Kirch | 
|  | 7 | */ | 
|  | 8 |  | 
|  | 9 | #include <linux/mm.h> | 
|  | 10 | #include <linux/utsname.h> | 
|  | 11 | #include <linux/errno.h> | 
|  | 12 | #include <linux/string.h> | 
|  | 13 | #include <linux/sunrpc/clnt.h> | 
|  | 14 | #include <linux/nfs.h> | 
|  | 15 | #include <linux/nfs3.h> | 
|  | 16 | #include <linux/nfs_fs.h> | 
|  | 17 | #include <linux/nfs_page.h> | 
|  | 18 | #include <linux/lockd/bind.h> | 
| Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 19 | #include <linux/nfs_mount.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 21 | #include "iostat.h" | 
| David Howells | f7b422b | 2006-06-09 09:34:33 -0400 | [diff] [blame] | 22 | #include "internal.h" | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define NFSDBG_FACILITY		NFSDBG_PROC | 
|  | 25 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* A wrapper to handle the EJUKEBOX error message */ | 
|  | 27 | static int | 
|  | 28 | nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) | 
|  | 29 | { | 
|  | 30 | sigset_t oldset; | 
|  | 31 | int res; | 
|  | 32 | rpc_clnt_sigmask(clnt, &oldset); | 
|  | 33 | do { | 
|  | 34 | res = rpc_call_sync(clnt, msg, flags); | 
|  | 35 | if (res != -EJUKEBOX) | 
|  | 36 | break; | 
| Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 37 | schedule_timeout_interruptible(NFS_JUKEBOX_RETRY_TIME); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | res = -ERESTARTSYS; | 
|  | 39 | } while (!signalled()); | 
|  | 40 | rpc_clnt_sigunmask(clnt, &oldset); | 
|  | 41 | return res; | 
|  | 42 | } | 
|  | 43 |  | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 44 | #define rpc_call_sync(clnt, msg, flags)	nfs3_rpc_wrapper(clnt, msg, flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 |  | 
|  | 46 | static int | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 47 | nfs3_async_handle_jukebox(struct rpc_task *task, struct inode *inode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { | 
|  | 49 | if (task->tk_status != -EJUKEBOX) | 
|  | 50 | return 0; | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 51 | nfs_inc_stats(inode, NFSIOS_DELAY); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | task->tk_status = 0; | 
|  | 53 | rpc_restart_call(task); | 
|  | 54 | rpc_delay(task, NFS_JUKEBOX_RETRY_TIME); | 
|  | 55 | return 1; | 
|  | 56 | } | 
|  | 57 |  | 
| J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 58 | static int | 
|  | 59 | do_proc_get_root(struct rpc_clnt *client, struct nfs_fh *fhandle, | 
|  | 60 | struct nfs_fsinfo *info) | 
|  | 61 | { | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 62 | struct rpc_message msg = { | 
|  | 63 | .rpc_proc	= &nfs3_procedures[NFS3PROC_FSINFO], | 
|  | 64 | .rpc_argp	= fhandle, | 
|  | 65 | .rpc_resp	= info, | 
|  | 66 | }; | 
| J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 67 | int	status; | 
|  | 68 |  | 
|  | 69 | dprintk("%s: call  fsinfo\n", __FUNCTION__); | 
|  | 70 | nfs_fattr_init(info->fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 71 | status = rpc_call_sync(client, &msg, 0); | 
| J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 72 | dprintk("%s: reply fsinfo: %d\n", __FUNCTION__, status); | 
|  | 73 | if (!(info->fattr->valid & NFS_ATTR_FATTR)) { | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 74 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; | 
|  | 75 | msg.rpc_resp = info->fattr; | 
|  | 76 | status = rpc_call_sync(client, &msg, 0); | 
| J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 77 | dprintk("%s: reply getattr: %d\n", __FUNCTION__, status); | 
|  | 78 | } | 
|  | 79 | return status; | 
|  | 80 | } | 
|  | 81 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* | 
| David Howells | 54ceac4 | 2006-08-22 20:06:13 -0400 | [diff] [blame] | 83 | * Bare-bones access to getattr: this is for nfs_get_root/nfs_get_sb | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | */ | 
|  | 85 | static int | 
|  | 86 | nfs3_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 87 | struct nfs_fsinfo *info) | 
|  | 88 | { | 
|  | 89 | int	status; | 
|  | 90 |  | 
| J. Bruce Fields | 03c2173 | 2006-01-03 09:55:48 +0100 | [diff] [blame] | 91 | status = do_proc_get_root(server->client, fhandle, info); | 
| David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 92 | if (status && server->nfs_client->cl_rpcclient != server->client) | 
|  | 93 | status = do_proc_get_root(server->nfs_client->cl_rpcclient, fhandle, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return status; | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | /* | 
|  | 98 | * One function for each procedure in the NFS protocol. | 
|  | 99 | */ | 
|  | 100 | static int | 
|  | 101 | nfs3_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	= &nfs3_procedures[NFS3PROC_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 | nfs3_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr, | 
|  | 120 | struct iattr *sattr) | 
|  | 121 | { | 
|  | 122 | struct inode *inode = dentry->d_inode; | 
|  | 123 | struct nfs3_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	= &nfs3_procedures[NFS3PROC_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 |  | 
|  | 134 | dprintk("NFS call  setattr\n"); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 135 | nfs_fattr_init(fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 136 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 137 | if (status == 0) | 
|  | 138 | nfs_setattr_update_inode(inode, sattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | dprintk("NFS reply setattr: %d\n", status); | 
|  | 140 | return status; | 
|  | 141 | } | 
|  | 142 |  | 
|  | 143 | static int | 
|  | 144 | nfs3_proc_lookup(struct inode *dir, struct qstr *name, | 
|  | 145 | struct nfs_fh *fhandle, struct nfs_fattr *fattr) | 
|  | 146 | { | 
|  | 147 | struct nfs_fattr	dir_attr; | 
|  | 148 | struct nfs3_diropargs	arg = { | 
|  | 149 | .fh		= NFS_FH(dir), | 
|  | 150 | .name		= name->name, | 
|  | 151 | .len		= name->len | 
|  | 152 | }; | 
|  | 153 | struct nfs3_diropres	res = { | 
|  | 154 | .dir_attr	= &dir_attr, | 
|  | 155 | .fh		= fhandle, | 
|  | 156 | .fattr		= fattr | 
|  | 157 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 158 | struct rpc_message msg = { | 
|  | 159 | .rpc_proc	= &nfs3_procedures[NFS3PROC_LOOKUP], | 
|  | 160 | .rpc_argp	= &arg, | 
|  | 161 | .rpc_resp	= &res, | 
|  | 162 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | int			status; | 
|  | 164 |  | 
|  | 165 | dprintk("NFS call  lookup %s\n", name->name); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 166 | nfs_fattr_init(&dir_attr); | 
|  | 167 | nfs_fattr_init(fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 168 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
|  | 169 | if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) { | 
|  | 170 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR]; | 
|  | 171 | msg.rpc_argp = fhandle; | 
|  | 172 | msg.rpc_resp = fattr; | 
|  | 173 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
|  | 174 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | dprintk("NFS reply lookup: %d\n", status); | 
|  | 176 | if (status >= 0) | 
|  | 177 | status = nfs_refresh_inode(dir, &dir_attr); | 
|  | 178 | return status; | 
|  | 179 | } | 
|  | 180 |  | 
|  | 181 | static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry) | 
|  | 182 | { | 
|  | 183 | struct nfs_fattr	fattr; | 
|  | 184 | struct nfs3_accessargs	arg = { | 
|  | 185 | .fh		= NFS_FH(inode), | 
|  | 186 | }; | 
|  | 187 | struct nfs3_accessres	res = { | 
|  | 188 | .fattr		= &fattr, | 
|  | 189 | }; | 
|  | 190 | struct rpc_message msg = { | 
|  | 191 | .rpc_proc	= &nfs3_procedures[NFS3PROC_ACCESS], | 
|  | 192 | .rpc_argp	= &arg, | 
|  | 193 | .rpc_resp	= &res, | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 194 | .rpc_cred	= entry->cred, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | }; | 
|  | 196 | int mode = entry->mask; | 
|  | 197 | int status; | 
|  | 198 |  | 
|  | 199 | dprintk("NFS call  access\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 |  | 
|  | 201 | if (mode & MAY_READ) | 
|  | 202 | arg.access |= NFS3_ACCESS_READ; | 
|  | 203 | if (S_ISDIR(inode->i_mode)) { | 
|  | 204 | if (mode & MAY_WRITE) | 
|  | 205 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE; | 
|  | 206 | if (mode & MAY_EXEC) | 
|  | 207 | arg.access |= NFS3_ACCESS_LOOKUP; | 
|  | 208 | } else { | 
|  | 209 | if (mode & MAY_WRITE) | 
|  | 210 | arg.access |= NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND; | 
|  | 211 | if (mode & MAY_EXEC) | 
|  | 212 | arg.access |= NFS3_ACCESS_EXECUTE; | 
|  | 213 | } | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 214 | nfs_fattr_init(&fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 
|  | 216 | nfs_refresh_inode(inode, &fattr); | 
|  | 217 | if (status == 0) { | 
|  | 218 | entry->mask = 0; | 
|  | 219 | if (res.access & NFS3_ACCESS_READ) | 
|  | 220 | entry->mask |= MAY_READ; | 
|  | 221 | if (res.access & (NFS3_ACCESS_MODIFY | NFS3_ACCESS_EXTEND | NFS3_ACCESS_DELETE)) | 
|  | 222 | entry->mask |= MAY_WRITE; | 
|  | 223 | if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE)) | 
|  | 224 | entry->mask |= MAY_EXEC; | 
|  | 225 | } | 
|  | 226 | dprintk("NFS reply access: %d\n", status); | 
|  | 227 | return status; | 
|  | 228 | } | 
|  | 229 |  | 
|  | 230 | static int nfs3_proc_readlink(struct inode *inode, struct page *page, | 
|  | 231 | unsigned int pgbase, unsigned int pglen) | 
|  | 232 | { | 
|  | 233 | struct nfs_fattr	fattr; | 
|  | 234 | struct nfs3_readlinkargs args = { | 
|  | 235 | .fh		= NFS_FH(inode), | 
|  | 236 | .pgbase		= pgbase, | 
|  | 237 | .pglen		= pglen, | 
|  | 238 | .pages		= &page | 
|  | 239 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 240 | struct rpc_message msg = { | 
|  | 241 | .rpc_proc	= &nfs3_procedures[NFS3PROC_READLINK], | 
|  | 242 | .rpc_argp	= &args, | 
|  | 243 | .rpc_resp	= &fattr, | 
|  | 244 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | int			status; | 
|  | 246 |  | 
|  | 247 | dprintk("NFS call  readlink\n"); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 248 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 249 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | nfs_refresh_inode(inode, &fattr); | 
|  | 251 | dprintk("NFS reply readlink: %d\n", status); | 
|  | 252 | return status; | 
|  | 253 | } | 
|  | 254 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* | 
|  | 256 | * Create a regular file. | 
|  | 257 | * For now, we don't implement O_EXCL. | 
|  | 258 | */ | 
|  | 259 | static int | 
|  | 260 | nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 
| Trond Myklebust | 02a913a | 2005-10-18 14:20:17 -0700 | [diff] [blame] | 261 | int flags, struct nameidata *nd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { | 
|  | 263 | struct nfs_fh		fhandle; | 
|  | 264 | struct nfs_fattr	fattr; | 
|  | 265 | struct nfs_fattr	dir_attr; | 
|  | 266 | struct nfs3_createargs	arg = { | 
|  | 267 | .fh		= NFS_FH(dir), | 
|  | 268 | .name		= dentry->d_name.name, | 
|  | 269 | .len		= dentry->d_name.len, | 
|  | 270 | .sattr		= sattr, | 
|  | 271 | }; | 
|  | 272 | struct nfs3_diropres	res = { | 
|  | 273 | .dir_attr	= &dir_attr, | 
|  | 274 | .fh		= &fhandle, | 
|  | 275 | .fattr		= &fattr | 
|  | 276 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 277 | struct rpc_message msg = { | 
|  | 278 | .rpc_proc	= &nfs3_procedures[NFS3PROC_CREATE], | 
|  | 279 | .rpc_argp	= &arg, | 
|  | 280 | .rpc_resp	= &res, | 
|  | 281 | }; | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 282 | mode_t mode = sattr->ia_mode; | 
|  | 283 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 |  | 
|  | 285 | dprintk("NFS call  create %s\n", dentry->d_name.name); | 
|  | 286 | arg.createmode = NFS3_CREATE_UNCHECKED; | 
|  | 287 | if (flags & O_EXCL) { | 
|  | 288 | arg.createmode  = NFS3_CREATE_EXCLUSIVE; | 
|  | 289 | arg.verifier[0] = jiffies; | 
|  | 290 | arg.verifier[1] = current->pid; | 
|  | 291 | } | 
|  | 292 |  | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 293 | sattr->ia_mode &= ~current->fs->umask; | 
|  | 294 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | again: | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 296 | nfs_fattr_init(&dir_attr); | 
|  | 297 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 298 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
|  | 299 | nfs_refresh_inode(dir, &dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 |  | 
|  | 301 | /* If the server doesn't support the exclusive creation semantics, | 
|  | 302 | * try again with simple 'guarded' mode. */ | 
| Andy Ryan | 46b9f8e | 2006-11-07 14:36:26 -0600 | [diff] [blame] | 303 | if (status == -ENOTSUPP) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | switch (arg.createmode) { | 
|  | 305 | case NFS3_CREATE_EXCLUSIVE: | 
|  | 306 | arg.createmode = NFS3_CREATE_GUARDED; | 
|  | 307 | break; | 
|  | 308 |  | 
|  | 309 | case NFS3_CREATE_GUARDED: | 
|  | 310 | arg.createmode = NFS3_CREATE_UNCHECKED; | 
|  | 311 | break; | 
|  | 312 |  | 
|  | 313 | case NFS3_CREATE_UNCHECKED: | 
|  | 314 | goto out; | 
|  | 315 | } | 
|  | 316 | goto again; | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | if (status == 0) | 
|  | 320 | status = nfs_instantiate(dentry, &fhandle, &fattr); | 
|  | 321 | if (status != 0) | 
|  | 322 | goto out; | 
|  | 323 |  | 
|  | 324 | /* When we created the file with exclusive semantics, make | 
|  | 325 | * sure we set the attributes afterwards. */ | 
|  | 326 | if (arg.createmode == NFS3_CREATE_EXCLUSIVE) { | 
|  | 327 | dprintk("NFS call  setattr (post-create)\n"); | 
|  | 328 |  | 
|  | 329 | if (!(sattr->ia_valid & ATTR_ATIME_SET)) | 
|  | 330 | sattr->ia_valid |= ATTR_ATIME; | 
|  | 331 | if (!(sattr->ia_valid & ATTR_MTIME_SET)) | 
|  | 332 | sattr->ia_valid |= ATTR_MTIME; | 
|  | 333 |  | 
|  | 334 | /* Note: we could use a guarded setattr here, but I'm | 
|  | 335 | * not sure this buys us anything (and I'd have | 
|  | 336 | * to revamp the NFSv3 XDR code) */ | 
|  | 337 | status = nfs3_proc_setattr(dentry, &fattr, sattr); | 
| Trond Myklebust | 65e4308 | 2005-08-16 11:49:44 -0400 | [diff] [blame] | 338 | if (status == 0) | 
|  | 339 | nfs_setattr_update_inode(dentry->d_inode, sattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | nfs_refresh_inode(dentry->d_inode, &fattr); | 
|  | 341 | dprintk("NFS reply setattr (post-create): %d\n", status); | 
|  | 342 | } | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 343 | if (status != 0) | 
|  | 344 | goto out; | 
|  | 345 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | out: | 
|  | 347 | dprintk("NFS reply create: %d\n", status); | 
|  | 348 | return status; | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | static int | 
|  | 352 | nfs3_proc_remove(struct inode *dir, struct qstr *name) | 
|  | 353 | { | 
|  | 354 | struct nfs_fattr	dir_attr; | 
|  | 355 | struct nfs3_diropargs	arg = { | 
|  | 356 | .fh		= NFS_FH(dir), | 
|  | 357 | .name		= name->name, | 
|  | 358 | .len		= name->len | 
|  | 359 | }; | 
|  | 360 | struct rpc_message	msg = { | 
|  | 361 | .rpc_proc	= &nfs3_procedures[NFS3PROC_REMOVE], | 
|  | 362 | .rpc_argp	= &arg, | 
|  | 363 | .rpc_resp	= &dir_attr, | 
|  | 364 | }; | 
|  | 365 | int			status; | 
|  | 366 |  | 
|  | 367 | dprintk("NFS call  remove %s\n", name->name); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 368 | nfs_fattr_init(&dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 370 | nfs_post_op_update_inode(dir, &dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | dprintk("NFS reply remove: %d\n", status); | 
|  | 372 | return status; | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | static int | 
|  | 376 | nfs3_proc_unlink_setup(struct rpc_message *msg, struct dentry *dir, struct qstr *name) | 
|  | 377 | { | 
|  | 378 | struct unlinkxdr { | 
|  | 379 | struct nfs3_diropargs arg; | 
|  | 380 | struct nfs_fattr res; | 
|  | 381 | } *ptr; | 
|  | 382 |  | 
| Panagiotis Issaris | f52720c | 2006-09-27 01:49:39 -0700 | [diff] [blame] | 383 | ptr = kmalloc(sizeof(*ptr), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if (!ptr) | 
|  | 385 | return -ENOMEM; | 
|  | 386 | ptr->arg.fh = NFS_FH(dir->d_inode); | 
|  | 387 | ptr->arg.name = name->name; | 
|  | 388 | ptr->arg.len = name->len; | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 389 | nfs_fattr_init(&ptr->res); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | msg->rpc_proc = &nfs3_procedures[NFS3PROC_REMOVE]; | 
|  | 391 | msg->rpc_argp = &ptr->arg; | 
|  | 392 | msg->rpc_resp = &ptr->res; | 
|  | 393 | return 0; | 
|  | 394 | } | 
|  | 395 |  | 
|  | 396 | static int | 
|  | 397 | nfs3_proc_unlink_done(struct dentry *dir, struct rpc_task *task) | 
|  | 398 | { | 
|  | 399 | struct rpc_message *msg = &task->tk_msg; | 
|  | 400 | struct nfs_fattr	*dir_attr; | 
|  | 401 |  | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 402 | if (nfs3_async_handle_jukebox(task, dir->d_inode)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return 1; | 
|  | 404 | if (msg->rpc_argp) { | 
|  | 405 | dir_attr = (struct nfs_fattr*)msg->rpc_resp; | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 406 | nfs_post_op_update_inode(dir->d_inode, dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | kfree(msg->rpc_argp); | 
|  | 408 | } | 
|  | 409 | return 0; | 
|  | 410 | } | 
|  | 411 |  | 
|  | 412 | static int | 
|  | 413 | nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name, | 
|  | 414 | struct inode *new_dir, struct qstr *new_name) | 
|  | 415 | { | 
|  | 416 | struct nfs_fattr	old_dir_attr, new_dir_attr; | 
|  | 417 | struct nfs3_renameargs	arg = { | 
|  | 418 | .fromfh		= NFS_FH(old_dir), | 
|  | 419 | .fromname	= old_name->name, | 
|  | 420 | .fromlen	= old_name->len, | 
|  | 421 | .tofh		= NFS_FH(new_dir), | 
|  | 422 | .toname		= new_name->name, | 
|  | 423 | .tolen		= new_name->len | 
|  | 424 | }; | 
|  | 425 | struct nfs3_renameres	res = { | 
|  | 426 | .fromattr	= &old_dir_attr, | 
|  | 427 | .toattr		= &new_dir_attr | 
|  | 428 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 429 | struct rpc_message msg = { | 
|  | 430 | .rpc_proc	= &nfs3_procedures[NFS3PROC_RENAME], | 
|  | 431 | .rpc_argp	= &arg, | 
|  | 432 | .rpc_resp	= &res, | 
|  | 433 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | int			status; | 
|  | 435 |  | 
|  | 436 | dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 437 | nfs_fattr_init(&old_dir_attr); | 
|  | 438 | nfs_fattr_init(&new_dir_attr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 439 | status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 440 | nfs_post_op_update_inode(old_dir, &old_dir_attr); | 
|  | 441 | nfs_post_op_update_inode(new_dir, &new_dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | dprintk("NFS reply rename: %d\n", status); | 
|  | 443 | return status; | 
|  | 444 | } | 
|  | 445 |  | 
|  | 446 | static int | 
|  | 447 | nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name) | 
|  | 448 | { | 
|  | 449 | struct nfs_fattr	dir_attr, fattr; | 
|  | 450 | struct nfs3_linkargs	arg = { | 
|  | 451 | .fromfh		= NFS_FH(inode), | 
|  | 452 | .tofh		= NFS_FH(dir), | 
|  | 453 | .toname		= name->name, | 
|  | 454 | .tolen		= name->len | 
|  | 455 | }; | 
|  | 456 | struct nfs3_linkres	res = { | 
|  | 457 | .dir_attr	= &dir_attr, | 
|  | 458 | .fattr		= &fattr | 
|  | 459 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 460 | struct rpc_message msg = { | 
|  | 461 | .rpc_proc	= &nfs3_procedures[NFS3PROC_LINK], | 
|  | 462 | .rpc_argp	= &arg, | 
|  | 463 | .rpc_resp	= &res, | 
|  | 464 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | int			status; | 
|  | 466 |  | 
|  | 467 | dprintk("NFS call  link %s\n", name->name); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 468 | nfs_fattr_init(&dir_attr); | 
|  | 469 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 470 | status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 471 | nfs_post_op_update_inode(dir, &dir_attr); | 
|  | 472 | nfs_post_op_update_inode(inode, &fattr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | dprintk("NFS reply link: %d\n", status); | 
|  | 474 | return status; | 
|  | 475 | } | 
|  | 476 |  | 
|  | 477 | static int | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 478 | nfs3_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page, | 
|  | 479 | unsigned int len, struct iattr *sattr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 481 | struct nfs_fh fhandle; | 
|  | 482 | struct nfs_fattr fattr, dir_attr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | struct nfs3_symlinkargs	arg = { | 
|  | 484 | .fromfh		= NFS_FH(dir), | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 485 | .fromname	= dentry->d_name.name, | 
|  | 486 | .fromlen	= dentry->d_name.len, | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 487 | .pages		= &page, | 
|  | 488 | .pathlen	= len, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | .sattr		= sattr | 
|  | 490 | }; | 
|  | 491 | struct nfs3_diropres	res = { | 
|  | 492 | .dir_attr	= &dir_attr, | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 493 | .fh		= &fhandle, | 
|  | 494 | .fattr		= &fattr | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 496 | struct rpc_message msg = { | 
|  | 497 | .rpc_proc	= &nfs3_procedures[NFS3PROC_SYMLINK], | 
|  | 498 | .rpc_argp	= &arg, | 
|  | 499 | .rpc_resp	= &res, | 
|  | 500 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | int			status; | 
|  | 502 |  | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 503 | if (len > NFS3_MAXPATHLEN) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return -ENAMETOOLONG; | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 505 |  | 
| Chuck Lever | 94a6d75 | 2006-08-22 20:06:23 -0400 | [diff] [blame] | 506 | dprintk("NFS call  symlink %s\n", dentry->d_name.name); | 
|  | 507 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 508 | nfs_fattr_init(&dir_attr); | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 509 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 510 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 511 | nfs_post_op_update_inode(dir, &dir_attr); | 
| Chuck Lever | 4f390c1 | 2006-08-22 20:06:22 -0400 | [diff] [blame] | 512 | if (status != 0) | 
|  | 513 | goto out; | 
|  | 514 | status = nfs_instantiate(dentry, &fhandle, &fattr); | 
|  | 515 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | dprintk("NFS reply symlink: %d\n", status); | 
|  | 517 | return status; | 
|  | 518 | } | 
|  | 519 |  | 
|  | 520 | static int | 
|  | 521 | nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) | 
|  | 522 | { | 
|  | 523 | struct nfs_fh fhandle; | 
|  | 524 | struct nfs_fattr fattr, dir_attr; | 
|  | 525 | struct nfs3_mkdirargs	arg = { | 
|  | 526 | .fh		= NFS_FH(dir), | 
|  | 527 | .name		= dentry->d_name.name, | 
|  | 528 | .len		= dentry->d_name.len, | 
|  | 529 | .sattr		= sattr | 
|  | 530 | }; | 
|  | 531 | struct nfs3_diropres	res = { | 
|  | 532 | .dir_attr	= &dir_attr, | 
|  | 533 | .fh		= &fhandle, | 
|  | 534 | .fattr		= &fattr | 
|  | 535 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 536 | struct rpc_message msg = { | 
|  | 537 | .rpc_proc	= &nfs3_procedures[NFS3PROC_MKDIR], | 
|  | 538 | .rpc_argp	= &arg, | 
|  | 539 | .rpc_resp	= &res, | 
|  | 540 | }; | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 541 | int mode = sattr->ia_mode; | 
|  | 542 | int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 |  | 
|  | 544 | dprintk("NFS call  mkdir %s\n", dentry->d_name.name); | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 545 |  | 
|  | 546 | sattr->ia_mode &= ~current->fs->umask; | 
|  | 547 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 548 | nfs_fattr_init(&dir_attr); | 
|  | 549 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 550 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 551 | nfs_post_op_update_inode(dir, &dir_attr); | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 552 | if (status != 0) | 
|  | 553 | goto out; | 
|  | 554 | status = nfs_instantiate(dentry, &fhandle, &fattr); | 
|  | 555 | if (status != 0) | 
|  | 556 | goto out; | 
|  | 557 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); | 
|  | 558 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | dprintk("NFS reply mkdir: %d\n", status); | 
|  | 560 | return status; | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | static int | 
|  | 564 | nfs3_proc_rmdir(struct inode *dir, struct qstr *name) | 
|  | 565 | { | 
|  | 566 | struct nfs_fattr	dir_attr; | 
|  | 567 | struct nfs3_diropargs	arg = { | 
|  | 568 | .fh		= NFS_FH(dir), | 
|  | 569 | .name		= name->name, | 
|  | 570 | .len		= name->len | 
|  | 571 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 572 | struct rpc_message msg = { | 
|  | 573 | .rpc_proc	= &nfs3_procedures[NFS3PROC_RMDIR], | 
|  | 574 | .rpc_argp	= &arg, | 
|  | 575 | .rpc_resp	= &dir_attr, | 
|  | 576 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | int			status; | 
|  | 578 |  | 
|  | 579 | dprintk("NFS call  rmdir %s\n", name->name); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 580 | nfs_fattr_init(&dir_attr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 581 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 582 | nfs_post_op_update_inode(dir, &dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | dprintk("NFS reply rmdir: %d\n", status); | 
|  | 584 | return status; | 
|  | 585 | } | 
|  | 586 |  | 
|  | 587 | /* | 
|  | 588 | * The READDIR implementation is somewhat hackish - we pass the user buffer | 
|  | 589 | * to the encode function, which installs it in the receive iovec. | 
|  | 590 | * The decode function itself doesn't perform any decoding, it just makes | 
|  | 591 | * sure the reply is syntactically correct. | 
|  | 592 | * | 
|  | 593 | * Also note that this implementation handles both plain readdir and | 
|  | 594 | * readdirplus. | 
|  | 595 | */ | 
|  | 596 | static int | 
|  | 597 | nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred, | 
|  | 598 | u64 cookie, struct page *page, unsigned int count, int plus) | 
|  | 599 | { | 
|  | 600 | struct inode		*dir = dentry->d_inode; | 
|  | 601 | struct nfs_fattr	dir_attr; | 
| Al Viro | bc4785c | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 602 | __be32			*verf = NFS_COOKIEVERF(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | struct nfs3_readdirargs	arg = { | 
|  | 604 | .fh		= NFS_FH(dir), | 
|  | 605 | .cookie		= cookie, | 
|  | 606 | .verf		= {verf[0], verf[1]}, | 
|  | 607 | .plus		= plus, | 
|  | 608 | .count		= count, | 
|  | 609 | .pages		= &page | 
|  | 610 | }; | 
|  | 611 | struct nfs3_readdirres	res = { | 
|  | 612 | .dir_attr	= &dir_attr, | 
|  | 613 | .verf		= verf, | 
|  | 614 | .plus		= plus | 
|  | 615 | }; | 
|  | 616 | struct rpc_message	msg = { | 
|  | 617 | .rpc_proc	= &nfs3_procedures[NFS3PROC_READDIR], | 
|  | 618 | .rpc_argp	= &arg, | 
|  | 619 | .rpc_resp	= &res, | 
|  | 620 | .rpc_cred	= cred | 
|  | 621 | }; | 
|  | 622 | int			status; | 
|  | 623 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (plus) | 
|  | 625 | msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS]; | 
|  | 626 |  | 
|  | 627 | dprintk("NFS call  readdir%s %d\n", | 
|  | 628 | plus? "plus" : "", (unsigned int) cookie); | 
|  | 629 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 630 | nfs_fattr_init(&dir_attr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
|  | 632 | nfs_refresh_inode(dir, &dir_attr); | 
|  | 633 | dprintk("NFS reply readdir: %d\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return status; | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 | static int | 
|  | 638 | nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr, | 
|  | 639 | dev_t rdev) | 
|  | 640 | { | 
|  | 641 | struct nfs_fh fh; | 
|  | 642 | struct nfs_fattr fattr, dir_attr; | 
|  | 643 | struct nfs3_mknodargs	arg = { | 
|  | 644 | .fh		= NFS_FH(dir), | 
|  | 645 | .name		= dentry->d_name.name, | 
|  | 646 | .len		= dentry->d_name.len, | 
|  | 647 | .sattr		= sattr, | 
|  | 648 | .rdev		= rdev | 
|  | 649 | }; | 
|  | 650 | struct nfs3_diropres	res = { | 
|  | 651 | .dir_attr	= &dir_attr, | 
|  | 652 | .fh		= &fh, | 
|  | 653 | .fattr		= &fattr | 
|  | 654 | }; | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 655 | struct rpc_message msg = { | 
|  | 656 | .rpc_proc	= &nfs3_procedures[NFS3PROC_MKNOD], | 
|  | 657 | .rpc_argp	= &arg, | 
|  | 658 | .rpc_resp	= &res, | 
|  | 659 | }; | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 660 | mode_t mode = sattr->ia_mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | int status; | 
|  | 662 |  | 
|  | 663 | switch (sattr->ia_mode & S_IFMT) { | 
|  | 664 | case S_IFBLK:	arg.type = NF3BLK;  break; | 
|  | 665 | case S_IFCHR:	arg.type = NF3CHR;  break; | 
|  | 666 | case S_IFIFO:	arg.type = NF3FIFO; break; | 
|  | 667 | case S_IFSOCK:	arg.type = NF3SOCK; break; | 
|  | 668 | default:	return -EINVAL; | 
|  | 669 | } | 
|  | 670 |  | 
|  | 671 | dprintk("NFS call  mknod %s %u:%u\n", dentry->d_name.name, | 
|  | 672 | MAJOR(rdev), MINOR(rdev)); | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 673 |  | 
|  | 674 | sattr->ia_mode &= ~current->fs->umask; | 
|  | 675 |  | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 676 | nfs_fattr_init(&dir_attr); | 
|  | 677 | nfs_fattr_init(&fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 678 | status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 679 | nfs_post_op_update_inode(dir, &dir_attr); | 
| Andreas Gruenbacher | 055ffbe | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 680 | if (status != 0) | 
|  | 681 | goto out; | 
|  | 682 | status = nfs_instantiate(dentry, &fh, &fattr); | 
|  | 683 | if (status != 0) | 
|  | 684 | goto out; | 
|  | 685 | status = nfs3_proc_set_default_acl(dir, dentry->d_inode, mode); | 
|  | 686 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | dprintk("NFS reply mknod: %d\n", status); | 
|  | 688 | return status; | 
|  | 689 | } | 
|  | 690 |  | 
|  | 691 | static int | 
|  | 692 | nfs3_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 693 | struct nfs_fsstat *stat) | 
|  | 694 | { | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 695 | struct rpc_message msg = { | 
|  | 696 | .rpc_proc	= &nfs3_procedures[NFS3PROC_FSSTAT], | 
|  | 697 | .rpc_argp	= fhandle, | 
|  | 698 | .rpc_resp	= stat, | 
|  | 699 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | int	status; | 
|  | 701 |  | 
|  | 702 | dprintk("NFS call  fsstat\n"); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 703 | nfs_fattr_init(stat->fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 704 | status = rpc_call_sync(server->client, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | dprintk("NFS reply statfs: %d\n", status); | 
|  | 706 | return status; | 
|  | 707 | } | 
|  | 708 |  | 
|  | 709 | static int | 
|  | 710 | nfs3_proc_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 711 | struct nfs_fsinfo *info) | 
|  | 712 | { | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 713 | struct rpc_message msg = { | 
|  | 714 | .rpc_proc	= &nfs3_procedures[NFS3PROC_FSINFO], | 
|  | 715 | .rpc_argp	= fhandle, | 
|  | 716 | .rpc_resp	= info, | 
|  | 717 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | int	status; | 
|  | 719 |  | 
|  | 720 | dprintk("NFS call  fsinfo\n"); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 721 | nfs_fattr_init(info->fattr); | 
| David Howells | 5006a76 | 2006-08-22 20:06:12 -0400 | [diff] [blame] | 722 | status = rpc_call_sync(server->nfs_client->cl_rpcclient, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | dprintk("NFS reply fsinfo: %d\n", status); | 
|  | 724 | return status; | 
|  | 725 | } | 
|  | 726 |  | 
|  | 727 | static int | 
|  | 728 | nfs3_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle, | 
|  | 729 | struct nfs_pathconf *info) | 
|  | 730 | { | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 731 | struct rpc_message msg = { | 
|  | 732 | .rpc_proc	= &nfs3_procedures[NFS3PROC_PATHCONF], | 
|  | 733 | .rpc_argp	= fhandle, | 
|  | 734 | .rpc_resp	= info, | 
|  | 735 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | int	status; | 
|  | 737 |  | 
|  | 738 | dprintk("NFS call  pathconf\n"); | 
| Trond Myklebust | 0e574af | 2005-10-27 22:12:38 -0400 | [diff] [blame] | 739 | nfs_fattr_init(info->fattr); | 
| Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 740 | status = rpc_call_sync(server->client, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | dprintk("NFS reply pathconf: %d\n", status); | 
|  | 742 | return status; | 
|  | 743 | } | 
|  | 744 |  | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 745 | static int nfs3_read_done(struct rpc_task *task, struct nfs_read_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 747 | if (nfs3_async_handle_jukebox(task, data->inode)) | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 748 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | /* Call back common NFS readpage processing */ | 
|  | 750 | if (task->tk_status >= 0) | 
|  | 751 | nfs_refresh_inode(data->inode, &data->fattr); | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 752 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } | 
|  | 754 |  | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 755 | static void nfs3_proc_read_setup(struct nfs_read_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | struct rpc_message	msg = { | 
|  | 758 | .rpc_proc	= &nfs3_procedures[NFS3PROC_READ], | 
|  | 759 | .rpc_argp	= &data->args, | 
|  | 760 | .rpc_resp	= &data->res, | 
|  | 761 | .rpc_cred	= data->cred, | 
|  | 762 | }; | 
|  | 763 |  | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 764 | rpc_call_setup(&data->task, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | } | 
|  | 766 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 767 | static int nfs3_write_done(struct rpc_task *task, struct nfs_write_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 769 | if (nfs3_async_handle_jukebox(task, data->inode)) | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 770 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | if (task->tk_status >= 0) | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 772 | nfs_post_op_update_inode(data->inode, data->res.fattr); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 773 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | } | 
|  | 775 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 776 | static void nfs3_proc_write_setup(struct nfs_write_data *data, int how) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | struct rpc_message	msg = { | 
|  | 779 | .rpc_proc	= &nfs3_procedures[NFS3PROC_WRITE], | 
|  | 780 | .rpc_argp	= &data->args, | 
|  | 781 | .rpc_resp	= &data->res, | 
|  | 782 | .rpc_cred	= data->cred, | 
|  | 783 | }; | 
|  | 784 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 785 | data->args.stable = NFS_UNSTABLE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | if (how & FLUSH_STABLE) { | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 787 | data->args.stable = NFS_FILE_SYNC; | 
|  | 788 | if (NFS_I(data->inode)->ncommit) | 
|  | 789 | data->args.stable = NFS_DATA_SYNC; | 
|  | 790 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 |  | 
|  | 792 | /* Finalize the task. */ | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 793 | rpc_call_setup(&data->task, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | } | 
|  | 795 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 796 | static int nfs3_commit_done(struct rpc_task *task, struct nfs_write_data *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | { | 
| Chuck Lever | 006ea73 | 2006-03-20 13:44:14 -0500 | [diff] [blame] | 798 | if (nfs3_async_handle_jukebox(task, data->inode)) | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 799 | return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | if (task->tk_status >= 0) | 
| Trond Myklebust | decf491 | 2005-10-27 22:12:39 -0400 | [diff] [blame] | 801 | nfs_post_op_update_inode(data->inode, data->res.fattr); | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 802 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } | 
|  | 804 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 805 | static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | struct rpc_message	msg = { | 
|  | 808 | .rpc_proc	= &nfs3_procedures[NFS3PROC_COMMIT], | 
|  | 809 | .rpc_argp	= &data->args, | 
|  | 810 | .rpc_resp	= &data->res, | 
|  | 811 | .rpc_cred	= data->cred, | 
|  | 812 | }; | 
|  | 813 |  | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 814 | rpc_call_setup(&data->task, &msg, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } | 
|  | 816 |  | 
|  | 817 | static int | 
|  | 818 | nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) | 
|  | 819 | { | 
| Josef "Jeff" Sipek | 01cce93 | 2006-12-08 02:36:40 -0800 | [diff] [blame] | 820 | return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } | 
|  | 822 |  | 
| David Howells | 509de81 | 2006-08-22 20:06:11 -0400 | [diff] [blame] | 823 | const struct nfs_rpc_ops nfs_v3_clientops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | .version	= 3,			/* protocol version */ | 
|  | 825 | .dentry_ops	= &nfs_dentry_operations, | 
| Andreas Gruenbacher | b7fa055 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 826 | .dir_inode_ops	= &nfs3_dir_inode_operations, | 
|  | 827 | .file_inode_ops	= &nfs3_file_inode_operations, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | .getroot	= nfs3_proc_get_root, | 
|  | 829 | .getattr	= nfs3_proc_getattr, | 
|  | 830 | .setattr	= nfs3_proc_setattr, | 
|  | 831 | .lookup		= nfs3_proc_lookup, | 
|  | 832 | .access		= nfs3_proc_access, | 
|  | 833 | .readlink	= nfs3_proc_readlink, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | .create		= nfs3_proc_create, | 
|  | 835 | .remove		= nfs3_proc_remove, | 
|  | 836 | .unlink_setup	= nfs3_proc_unlink_setup, | 
|  | 837 | .unlink_done	= nfs3_proc_unlink_done, | 
|  | 838 | .rename		= nfs3_proc_rename, | 
|  | 839 | .link		= nfs3_proc_link, | 
|  | 840 | .symlink	= nfs3_proc_symlink, | 
|  | 841 | .mkdir		= nfs3_proc_mkdir, | 
|  | 842 | .rmdir		= nfs3_proc_rmdir, | 
|  | 843 | .readdir	= nfs3_proc_readdir, | 
|  | 844 | .mknod		= nfs3_proc_mknod, | 
|  | 845 | .statfs		= nfs3_proc_statfs, | 
|  | 846 | .fsinfo		= nfs3_proc_fsinfo, | 
|  | 847 | .pathconf	= nfs3_proc_pathconf, | 
|  | 848 | .decode_dirent	= nfs3_decode_dirent, | 
|  | 849 | .read_setup	= nfs3_proc_read_setup, | 
| Trond Myklebust | ec06c09 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 850 | .read_done	= nfs3_read_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | .write_setup	= nfs3_proc_write_setup, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 852 | .write_done	= nfs3_write_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | .commit_setup	= nfs3_proc_commit_setup, | 
| Trond Myklebust | 788e7a8 | 2006-03-20 13:44:27 -0500 | [diff] [blame] | 854 | .commit_done	= nfs3_commit_done, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | .file_open	= nfs_open, | 
|  | 856 | .file_release	= nfs_release, | 
|  | 857 | .lock		= nfs3_proc_lock, | 
| Andreas Gruenbacher | 5c6a9f7 | 2005-06-22 17:16:27 +0000 | [diff] [blame] | 858 | .clear_acl_cache = nfs3_forget_cached_acls, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | }; |