blob: 2b1449dd2f495b4c6389399b8e29e0da7165d2c2 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/nfsd/syscall.h>
Wendy Cheng4373ea82008-01-17 11:10:12 -050013#include <linux/lockd/lockd.h>
Chuck Lever41160922009-08-09 15:09:40 -040014#include <linux/sunrpc/clnt.h>
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050015#include <linux/sunrpc/gss_api.h>
J. Bruce Fieldsb084f592011-05-31 12:24:58 -040016#include <linux/sunrpc/gss_krb5_enctypes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
J. Bruce Fields2ca72e12011-01-04 17:37:15 -050018#include "idmap.h"
Boaz Harrosh9a74af22009-12-03 20:30:56 +020019#include "nfsd.h"
20#include "cache.h"
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/*
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050023 * We have a single directory with several nodes in it.
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 */
25enum {
26 NFSD_Root = 1,
NeilBrown1e140562010-09-22 12:55:07 +100027#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 NFSD_Svc,
29 NFSD_Add,
30 NFSD_Del,
31 NFSD_Export,
32 NFSD_Unexport,
33 NFSD_Getfd,
34 NFSD_Getfs,
NeilBrown1e140562010-09-22 12:55:07 +100035#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 NFSD_List,
J. Bruce Fieldse8e87532009-12-14 12:53:32 -050037 NFSD_Export_features,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 NFSD_Fh,
Wendy Cheng4373ea82008-01-17 11:10:12 -050039 NFSD_FO_UnlockIP,
Wendy Cheng17efa372008-01-17 11:10:12 -050040 NFSD_FO_UnlockFS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 NFSD_Threads,
Greg Bankseed29652006-10-02 02:18:02 -070042 NFSD_Pool_Threads,
Greg Banks03cf6c92009-01-13 21:26:36 +110043 NFSD_Pool_Stats,
NeilBrown70c3b762005-11-07 01:00:25 -080044 NFSD_Versions,
NeilBrown80212d52006-10-02 02:17:47 -070045 NFSD_Ports,
NeilBrown596bbe52006-10-04 02:15:48 -070046 NFSD_MaxBlkSize,
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -050047 NFSD_SupportedEnctypes,
NeilBrown70c3b762005-11-07 01:00:25 -080048 /*
49 * The below MUST come last. Otherwise we leave a hole in nfsd_files[]
50 * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops
51 */
52#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 NFSD_Leasetime,
J. Bruce Fieldsefc4bb42010-03-02 11:04:06 -050054 NFSD_Gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -070055 NFSD_RecoveryDir,
NeilBrown70c3b762005-11-07 01:00:25 -080056#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
59/*
60 * write() for these nodes.
61 */
NeilBrown1e140562010-09-22 12:55:07 +100062#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070063static ssize_t write_svc(struct file *file, char *buf, size_t size);
64static ssize_t write_add(struct file *file, char *buf, size_t size);
65static ssize_t write_del(struct file *file, char *buf, size_t size);
66static ssize_t write_export(struct file *file, char *buf, size_t size);
67static ssize_t write_unexport(struct file *file, char *buf, size_t size);
68static ssize_t write_getfd(struct file *file, char *buf, size_t size);
69static ssize_t write_getfs(struct file *file, char *buf, size_t size);
NeilBrown1e140562010-09-22 12:55:07 +100070#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070071static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
Chuck Leverb046ccd2008-12-12 16:57:13 -050072static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size);
73static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static ssize_t write_threads(struct file *file, char *buf, size_t size);
Greg Bankseed29652006-10-02 02:18:02 -070075static ssize_t write_pool_threads(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080076static ssize_t write_versions(struct file *file, char *buf, size_t size);
NeilBrown80212d52006-10-02 02:17:47 -070077static ssize_t write_ports(struct file *file, char *buf, size_t size);
NeilBrown596bbe52006-10-04 02:15:48 -070078static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080079#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
J. Bruce Fieldsefc4bb42010-03-02 11:04:06 -050081static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
NeilBrown0964a3d2005-06-23 22:04:32 -070082static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
NeilBrown70c3b762005-11-07 01:00:25 -080083#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static ssize_t (*write_op[])(struct file *, char *, size_t) = {
NeilBrown1e140562010-09-22 12:55:07 +100086#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 [NFSD_Svc] = write_svc,
88 [NFSD_Add] = write_add,
89 [NFSD_Del] = write_del,
90 [NFSD_Export] = write_export,
91 [NFSD_Unexport] = write_unexport,
92 [NFSD_Getfd] = write_getfd,
93 [NFSD_Getfs] = write_getfs,
NeilBrown1e140562010-09-22 12:55:07 +100094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 [NFSD_Fh] = write_filehandle,
Chuck Leverb046ccd2008-12-12 16:57:13 -050096 [NFSD_FO_UnlockIP] = write_unlock_ip,
97 [NFSD_FO_UnlockFS] = write_unlock_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 [NFSD_Threads] = write_threads,
Greg Bankseed29652006-10-02 02:18:02 -070099 [NFSD_Pool_Threads] = write_pool_threads,
NeilBrown70c3b762005-11-07 01:00:25 -0800100 [NFSD_Versions] = write_versions,
NeilBrown80212d52006-10-02 02:17:47 -0700101 [NFSD_Ports] = write_ports,
NeilBrown596bbe52006-10-04 02:15:48 -0700102 [NFSD_MaxBlkSize] = write_maxblksize,
NeilBrown70c3b762005-11-07 01:00:25 -0800103#ifdef CONFIG_NFSD_V4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 [NFSD_Leasetime] = write_leasetime,
J. Bruce Fieldsefc4bb42010-03-02 11:04:06 -0500105 [NFSD_Gracetime] = write_gracetime,
NeilBrown0964a3d2005-06-23 22:04:32 -0700106 [NFSD_RecoveryDir] = write_recoverydir,
NeilBrown70c3b762005-11-07 01:00:25 -0800107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108};
109
110static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
111{
Josef "Jeff" Sipek7eaa36e2006-12-08 02:36:41 -0800112 ino_t ino = file->f_path.dentry->d_inode->i_ino;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 char *data;
114 ssize_t rv;
115
Tobias Klausere8c96f82006-03-24 03:15:34 -0800116 if (ino >= ARRAY_SIZE(write_op) || !write_op[ino])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return -EINVAL;
118
119 data = simple_transaction_get(file, buf, size);
120 if (IS_ERR(data))
121 return PTR_ERR(data);
122
123 rv = write_op[ino](file, data, size);
NeilBrown8971a102007-02-14 00:33:11 -0800124 if (rv >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 simple_transaction_set(file, rv);
126 rv = size;
127 }
128 return rv;
129}
130
NeilBrown73900222005-11-07 01:00:24 -0800131static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos)
132{
bookjovi@gmail.com5b6a5992010-12-11 00:21:17 -0500133#ifdef CONFIG_NFSD_DEPRECATED
NeilBrownc67874f2010-09-22 12:55:07 +1000134 static int warned;
135 if (file->f_dentry->d_name.name[0] == '.' && !warned) {
NeilBrownc67874f2010-09-22 12:55:07 +1000136 printk(KERN_INFO
137 "Warning: \"%s\" uses deprecated NFSD interface: %s."
138 " This will be removed in 2.6.40\n",
Pavel Emelyanov049ef272010-09-23 18:26:58 +0400139 current->comm, file->f_dentry->d_name.name);
NeilBrownc67874f2010-09-22 12:55:07 +1000140 warned = 1;
141 }
bookjovi@gmail.com5b6a5992010-12-11 00:21:17 -0500142#endif
NeilBrown73900222005-11-07 01:00:24 -0800143 if (! file->private_data) {
144 /* An attempt to read a transaction file without writing
145 * causes a 0-byte write so that the file can return
146 * state information
147 */
148 ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos);
149 if (rv < 0)
150 return rv;
151 }
152 return simple_transaction_read(file, buf, size, pos);
153}
154
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800155static const struct file_operations transaction_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 .write = nfsctl_transaction_write,
NeilBrown73900222005-11-07 01:00:24 -0800157 .read = nfsctl_transaction_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 .release = simple_transaction_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200159 .llseek = default_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162static int exports_open(struct inode *inode, struct file *file)
163{
164 return seq_open(file, &nfs_exports_op);
165}
166
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800167static const struct file_operations exports_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 .open = exports_open,
169 .read = seq_read,
170 .llseek = seq_lseek,
171 .release = seq_release,
Denis V. Lunev9ef2db22008-04-29 01:02:04 -0700172 .owner = THIS_MODULE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
J. Bruce Fieldse8e87532009-12-14 12:53:32 -0500175static int export_features_show(struct seq_file *m, void *v)
176{
177 seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS);
178 return 0;
179}
180
181static int export_features_open(struct inode *inode, struct file *file)
182{
183 return single_open(file, export_features_show, NULL);
184}
185
186static struct file_operations export_features_operations = {
187 .open = export_features_open,
188 .read = seq_read,
189 .llseek = seq_lseek,
190 .release = single_release,
191};
192
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400193#if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500194static int supported_enctypes_show(struct seq_file *m, void *v)
195{
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400196 seq_printf(m, KRB5_SUPPORTED_ENCTYPES);
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500197 return 0;
198}
199
200static int supported_enctypes_open(struct inode *inode, struct file *file)
201{
202 return single_open(file, supported_enctypes_show, NULL);
203}
204
205static struct file_operations supported_enctypes_ops = {
206 .open = supported_enctypes_open,
207 .read = seq_read,
208 .llseek = seq_lseek,
209 .release = single_release,
210};
J. Bruce Fieldsb084f592011-05-31 12:24:58 -0400211#endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -0500212
Greg Banks03cf6c92009-01-13 21:26:36 +1100213extern int nfsd_pool_stats_open(struct inode *inode, struct file *file);
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900214extern int nfsd_pool_stats_release(struct inode *inode, struct file *file);
Greg Banks03cf6c92009-01-13 21:26:36 +1100215
Alexey Dobriyan828c0952009-10-01 15:43:56 -0700216static const struct file_operations pool_stats_operations = {
Greg Banks03cf6c92009-01-13 21:26:36 +1100217 .open = nfsd_pool_stats_open,
218 .read = seq_read,
219 .llseek = seq_lseek,
Ryusei Yamaguchied2d8ae2009-08-16 00:54:41 +0900220 .release = nfsd_pool_stats_release,
Greg Banks03cf6c92009-01-13 21:26:36 +1100221 .owner = THIS_MODULE,
222};
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*----------------------------------------------------------------------------*/
225/*
226 * payload - write methods
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 */
228
NeilBrown1e140562010-09-22 12:55:07 +1000229#ifdef CONFIG_NFSD_DEPRECATED
Chuck Lever262a0982008-12-12 16:57:35 -0500230/**
231 * write_svc - Start kernel's NFSD server
232 *
233 * Deprecated. /proc/fs/nfsd/threads is preferred.
234 * Function remains to support old versions of nfs-utils.
235 *
236 * Input:
237 * buf: struct nfsctl_svc
238 * svc_port: port number of this
239 * server's listener
240 * svc_nthreads: number of threads to start
241 * size: size in bytes of passed in nfsctl_svc
242 * Output:
243 * On success: returns zero
244 * On error: return code is negative errno value
245 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static ssize_t write_svc(struct file *file, char *buf, size_t size)
247{
248 struct nfsctl_svc *data;
NeilBrown82e12fe2009-06-16 11:03:07 +1000249 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (size < sizeof(*data))
251 return -EINVAL;
252 data = (struct nfsctl_svc*) buf;
NeilBrown82e12fe2009-06-16 11:03:07 +1000253 err = nfsd_svc(data->svc_port, data->svc_nthreads);
254 if (err < 0)
255 return err;
256 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Chuck Lever262a0982008-12-12 16:57:35 -0500259/**
260 * write_add - Add or modify client entry in auth unix cache
261 *
262 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
263 * Function remains to support old versions of nfs-utils.
264 *
265 * Input:
266 * buf: struct nfsctl_client
267 * cl_ident: '\0'-terminated C string
268 * containing domain name
269 * of client
270 * cl_naddr: no. of items in cl_addrlist
271 * cl_addrlist: array of client addresses
272 * cl_fhkeytype: ignored
273 * cl_fhkeylen: ignored
274 * cl_fhkey: ignored
275 * size: size in bytes of passed in nfsctl_client
276 * Output:
277 * On success: returns zero
278 * On error: return code is negative errno value
279 *
280 * Note: Only AF_INET client addresses are passed in, since
281 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
282 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283static ssize_t write_add(struct file *file, char *buf, size_t size)
284{
285 struct nfsctl_client *data;
286 if (size < sizeof(*data))
287 return -EINVAL;
288 data = (struct nfsctl_client *)buf;
289 return exp_addclient(data);
290}
291
Chuck Lever262a0982008-12-12 16:57:35 -0500292/**
293 * write_del - Remove client from auth unix cache
294 *
295 * Deprecated. /proc/net/rpc/auth.unix.ip is preferred.
296 * Function remains to support old versions of nfs-utils.
297 *
298 * Input:
299 * buf: struct nfsctl_client
300 * cl_ident: '\0'-terminated C string
301 * containing domain name
302 * of client
303 * cl_naddr: ignored
304 * cl_addrlist: ignored
305 * cl_fhkeytype: ignored
306 * cl_fhkeylen: ignored
307 * cl_fhkey: ignored
308 * size: size in bytes of passed in nfsctl_client
309 * Output:
310 * On success: returns zero
311 * On error: return code is negative errno value
312 *
313 * Note: Only AF_INET client addresses are passed in, since
314 * nfsctl_client.cl_addrlist contains only in_addr fields for addresses.
315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316static ssize_t write_del(struct file *file, char *buf, size_t size)
317{
318 struct nfsctl_client *data;
319 if (size < sizeof(*data))
320 return -EINVAL;
321 data = (struct nfsctl_client *)buf;
322 return exp_delclient(data);
323}
324
Chuck Lever262a0982008-12-12 16:57:35 -0500325/**
326 * write_export - Export part or all of a local file system
327 *
328 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
329 * Function remains to support old versions of nfs-utils.
330 *
331 * Input:
332 * buf: struct nfsctl_export
333 * ex_client: '\0'-terminated C string
334 * containing domain name
335 * of client allowed to access
336 * this export
337 * ex_path: '\0'-terminated C string
338 * containing pathname of
339 * directory in local file system
340 * ex_dev: fsid to use for this export
341 * ex_ino: ignored
342 * ex_flags: export flags for this export
343 * ex_anon_uid: UID to use for anonymous
344 * requests
345 * ex_anon_gid: GID to use for anonymous
346 * requests
347 * size: size in bytes of passed in nfsctl_export
348 * Output:
349 * On success: returns zero
350 * On error: return code is negative errno value
351 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352static ssize_t write_export(struct file *file, char *buf, size_t size)
353{
354 struct nfsctl_export *data;
355 if (size < sizeof(*data))
356 return -EINVAL;
357 data = (struct nfsctl_export*)buf;
358 return exp_export(data);
359}
360
Chuck Lever262a0982008-12-12 16:57:35 -0500361/**
362 * write_unexport - Unexport a previously exported file system
363 *
364 * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred.
365 * Function remains to support old versions of nfs-utils.
366 *
367 * Input:
368 * buf: struct nfsctl_export
369 * ex_client: '\0'-terminated C string
370 * containing domain name
371 * of client no longer allowed
372 * to access this export
373 * ex_path: '\0'-terminated C string
374 * containing pathname of
375 * directory in local file system
376 * ex_dev: ignored
377 * ex_ino: ignored
378 * ex_flags: ignored
379 * ex_anon_uid: ignored
380 * ex_anon_gid: ignored
381 * size: size in bytes of passed in nfsctl_export
382 * Output:
383 * On success: returns zero
384 * On error: return code is negative errno value
385 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386static ssize_t write_unexport(struct file *file, char *buf, size_t size)
387{
388 struct nfsctl_export *data;
389
390 if (size < sizeof(*data))
391 return -EINVAL;
392 data = (struct nfsctl_export*)buf;
393 return exp_unexport(data);
394}
395
Chuck Lever262a0982008-12-12 16:57:35 -0500396/**
397 * write_getfs - Get a variable-length NFS file handle by path
398 *
399 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
400 * Function remains to support old versions of nfs-utils.
401 *
402 * Input:
403 * buf: struct nfsctl_fsparm
404 * gd_addr: socket address of client
405 * gd_path: '\0'-terminated C string
406 * containing pathname of
407 * directory in local file system
408 * gd_maxlen: maximum size of returned file
409 * handle
410 * size: size in bytes of passed in nfsctl_fsparm
411 * Output:
412 * On success: passed-in buffer filled with a knfsd_fh structure
413 * (a variable-length raw NFS file handle);
414 * return code is the size in bytes of the file handle
415 * On error: return code is negative errno value
416 *
417 * Note: Only AF_INET client addresses are passed in, since gd_addr
418 * is the same size as a struct sockaddr_in.
419 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420static ssize_t write_getfs(struct file *file, char *buf, size_t size)
421{
422 struct nfsctl_fsparm *data;
423 struct sockaddr_in *sin;
424 struct auth_domain *clp;
425 int err = 0;
426 struct knfsd_fh *res;
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100427 struct in6_addr in6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 if (size < sizeof(*data))
430 return -EINVAL;
431 data = (struct nfsctl_fsparm*)buf;
432 err = -EPROTONOSUPPORT;
433 if (data->gd_addr.sa_family != AF_INET)
434 goto out;
435 sin = (struct sockaddr_in *)&data->gd_addr;
436 if (data->gd_maxlen > NFS3_FHSIZE)
437 data->gd_maxlen = NFS3_FHSIZE;
438
439 res = (struct knfsd_fh*)buf;
440
441 exp_readlock();
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100442
443 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
444
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400445 clp = auth_unix_lookup(&init_net, &in6);
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100446 if (!clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 err = -EPERM;
448 else {
449 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
450 auth_domain_put(clp);
451 }
452 exp_readunlock();
453 if (err == 0)
Andrew Morton12127492007-07-17 04:04:34 -0700454 err = res->fh_size + offsetof(struct knfsd_fh, fh_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 out:
456 return err;
457}
458
Chuck Lever262a0982008-12-12 16:57:35 -0500459/**
460 * write_getfd - Get a fixed-length NFS file handle by path (used by mountd)
461 *
462 * Deprecated. /proc/fs/nfsd/filehandle is preferred.
463 * Function remains to support old versions of nfs-utils.
464 *
465 * Input:
466 * buf: struct nfsctl_fdparm
467 * gd_addr: socket address of client
468 * gd_path: '\0'-terminated C string
469 * containing pathname of
470 * directory in local file system
471 * gd_version: fdparm structure version
472 * size: size in bytes of passed in nfsctl_fdparm
473 * Output:
474 * On success: passed-in buffer filled with nfsctl_res
475 * (a fixed-length raw NFS file handle);
476 * return code is the size in bytes of the file handle
477 * On error: return code is negative errno value
478 *
479 * Note: Only AF_INET client addresses are passed in, since gd_addr
480 * is the same size as a struct sockaddr_in.
481 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482static ssize_t write_getfd(struct file *file, char *buf, size_t size)
483{
484 struct nfsctl_fdparm *data;
485 struct sockaddr_in *sin;
486 struct auth_domain *clp;
487 int err = 0;
488 struct knfsd_fh fh;
489 char *res;
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100490 struct in6_addr in6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 if (size < sizeof(*data))
493 return -EINVAL;
494 data = (struct nfsctl_fdparm*)buf;
495 err = -EPROTONOSUPPORT;
496 if (data->gd_addr.sa_family != AF_INET)
497 goto out;
498 err = -EINVAL;
499 if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
500 goto out;
501
502 res = buf;
503 sin = (struct sockaddr_in *)&data->gd_addr;
504 exp_readlock();
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100505
506 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
507
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400508 clp = auth_unix_lookup(&init_net, &in6);
Aurélien Charbonf15364b2008-01-18 15:50:56 +0100509 if (!clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 err = -EPERM;
511 else {
512 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
513 auth_domain_put(clp);
514 }
515 exp_readunlock();
516
517 if (err == 0) {
518 memset(res,0, NFS_FHSIZE);
519 memcpy(res, &fh.fh_base, fh.fh_size);
520 err = NFS_FHSIZE;
521 }
522 out:
523 return err;
524}
NeilBrown1e140562010-09-22 12:55:07 +1000525#endif /* CONFIG_NFSD_DEPRECATED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Chuck Lever262a0982008-12-12 16:57:35 -0500527/**
528 * write_unlock_ip - Release all locks used by a client
529 *
530 * Experimental.
531 *
532 * Input:
533 * buf: '\n'-terminated C string containing a
Chuck Lever41160922009-08-09 15:09:40 -0400534 * presentation format IP address
Chuck Lever262a0982008-12-12 16:57:35 -0500535 * size: length of C string in @buf
536 * Output:
537 * On success: returns zero if all specified locks were released;
538 * returns one if one or more locks were not released
539 * On error: return code is negative errno value
Chuck Lever262a0982008-12-12 16:57:35 -0500540 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500541static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500542{
Chuck Lever41160922009-08-09 15:09:40 -0400543 struct sockaddr_storage address;
544 struct sockaddr *sap = (struct sockaddr *)&address;
545 size_t salen = sizeof(address);
Chuck Lever367c8c72008-06-30 18:58:14 -0400546 char *fo_path;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500547
548 /* sanity check */
549 if (size == 0)
550 return -EINVAL;
551
552 if (buf[size-1] != '\n')
553 return -EINVAL;
554
555 fo_path = buf;
556 if (qword_get(&buf, fo_path, size) < 0)
557 return -EINVAL;
558
Chuck Lever41160922009-08-09 15:09:40 -0400559 if (rpc_pton(fo_path, size, sap, salen) == 0)
Wendy Cheng4373ea82008-01-17 11:10:12 -0500560 return -EINVAL;
Wendy Cheng4373ea82008-01-17 11:10:12 -0500561
Chuck Lever41160922009-08-09 15:09:40 -0400562 return nlmsvc_unlock_all_by_ip(sap);
Wendy Cheng4373ea82008-01-17 11:10:12 -0500563}
564
Chuck Lever262a0982008-12-12 16:57:35 -0500565/**
566 * write_unlock_fs - Release all locks on a local file system
567 *
568 * Experimental.
569 *
570 * Input:
571 * buf: '\n'-terminated C string containing the
572 * absolute pathname of a local file system
573 * size: length of C string in @buf
574 * Output:
575 * On success: returns zero if all specified locks were released;
576 * returns one if one or more locks were not released
577 * On error: return code is negative errno value
578 */
Chuck Leverb046ccd2008-12-12 16:57:13 -0500579static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size)
Wendy Cheng17efa372008-01-17 11:10:12 -0500580{
Al Viroa63bb992008-08-02 01:03:36 -0400581 struct path path;
Wendy Cheng17efa372008-01-17 11:10:12 -0500582 char *fo_path;
583 int error;
584
585 /* sanity check */
586 if (size == 0)
587 return -EINVAL;
588
589 if (buf[size-1] != '\n')
590 return -EINVAL;
591
592 fo_path = buf;
593 if (qword_get(&buf, fo_path, size) < 0)
594 return -EINVAL;
595
Al Viroa63bb992008-08-02 01:03:36 -0400596 error = kern_path(fo_path, 0, &path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500597 if (error)
598 return error;
599
Chuck Lever262a0982008-12-12 16:57:35 -0500600 /*
601 * XXX: Needs better sanity checking. Otherwise we could end up
602 * releasing locks on the wrong file system.
603 *
604 * For example:
605 * 1. Does the path refer to a directory?
606 * 2. Is that directory a mount point, or
607 * 3. Is that directory the root of an exported file system?
608 */
Al Viroa63bb992008-08-02 01:03:36 -0400609 error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);
Wendy Cheng17efa372008-01-17 11:10:12 -0500610
Al Viroa63bb992008-08-02 01:03:36 -0400611 path_put(&path);
Wendy Cheng17efa372008-01-17 11:10:12 -0500612 return error;
613}
614
Chuck Lever262a0982008-12-12 16:57:35 -0500615/**
616 * write_filehandle - Get a variable-length NFS file handle by path
617 *
618 * On input, the buffer contains a '\n'-terminated C string comprised of
619 * three alphanumeric words separated by whitespace. The string may
620 * contain escape sequences.
621 *
622 * Input:
623 * buf:
624 * domain: client domain name
625 * path: export pathname
626 * maxsize: numeric maximum size of
627 * @buf
628 * size: length of C string in @buf
629 * Output:
630 * On success: passed-in buffer filled with '\n'-terminated C
631 * string containing a ASCII hex text version
632 * of the NFS file handle;
633 * return code is the size in bytes of the string
634 * On error: return code is negative errno value
635 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
637{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 char *dname, *path;
Andrew Morton246d95b2007-08-09 00:53:50 -0700639 int uninitialized_var(maxsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 char *mesg = buf;
641 int len;
642 struct auth_domain *dom;
643 struct knfsd_fh fh;
644
J. Bruce Fields87d26ea2008-01-22 17:40:42 -0500645 if (size == 0)
646 return -EINVAL;
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (buf[size-1] != '\n')
649 return -EINVAL;
650 buf[size-1] = 0;
651
652 dname = mesg;
653 len = qword_get(&mesg, dname, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500654 if (len <= 0)
655 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 path = dname+len+1;
658 len = qword_get(&mesg, path, size);
Chuck Lever54224f02008-12-12 16:57:20 -0500659 if (len <= 0)
660 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 len = get_int(&mesg, &maxsize);
663 if (len)
664 return len;
665
666 if (maxsize < NFS_FHSIZE)
667 return -EINVAL;
668 if (maxsize > NFS3_FHSIZE)
669 maxsize = NFS3_FHSIZE;
670
671 if (qword_get(&mesg, mesg, size)>0)
672 return -EINVAL;
673
674 /* we have all the words, they are in buf.. */
675 dom = unix_domain_find(dname);
676 if (!dom)
677 return -ENOMEM;
678
679 len = exp_rootfh(dom, path, &fh, maxsize);
680 auth_domain_put(dom);
681 if (len)
682 return len;
683
Chuck Lever54224f02008-12-12 16:57:20 -0500684 mesg = buf;
685 len = SIMPLE_TRANSACTION_LIMIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size);
687 mesg[-1] = '\n';
688 return mesg - buf;
689}
690
Chuck Lever262a0982008-12-12 16:57:35 -0500691/**
692 * write_threads - Start NFSD, or report the current number of running threads
693 *
694 * Input:
695 * buf: ignored
696 * size: zero
697 * Output:
698 * On success: passed-in buffer filled with '\n'-terminated C
699 * string numeric value representing the number of
700 * running NFSD threads;
701 * return code is the size in bytes of the string
702 * On error: return code is zero
703 *
704 * OR
705 *
706 * Input:
707 * buf: C string containing an unsigned
708 * integer value representing the
709 * number of NFSD threads to start
710 * size: non-zero length of C string in @buf
711 * Output:
712 * On success: NFS service is started;
713 * passed-in buffer filled with '\n'-terminated C
714 * string numeric value representing the number of
715 * running NFSD threads;
716 * return code is the size in bytes of the string
717 * On error: return code is zero or a negative errno value
718 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719static ssize_t write_threads(struct file *file, char *buf, size_t size)
720{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 char *mesg = buf;
722 int rv;
723 if (size > 0) {
724 int newthreads;
725 rv = get_int(&mesg, &newthreads);
726 if (rv)
727 return rv;
Chuck Lever9e074852008-12-12 16:57:27 -0500728 if (newthreads < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 return -EINVAL;
Chuck Lever9e074852008-12-12 16:57:27 -0500730 rv = nfsd_svc(NFS_PORT, newthreads);
NeilBrown82e12fe2009-06-16 11:03:07 +1000731 if (rv < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 return rv;
NeilBrown82e12fe2009-06-16 11:03:07 +1000733 } else
734 rv = nfsd_nrthreads();
Chuck Levere06b6402009-04-23 19:33:25 -0400735
NeilBrown82e12fe2009-06-16 11:03:07 +1000736 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
Chuck Lever262a0982008-12-12 16:57:35 -0500739/**
740 * write_pool_threads - Set or report the current number of threads per pool
741 *
742 * Input:
743 * buf: ignored
744 * size: zero
745 *
746 * OR
747 *
748 * Input:
749 * buf: C string containing whitespace-
750 * separated unsigned integer values
751 * representing the number of NFSD
752 * threads to start in each pool
753 * size: non-zero length of C string in @buf
754 * Output:
755 * On success: passed-in buffer filled with '\n'-terminated C
756 * string containing integer values representing the
757 * number of NFSD threads in each pool;
758 * return code is the size in bytes of the string
759 * On error: return code is zero or a negative errno value
760 */
Greg Bankseed29652006-10-02 02:18:02 -0700761static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
762{
763 /* if size > 0, look for an array of number of threads per node
764 * and apply them then write out number of threads per node as reply
765 */
766 char *mesg = buf;
767 int i;
768 int rv;
769 int len;
Neil Brownbedbdd82008-06-10 08:40:35 -0400770 int npools;
Greg Bankseed29652006-10-02 02:18:02 -0700771 int *nthreads;
772
Neil Brownbedbdd82008-06-10 08:40:35 -0400773 mutex_lock(&nfsd_mutex);
774 npools = nfsd_nrpools();
Greg Bankseed29652006-10-02 02:18:02 -0700775 if (npools == 0) {
776 /*
777 * NFS is shut down. The admin can start it by
778 * writing to the threads file but NOT the pool_threads
779 * file, sorry. Report zero threads.
780 */
Neil Brownbedbdd82008-06-10 08:40:35 -0400781 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700782 strcpy(buf, "0\n");
783 return strlen(buf);
784 }
785
786 nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL);
Neil Brownbedbdd82008-06-10 08:40:35 -0400787 rv = -ENOMEM;
Greg Bankseed29652006-10-02 02:18:02 -0700788 if (nthreads == NULL)
Neil Brownbedbdd82008-06-10 08:40:35 -0400789 goto out_free;
Greg Bankseed29652006-10-02 02:18:02 -0700790
791 if (size > 0) {
792 for (i = 0; i < npools; i++) {
793 rv = get_int(&mesg, &nthreads[i]);
794 if (rv == -ENOENT)
795 break; /* fewer numbers than pools */
796 if (rv)
797 goto out_free; /* syntax error */
798 rv = -EINVAL;
799 if (nthreads[i] < 0)
800 goto out_free;
801 }
802 rv = nfsd_set_nrthreads(i, nthreads);
803 if (rv)
804 goto out_free;
805 }
806
807 rv = nfsd_get_nrthreads(npools, nthreads);
808 if (rv)
809 goto out_free;
810
811 mesg = buf;
812 size = SIMPLE_TRANSACTION_LIMIT;
813 for (i = 0; i < npools && size > 0; i++) {
814 snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' '));
815 len = strlen(mesg);
816 size -= len;
817 mesg += len;
818 }
J. Bruce Fields413d63d2009-07-28 11:37:25 -0400819 rv = mesg - buf;
Greg Bankseed29652006-10-02 02:18:02 -0700820out_free:
821 kfree(nthreads);
Neil Brownbedbdd82008-06-10 08:40:35 -0400822 mutex_unlock(&nfsd_mutex);
Greg Bankseed29652006-10-02 02:18:02 -0700823 return rv;
824}
825
Jeff Layton3dd98a32008-06-10 08:40:36 -0400826static ssize_t __write_versions(struct file *file, char *buf, size_t size)
NeilBrown70c3b762005-11-07 01:00:25 -0800827{
NeilBrown70c3b762005-11-07 01:00:25 -0800828 char *mesg = buf;
Benny Halevy8daf2202009-04-03 08:28:59 +0300829 char *vers, *minorp, sign;
Chuck Lever261758b2009-04-23 19:33:18 -0400830 int len, num, remaining;
Benny Halevy8daf2202009-04-03 08:28:59 +0300831 unsigned minor;
NeilBrown70c3b762005-11-07 01:00:25 -0800832 ssize_t tlen = 0;
833 char *sep;
834
835 if (size>0) {
836 if (nfsd_serv)
NeilBrown6658d3a2006-10-02 02:17:46 -0700837 /* Cannot change versions without updating
838 * nfsd_serv->sv_xdrsize, and reallocing
839 * rq_argp and rq_resp
840 */
NeilBrown70c3b762005-11-07 01:00:25 -0800841 return -EBUSY;
842 if (buf[size-1] != '\n')
843 return -EINVAL;
844 buf[size-1] = 0;
845
846 vers = mesg;
847 len = qword_get(&mesg, vers, size);
848 if (len <= 0) return -EINVAL;
849 do {
850 sign = *vers;
851 if (sign == '+' || sign == '-')
Benny Halevy8daf2202009-04-03 08:28:59 +0300852 num = simple_strtol((vers+1), &minorp, 0);
NeilBrown70c3b762005-11-07 01:00:25 -0800853 else
Benny Halevy8daf2202009-04-03 08:28:59 +0300854 num = simple_strtol(vers, &minorp, 0);
855 if (*minorp == '.') {
856 if (num < 4)
857 return -EINVAL;
858 minor = simple_strtoul(minorp+1, NULL, 0);
859 if (minor == 0)
860 return -EINVAL;
861 if (nfsd_minorversion(minor, sign == '-' ?
862 NFSD_CLEAR : NFSD_SET) < 0)
863 return -EINVAL;
864 goto next;
865 }
NeilBrown70c3b762005-11-07 01:00:25 -0800866 switch(num) {
867 case 2:
868 case 3:
869 case 4:
NeilBrown6658d3a2006-10-02 02:17:46 -0700870 nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET);
NeilBrown70c3b762005-11-07 01:00:25 -0800871 break;
872 default:
873 return -EINVAL;
874 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300875 next:
NeilBrown70c3b762005-11-07 01:00:25 -0800876 vers += len + 1;
NeilBrown70c3b762005-11-07 01:00:25 -0800877 } while ((len = qword_get(&mesg, vers, size)) > 0);
878 /* If all get turned off, turn them back on, as
879 * having no versions is BAD
880 */
NeilBrown6658d3a2006-10-02 02:17:46 -0700881 nfsd_reset_versions();
NeilBrown70c3b762005-11-07 01:00:25 -0800882 }
Chuck Lever261758b2009-04-23 19:33:18 -0400883
NeilBrown70c3b762005-11-07 01:00:25 -0800884 /* Now write current state into reply buffer */
885 len = 0;
886 sep = "";
Chuck Lever261758b2009-04-23 19:33:18 -0400887 remaining = SIMPLE_TRANSACTION_LIMIT;
NeilBrown70c3b762005-11-07 01:00:25 -0800888 for (num=2 ; num <= 4 ; num++)
NeilBrown6658d3a2006-10-02 02:17:46 -0700889 if (nfsd_vers(num, NFSD_AVAIL)) {
Chuck Lever261758b2009-04-23 19:33:18 -0400890 len = snprintf(buf, remaining, "%s%c%d", sep,
NeilBrown6658d3a2006-10-02 02:17:46 -0700891 nfsd_vers(num, NFSD_TEST)?'+':'-',
NeilBrown70c3b762005-11-07 01:00:25 -0800892 num);
893 sep = " ";
Chuck Lever261758b2009-04-23 19:33:18 -0400894
895 if (len > remaining)
896 break;
897 remaining -= len;
898 buf += len;
899 tlen += len;
NeilBrown70c3b762005-11-07 01:00:25 -0800900 }
Benny Halevy8daf2202009-04-03 08:28:59 +0300901 if (nfsd_vers(4, NFSD_AVAIL))
Chuck Lever261758b2009-04-23 19:33:18 -0400902 for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION;
903 minor++) {
904 len = snprintf(buf, remaining, " %c4.%u",
Benny Halevy8daf2202009-04-03 08:28:59 +0300905 (nfsd_vers(4, NFSD_TEST) &&
906 nfsd_minorversion(minor, NFSD_TEST)) ?
907 '+' : '-',
908 minor);
Chuck Lever261758b2009-04-23 19:33:18 -0400909
910 if (len > remaining)
911 break;
912 remaining -= len;
913 buf += len;
914 tlen += len;
915 }
916
917 len = snprintf(buf, remaining, "\n");
918 if (len > remaining)
919 return -EINVAL;
920 return tlen + len;
NeilBrown70c3b762005-11-07 01:00:25 -0800921}
922
Chuck Lever262a0982008-12-12 16:57:35 -0500923/**
924 * write_versions - Set or report the available NFS protocol versions
925 *
926 * Input:
927 * buf: ignored
928 * size: zero
929 * Output:
930 * On success: passed-in buffer filled with '\n'-terminated C
931 * string containing positive or negative integer
932 * values representing the current status of each
933 * protocol version;
934 * return code is the size in bytes of the string
935 * On error: return code is zero or a negative errno value
936 *
937 * OR
938 *
939 * Input:
940 * buf: C string containing whitespace-
941 * separated positive or negative
942 * integer values representing NFS
943 * protocol versions to enable ("+n")
944 * or disable ("-n")
945 * size: non-zero length of C string in @buf
946 * Output:
947 * On success: status of zero or more protocol versions has
948 * been updated; passed-in buffer filled with
949 * '\n'-terminated C string containing positive
950 * or negative integer values representing the
951 * current status of each protocol version;
952 * return code is the size in bytes of the string
953 * On error: return code is zero or a negative errno value
954 */
Jeff Layton3dd98a32008-06-10 08:40:36 -0400955static ssize_t write_versions(struct file *file, char *buf, size_t size)
956{
957 ssize_t rv;
958
959 mutex_lock(&nfsd_mutex);
960 rv = __write_versions(file, buf, size);
961 mutex_unlock(&nfsd_mutex);
962 return rv;
963}
964
Chuck Lever4cd5dc72009-04-23 19:31:32 -0400965/*
Chuck Lever0a5372d2009-04-23 19:32:10 -0400966 * Zero-length write. Return a list of NFSD's current listener
967 * transports.
968 */
969static ssize_t __write_ports_names(char *buf)
970{
971 if (nfsd_serv == NULL)
972 return 0;
Chuck Lever335c54b2009-04-23 19:32:25 -0400973 return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT);
Chuck Lever0a5372d2009-04-23 19:32:10 -0400974}
975
976/*
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400977 * A single 'fd' number was written, in which case it must be for
978 * a socket of a supported family/protocol, and we use it as an
979 * nfsd listener.
980 */
981static ssize_t __write_ports_addfd(char *buf)
982{
983 char *mesg = buf;
984 int fd, err;
985
986 err = get_int(&mesg, &fd);
987 if (err != 0 || fd < 0)
988 return -EINVAL;
989
990 err = nfsd_create_serv();
991 if (err != 0)
992 return err;
993
Chuck Leverbfba9ab2009-04-23 19:32:33 -0400994 err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400995 if (err < 0) {
Jeff Layton78a8d7c2010-07-19 16:50:05 -0400996 svc_destroy(nfsd_serv);
997 return err;
998 }
Chuck Lever0b7c2f62009-04-23 19:31:55 -0400999
Chuck Leverea068ba2009-04-23 19:32:18 -04001000 /* Decrease the count, but don't shut down the service */
1001 nfsd_serv->sv_nrthreads--;
1002 return err;
Chuck Lever0b7c2f62009-04-23 19:31:55 -04001003}
1004
1005/*
Chuck Lever82d56592009-04-23 19:31:48 -04001006 * A '-' followed by the 'name' of a socket means we close the socket.
1007 */
1008static ssize_t __write_ports_delfd(char *buf)
1009{
1010 char *toclose;
1011 int len = 0;
1012
1013 toclose = kstrdup(buf + 1, GFP_KERNEL);
1014 if (toclose == NULL)
1015 return -ENOMEM;
1016
1017 if (nfsd_serv != NULL)
Chuck Lever8435d342009-04-23 19:32:40 -04001018 len = svc_sock_names(nfsd_serv, buf,
1019 SIMPLE_TRANSACTION_LIMIT, toclose);
Chuck Lever82d56592009-04-23 19:31:48 -04001020 kfree(toclose);
1021 return len;
1022}
1023
1024/*
Chuck Lever4eb68c22009-04-23 19:31:40 -04001025 * A transport listener is added by writing it's transport name and
1026 * a port number.
1027 */
1028static ssize_t __write_ports_addxprt(char *buf)
1029{
1030 char transport[16];
Chuck Lever374982922010-01-26 14:04:22 -05001031 struct svc_xprt *xprt;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001032 int port, err;
1033
1034 if (sscanf(buf, "%15s %4u", transport, &port) != 2)
1035 return -EINVAL;
1036
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001037 if (port < 1 || port > USHRT_MAX)
Chuck Lever4eb68c22009-04-23 19:31:40 -04001038 return -EINVAL;
1039
1040 err = nfsd_create_serv();
1041 if (err != 0)
1042 return err;
1043
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +04001044 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever4eb68c22009-04-23 19:31:40 -04001045 PF_INET, port, SVC_SOCK_ANONYMOUS);
Chuck Lever68717902010-01-26 14:04:13 -05001046 if (err < 0)
Chuck Lever374982922010-01-26 14:04:22 -05001047 goto out_err;
1048
Pavel Emelyanovfc5d00b2010-09-29 16:03:50 +04001049 err = svc_create_xprt(nfsd_serv, transport, &init_net,
Chuck Lever374982922010-01-26 14:04:22 -05001050 PF_INET6, port, SVC_SOCK_ANONYMOUS);
1051 if (err < 0 && err != -EAFNOSUPPORT)
1052 goto out_close;
Jeff Layton0cd14a02010-07-19 16:50:06 -04001053
1054 /* Decrease the count, but don't shut down the service */
1055 nfsd_serv->sv_nrthreads--;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001056 return 0;
Chuck Lever374982922010-01-26 14:04:22 -05001057out_close:
1058 xprt = svc_find_xprt(nfsd_serv, transport, PF_INET, port);
1059 if (xprt != NULL) {
1060 svc_close_xprt(xprt);
1061 svc_xprt_put(xprt);
1062 }
1063out_err:
Jeff Layton0cd14a02010-07-19 16:50:06 -04001064 svc_destroy(nfsd_serv);
Chuck Lever374982922010-01-26 14:04:22 -05001065 return err;
Chuck Lever4eb68c22009-04-23 19:31:40 -04001066}
1067
1068/*
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001069 * A transport listener is removed by writing a "-", it's transport
1070 * name, and it's port number.
1071 */
1072static ssize_t __write_ports_delxprt(char *buf)
1073{
1074 struct svc_xprt *xprt;
1075 char transport[16];
1076 int port;
1077
1078 if (sscanf(&buf[1], "%15s %4u", transport, &port) != 2)
1079 return -EINVAL;
1080
Alexey Dobriyan4be929b2010-05-24 14:33:03 -07001081 if (port < 1 || port > USHRT_MAX || nfsd_serv == NULL)
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001082 return -EINVAL;
1083
1084 xprt = svc_find_xprt(nfsd_serv, transport, AF_UNSPEC, port);
1085 if (xprt == NULL)
1086 return -ENOTCONN;
1087
1088 svc_close_xprt(xprt);
1089 svc_xprt_put(xprt);
1090 return 0;
1091}
1092
Neil Brownbedbdd82008-06-10 08:40:35 -04001093static ssize_t __write_ports(struct file *file, char *buf, size_t size)
NeilBrown80212d52006-10-02 02:17:47 -07001094{
Chuck Lever0a5372d2009-04-23 19:32:10 -04001095 if (size == 0)
1096 return __write_ports_names(buf);
Chuck Lever0b7c2f62009-04-23 19:31:55 -04001097
1098 if (isdigit(buf[0]))
1099 return __write_ports_addfd(buf);
Chuck Lever82d56592009-04-23 19:31:48 -04001100
1101 if (buf[0] == '-' && isdigit(buf[1]))
1102 return __write_ports_delfd(buf);
Chuck Lever4eb68c22009-04-23 19:31:40 -04001103
1104 if (isalpha(buf[0]))
1105 return __write_ports_addxprt(buf);
Chuck Lever4cd5dc72009-04-23 19:31:32 -04001106
1107 if (buf[0] == '-' && isalpha(buf[1]))
1108 return __write_ports_delxprt(buf);
1109
NeilBrownb41b66d2006-10-02 02:17:48 -07001110 return -EINVAL;
NeilBrown80212d52006-10-02 02:17:47 -07001111}
1112
Chuck Lever262a0982008-12-12 16:57:35 -05001113/**
1114 * write_ports - Pass a socket file descriptor or transport name to listen on
1115 *
1116 * Input:
1117 * buf: ignored
1118 * size: zero
1119 * Output:
1120 * On success: passed-in buffer filled with a '\n'-terminated C
1121 * string containing a whitespace-separated list of
1122 * named NFSD listeners;
1123 * return code is the size in bytes of the string
1124 * On error: return code is zero or a negative errno value
1125 *
1126 * OR
1127 *
1128 * Input:
1129 * buf: C string containing an unsigned
1130 * integer value representing a bound
1131 * but unconnected socket that is to be
Chuck Leverc71206a2009-04-23 19:32:03 -04001132 * used as an NFSD listener; listen(3)
1133 * must be called for a SOCK_STREAM
1134 * socket, otherwise it is ignored
Chuck Lever262a0982008-12-12 16:57:35 -05001135 * size: non-zero length of C string in @buf
1136 * Output:
1137 * On success: NFS service is started;
1138 * passed-in buffer filled with a '\n'-terminated C
1139 * string containing a unique alphanumeric name of
1140 * the listener;
1141 * return code is the size in bytes of the string
1142 * On error: return code is a negative errno value
1143 *
1144 * OR
1145 *
1146 * Input:
1147 * buf: C string containing a "-" followed
1148 * by an integer value representing a
1149 * previously passed in socket file
1150 * descriptor
1151 * size: non-zero length of C string in @buf
1152 * Output:
1153 * On success: NFS service no longer listens on that socket;
1154 * passed-in buffer filled with a '\n'-terminated C
1155 * string containing a unique name of the listener;
1156 * return code is the size in bytes of the string
1157 * On error: return code is a negative errno value
1158 *
1159 * OR
1160 *
1161 * Input:
1162 * buf: C string containing a transport
1163 * name and an unsigned integer value
1164 * representing the port to listen on,
1165 * separated by whitespace
1166 * size: non-zero length of C string in @buf
1167 * Output:
1168 * On success: returns zero; NFS service is started
1169 * On error: return code is a negative errno value
1170 *
1171 * OR
1172 *
1173 * Input:
1174 * buf: C string containing a "-" followed
1175 * by a transport name and an unsigned
1176 * integer value representing the port
1177 * to listen on, separated by whitespace
1178 * size: non-zero length of C string in @buf
1179 * Output:
1180 * On success: returns zero; NFS service no longer listens
1181 * on that transport
1182 * On error: return code is a negative errno value
1183 */
Neil Brownbedbdd82008-06-10 08:40:35 -04001184static ssize_t write_ports(struct file *file, char *buf, size_t size)
1185{
1186 ssize_t rv;
Jeff Layton3dd98a32008-06-10 08:40:36 -04001187
Neil Brownbedbdd82008-06-10 08:40:35 -04001188 mutex_lock(&nfsd_mutex);
1189 rv = __write_ports(file, buf, size);
1190 mutex_unlock(&nfsd_mutex);
1191 return rv;
1192}
1193
1194
NeilBrown596bbe52006-10-04 02:15:48 -07001195int nfsd_max_blksize;
1196
Chuck Lever262a0982008-12-12 16:57:35 -05001197/**
1198 * write_maxblksize - Set or report the current NFS blksize
1199 *
1200 * Input:
1201 * buf: ignored
1202 * size: zero
1203 *
1204 * OR
1205 *
1206 * Input:
1207 * buf: C string containing an unsigned
1208 * integer value representing the new
1209 * NFS blksize
1210 * size: non-zero length of C string in @buf
1211 * Output:
1212 * On success: passed-in buffer filled with '\n'-terminated C string
1213 * containing numeric value of the current NFS blksize
1214 * setting;
1215 * return code is the size in bytes of the string
1216 * On error: return code is zero or a negative errno value
1217 */
NeilBrown596bbe52006-10-04 02:15:48 -07001218static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
1219{
1220 char *mesg = buf;
1221 if (size > 0) {
1222 int bsize;
1223 int rv = get_int(&mesg, &bsize);
1224 if (rv)
1225 return rv;
1226 /* force bsize into allowed range and
1227 * required alignment.
1228 */
1229 if (bsize < 1024)
1230 bsize = 1024;
1231 if (bsize > NFSSVC_MAXBLKSIZE)
1232 bsize = NFSSVC_MAXBLKSIZE;
1233 bsize &= ~(1024-1);
Neil Brownbedbdd82008-06-10 08:40:35 -04001234 mutex_lock(&nfsd_mutex);
J. Bruce Fields7fa53cc2010-08-06 18:00:33 -04001235 if (nfsd_serv) {
Neil Brownbedbdd82008-06-10 08:40:35 -04001236 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -07001237 return -EBUSY;
1238 }
1239 nfsd_max_blksize = bsize;
Neil Brownbedbdd82008-06-10 08:40:35 -04001240 mutex_unlock(&nfsd_mutex);
NeilBrown596bbe52006-10-04 02:15:48 -07001241 }
Chuck Levere06b6402009-04-23 19:33:25 -04001242
1243 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
1244 nfsd_max_blksize);
NeilBrown596bbe52006-10-04 02:15:48 -07001245}
1246
NeilBrown70c3b762005-11-07 01:00:25 -08001247#ifdef CONFIG_NFSD_V4
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001248static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 char *mesg = buf;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001251 int rv, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 if (size > 0) {
Jeff Layton3dd98a32008-06-10 08:40:36 -04001254 if (nfsd_serv)
1255 return -EBUSY;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001256 rv = get_int(&mesg, &i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (rv)
1258 return rv;
J. Bruce Fieldse7b184f2010-03-02 11:18:40 -05001259 /*
1260 * Some sanity checking. We don't have a reason for
1261 * these particular numbers, but problems with the
1262 * extremes are:
1263 * - Too short: the briefest network outage may
1264 * cause clients to lose all their locks. Also,
1265 * the frequent polling may be wasteful.
1266 * - Too long: do you really want reboot recovery
1267 * to take more than an hour? Or to make other
1268 * clients wait an hour before being able to
1269 * revoke a dead client's locks?
1270 */
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001271 if (i < 10 || i > 3600)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 return -EINVAL;
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001273 *time = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 }
Chuck Levere06b6402009-04-23 19:33:25 -04001275
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001276 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
1277}
1278
1279static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
1280{
1281 ssize_t rv;
1282
1283 mutex_lock(&nfsd_mutex);
1284 rv = __nfsd4_write_time(file, buf, size, time);
1285 mutex_unlock(&nfsd_mutex);
1286 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Chuck Lever262a0982008-12-12 16:57:35 -05001289/**
1290 * write_leasetime - Set or report the current NFSv4 lease time
1291 *
1292 * Input:
1293 * buf: ignored
1294 * size: zero
1295 *
1296 * OR
1297 *
1298 * Input:
1299 * buf: C string containing an unsigned
1300 * integer value representing the new
1301 * NFSv4 lease expiry time
1302 * size: non-zero length of C string in @buf
1303 * Output:
1304 * On success: passed-in buffer filled with '\n'-terminated C
1305 * string containing unsigned integer value of the
1306 * current lease expiry time;
1307 * return code is the size in bytes of the string
1308 * On error: return code is zero or a negative errno value
1309 */
Jeff Layton3dd98a32008-06-10 08:40:36 -04001310static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
1311{
J. Bruce Fieldsf0135742010-03-01 19:32:36 -05001312 return nfsd4_write_time(file, buf, size, &nfsd4_lease);
Jeff Layton3dd98a32008-06-10 08:40:36 -04001313}
1314
J. Bruce Fieldsefc4bb42010-03-02 11:04:06 -05001315/**
1316 * write_gracetime - Set or report current NFSv4 grace period time
1317 *
1318 * As above, but sets the time of the NFSv4 grace period.
1319 *
1320 * Note this should never be set to less than the *previous*
1321 * lease-period time, but we don't try to enforce this. (In the common
1322 * case (a new boot), we don't know what the previous lease time was
1323 * anyway.)
1324 */
1325static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
1326{
1327 return nfsd4_write_time(file, buf, size, &nfsd4_grace);
1328}
1329
Jeff Layton3dd98a32008-06-10 08:40:36 -04001330extern char *nfs4_recoverydir(void);
1331
1332static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size)
NeilBrown0964a3d2005-06-23 22:04:32 -07001333{
1334 char *mesg = buf;
1335 char *recdir;
1336 int len, status;
1337
Jeff Layton3dd98a32008-06-10 08:40:36 -04001338 if (size > 0) {
1339 if (nfsd_serv)
1340 return -EBUSY;
1341 if (size > PATH_MAX || buf[size-1] != '\n')
1342 return -EINVAL;
1343 buf[size-1] = 0;
NeilBrown0964a3d2005-06-23 22:04:32 -07001344
Jeff Layton3dd98a32008-06-10 08:40:36 -04001345 recdir = mesg;
1346 len = qword_get(&mesg, recdir, size);
1347 if (len <= 0)
1348 return -EINVAL;
NeilBrown0964a3d2005-06-23 22:04:32 -07001349
Jeff Layton3dd98a32008-06-10 08:40:36 -04001350 status = nfs4_reset_recoverydir(recdir);
Andi Kleen69049962010-07-20 15:24:27 -07001351 if (status)
1352 return status;
Jeff Layton3dd98a32008-06-10 08:40:36 -04001353 }
Chuck Lever3d72ab82009-04-23 19:33:10 -04001354
1355 return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n",
1356 nfs4_recoverydir());
NeilBrown0964a3d2005-06-23 22:04:32 -07001357}
Jeff Layton3dd98a32008-06-10 08:40:36 -04001358
Chuck Lever262a0982008-12-12 16:57:35 -05001359/**
1360 * write_recoverydir - Set or report the pathname of the recovery directory
1361 *
1362 * Input:
1363 * buf: ignored
1364 * size: zero
1365 *
1366 * OR
1367 *
1368 * Input:
1369 * buf: C string containing the pathname
1370 * of the directory on a local file
1371 * system containing permanent NFSv4
1372 * recovery data
1373 * size: non-zero length of C string in @buf
1374 * Output:
1375 * On success: passed-in buffer filled with '\n'-terminated C string
1376 * containing the current recovery pathname setting;
1377 * return code is the size in bytes of the string
1378 * On error: return code is zero or a negative errno value
1379 */
Jeff Layton3dd98a32008-06-10 08:40:36 -04001380static ssize_t write_recoverydir(struct file *file, char *buf, size_t size)
1381{
1382 ssize_t rv;
1383
1384 mutex_lock(&nfsd_mutex);
1385 rv = __write_recoverydir(file, buf, size);
1386 mutex_unlock(&nfsd_mutex);
1387 return rv;
1388}
1389
NeilBrown70c3b762005-11-07 01:00:25 -08001390#endif
NeilBrown0964a3d2005-06-23 22:04:32 -07001391
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392/*----------------------------------------------------------------------------*/
1393/*
1394 * populating the filesystem.
1395 */
1396
1397static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
1398{
1399 static struct tree_descr nfsd_files[] = {
NeilBrown1e140562010-09-22 12:55:07 +10001400#ifdef CONFIG_NFSD_DEPRECATED
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR},
1402 [NFSD_Add] = {".add", &transaction_ops, S_IWUSR},
1403 [NFSD_Del] = {".del", &transaction_ops, S_IWUSR},
1404 [NFSD_Export] = {".export", &transaction_ops, S_IWUSR},
1405 [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR},
1406 [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR},
1407 [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown1e140562010-09-22 12:55:07 +10001408#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 [NFSD_List] = {"exports", &exports_operations, S_IRUGO},
J. Bruce Fieldse8e87532009-12-14 12:53:32 -05001410 [NFSD_Export_features] = {"export_features",
1411 &export_features_operations, S_IRUGO},
Wendy Cheng4373ea82008-01-17 11:10:12 -05001412 [NFSD_FO_UnlockIP] = {"unlock_ip",
1413 &transaction_ops, S_IWUSR|S_IRUSR},
Wendy Cheng17efa372008-01-17 11:10:12 -05001414 [NFSD_FO_UnlockFS] = {"unlock_filesystem",
1415 &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
1417 [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Bankseed29652006-10-02 02:18:02 -07001418 [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR},
Greg Banks03cf6c92009-01-13 21:26:36 +11001419 [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO},
NeilBrown70c3b762005-11-07 01:00:25 -08001420 [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown80212d52006-10-02 02:17:47 -07001421 [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO},
NeilBrown596bbe52006-10-04 02:15:48 -07001422 [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
J. Bruce Fieldsb084f592011-05-31 12:24:58 -04001423#if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE)
Kevin Coffmanb0b0c0a2011-03-02 19:51:42 -05001424 [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO},
J. Bruce Fieldsb084f592011-05-31 12:24:58 -04001425#endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426#ifdef CONFIG_NFSD_V4
1427 [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
J. Bruce Fieldsefc4bb42010-03-02 11:04:06 -05001428 [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
NeilBrown0964a3d2005-06-23 22:04:32 -07001429 [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430#endif
1431 /* last one */ {""}
1432 };
1433 return simple_fill_super(sb, 0x6e667364, nfsd_files);
1434}
1435
Al Virofc14f2f2010-07-25 01:48:30 +04001436static struct dentry *nfsd_mount(struct file_system_type *fs_type,
1437 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438{
Al Virofc14f2f2010-07-25 01:48:30 +04001439 return mount_single(fs_type, flags, data, nfsd_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
1442static struct file_system_type nfsd_fs_type = {
1443 .owner = THIS_MODULE,
1444 .name = "nfsd",
Al Virofc14f2f2010-07-25 01:48:30 +04001445 .mount = nfsd_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .kill_sb = kill_litter_super,
1447};
1448
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001449#ifdef CONFIG_PROC_FS
1450static int create_proc_exports_entry(void)
1451{
1452 struct proc_dir_entry *entry;
1453
1454 entry = proc_mkdir("fs/nfs", NULL);
1455 if (!entry)
1456 return -ENOMEM;
Denis V. Lunev9ef2db22008-04-29 01:02:04 -07001457 entry = proc_create("exports", 0, entry, &exports_operations);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001458 if (!entry)
1459 return -ENOMEM;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001460 return 0;
1461}
1462#else /* CONFIG_PROC_FS */
1463static int create_proc_exports_entry(void)
1464{
1465 return 0;
1466}
1467#endif
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469static int __init init_nfsd(void)
1470{
1471 int retval;
1472 printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
1473
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001474 retval = nfs4_state_init(); /* nfs4 locking state */
1475 if (retval)
1476 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 nfsd_stat_init(); /* Statistics */
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001478 retval = nfsd_reply_cache_init();
1479 if (retval)
1480 goto out_free_stat;
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001481 retval = nfsd_export_init();
1482 if (retval)
1483 goto out_free_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 nfsd_lockd_init(); /* lockd->nfsd callbacks */
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001485 retval = nfsd_idmap_init();
1486 if (retval)
1487 goto out_free_lockd;
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001488 retval = create_proc_exports_entry();
1489 if (retval)
1490 goto out_free_idmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 retval = register_filesystem(&nfsd_fs_type);
J. Bruce Fields26808d32007-11-09 13:44:06 -05001492 if (retval)
1493 goto out_free_all;
1494 return 0;
1495out_free_all:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001496 remove_proc_entry("fs/nfs/exports", NULL);
1497 remove_proc_entry("fs/nfs", NULL);
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001498out_free_idmap:
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001499 nfsd_idmap_shutdown();
1500out_free_lockd:
J. Bruce Fields26808d32007-11-09 13:44:06 -05001501 nfsd_lockd_shutdown();
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001502 nfsd_export_shutdown();
J. Bruce Fieldsdbf847e2007-11-08 17:20:34 -05001503out_free_cache:
J. Bruce Fieldse331f602007-11-12 17:32:21 -05001504 nfsd_reply_cache_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001505out_free_stat:
1506 nfsd_stat_shutdown();
J. Bruce Fields26808d32007-11-09 13:44:06 -05001507 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 return retval;
1509}
1510
1511static void __exit exit_nfsd(void)
1512{
1513 nfsd_export_shutdown();
J. Bruce Fieldsd5c34282007-11-09 14:10:56 -05001514 nfsd_reply_cache_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 remove_proc_entry("fs/nfs/exports", NULL);
1516 remove_proc_entry("fs/nfs", NULL);
1517 nfsd_stat_shutdown();
1518 nfsd_lockd_shutdown();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 nfsd_idmap_shutdown();
J. Bruce Fieldse8ff2a82007-08-01 15:30:59 -04001520 nfsd4_free_slabs();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 unregister_filesystem(&nfsd_fs_type);
1522}
1523
1524MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
1525MODULE_LICENSE("GPL");
1526module_init(init_nfsd)
1527module_exit(exit_nfsd)