2 * linux/fs/nfsd/nfsctl.c
4 * Syscall interface to knfsd.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
9 #include <linux/config.h>
10 #include <linux/module.h>
12 #include <linux/linkage.h>
13 #include <linux/time.h>
14 #include <linux/errno.h>
16 #include <linux/fcntl.h>
17 #include <linux/net.h>
19 #include <linux/syscalls.h>
20 #include <linux/unistd.h>
21 #include <linux/slab.h>
22 #include <linux/proc_fs.h>
23 #include <linux/seq_file.h>
24 #include <linux/pagemap.h>
25 #include <linux/init.h>
27 #include <linux/nfs.h>
28 #include <linux/nfsd_idmap.h>
29 #include <linux/sunrpc/svc.h>
30 #include <linux/nfsd/nfsd.h>
31 #include <linux/nfsd/cache.h>
32 #include <linux/nfsd/xdr.h>
33 #include <linux/nfsd/syscall.h>
34 #include <linux/nfsd/interface.h>
36 #include <asm/uaccess.h>
39 * We have a single directory with 9 nodes in it.
57 * write() for these nodes.
59 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
);
60 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
);
61 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
);
62 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
);
63 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
);
64 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
);
65 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
);
66 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
);
67 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
);
68 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
);
70 static ssize_t (*write_op
[])(struct file
*, char *, size_t) = {
71 [NFSD_Svc
] = write_svc
,
72 [NFSD_Add
] = write_add
,
73 [NFSD_Del
] = write_del
,
74 [NFSD_Export
] = write_export
,
75 [NFSD_Unexport
] = write_unexport
,
76 [NFSD_Getfd
] = write_getfd
,
77 [NFSD_Getfs
] = write_getfs
,
78 [NFSD_Fh
] = write_filehandle
,
79 [NFSD_Threads
] = write_threads
,
80 [NFSD_Leasetime
] = write_leasetime
,
83 static ssize_t
nfsctl_transaction_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*pos
)
85 ino_t ino
= file
->f_dentry
->d_inode
->i_ino
;
89 if (ino
>= sizeof(write_op
)/sizeof(write_op
[0]) || !write_op
[ino
])
92 data
= simple_transaction_get(file
, buf
, size
);
96 rv
= write_op
[ino
](file
, data
, size
);
98 simple_transaction_set(file
, rv
);
104 static struct file_operations transaction_ops
= {
105 .write
= nfsctl_transaction_write
,
106 .read
= simple_transaction_read
,
107 .release
= simple_transaction_release
,
110 extern struct seq_operations nfs_exports_op
;
111 static int exports_open(struct inode
*inode
, struct file
*file
)
113 return seq_open(file
, &nfs_exports_op
);
116 static struct file_operations exports_operations
= {
117 .open
= exports_open
,
120 .release
= seq_release
,
123 /*----------------------------------------------------------------------------*/
125 * payload - write methods
126 * If the method has a response, the response should be put in buf,
127 * and the length returned. Otherwise return 0 or and -error.
130 static ssize_t
write_svc(struct file
*file
, char *buf
, size_t size
)
132 struct nfsctl_svc
*data
;
133 if (size
< sizeof(*data
))
135 data
= (struct nfsctl_svc
*) buf
;
136 return nfsd_svc(data
->svc_port
, data
->svc_nthreads
);
139 static ssize_t
write_add(struct file
*file
, char *buf
, size_t size
)
141 struct nfsctl_client
*data
;
142 if (size
< sizeof(*data
))
144 data
= (struct nfsctl_client
*)buf
;
145 return exp_addclient(data
);
148 static ssize_t
write_del(struct file
*file
, char *buf
, size_t size
)
150 struct nfsctl_client
*data
;
151 if (size
< sizeof(*data
))
153 data
= (struct nfsctl_client
*)buf
;
154 return exp_delclient(data
);
157 static ssize_t
write_export(struct file
*file
, char *buf
, size_t size
)
159 struct nfsctl_export
*data
;
160 if (size
< sizeof(*data
))
162 data
= (struct nfsctl_export
*)buf
;
163 return exp_export(data
);
166 static ssize_t
write_unexport(struct file
*file
, char *buf
, size_t size
)
168 struct nfsctl_export
*data
;
170 if (size
< sizeof(*data
))
172 data
= (struct nfsctl_export
*)buf
;
173 return exp_unexport(data
);
176 static ssize_t
write_getfs(struct file
*file
, char *buf
, size_t size
)
178 struct nfsctl_fsparm
*data
;
179 struct sockaddr_in
*sin
;
180 struct auth_domain
*clp
;
182 struct knfsd_fh
*res
;
184 if (size
< sizeof(*data
))
186 data
= (struct nfsctl_fsparm
*)buf
;
187 err
= -EPROTONOSUPPORT
;
188 if (data
->gd_addr
.sa_family
!= AF_INET
)
190 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
191 if (data
->gd_maxlen
> NFS3_FHSIZE
)
192 data
->gd_maxlen
= NFS3_FHSIZE
;
194 res
= (struct knfsd_fh
*)buf
;
197 if (!(clp
= auth_unix_lookup(sin
->sin_addr
)))
200 err
= exp_rootfh(clp
, data
->gd_path
, res
, data
->gd_maxlen
);
201 auth_domain_put(clp
);
205 err
= res
->fh_size
+ (int)&((struct knfsd_fh
*)0)->fh_base
;
210 static ssize_t
write_getfd(struct file
*file
, char *buf
, size_t size
)
212 struct nfsctl_fdparm
*data
;
213 struct sockaddr_in
*sin
;
214 struct auth_domain
*clp
;
219 if (size
< sizeof(*data
))
221 data
= (struct nfsctl_fdparm
*)buf
;
222 err
= -EPROTONOSUPPORT
;
223 if (data
->gd_addr
.sa_family
!= AF_INET
)
226 if (data
->gd_version
< 2 || data
->gd_version
> NFSSVC_MAXVERS
)
230 sin
= (struct sockaddr_in
*)&data
->gd_addr
;
232 if (!(clp
= auth_unix_lookup(sin
->sin_addr
)))
235 err
= exp_rootfh(clp
, data
->gd_path
, &fh
, NFS_FHSIZE
);
236 auth_domain_put(clp
);
241 memset(res
,0, NFS_FHSIZE
);
242 memcpy(res
, &fh
.fh_base
, fh
.fh_size
);
249 static ssize_t
write_filehandle(struct file
*file
, char *buf
, size_t size
)
252 * domain path maxsize
256 * qword quoting is used, so filehandle will be \x....
262 struct auth_domain
*dom
;
265 if (buf
[size
-1] != '\n')
270 len
= qword_get(&mesg
, dname
, size
);
271 if (len
<= 0) return -EINVAL
;
274 len
= qword_get(&mesg
, path
, size
);
275 if (len
<= 0) return -EINVAL
;
277 len
= get_int(&mesg
, &maxsize
);
281 if (maxsize
< NFS_FHSIZE
)
283 if (maxsize
> NFS3_FHSIZE
)
284 maxsize
= NFS3_FHSIZE
;
286 if (qword_get(&mesg
, mesg
, size
)>0)
289 /* we have all the words, they are in buf.. */
290 dom
= unix_domain_find(dname
);
294 len
= exp_rootfh(dom
, path
, &fh
, maxsize
);
295 auth_domain_put(dom
);
299 mesg
= buf
; len
= SIMPLE_TRANSACTION_LIMIT
;
300 qword_addhex(&mesg
, &len
, (char*)&fh
.fh_base
, fh
.fh_size
);
305 extern int nfsd_nrthreads(void);
307 static ssize_t
write_threads(struct file
*file
, char *buf
, size_t size
)
309 /* if size > 0, look for a number of threads and call nfsd_svc
310 * then write out number of threads as reply
316 rv
= get_int(&mesg
, &newthreads
);
321 rv
= nfsd_svc(2049, newthreads
);
325 sprintf(buf
, "%d\n", nfsd_nrthreads());
329 extern time_t nfs4_leasetime(void);
331 static ssize_t
write_leasetime(struct file
*file
, char *buf
, size_t size
)
333 /* if size > 10 seconds, call
334 * nfs4_reset_lease() then write out the new lease (seconds) as reply
341 rv
= get_int(&mesg
, &lease
);
344 if (lease
< 10 || lease
> 3600)
346 nfs4_reset_lease(lease
);
348 sprintf(buf
, "%ld\n", nfs4_lease_time());
352 /*----------------------------------------------------------------------------*/
354 * populating the filesystem.
357 static int nfsd_fill_super(struct super_block
* sb
, void * data
, int silent
)
359 static struct tree_descr nfsd_files
[] = {
360 [NFSD_Svc
] = {".svc", &transaction_ops
, S_IWUSR
},
361 [NFSD_Add
] = {".add", &transaction_ops
, S_IWUSR
},
362 [NFSD_Del
] = {".del", &transaction_ops
, S_IWUSR
},
363 [NFSD_Export
] = {".export", &transaction_ops
, S_IWUSR
},
364 [NFSD_Unexport
] = {".unexport", &transaction_ops
, S_IWUSR
},
365 [NFSD_Getfd
] = {".getfd", &transaction_ops
, S_IWUSR
|S_IRUSR
},
366 [NFSD_Getfs
] = {".getfs", &transaction_ops
, S_IWUSR
|S_IRUSR
},
367 [NFSD_List
] = {"exports", &exports_operations
, S_IRUGO
},
368 [NFSD_Fh
] = {"filehandle", &transaction_ops
, S_IWUSR
|S_IRUSR
},
369 [NFSD_Threads
] = {"threads", &transaction_ops
, S_IWUSR
|S_IRUSR
},
370 #ifdef CONFIG_NFSD_V4
371 [NFSD_Leasetime
] = {"nfsv4leasetime", &transaction_ops
, S_IWUSR
|S_IRUSR
},
375 return simple_fill_super(sb
, 0x6e667364, nfsd_files
);
378 static struct super_block
*nfsd_get_sb(struct file_system_type
*fs_type
,
379 int flags
, const char *dev_name
, void *data
)
381 return get_sb_single(fs_type
, flags
, data
, nfsd_fill_super
);
384 static struct file_system_type nfsd_fs_type
= {
385 .owner
= THIS_MODULE
,
387 .get_sb
= nfsd_get_sb
,
388 .kill_sb
= kill_litter_super
,
391 static int __init
init_nfsd(void)
394 printk(KERN_INFO
"Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n");
396 nfsd_stat_init(); /* Statistics */
397 nfsd_cache_init(); /* RPC reply cache */
398 nfsd_export_init(); /* Exports table */
399 nfsd_lockd_init(); /* lockd->nfsd callbacks */
400 #ifdef CONFIG_NFSD_V4
401 nfsd_idmap_init(); /* Name to ID mapping */
402 #endif /* CONFIG_NFSD_V4 */
403 if (proc_mkdir("fs/nfs", NULL
)) {
404 struct proc_dir_entry
*entry
;
405 entry
= create_proc_entry("fs/nfs/exports", 0, NULL
);
407 entry
->proc_fops
= &exports_operations
;
409 retval
= register_filesystem(&nfsd_fs_type
);
411 nfsd_export_shutdown();
412 nfsd_cache_shutdown();
413 remove_proc_entry("fs/nfs/exports", NULL
);
414 remove_proc_entry("fs/nfs", NULL
);
415 nfsd_stat_shutdown();
416 nfsd_lockd_shutdown();
421 static void __exit
exit_nfsd(void)
423 nfsd_export_shutdown();
424 nfsd_cache_shutdown();
425 remove_proc_entry("fs/nfs/exports", NULL
);
426 remove_proc_entry("fs/nfs", NULL
);
427 nfsd_stat_shutdown();
428 nfsd_lockd_shutdown();
429 #ifdef CONFIG_NFSD_V4
430 nfsd_idmap_shutdown();
431 #endif /* CONFIG_NFSD_V4 */
432 unregister_filesystem(&nfsd_fs_type
);
435 MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>");
436 MODULE_LICENSE("GPL");
437 module_init(init_nfsd
)
438 module_exit(exit_nfsd
)