| 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> | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 12 | #include <linux/lockd/lockd.h> | 
| Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 13 | #include <linux/sunrpc/clnt.h> | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 14 | #include <linux/sunrpc/gss_api.h> | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 15 | #include <linux/sunrpc/gss_krb5_enctypes.h> | 
| Paul Gortmaker | 143cb49 | 2011-07-01 14:23:34 -0400 | [diff] [blame] | 16 | #include <linux/module.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  | 
| J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 18 | #include "idmap.h" | 
| Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 19 | #include "nfsd.h" | 
|  | 20 | #include "cache.h" | 
| Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 21 | #include "fault_inject.h" | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 22 | #include "netns.h" | 
| Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 25 | *	We have a single directory with several nodes in it. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ | 
|  | 27 | enum { | 
|  | 28 | NFSD_Root = 1, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | NFSD_List, | 
| J. Bruce Fields | e8e8753 | 2009-12-14 12:53:32 -0500 | [diff] [blame] | 30 | NFSD_Export_features, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | NFSD_Fh, | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 32 | NFSD_FO_UnlockIP, | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 33 | NFSD_FO_UnlockFS, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | NFSD_Threads, | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 35 | NFSD_Pool_Threads, | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 36 | NFSD_Pool_Stats, | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 37 | NFSD_Versions, | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 38 | NFSD_Ports, | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 39 | NFSD_MaxBlkSize, | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 40 | NFSD_SupportedEnctypes, | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 41 | /* | 
|  | 42 | * The below MUST come last.  Otherwise we leave a hole in nfsd_files[] | 
|  | 43 | * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops | 
|  | 44 | */ | 
|  | 45 | #ifdef CONFIG_NFSD_V4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | NFSD_Leasetime, | 
| J. Bruce Fields | efc4bb4 | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 47 | NFSD_Gracetime, | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 48 | NFSD_RecoveryDir, | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 49 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; | 
|  | 51 |  | 
|  | 52 | /* | 
|  | 53 | * write() for these nodes. | 
|  | 54 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 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] | 56 | static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); | 
|  | 57 | 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] | 58 | 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] | 59 | 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] | 60 | static ssize_t write_versions(struct file *file, char *buf, size_t size); | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 61 | static ssize_t write_ports(struct file *file, char *buf, size_t size); | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 62 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 63 | #ifdef CONFIG_NFSD_V4 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size); | 
| J. Bruce Fields | efc4bb4 | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 65 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size); | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 66 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 67 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
|  | 69 | static ssize_t (*write_op[])(struct file *, char *, size_t) = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | [NFSD_Fh] = write_filehandle, | 
| Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 71 | [NFSD_FO_UnlockIP] = write_unlock_ip, | 
|  | 72 | [NFSD_FO_UnlockFS] = write_unlock_fs, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | [NFSD_Threads] = write_threads, | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 74 | [NFSD_Pool_Threads] = write_pool_threads, | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 75 | [NFSD_Versions] = write_versions, | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 76 | [NFSD_Ports] = write_ports, | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 77 | [NFSD_MaxBlkSize] = write_maxblksize, | 
| 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 | [NFSD_Leasetime] = write_leasetime, | 
| J. Bruce Fields | efc4bb4 | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 80 | [NFSD_Gracetime] = write_gracetime, | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 81 | [NFSD_RecoveryDir] = write_recoverydir, | 
| 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 |  | 
|  | 85 | static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) | 
|  | 86 | { | 
| Josef "Jeff" Sipek | 7eaa36e | 2006-12-08 02:36:41 -0800 | [diff] [blame] | 87 | ino_t ino =  file->f_path.dentry->d_inode->i_ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | char *data; | 
|  | 89 | ssize_t rv; | 
|  | 90 |  | 
| Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 91 | if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return -EINVAL; | 
|  | 93 |  | 
|  | 94 | data = simple_transaction_get(file, buf, size); | 
|  | 95 | if (IS_ERR(data)) | 
|  | 96 | return PTR_ERR(data); | 
|  | 97 |  | 
|  | 98 | rv =  write_op[ino](file, data, size); | 
| NeilBrown | 8971a10 | 2007-02-14 00:33:11 -0800 | [diff] [blame] | 99 | if (rv >= 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | simple_transaction_set(file, rv); | 
|  | 101 | rv = size; | 
|  | 102 | } | 
|  | 103 | return rv; | 
|  | 104 | } | 
|  | 105 |  | 
| NeilBrown | 7390022 | 2005-11-07 01:00:24 -0800 | [diff] [blame] | 106 | static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) | 
|  | 107 | { | 
|  | 108 | if (! file->private_data) { | 
|  | 109 | /* An attempt to read a transaction file without writing | 
|  | 110 | * causes a 0-byte write so that the file can return | 
|  | 111 | * state information | 
|  | 112 | */ | 
|  | 113 | ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); | 
|  | 114 | if (rv < 0) | 
|  | 115 | return rv; | 
|  | 116 | } | 
|  | 117 | return simple_transaction_read(file, buf, size, pos); | 
|  | 118 | } | 
|  | 119 |  | 
| Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 120 | static const struct file_operations transaction_ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | .write		= nfsctl_transaction_write, | 
| NeilBrown | 7390022 | 2005-11-07 01:00:24 -0800 | [diff] [blame] | 122 | .read		= nfsctl_transaction_read, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | .release	= simple_transaction_release, | 
| Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 124 | .llseek		= default_llseek, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | }; | 
|  | 126 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | static int exports_open(struct inode *inode, struct file *file) | 
|  | 128 | { | 
|  | 129 | return seq_open(file, &nfs_exports_op); | 
|  | 130 | } | 
|  | 131 |  | 
| Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 132 | static const struct file_operations exports_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .open		= exports_open, | 
|  | 134 | .read		= seq_read, | 
|  | 135 | .llseek		= seq_lseek, | 
|  | 136 | .release	= seq_release, | 
| Denis V. Lunev | 9ef2db2 | 2008-04-29 01:02:04 -0700 | [diff] [blame] | 137 | .owner		= THIS_MODULE, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; | 
|  | 139 |  | 
| J. Bruce Fields | e8e8753 | 2009-12-14 12:53:32 -0500 | [diff] [blame] | 140 | static int export_features_show(struct seq_file *m, void *v) | 
|  | 141 | { | 
|  | 142 | seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); | 
|  | 143 | return 0; | 
|  | 144 | } | 
|  | 145 |  | 
|  | 146 | static int export_features_open(struct inode *inode, struct file *file) | 
|  | 147 | { | 
|  | 148 | return single_open(file, export_features_show, NULL); | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | static struct file_operations export_features_operations = { | 
|  | 152 | .open		= export_features_open, | 
|  | 153 | .read		= seq_read, | 
|  | 154 | .llseek		= seq_lseek, | 
|  | 155 | .release	= single_release, | 
|  | 156 | }; | 
|  | 157 |  | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 158 | #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 159 | static int supported_enctypes_show(struct seq_file *m, void *v) | 
|  | 160 | { | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 161 | seq_printf(m, KRB5_SUPPORTED_ENCTYPES); | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 162 | return 0; | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | static int supported_enctypes_open(struct inode *inode, struct file *file) | 
|  | 166 | { | 
|  | 167 | return single_open(file, supported_enctypes_show, NULL); | 
|  | 168 | } | 
|  | 169 |  | 
|  | 170 | static struct file_operations supported_enctypes_ops = { | 
|  | 171 | .open		= supported_enctypes_open, | 
|  | 172 | .read		= seq_read, | 
|  | 173 | .llseek		= seq_lseek, | 
|  | 174 | .release	= single_release, | 
|  | 175 | }; | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 176 | #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 177 |  | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 178 | extern int nfsd_pool_stats_open(struct inode *inode, struct file *file); | 
| Ryusei Yamaguchi | ed2d8ae | 2009-08-16 00:54:41 +0900 | [diff] [blame] | 179 | extern int nfsd_pool_stats_release(struct inode *inode, struct file *file); | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 180 |  | 
| Alexey Dobriyan | 828c095 | 2009-10-01 15:43:56 -0700 | [diff] [blame] | 181 | static const struct file_operations pool_stats_operations = { | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 182 | .open		= nfsd_pool_stats_open, | 
|  | 183 | .read		= seq_read, | 
|  | 184 | .llseek		= seq_lseek, | 
| Ryusei Yamaguchi | ed2d8ae | 2009-08-16 00:54:41 +0900 | [diff] [blame] | 185 | .release	= nfsd_pool_stats_release, | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 186 | .owner		= THIS_MODULE, | 
|  | 187 | }; | 
|  | 188 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | /*----------------------------------------------------------------------------*/ | 
|  | 190 | /* | 
|  | 191 | * payload - write methods | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | */ | 
|  | 193 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 195 | /** | 
|  | 196 | * write_unlock_ip - Release all locks used by a client | 
|  | 197 | * | 
|  | 198 | * Experimental. | 
|  | 199 | * | 
|  | 200 | * Input: | 
|  | 201 | *			buf:	'\n'-terminated C string containing a | 
| Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 202 | *				presentation format IP address | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 203 | *			size:	length of C string in @buf | 
|  | 204 | * Output: | 
|  | 205 | *	On success:	returns zero if all specified locks were released; | 
|  | 206 | *			returns one if one or more locks were not released | 
|  | 207 | *	On error:	return code is negative errno value | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 208 | */ | 
| Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 209 | 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] | 210 | { | 
| Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 211 | struct sockaddr_storage address; | 
|  | 212 | struct sockaddr *sap = (struct sockaddr *)&address; | 
|  | 213 | size_t salen = sizeof(address); | 
| Chuck Lever | 367c8c7 | 2008-06-30 18:58:14 -0400 | [diff] [blame] | 214 | char *fo_path; | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 215 |  | 
|  | 216 | /* sanity check */ | 
|  | 217 | if (size == 0) | 
|  | 218 | return -EINVAL; | 
|  | 219 |  | 
|  | 220 | if (buf[size-1] != '\n') | 
|  | 221 | return -EINVAL; | 
|  | 222 |  | 
|  | 223 | fo_path = buf; | 
|  | 224 | if (qword_get(&buf, fo_path, size) < 0) | 
|  | 225 | return -EINVAL; | 
|  | 226 |  | 
| Stanislav Kinsbursky | 90100b1 | 2012-01-13 13:09:19 +0400 | [diff] [blame] | 227 | if (rpc_pton(&init_net, fo_path, size, sap, salen) == 0) | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 228 | return -EINVAL; | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 229 |  | 
| Chuck Lever | 4116092 | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 230 | return nlmsvc_unlock_all_by_ip(sap); | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 231 | } | 
|  | 232 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 233 | /** | 
|  | 234 | * write_unlock_fs - Release all locks on a local file system | 
|  | 235 | * | 
|  | 236 | * Experimental. | 
|  | 237 | * | 
|  | 238 | * Input: | 
|  | 239 | *			buf:	'\n'-terminated C string containing the | 
|  | 240 | *				absolute pathname of a local file system | 
|  | 241 | *			size:	length of C string in @buf | 
|  | 242 | * Output: | 
|  | 243 | *	On success:	returns zero if all specified locks were released; | 
|  | 244 | *			returns one if one or more locks were not released | 
|  | 245 | *	On error:	return code is negative errno value | 
|  | 246 | */ | 
| Chuck Lever | b046ccd | 2008-12-12 16:57:13 -0500 | [diff] [blame] | 247 | 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] | 248 | { | 
| Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 249 | struct path path; | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 250 | char *fo_path; | 
|  | 251 | int error; | 
|  | 252 |  | 
|  | 253 | /* sanity check */ | 
|  | 254 | if (size == 0) | 
|  | 255 | return -EINVAL; | 
|  | 256 |  | 
|  | 257 | if (buf[size-1] != '\n') | 
|  | 258 | return -EINVAL; | 
|  | 259 |  | 
|  | 260 | fo_path = buf; | 
|  | 261 | if (qword_get(&buf, fo_path, size) < 0) | 
|  | 262 | return -EINVAL; | 
|  | 263 |  | 
| Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 264 | error = kern_path(fo_path, 0, &path); | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 265 | if (error) | 
|  | 266 | return error; | 
|  | 267 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 268 | /* | 
|  | 269 | * XXX: Needs better sanity checking.  Otherwise we could end up | 
|  | 270 | * releasing locks on the wrong file system. | 
|  | 271 | * | 
|  | 272 | * For example: | 
|  | 273 | * 1.  Does the path refer to a directory? | 
|  | 274 | * 2.  Is that directory a mount point, or | 
|  | 275 | * 3.  Is that directory the root of an exported file system? | 
|  | 276 | */ | 
| Al Viro | d8c9584 | 2011-12-07 18:16:57 -0500 | [diff] [blame] | 277 | error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb); | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 278 |  | 
| Al Viro | a63bb99 | 2008-08-02 01:03:36 -0400 | [diff] [blame] | 279 | path_put(&path); | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 280 | return error; | 
|  | 281 | } | 
|  | 282 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 283 | /** | 
|  | 284 | * write_filehandle - Get a variable-length NFS file handle by path | 
|  | 285 | * | 
|  | 286 | * On input, the buffer contains a '\n'-terminated C string comprised of | 
|  | 287 | * three alphanumeric words separated by whitespace.  The string may | 
|  | 288 | * contain escape sequences. | 
|  | 289 | * | 
|  | 290 | * Input: | 
|  | 291 | *			buf: | 
|  | 292 | *				domain:		client domain name | 
|  | 293 | *				path:		export pathname | 
|  | 294 | *				maxsize:	numeric maximum size of | 
|  | 295 | *						@buf | 
|  | 296 | *			size:	length of C string in @buf | 
|  | 297 | * Output: | 
|  | 298 | *	On success:	passed-in buffer filled with '\n'-terminated C | 
|  | 299 | *			string containing a ASCII hex text version | 
|  | 300 | *			of the NFS file handle; | 
|  | 301 | *			return code is the size in bytes of the string | 
|  | 302 | *	On error:	return code is negative errno value | 
|  | 303 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | static ssize_t write_filehandle(struct file *file, char *buf, size_t size) | 
|  | 305 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | char *dname, *path; | 
| Andrew Morton | 246d95b | 2007-08-09 00:53:50 -0700 | [diff] [blame] | 307 | int uninitialized_var(maxsize); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | char *mesg = buf; | 
|  | 309 | int len; | 
|  | 310 | struct auth_domain *dom; | 
|  | 311 | struct knfsd_fh fh; | 
|  | 312 |  | 
| J. Bruce Fields | 87d26ea | 2008-01-22 17:40:42 -0500 | [diff] [blame] | 313 | if (size == 0) | 
|  | 314 | return -EINVAL; | 
|  | 315 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | if (buf[size-1] != '\n') | 
|  | 317 | return -EINVAL; | 
|  | 318 | buf[size-1] = 0; | 
|  | 319 |  | 
|  | 320 | dname = mesg; | 
|  | 321 | len = qword_get(&mesg, dname, size); | 
| Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 322 | if (len <= 0) | 
|  | 323 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 |  | 
|  | 325 | path = dname+len+1; | 
|  | 326 | len = qword_get(&mesg, path, size); | 
| Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 327 | if (len <= 0) | 
|  | 328 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 |  | 
|  | 330 | len = get_int(&mesg, &maxsize); | 
|  | 331 | if (len) | 
|  | 332 | return len; | 
|  | 333 |  | 
|  | 334 | if (maxsize < NFS_FHSIZE) | 
|  | 335 | return -EINVAL; | 
|  | 336 | if (maxsize > NFS3_FHSIZE) | 
|  | 337 | maxsize = NFS3_FHSIZE; | 
|  | 338 |  | 
|  | 339 | if (qword_get(&mesg, mesg, size)>0) | 
|  | 340 | return -EINVAL; | 
|  | 341 |  | 
|  | 342 | /* we have all the words, they are in buf.. */ | 
|  | 343 | dom = unix_domain_find(dname); | 
|  | 344 | if (!dom) | 
|  | 345 | return -ENOMEM; | 
|  | 346 |  | 
|  | 347 | len = exp_rootfh(dom, path, &fh,  maxsize); | 
|  | 348 | auth_domain_put(dom); | 
|  | 349 | if (len) | 
|  | 350 | return len; | 
|  | 351 |  | 
| Chuck Lever | 54224f0 | 2008-12-12 16:57:20 -0500 | [diff] [blame] | 352 | mesg = buf; | 
|  | 353 | len = SIMPLE_TRANSACTION_LIMIT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); | 
|  | 355 | mesg[-1] = '\n'; | 
|  | 356 | return mesg - buf; | 
|  | 357 | } | 
|  | 358 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 359 | /** | 
|  | 360 | * write_threads - Start NFSD, or report the current number of running threads | 
|  | 361 | * | 
|  | 362 | * Input: | 
|  | 363 | *			buf:		ignored | 
|  | 364 | *			size:		zero | 
|  | 365 | * Output: | 
|  | 366 | *	On success:	passed-in buffer filled with '\n'-terminated C | 
|  | 367 | *			string numeric value representing the number of | 
|  | 368 | *			running NFSD threads; | 
|  | 369 | *			return code is the size in bytes of the string | 
|  | 370 | *	On error:	return code is zero | 
|  | 371 | * | 
|  | 372 | * OR | 
|  | 373 | * | 
|  | 374 | * Input: | 
|  | 375 | *			buf:		C string containing an unsigned | 
|  | 376 | *					integer value representing the | 
|  | 377 | *					number of NFSD threads to start | 
|  | 378 | *			size:		non-zero length of C string in @buf | 
|  | 379 | * Output: | 
|  | 380 | *	On success:	NFS service is started; | 
|  | 381 | *			passed-in buffer filled with '\n'-terminated C | 
|  | 382 | *			string numeric value representing the number of | 
|  | 383 | *			running NFSD threads; | 
|  | 384 | *			return code is the size in bytes of the string | 
|  | 385 | *	On error:	return code is zero or a negative errno value | 
|  | 386 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | static ssize_t write_threads(struct file *file, char *buf, size_t size) | 
|  | 388 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | char *mesg = buf; | 
|  | 390 | int rv; | 
|  | 391 | if (size > 0) { | 
|  | 392 | int newthreads; | 
|  | 393 | rv = get_int(&mesg, &newthreads); | 
|  | 394 | if (rv) | 
|  | 395 | return rv; | 
| Chuck Lever | 9e07485 | 2008-12-12 16:57:27 -0500 | [diff] [blame] | 396 | if (newthreads < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | return -EINVAL; | 
| Chuck Lever | 9e07485 | 2008-12-12 16:57:27 -0500 | [diff] [blame] | 398 | rv = nfsd_svc(NFS_PORT, newthreads); | 
| NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 399 | if (rv < 0) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return rv; | 
| NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 401 | } else | 
|  | 402 | rv = nfsd_nrthreads(); | 
| Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 403 |  | 
| NeilBrown | 82e12fe | 2009-06-16 11:03:07 +1000 | [diff] [blame] | 404 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } | 
|  | 406 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 407 | /** | 
|  | 408 | * write_pool_threads - Set or report the current number of threads per pool | 
|  | 409 | * | 
|  | 410 | * Input: | 
|  | 411 | *			buf:		ignored | 
|  | 412 | *			size:		zero | 
|  | 413 | * | 
|  | 414 | * OR | 
|  | 415 | * | 
|  | 416 | * Input: | 
|  | 417 | * 			buf:		C string containing whitespace- | 
|  | 418 | * 					separated unsigned integer values | 
|  | 419 | *					representing the number of NFSD | 
|  | 420 | *					threads to start in each pool | 
|  | 421 | *			size:		non-zero length of C string in @buf | 
|  | 422 | * Output: | 
|  | 423 | *	On success:	passed-in buffer filled with '\n'-terminated C | 
|  | 424 | *			string containing integer values representing the | 
|  | 425 | *			number of NFSD threads in each pool; | 
|  | 426 | *			return code is the size in bytes of the string | 
|  | 427 | *	On error:	return code is zero or a negative errno value | 
|  | 428 | */ | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 429 | static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) | 
|  | 430 | { | 
|  | 431 | /* if size > 0, look for an array of number of threads per node | 
|  | 432 | * and apply them  then write out number of threads per node as reply | 
|  | 433 | */ | 
|  | 434 | char *mesg = buf; | 
|  | 435 | int i; | 
|  | 436 | int rv; | 
|  | 437 | int len; | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 438 | int npools; | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 439 | int *nthreads; | 
|  | 440 |  | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 441 | mutex_lock(&nfsd_mutex); | 
|  | 442 | npools = nfsd_nrpools(); | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 443 | if (npools == 0) { | 
|  | 444 | /* | 
|  | 445 | * NFS is shut down.  The admin can start it by | 
|  | 446 | * writing to the threads file but NOT the pool_threads | 
|  | 447 | * file, sorry.  Report zero threads. | 
|  | 448 | */ | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 449 | mutex_unlock(&nfsd_mutex); | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 450 | strcpy(buf, "0\n"); | 
|  | 451 | return strlen(buf); | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 455 | rv = -ENOMEM; | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 456 | if (nthreads == NULL) | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 457 | goto out_free; | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 458 |  | 
|  | 459 | if (size > 0) { | 
|  | 460 | for (i = 0; i < npools; i++) { | 
|  | 461 | rv = get_int(&mesg, &nthreads[i]); | 
|  | 462 | if (rv == -ENOENT) | 
|  | 463 | break;		/* fewer numbers than pools */ | 
|  | 464 | if (rv) | 
|  | 465 | goto out_free;	/* syntax error */ | 
|  | 466 | rv = -EINVAL; | 
|  | 467 | if (nthreads[i] < 0) | 
|  | 468 | goto out_free; | 
|  | 469 | } | 
|  | 470 | rv = nfsd_set_nrthreads(i, nthreads); | 
|  | 471 | if (rv) | 
|  | 472 | goto out_free; | 
|  | 473 | } | 
|  | 474 |  | 
|  | 475 | rv = nfsd_get_nrthreads(npools, nthreads); | 
|  | 476 | if (rv) | 
|  | 477 | goto out_free; | 
|  | 478 |  | 
|  | 479 | mesg = buf; | 
|  | 480 | size = SIMPLE_TRANSACTION_LIMIT; | 
|  | 481 | for (i = 0; i < npools && size > 0; i++) { | 
|  | 482 | snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); | 
|  | 483 | len = strlen(mesg); | 
|  | 484 | size -= len; | 
|  | 485 | mesg += len; | 
|  | 486 | } | 
| J. Bruce Fields | 413d63d | 2009-07-28 11:37:25 -0400 | [diff] [blame] | 487 | rv = mesg - buf; | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 488 | out_free: | 
|  | 489 | kfree(nthreads); | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 490 | mutex_unlock(&nfsd_mutex); | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 491 | return rv; | 
|  | 492 | } | 
|  | 493 |  | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 494 | static ssize_t __write_versions(struct file *file, char *buf, size_t size) | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 495 | { | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 496 | char *mesg = buf; | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 497 | char *vers, *minorp, sign; | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 498 | int len, num, remaining; | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 499 | unsigned minor; | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 500 | ssize_t tlen = 0; | 
|  | 501 | char *sep; | 
|  | 502 |  | 
|  | 503 | if (size>0) { | 
|  | 504 | if (nfsd_serv) | 
| NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 505 | /* Cannot change versions without updating | 
|  | 506 | * nfsd_serv->sv_xdrsize, and reallocing | 
|  | 507 | * rq_argp and rq_resp | 
|  | 508 | */ | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 509 | return -EBUSY; | 
|  | 510 | if (buf[size-1] != '\n') | 
|  | 511 | return -EINVAL; | 
|  | 512 | buf[size-1] = 0; | 
|  | 513 |  | 
|  | 514 | vers = mesg; | 
|  | 515 | len = qword_get(&mesg, vers, size); | 
|  | 516 | if (len <= 0) return -EINVAL; | 
|  | 517 | do { | 
|  | 518 | sign = *vers; | 
|  | 519 | if (sign == '+' || sign == '-') | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 520 | num = simple_strtol((vers+1), &minorp, 0); | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 521 | else | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 522 | num = simple_strtol(vers, &minorp, 0); | 
|  | 523 | if (*minorp == '.') { | 
|  | 524 | if (num < 4) | 
|  | 525 | return -EINVAL; | 
|  | 526 | minor = simple_strtoul(minorp+1, NULL, 0); | 
|  | 527 | if (minor == 0) | 
|  | 528 | return -EINVAL; | 
|  | 529 | if (nfsd_minorversion(minor, sign == '-' ? | 
|  | 530 | NFSD_CLEAR : NFSD_SET) < 0) | 
|  | 531 | return -EINVAL; | 
|  | 532 | goto next; | 
|  | 533 | } | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 534 | switch(num) { | 
|  | 535 | case 2: | 
|  | 536 | case 3: | 
|  | 537 | case 4: | 
| NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 538 | nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 539 | break; | 
|  | 540 | default: | 
|  | 541 | return -EINVAL; | 
|  | 542 | } | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 543 | next: | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 544 | vers += len + 1; | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 545 | } while ((len = qword_get(&mesg, vers, size)) > 0); | 
|  | 546 | /* If all get turned off, turn them back on, as | 
|  | 547 | * having no versions is BAD | 
|  | 548 | */ | 
| NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 549 | nfsd_reset_versions(); | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 550 | } | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 551 |  | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 552 | /* Now write current state into reply buffer */ | 
|  | 553 | len = 0; | 
|  | 554 | sep = ""; | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 555 | remaining = SIMPLE_TRANSACTION_LIMIT; | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 556 | for (num=2 ; num <= 4 ; num++) | 
| NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 557 | if (nfsd_vers(num, NFSD_AVAIL)) { | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 558 | len = snprintf(buf, remaining, "%s%c%d", sep, | 
| NeilBrown | 6658d3a | 2006-10-02 02:17:46 -0700 | [diff] [blame] | 559 | nfsd_vers(num, NFSD_TEST)?'+':'-', | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 560 | num); | 
|  | 561 | sep = " "; | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 562 |  | 
|  | 563 | if (len > remaining) | 
|  | 564 | break; | 
|  | 565 | remaining -= len; | 
|  | 566 | buf += len; | 
|  | 567 | tlen += len; | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 568 | } | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 569 | if (nfsd_vers(4, NFSD_AVAIL)) | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 570 | for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION; | 
|  | 571 | minor++) { | 
|  | 572 | len = snprintf(buf, remaining, " %c4.%u", | 
| Benny Halevy | 8daf220 | 2009-04-03 08:28:59 +0300 | [diff] [blame] | 573 | (nfsd_vers(4, NFSD_TEST) && | 
|  | 574 | nfsd_minorversion(minor, NFSD_TEST)) ? | 
|  | 575 | '+' : '-', | 
|  | 576 | minor); | 
| Chuck Lever | 261758b | 2009-04-23 19:33:18 -0400 | [diff] [blame] | 577 |  | 
|  | 578 | if (len > remaining) | 
|  | 579 | break; | 
|  | 580 | remaining -= len; | 
|  | 581 | buf += len; | 
|  | 582 | tlen += len; | 
|  | 583 | } | 
|  | 584 |  | 
|  | 585 | len = snprintf(buf, remaining, "\n"); | 
|  | 586 | if (len > remaining) | 
|  | 587 | return -EINVAL; | 
|  | 588 | return tlen + len; | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 589 | } | 
|  | 590 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 591 | /** | 
|  | 592 | * write_versions - Set or report the available NFS protocol versions | 
|  | 593 | * | 
|  | 594 | * Input: | 
|  | 595 | *			buf:		ignored | 
|  | 596 | *			size:		zero | 
|  | 597 | * Output: | 
|  | 598 | *	On success:	passed-in buffer filled with '\n'-terminated C | 
|  | 599 | *			string containing positive or negative integer | 
|  | 600 | *			values representing the current status of each | 
|  | 601 | *			protocol version; | 
|  | 602 | *			return code is the size in bytes of the string | 
|  | 603 | *	On error:	return code is zero or a negative errno value | 
|  | 604 | * | 
|  | 605 | * OR | 
|  | 606 | * | 
|  | 607 | * Input: | 
|  | 608 | * 			buf:		C string containing whitespace- | 
|  | 609 | * 					separated positive or negative | 
|  | 610 | * 					integer values representing NFS | 
|  | 611 | * 					protocol versions to enable ("+n") | 
|  | 612 | * 					or disable ("-n") | 
|  | 613 | *			size:		non-zero length of C string in @buf | 
|  | 614 | * Output: | 
|  | 615 | *	On success:	status of zero or more protocol versions has | 
|  | 616 | *			been updated; passed-in buffer filled with | 
|  | 617 | *			'\n'-terminated C string containing positive | 
|  | 618 | *			or negative integer values representing the | 
|  | 619 | *			current status of each protocol version; | 
|  | 620 | *			return code is the size in bytes of the string | 
|  | 621 | *	On error:	return code is zero or a negative errno value | 
|  | 622 | */ | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 623 | static ssize_t write_versions(struct file *file, char *buf, size_t size) | 
|  | 624 | { | 
|  | 625 | ssize_t rv; | 
|  | 626 |  | 
|  | 627 | mutex_lock(&nfsd_mutex); | 
|  | 628 | rv = __write_versions(file, buf, size); | 
|  | 629 | mutex_unlock(&nfsd_mutex); | 
|  | 630 | return rv; | 
|  | 631 | } | 
|  | 632 |  | 
| Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 633 | /* | 
| Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 634 | * Zero-length write.  Return a list of NFSD's current listener | 
|  | 635 | * transports. | 
|  | 636 | */ | 
|  | 637 | static ssize_t __write_ports_names(char *buf) | 
|  | 638 | { | 
|  | 639 | if (nfsd_serv == NULL) | 
|  | 640 | return 0; | 
| Chuck Lever | 335c54b | 2009-04-23 19:32:25 -0400 | [diff] [blame] | 641 | return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); | 
| Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 642 | } | 
|  | 643 |  | 
|  | 644 | /* | 
| Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 645 | * A single 'fd' number was written, in which case it must be for | 
|  | 646 | * a socket of a supported family/protocol, and we use it as an | 
|  | 647 | * nfsd listener. | 
|  | 648 | */ | 
|  | 649 | static ssize_t __write_ports_addfd(char *buf) | 
|  | 650 | { | 
|  | 651 | char *mesg = buf; | 
|  | 652 | int fd, err; | 
|  | 653 |  | 
|  | 654 | err = get_int(&mesg, &fd); | 
|  | 655 | if (err != 0 || fd < 0) | 
|  | 656 | return -EINVAL; | 
|  | 657 |  | 
|  | 658 | err = nfsd_create_serv(); | 
|  | 659 | if (err != 0) | 
|  | 660 | return err; | 
|  | 661 |  | 
| Chuck Lever | bfba9ab | 2009-04-23 19:32:33 -0400 | [diff] [blame] | 662 | err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); | 
| Jeff Layton | 78a8d7c | 2010-07-19 16:50:05 -0400 | [diff] [blame] | 663 | if (err < 0) { | 
| Jeff Layton | 78a8d7c | 2010-07-19 16:50:05 -0400 | [diff] [blame] | 664 | svc_destroy(nfsd_serv); | 
|  | 665 | return err; | 
|  | 666 | } | 
| Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 667 |  | 
| Chuck Lever | ea068ba | 2009-04-23 19:32:18 -0400 | [diff] [blame] | 668 | /* Decrease the count, but don't shut down the service */ | 
|  | 669 | nfsd_serv->sv_nrthreads--; | 
|  | 670 | return err; | 
| Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 671 | } | 
|  | 672 |  | 
|  | 673 | /* | 
| Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 674 | * A '-' followed by the 'name' of a socket means we close the socket. | 
|  | 675 | */ | 
|  | 676 | static ssize_t __write_ports_delfd(char *buf) | 
|  | 677 | { | 
|  | 678 | char *toclose; | 
|  | 679 | int len = 0; | 
|  | 680 |  | 
|  | 681 | toclose = kstrdup(buf + 1, GFP_KERNEL); | 
|  | 682 | if (toclose == NULL) | 
|  | 683 | return -ENOMEM; | 
|  | 684 |  | 
|  | 685 | if (nfsd_serv != NULL) | 
| Chuck Lever | 8435d34 | 2009-04-23 19:32:40 -0400 | [diff] [blame] | 686 | len = svc_sock_names(nfsd_serv, buf, | 
|  | 687 | SIMPLE_TRANSACTION_LIMIT, toclose); | 
| Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 688 | kfree(toclose); | 
|  | 689 | return len; | 
|  | 690 | } | 
|  | 691 |  | 
|  | 692 | /* | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 693 | * A transport listener is added by writing it's transport name and | 
|  | 694 | * a port number. | 
|  | 695 | */ | 
|  | 696 | static ssize_t __write_ports_addxprt(char *buf) | 
|  | 697 | { | 
|  | 698 | char transport[16]; | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 699 | struct svc_xprt *xprt; | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 700 | int port, err; | 
|  | 701 |  | 
|  | 702 | if (sscanf(buf, "%15s %4u", transport, &port) != 2) | 
|  | 703 | return -EINVAL; | 
|  | 704 |  | 
| Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 705 | if (port < 1 || port > USHRT_MAX) | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 706 | return -EINVAL; | 
|  | 707 |  | 
|  | 708 | err = nfsd_create_serv(); | 
|  | 709 | if (err != 0) | 
|  | 710 | return err; | 
|  | 711 |  | 
| Pavel Emelyanov | fc5d00b | 2010-09-29 16:03:50 +0400 | [diff] [blame] | 712 | err = svc_create_xprt(nfsd_serv, transport, &init_net, | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 713 | PF_INET, port, SVC_SOCK_ANONYMOUS); | 
| Chuck Lever | 6871790 | 2010-01-26 14:04:13 -0500 | [diff] [blame] | 714 | if (err < 0) | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 715 | goto out_err; | 
|  | 716 |  | 
| Pavel Emelyanov | fc5d00b | 2010-09-29 16:03:50 +0400 | [diff] [blame] | 717 | err = svc_create_xprt(nfsd_serv, transport, &init_net, | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 718 | PF_INET6, port, SVC_SOCK_ANONYMOUS); | 
|  | 719 | if (err < 0 && err != -EAFNOSUPPORT) | 
|  | 720 | goto out_close; | 
| Jeff Layton | 0cd14a0 | 2010-07-19 16:50:06 -0400 | [diff] [blame] | 721 |  | 
|  | 722 | /* Decrease the count, but don't shut down the service */ | 
|  | 723 | nfsd_serv->sv_nrthreads--; | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 724 | return 0; | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 725 | out_close: | 
| Stanislav Kinsbursky | 4cb54ca | 2012-01-20 16:50:53 +0400 | [diff] [blame] | 726 | xprt = svc_find_xprt(nfsd_serv, transport, &init_net, PF_INET, port); | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 727 | if (xprt != NULL) { | 
|  | 728 | svc_close_xprt(xprt); | 
|  | 729 | svc_xprt_put(xprt); | 
|  | 730 | } | 
|  | 731 | out_err: | 
| Jeff Layton | 0cd14a0 | 2010-07-19 16:50:06 -0400 | [diff] [blame] | 732 | svc_destroy(nfsd_serv); | 
| Chuck Lever | 3749829 | 2010-01-26 14:04:22 -0500 | [diff] [blame] | 733 | return err; | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 734 | } | 
|  | 735 |  | 
|  | 736 | /* | 
| Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 737 | * A transport listener is removed by writing a "-", it's transport | 
|  | 738 | * name, and it's port number. | 
|  | 739 | */ | 
|  | 740 | static ssize_t __write_ports_delxprt(char *buf) | 
|  | 741 | { | 
|  | 742 | struct svc_xprt *xprt; | 
|  | 743 | char transport[16]; | 
|  | 744 | int port; | 
|  | 745 |  | 
|  | 746 | if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2) | 
|  | 747 | return -EINVAL; | 
|  | 748 |  | 
| Alexey Dobriyan | 4be929b | 2010-05-24 14:33:03 -0700 | [diff] [blame] | 749 | if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL) | 
| Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 750 | return -EINVAL; | 
|  | 751 |  | 
| Stanislav Kinsbursky | 4cb54ca | 2012-01-20 16:50:53 +0400 | [diff] [blame] | 752 | xprt = svc_find_xprt(nfsd_serv, transport, &init_net, AF_UNSPEC, port); | 
| Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 753 | if (xprt == NULL) | 
|  | 754 | return -ENOTCONN; | 
|  | 755 |  | 
|  | 756 | svc_close_xprt(xprt); | 
|  | 757 | svc_xprt_put(xprt); | 
|  | 758 | return 0; | 
|  | 759 | } | 
|  | 760 |  | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 761 | static ssize_t __write_ports(struct file *file, char *buf, size_t size) | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 762 | { | 
| Chuck Lever | 0a5372d | 2009-04-23 19:32:10 -0400 | [diff] [blame] | 763 | if (size == 0) | 
|  | 764 | return __write_ports_names(buf); | 
| Chuck Lever | 0b7c2f6 | 2009-04-23 19:31:55 -0400 | [diff] [blame] | 765 |  | 
|  | 766 | if (isdigit(buf[0])) | 
|  | 767 | return __write_ports_addfd(buf); | 
| Chuck Lever | 82d5659 | 2009-04-23 19:31:48 -0400 | [diff] [blame] | 768 |  | 
|  | 769 | if (buf[0] == '-' && isdigit(buf[1])) | 
|  | 770 | return __write_ports_delfd(buf); | 
| Chuck Lever | 4eb68c2 | 2009-04-23 19:31:40 -0400 | [diff] [blame] | 771 |  | 
|  | 772 | if (isalpha(buf[0])) | 
|  | 773 | return __write_ports_addxprt(buf); | 
| Chuck Lever | 4cd5dc7 | 2009-04-23 19:31:32 -0400 | [diff] [blame] | 774 |  | 
|  | 775 | if (buf[0] == '-' && isalpha(buf[1])) | 
|  | 776 | return __write_ports_delxprt(buf); | 
|  | 777 |  | 
| NeilBrown | b41b66d | 2006-10-02 02:17:48 -0700 | [diff] [blame] | 778 | return -EINVAL; | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 779 | } | 
|  | 780 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 781 | /** | 
|  | 782 | * write_ports - Pass a socket file descriptor or transport name to listen on | 
|  | 783 | * | 
|  | 784 | * Input: | 
|  | 785 | *			buf:		ignored | 
|  | 786 | *			size:		zero | 
|  | 787 | * Output: | 
|  | 788 | *	On success:	passed-in buffer filled with a '\n'-terminated C | 
|  | 789 | *			string containing a whitespace-separated list of | 
|  | 790 | *			named NFSD listeners; | 
|  | 791 | *			return code is the size in bytes of the string | 
|  | 792 | *	On error:	return code is zero or a negative errno value | 
|  | 793 | * | 
|  | 794 | * OR | 
|  | 795 | * | 
|  | 796 | * Input: | 
|  | 797 | *			buf:		C string containing an unsigned | 
|  | 798 | *					integer value representing a bound | 
|  | 799 | *					but unconnected socket that is to be | 
| Chuck Lever | c71206a | 2009-04-23 19:32:03 -0400 | [diff] [blame] | 800 | *					used as an NFSD listener; listen(3) | 
|  | 801 | *					must be called for a SOCK_STREAM | 
|  | 802 | *					socket, otherwise it is ignored | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 803 | *			size:		non-zero length of C string in @buf | 
|  | 804 | * Output: | 
|  | 805 | *	On success:	NFS service is started; | 
|  | 806 | *			passed-in buffer filled with a '\n'-terminated C | 
|  | 807 | *			string containing a unique alphanumeric name of | 
|  | 808 | *			the listener; | 
|  | 809 | *			return code is the size in bytes of the string | 
|  | 810 | *	On error:	return code is a negative errno value | 
|  | 811 | * | 
|  | 812 | * OR | 
|  | 813 | * | 
|  | 814 | * Input: | 
|  | 815 | *			buf:		C string containing a "-" followed | 
|  | 816 | *					by an integer value representing a | 
|  | 817 | *					previously passed in socket file | 
|  | 818 | *					descriptor | 
|  | 819 | *			size:		non-zero length of C string in @buf | 
|  | 820 | * Output: | 
|  | 821 | *	On success:	NFS service no longer listens on that socket; | 
|  | 822 | *			passed-in buffer filled with a '\n'-terminated C | 
|  | 823 | *			string containing a unique name of the listener; | 
|  | 824 | *			return code is the size in bytes of the string | 
|  | 825 | *	On error:	return code is a negative errno value | 
|  | 826 | * | 
|  | 827 | * OR | 
|  | 828 | * | 
|  | 829 | * Input: | 
|  | 830 | *			buf:		C string containing a transport | 
|  | 831 | *					name and an unsigned integer value | 
|  | 832 | *					representing the port to listen on, | 
|  | 833 | *					separated by whitespace | 
|  | 834 | *			size:		non-zero length of C string in @buf | 
|  | 835 | * Output: | 
|  | 836 | *	On success:	returns zero; NFS service is started | 
|  | 837 | *	On error:	return code is a negative errno value | 
|  | 838 | * | 
|  | 839 | * OR | 
|  | 840 | * | 
|  | 841 | * Input: | 
|  | 842 | *			buf:		C string containing a "-" followed | 
|  | 843 | *					by a transport name and an unsigned | 
|  | 844 | *					integer value representing the port | 
|  | 845 | *					to listen on, separated by whitespace | 
|  | 846 | *			size:		non-zero length of C string in @buf | 
|  | 847 | * Output: | 
|  | 848 | *	On success:	returns zero; NFS service no longer listens | 
|  | 849 | *			on that transport | 
|  | 850 | *	On error:	return code is a negative errno value | 
|  | 851 | */ | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 852 | static ssize_t write_ports(struct file *file, char *buf, size_t size) | 
|  | 853 | { | 
|  | 854 | ssize_t rv; | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 855 |  | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 856 | mutex_lock(&nfsd_mutex); | 
|  | 857 | rv = __write_ports(file, buf, size); | 
|  | 858 | mutex_unlock(&nfsd_mutex); | 
|  | 859 | return rv; | 
|  | 860 | } | 
|  | 861 |  | 
|  | 862 |  | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 863 | int nfsd_max_blksize; | 
|  | 864 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 865 | /** | 
|  | 866 | * write_maxblksize - Set or report the current NFS blksize | 
|  | 867 | * | 
|  | 868 | * Input: | 
|  | 869 | *			buf:		ignored | 
|  | 870 | *			size:		zero | 
|  | 871 | * | 
|  | 872 | * OR | 
|  | 873 | * | 
|  | 874 | * Input: | 
|  | 875 | * 			buf:		C string containing an unsigned | 
|  | 876 | * 					integer value representing the new | 
|  | 877 | * 					NFS blksize | 
|  | 878 | *			size:		non-zero length of C string in @buf | 
|  | 879 | * Output: | 
|  | 880 | *	On success:	passed-in buffer filled with '\n'-terminated C string | 
|  | 881 | *			containing numeric value of the current NFS blksize | 
|  | 882 | *			setting; | 
|  | 883 | *			return code is the size in bytes of the string | 
|  | 884 | *	On error:	return code is zero or a negative errno value | 
|  | 885 | */ | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 886 | static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) | 
|  | 887 | { | 
|  | 888 | char *mesg = buf; | 
|  | 889 | if (size > 0) { | 
|  | 890 | int bsize; | 
|  | 891 | int rv = get_int(&mesg, &bsize); | 
|  | 892 | if (rv) | 
|  | 893 | return rv; | 
|  | 894 | /* force bsize into allowed range and | 
|  | 895 | * required alignment. | 
|  | 896 | */ | 
|  | 897 | if (bsize < 1024) | 
|  | 898 | bsize = 1024; | 
|  | 899 | if (bsize > NFSSVC_MAXBLKSIZE) | 
|  | 900 | bsize = NFSSVC_MAXBLKSIZE; | 
|  | 901 | bsize &= ~(1024-1); | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 902 | mutex_lock(&nfsd_mutex); | 
| J. Bruce Fields | 7fa53cc | 2010-08-06 18:00:33 -0400 | [diff] [blame] | 903 | if (nfsd_serv) { | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 904 | mutex_unlock(&nfsd_mutex); | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 905 | return -EBUSY; | 
|  | 906 | } | 
|  | 907 | nfsd_max_blksize = bsize; | 
| Neil Brown | bedbdd8 | 2008-06-10 08:40:35 -0400 | [diff] [blame] | 908 | mutex_unlock(&nfsd_mutex); | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 909 | } | 
| Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 910 |  | 
|  | 911 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", | 
|  | 912 | nfsd_max_blksize); | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 913 | } | 
|  | 914 |  | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 915 | #ifdef CONFIG_NFSD_V4 | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 916 | 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] | 917 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | char *mesg = buf; | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 919 | int rv, i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 |  | 
|  | 921 | if (size > 0) { | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 922 | if (nfsd_serv) | 
|  | 923 | return -EBUSY; | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 924 | rv = get_int(&mesg, &i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | if (rv) | 
|  | 926 | return rv; | 
| J. Bruce Fields | e7b184f | 2010-03-02 11:18:40 -0500 | [diff] [blame] | 927 | /* | 
|  | 928 | * Some sanity checking.  We don't have a reason for | 
|  | 929 | * these particular numbers, but problems with the | 
|  | 930 | * extremes are: | 
|  | 931 | *	- Too short: the briefest network outage may | 
|  | 932 | *	  cause clients to lose all their locks.  Also, | 
|  | 933 | *	  the frequent polling may be wasteful. | 
|  | 934 | *	- Too long: do you really want reboot recovery | 
|  | 935 | *	  to take more than an hour?  Or to make other | 
|  | 936 | *	  clients wait an hour before being able to | 
|  | 937 | *	  revoke a dead client's locks? | 
|  | 938 | */ | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 939 | if (i < 10 || i > 3600) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | return -EINVAL; | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 941 | *time = i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } | 
| Chuck Lever | e06b640 | 2009-04-23 19:33:25 -0400 | [diff] [blame] | 943 |  | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 944 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time); | 
|  | 945 | } | 
|  | 946 |  | 
|  | 947 | static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) | 
|  | 948 | { | 
|  | 949 | ssize_t rv; | 
|  | 950 |  | 
|  | 951 | mutex_lock(&nfsd_mutex); | 
|  | 952 | rv = __nfsd4_write_time(file, buf, size, time); | 
|  | 953 | mutex_unlock(&nfsd_mutex); | 
|  | 954 | return rv; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | } | 
|  | 956 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 957 | /** | 
|  | 958 | * write_leasetime - Set or report the current NFSv4 lease time | 
|  | 959 | * | 
|  | 960 | * Input: | 
|  | 961 | *			buf:		ignored | 
|  | 962 | *			size:		zero | 
|  | 963 | * | 
|  | 964 | * OR | 
|  | 965 | * | 
|  | 966 | * Input: | 
|  | 967 | *			buf:		C string containing an unsigned | 
|  | 968 | *					integer value representing the new | 
|  | 969 | *					NFSv4 lease expiry time | 
|  | 970 | *			size:		non-zero length of C string in @buf | 
|  | 971 | * Output: | 
|  | 972 | *	On success:	passed-in buffer filled with '\n'-terminated C | 
|  | 973 | *			string containing unsigned integer value of the | 
|  | 974 | *			current lease expiry time; | 
|  | 975 | *			return code is the size in bytes of the string | 
|  | 976 | *	On error:	return code is zero or a negative errno value | 
|  | 977 | */ | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 978 | static ssize_t write_leasetime(struct file *file, char *buf, size_t size) | 
|  | 979 | { | 
| J. Bruce Fields | f013574 | 2010-03-01 19:32:36 -0500 | [diff] [blame] | 980 | return nfsd4_write_time(file, buf, size, &nfsd4_lease); | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 981 | } | 
|  | 982 |  | 
| J. Bruce Fields | efc4bb4 | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 983 | /** | 
|  | 984 | * write_gracetime - Set or report current NFSv4 grace period time | 
|  | 985 | * | 
|  | 986 | * As above, but sets the time of the NFSv4 grace period. | 
|  | 987 | * | 
|  | 988 | * Note this should never be set to less than the *previous* | 
|  | 989 | * lease-period time, but we don't try to enforce this.  (In the common | 
|  | 990 | * case (a new boot), we don't know what the previous lease time was | 
|  | 991 | * anyway.) | 
|  | 992 | */ | 
|  | 993 | static ssize_t write_gracetime(struct file *file, char *buf, size_t size) | 
|  | 994 | { | 
|  | 995 | return nfsd4_write_time(file, buf, size, &nfsd4_grace); | 
|  | 996 | } | 
|  | 997 |  | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 998 | extern char *nfs4_recoverydir(void); | 
|  | 999 |  | 
|  | 1000 | static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1001 | { | 
|  | 1002 | char *mesg = buf; | 
|  | 1003 | char *recdir; | 
|  | 1004 | int len, status; | 
|  | 1005 |  | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1006 | if (size > 0) { | 
|  | 1007 | if (nfsd_serv) | 
|  | 1008 | return -EBUSY; | 
|  | 1009 | if (size > PATH_MAX || buf[size-1] != '\n') | 
|  | 1010 | return -EINVAL; | 
|  | 1011 | buf[size-1] = 0; | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1012 |  | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1013 | recdir = mesg; | 
|  | 1014 | len = qword_get(&mesg, recdir, size); | 
|  | 1015 | if (len <= 0) | 
|  | 1016 | return -EINVAL; | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1017 |  | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1018 | status = nfs4_reset_recoverydir(recdir); | 
| Andi Kleen | 6904996 | 2010-07-20 15:24:27 -0700 | [diff] [blame] | 1019 | if (status) | 
|  | 1020 | return status; | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1021 | } | 
| Chuck Lever | 3d72ab8 | 2009-04-23 19:33:10 -0400 | [diff] [blame] | 1022 |  | 
|  | 1023 | return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", | 
|  | 1024 | nfs4_recoverydir()); | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1025 | } | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1026 |  | 
| Chuck Lever | 262a098 | 2008-12-12 16:57:35 -0500 | [diff] [blame] | 1027 | /** | 
|  | 1028 | * write_recoverydir - Set or report the pathname of the recovery directory | 
|  | 1029 | * | 
|  | 1030 | * Input: | 
|  | 1031 | *			buf:		ignored | 
|  | 1032 | *			size:		zero | 
|  | 1033 | * | 
|  | 1034 | * OR | 
|  | 1035 | * | 
|  | 1036 | * Input: | 
|  | 1037 | *			buf:		C string containing the pathname | 
|  | 1038 | *					of the directory on a local file | 
|  | 1039 | *					system containing permanent NFSv4 | 
|  | 1040 | *					recovery data | 
|  | 1041 | *			size:		non-zero length of C string in @buf | 
|  | 1042 | * Output: | 
|  | 1043 | *	On success:	passed-in buffer filled with '\n'-terminated C string | 
|  | 1044 | *			containing the current recovery pathname setting; | 
|  | 1045 | *			return code is the size in bytes of the string | 
|  | 1046 | *	On error:	return code is zero or a negative errno value | 
|  | 1047 | */ | 
| Jeff Layton | 3dd98a3 | 2008-06-10 08:40:36 -0400 | [diff] [blame] | 1048 | static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) | 
|  | 1049 | { | 
|  | 1050 | ssize_t rv; | 
|  | 1051 |  | 
|  | 1052 | mutex_lock(&nfsd_mutex); | 
|  | 1053 | rv = __write_recoverydir(file, buf, size); | 
|  | 1054 | mutex_unlock(&nfsd_mutex); | 
|  | 1055 | return rv; | 
|  | 1056 | } | 
|  | 1057 |  | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 1058 | #endif | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1059 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | /*----------------------------------------------------------------------------*/ | 
|  | 1061 | /* | 
|  | 1062 | *	populating the filesystem. | 
|  | 1063 | */ | 
|  | 1064 |  | 
|  | 1065 | static int nfsd_fill_super(struct super_block * sb, void * data, int silent) | 
|  | 1066 | { | 
|  | 1067 | static struct tree_descr nfsd_files[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, | 
| J. Bruce Fields | e8e8753 | 2009-12-14 12:53:32 -0500 | [diff] [blame] | 1069 | [NFSD_Export_features] = {"export_features", | 
|  | 1070 | &export_features_operations, S_IRUGO}, | 
| Wendy Cheng | 4373ea8 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 1071 | [NFSD_FO_UnlockIP] = {"unlock_ip", | 
|  | 1072 | &transaction_ops, S_IWUSR|S_IRUSR}, | 
| Wendy Cheng | 17efa37 | 2008-01-17 11:10:12 -0500 | [diff] [blame] | 1073 | [NFSD_FO_UnlockFS] = {"unlock_filesystem", | 
|  | 1074 | &transaction_ops, S_IWUSR|S_IRUSR}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, | 
|  | 1076 | [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| Greg Banks | eed2965 | 2006-10-02 02:18:02 -0700 | [diff] [blame] | 1077 | [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| Greg Banks | 03cf6c9 | 2009-01-13 21:26:36 +1100 | [diff] [blame] | 1078 | [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, | 
| NeilBrown | 70c3b76 | 2005-11-07 01:00:25 -0800 | [diff] [blame] | 1079 | [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| NeilBrown | 80212d5 | 2006-10-02 02:17:47 -0700 | [diff] [blame] | 1080 | [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, | 
| NeilBrown | 596bbe5 | 2006-10-04 02:15:48 -0700 | [diff] [blame] | 1081 | [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 1082 | #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) | 
| Kevin Coffman | b0b0c0a | 2011-03-02 19:51:42 -0500 | [diff] [blame] | 1083 | [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO}, | 
| J. Bruce Fields | b084f59 | 2011-05-31 12:24:58 -0400 | [diff] [blame] | 1084 | #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | #ifdef CONFIG_NFSD_V4 | 
|  | 1086 | [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| J. Bruce Fields | efc4bb4 | 2010-03-02 11:04:06 -0500 | [diff] [blame] | 1087 | [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| NeilBrown | 0964a3d | 2005-06-23 22:04:32 -0700 | [diff] [blame] | 1088 | [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | #endif | 
|  | 1090 | /* last one */ {""} | 
|  | 1091 | }; | 
|  | 1092 | return simple_fill_super(sb, 0x6e667364, nfsd_files); | 
|  | 1093 | } | 
|  | 1094 |  | 
| Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 1095 | static struct dentry *nfsd_mount(struct file_system_type *fs_type, | 
|  | 1096 | int flags, const char *dev_name, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | { | 
| Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 1098 | return mount_single(fs_type, flags, data, nfsd_fill_super); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } | 
|  | 1100 |  | 
|  | 1101 | static struct file_system_type nfsd_fs_type = { | 
|  | 1102 | .owner		= THIS_MODULE, | 
|  | 1103 | .name		= "nfsd", | 
| Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 1104 | .mount		= nfsd_mount, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | .kill_sb	= kill_litter_super, | 
|  | 1106 | }; | 
|  | 1107 |  | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1108 | #ifdef CONFIG_PROC_FS | 
|  | 1109 | static int create_proc_exports_entry(void) | 
|  | 1110 | { | 
|  | 1111 | struct proc_dir_entry *entry; | 
|  | 1112 |  | 
|  | 1113 | entry = proc_mkdir("fs/nfs", NULL); | 
|  | 1114 | if (!entry) | 
|  | 1115 | return -ENOMEM; | 
| Denis V. Lunev | 9ef2db2 | 2008-04-29 01:02:04 -0700 | [diff] [blame] | 1116 | entry = proc_create("exports", 0, entry, &exports_operations); | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1117 | if (!entry) | 
|  | 1118 | return -ENOMEM; | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1119 | return 0; | 
|  | 1120 | } | 
|  | 1121 | #else /* CONFIG_PROC_FS */ | 
|  | 1122 | static int create_proc_exports_entry(void) | 
|  | 1123 | { | 
|  | 1124 | return 0; | 
|  | 1125 | } | 
|  | 1126 | #endif | 
|  | 1127 |  | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 1128 | int nfsd_net_id; | 
|  | 1129 | static struct pernet_operations nfsd_net_ops = { | 
|  | 1130 | .id   = &nfsd_net_id, | 
|  | 1131 | .size = sizeof(struct nfsd_net), | 
|  | 1132 | }; | 
|  | 1133 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | static int __init init_nfsd(void) | 
|  | 1135 | { | 
|  | 1136 | int retval; | 
|  | 1137 | printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); | 
|  | 1138 |  | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 1139 | retval = register_pernet_subsys(&nfsd_net_ops); | 
|  | 1140 | if (retval < 0) | 
|  | 1141 | return retval; | 
| Bryan Schumaker | 7208339 | 2011-11-01 15:24:59 -0400 | [diff] [blame] | 1142 | retval = nfsd4_init_slabs(); | 
| J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 1143 | if (retval) | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 1144 | goto out_unregister_pernet; | 
| Bryan Schumaker | 7208339 | 2011-11-01 15:24:59 -0400 | [diff] [blame] | 1145 | nfs4_state_init(); | 
| Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 1146 | retval = nfsd_fault_inject_init(); /* nfsd fault injection controls */ | 
|  | 1147 | if (retval) | 
|  | 1148 | goto out_free_slabs; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | nfsd_stat_init();	/* Statistics */ | 
| J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1150 | retval = nfsd_reply_cache_init(); | 
|  | 1151 | if (retval) | 
|  | 1152 | goto out_free_stat; | 
| J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1153 | retval = nfsd_export_init(); | 
|  | 1154 | if (retval) | 
|  | 1155 | goto out_free_cache; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | nfsd_lockd_init();	/* lockd->nfsd callbacks */ | 
| J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1157 | retval = nfsd_idmap_init(); | 
|  | 1158 | if (retval) | 
|  | 1159 | goto out_free_lockd; | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1160 | retval = create_proc_exports_entry(); | 
|  | 1161 | if (retval) | 
|  | 1162 | goto out_free_idmap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | retval = register_filesystem(&nfsd_fs_type); | 
| J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1164 | if (retval) | 
|  | 1165 | goto out_free_all; | 
|  | 1166 | return 0; | 
|  | 1167 | out_free_all: | 
| J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1168 | remove_proc_entry("fs/nfs/exports", NULL); | 
|  | 1169 | remove_proc_entry("fs/nfs", NULL); | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1170 | out_free_idmap: | 
| J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1171 | nfsd_idmap_shutdown(); | 
|  | 1172 | out_free_lockd: | 
| J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1173 | nfsd_lockd_shutdown(); | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1174 | nfsd_export_shutdown(); | 
| J. Bruce Fields | dbf847e | 2007-11-08 17:20:34 -0500 | [diff] [blame] | 1175 | out_free_cache: | 
| J. Bruce Fields | e331f60 | 2007-11-12 17:32:21 -0500 | [diff] [blame] | 1176 | nfsd_reply_cache_shutdown(); | 
| J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1177 | out_free_stat: | 
|  | 1178 | nfsd_stat_shutdown(); | 
| Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 1179 | nfsd_fault_inject_cleanup(); | 
|  | 1180 | out_free_slabs: | 
| J. Bruce Fields | 26808d3 | 2007-11-09 13:44:06 -0500 | [diff] [blame] | 1181 | nfsd4_free_slabs(); | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 1182 | out_unregister_pernet: | 
|  | 1183 | unregister_pernet_subsys(&nfsd_net_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | return retval; | 
|  | 1185 | } | 
|  | 1186 |  | 
|  | 1187 | static void __exit exit_nfsd(void) | 
|  | 1188 | { | 
|  | 1189 | nfsd_export_shutdown(); | 
| J. Bruce Fields | d5c3428 | 2007-11-09 14:10:56 -0500 | [diff] [blame] | 1190 | nfsd_reply_cache_shutdown(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | remove_proc_entry("fs/nfs/exports", NULL); | 
|  | 1192 | remove_proc_entry("fs/nfs", NULL); | 
|  | 1193 | nfsd_stat_shutdown(); | 
|  | 1194 | nfsd_lockd_shutdown(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | nfsd_idmap_shutdown(); | 
| J. Bruce Fields | e8ff2a8 | 2007-08-01 15:30:59 -0400 | [diff] [blame] | 1196 | nfsd4_free_slabs(); | 
| Bryan Schumaker | 65178db | 2011-11-01 13:35:21 -0400 | [diff] [blame] | 1197 | nfsd_fault_inject_cleanup(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | unregister_filesystem(&nfsd_fs_type); | 
| Jeff Layton | 7ea34ac | 2012-03-21 09:52:05 -0400 | [diff] [blame^] | 1199 | unregister_pernet_subsys(&nfsd_net_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | } | 
|  | 1201 |  | 
|  | 1202 | MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); | 
|  | 1203 | MODULE_LICENSE("GPL"); | 
|  | 1204 | module_init(init_nfsd) | 
|  | 1205 | module_exit(exit_nfsd) |