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