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