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