blob: db34a585e1129926b672ccc9f5a2f4b42c0a6f2e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Syscall interface to knfsd.
3 *
4 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
5 */
6
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Al Viro3f8206d2008-07-26 03:46:43 -04008#include <linux/namei.h>
NeilBrownb41b66d2006-10-02 02:17:48 -07009#include <linux/ctype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
NeilBrown80212d52006-10-02 02:17:47 -070011#include <linux/sunrpc/svcsock.h>
Wendy Cheng4373ea82008-01-17 11:10:12 -050012#include <linux/lockd/lockd.h>
Chuck Lever41160922009-08-09 15:09:40 -040013#include <linux/sunrpc/clnt.h>
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050014#include <linux/sunrpc/gss_api.h>
J. Bruce Fieldsb084f592011-05-31 12:24:58 -040015#include <linux/sunrpc/gss_krb5_enctypes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
J. Bruce Fields2ca72e12011-01-04 17:37:15 -050017#include "idmap.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020018#include "nfsd.h"
19#include "cache.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/*
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050022 * We have a single directory with several nodes in it.
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 */
24enum {
25 NFSD_Root = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 NFSD_List,
J. Bruce Fieldse8e87532009-12-14 12:53:32 -050027 NFSD_Export_features,
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 NFSD_Fh,
Wendy Cheng4373ea82008-01-17 11:10:12 -050029 NFSD_FO_UnlockIP,
Wendy Cheng17efa372008-01-17 11:10:12 -050030 NFSD_FO_UnlockFS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 NFSD_Threads,
Greg Bankseed29652006-10-02 02:18:02 -070032 NFSD_Pool_Threads,
Greg Banks03cf6c92009-01-13 21:26:36 +110033 NFSD_Pool_Stats,
NeilBrown70c3b762005-11-07 01:00:25 -080034 NFSD_Versions,
NeilBrown80212d52006-10-02 02:17:47 -070035 NFSD_Ports,
NeilBrown596bbe52006-10-04 02:15:48 -070036 NFSD_MaxBlkSize,
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050037 NFSD_SupportedEnctypes,
NeilBrown70c3b762005-11-07 01:00:25 -080038 /*
39 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
40 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
41 */
42#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 NFSD_Leasetime,
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -050044 NFSD_Gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -070045 NFSD_RecoveryDir,
NeilBrown70c3b762005-11-07 01:00:25 -080046#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070047};
48
49/*
50 * write() for these nodes.
51 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070052static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
Chuck Leverb046ccd2008-12-12 16:57:13 -050053static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
54static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055static ssize_t write_threads(struct file *file, char *buf, size_t size);
Greg Bankseed29652006-10-02 02:18:02 -070056static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080057static ssize_t write_versions(struct file *file, char *buf, size_t size);
NeilBrown80212d52006-10-02 02:17:47 -070058static ssize_t write_ports(struct file *file, char *buf, size_t size);
NeilBrown596bbe52006-10-04 02:15:48 -070059static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080060#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070061static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -050062static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
NeilBrown0964a3d2005-06-23 22:04:32 -070063static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080064#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66static ssize_t (*write_op[])(struct file *, char *, size_t) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 [NFSD_Fh] = write_filehandle,
Chuck Leverb046ccd2008-12-12 16:57:13 -050068 [NFSD_FO_UnlockIP] = write_unlock_ip,
69 [NFSD_FO_UnlockFS] = write_unlock_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 [NFSD_Threads] = write_threads,
Greg Bankseed29652006-10-02 02:18:02 -070071 [NFSD_Pool_Threads] = write_pool_threads,
NeilBrown70c3b762005-11-07 01:00:25 -080072 [NFSD_Versions] = write_versions,
NeilBrown80212d52006-10-02 02:17:47 -070073 [NFSD_Ports] = write_ports,
NeilBrown596bbe52006-10-04 02:15:48 -070074 [NFSD_MaxBlkSize] = write_maxblksize,
NeilBrown70c3b762005-11-07 01:00:25 -080075#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 [NFSD_Leasetime] = write_leasetime,
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -050077 [NFSD_Gracetime] = write_gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -070078 [NFSD_RecoveryDir] = write_recoverydir,
NeilBrown70c3b762005-11-07 01:00:25 -080079#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070080};
81
82static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
83{
Josef "Jeff" Sipek7eaa36e2006-12-08 02:36:41 -080084 ino_t ino = file->f_path.dentry->d_inode->i_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 char *data;
86 ssize_t rv;
87
Tobias Klausere8c96f82006-03-24 03:15:34 -080088 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return -EINVAL;
90
91 data = simple_transaction_get(file, buf, size);
92 if (IS_ERR(data))
93 return PTR_ERR(data);
94
95 rv = write_op[ino](file, data, size);
NeilBrown8971a102007-02-14 00:33:11 -080096 if (rv >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 simple_transaction_set(file, rv);
98 rv = size;
99 }
100 return rv;
101}
102
NeilBrown73900222005-11-07 01:00:24 -0800103static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
104{
105 if (! file->private_data) {
106 /* An attempt to read a transaction file without writing
107 * causes a 0-byte write so that the file can return
108 * state information
109 */
110 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
111 if (rv < 0)
112 return rv;
113 }
114 return simple_transaction_read(file, buf, size, pos);
115}
116
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800117static const struct file_operations transaction_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .write = nfsctl_transaction_write,
NeilBrown73900222005-11-07 01:00:24 -0800119 .read = nfsctl_transaction_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .release = simple_transaction_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200121 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122};
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static int exports_open(struct inode *inode, struct file *file)
125{
126 return seq_open(file, &nfs_exports_op);
127}
128
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800129static const struct file_operations exports_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .open = exports_open,
131 .read = seq_read,
132 .llseek = seq_lseek,
133 .release = seq_release,
Denis V. Lunev9ef2db22008-04-29 01:02:04 -0700134 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
J. Bruce Fieldse8e87532009-12-14 12:53:32 -0500137static int export_features_show(struct seq_file *m, void *v)
138{
139 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
140 return 0;
141}
142
143static int export_features_open(struct inode *inode, struct file *file)
144{
145 return single_open(file, export_features_show, NULL);
146}
147
148static struct file_operations export_features_operations = {
149 .open = export_features_open,
150 .read = seq_read,
151 .llseek = seq_lseek,
152 .release = single_release,
153};
154
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400155#if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500156static int supported_enctypes_show(struct seq_file *m, void *v)
157{
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400158 seq_printf(m, KRB5_SUPPORTED_ENCTYPES);
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500159 return 0;
160}
161
162static int supported_enctypes_open(struct inode *inode, struct file *file)
163{
164 return single_open(file, supported_enctypes_show, NULL);
165}
166
167static struct file_operations supported_enctypes_ops = {
168 .open = supported_enctypes_open,
169 .read = seq_read,
170 .llseek = seq_lseek,
171 .release = single_release,
172};
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400173#endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500174
Greg Banks03cf6c92009-01-13 21:26:36 +1100175extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900176extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
Greg Banks03cf6c92009-01-13 21:26:36 +1100177
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700178static const struct file_operations pool_stats_operations = {
Greg Banks03cf6c92009-01-13 21:26:36 +1100179 .open = nfsd_pool_stats_open,
180 .read = seq_read,
181 .llseek = seq_lseek,
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900182 .release = nfsd_pool_stats_release,
Greg Banks03cf6c92009-01-13 21:26:36 +1100183 .owner = THIS_MODULE,
184};
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/*----------------------------------------------------------------------------*/
187/*
188 * payload - write methods
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 */
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Chuck Lever262a0982008-12-12 16:57:35 -0500192/**
193 * write_unlock_ip - Release all locks used by a client
194 *
195 * Experimental.
196 *
197 * Input:
198 * buf: '\n'-terminated C string containing a
Chuck Lever41160922009-08-09 15:09:40 -0400199 * presentation format IP address
Chuck Lever262a0982008-12-12 16:57:35 -0500200 * size: length of C string in @buf
201 * Output:
202 * On success: returns zero if all specified locks were released;
203 * returns one if one or more locks were not released
204 * On error: return code is negative errno value
Chuck Lever262a0982008-12-12 16:57:35 -0500205 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500206static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500207{
Chuck Lever41160922009-08-09 15:09:40 -0400208 struct sockaddr_storage address;
209 struct sockaddr *sap = (struct sockaddr *)&address;
210 size_t salen = sizeof(address);
Chuck Lever367c8c72008-06-30 18:58:14 -0400211 char *fo_path;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500212
213 /* sanity check */
214 if (size == 0)
215 return -EINVAL;
216
217 if (buf[size-1] != '\n')
218 return -EINVAL;
219
220 fo_path = buf;
221 if (qword_get(&buf, fo_path, size) < 0)
222 return -EINVAL;
223
Chuck Lever41160922009-08-09 15:09:40 -0400224 if (rpc_pton(fo_path, size, sap, salen) == 0)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500225 return -EINVAL;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500226
Chuck Lever41160922009-08-09 15:09:40 -0400227 return nlmsvc_unlock_all_by_ip(sap);
Wendy Cheng4373ea82008-01-17 11:10:12 -0500228}
229
Chuck Lever262a0982008-12-12 16:57:35 -0500230/**
231 * write_unlock_fs - Release all locks on a local file system
232 *
233 * Experimental.
234 *
235 * Input:
236 * buf: '\n'-terminated C string containing the
237 * absolute pathname of a local file system
238 * size: length of C string in @buf
239 * Output:
240 * On success: returns zero if all specified locks were released;
241 * returns one if one or more locks were not released
242 * On error: return code is negative errno value
243 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500244static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
Wendy Cheng17efa372008-01-17 11:10:12 -0500245{
Al Viroa63bb992008-08-02 01:03:36 -0400246 struct path path;
Wendy Cheng17efa372008-01-17 11:10:12 -0500247 char *fo_path;
248 int error;
249
250 /* sanity check */
251 if (size == 0)
252 return -EINVAL;
253
254 if (buf[size-1] != '\n')
255 return -EINVAL;
256
257 fo_path = buf;
258 if (qword_get(&buf, fo_path, size) < 0)
259 return -EINVAL;
260
Al Viroa63bb992008-08-02 01:03:36 -0400261 error = kern_path(fo_path, 0, &path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500262 if (error)
263 return error;
264
Chuck Lever262a0982008-12-12 16:57:35 -0500265 /*
266 * XXX: Needs better sanity checking. Otherwise we could end up
267 * releasing locks on the wrong file system.
268 *
269 * For example:
270 * 1. Does the path refer to a directory?
271 * 2. Is that directory a mount point, or
272 * 3. Is that directory the root of an exported file system?
273 */
Al Viroa63bb992008-08-02 01:03:36 -0400274 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
Wendy Cheng17efa372008-01-17 11:10:12 -0500275
Al Viroa63bb992008-08-02 01:03:36 -0400276 path_put(&path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500277 return error;
278}
279
Chuck Lever262a0982008-12-12 16:57:35 -0500280/**
281 * write_filehandle - Get a variable-length NFS file handle by path
282 *
283 * On input, the buffer contains a '\n'-terminated C string comprised of
284 * three alphanumeric words separated by whitespace. The string may
285 * contain escape sequences.
286 *
287 * Input:
288 * buf:
289 * domain: client domain name
290 * path: export pathname
291 * maxsize: numeric maximum size of
292 * @buf
293 * size: length of C string in @buf
294 * Output:
295 * On success: passed-in buffer filled with '\n'-terminated C
296 * string containing a ASCII hex text version
297 * of the NFS file handle;
298 * return code is the size in bytes of the string
299 * On error: return code is negative errno value
300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
302{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 char *dname, *path;
Andrew Morton246d95b2007-08-09 00:53:50 -0700304 int uninitialized_var(maxsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 char *mesg = buf;
306 int len;
307 struct auth_domain *dom;
308 struct knfsd_fh fh;
309
J. Bruce Fields87d26ea2008-01-22 17:40:42 -0500310 if (size == 0)
311 return -EINVAL;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (buf[size-1] != '\n')
314 return -EINVAL;
315 buf[size-1] = 0;
316
317 dname = mesg;
318 len = qword_get(&mesg, dname, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500319 if (len <= 0)
320 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 path = dname+len+1;
323 len = qword_get(&mesg, path, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500324 if (len <= 0)
325 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 len = get_int(&mesg, &maxsize);
328 if (len)
329 return len;
330
331 if (maxsize < NFS_FHSIZE)
332 return -EINVAL;
333 if (maxsize > NFS3_FHSIZE)
334 maxsize = NFS3_FHSIZE;
335
336 if (qword_get(&mesg, mesg, size)>0)
337 return -EINVAL;
338
339 /* we have all the words, they are in buf.. */
340 dom = unix_domain_find(dname);
341 if (!dom)
342 return -ENOMEM;
343
344 len = exp_rootfh(dom, path, &fh, maxsize);
345 auth_domain_put(dom);
346 if (len)
347 return len;
348
Chuck Lever54224f02008-12-12 16:57:20 -0500349 mesg = buf;
350 len = SIMPLE_TRANSACTION_LIMIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
352 mesg[-1] = '\n';
353 return mesg - buf;
354}
355
Chuck Lever262a0982008-12-12 16:57:35 -0500356/**
357 * write_threads - Start NFSD, or report the current number of running threads
358 *
359 * Input:
360 * buf: ignored
361 * size: zero
362 * Output:
363 * On success: passed-in buffer filled with '\n'-terminated C
364 * string numeric value representing the number of
365 * running NFSD threads;
366 * return code is the size in bytes of the string
367 * On error: return code is zero
368 *
369 * OR
370 *
371 * Input:
372 * buf: C string containing an unsigned
373 * integer value representing the
374 * number of NFSD threads to start
375 * size: non-zero length of C string in @buf
376 * Output:
377 * On success: NFS service is started;
378 * passed-in buffer filled with '\n'-terminated C
379 * string numeric value representing the number of
380 * running NFSD threads;
381 * return code is the size in bytes of the string
382 * On error: return code is zero or a negative errno value
383 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384static ssize_t write_threads(struct file *file, char *buf, size_t size)
385{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 char *mesg = buf;
387 int rv;
388 if (size > 0) {
389 int newthreads;
390 rv = get_int(&mesg, &newthreads);
391 if (rv)
392 return rv;
Chuck Lever9e074852008-12-12 16:57:27 -0500393 if (newthreads < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return -EINVAL;
Chuck Lever9e074852008-12-12 16:57:27 -0500395 rv = nfsd_svc(NFS_PORT, newthreads);
NeilBrown82e12fe2009-06-16 11:03:07 +1000396 if (rv < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return rv;
NeilBrown82e12fe2009-06-16 11:03:07 +1000398 } else
399 rv = nfsd_nrthreads();
Chuck Levere06b6402009-04-23 19:33:25 -0400400
NeilBrown82e12fe2009-06-16 11:03:07 +1000401 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
403
Chuck Lever262a0982008-12-12 16:57:35 -0500404/**
405 * write_pool_threads - Set or report the current number of threads per pool
406 *
407 * Input:
408 * buf: ignored
409 * size: zero
410 *
411 * OR
412 *
413 * Input:
414 * buf: C string containing whitespace-
415 * separated unsigned integer values
416 * representing the number of NFSD
417 * threads to start in each pool
418 * size: non-zero length of C string in @buf
419 * Output:
420 * On success: passed-in buffer filled with '\n'-terminated C
421 * string containing integer values representing the
422 * number of NFSD threads in each pool;
423 * return code is the size in bytes of the string
424 * On error: return code is zero or a negative errno value
425 */
Greg Bankseed29652006-10-02 02:18:02 -0700426static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
427{
428 /* if size > 0, look for an array of number of threads per node
429 * and apply them then write out number of threads per node as reply
430 */
431 char *mesg = buf;
432 int i;
433 int rv;
434 int len;
Neil Brownbedbdd82008-06-10 08:40:35 -0400435 int npools;
Greg Bankseed29652006-10-02 02:18:02 -0700436 int *nthreads;
437
Neil Brownbedbdd82008-06-10 08:40:35 -0400438 mutex_lock(&nfsd_mutex);
439 npools = nfsd_nrpools();
Greg Bankseed29652006-10-02 02:18:02 -0700440 if (npools == 0) {
441 /*
442 * NFS is shut down. The admin can start it by
443 * writing to the threads file but NOT the pool_threads
444 * file, sorry. Report zero threads.
445 */
Neil Brownbedbdd82008-06-10 08:40:35 -0400446 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700447 strcpy(buf, "0\n");
448 return strlen(buf);
449 }
450
451 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
Neil Brownbedbdd82008-06-10 08:40:35 -0400452 rv = -ENOMEM;
Greg Bankseed29652006-10-02 02:18:02 -0700453 if (nthreads == NULL)
Neil Brownbedbdd82008-06-10 08:40:35 -0400454 goto out_free;
Greg Bankseed29652006-10-02 02:18:02 -0700455
456 if (size > 0) {
457 for (i = 0; i < npools; i++) {
458 rv = get_int(&mesg, &nthreads[i]);
459 if (rv == -ENOENT)
460 break; /* fewer numbers than pools */
461 if (rv)
462 goto out_free; /* syntax error */
463 rv = -EINVAL;
464 if (nthreads[i] < 0)
465 goto out_free;
466 }
467 rv = nfsd_set_nrthreads(i, nthreads);
468 if (rv)
469 goto out_free;
470 }
471
472 rv = nfsd_get_nrthreads(npools, nthreads);
473 if (rv)
474 goto out_free;
475
476 mesg = buf;
477 size = SIMPLE_TRANSACTION_LIMIT;
478 for (i = 0; i < npools && size > 0; i++) {
479 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
480 len = strlen(mesg);
481 size -= len;
482 mesg += len;
483 }
J. Bruce Fields413d63d7102009-07-28 11:37:25 -0400484 rv = mesg - buf;
Greg Bankseed29652006-10-02 02:18:02 -0700485out_free:
486 kfree(nthreads);
Neil Brownbedbdd82008-06-10 08:40:35 -0400487 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700488 return rv;
489}
490
Jeff Layton3dd98a32008-06-10 08:40:36 -0400491static ssize_t __write_versions(struct file *file, char *buf, size_t size)
NeilBrown70c3b762005-11-07 01:00:25 -0800492{
NeilBrown70c3b762005-11-07 01:00:25 -0800493 char *mesg = buf;
Benny Halevy8daf2202009-04-03 08:28:59 +0300494 char *vers, *minorp, sign;
Chuck Lever261758b2009-04-23 19:33:18 -0400495 int len, num, remaining;
Benny Halevy8daf2202009-04-03 08:28:59 +0300496 unsigned minor;
NeilBrown70c3b762005-11-07 01:00:25 -0800497 ssize_t tlen = 0;
498 char *sep;
499
500 if (size>0) {
501 if (nfsd_serv)
NeilBrown6658d3a2006-10-02 02:17:46 -0700502 /* Cannot change versions without updating
503 * nfsd_serv->sv_xdrsize, and reallocing
504 * rq_argp and rq_resp
505 */
NeilBrown70c3b762005-11-07 01:00:25 -0800506 return -EBUSY;
507 if (buf[size-1] != '\n')
508 return -EINVAL;
509 buf[size-1] = 0;
510
511 vers = mesg;
512 len = qword_get(&mesg, vers, size);
513 if (len <= 0) return -EINVAL;
514 do {
515 sign = *vers;
516 if (sign == '+' || sign == '-')
Benny Halevy8daf2202009-04-03 08:28:59 +0300517 num = simple_strtol((vers+1), &minorp, 0);
NeilBrown70c3b762005-11-07 01:00:25 -0800518 else
Benny Halevy8daf2202009-04-03 08:28:59 +0300519 num = simple_strtol(vers, &minorp, 0);
520 if (*minorp == '.') {
521 if (num < 4)
522 return -EINVAL;
523 minor = simple_strtoul(minorp+1, NULL, 0);
524 if (minor == 0)
525 return -EINVAL;
526 if (nfsd_minorversion(minor, sign == '-' ?
527 NFSD_CLEAR : NFSD_SET) < 0)
528 return -EINVAL;
529 goto next;
530 }
NeilBrown70c3b762005-11-07 01:00:25 -0800531 switch(num) {
532 case 2:
533 case 3:
534 case 4:
NeilBrown6658d3a2006-10-02 02:17:46 -0700535 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
NeilBrown70c3b762005-11-07 01:00:25 -0800536 break;
537 default:
538 return -EINVAL;
539 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300540 next:
NeilBrown70c3b762005-11-07 01:00:25 -0800541 vers += len + 1;
NeilBrown70c3b762005-11-07 01:00:25 -0800542 } while ((len = qword_get(&mesg, vers, size)) > 0);
543 /* If all get turned off, turn them back on, as
544 * having no versions is BAD
545 */
NeilBrown6658d3a2006-10-02 02:17:46 -0700546 nfsd_reset_versions();
NeilBrown70c3b762005-11-07 01:00:25 -0800547 }
Chuck Lever261758b2009-04-23 19:33:18 -0400548
NeilBrown70c3b762005-11-07 01:00:25 -0800549 /* Now write current state into reply buffer */
550 len = 0;
551 sep = "";
Chuck Lever261758b2009-04-23 19:33:18 -0400552 remaining = SIMPLE_TRANSACTION_LIMIT;
NeilBrown70c3b762005-11-07 01:00:25 -0800553 for (num=2 ; num <= 4 ; num++)
NeilBrown6658d3a2006-10-02 02:17:46 -0700554 if (nfsd_vers(num, NFSD_AVAIL)) {
Chuck Lever261758b2009-04-23 19:33:18 -0400555 len = snprintf(buf, remaining, "%s%c%d", sep,
NeilBrown6658d3a2006-10-02 02:17:46 -0700556 nfsd_vers(num, NFSD_TEST)?'+':'-',
NeilBrown70c3b762005-11-07 01:00:25 -0800557 num);
558 sep = " ";
Chuck Lever261758b2009-04-23 19:33:18 -0400559
560 if (len > remaining)
561 break;
562 remaining -= len;
563 buf += len;
564 tlen += len;
NeilBrown70c3b762005-11-07 01:00:25 -0800565 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300566 if (nfsd_vers(4, NFSD_AVAIL))
Chuck Lever261758b2009-04-23 19:33:18 -0400567 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
568 minor++) {
569 len = snprintf(buf, remaining, " %c4.%u",
Benny Halevy8daf2202009-04-03 08:28:59 +0300570 (nfsd_vers(4, NFSD_TEST) &&
571 nfsd_minorversion(minor, NFSD_TEST)) ?
572 '+' : '-',
573 minor);
Chuck Lever261758b2009-04-23 19:33:18 -0400574
575 if (len > remaining)
576 break;
577 remaining -= len;
578 buf += len;
579 tlen += len;
580 }
581
582 len = snprintf(buf, remaining, "\n");
583 if (len > remaining)
584 return -EINVAL;
585 return tlen + len;
NeilBrown70c3b762005-11-07 01:00:25 -0800586}
587
Chuck Lever262a0982008-12-12 16:57:35 -0500588/**
589 * write_versions - Set or report the available NFS protocol versions
590 *
591 * Input:
592 * buf: ignored
593 * size: zero
594 * Output:
595 * On success: passed-in buffer filled with '\n'-terminated C
596 * string containing positive or negative integer
597 * values representing the current status of each
598 * protocol version;
599 * return code is the size in bytes of the string
600 * On error: return code is zero or a negative errno value
601 *
602 * OR
603 *
604 * Input:
605 * buf: C string containing whitespace-
606 * separated positive or negative
607 * integer values representing NFS
608 * protocol versions to enable ("+n")
609 * or disable ("-n")
610 * size: non-zero length of C string in @buf
611 * Output:
612 * On success: status of zero or more protocol versions has
613 * been updated; passed-in buffer filled with
614 * '\n'-terminated C string containing positive
615 * or negative integer values representing the
616 * current status of each protocol version;
617 * return code is the size in bytes of the string
618 * On error: return code is zero or a negative errno value
619 */
Jeff Layton3dd98a32008-06-10 08:40:36 -0400620static ssize_t write_versions(struct file *file, char *buf, size_t size)
621{
622 ssize_t rv;
623
624 mutex_lock(&nfsd_mutex);
625 rv = __write_versions(file, buf, size);
626 mutex_unlock(&nfsd_mutex);
627 return rv;
628}
629
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400630/*
Chuck Lever0a5372d2009-04-23 19:32:10 -0400631 * Zero-length write. Return a list of NFSD's current listener
632 * transports.
633 */
634static ssize_t __write_ports_names(char *buf)
635{
636 if (nfsd_serv == NULL)
637 return 0;
Chuck Lever335c54b2009-04-23 19:32:25 -0400638 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
Chuck Lever0a5372d2009-04-23 19:32:10 -0400639}
640
641/*
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400642 * A single 'fd' number was written, in which case it must be for
643 * a socket of a supported family/protocol, and we use it as an
644 * nfsd listener.
645 */
646static ssize_t __write_ports_addfd(char *buf)
647{
648 char *mesg = buf;
649 int fd, err;
650
651 err = get_int(&mesg, &fd);
652 if (err != 0 || fd < 0)
653 return -EINVAL;
654
655 err = nfsd_create_serv();
656 if (err != 0)
657 return err;
658
Chuck Leverbfba9ab2009-04-23 19:32:33 -0400659 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400660 if (err < 0) {
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400661 svc_destroy(nfsd_serv);
662 return err;
663 }
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400664
Chuck Leverea068ba2009-04-23 19:32:18 -0400665 /* Decrease the count, but don't shut down the service */
666 nfsd_serv->sv_nrthreads--;
667 return err;
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400668}
669
670/*
Chuck Lever82d56592009-04-23 19:31:48 -0400671 * A '-' followed by the 'name' of a socket means we close the socket.
672 */
673static ssize_t __write_ports_delfd(char *buf)
674{
675 char *toclose;
676 int len = 0;
677
678 toclose = kstrdup(buf + 1, GFP_KERNEL);
679 if (toclose == NULL)
680 return -ENOMEM;
681
682 if (nfsd_serv != NULL)
Chuck Lever8435d342009-04-23 19:32:40 -0400683 len = svc_sock_names(nfsd_serv, buf,
684 SIMPLE_TRANSACTION_LIMIT, toclose);
Chuck Lever82d56592009-04-23 19:31:48 -0400685 kfree(toclose);
686 return len;
687}
688
689/*
Chuck Lever4eb68c22009-04-23 19:31:40 -0400690 * A transport listener is added by writing it's transport name and
691 * a port number.
692 */
693static ssize_t __write_ports_addxprt(char *buf)
694{
695 char transport[16];
Chuck Lever37498292010-01-26 14:04:22 -0500696 struct svc_xprt *xprt;
Chuck Lever4eb68c22009-04-23 19:31:40 -0400697 int port, err;
698
699 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
700 return -EINVAL;
701
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700702 if (port < 1 || port > USHRT_MAX)
Chuck Lever4eb68c22009-04-23 19:31:40 -0400703 return -EINVAL;
704
705 err = nfsd_create_serv();
706 if (err != 0)
707 return err;
708
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +0400709 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever4eb68c22009-04-23 19:31:40 -0400710 PF_INET, port, SVC_SOCK_ANONYMOUS);
Chuck Lever68717902010-01-26 14:04:13 -0500711 if (err < 0)
Chuck Lever37498292010-01-26 14:04:22 -0500712 goto out_err;
713
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +0400714 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever37498292010-01-26 14:04:22 -0500715 PF_INET6, port, SVC_SOCK_ANONYMOUS);
716 if (err < 0 && err != -EAFNOSUPPORT)
717 goto out_close;
Jeff Layton0cd14a02010-07-19 16:50:06 -0400718
719 /* Decrease the count, but don't shut down the service */
720 nfsd_serv->sv_nrthreads--;
Chuck Lever4eb68c22009-04-23 19:31:40 -0400721 return 0;
Chuck Lever37498292010-01-26 14:04:22 -0500722out_close:
723 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
724 if (xprt != NULL) {
725 svc_close_xprt(xprt);
726 svc_xprt_put(xprt);
727 }
728out_err:
Jeff Layton0cd14a02010-07-19 16:50:06 -0400729 svc_destroy(nfsd_serv);
Chuck Lever37498292010-01-26 14:04:22 -0500730 return err;
Chuck Lever4eb68c22009-04-23 19:31:40 -0400731}
732
733/*
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400734 * A transport listener is removed by writing a "-", it's transport
735 * name, and it's port number.
736 */
737static ssize_t __write_ports_delxprt(char *buf)
738{
739 struct svc_xprt *xprt;
740 char transport[16];
741 int port;
742
743 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
744 return -EINVAL;
745
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700746 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400747 return -EINVAL;
748
749 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
750 if (xprt == NULL)
751 return -ENOTCONN;
752
753 svc_close_xprt(xprt);
754 svc_xprt_put(xprt);
755 return 0;
756}
757
Neil Brownbedbdd82008-06-10 08:40:35 -0400758static ssize_t __write_ports(struct file *file, char *buf, size_t size)
NeilBrown80212d52006-10-02 02:17:47 -0700759{
Chuck Lever0a5372d2009-04-23 19:32:10 -0400760 if (size == 0)
761 return __write_ports_names(buf);
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400762
763 if (isdigit(buf[0]))
764 return __write_ports_addfd(buf);
Chuck Lever82d56592009-04-23 19:31:48 -0400765
766 if (buf[0] == '-' && isdigit(buf[1]))
767 return __write_ports_delfd(buf);
Chuck Lever4eb68c22009-04-23 19:31:40 -0400768
769 if (isalpha(buf[0]))
770 return __write_ports_addxprt(buf);
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400771
772 if (buf[0] == '-' && isalpha(buf[1]))
773 return __write_ports_delxprt(buf);
774
NeilBrownb41b66d2006-10-02 02:17:48 -0700775 return -EINVAL;
NeilBrown80212d52006-10-02 02:17:47 -0700776}
777
Chuck Lever262a0982008-12-12 16:57:35 -0500778/**
779 * write_ports - Pass a socket file descriptor or transport name to listen on
780 *
781 * Input:
782 * buf: ignored
783 * size: zero
784 * Output:
785 * On success: passed-in buffer filled with a '\n'-terminated C
786 * string containing a whitespace-separated list of
787 * named NFSD listeners;
788 * return code is the size in bytes of the string
789 * On error: return code is zero or a negative errno value
790 *
791 * OR
792 *
793 * Input:
794 * buf: C string containing an unsigned
795 * integer value representing a bound
796 * but unconnected socket that is to be
Chuck Leverc71206a2009-04-23 19:32:03 -0400797 * used as an NFSD listener; listen(3)
798 * must be called for a SOCK_STREAM
799 * socket, otherwise it is ignored
Chuck Lever262a0982008-12-12 16:57:35 -0500800 * size: non-zero length of C string in @buf
801 * Output:
802 * On success: NFS service is started;
803 * passed-in buffer filled with a '\n'-terminated C
804 * string containing a unique alphanumeric name of
805 * the listener;
806 * return code is the size in bytes of the string
807 * On error: return code is a negative errno value
808 *
809 * OR
810 *
811 * Input:
812 * buf: C string containing a "-" followed
813 * by an integer value representing a
814 * previously passed in socket file
815 * descriptor
816 * size: non-zero length of C string in @buf
817 * Output:
818 * On success: NFS service no longer listens on that socket;
819 * passed-in buffer filled with a '\n'-terminated C
820 * string containing a unique name of the listener;
821 * return code is the size in bytes of the string
822 * On error: return code is a negative errno value
823 *
824 * OR
825 *
826 * Input:
827 * buf: C string containing a transport
828 * name and an unsigned integer value
829 * representing the port to listen on,
830 * separated by whitespace
831 * size: non-zero length of C string in @buf
832 * Output:
833 * On success: returns zero; NFS service is started
834 * On error: return code is a negative errno value
835 *
836 * OR
837 *
838 * Input:
839 * buf: C string containing a "-" followed
840 * by a transport name and an unsigned
841 * integer value representing the port
842 * to listen on, separated by whitespace
843 * size: non-zero length of C string in @buf
844 * Output:
845 * On success: returns zero; NFS service no longer listens
846 * on that transport
847 * On error: return code is a negative errno value
848 */
Neil Brownbedbdd82008-06-10 08:40:35 -0400849static ssize_t write_ports(struct file *file, char *buf, size_t size)
850{
851 ssize_t rv;
Jeff Layton3dd98a32008-06-10 08:40:36 -0400852
Neil Brownbedbdd82008-06-10 08:40:35 -0400853 mutex_lock(&nfsd_mutex);
854 rv = __write_ports(file, buf, size);
855 mutex_unlock(&nfsd_mutex);
856 return rv;
857}
858
859
NeilBrown596bbe52006-10-04 02:15:48 -0700860int nfsd_max_blksize;
861
Chuck Lever262a0982008-12-12 16:57:35 -0500862/**
863 * write_maxblksize - Set or report the current NFS blksize
864 *
865 * Input:
866 * buf: ignored
867 * size: zero
868 *
869 * OR
870 *
871 * Input:
872 * buf: C string containing an unsigned
873 * integer value representing the new
874 * NFS blksize
875 * size: non-zero length of C string in @buf
876 * Output:
877 * On success: passed-in buffer filled with '\n'-terminated C string
878 * containing numeric value of the current NFS blksize
879 * setting;
880 * return code is the size in bytes of the string
881 * On error: return code is zero or a negative errno value
882 */
NeilBrown596bbe52006-10-04 02:15:48 -0700883static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
884{
885 char *mesg = buf;
886 if (size > 0) {
887 int bsize;
888 int rv = get_int(&mesg, &bsize);
889 if (rv)
890 return rv;
891 /* force bsize into allowed range and
892 * required alignment.
893 */
894 if (bsize < 1024)
895 bsize = 1024;
896 if (bsize > NFSSVC_MAXBLKSIZE)
897 bsize = NFSSVC_MAXBLKSIZE;
898 bsize &= ~(1024-1);
Neil Brownbedbdd82008-06-10 08:40:35 -0400899 mutex_lock(&nfsd_mutex);
J. Bruce Fields7fa53cc2010-08-06 18:00:33 -0400900 if (nfsd_serv) {
Neil Brownbedbdd82008-06-10 08:40:35 -0400901 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -0700902 return -EBUSY;
903 }
904 nfsd_max_blksize = bsize;
Neil Brownbedbdd82008-06-10 08:40:35 -0400905 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -0700906 }
Chuck Levere06b6402009-04-23 19:33:25 -0400907
908 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
909 nfsd_max_blksize);
NeilBrown596bbe52006-10-04 02:15:48 -0700910}
911
NeilBrown70c3b762005-11-07 01:00:25 -0800912#ifdef CONFIG_NFSD_V4
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500913static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 char *mesg = buf;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500916 int rv, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 if (size > 0) {
Jeff Layton3dd98a32008-06-10 08:40:36 -0400919 if (nfsd_serv)
920 return -EBUSY;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500921 rv = get_int(&mesg, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (rv)
923 return rv;
J. Bruce Fieldse7b184f2010-03-02 11:18:40 -0500924 /*
925 * Some sanity checking. We don't have a reason for
926 * these particular numbers, but problems with the
927 * extremes are:
928 * - Too short: the briefest network outage may
929 * cause clients to lose all their locks. Also,
930 * the frequent polling may be wasteful.
931 * - Too long: do you really want reboot recovery
932 * to take more than an hour? Or to make other
933 * clients wait an hour before being able to
934 * revoke a dead client's locks?
935 */
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500936 if (i < 10 || i > 3600)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 return -EINVAL;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500938 *time = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
Chuck Levere06b6402009-04-23 19:33:25 -0400940
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500941 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
942}
943
944static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
945{
946 ssize_t rv;
947
948 mutex_lock(&nfsd_mutex);
949 rv = __nfsd4_write_time(file, buf, size, time);
950 mutex_unlock(&nfsd_mutex);
951 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
Chuck Lever262a0982008-12-12 16:57:35 -0500954/**
955 * write_leasetime - Set or report the current NFSv4 lease time
956 *
957 * Input:
958 * buf: ignored
959 * size: zero
960 *
961 * OR
962 *
963 * Input:
964 * buf: C string containing an unsigned
965 * integer value representing the new
966 * NFSv4 lease expiry time
967 * size: non-zero length of C string in @buf
968 * Output:
969 * On success: passed-in buffer filled with '\n'-terminated C
970 * string containing unsigned integer value of the
971 * current lease expiry time;
972 * return code is the size in bytes of the string
973 * On error: return code is zero or a negative errno value
974 */
Jeff Layton3dd98a32008-06-10 08:40:36 -0400975static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
976{
J. Bruce Fieldsf0135742010-03-01 19:32:36 -0500977 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
Jeff Layton3dd98a32008-06-10 08:40:36 -0400978}
979
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -0500980/**
981 * write_gracetime - Set or report current NFSv4 grace period time
982 *
983 * As above, but sets the time of the NFSv4 grace period.
984 *
985 * Note this should never be set to less than the *previous*
986 * lease-period time, but we don't try to enforce this. (In the common
987 * case (a new boot), we don't know what the previous lease time was
988 * anyway.)
989 */
990static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
991{
992 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
993}
994
Jeff Layton3dd98a32008-06-10 08:40:36 -0400995extern char *nfs4_recoverydir(void);
996
997static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
NeilBrown0964a3d2005-06-23 22:04:32 -0700998{
999 char *mesg = buf;
1000 char *recdir;
1001 int len, status;
1002
Jeff Layton3dd98a32008-06-10 08:40:36 -04001003 if (size > 0) {
1004 if (nfsd_serv)
1005 return -EBUSY;
1006 if (size > PATH_MAX || buf[size-1] != '\n')
1007 return -EINVAL;
1008 buf[size-1] = 0;
NeilBrown0964a3d2005-06-23 22:04:32 -07001009
Jeff Layton3dd98a32008-06-10 08:40:36 -04001010 recdir = mesg;
1011 len = qword_get(&mesg, recdir, size);
1012 if (len <= 0)
1013 return -EINVAL;
NeilBrown0964a3d2005-06-23 22:04:32 -07001014
Jeff Layton3dd98a32008-06-10 08:40:36 -04001015 status = nfs4_reset_recoverydir(recdir);
Andi Kleen69049962010-07-20 15:24:27 -07001016 if (status)
1017 return status;
Jeff Layton3dd98a32008-06-10 08:40:36 -04001018 }
Chuck Lever3d72ab82009-04-23 19:33:10 -04001019
1020 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1021 nfs4_recoverydir());
NeilBrown0964a3d2005-06-23 22:04:32 -07001022}
Jeff Layton3dd98a32008-06-10 08:40:36 -04001023
Chuck Lever262a0982008-12-12 16:57:35 -05001024/**
1025 * write_recoverydir - Set or report the pathname of the recovery directory
1026 *
1027 * Input:
1028 * buf: ignored
1029 * size: zero
1030 *
1031 * OR
1032 *
1033 * Input:
1034 * buf: C string containing the pathname
1035 * of the directory on a local file
1036 * system containing permanent NFSv4
1037 * recovery data
1038 * size: non-zero length of C string in @buf
1039 * Output:
1040 * On success: passed-in buffer filled with '\n'-terminated C string
1041 * containing the current recovery pathname setting;
1042 * return code is the size in bytes of the string
1043 * On error: return code is zero or a negative errno value
1044 */
Jeff Layton3dd98a32008-06-10 08:40:36 -04001045static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1046{
1047 ssize_t rv;
1048
1049 mutex_lock(&nfsd_mutex);
1050 rv = __write_recoverydir(file, buf, size);
1051 mutex_unlock(&nfsd_mutex);
1052 return rv;
1053}
1054
NeilBrown70c3b762005-11-07 01:00:25 -08001055#endif
NeilBrown0964a3d2005-06-23 22:04:32 -07001056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057/*----------------------------------------------------------------------------*/
1058/*
1059 * populating the filesystem.
1060 */
1061
1062static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1063{
1064 static struct tree_descr nfsd_files[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
J. Bruce Fieldse8e87532009-12-14 12:53:32 -05001066 [NFSD_Export_features] = {"export_features",
1067 &export_features_operations, S_IRUGO},
Wendy Cheng4373ea82008-01-17 11:10:12 -05001068 [NFSD_FO_UnlockIP] = {"unlock_ip",
1069 &transaction_ops, S_IWUSR|S_IRUSR},
Wendy Cheng17efa372008-01-17 11:10:12 -05001070 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1071 &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1073 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Bankseed29652006-10-02 02:18:02 -07001074 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Banks03cf6c92009-01-13 21:26:36 +11001075 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
NeilBrown70c3b762005-11-07 01:00:25 -08001076 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown80212d52006-10-02 02:17:47 -07001077 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
NeilBrown596bbe52006-10-04 02:15:48 -07001078 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
J. Bruce Fieldsb084f592011-05-31 12:24:58 -04001079#if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -05001080 [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO},
J. Bruce Fieldsb084f592011-05-31 12:24:58 -04001081#endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082#ifdef CONFIG_NFSD_V4
1083 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
J. Bruce Fieldsefc4bb4f2010-03-02 11:04:06 -05001084 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown0964a3d2005-06-23 22:04:32 -07001085 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086#endif
1087 /* last one */ {""}
1088 };
1089 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1090}
1091
Al Virofc14f2f2010-07-25 01:48:30 +04001092static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1093 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
Al Virofc14f2f2010-07-25 01:48:30 +04001095 return mount_single(fs_type, flags, data, nfsd_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096}
1097
1098static struct file_system_type nfsd_fs_type = {
1099 .owner = THIS_MODULE,
1100 .name = "nfsd",
Al Virofc14f2f2010-07-25 01:48:30 +04001101 .mount = nfsd_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .kill_sb = kill_litter_super,
1103};
1104
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001105#ifdef CONFIG_PROC_FS
1106static int create_proc_exports_entry(void)
1107{
1108 struct proc_dir_entry *entry;
1109
1110 entry = proc_mkdir("fs/nfs", NULL);
1111 if (!entry)
1112 return -ENOMEM;
Denis V. Lunev9ef2db22008-04-29 01:02:04 -07001113 entry = proc_create("exports", 0, entry, &exports_operations);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001114 if (!entry)
1115 return -ENOMEM;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001116 return 0;
1117}
1118#else /* CONFIG_PROC_FS */
1119static int create_proc_exports_entry(void)
1120{
1121 return 0;
1122}
1123#endif
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125static int __init init_nfsd(void)
1126{
1127 int retval;
1128 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1129
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001130 retval = nfs4_state_init(); /* nfs4 locking state */
1131 if (retval)
1132 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 nfsd_stat_init(); /* Statistics */
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001134 retval = nfsd_reply_cache_init();
1135 if (retval)
1136 goto out_free_stat;
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001137 retval = nfsd_export_init();
1138 if (retval)
1139 goto out_free_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 nfsd_lockd_init(); /* lockd->nfsd callbacks */
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001141 retval = nfsd_idmap_init();
1142 if (retval)
1143 goto out_free_lockd;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001144 retval = create_proc_exports_entry();
1145 if (retval)
1146 goto out_free_idmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 retval = register_filesystem(&nfsd_fs_type);
J. Bruce Fields26808d32007-11-09 13:44:06 -05001148 if (retval)
1149 goto out_free_all;
1150 return 0;
1151out_free_all:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001152 remove_proc_entry("fs/nfs/exports", NULL);
1153 remove_proc_entry("fs/nfs", NULL);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001154out_free_idmap:
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001155 nfsd_idmap_shutdown();
1156out_free_lockd:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001157 nfsd_lockd_shutdown();
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001158 nfsd_export_shutdown();
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001159out_free_cache:
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001160 nfsd_reply_cache_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001161out_free_stat:
1162 nfsd_stat_shutdown();
J. Bruce Fields26808d32007-11-09 13:44:06 -05001163 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 return retval;
1165}
1166
1167static void __exit exit_nfsd(void)
1168{
1169 nfsd_export_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001170 nfsd_reply_cache_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 remove_proc_entry("fs/nfs/exports", NULL);
1172 remove_proc_entry("fs/nfs", NULL);
1173 nfsd_stat_shutdown();
1174 nfsd_lockd_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 nfsd_idmap_shutdown();
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001176 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 unregister_filesystem(&nfsd_fs_type);
1178}
1179
1180MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1181MODULE_LICENSE("GPL");
1182module_init(init_nfsd)
1183module_exit(exit_nfsd)