Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfsd/nfsctl.c |
| 3 | * |
| 4 | * Syscall interface to knfsd. |
| 5 | * |
| 6 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> |
| 7 | */ |
| 8 | |
Al Viro | 3f8206d | 2008-07-26 03:46:43 -0400 | [diff] [blame] | 9 | #include <linux/namei.h> |
NeilBrown | b41b66d | 2006-10-02 02:17:48 -0700 | [diff] [blame] | 10 | #include <linux/ctype.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/nfsd_idmap.h> |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 13 | #include <linux/sunrpc/svcsock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/nfsd/syscall.h> |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 15 | #include <linux/lockd/lockd.h> |
Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 16 | #include <linux/sunrpc/clnt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame^] | 18 | #include "nfsd.h" |
| 19 | #include "cache.h" |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | /* |
| 22 | * We have a single directory with 9 nodes in it. |
| 23 | */ |
| 24 | enum { |
| 25 | NFSD_Root = 1, |
| 26 | NFSD_Svc, |
| 27 | NFSD_Add, |
| 28 | NFSD_Del, |
| 29 | NFSD_Export, |
| 30 | NFSD_Unexport, |
| 31 | NFSD_Getfd, |
| 32 | NFSD_Getfs, |
| 33 | NFSD_List, |
| 34 | NFSD_Fh, |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 35 | NFSD_FO_UnlockIP, |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 36 | NFSD_FO_UnlockFS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | NFSD_Threads, |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 38 | NFSD_Pool_Threads, |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 39 | NFSD_Pool_Stats, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 40 | NFSD_Versions, |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 41 | NFSD_Ports, |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 42 | NFSD_MaxBlkSize, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 43 | /* |
| 44 | * The below MUST come last. Otherwise we leave a hole in nfsd_files[] |
| 45 | * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops |
| 46 | */ |
| 47 | #ifdef CONFIG_NFSD_V4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | NFSD_Leasetime, |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 49 | NFSD_RecoveryDir, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 50 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /* |
| 54 | * write() for these nodes. |
| 55 | */ |
| 56 | static ssize_t write_svc(struct file *file, char *buf, size_t size); |
| 57 | static ssize_t write_add(struct file *file, char *buf, size_t size); |
| 58 | static ssize_t write_del(struct file *file, char *buf, size_t size); |
| 59 | static ssize_t write_export(struct file *file, char *buf, size_t size); |
| 60 | static ssize_t write_unexport(struct file *file, char *buf, size_t size); |
| 61 | static ssize_t write_getfd(struct file *file, char *buf, size_t size); |
| 62 | static ssize_t write_getfs(struct file *file, char *buf, size_t size); |
| 63 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size); |
Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 64 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); |
| 65 | static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static ssize_t write_threads(struct file *file, char *buf, size_t size); |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 67 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 68 | static ssize_t write_versions(struct file *file, char *buf, size_t size); |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 69 | static ssize_t write_ports(struct file *file, char *buf, size_t size); |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 70 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 71 | #ifdef CONFIG_NFSD_V4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size); |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 73 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 74 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | static ssize_t (*write_op[])(struct file *, char *, size_t) = { |
| 77 | [NFSD_Svc] = write_svc, |
| 78 | [NFSD_Add] = write_add, |
| 79 | [NFSD_Del] = write_del, |
| 80 | [NFSD_Export] = write_export, |
| 81 | [NFSD_Unexport] = write_unexport, |
| 82 | [NFSD_Getfd] = write_getfd, |
| 83 | [NFSD_Getfs] = write_getfs, |
| 84 | [NFSD_Fh] = write_filehandle, |
Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 85 | [NFSD_FO_UnlockIP] = write_unlock_ip, |
| 86 | [NFSD_FO_UnlockFS] = write_unlock_fs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | [NFSD_Threads] = write_threads, |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 88 | [NFSD_Pool_Threads] = write_pool_threads, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 89 | [NFSD_Versions] = write_versions, |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 90 | [NFSD_Ports] = write_ports, |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 91 | [NFSD_MaxBlkSize] = write_maxblksize, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 92 | #ifdef CONFIG_NFSD_V4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | [NFSD_Leasetime] = write_leasetime, |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 94 | [NFSD_RecoveryDir] = write_recoverydir, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 95 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) |
| 99 | { |
Josef "Jeff" Sipek | 7eaa36e | 2006-12-08 02:36:41 -0800 | [diff] [blame] | 100 | ino_t ino = file->f_path.dentry->d_inode->i_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | char *data; |
| 102 | ssize_t rv; |
| 103 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 104 | if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | return -EINVAL; |
| 106 | |
| 107 | data = simple_transaction_get(file, buf, size); |
| 108 | if (IS_ERR(data)) |
| 109 | return PTR_ERR(data); |
| 110 | |
| 111 | rv = write_op[ino](file, data, size); |
NeilBrown | 8971a10 | 2007-02-14 00:33:11 -0800 | [diff] [blame] | 112 | if (rv >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | simple_transaction_set(file, rv); |
| 114 | rv = size; |
| 115 | } |
| 116 | return rv; |
| 117 | } |
| 118 | |
NeilBrown | 7390022 | 2005-11-07 01:00:24 -0800 | [diff] [blame] | 119 | static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) |
| 120 | { |
| 121 | if (! file->private_data) { |
| 122 | /* An attempt to read a transaction file without writing |
| 123 | * causes a 0-byte write so that the file can return |
| 124 | * state information |
| 125 | */ |
| 126 | ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); |
| 127 | if (rv < 0) |
| 128 | return rv; |
| 129 | } |
| 130 | return simple_transaction_read(file, buf, size, pos); |
| 131 | } |
| 132 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 133 | static const struct file_operations transaction_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | .write = nfsctl_transaction_write, |
NeilBrown | 7390022 | 2005-11-07 01:00:24 -0800 | [diff] [blame] | 135 | .read = nfsctl_transaction_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | .release = simple_transaction_release, |
| 137 | }; |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | static int exports_open(struct inode *inode, struct file *file) |
| 140 | { |
| 141 | return seq_open(file, &nfs_exports_op); |
| 142 | } |
| 143 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 144 | static const struct file_operations exports_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | .open = exports_open, |
| 146 | .read = seq_read, |
| 147 | .llseek = seq_lseek, |
| 148 | .release = seq_release, |
Denis V. Lunev | 9ef2db2 | 2008-04-29 01:02:04 -0700 | [diff] [blame] | 149 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 152 | extern int nfsd_pool_stats_open(struct inode *inode, struct file *file); |
Ryusei Yamaguchi | ed2d8ae | 2009-08-16 00:54:41 +0900 | [diff] [blame] | 153 | extern int nfsd_pool_stats_release(struct inode *inode, struct file *file); |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 154 | |
Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 155 | static const struct file_operations pool_stats_operations = { |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 156 | .open = nfsd_pool_stats_open, |
| 157 | .read = seq_read, |
| 158 | .llseek = seq_lseek, |
Ryusei Yamaguchi | ed2d8ae | 2009-08-16 00:54:41 +0900 | [diff] [blame] | 159 | .release = nfsd_pool_stats_release, |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 160 | .owner = THIS_MODULE, |
| 161 | }; |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /*----------------------------------------------------------------------------*/ |
| 164 | /* |
| 165 | * payload - write methods |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | */ |
| 167 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 168 | /** |
| 169 | * write_svc - Start kernel's NFSD server |
| 170 | * |
| 171 | * Deprecated. /proc/fs/nfsd/threads is preferred. |
| 172 | * Function remains to support old versions of nfs-utils. |
| 173 | * |
| 174 | * Input: |
| 175 | * buf: struct nfsctl_svc |
| 176 | * svc_port: port number of this |
| 177 | * server's listener |
| 178 | * svc_nthreads: number of threads to start |
| 179 | * size: size in bytes of passed in nfsctl_svc |
| 180 | * Output: |
| 181 | * On success: returns zero |
| 182 | * On error: return code is negative errno value |
| 183 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static ssize_t write_svc(struct file *file, char *buf, size_t size) |
| 185 | { |
| 186 | struct nfsctl_svc *data; |
NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 187 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | if (size < sizeof(*data)) |
| 189 | return -EINVAL; |
| 190 | data = (struct nfsctl_svc*) buf; |
NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 191 | err = nfsd_svc(data->svc_port, data->svc_nthreads); |
| 192 | if (err < 0) |
| 193 | return err; |
| 194 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 197 | /** |
| 198 | * write_add - Add or modify client entry in auth unix cache |
| 199 | * |
| 200 | * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. |
| 201 | * Function remains to support old versions of nfs-utils. |
| 202 | * |
| 203 | * Input: |
| 204 | * buf: struct nfsctl_client |
| 205 | * cl_ident: '\0'-terminated C string |
| 206 | * containing domain name |
| 207 | * of client |
| 208 | * cl_naddr: no. of items in cl_addrlist |
| 209 | * cl_addrlist: array of client addresses |
| 210 | * cl_fhkeytype: ignored |
| 211 | * cl_fhkeylen: ignored |
| 212 | * cl_fhkey: ignored |
| 213 | * size: size in bytes of passed in nfsctl_client |
| 214 | * Output: |
| 215 | * On success: returns zero |
| 216 | * On error: return code is negative errno value |
| 217 | * |
| 218 | * Note: Only AF_INET client addresses are passed in, since |
| 219 | * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. |
| 220 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | static ssize_t write_add(struct file *file, char *buf, size_t size) |
| 222 | { |
| 223 | struct nfsctl_client *data; |
| 224 | if (size < sizeof(*data)) |
| 225 | return -EINVAL; |
| 226 | data = (struct nfsctl_client *)buf; |
| 227 | return exp_addclient(data); |
| 228 | } |
| 229 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 230 | /** |
| 231 | * write_del - Remove client from auth unix cache |
| 232 | * |
| 233 | * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. |
| 234 | * Function remains to support old versions of nfs-utils. |
| 235 | * |
| 236 | * Input: |
| 237 | * buf: struct nfsctl_client |
| 238 | * cl_ident: '\0'-terminated C string |
| 239 | * containing domain name |
| 240 | * of client |
| 241 | * cl_naddr: ignored |
| 242 | * cl_addrlist: ignored |
| 243 | * cl_fhkeytype: ignored |
| 244 | * cl_fhkeylen: ignored |
| 245 | * cl_fhkey: ignored |
| 246 | * size: size in bytes of passed in nfsctl_client |
| 247 | * Output: |
| 248 | * On success: returns zero |
| 249 | * On error: return code is negative errno value |
| 250 | * |
| 251 | * Note: Only AF_INET client addresses are passed in, since |
| 252 | * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. |
| 253 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | static ssize_t write_del(struct file *file, char *buf, size_t size) |
| 255 | { |
| 256 | struct nfsctl_client *data; |
| 257 | if (size < sizeof(*data)) |
| 258 | return -EINVAL; |
| 259 | data = (struct nfsctl_client *)buf; |
| 260 | return exp_delclient(data); |
| 261 | } |
| 262 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 263 | /** |
| 264 | * write_export - Export part or all of a local file system |
| 265 | * |
| 266 | * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. |
| 267 | * Function remains to support old versions of nfs-utils. |
| 268 | * |
| 269 | * Input: |
| 270 | * buf: struct nfsctl_export |
| 271 | * ex_client: '\0'-terminated C string |
| 272 | * containing domain name |
| 273 | * of client allowed to access |
| 274 | * this export |
| 275 | * ex_path: '\0'-terminated C string |
| 276 | * containing pathname of |
| 277 | * directory in local file system |
| 278 | * ex_dev: fsid to use for this export |
| 279 | * ex_ino: ignored |
| 280 | * ex_flags: export flags for this export |
| 281 | * ex_anon_uid: UID to use for anonymous |
| 282 | * requests |
| 283 | * ex_anon_gid: GID to use for anonymous |
| 284 | * requests |
| 285 | * size: size in bytes of passed in nfsctl_export |
| 286 | * Output: |
| 287 | * On success: returns zero |
| 288 | * On error: return code is negative errno value |
| 289 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | static ssize_t write_export(struct file *file, char *buf, size_t size) |
| 291 | { |
| 292 | struct nfsctl_export *data; |
| 293 | if (size < sizeof(*data)) |
| 294 | return -EINVAL; |
| 295 | data = (struct nfsctl_export*)buf; |
| 296 | return exp_export(data); |
| 297 | } |
| 298 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 299 | /** |
| 300 | * write_unexport - Unexport a previously exported file system |
| 301 | * |
| 302 | * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. |
| 303 | * Function remains to support old versions of nfs-utils. |
| 304 | * |
| 305 | * Input: |
| 306 | * buf: struct nfsctl_export |
| 307 | * ex_client: '\0'-terminated C string |
| 308 | * containing domain name |
| 309 | * of client no longer allowed |
| 310 | * to access this export |
| 311 | * ex_path: '\0'-terminated C string |
| 312 | * containing pathname of |
| 313 | * directory in local file system |
| 314 | * ex_dev: ignored |
| 315 | * ex_ino: ignored |
| 316 | * ex_flags: ignored |
| 317 | * ex_anon_uid: ignored |
| 318 | * ex_anon_gid: ignored |
| 319 | * size: size in bytes of passed in nfsctl_export |
| 320 | * Output: |
| 321 | * On success: returns zero |
| 322 | * On error: return code is negative errno value |
| 323 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | static ssize_t write_unexport(struct file *file, char *buf, size_t size) |
| 325 | { |
| 326 | struct nfsctl_export *data; |
| 327 | |
| 328 | if (size < sizeof(*data)) |
| 329 | return -EINVAL; |
| 330 | data = (struct nfsctl_export*)buf; |
| 331 | return exp_unexport(data); |
| 332 | } |
| 333 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 334 | /** |
| 335 | * write_getfs - Get a variable-length NFS file handle by path |
| 336 | * |
| 337 | * Deprecated. /proc/fs/nfsd/filehandle is preferred. |
| 338 | * Function remains to support old versions of nfs-utils. |
| 339 | * |
| 340 | * Input: |
| 341 | * buf: struct nfsctl_fsparm |
| 342 | * gd_addr: socket address of client |
| 343 | * gd_path: '\0'-terminated C string |
| 344 | * containing pathname of |
| 345 | * directory in local file system |
| 346 | * gd_maxlen: maximum size of returned file |
| 347 | * handle |
| 348 | * size: size in bytes of passed in nfsctl_fsparm |
| 349 | * Output: |
| 350 | * On success: passed-in buffer filled with a knfsd_fh structure |
| 351 | * (a variable-length raw NFS file handle); |
| 352 | * return code is the size in bytes of the file handle |
| 353 | * On error: return code is negative errno value |
| 354 | * |
| 355 | * Note: Only AF_INET client addresses are passed in, since gd_addr |
| 356 | * is the same size as a struct sockaddr_in. |
| 357 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | static ssize_t write_getfs(struct file *file, char *buf, size_t size) |
| 359 | { |
| 360 | struct nfsctl_fsparm *data; |
| 361 | struct sockaddr_in *sin; |
| 362 | struct auth_domain *clp; |
| 363 | int err = 0; |
| 364 | struct knfsd_fh *res; |
Aurélien Charbon | f15364b | 2008-01-18 15:50:56 +0100 | [diff] [blame] | 365 | struct in6_addr in6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | if (size < sizeof(*data)) |
| 368 | return -EINVAL; |
| 369 | data = (struct nfsctl_fsparm*)buf; |
| 370 | err = -EPROTONOSUPPORT; |
| 371 | if (data->gd_addr.sa_family != AF_INET) |
| 372 | goto out; |
| 373 | sin = (struct sockaddr_in *)&data->gd_addr; |
| 374 | if (data->gd_maxlen > NFS3_FHSIZE) |
| 375 | data->gd_maxlen = NFS3_FHSIZE; |
| 376 | |
| 377 | res = (struct knfsd_fh*)buf; |
| 378 | |
| 379 | exp_readlock(); |
Aurélien Charbon | f15364b | 2008-01-18 15:50:56 +0100 | [diff] [blame] | 380 | |
| 381 | ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); |
| 382 | |
| 383 | clp = auth_unix_lookup(&in6); |
| 384 | if (!clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | err = -EPERM; |
| 386 | else { |
| 387 | err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen); |
| 388 | auth_domain_put(clp); |
| 389 | } |
| 390 | exp_readunlock(); |
| 391 | if (err == 0) |
Andrew Morton | 1212749 | 2007-07-17 04:04:34 -0700 | [diff] [blame] | 392 | err = res->fh_size + offsetof(struct knfsd_fh, fh_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | out: |
| 394 | return err; |
| 395 | } |
| 396 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 397 | /** |
| 398 | * write_getfd - Get a fixed-length NFS file handle by path (used by mountd) |
| 399 | * |
| 400 | * Deprecated. /proc/fs/nfsd/filehandle is preferred. |
| 401 | * Function remains to support old versions of nfs-utils. |
| 402 | * |
| 403 | * Input: |
| 404 | * buf: struct nfsctl_fdparm |
| 405 | * gd_addr: socket address of client |
| 406 | * gd_path: '\0'-terminated C string |
| 407 | * containing pathname of |
| 408 | * directory in local file system |
| 409 | * gd_version: fdparm structure version |
| 410 | * size: size in bytes of passed in nfsctl_fdparm |
| 411 | * Output: |
| 412 | * On success: passed-in buffer filled with nfsctl_res |
| 413 | * (a fixed-length raw NFS file handle); |
| 414 | * return code is the size in bytes of the file handle |
| 415 | * On error: return code is negative errno value |
| 416 | * |
| 417 | * Note: Only AF_INET client addresses are passed in, since gd_addr |
| 418 | * is the same size as a struct sockaddr_in. |
| 419 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | static ssize_t write_getfd(struct file *file, char *buf, size_t size) |
| 421 | { |
| 422 | struct nfsctl_fdparm *data; |
| 423 | struct sockaddr_in *sin; |
| 424 | struct auth_domain *clp; |
| 425 | int err = 0; |
| 426 | struct knfsd_fh fh; |
| 427 | char *res; |
Aurélien Charbon | f15364b | 2008-01-18 15:50:56 +0100 | [diff] [blame] | 428 | struct in6_addr in6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | if (size < sizeof(*data)) |
| 431 | return -EINVAL; |
| 432 | data = (struct nfsctl_fdparm*)buf; |
| 433 | err = -EPROTONOSUPPORT; |
| 434 | if (data->gd_addr.sa_family != AF_INET) |
| 435 | goto out; |
| 436 | err = -EINVAL; |
| 437 | if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS) |
| 438 | goto out; |
| 439 | |
| 440 | res = buf; |
| 441 | sin = (struct sockaddr_in *)&data->gd_addr; |
| 442 | exp_readlock(); |
Aurélien Charbon | f15364b | 2008-01-18 15:50:56 +0100 | [diff] [blame] | 443 | |
| 444 | ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); |
| 445 | |
| 446 | clp = auth_unix_lookup(&in6); |
| 447 | if (!clp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | err = -EPERM; |
| 449 | else { |
| 450 | err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE); |
| 451 | auth_domain_put(clp); |
| 452 | } |
| 453 | exp_readunlock(); |
| 454 | |
| 455 | if (err == 0) { |
| 456 | memset(res,0, NFS_FHSIZE); |
| 457 | memcpy(res, &fh.fh_base, fh.fh_size); |
| 458 | err = NFS_FHSIZE; |
| 459 | } |
| 460 | out: |
| 461 | return err; |
| 462 | } |
| 463 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 464 | /** |
| 465 | * write_unlock_ip - Release all locks used by a client |
| 466 | * |
| 467 | * Experimental. |
| 468 | * |
| 469 | * Input: |
| 470 | * buf: '\n'-terminated C string containing a |
Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 471 | * presentation format IP address |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 472 | * size: length of C string in @buf |
| 473 | * Output: |
| 474 | * On success: returns zero if all specified locks were released; |
| 475 | * returns one if one or more locks were not released |
| 476 | * On error: return code is negative errno value |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 477 | */ |
Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 478 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 479 | { |
Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 480 | struct sockaddr_storage address; |
| 481 | struct sockaddr *sap = (struct sockaddr *)&address; |
| 482 | size_t salen = sizeof(address); |
Chuck Lever | 367c8c7 | 2008-06-30 18:58:14 -0400 | [diff] [blame] | 483 | char *fo_path; |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 484 | |
| 485 | /* sanity check */ |
| 486 | if (size == 0) |
| 487 | return -EINVAL; |
| 488 | |
| 489 | if (buf[size-1] != '\n') |
| 490 | return -EINVAL; |
| 491 | |
| 492 | fo_path = buf; |
| 493 | if (qword_get(&buf, fo_path, size) < 0) |
| 494 | return -EINVAL; |
| 495 | |
Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 496 | if (rpc_pton(fo_path, size, sap, salen) == 0) |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 497 | return -EINVAL; |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 498 | |
Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 499 | return nlmsvc_unlock_all_by_ip(sap); |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 502 | /** |
| 503 | * write_unlock_fs - Release all locks on a local file system |
| 504 | * |
| 505 | * Experimental. |
| 506 | * |
| 507 | * Input: |
| 508 | * buf: '\n'-terminated C string containing the |
| 509 | * absolute pathname of a local file system |
| 510 | * size: length of C string in @buf |
| 511 | * Output: |
| 512 | * On success: returns zero if all specified locks were released; |
| 513 | * returns one if one or more locks were not released |
| 514 | * On error: return code is negative errno value |
| 515 | */ |
Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 516 | static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 517 | { |
Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 518 | struct path path; |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 519 | char *fo_path; |
| 520 | int error; |
| 521 | |
| 522 | /* sanity check */ |
| 523 | if (size == 0) |
| 524 | return -EINVAL; |
| 525 | |
| 526 | if (buf[size-1] != '\n') |
| 527 | return -EINVAL; |
| 528 | |
| 529 | fo_path = buf; |
| 530 | if (qword_get(&buf, fo_path, size) < 0) |
| 531 | return -EINVAL; |
| 532 | |
Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 533 | error = kern_path(fo_path, 0, &path); |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 534 | if (error) |
| 535 | return error; |
| 536 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 537 | /* |
| 538 | * XXX: Needs better sanity checking. Otherwise we could end up |
| 539 | * releasing locks on the wrong file system. |
| 540 | * |
| 541 | * For example: |
| 542 | * 1. Does the path refer to a directory? |
| 543 | * 2. Is that directory a mount point, or |
| 544 | * 3. Is that directory the root of an exported file system? |
| 545 | */ |
Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 546 | error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb); |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 547 | |
Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 548 | path_put(&path); |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 549 | return error; |
| 550 | } |
| 551 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 552 | /** |
| 553 | * write_filehandle - Get a variable-length NFS file handle by path |
| 554 | * |
| 555 | * On input, the buffer contains a '\n'-terminated C string comprised of |
| 556 | * three alphanumeric words separated by whitespace. The string may |
| 557 | * contain escape sequences. |
| 558 | * |
| 559 | * Input: |
| 560 | * buf: |
| 561 | * domain: client domain name |
| 562 | * path: export pathname |
| 563 | * maxsize: numeric maximum size of |
| 564 | * @buf |
| 565 | * size: length of C string in @buf |
| 566 | * Output: |
| 567 | * On success: passed-in buffer filled with '\n'-terminated C |
| 568 | * string containing a ASCII hex text version |
| 569 | * of the NFS file handle; |
| 570 | * return code is the size in bytes of the string |
| 571 | * On error: return code is negative errno value |
| 572 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size) |
| 574 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | char *dname, *path; |
Andrew Morton | 246d95b | 2007-08-09 00:53:50 -0700 | [diff] [blame] | 576 | int uninitialized_var(maxsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | char *mesg = buf; |
| 578 | int len; |
| 579 | struct auth_domain *dom; |
| 580 | struct knfsd_fh fh; |
| 581 | |
J. Bruce Fields | 87d26ea | 2008-01-22 17:40:42 -0500 | [diff] [blame] | 582 | if (size == 0) |
| 583 | return -EINVAL; |
| 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | if (buf[size-1] != '\n') |
| 586 | return -EINVAL; |
| 587 | buf[size-1] = 0; |
| 588 | |
| 589 | dname = mesg; |
| 590 | len = qword_get(&mesg, dname, size); |
Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 591 | if (len <= 0) |
| 592 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | path = dname+len+1; |
| 595 | len = qword_get(&mesg, path, size); |
Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 596 | if (len <= 0) |
| 597 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
| 599 | len = get_int(&mesg, &maxsize); |
| 600 | if (len) |
| 601 | return len; |
| 602 | |
| 603 | if (maxsize < NFS_FHSIZE) |
| 604 | return -EINVAL; |
| 605 | if (maxsize > NFS3_FHSIZE) |
| 606 | maxsize = NFS3_FHSIZE; |
| 607 | |
| 608 | if (qword_get(&mesg, mesg, size)>0) |
| 609 | return -EINVAL; |
| 610 | |
| 611 | /* we have all the words, they are in buf.. */ |
| 612 | dom = unix_domain_find(dname); |
| 613 | if (!dom) |
| 614 | return -ENOMEM; |
| 615 | |
| 616 | len = exp_rootfh(dom, path, &fh, maxsize); |
| 617 | auth_domain_put(dom); |
| 618 | if (len) |
| 619 | return len; |
| 620 | |
Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 621 | mesg = buf; |
| 622 | len = SIMPLE_TRANSACTION_LIMIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); |
| 624 | mesg[-1] = '\n'; |
| 625 | return mesg - buf; |
| 626 | } |
| 627 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 628 | /** |
| 629 | * write_threads - Start NFSD, or report the current number of running threads |
| 630 | * |
| 631 | * Input: |
| 632 | * buf: ignored |
| 633 | * size: zero |
| 634 | * Output: |
| 635 | * On success: passed-in buffer filled with '\n'-terminated C |
| 636 | * string numeric value representing the number of |
| 637 | * running NFSD threads; |
| 638 | * return code is the size in bytes of the string |
| 639 | * On error: return code is zero |
| 640 | * |
| 641 | * OR |
| 642 | * |
| 643 | * Input: |
| 644 | * buf: C string containing an unsigned |
| 645 | * integer value representing the |
| 646 | * number of NFSD threads to start |
| 647 | * size: non-zero length of C string in @buf |
| 648 | * Output: |
| 649 | * On success: NFS service is started; |
| 650 | * passed-in buffer filled with '\n'-terminated C |
| 651 | * string numeric value representing the number of |
| 652 | * running NFSD threads; |
| 653 | * return code is the size in bytes of the string |
| 654 | * On error: return code is zero or a negative errno value |
| 655 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | static ssize_t write_threads(struct file *file, char *buf, size_t size) |
| 657 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | char *mesg = buf; |
| 659 | int rv; |
| 660 | if (size > 0) { |
| 661 | int newthreads; |
| 662 | rv = get_int(&mesg, &newthreads); |
| 663 | if (rv) |
| 664 | return rv; |
Chuck Lever | 9e07485 | 2008-12-12 16:57:27 -0500 | [diff] [blame] | 665 | if (newthreads < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return -EINVAL; |
Chuck Lever | 9e07485 | 2008-12-12 16:57:27 -0500 | [diff] [blame] | 667 | rv = nfsd_svc(NFS_PORT, newthreads); |
NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 668 | if (rv < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return rv; |
NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 670 | } else |
| 671 | rv = nfsd_nrthreads(); |
Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 672 | |
NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 673 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 676 | /** |
| 677 | * write_pool_threads - Set or report the current number of threads per pool |
| 678 | * |
| 679 | * Input: |
| 680 | * buf: ignored |
| 681 | * size: zero |
| 682 | * |
| 683 | * OR |
| 684 | * |
| 685 | * Input: |
| 686 | * buf: C string containing whitespace- |
| 687 | * separated unsigned integer values |
| 688 | * representing the number of NFSD |
| 689 | * threads to start in each pool |
| 690 | * size: non-zero length of C string in @buf |
| 691 | * Output: |
| 692 | * On success: passed-in buffer filled with '\n'-terminated C |
| 693 | * string containing integer values representing the |
| 694 | * number of NFSD threads in each pool; |
| 695 | * return code is the size in bytes of the string |
| 696 | * On error: return code is zero or a negative errno value |
| 697 | */ |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 698 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) |
| 699 | { |
| 700 | /* if size > 0, look for an array of number of threads per node |
| 701 | * and apply them then write out number of threads per node as reply |
| 702 | */ |
| 703 | char *mesg = buf; |
| 704 | int i; |
| 705 | int rv; |
| 706 | int len; |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 707 | int npools; |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 708 | int *nthreads; |
| 709 | |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 710 | mutex_lock(&nfsd_mutex); |
| 711 | npools = nfsd_nrpools(); |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 712 | if (npools == 0) { |
| 713 | /* |
| 714 | * NFS is shut down. The admin can start it by |
| 715 | * writing to the threads file but NOT the pool_threads |
| 716 | * file, sorry. Report zero threads. |
| 717 | */ |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 718 | mutex_unlock(&nfsd_mutex); |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 719 | strcpy(buf, "0\n"); |
| 720 | return strlen(buf); |
| 721 | } |
| 722 | |
| 723 | nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 724 | rv = -ENOMEM; |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 725 | if (nthreads == NULL) |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 726 | goto out_free; |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 727 | |
| 728 | if (size > 0) { |
| 729 | for (i = 0; i < npools; i++) { |
| 730 | rv = get_int(&mesg, &nthreads[i]); |
| 731 | if (rv == -ENOENT) |
| 732 | break; /* fewer numbers than pools */ |
| 733 | if (rv) |
| 734 | goto out_free; /* syntax error */ |
| 735 | rv = -EINVAL; |
| 736 | if (nthreads[i] < 0) |
| 737 | goto out_free; |
| 738 | } |
| 739 | rv = nfsd_set_nrthreads(i, nthreads); |
| 740 | if (rv) |
| 741 | goto out_free; |
| 742 | } |
| 743 | |
| 744 | rv = nfsd_get_nrthreads(npools, nthreads); |
| 745 | if (rv) |
| 746 | goto out_free; |
| 747 | |
| 748 | mesg = buf; |
| 749 | size = SIMPLE_TRANSACTION_LIMIT; |
| 750 | for (i = 0; i < npools && size > 0; i++) { |
| 751 | snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); |
| 752 | len = strlen(mesg); |
| 753 | size -= len; |
| 754 | mesg += len; |
| 755 | } |
J. Bruce Fields | 413d63d710 | 2009-07-28 11:37:25 -0400 | [diff] [blame] | 756 | rv = mesg - buf; |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 757 | out_free: |
| 758 | kfree(nthreads); |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 759 | mutex_unlock(&nfsd_mutex); |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 760 | return rv; |
| 761 | } |
| 762 | |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 763 | static ssize_t __write_versions(struct file *file, char *buf, size_t size) |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 764 | { |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 765 | char *mesg = buf; |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 766 | char *vers, *minorp, sign; |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 767 | int len, num, remaining; |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 768 | unsigned minor; |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 769 | ssize_t tlen = 0; |
| 770 | char *sep; |
| 771 | |
| 772 | if (size>0) { |
| 773 | if (nfsd_serv) |
NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 774 | /* Cannot change versions without updating |
| 775 | * nfsd_serv->sv_xdrsize, and reallocing |
| 776 | * rq_argp and rq_resp |
| 777 | */ |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 778 | return -EBUSY; |
| 779 | if (buf[size-1] != '\n') |
| 780 | return -EINVAL; |
| 781 | buf[size-1] = 0; |
| 782 | |
| 783 | vers = mesg; |
| 784 | len = qword_get(&mesg, vers, size); |
| 785 | if (len <= 0) return -EINVAL; |
| 786 | do { |
| 787 | sign = *vers; |
| 788 | if (sign == '+' || sign == '-') |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 789 | num = simple_strtol((vers+1), &minorp, 0); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 790 | else |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 791 | num = simple_strtol(vers, &minorp, 0); |
| 792 | if (*minorp == '.') { |
| 793 | if (num < 4) |
| 794 | return -EINVAL; |
| 795 | minor = simple_strtoul(minorp+1, NULL, 0); |
| 796 | if (minor == 0) |
| 797 | return -EINVAL; |
| 798 | if (nfsd_minorversion(minor, sign == '-' ? |
| 799 | NFSD_CLEAR : NFSD_SET) < 0) |
| 800 | return -EINVAL; |
| 801 | goto next; |
| 802 | } |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 803 | switch(num) { |
| 804 | case 2: |
| 805 | case 3: |
| 806 | case 4: |
NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 807 | nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 808 | break; |
| 809 | default: |
| 810 | return -EINVAL; |
| 811 | } |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 812 | next: |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 813 | vers += len + 1; |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 814 | } while ((len = qword_get(&mesg, vers, size)) > 0); |
| 815 | /* If all get turned off, turn them back on, as |
| 816 | * having no versions is BAD |
| 817 | */ |
NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 818 | nfsd_reset_versions(); |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 819 | } |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 820 | |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 821 | /* Now write current state into reply buffer */ |
| 822 | len = 0; |
| 823 | sep = ""; |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 824 | remaining = SIMPLE_TRANSACTION_LIMIT; |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 825 | for (num=2 ; num <= 4 ; num++) |
NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 826 | if (nfsd_vers(num, NFSD_AVAIL)) { |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 827 | len = snprintf(buf, remaining, "%s%c%d", sep, |
NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 828 | nfsd_vers(num, NFSD_TEST)?'+':'-', |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 829 | num); |
| 830 | sep = " "; |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 831 | |
| 832 | if (len > remaining) |
| 833 | break; |
| 834 | remaining -= len; |
| 835 | buf += len; |
| 836 | tlen += len; |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 837 | } |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 838 | if (nfsd_vers(4, NFSD_AVAIL)) |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 839 | for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION; |
| 840 | minor++) { |
| 841 | len = snprintf(buf, remaining, " %c4.%u", |
Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 842 | (nfsd_vers(4, NFSD_TEST) && |
| 843 | nfsd_minorversion(minor, NFSD_TEST)) ? |
| 844 | '+' : '-', |
| 845 | minor); |
Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 846 | |
| 847 | if (len > remaining) |
| 848 | break; |
| 849 | remaining -= len; |
| 850 | buf += len; |
| 851 | tlen += len; |
| 852 | } |
| 853 | |
| 854 | len = snprintf(buf, remaining, "\n"); |
| 855 | if (len > remaining) |
| 856 | return -EINVAL; |
| 857 | return tlen + len; |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 858 | } |
| 859 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 860 | /** |
| 861 | * write_versions - Set or report the available NFS protocol versions |
| 862 | * |
| 863 | * Input: |
| 864 | * buf: ignored |
| 865 | * size: zero |
| 866 | * Output: |
| 867 | * On success: passed-in buffer filled with '\n'-terminated C |
| 868 | * string containing positive or negative integer |
| 869 | * values representing the current status of each |
| 870 | * protocol version; |
| 871 | * return code is the size in bytes of the string |
| 872 | * On error: return code is zero or a negative errno value |
| 873 | * |
| 874 | * OR |
| 875 | * |
| 876 | * Input: |
| 877 | * buf: C string containing whitespace- |
| 878 | * separated positive or negative |
| 879 | * integer values representing NFS |
| 880 | * protocol versions to enable ("+n") |
| 881 | * or disable ("-n") |
| 882 | * size: non-zero length of C string in @buf |
| 883 | * Output: |
| 884 | * On success: status of zero or more protocol versions has |
| 885 | * been updated; passed-in buffer filled with |
| 886 | * '\n'-terminated C string containing positive |
| 887 | * or negative integer values representing the |
| 888 | * current status of each protocol version; |
| 889 | * return code is the size in bytes of the string |
| 890 | * On error: return code is zero or a negative errno value |
| 891 | */ |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 892 | static ssize_t write_versions(struct file *file, char *buf, size_t size) |
| 893 | { |
| 894 | ssize_t rv; |
| 895 | |
| 896 | mutex_lock(&nfsd_mutex); |
| 897 | rv = __write_versions(file, buf, size); |
| 898 | mutex_unlock(&nfsd_mutex); |
| 899 | return rv; |
| 900 | } |
| 901 | |
Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 902 | /* |
Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 903 | * Zero-length write. Return a list of NFSD's current listener |
| 904 | * transports. |
| 905 | */ |
| 906 | static ssize_t __write_ports_names(char *buf) |
| 907 | { |
| 908 | if (nfsd_serv == NULL) |
| 909 | return 0; |
Chuck Lever | 335c54b | 2009-04-23 19:32:25 -0400 | [diff] [blame] | 910 | return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); |
Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | /* |
Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 914 | * A single 'fd' number was written, in which case it must be for |
| 915 | * a socket of a supported family/protocol, and we use it as an |
| 916 | * nfsd listener. |
| 917 | */ |
| 918 | static ssize_t __write_ports_addfd(char *buf) |
| 919 | { |
| 920 | char *mesg = buf; |
| 921 | int fd, err; |
| 922 | |
| 923 | err = get_int(&mesg, &fd); |
| 924 | if (err != 0 || fd < 0) |
| 925 | return -EINVAL; |
| 926 | |
| 927 | err = nfsd_create_serv(); |
| 928 | if (err != 0) |
| 929 | return err; |
| 930 | |
Chuck Lever | ea068ba | 2009-04-23 19:32:18 -0400 | [diff] [blame] | 931 | err = lockd_up(); |
| 932 | if (err != 0) |
| 933 | goto out; |
| 934 | |
Chuck Lever | bfba9ab | 2009-04-23 19:32:33 -0400 | [diff] [blame] | 935 | err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); |
Chuck Lever | ea068ba | 2009-04-23 19:32:18 -0400 | [diff] [blame] | 936 | if (err < 0) |
| 937 | lockd_down(); |
Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 938 | |
Chuck Lever | ea068ba | 2009-04-23 19:32:18 -0400 | [diff] [blame] | 939 | out: |
| 940 | /* Decrease the count, but don't shut down the service */ |
| 941 | nfsd_serv->sv_nrthreads--; |
| 942 | return err; |
Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | /* |
Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 946 | * A '-' followed by the 'name' of a socket means we close the socket. |
| 947 | */ |
| 948 | static ssize_t __write_ports_delfd(char *buf) |
| 949 | { |
| 950 | char *toclose; |
| 951 | int len = 0; |
| 952 | |
| 953 | toclose = kstrdup(buf + 1, GFP_KERNEL); |
| 954 | if (toclose == NULL) |
| 955 | return -ENOMEM; |
| 956 | |
| 957 | if (nfsd_serv != NULL) |
Chuck Lever | 8435d34 | 2009-04-23 19:32:40 -0400 | [diff] [blame] | 958 | len = svc_sock_names(nfsd_serv, buf, |
| 959 | SIMPLE_TRANSACTION_LIMIT, toclose); |
Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 960 | if (len >= 0) |
| 961 | lockd_down(); |
| 962 | |
| 963 | kfree(toclose); |
| 964 | return len; |
| 965 | } |
| 966 | |
| 967 | /* |
Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 968 | * A transport listener is added by writing it's transport name and |
| 969 | * a port number. |
| 970 | */ |
| 971 | static ssize_t __write_ports_addxprt(char *buf) |
| 972 | { |
| 973 | char transport[16]; |
| 974 | int port, err; |
| 975 | |
| 976 | if (sscanf(buf, "%15s %4u", transport, &port) != 2) |
| 977 | return -EINVAL; |
| 978 | |
| 979 | if (port < 1 || port > USHORT_MAX) |
| 980 | return -EINVAL; |
| 981 | |
| 982 | err = nfsd_create_serv(); |
| 983 | if (err != 0) |
| 984 | return err; |
| 985 | |
| 986 | err = svc_create_xprt(nfsd_serv, transport, |
| 987 | PF_INET, port, SVC_SOCK_ANONYMOUS); |
| 988 | if (err < 0) { |
| 989 | /* Give a reasonable perror msg for bad transport string */ |
| 990 | if (err == -ENOENT) |
| 991 | err = -EPROTONOSUPPORT; |
| 992 | return err; |
| 993 | } |
| 994 | return 0; |
| 995 | } |
| 996 | |
| 997 | /* |
Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 998 | * A transport listener is removed by writing a "-", it's transport |
| 999 | * name, and it's port number. |
| 1000 | */ |
| 1001 | static ssize_t __write_ports_delxprt(char *buf) |
| 1002 | { |
| 1003 | struct svc_xprt *xprt; |
| 1004 | char transport[16]; |
| 1005 | int port; |
| 1006 | |
| 1007 | if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2) |
| 1008 | return -EINVAL; |
| 1009 | |
| 1010 | if (port < 1 || port > USHORT_MAX || nfsd_serv == NULL) |
| 1011 | return -EINVAL; |
| 1012 | |
| 1013 | xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port); |
| 1014 | if (xprt == NULL) |
| 1015 | return -ENOTCONN; |
| 1016 | |
| 1017 | svc_close_xprt(xprt); |
| 1018 | svc_xprt_put(xprt); |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1022 | static ssize_t __write_ports(struct file *file, char *buf, size_t size) |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 1023 | { |
Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 1024 | if (size == 0) |
| 1025 | return __write_ports_names(buf); |
Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 1026 | |
| 1027 | if (isdigit(buf[0])) |
| 1028 | return __write_ports_addfd(buf); |
Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 1029 | |
| 1030 | if (buf[0] == '-' && isdigit(buf[1])) |
| 1031 | return __write_ports_delfd(buf); |
Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 1032 | |
| 1033 | if (isalpha(buf[0])) |
| 1034 | return __write_ports_addxprt(buf); |
Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 1035 | |
| 1036 | if (buf[0] == '-' && isalpha(buf[1])) |
| 1037 | return __write_ports_delxprt(buf); |
| 1038 | |
NeilBrown | b41b66d | 2006-10-02 02:17:48 -0700 | [diff] [blame] | 1039 | return -EINVAL; |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1042 | /** |
| 1043 | * write_ports - Pass a socket file descriptor or transport name to listen on |
| 1044 | * |
| 1045 | * Input: |
| 1046 | * buf: ignored |
| 1047 | * size: zero |
| 1048 | * Output: |
| 1049 | * On success: passed-in buffer filled with a '\n'-terminated C |
| 1050 | * string containing a whitespace-separated list of |
| 1051 | * named NFSD listeners; |
| 1052 | * return code is the size in bytes of the string |
| 1053 | * On error: return code is zero or a negative errno value |
| 1054 | * |
| 1055 | * OR |
| 1056 | * |
| 1057 | * Input: |
| 1058 | * buf: C string containing an unsigned |
| 1059 | * integer value representing a bound |
| 1060 | * but unconnected socket that is to be |
Chuck Lever | c71206a | 2009-04-23 19:32:03 -0400 | [diff] [blame] | 1061 | * used as an NFSD listener; listen(3) |
| 1062 | * must be called for a SOCK_STREAM |
| 1063 | * socket, otherwise it is ignored |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1064 | * size: non-zero length of C string in @buf |
| 1065 | * Output: |
| 1066 | * On success: NFS service is started; |
| 1067 | * passed-in buffer filled with a '\n'-terminated C |
| 1068 | * string containing a unique alphanumeric name of |
| 1069 | * the listener; |
| 1070 | * return code is the size in bytes of the string |
| 1071 | * On error: return code is a negative errno value |
| 1072 | * |
| 1073 | * OR |
| 1074 | * |
| 1075 | * Input: |
| 1076 | * buf: C string containing a "-" followed |
| 1077 | * by an integer value representing a |
| 1078 | * previously passed in socket file |
| 1079 | * descriptor |
| 1080 | * size: non-zero length of C string in @buf |
| 1081 | * Output: |
| 1082 | * On success: NFS service no longer listens on that socket; |
| 1083 | * passed-in buffer filled with a '\n'-terminated C |
| 1084 | * string containing a unique name of the listener; |
| 1085 | * return code is the size in bytes of the string |
| 1086 | * On error: return code is a negative errno value |
| 1087 | * |
| 1088 | * OR |
| 1089 | * |
| 1090 | * Input: |
| 1091 | * buf: C string containing a transport |
| 1092 | * name and an unsigned integer value |
| 1093 | * representing the port to listen on, |
| 1094 | * separated by whitespace |
| 1095 | * size: non-zero length of C string in @buf |
| 1096 | * Output: |
| 1097 | * On success: returns zero; NFS service is started |
| 1098 | * On error: return code is a negative errno value |
| 1099 | * |
| 1100 | * OR |
| 1101 | * |
| 1102 | * Input: |
| 1103 | * buf: C string containing a "-" followed |
| 1104 | * by a transport name and an unsigned |
| 1105 | * integer value representing the port |
| 1106 | * to listen on, separated by whitespace |
| 1107 | * size: non-zero length of C string in @buf |
| 1108 | * Output: |
| 1109 | * On success: returns zero; NFS service no longer listens |
| 1110 | * on that transport |
| 1111 | * On error: return code is a negative errno value |
| 1112 | */ |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1113 | static ssize_t write_ports(struct file *file, char *buf, size_t size) |
| 1114 | { |
| 1115 | ssize_t rv; |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1116 | |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1117 | mutex_lock(&nfsd_mutex); |
| 1118 | rv = __write_ports(file, buf, size); |
| 1119 | mutex_unlock(&nfsd_mutex); |
| 1120 | return rv; |
| 1121 | } |
| 1122 | |
| 1123 | |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1124 | int nfsd_max_blksize; |
| 1125 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1126 | /** |
| 1127 | * write_maxblksize - Set or report the current NFS blksize |
| 1128 | * |
| 1129 | * Input: |
| 1130 | * buf: ignored |
| 1131 | * size: zero |
| 1132 | * |
| 1133 | * OR |
| 1134 | * |
| 1135 | * Input: |
| 1136 | * buf: C string containing an unsigned |
| 1137 | * integer value representing the new |
| 1138 | * NFS blksize |
| 1139 | * size: non-zero length of C string in @buf |
| 1140 | * Output: |
| 1141 | * On success: passed-in buffer filled with '\n'-terminated C string |
| 1142 | * containing numeric value of the current NFS blksize |
| 1143 | * setting; |
| 1144 | * return code is the size in bytes of the string |
| 1145 | * On error: return code is zero or a negative errno value |
| 1146 | */ |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1147 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) |
| 1148 | { |
| 1149 | char *mesg = buf; |
| 1150 | if (size > 0) { |
| 1151 | int bsize; |
| 1152 | int rv = get_int(&mesg, &bsize); |
| 1153 | if (rv) |
| 1154 | return rv; |
| 1155 | /* force bsize into allowed range and |
| 1156 | * required alignment. |
| 1157 | */ |
| 1158 | if (bsize < 1024) |
| 1159 | bsize = 1024; |
| 1160 | if (bsize > NFSSVC_MAXBLKSIZE) |
| 1161 | bsize = NFSSVC_MAXBLKSIZE; |
| 1162 | bsize &= ~(1024-1); |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1163 | mutex_lock(&nfsd_mutex); |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1164 | if (nfsd_serv && nfsd_serv->sv_nrthreads) { |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1165 | mutex_unlock(&nfsd_mutex); |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1166 | return -EBUSY; |
| 1167 | } |
| 1168 | nfsd_max_blksize = bsize; |
Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 1169 | mutex_unlock(&nfsd_mutex); |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1170 | } |
Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 1171 | |
| 1172 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", |
| 1173 | nfsd_max_blksize); |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 1176 | #ifdef CONFIG_NFSD_V4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | extern time_t nfs4_leasetime(void); |
| 1178 | |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1179 | static ssize_t __write_leasetime(struct file *file, char *buf, size_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | { |
| 1181 | /* if size > 10 seconds, call |
| 1182 | * nfs4_reset_lease() then write out the new lease (seconds) as reply |
| 1183 | */ |
| 1184 | char *mesg = buf; |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1185 | int rv, lease; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (size > 0) { |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1188 | if (nfsd_serv) |
| 1189 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | rv = get_int(&mesg, &lease); |
| 1191 | if (rv) |
| 1192 | return rv; |
| 1193 | if (lease < 10 || lease > 3600) |
| 1194 | return -EINVAL; |
| 1195 | nfs4_reset_lease(lease); |
| 1196 | } |
Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 1197 | |
| 1198 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", |
| 1199 | nfs4_lease_time()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1202 | /** |
| 1203 | * write_leasetime - Set or report the current NFSv4 lease time |
| 1204 | * |
| 1205 | * Input: |
| 1206 | * buf: ignored |
| 1207 | * size: zero |
| 1208 | * |
| 1209 | * OR |
| 1210 | * |
| 1211 | * Input: |
| 1212 | * buf: C string containing an unsigned |
| 1213 | * integer value representing the new |
| 1214 | * NFSv4 lease expiry time |
| 1215 | * size: non-zero length of C string in @buf |
| 1216 | * Output: |
| 1217 | * On success: passed-in buffer filled with '\n'-terminated C |
| 1218 | * string containing unsigned integer value of the |
| 1219 | * current lease expiry time; |
| 1220 | * return code is the size in bytes of the string |
| 1221 | * On error: return code is zero or a negative errno value |
| 1222 | */ |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1223 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size) |
| 1224 | { |
| 1225 | ssize_t rv; |
| 1226 | |
| 1227 | mutex_lock(&nfsd_mutex); |
| 1228 | rv = __write_leasetime(file, buf, size); |
| 1229 | mutex_unlock(&nfsd_mutex); |
| 1230 | return rv; |
| 1231 | } |
| 1232 | |
| 1233 | extern char *nfs4_recoverydir(void); |
| 1234 | |
| 1235 | static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1236 | { |
| 1237 | char *mesg = buf; |
| 1238 | char *recdir; |
| 1239 | int len, status; |
| 1240 | |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1241 | if (size > 0) { |
| 1242 | if (nfsd_serv) |
| 1243 | return -EBUSY; |
| 1244 | if (size > PATH_MAX || buf[size-1] != '\n') |
| 1245 | return -EINVAL; |
| 1246 | buf[size-1] = 0; |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1247 | |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1248 | recdir = mesg; |
| 1249 | len = qword_get(&mesg, recdir, size); |
| 1250 | if (len <= 0) |
| 1251 | return -EINVAL; |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1252 | |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1253 | status = nfs4_reset_recoverydir(recdir); |
| 1254 | } |
Chuck Lever | 3d72ab8 | 2009-04-23 19:33:10 -0400 | [diff] [blame] | 1255 | |
| 1256 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", |
| 1257 | nfs4_recoverydir()); |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1258 | } |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1259 | |
Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1260 | /** |
| 1261 | * write_recoverydir - Set or report the pathname of the recovery directory |
| 1262 | * |
| 1263 | * Input: |
| 1264 | * buf: ignored |
| 1265 | * size: zero |
| 1266 | * |
| 1267 | * OR |
| 1268 | * |
| 1269 | * Input: |
| 1270 | * buf: C string containing the pathname |
| 1271 | * of the directory on a local file |
| 1272 | * system containing permanent NFSv4 |
| 1273 | * recovery data |
| 1274 | * size: non-zero length of C string in @buf |
| 1275 | * Output: |
| 1276 | * On success: passed-in buffer filled with '\n'-terminated C string |
| 1277 | * containing the current recovery pathname setting; |
| 1278 | * return code is the size in bytes of the string |
| 1279 | * On error: return code is zero or a negative errno value |
| 1280 | */ |
Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1281 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) |
| 1282 | { |
| 1283 | ssize_t rv; |
| 1284 | |
| 1285 | mutex_lock(&nfsd_mutex); |
| 1286 | rv = __write_recoverydir(file, buf, size); |
| 1287 | mutex_unlock(&nfsd_mutex); |
| 1288 | return rv; |
| 1289 | } |
| 1290 | |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 1291 | #endif |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | /*----------------------------------------------------------------------------*/ |
| 1294 | /* |
| 1295 | * populating the filesystem. |
| 1296 | */ |
| 1297 | |
| 1298 | static int nfsd_fill_super(struct super_block * sb, void * data, int silent) |
| 1299 | { |
| 1300 | static struct tree_descr nfsd_files[] = { |
| 1301 | [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR}, |
| 1302 | [NFSD_Add] = {".add", &transaction_ops, S_IWUSR}, |
| 1303 | [NFSD_Del] = {".del", &transaction_ops, S_IWUSR}, |
| 1304 | [NFSD_Export] = {".export", &transaction_ops, S_IWUSR}, |
| 1305 | [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR}, |
| 1306 | [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR}, |
| 1307 | [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR}, |
| 1308 | [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, |
Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 1309 | [NFSD_FO_UnlockIP] = {"unlock_ip", |
| 1310 | &transaction_ops, S_IWUSR|S_IRUSR}, |
Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 1311 | [NFSD_FO_UnlockFS] = {"unlock_filesystem", |
| 1312 | &transaction_ops, S_IWUSR|S_IRUSR}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, |
| 1314 | [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, |
Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 1315 | [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, |
Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 1316 | [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, |
NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 1317 | [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, |
NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 1318 | [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, |
NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1319 | [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | #ifdef CONFIG_NFSD_V4 |
| 1321 | [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, |
NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1322 | [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | #endif |
| 1324 | /* last one */ {""} |
| 1325 | }; |
| 1326 | return simple_fill_super(sb, 0x6e667364, nfsd_files); |
| 1327 | } |
| 1328 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1329 | static int nfsd_get_sb(struct file_system_type *fs_type, |
| 1330 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1332 | return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | static struct file_system_type nfsd_fs_type = { |
| 1336 | .owner = THIS_MODULE, |
| 1337 | .name = "nfsd", |
| 1338 | .get_sb = nfsd_get_sb, |
| 1339 | .kill_sb = kill_litter_super, |
| 1340 | }; |
| 1341 | |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1342 | #ifdef CONFIG_PROC_FS |
| 1343 | static int create_proc_exports_entry(void) |
| 1344 | { |
| 1345 | struct proc_dir_entry *entry; |
| 1346 | |
| 1347 | entry = proc_mkdir("fs/nfs", NULL); |
| 1348 | if (!entry) |
| 1349 | return -ENOMEM; |
Denis V. Lunev | 9ef2db2 | 2008-04-29 01:02:04 -0700 | [diff] [blame] | 1350 | entry = proc_create("exports", 0, entry, &exports_operations); |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1351 | if (!entry) |
| 1352 | return -ENOMEM; |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1353 | return 0; |
| 1354 | } |
| 1355 | #else /* CONFIG_PROC_FS */ |
| 1356 | static int create_proc_exports_entry(void) |
| 1357 | { |
| 1358 | return 0; |
| 1359 | } |
| 1360 | #endif |
| 1361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | static int __init init_nfsd(void) |
| 1363 | { |
| 1364 | int retval; |
| 1365 | printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); |
| 1366 | |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 1367 | retval = nfs4_state_init(); /* nfs4 locking state */ |
| 1368 | if (retval) |
| 1369 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | nfsd_stat_init(); /* Statistics */ |
J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1371 | retval = nfsd_reply_cache_init(); |
| 1372 | if (retval) |
| 1373 | goto out_free_stat; |
J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1374 | retval = nfsd_export_init(); |
| 1375 | if (retval) |
| 1376 | goto out_free_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | nfsd_lockd_init(); /* lockd->nfsd callbacks */ |
J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1378 | retval = nfsd_idmap_init(); |
| 1379 | if (retval) |
| 1380 | goto out_free_lockd; |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1381 | retval = create_proc_exports_entry(); |
| 1382 | if (retval) |
| 1383 | goto out_free_idmap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | retval = register_filesystem(&nfsd_fs_type); |
J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1385 | if (retval) |
| 1386 | goto out_free_all; |
| 1387 | return 0; |
| 1388 | out_free_all: |
J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1389 | remove_proc_entry("fs/nfs/exports", NULL); |
| 1390 | remove_proc_entry("fs/nfs", NULL); |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1391 | out_free_idmap: |
J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1392 | nfsd_idmap_shutdown(); |
| 1393 | out_free_lockd: |
J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1394 | nfsd_lockd_shutdown(); |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1395 | nfsd_export_shutdown(); |
J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1396 | out_free_cache: |
J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1397 | nfsd_reply_cache_shutdown(); |
J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1398 | out_free_stat: |
| 1399 | nfsd_stat_shutdown(); |
J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1400 | nfsd4_free_slabs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | return retval; |
| 1402 | } |
| 1403 | |
| 1404 | static void __exit exit_nfsd(void) |
| 1405 | { |
| 1406 | nfsd_export_shutdown(); |
J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1407 | nfsd_reply_cache_shutdown(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | remove_proc_entry("fs/nfs/exports", NULL); |
| 1409 | remove_proc_entry("fs/nfs", NULL); |
| 1410 | nfsd_stat_shutdown(); |
| 1411 | nfsd_lockd_shutdown(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | nfsd_idmap_shutdown(); |
J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 1413 | nfsd4_free_slabs(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | unregister_filesystem(&nfsd_fs_type); |
| 1415 | } |
| 1416 | |
| 1417 | MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); |
| 1418 | MODULE_LICENSE("GPL"); |
| 1419 | module_init(init_nfsd) |
| 1420 | module_exit(exit_nfsd) |