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