11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * linux/fs/nfsd/nfsctl.c 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Syscall interface to knfsd. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> 71da177e4SLinus Torvalds */ 81da177e4SLinus Torvalds 91da177e4SLinus Torvalds #include <linux/module.h> 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/linkage.h> 121da177e4SLinus Torvalds #include <linux/time.h> 131da177e4SLinus Torvalds #include <linux/errno.h> 141da177e4SLinus Torvalds #include <linux/fs.h> 153f8206d4SAl Viro #include <linux/namei.h> 161da177e4SLinus Torvalds #include <linux/fcntl.h> 171da177e4SLinus Torvalds #include <linux/net.h> 181da177e4SLinus Torvalds #include <linux/in.h> 191da177e4SLinus Torvalds #include <linux/syscalls.h> 201da177e4SLinus Torvalds #include <linux/unistd.h> 211da177e4SLinus Torvalds #include <linux/slab.h> 221da177e4SLinus Torvalds #include <linux/proc_fs.h> 231da177e4SLinus Torvalds #include <linux/seq_file.h> 241da177e4SLinus Torvalds #include <linux/pagemap.h> 251da177e4SLinus Torvalds #include <linux/init.h> 264373ea84SWendy Cheng #include <linux/inet.h> 2770c3b76cSNeilBrown #include <linux/string.h> 2880212d59SNeilBrown #include <linux/smp_lock.h> 29b41b66d6SNeilBrown #include <linux/ctype.h> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #include <linux/nfs.h> 321da177e4SLinus Torvalds #include <linux/nfsd_idmap.h> 33b41b66d6SNeilBrown #include <linux/lockd/bind.h> 341da177e4SLinus Torvalds #include <linux/sunrpc/svc.h> 3580212d59SNeilBrown #include <linux/sunrpc/svcsock.h> 361da177e4SLinus Torvalds #include <linux/nfsd/nfsd.h> 371da177e4SLinus Torvalds #include <linux/nfsd/cache.h> 381da177e4SLinus Torvalds #include <linux/nfsd/xdr.h> 391da177e4SLinus Torvalds #include <linux/nfsd/syscall.h> 404373ea84SWendy Cheng #include <linux/lockd/lockd.h> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #include <asm/uaccess.h> 43f15364bdSAurélien Charbon #include <net/ipv6.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds /* 461da177e4SLinus Torvalds * We have a single directory with 9 nodes in it. 471da177e4SLinus Torvalds */ 481da177e4SLinus Torvalds enum { 491da177e4SLinus Torvalds NFSD_Root = 1, 501da177e4SLinus Torvalds NFSD_Svc, 511da177e4SLinus Torvalds NFSD_Add, 521da177e4SLinus Torvalds NFSD_Del, 531da177e4SLinus Torvalds NFSD_Export, 541da177e4SLinus Torvalds NFSD_Unexport, 551da177e4SLinus Torvalds NFSD_Getfd, 561da177e4SLinus Torvalds NFSD_Getfs, 571da177e4SLinus Torvalds NFSD_List, 581da177e4SLinus Torvalds NFSD_Fh, 594373ea84SWendy Cheng NFSD_FO_UnlockIP, 6017efa372SWendy Cheng NFSD_FO_UnlockFS, 611da177e4SLinus Torvalds NFSD_Threads, 62eed2965aSGreg Banks NFSD_Pool_Threads, 63*03cf6c9fSGreg Banks NFSD_Pool_Stats, 6470c3b76cSNeilBrown NFSD_Versions, 6580212d59SNeilBrown NFSD_Ports, 66596bbe53SNeilBrown NFSD_MaxBlkSize, 6770c3b76cSNeilBrown /* 6870c3b76cSNeilBrown * The below MUST come last. Otherwise we leave a hole in nfsd_files[] 6970c3b76cSNeilBrown * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops 7070c3b76cSNeilBrown */ 7170c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 721da177e4SLinus Torvalds NFSD_Leasetime, 730964a3d3SNeilBrown NFSD_RecoveryDir, 7470c3b76cSNeilBrown #endif 751da177e4SLinus Torvalds }; 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* 781da177e4SLinus Torvalds * write() for these nodes. 791da177e4SLinus Torvalds */ 801da177e4SLinus Torvalds static ssize_t write_svc(struct file *file, char *buf, size_t size); 811da177e4SLinus Torvalds static ssize_t write_add(struct file *file, char *buf, size_t size); 821da177e4SLinus Torvalds static ssize_t write_del(struct file *file, char *buf, size_t size); 831da177e4SLinus Torvalds static ssize_t write_export(struct file *file, char *buf, size_t size); 841da177e4SLinus Torvalds static ssize_t write_unexport(struct file *file, char *buf, size_t size); 851da177e4SLinus Torvalds static ssize_t write_getfd(struct file *file, char *buf, size_t size); 861da177e4SLinus Torvalds static ssize_t write_getfs(struct file *file, char *buf, size_t size); 871da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size); 88b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); 89b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); 901da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size); 91eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); 9270c3b76cSNeilBrown static ssize_t write_versions(struct file *file, char *buf, size_t size); 9380212d59SNeilBrown static ssize_t write_ports(struct file *file, char *buf, size_t size); 94596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); 9570c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 961da177e4SLinus Torvalds static ssize_t write_leasetime(struct file *file, char *buf, size_t size); 970964a3d3SNeilBrown static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); 9870c3b76cSNeilBrown #endif 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds static ssize_t (*write_op[])(struct file *, char *, size_t) = { 1011da177e4SLinus Torvalds [NFSD_Svc] = write_svc, 1021da177e4SLinus Torvalds [NFSD_Add] = write_add, 1031da177e4SLinus Torvalds [NFSD_Del] = write_del, 1041da177e4SLinus Torvalds [NFSD_Export] = write_export, 1051da177e4SLinus Torvalds [NFSD_Unexport] = write_unexport, 1061da177e4SLinus Torvalds [NFSD_Getfd] = write_getfd, 1071da177e4SLinus Torvalds [NFSD_Getfs] = write_getfs, 1081da177e4SLinus Torvalds [NFSD_Fh] = write_filehandle, 109b046ccdcSChuck Lever [NFSD_FO_UnlockIP] = write_unlock_ip, 110b046ccdcSChuck Lever [NFSD_FO_UnlockFS] = write_unlock_fs, 1111da177e4SLinus Torvalds [NFSD_Threads] = write_threads, 112eed2965aSGreg Banks [NFSD_Pool_Threads] = write_pool_threads, 11370c3b76cSNeilBrown [NFSD_Versions] = write_versions, 11480212d59SNeilBrown [NFSD_Ports] = write_ports, 115596bbe53SNeilBrown [NFSD_MaxBlkSize] = write_maxblksize, 11670c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 1171da177e4SLinus Torvalds [NFSD_Leasetime] = write_leasetime, 1180964a3d3SNeilBrown [NFSD_RecoveryDir] = write_recoverydir, 11970c3b76cSNeilBrown #endif 1201da177e4SLinus Torvalds }; 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 1231da177e4SLinus Torvalds { 1247eaa36e2SJosef "Jeff" Sipek ino_t ino = file->f_path.dentry->d_inode->i_ino; 1251da177e4SLinus Torvalds char *data; 1261da177e4SLinus Torvalds ssize_t rv; 1271da177e4SLinus Torvalds 128e8c96f8cSTobias Klauser if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) 1291da177e4SLinus Torvalds return -EINVAL; 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds data = simple_transaction_get(file, buf, size); 1321da177e4SLinus Torvalds if (IS_ERR(data)) 1331da177e4SLinus Torvalds return PTR_ERR(data); 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds rv = write_op[ino](file, data, size); 1368971a101SNeilBrown if (rv >= 0) { 1371da177e4SLinus Torvalds simple_transaction_set(file, rv); 1381da177e4SLinus Torvalds rv = size; 1391da177e4SLinus Torvalds } 1401da177e4SLinus Torvalds return rv; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1437390022dSNeilBrown static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) 1447390022dSNeilBrown { 1457390022dSNeilBrown if (! file->private_data) { 1467390022dSNeilBrown /* An attempt to read a transaction file without writing 1477390022dSNeilBrown * causes a 0-byte write so that the file can return 1487390022dSNeilBrown * state information 1497390022dSNeilBrown */ 1507390022dSNeilBrown ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); 1517390022dSNeilBrown if (rv < 0) 1527390022dSNeilBrown return rv; 1537390022dSNeilBrown } 1547390022dSNeilBrown return simple_transaction_read(file, buf, size, pos); 1557390022dSNeilBrown } 1567390022dSNeilBrown 1574b6f5d20SArjan van de Ven static const struct file_operations transaction_ops = { 1581da177e4SLinus Torvalds .write = nfsctl_transaction_write, 1597390022dSNeilBrown .read = nfsctl_transaction_read, 1601da177e4SLinus Torvalds .release = simple_transaction_release, 1611da177e4SLinus Torvalds }; 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds static int exports_open(struct inode *inode, struct file *file) 1641da177e4SLinus Torvalds { 1651da177e4SLinus Torvalds return seq_open(file, &nfs_exports_op); 1661da177e4SLinus Torvalds } 1671da177e4SLinus Torvalds 1684b6f5d20SArjan van de Ven static const struct file_operations exports_operations = { 1691da177e4SLinus Torvalds .open = exports_open, 1701da177e4SLinus Torvalds .read = seq_read, 1711da177e4SLinus Torvalds .llseek = seq_lseek, 1721da177e4SLinus Torvalds .release = seq_release, 1739ef2db26SDenis V. Lunev .owner = THIS_MODULE, 1741da177e4SLinus Torvalds }; 1751da177e4SLinus Torvalds 176*03cf6c9fSGreg Banks extern int nfsd_pool_stats_open(struct inode *inode, struct file *file); 177*03cf6c9fSGreg Banks 178*03cf6c9fSGreg Banks static struct file_operations pool_stats_operations = { 179*03cf6c9fSGreg Banks .open = nfsd_pool_stats_open, 180*03cf6c9fSGreg Banks .read = seq_read, 181*03cf6c9fSGreg Banks .llseek = seq_lseek, 182*03cf6c9fSGreg Banks .release = seq_release, 183*03cf6c9fSGreg Banks .owner = THIS_MODULE, 184*03cf6c9fSGreg Banks }; 185*03cf6c9fSGreg Banks 1861da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 1871da177e4SLinus Torvalds /* 1881da177e4SLinus Torvalds * payload - write methods 1891da177e4SLinus Torvalds */ 1901da177e4SLinus Torvalds 191262a0982SChuck Lever /** 192262a0982SChuck Lever * write_svc - Start kernel's NFSD server 193262a0982SChuck Lever * 194262a0982SChuck Lever * Deprecated. /proc/fs/nfsd/threads is preferred. 195262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 196262a0982SChuck Lever * 197262a0982SChuck Lever * Input: 198262a0982SChuck Lever * buf: struct nfsctl_svc 199262a0982SChuck Lever * svc_port: port number of this 200262a0982SChuck Lever * server's listener 201262a0982SChuck Lever * svc_nthreads: number of threads to start 202262a0982SChuck Lever * size: size in bytes of passed in nfsctl_svc 203262a0982SChuck Lever * Output: 204262a0982SChuck Lever * On success: returns zero 205262a0982SChuck Lever * On error: return code is negative errno value 206262a0982SChuck Lever */ 2071da177e4SLinus Torvalds static ssize_t write_svc(struct file *file, char *buf, size_t size) 2081da177e4SLinus Torvalds { 2091da177e4SLinus Torvalds struct nfsctl_svc *data; 2101da177e4SLinus Torvalds if (size < sizeof(*data)) 2111da177e4SLinus Torvalds return -EINVAL; 2121da177e4SLinus Torvalds data = (struct nfsctl_svc*) buf; 2131da177e4SLinus Torvalds return nfsd_svc(data->svc_port, data->svc_nthreads); 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 216262a0982SChuck Lever /** 217262a0982SChuck Lever * write_add - Add or modify client entry in auth unix cache 218262a0982SChuck Lever * 219262a0982SChuck Lever * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. 220262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 221262a0982SChuck Lever * 222262a0982SChuck Lever * Input: 223262a0982SChuck Lever * buf: struct nfsctl_client 224262a0982SChuck Lever * cl_ident: '\0'-terminated C string 225262a0982SChuck Lever * containing domain name 226262a0982SChuck Lever * of client 227262a0982SChuck Lever * cl_naddr: no. of items in cl_addrlist 228262a0982SChuck Lever * cl_addrlist: array of client addresses 229262a0982SChuck Lever * cl_fhkeytype: ignored 230262a0982SChuck Lever * cl_fhkeylen: ignored 231262a0982SChuck Lever * cl_fhkey: ignored 232262a0982SChuck Lever * size: size in bytes of passed in nfsctl_client 233262a0982SChuck Lever * Output: 234262a0982SChuck Lever * On success: returns zero 235262a0982SChuck Lever * On error: return code is negative errno value 236262a0982SChuck Lever * 237262a0982SChuck Lever * Note: Only AF_INET client addresses are passed in, since 238262a0982SChuck Lever * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. 239262a0982SChuck Lever */ 2401da177e4SLinus Torvalds static ssize_t write_add(struct file *file, char *buf, size_t size) 2411da177e4SLinus Torvalds { 2421da177e4SLinus Torvalds struct nfsctl_client *data; 2431da177e4SLinus Torvalds if (size < sizeof(*data)) 2441da177e4SLinus Torvalds return -EINVAL; 2451da177e4SLinus Torvalds data = (struct nfsctl_client *)buf; 2461da177e4SLinus Torvalds return exp_addclient(data); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 249262a0982SChuck Lever /** 250262a0982SChuck Lever * write_del - Remove client from auth unix cache 251262a0982SChuck Lever * 252262a0982SChuck Lever * Deprecated. /proc/net/rpc/auth.unix.ip is preferred. 253262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 254262a0982SChuck Lever * 255262a0982SChuck Lever * Input: 256262a0982SChuck Lever * buf: struct nfsctl_client 257262a0982SChuck Lever * cl_ident: '\0'-terminated C string 258262a0982SChuck Lever * containing domain name 259262a0982SChuck Lever * of client 260262a0982SChuck Lever * cl_naddr: ignored 261262a0982SChuck Lever * cl_addrlist: ignored 262262a0982SChuck Lever * cl_fhkeytype: ignored 263262a0982SChuck Lever * cl_fhkeylen: ignored 264262a0982SChuck Lever * cl_fhkey: ignored 265262a0982SChuck Lever * size: size in bytes of passed in nfsctl_client 266262a0982SChuck Lever * Output: 267262a0982SChuck Lever * On success: returns zero 268262a0982SChuck Lever * On error: return code is negative errno value 269262a0982SChuck Lever * 270262a0982SChuck Lever * Note: Only AF_INET client addresses are passed in, since 271262a0982SChuck Lever * nfsctl_client.cl_addrlist contains only in_addr fields for addresses. 272262a0982SChuck Lever */ 2731da177e4SLinus Torvalds static ssize_t write_del(struct file *file, char *buf, size_t size) 2741da177e4SLinus Torvalds { 2751da177e4SLinus Torvalds struct nfsctl_client *data; 2761da177e4SLinus Torvalds if (size < sizeof(*data)) 2771da177e4SLinus Torvalds return -EINVAL; 2781da177e4SLinus Torvalds data = (struct nfsctl_client *)buf; 2791da177e4SLinus Torvalds return exp_delclient(data); 2801da177e4SLinus Torvalds } 2811da177e4SLinus Torvalds 282262a0982SChuck Lever /** 283262a0982SChuck Lever * write_export - Export part or all of a local file system 284262a0982SChuck Lever * 285262a0982SChuck Lever * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. 286262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 287262a0982SChuck Lever * 288262a0982SChuck Lever * Input: 289262a0982SChuck Lever * buf: struct nfsctl_export 290262a0982SChuck Lever * ex_client: '\0'-terminated C string 291262a0982SChuck Lever * containing domain name 292262a0982SChuck Lever * of client allowed to access 293262a0982SChuck Lever * this export 294262a0982SChuck Lever * ex_path: '\0'-terminated C string 295262a0982SChuck Lever * containing pathname of 296262a0982SChuck Lever * directory in local file system 297262a0982SChuck Lever * ex_dev: fsid to use for this export 298262a0982SChuck Lever * ex_ino: ignored 299262a0982SChuck Lever * ex_flags: export flags for this export 300262a0982SChuck Lever * ex_anon_uid: UID to use for anonymous 301262a0982SChuck Lever * requests 302262a0982SChuck Lever * ex_anon_gid: GID to use for anonymous 303262a0982SChuck Lever * requests 304262a0982SChuck Lever * size: size in bytes of passed in nfsctl_export 305262a0982SChuck Lever * Output: 306262a0982SChuck Lever * On success: returns zero 307262a0982SChuck Lever * On error: return code is negative errno value 308262a0982SChuck Lever */ 3091da177e4SLinus Torvalds static ssize_t write_export(struct file *file, char *buf, size_t size) 3101da177e4SLinus Torvalds { 3111da177e4SLinus Torvalds struct nfsctl_export *data; 3121da177e4SLinus Torvalds if (size < sizeof(*data)) 3131da177e4SLinus Torvalds return -EINVAL; 3141da177e4SLinus Torvalds data = (struct nfsctl_export*)buf; 3151da177e4SLinus Torvalds return exp_export(data); 3161da177e4SLinus Torvalds } 3171da177e4SLinus Torvalds 318262a0982SChuck Lever /** 319262a0982SChuck Lever * write_unexport - Unexport a previously exported file system 320262a0982SChuck Lever * 321262a0982SChuck Lever * Deprecated. /proc/net/rpc/{nfsd.export,nfsd.fh} are preferred. 322262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 323262a0982SChuck Lever * 324262a0982SChuck Lever * Input: 325262a0982SChuck Lever * buf: struct nfsctl_export 326262a0982SChuck Lever * ex_client: '\0'-terminated C string 327262a0982SChuck Lever * containing domain name 328262a0982SChuck Lever * of client no longer allowed 329262a0982SChuck Lever * to access this export 330262a0982SChuck Lever * ex_path: '\0'-terminated C string 331262a0982SChuck Lever * containing pathname of 332262a0982SChuck Lever * directory in local file system 333262a0982SChuck Lever * ex_dev: ignored 334262a0982SChuck Lever * ex_ino: ignored 335262a0982SChuck Lever * ex_flags: ignored 336262a0982SChuck Lever * ex_anon_uid: ignored 337262a0982SChuck Lever * ex_anon_gid: ignored 338262a0982SChuck Lever * size: size in bytes of passed in nfsctl_export 339262a0982SChuck Lever * Output: 340262a0982SChuck Lever * On success: returns zero 341262a0982SChuck Lever * On error: return code is negative errno value 342262a0982SChuck Lever */ 3431da177e4SLinus Torvalds static ssize_t write_unexport(struct file *file, char *buf, size_t size) 3441da177e4SLinus Torvalds { 3451da177e4SLinus Torvalds struct nfsctl_export *data; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds if (size < sizeof(*data)) 3481da177e4SLinus Torvalds return -EINVAL; 3491da177e4SLinus Torvalds data = (struct nfsctl_export*)buf; 3501da177e4SLinus Torvalds return exp_unexport(data); 3511da177e4SLinus Torvalds } 3521da177e4SLinus Torvalds 353262a0982SChuck Lever /** 354262a0982SChuck Lever * write_getfs - Get a variable-length NFS file handle by path 355262a0982SChuck Lever * 356262a0982SChuck Lever * Deprecated. /proc/fs/nfsd/filehandle is preferred. 357262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 358262a0982SChuck Lever * 359262a0982SChuck Lever * Input: 360262a0982SChuck Lever * buf: struct nfsctl_fsparm 361262a0982SChuck Lever * gd_addr: socket address of client 362262a0982SChuck Lever * gd_path: '\0'-terminated C string 363262a0982SChuck Lever * containing pathname of 364262a0982SChuck Lever * directory in local file system 365262a0982SChuck Lever * gd_maxlen: maximum size of returned file 366262a0982SChuck Lever * handle 367262a0982SChuck Lever * size: size in bytes of passed in nfsctl_fsparm 368262a0982SChuck Lever * Output: 369262a0982SChuck Lever * On success: passed-in buffer filled with a knfsd_fh structure 370262a0982SChuck Lever * (a variable-length raw NFS file handle); 371262a0982SChuck Lever * return code is the size in bytes of the file handle 372262a0982SChuck Lever * On error: return code is negative errno value 373262a0982SChuck Lever * 374262a0982SChuck Lever * Note: Only AF_INET client addresses are passed in, since gd_addr 375262a0982SChuck Lever * is the same size as a struct sockaddr_in. 376262a0982SChuck Lever */ 3771da177e4SLinus Torvalds static ssize_t write_getfs(struct file *file, char *buf, size_t size) 3781da177e4SLinus Torvalds { 3791da177e4SLinus Torvalds struct nfsctl_fsparm *data; 3801da177e4SLinus Torvalds struct sockaddr_in *sin; 3811da177e4SLinus Torvalds struct auth_domain *clp; 3821da177e4SLinus Torvalds int err = 0; 3831da177e4SLinus Torvalds struct knfsd_fh *res; 384f15364bdSAurélien Charbon struct in6_addr in6; 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if (size < sizeof(*data)) 3871da177e4SLinus Torvalds return -EINVAL; 3881da177e4SLinus Torvalds data = (struct nfsctl_fsparm*)buf; 3891da177e4SLinus Torvalds err = -EPROTONOSUPPORT; 3901da177e4SLinus Torvalds if (data->gd_addr.sa_family != AF_INET) 3911da177e4SLinus Torvalds goto out; 3921da177e4SLinus Torvalds sin = (struct sockaddr_in *)&data->gd_addr; 3931da177e4SLinus Torvalds if (data->gd_maxlen > NFS3_FHSIZE) 3941da177e4SLinus Torvalds data->gd_maxlen = NFS3_FHSIZE; 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds res = (struct knfsd_fh*)buf; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds exp_readlock(); 399f15364bdSAurélien Charbon 400f15364bdSAurélien Charbon ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); 401f15364bdSAurélien Charbon 402f15364bdSAurélien Charbon clp = auth_unix_lookup(&in6); 403f15364bdSAurélien Charbon if (!clp) 4041da177e4SLinus Torvalds err = -EPERM; 4051da177e4SLinus Torvalds else { 4061da177e4SLinus Torvalds err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen); 4071da177e4SLinus Torvalds auth_domain_put(clp); 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds exp_readunlock(); 4101da177e4SLinus Torvalds if (err == 0) 41112127498SAndrew Morton err = res->fh_size + offsetof(struct knfsd_fh, fh_base); 4121da177e4SLinus Torvalds out: 4131da177e4SLinus Torvalds return err; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 416262a0982SChuck Lever /** 417262a0982SChuck Lever * write_getfd - Get a fixed-length NFS file handle by path (used by mountd) 418262a0982SChuck Lever * 419262a0982SChuck Lever * Deprecated. /proc/fs/nfsd/filehandle is preferred. 420262a0982SChuck Lever * Function remains to support old versions of nfs-utils. 421262a0982SChuck Lever * 422262a0982SChuck Lever * Input: 423262a0982SChuck Lever * buf: struct nfsctl_fdparm 424262a0982SChuck Lever * gd_addr: socket address of client 425262a0982SChuck Lever * gd_path: '\0'-terminated C string 426262a0982SChuck Lever * containing pathname of 427262a0982SChuck Lever * directory in local file system 428262a0982SChuck Lever * gd_version: fdparm structure version 429262a0982SChuck Lever * size: size in bytes of passed in nfsctl_fdparm 430262a0982SChuck Lever * Output: 431262a0982SChuck Lever * On success: passed-in buffer filled with nfsctl_res 432262a0982SChuck Lever * (a fixed-length raw NFS file handle); 433262a0982SChuck Lever * return code is the size in bytes of the file handle 434262a0982SChuck Lever * On error: return code is negative errno value 435262a0982SChuck Lever * 436262a0982SChuck Lever * Note: Only AF_INET client addresses are passed in, since gd_addr 437262a0982SChuck Lever * is the same size as a struct sockaddr_in. 438262a0982SChuck Lever */ 4391da177e4SLinus Torvalds static ssize_t write_getfd(struct file *file, char *buf, size_t size) 4401da177e4SLinus Torvalds { 4411da177e4SLinus Torvalds struct nfsctl_fdparm *data; 4421da177e4SLinus Torvalds struct sockaddr_in *sin; 4431da177e4SLinus Torvalds struct auth_domain *clp; 4441da177e4SLinus Torvalds int err = 0; 4451da177e4SLinus Torvalds struct knfsd_fh fh; 4461da177e4SLinus Torvalds char *res; 447f15364bdSAurélien Charbon struct in6_addr in6; 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds if (size < sizeof(*data)) 4501da177e4SLinus Torvalds return -EINVAL; 4511da177e4SLinus Torvalds data = (struct nfsctl_fdparm*)buf; 4521da177e4SLinus Torvalds err = -EPROTONOSUPPORT; 4531da177e4SLinus Torvalds if (data->gd_addr.sa_family != AF_INET) 4541da177e4SLinus Torvalds goto out; 4551da177e4SLinus Torvalds err = -EINVAL; 4561da177e4SLinus Torvalds if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS) 4571da177e4SLinus Torvalds goto out; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvalds res = buf; 4601da177e4SLinus Torvalds sin = (struct sockaddr_in *)&data->gd_addr; 4611da177e4SLinus Torvalds exp_readlock(); 462f15364bdSAurélien Charbon 463f15364bdSAurélien Charbon ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6); 464f15364bdSAurélien Charbon 465f15364bdSAurélien Charbon clp = auth_unix_lookup(&in6); 466f15364bdSAurélien Charbon if (!clp) 4671da177e4SLinus Torvalds err = -EPERM; 4681da177e4SLinus Torvalds else { 4691da177e4SLinus Torvalds err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE); 4701da177e4SLinus Torvalds auth_domain_put(clp); 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds exp_readunlock(); 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds if (err == 0) { 4751da177e4SLinus Torvalds memset(res,0, NFS_FHSIZE); 4761da177e4SLinus Torvalds memcpy(res, &fh.fh_base, fh.fh_size); 4771da177e4SLinus Torvalds err = NFS_FHSIZE; 4781da177e4SLinus Torvalds } 4791da177e4SLinus Torvalds out: 4801da177e4SLinus Torvalds return err; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds 483262a0982SChuck Lever /** 484262a0982SChuck Lever * write_unlock_ip - Release all locks used by a client 485262a0982SChuck Lever * 486262a0982SChuck Lever * Experimental. 487262a0982SChuck Lever * 488262a0982SChuck Lever * Input: 489262a0982SChuck Lever * buf: '\n'-terminated C string containing a 490262a0982SChuck Lever * presentation format IPv4 address 491262a0982SChuck Lever * size: length of C string in @buf 492262a0982SChuck Lever * Output: 493262a0982SChuck Lever * On success: returns zero if all specified locks were released; 494262a0982SChuck Lever * returns one if one or more locks were not released 495262a0982SChuck Lever * On error: return code is negative errno value 496262a0982SChuck Lever * 497262a0982SChuck Lever * Note: Only AF_INET client addresses are passed in 498262a0982SChuck Lever */ 499b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) 5004373ea84SWendy Cheng { 501367c8c7bSChuck Lever struct sockaddr_in sin = { 502367c8c7bSChuck Lever .sin_family = AF_INET, 503367c8c7bSChuck Lever }; 5044373ea84SWendy Cheng int b1, b2, b3, b4; 505367c8c7bSChuck Lever char c; 506367c8c7bSChuck Lever char *fo_path; 5074373ea84SWendy Cheng 5084373ea84SWendy Cheng /* sanity check */ 5094373ea84SWendy Cheng if (size == 0) 5104373ea84SWendy Cheng return -EINVAL; 5114373ea84SWendy Cheng 5124373ea84SWendy Cheng if (buf[size-1] != '\n') 5134373ea84SWendy Cheng return -EINVAL; 5144373ea84SWendy Cheng 5154373ea84SWendy Cheng fo_path = buf; 5164373ea84SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 5174373ea84SWendy Cheng return -EINVAL; 5184373ea84SWendy Cheng 5194373ea84SWendy Cheng /* get ipv4 address */ 520be859405SHarvey Harrison if (sscanf(fo_path, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4) 5214373ea84SWendy Cheng return -EINVAL; 522367c8c7bSChuck Lever if (b1 > 255 || b2 > 255 || b3 > 255 || b4 > 255) 523367c8c7bSChuck Lever return -EINVAL; 524367c8c7bSChuck Lever sin.sin_addr.s_addr = htonl((b1 << 24) | (b2 << 16) | (b3 << 8) | b4); 5254373ea84SWendy Cheng 526367c8c7bSChuck Lever return nlmsvc_unlock_all_by_ip((struct sockaddr *)&sin); 5274373ea84SWendy Cheng } 5284373ea84SWendy Cheng 529262a0982SChuck Lever /** 530262a0982SChuck Lever * write_unlock_fs - Release all locks on a local file system 531262a0982SChuck Lever * 532262a0982SChuck Lever * Experimental. 533262a0982SChuck Lever * 534262a0982SChuck Lever * Input: 535262a0982SChuck Lever * buf: '\n'-terminated C string containing the 536262a0982SChuck Lever * absolute pathname of a local file system 537262a0982SChuck Lever * size: length of C string in @buf 538262a0982SChuck Lever * Output: 539262a0982SChuck Lever * On success: returns zero if all specified locks were released; 540262a0982SChuck Lever * returns one if one or more locks were not released 541262a0982SChuck Lever * On error: return code is negative errno value 542262a0982SChuck Lever */ 543b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) 54417efa372SWendy Cheng { 545a63bb996SAl Viro struct path path; 54617efa372SWendy Cheng char *fo_path; 54717efa372SWendy Cheng int error; 54817efa372SWendy Cheng 54917efa372SWendy Cheng /* sanity check */ 55017efa372SWendy Cheng if (size == 0) 55117efa372SWendy Cheng return -EINVAL; 55217efa372SWendy Cheng 55317efa372SWendy Cheng if (buf[size-1] != '\n') 55417efa372SWendy Cheng return -EINVAL; 55517efa372SWendy Cheng 55617efa372SWendy Cheng fo_path = buf; 55717efa372SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 55817efa372SWendy Cheng return -EINVAL; 55917efa372SWendy Cheng 560a63bb996SAl Viro error = kern_path(fo_path, 0, &path); 56117efa372SWendy Cheng if (error) 56217efa372SWendy Cheng return error; 56317efa372SWendy Cheng 564262a0982SChuck Lever /* 565262a0982SChuck Lever * XXX: Needs better sanity checking. Otherwise we could end up 566262a0982SChuck Lever * releasing locks on the wrong file system. 567262a0982SChuck Lever * 568262a0982SChuck Lever * For example: 569262a0982SChuck Lever * 1. Does the path refer to a directory? 570262a0982SChuck Lever * 2. Is that directory a mount point, or 571262a0982SChuck Lever * 3. Is that directory the root of an exported file system? 572262a0982SChuck Lever */ 573a63bb996SAl Viro error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb); 57417efa372SWendy Cheng 575a63bb996SAl Viro path_put(&path); 57617efa372SWendy Cheng return error; 57717efa372SWendy Cheng } 57817efa372SWendy Cheng 579262a0982SChuck Lever /** 580262a0982SChuck Lever * write_filehandle - Get a variable-length NFS file handle by path 581262a0982SChuck Lever * 582262a0982SChuck Lever * On input, the buffer contains a '\n'-terminated C string comprised of 583262a0982SChuck Lever * three alphanumeric words separated by whitespace. The string may 584262a0982SChuck Lever * contain escape sequences. 585262a0982SChuck Lever * 586262a0982SChuck Lever * Input: 587262a0982SChuck Lever * buf: 588262a0982SChuck Lever * domain: client domain name 589262a0982SChuck Lever * path: export pathname 590262a0982SChuck Lever * maxsize: numeric maximum size of 591262a0982SChuck Lever * @buf 592262a0982SChuck Lever * size: length of C string in @buf 593262a0982SChuck Lever * Output: 594262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 595262a0982SChuck Lever * string containing a ASCII hex text version 596262a0982SChuck Lever * of the NFS file handle; 597262a0982SChuck Lever * return code is the size in bytes of the string 598262a0982SChuck Lever * On error: return code is negative errno value 599262a0982SChuck Lever */ 6001da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size) 6011da177e4SLinus Torvalds { 6021da177e4SLinus Torvalds char *dname, *path; 603246d95baSAndrew Morton int uninitialized_var(maxsize); 6041da177e4SLinus Torvalds char *mesg = buf; 6051da177e4SLinus Torvalds int len; 6061da177e4SLinus Torvalds struct auth_domain *dom; 6071da177e4SLinus Torvalds struct knfsd_fh fh; 6081da177e4SLinus Torvalds 60987d26ea7SJ. Bruce Fields if (size == 0) 61087d26ea7SJ. Bruce Fields return -EINVAL; 61187d26ea7SJ. Bruce Fields 6121da177e4SLinus Torvalds if (buf[size-1] != '\n') 6131da177e4SLinus Torvalds return -EINVAL; 6141da177e4SLinus Torvalds buf[size-1] = 0; 6151da177e4SLinus Torvalds 6161da177e4SLinus Torvalds dname = mesg; 6171da177e4SLinus Torvalds len = qword_get(&mesg, dname, size); 61854224f04SChuck Lever if (len <= 0) 61954224f04SChuck Lever return -EINVAL; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds path = dname+len+1; 6221da177e4SLinus Torvalds len = qword_get(&mesg, path, size); 62354224f04SChuck Lever if (len <= 0) 62454224f04SChuck Lever return -EINVAL; 6251da177e4SLinus Torvalds 6261da177e4SLinus Torvalds len = get_int(&mesg, &maxsize); 6271da177e4SLinus Torvalds if (len) 6281da177e4SLinus Torvalds return len; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds if (maxsize < NFS_FHSIZE) 6311da177e4SLinus Torvalds return -EINVAL; 6321da177e4SLinus Torvalds if (maxsize > NFS3_FHSIZE) 6331da177e4SLinus Torvalds maxsize = NFS3_FHSIZE; 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds if (qword_get(&mesg, mesg, size)>0) 6361da177e4SLinus Torvalds return -EINVAL; 6371da177e4SLinus Torvalds 6381da177e4SLinus Torvalds /* we have all the words, they are in buf.. */ 6391da177e4SLinus Torvalds dom = unix_domain_find(dname); 6401da177e4SLinus Torvalds if (!dom) 6411da177e4SLinus Torvalds return -ENOMEM; 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds len = exp_rootfh(dom, path, &fh, maxsize); 6441da177e4SLinus Torvalds auth_domain_put(dom); 6451da177e4SLinus Torvalds if (len) 6461da177e4SLinus Torvalds return len; 6471da177e4SLinus Torvalds 64854224f04SChuck Lever mesg = buf; 64954224f04SChuck Lever len = SIMPLE_TRANSACTION_LIMIT; 6501da177e4SLinus Torvalds qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); 6511da177e4SLinus Torvalds mesg[-1] = '\n'; 6521da177e4SLinus Torvalds return mesg - buf; 6531da177e4SLinus Torvalds } 6541da177e4SLinus Torvalds 655262a0982SChuck Lever /** 656262a0982SChuck Lever * write_threads - Start NFSD, or report the current number of running threads 657262a0982SChuck Lever * 658262a0982SChuck Lever * Input: 659262a0982SChuck Lever * buf: ignored 660262a0982SChuck Lever * size: zero 661262a0982SChuck Lever * Output: 662262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 663262a0982SChuck Lever * string numeric value representing the number of 664262a0982SChuck Lever * running NFSD threads; 665262a0982SChuck Lever * return code is the size in bytes of the string 666262a0982SChuck Lever * On error: return code is zero 667262a0982SChuck Lever * 668262a0982SChuck Lever * OR 669262a0982SChuck Lever * 670262a0982SChuck Lever * Input: 671262a0982SChuck Lever * buf: C string containing an unsigned 672262a0982SChuck Lever * integer value representing the 673262a0982SChuck Lever * number of NFSD threads to start 674262a0982SChuck Lever * size: non-zero length of C string in @buf 675262a0982SChuck Lever * Output: 676262a0982SChuck Lever * On success: NFS service is started; 677262a0982SChuck Lever * passed-in buffer filled with '\n'-terminated C 678262a0982SChuck Lever * string numeric value representing the number of 679262a0982SChuck Lever * running NFSD threads; 680262a0982SChuck Lever * return code is the size in bytes of the string 681262a0982SChuck Lever * On error: return code is zero or a negative errno value 682262a0982SChuck Lever */ 6831da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size) 6841da177e4SLinus Torvalds { 6851da177e4SLinus Torvalds char *mesg = buf; 6861da177e4SLinus Torvalds int rv; 6871da177e4SLinus Torvalds if (size > 0) { 6881da177e4SLinus Torvalds int newthreads; 6891da177e4SLinus Torvalds rv = get_int(&mesg, &newthreads); 6901da177e4SLinus Torvalds if (rv) 6911da177e4SLinus Torvalds return rv; 6921da177e4SLinus Torvalds if (newthreads < 0) 6931da177e4SLinus Torvalds return -EINVAL; 6949e074856SChuck Lever rv = nfsd_svc(NFS_PORT, newthreads); 6951da177e4SLinus Torvalds if (rv) 6961da177e4SLinus Torvalds return rv; 6971da177e4SLinus Torvalds } 6981da177e4SLinus Torvalds sprintf(buf, "%d\n", nfsd_nrthreads()); 6991da177e4SLinus Torvalds return strlen(buf); 7001da177e4SLinus Torvalds } 7011da177e4SLinus Torvalds 702262a0982SChuck Lever /** 703262a0982SChuck Lever * write_pool_threads - Set or report the current number of threads per pool 704262a0982SChuck Lever * 705262a0982SChuck Lever * Input: 706262a0982SChuck Lever * buf: ignored 707262a0982SChuck Lever * size: zero 708262a0982SChuck Lever * 709262a0982SChuck Lever * OR 710262a0982SChuck Lever * 711262a0982SChuck Lever * Input: 712262a0982SChuck Lever * buf: C string containing whitespace- 713262a0982SChuck Lever * separated unsigned integer values 714262a0982SChuck Lever * representing the number of NFSD 715262a0982SChuck Lever * threads to start in each pool 716262a0982SChuck Lever * size: non-zero length of C string in @buf 717262a0982SChuck Lever * Output: 718262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 719262a0982SChuck Lever * string containing integer values representing the 720262a0982SChuck Lever * number of NFSD threads in each pool; 721262a0982SChuck Lever * return code is the size in bytes of the string 722262a0982SChuck Lever * On error: return code is zero or a negative errno value 723262a0982SChuck Lever */ 724eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) 725eed2965aSGreg Banks { 726eed2965aSGreg Banks /* if size > 0, look for an array of number of threads per node 727eed2965aSGreg Banks * and apply them then write out number of threads per node as reply 728eed2965aSGreg Banks */ 729eed2965aSGreg Banks char *mesg = buf; 730eed2965aSGreg Banks int i; 731eed2965aSGreg Banks int rv; 732eed2965aSGreg Banks int len; 733bedbdd8bSNeil Brown int npools; 734eed2965aSGreg Banks int *nthreads; 735eed2965aSGreg Banks 736bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 737bedbdd8bSNeil Brown npools = nfsd_nrpools(); 738eed2965aSGreg Banks if (npools == 0) { 739eed2965aSGreg Banks /* 740eed2965aSGreg Banks * NFS is shut down. The admin can start it by 741eed2965aSGreg Banks * writing to the threads file but NOT the pool_threads 742eed2965aSGreg Banks * file, sorry. Report zero threads. 743eed2965aSGreg Banks */ 744bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 745eed2965aSGreg Banks strcpy(buf, "0\n"); 746eed2965aSGreg Banks return strlen(buf); 747eed2965aSGreg Banks } 748eed2965aSGreg Banks 749eed2965aSGreg Banks nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); 750bedbdd8bSNeil Brown rv = -ENOMEM; 751eed2965aSGreg Banks if (nthreads == NULL) 752bedbdd8bSNeil Brown goto out_free; 753eed2965aSGreg Banks 754eed2965aSGreg Banks if (size > 0) { 755eed2965aSGreg Banks for (i = 0; i < npools; i++) { 756eed2965aSGreg Banks rv = get_int(&mesg, &nthreads[i]); 757eed2965aSGreg Banks if (rv == -ENOENT) 758eed2965aSGreg Banks break; /* fewer numbers than pools */ 759eed2965aSGreg Banks if (rv) 760eed2965aSGreg Banks goto out_free; /* syntax error */ 761eed2965aSGreg Banks rv = -EINVAL; 762eed2965aSGreg Banks if (nthreads[i] < 0) 763eed2965aSGreg Banks goto out_free; 764eed2965aSGreg Banks } 765eed2965aSGreg Banks rv = nfsd_set_nrthreads(i, nthreads); 766eed2965aSGreg Banks if (rv) 767eed2965aSGreg Banks goto out_free; 768eed2965aSGreg Banks } 769eed2965aSGreg Banks 770eed2965aSGreg Banks rv = nfsd_get_nrthreads(npools, nthreads); 771eed2965aSGreg Banks if (rv) 772eed2965aSGreg Banks goto out_free; 773eed2965aSGreg Banks 774eed2965aSGreg Banks mesg = buf; 775eed2965aSGreg Banks size = SIMPLE_TRANSACTION_LIMIT; 776eed2965aSGreg Banks for (i = 0; i < npools && size > 0; i++) { 777eed2965aSGreg Banks snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); 778eed2965aSGreg Banks len = strlen(mesg); 779eed2965aSGreg Banks size -= len; 780eed2965aSGreg Banks mesg += len; 781eed2965aSGreg Banks } 782eed2965aSGreg Banks 783bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 784eed2965aSGreg Banks return (mesg-buf); 785eed2965aSGreg Banks 786eed2965aSGreg Banks out_free: 787eed2965aSGreg Banks kfree(nthreads); 788bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 789eed2965aSGreg Banks return rv; 790eed2965aSGreg Banks } 791eed2965aSGreg Banks 7923dd98a3bSJeff Layton static ssize_t __write_versions(struct file *file, char *buf, size_t size) 79370c3b76cSNeilBrown { 79470c3b76cSNeilBrown char *mesg = buf; 79570c3b76cSNeilBrown char *vers, sign; 79670c3b76cSNeilBrown int len, num; 79770c3b76cSNeilBrown ssize_t tlen = 0; 79870c3b76cSNeilBrown char *sep; 79970c3b76cSNeilBrown 80070c3b76cSNeilBrown if (size>0) { 80170c3b76cSNeilBrown if (nfsd_serv) 8026658d3a7SNeilBrown /* Cannot change versions without updating 8036658d3a7SNeilBrown * nfsd_serv->sv_xdrsize, and reallocing 8046658d3a7SNeilBrown * rq_argp and rq_resp 8056658d3a7SNeilBrown */ 80670c3b76cSNeilBrown return -EBUSY; 80770c3b76cSNeilBrown if (buf[size-1] != '\n') 80870c3b76cSNeilBrown return -EINVAL; 80970c3b76cSNeilBrown buf[size-1] = 0; 81070c3b76cSNeilBrown 81170c3b76cSNeilBrown vers = mesg; 81270c3b76cSNeilBrown len = qword_get(&mesg, vers, size); 81370c3b76cSNeilBrown if (len <= 0) return -EINVAL; 81470c3b76cSNeilBrown do { 81570c3b76cSNeilBrown sign = *vers; 81670c3b76cSNeilBrown if (sign == '+' || sign == '-') 81770c3b76cSNeilBrown num = simple_strtol((vers+1), NULL, 0); 81870c3b76cSNeilBrown else 81970c3b76cSNeilBrown num = simple_strtol(vers, NULL, 0); 82070c3b76cSNeilBrown switch(num) { 82170c3b76cSNeilBrown case 2: 82270c3b76cSNeilBrown case 3: 82370c3b76cSNeilBrown case 4: 8246658d3a7SNeilBrown nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); 82570c3b76cSNeilBrown break; 82670c3b76cSNeilBrown default: 82770c3b76cSNeilBrown return -EINVAL; 82870c3b76cSNeilBrown } 82970c3b76cSNeilBrown vers += len + 1; 83070c3b76cSNeilBrown tlen += len; 83170c3b76cSNeilBrown } while ((len = qword_get(&mesg, vers, size)) > 0); 83270c3b76cSNeilBrown /* If all get turned off, turn them back on, as 83370c3b76cSNeilBrown * having no versions is BAD 83470c3b76cSNeilBrown */ 8356658d3a7SNeilBrown nfsd_reset_versions(); 83670c3b76cSNeilBrown } 83770c3b76cSNeilBrown /* Now write current state into reply buffer */ 83870c3b76cSNeilBrown len = 0; 83970c3b76cSNeilBrown sep = ""; 84070c3b76cSNeilBrown for (num=2 ; num <= 4 ; num++) 8416658d3a7SNeilBrown if (nfsd_vers(num, NFSD_AVAIL)) { 84270c3b76cSNeilBrown len += sprintf(buf+len, "%s%c%d", sep, 8436658d3a7SNeilBrown nfsd_vers(num, NFSD_TEST)?'+':'-', 84470c3b76cSNeilBrown num); 84570c3b76cSNeilBrown sep = " "; 84670c3b76cSNeilBrown } 84770c3b76cSNeilBrown len += sprintf(buf+len, "\n"); 84870c3b76cSNeilBrown return len; 84970c3b76cSNeilBrown } 85070c3b76cSNeilBrown 851262a0982SChuck Lever /** 852262a0982SChuck Lever * write_versions - Set or report the available NFS protocol versions 853262a0982SChuck Lever * 854262a0982SChuck Lever * Input: 855262a0982SChuck Lever * buf: ignored 856262a0982SChuck Lever * size: zero 857262a0982SChuck Lever * Output: 858262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 859262a0982SChuck Lever * string containing positive or negative integer 860262a0982SChuck Lever * values representing the current status of each 861262a0982SChuck Lever * protocol version; 862262a0982SChuck Lever * return code is the size in bytes of the string 863262a0982SChuck Lever * On error: return code is zero or a negative errno value 864262a0982SChuck Lever * 865262a0982SChuck Lever * OR 866262a0982SChuck Lever * 867262a0982SChuck Lever * Input: 868262a0982SChuck Lever * buf: C string containing whitespace- 869262a0982SChuck Lever * separated positive or negative 870262a0982SChuck Lever * integer values representing NFS 871262a0982SChuck Lever * protocol versions to enable ("+n") 872262a0982SChuck Lever * or disable ("-n") 873262a0982SChuck Lever * size: non-zero length of C string in @buf 874262a0982SChuck Lever * Output: 875262a0982SChuck Lever * On success: status of zero or more protocol versions has 876262a0982SChuck Lever * been updated; passed-in buffer filled with 877262a0982SChuck Lever * '\n'-terminated C string containing positive 878262a0982SChuck Lever * or negative integer values representing the 879262a0982SChuck Lever * current status of each protocol version; 880262a0982SChuck Lever * return code is the size in bytes of the string 881262a0982SChuck Lever * On error: return code is zero or a negative errno value 882262a0982SChuck Lever */ 8833dd98a3bSJeff Layton static ssize_t write_versions(struct file *file, char *buf, size_t size) 8843dd98a3bSJeff Layton { 8853dd98a3bSJeff Layton ssize_t rv; 8863dd98a3bSJeff Layton 8873dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 8883dd98a3bSJeff Layton rv = __write_versions(file, buf, size); 8893dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 8903dd98a3bSJeff Layton return rv; 8913dd98a3bSJeff Layton } 8923dd98a3bSJeff Layton 893bedbdd8bSNeil Brown static ssize_t __write_ports(struct file *file, char *buf, size_t size) 89480212d59SNeilBrown { 895b41b66d6SNeilBrown if (size == 0) { 89680212d59SNeilBrown int len = 0; 897bedbdd8bSNeil Brown 89880212d59SNeilBrown if (nfsd_serv) 8999571af18STom Tucker len = svc_xprt_names(nfsd_serv, buf, 0); 90080212d59SNeilBrown return len; 90180212d59SNeilBrown } 902b41b66d6SNeilBrown /* Either a single 'fd' number is written, in which 903b41b66d6SNeilBrown * case it must be for a socket of a supported family/protocol, 904b41b66d6SNeilBrown * and we use it as an nfsd socket, or 905b41b66d6SNeilBrown * A '-' followed by the 'name' of a socket in which case 906b41b66d6SNeilBrown * we close the socket. 907b41b66d6SNeilBrown */ 908b41b66d6SNeilBrown if (isdigit(buf[0])) { 909b41b66d6SNeilBrown char *mesg = buf; 910b41b66d6SNeilBrown int fd; 911b41b66d6SNeilBrown int err; 912b41b66d6SNeilBrown err = get_int(&mesg, &fd); 913b41b66d6SNeilBrown if (err) 914b41b66d6SNeilBrown return -EINVAL; 915b41b66d6SNeilBrown if (fd < 0) 916b41b66d6SNeilBrown return -EINVAL; 917b41b66d6SNeilBrown err = nfsd_create_serv(); 918b41b66d6SNeilBrown if (!err) { 91929373913SChuck Lever err = svc_addsock(nfsd_serv, fd, buf); 9205680c446SNeilBrown if (err >= 0) { 92126a41409SChuck Lever err = lockd_up(); 9225680c446SNeilBrown if (err < 0) 9235680c446SNeilBrown svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf); 9243dfb4210SNeilBrown } 925b41b66d6SNeilBrown /* Decrease the count, but don't shutdown the 926b41b66d6SNeilBrown * the service 927b41b66d6SNeilBrown */ 928b41b66d6SNeilBrown nfsd_serv->sv_nrthreads--; 929b41b66d6SNeilBrown } 9305680c446SNeilBrown return err < 0 ? err : 0; 931b41b66d6SNeilBrown } 932a217813fSTom Tucker if (buf[0] == '-' && isdigit(buf[1])) { 933b41b66d6SNeilBrown char *toclose = kstrdup(buf+1, GFP_KERNEL); 934b41b66d6SNeilBrown int len = 0; 935b41b66d6SNeilBrown if (!toclose) 936b41b66d6SNeilBrown return -ENOMEM; 937b41b66d6SNeilBrown if (nfsd_serv) 938b41b66d6SNeilBrown len = svc_sock_names(buf, nfsd_serv, toclose); 93937a03472SNeilBrown if (len >= 0) 94037a03472SNeilBrown lockd_down(); 941b41b66d6SNeilBrown kfree(toclose); 942b41b66d6SNeilBrown return len; 943b41b66d6SNeilBrown } 944a217813fSTom Tucker /* 945a217813fSTom Tucker * Add a transport listener by writing it's transport name 946a217813fSTom Tucker */ 947a217813fSTom Tucker if (isalpha(buf[0])) { 948a217813fSTom Tucker int err; 949a217813fSTom Tucker char transport[16]; 950a217813fSTom Tucker int port; 951a217813fSTom Tucker if (sscanf(buf, "%15s %4d", transport, &port) == 2) { 952a217813fSTom Tucker err = nfsd_create_serv(); 953a217813fSTom Tucker if (!err) { 954a217813fSTom Tucker err = svc_create_xprt(nfsd_serv, 955a217813fSTom Tucker transport, port, 956a217813fSTom Tucker SVC_SOCK_ANONYMOUS); 957a217813fSTom Tucker if (err == -ENOENT) 958a217813fSTom Tucker /* Give a reasonable perror msg for 959a217813fSTom Tucker * bad transport string */ 960a217813fSTom Tucker err = -EPROTONOSUPPORT; 961a217813fSTom Tucker } 962a217813fSTom Tucker return err < 0 ? err : 0; 963a217813fSTom Tucker } 964a217813fSTom Tucker } 965a217813fSTom Tucker /* 966a217813fSTom Tucker * Remove a transport by writing it's transport name and port number 967a217813fSTom Tucker */ 968a217813fSTom Tucker if (buf[0] == '-' && isalpha(buf[1])) { 969a217813fSTom Tucker struct svc_xprt *xprt; 970a217813fSTom Tucker int err = -EINVAL; 971a217813fSTom Tucker char transport[16]; 972a217813fSTom Tucker int port; 973a217813fSTom Tucker if (sscanf(&buf[1], "%15s %4d", transport, &port) == 2) { 974a217813fSTom Tucker if (port == 0) 975a217813fSTom Tucker return -EINVAL; 976a217813fSTom Tucker if (nfsd_serv) { 977a217813fSTom Tucker xprt = svc_find_xprt(nfsd_serv, transport, 978a217813fSTom Tucker AF_UNSPEC, port); 979a217813fSTom Tucker if (xprt) { 980a217813fSTom Tucker svc_close_xprt(xprt); 981a217813fSTom Tucker svc_xprt_put(xprt); 982a217813fSTom Tucker err = 0; 983a217813fSTom Tucker } else 984a217813fSTom Tucker err = -ENOTCONN; 985a217813fSTom Tucker } 986a217813fSTom Tucker return err < 0 ? err : 0; 987a217813fSTom Tucker } 988a217813fSTom Tucker } 989b41b66d6SNeilBrown return -EINVAL; 990b41b66d6SNeilBrown } 99180212d59SNeilBrown 992262a0982SChuck Lever /** 993262a0982SChuck Lever * write_ports - Pass a socket file descriptor or transport name to listen on 994262a0982SChuck Lever * 995262a0982SChuck Lever * Input: 996262a0982SChuck Lever * buf: ignored 997262a0982SChuck Lever * size: zero 998262a0982SChuck Lever * Output: 999262a0982SChuck Lever * On success: passed-in buffer filled with a '\n'-terminated C 1000262a0982SChuck Lever * string containing a whitespace-separated list of 1001262a0982SChuck Lever * named NFSD listeners; 1002262a0982SChuck Lever * return code is the size in bytes of the string 1003262a0982SChuck Lever * On error: return code is zero or a negative errno value 1004262a0982SChuck Lever * 1005262a0982SChuck Lever * OR 1006262a0982SChuck Lever * 1007262a0982SChuck Lever * Input: 1008262a0982SChuck Lever * buf: C string containing an unsigned 1009262a0982SChuck Lever * integer value representing a bound 1010262a0982SChuck Lever * but unconnected socket that is to be 1011262a0982SChuck Lever * used as an NFSD listener 1012262a0982SChuck Lever * size: non-zero length of C string in @buf 1013262a0982SChuck Lever * Output: 1014262a0982SChuck Lever * On success: NFS service is started; 1015262a0982SChuck Lever * passed-in buffer filled with a '\n'-terminated C 1016262a0982SChuck Lever * string containing a unique alphanumeric name of 1017262a0982SChuck Lever * the listener; 1018262a0982SChuck Lever * return code is the size in bytes of the string 1019262a0982SChuck Lever * On error: return code is a negative errno value 1020262a0982SChuck Lever * 1021262a0982SChuck Lever * OR 1022262a0982SChuck Lever * 1023262a0982SChuck Lever * Input: 1024262a0982SChuck Lever * buf: C string containing a "-" followed 1025262a0982SChuck Lever * by an integer value representing a 1026262a0982SChuck Lever * previously passed in socket file 1027262a0982SChuck Lever * descriptor 1028262a0982SChuck Lever * size: non-zero length of C string in @buf 1029262a0982SChuck Lever * Output: 1030262a0982SChuck Lever * On success: NFS service no longer listens on that socket; 1031262a0982SChuck Lever * passed-in buffer filled with a '\n'-terminated C 1032262a0982SChuck Lever * string containing a unique name of the listener; 1033262a0982SChuck Lever * return code is the size in bytes of the string 1034262a0982SChuck Lever * On error: return code is a negative errno value 1035262a0982SChuck Lever * 1036262a0982SChuck Lever * OR 1037262a0982SChuck Lever * 1038262a0982SChuck Lever * Input: 1039262a0982SChuck Lever * buf: C string containing a transport 1040262a0982SChuck Lever * name and an unsigned integer value 1041262a0982SChuck Lever * representing the port to listen on, 1042262a0982SChuck Lever * separated by whitespace 1043262a0982SChuck Lever * size: non-zero length of C string in @buf 1044262a0982SChuck Lever * Output: 1045262a0982SChuck Lever * On success: returns zero; NFS service is started 1046262a0982SChuck Lever * On error: return code is a negative errno value 1047262a0982SChuck Lever * 1048262a0982SChuck Lever * OR 1049262a0982SChuck Lever * 1050262a0982SChuck Lever * Input: 1051262a0982SChuck Lever * buf: C string containing a "-" followed 1052262a0982SChuck Lever * by a transport name and an unsigned 1053262a0982SChuck Lever * integer value representing the port 1054262a0982SChuck Lever * to listen on, separated by whitespace 1055262a0982SChuck Lever * size: non-zero length of C string in @buf 1056262a0982SChuck Lever * Output: 1057262a0982SChuck Lever * On success: returns zero; NFS service no longer listens 1058262a0982SChuck Lever * on that transport 1059262a0982SChuck Lever * On error: return code is a negative errno value 1060262a0982SChuck Lever */ 1061bedbdd8bSNeil Brown static ssize_t write_ports(struct file *file, char *buf, size_t size) 1062bedbdd8bSNeil Brown { 1063bedbdd8bSNeil Brown ssize_t rv; 10643dd98a3bSJeff Layton 1065bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 1066bedbdd8bSNeil Brown rv = __write_ports(file, buf, size); 1067bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 1068bedbdd8bSNeil Brown return rv; 1069bedbdd8bSNeil Brown } 1070bedbdd8bSNeil Brown 1071bedbdd8bSNeil Brown 1072596bbe53SNeilBrown int nfsd_max_blksize; 1073596bbe53SNeilBrown 1074262a0982SChuck Lever /** 1075262a0982SChuck Lever * write_maxblksize - Set or report the current NFS blksize 1076262a0982SChuck Lever * 1077262a0982SChuck Lever * Input: 1078262a0982SChuck Lever * buf: ignored 1079262a0982SChuck Lever * size: zero 1080262a0982SChuck Lever * 1081262a0982SChuck Lever * OR 1082262a0982SChuck Lever * 1083262a0982SChuck Lever * Input: 1084262a0982SChuck Lever * buf: C string containing an unsigned 1085262a0982SChuck Lever * integer value representing the new 1086262a0982SChuck Lever * NFS blksize 1087262a0982SChuck Lever * size: non-zero length of C string in @buf 1088262a0982SChuck Lever * Output: 1089262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 1090262a0982SChuck Lever * containing numeric value of the current NFS blksize 1091262a0982SChuck Lever * setting; 1092262a0982SChuck Lever * return code is the size in bytes of the string 1093262a0982SChuck Lever * On error: return code is zero or a negative errno value 1094262a0982SChuck Lever */ 1095596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) 1096596bbe53SNeilBrown { 1097596bbe53SNeilBrown char *mesg = buf; 1098596bbe53SNeilBrown if (size > 0) { 1099596bbe53SNeilBrown int bsize; 1100596bbe53SNeilBrown int rv = get_int(&mesg, &bsize); 1101596bbe53SNeilBrown if (rv) 1102596bbe53SNeilBrown return rv; 1103596bbe53SNeilBrown /* force bsize into allowed range and 1104596bbe53SNeilBrown * required alignment. 1105596bbe53SNeilBrown */ 1106596bbe53SNeilBrown if (bsize < 1024) 1107596bbe53SNeilBrown bsize = 1024; 1108596bbe53SNeilBrown if (bsize > NFSSVC_MAXBLKSIZE) 1109596bbe53SNeilBrown bsize = NFSSVC_MAXBLKSIZE; 1110596bbe53SNeilBrown bsize &= ~(1024-1); 1111bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 1112596bbe53SNeilBrown if (nfsd_serv && nfsd_serv->sv_nrthreads) { 1113bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 1114596bbe53SNeilBrown return -EBUSY; 1115596bbe53SNeilBrown } 1116596bbe53SNeilBrown nfsd_max_blksize = bsize; 1117bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 1118596bbe53SNeilBrown } 1119596bbe53SNeilBrown return sprintf(buf, "%d\n", nfsd_max_blksize); 1120596bbe53SNeilBrown } 1121596bbe53SNeilBrown 112270c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 11231da177e4SLinus Torvalds extern time_t nfs4_leasetime(void); 11241da177e4SLinus Torvalds 11253dd98a3bSJeff Layton static ssize_t __write_leasetime(struct file *file, char *buf, size_t size) 11261da177e4SLinus Torvalds { 11271da177e4SLinus Torvalds /* if size > 10 seconds, call 11281da177e4SLinus Torvalds * nfs4_reset_lease() then write out the new lease (seconds) as reply 11291da177e4SLinus Torvalds */ 11301da177e4SLinus Torvalds char *mesg = buf; 11313dd98a3bSJeff Layton int rv, lease; 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds if (size > 0) { 11343dd98a3bSJeff Layton if (nfsd_serv) 11353dd98a3bSJeff Layton return -EBUSY; 11361da177e4SLinus Torvalds rv = get_int(&mesg, &lease); 11371da177e4SLinus Torvalds if (rv) 11381da177e4SLinus Torvalds return rv; 11391da177e4SLinus Torvalds if (lease < 10 || lease > 3600) 11401da177e4SLinus Torvalds return -EINVAL; 11411da177e4SLinus Torvalds nfs4_reset_lease(lease); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds sprintf(buf, "%ld\n", nfs4_lease_time()); 11441da177e4SLinus Torvalds return strlen(buf); 11451da177e4SLinus Torvalds } 11461da177e4SLinus Torvalds 1147262a0982SChuck Lever /** 1148262a0982SChuck Lever * write_leasetime - Set or report the current NFSv4 lease time 1149262a0982SChuck Lever * 1150262a0982SChuck Lever * Input: 1151262a0982SChuck Lever * buf: ignored 1152262a0982SChuck Lever * size: zero 1153262a0982SChuck Lever * 1154262a0982SChuck Lever * OR 1155262a0982SChuck Lever * 1156262a0982SChuck Lever * Input: 1157262a0982SChuck Lever * buf: C string containing an unsigned 1158262a0982SChuck Lever * integer value representing the new 1159262a0982SChuck Lever * NFSv4 lease expiry time 1160262a0982SChuck Lever * size: non-zero length of C string in @buf 1161262a0982SChuck Lever * Output: 1162262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 1163262a0982SChuck Lever * string containing unsigned integer value of the 1164262a0982SChuck Lever * current lease expiry time; 1165262a0982SChuck Lever * return code is the size in bytes of the string 1166262a0982SChuck Lever * On error: return code is zero or a negative errno value 1167262a0982SChuck Lever */ 11683dd98a3bSJeff Layton static ssize_t write_leasetime(struct file *file, char *buf, size_t size) 11693dd98a3bSJeff Layton { 11703dd98a3bSJeff Layton ssize_t rv; 11713dd98a3bSJeff Layton 11723dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 11733dd98a3bSJeff Layton rv = __write_leasetime(file, buf, size); 11743dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 11753dd98a3bSJeff Layton return rv; 11763dd98a3bSJeff Layton } 11773dd98a3bSJeff Layton 11783dd98a3bSJeff Layton extern char *nfs4_recoverydir(void); 11793dd98a3bSJeff Layton 11803dd98a3bSJeff Layton static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) 11810964a3d3SNeilBrown { 11820964a3d3SNeilBrown char *mesg = buf; 11830964a3d3SNeilBrown char *recdir; 11840964a3d3SNeilBrown int len, status; 11850964a3d3SNeilBrown 11863dd98a3bSJeff Layton if (size > 0) { 11873dd98a3bSJeff Layton if (nfsd_serv) 11883dd98a3bSJeff Layton return -EBUSY; 11893dd98a3bSJeff Layton if (size > PATH_MAX || buf[size-1] != '\n') 11900964a3d3SNeilBrown return -EINVAL; 11910964a3d3SNeilBrown buf[size-1] = 0; 11920964a3d3SNeilBrown 11930964a3d3SNeilBrown recdir = mesg; 11940964a3d3SNeilBrown len = qword_get(&mesg, recdir, size); 11950964a3d3SNeilBrown if (len <= 0) 11960964a3d3SNeilBrown return -EINVAL; 11970964a3d3SNeilBrown 11980964a3d3SNeilBrown status = nfs4_reset_recoverydir(recdir); 11993dd98a3bSJeff Layton } 12003dd98a3bSJeff Layton sprintf(buf, "%s\n", nfs4_recoverydir()); 12010964a3d3SNeilBrown return strlen(buf); 12020964a3d3SNeilBrown } 12033dd98a3bSJeff Layton 1204262a0982SChuck Lever /** 1205262a0982SChuck Lever * write_recoverydir - Set or report the pathname of the recovery directory 1206262a0982SChuck Lever * 1207262a0982SChuck Lever * Input: 1208262a0982SChuck Lever * buf: ignored 1209262a0982SChuck Lever * size: zero 1210262a0982SChuck Lever * 1211262a0982SChuck Lever * OR 1212262a0982SChuck Lever * 1213262a0982SChuck Lever * Input: 1214262a0982SChuck Lever * buf: C string containing the pathname 1215262a0982SChuck Lever * of the directory on a local file 1216262a0982SChuck Lever * system containing permanent NFSv4 1217262a0982SChuck Lever * recovery data 1218262a0982SChuck Lever * size: non-zero length of C string in @buf 1219262a0982SChuck Lever * Output: 1220262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 1221262a0982SChuck Lever * containing the current recovery pathname setting; 1222262a0982SChuck Lever * return code is the size in bytes of the string 1223262a0982SChuck Lever * On error: return code is zero or a negative errno value 1224262a0982SChuck Lever */ 12253dd98a3bSJeff Layton static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) 12263dd98a3bSJeff Layton { 12273dd98a3bSJeff Layton ssize_t rv; 12283dd98a3bSJeff Layton 12293dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 12303dd98a3bSJeff Layton rv = __write_recoverydir(file, buf, size); 12313dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 12323dd98a3bSJeff Layton return rv; 12333dd98a3bSJeff Layton } 12343dd98a3bSJeff Layton 123570c3b76cSNeilBrown #endif 12360964a3d3SNeilBrown 12371da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 12381da177e4SLinus Torvalds /* 12391da177e4SLinus Torvalds * populating the filesystem. 12401da177e4SLinus Torvalds */ 12411da177e4SLinus Torvalds 12421da177e4SLinus Torvalds static int nfsd_fill_super(struct super_block * sb, void * data, int silent) 12431da177e4SLinus Torvalds { 12441da177e4SLinus Torvalds static struct tree_descr nfsd_files[] = { 12451da177e4SLinus Torvalds [NFSD_Svc] = {".svc", &transaction_ops, S_IWUSR}, 12461da177e4SLinus Torvalds [NFSD_Add] = {".add", &transaction_ops, S_IWUSR}, 12471da177e4SLinus Torvalds [NFSD_Del] = {".del", &transaction_ops, S_IWUSR}, 12481da177e4SLinus Torvalds [NFSD_Export] = {".export", &transaction_ops, S_IWUSR}, 12491da177e4SLinus Torvalds [NFSD_Unexport] = {".unexport", &transaction_ops, S_IWUSR}, 12501da177e4SLinus Torvalds [NFSD_Getfd] = {".getfd", &transaction_ops, S_IWUSR|S_IRUSR}, 12511da177e4SLinus Torvalds [NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR}, 12521da177e4SLinus Torvalds [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, 12534373ea84SWendy Cheng [NFSD_FO_UnlockIP] = {"unlock_ip", 12544373ea84SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 125517efa372SWendy Cheng [NFSD_FO_UnlockFS] = {"unlock_filesystem", 125617efa372SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 12571da177e4SLinus Torvalds [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 12581da177e4SLinus Torvalds [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 1259eed2965aSGreg Banks [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, 1260*03cf6c9fSGreg Banks [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, 126170c3b76cSNeilBrown [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, 126280212d59SNeilBrown [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, 1263596bbe53SNeilBrown [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, 12641da177e4SLinus Torvalds #ifdef CONFIG_NFSD_V4 12651da177e4SLinus Torvalds [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, 12660964a3d3SNeilBrown [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, 12671da177e4SLinus Torvalds #endif 12681da177e4SLinus Torvalds /* last one */ {""} 12691da177e4SLinus Torvalds }; 12701da177e4SLinus Torvalds return simple_fill_super(sb, 0x6e667364, nfsd_files); 12711da177e4SLinus Torvalds } 12721da177e4SLinus Torvalds 1273454e2398SDavid Howells static int nfsd_get_sb(struct file_system_type *fs_type, 1274454e2398SDavid Howells int flags, const char *dev_name, void *data, struct vfsmount *mnt) 12751da177e4SLinus Torvalds { 1276454e2398SDavid Howells return get_sb_single(fs_type, flags, data, nfsd_fill_super, mnt); 12771da177e4SLinus Torvalds } 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds static struct file_system_type nfsd_fs_type = { 12801da177e4SLinus Torvalds .owner = THIS_MODULE, 12811da177e4SLinus Torvalds .name = "nfsd", 12821da177e4SLinus Torvalds .get_sb = nfsd_get_sb, 12831da177e4SLinus Torvalds .kill_sb = kill_litter_super, 12841da177e4SLinus Torvalds }; 12851da177e4SLinus Torvalds 1286e331f606SJ. Bruce Fields #ifdef CONFIG_PROC_FS 1287e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1288e331f606SJ. Bruce Fields { 1289e331f606SJ. Bruce Fields struct proc_dir_entry *entry; 1290e331f606SJ. Bruce Fields 1291e331f606SJ. Bruce Fields entry = proc_mkdir("fs/nfs", NULL); 1292e331f606SJ. Bruce Fields if (!entry) 1293e331f606SJ. Bruce Fields return -ENOMEM; 12949ef2db26SDenis V. Lunev entry = proc_create("exports", 0, entry, &exports_operations); 1295e331f606SJ. Bruce Fields if (!entry) 1296e331f606SJ. Bruce Fields return -ENOMEM; 1297e331f606SJ. Bruce Fields return 0; 1298e331f606SJ. Bruce Fields } 1299e331f606SJ. Bruce Fields #else /* CONFIG_PROC_FS */ 1300e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1301e331f606SJ. Bruce Fields { 1302e331f606SJ. Bruce Fields return 0; 1303e331f606SJ. Bruce Fields } 1304e331f606SJ. Bruce Fields #endif 1305e331f606SJ. Bruce Fields 13061da177e4SLinus Torvalds static int __init init_nfsd(void) 13071da177e4SLinus Torvalds { 13081da177e4SLinus Torvalds int retval; 13091da177e4SLinus Torvalds printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 13101da177e4SLinus Torvalds 1311e8ff2a84SJ. Bruce Fields retval = nfs4_state_init(); /* nfs4 locking state */ 1312e8ff2a84SJ. Bruce Fields if (retval) 1313e8ff2a84SJ. Bruce Fields return retval; 13141da177e4SLinus Torvalds nfsd_stat_init(); /* Statistics */ 1315d5c3428bSJ. Bruce Fields retval = nfsd_reply_cache_init(); 1316d5c3428bSJ. Bruce Fields if (retval) 1317d5c3428bSJ. Bruce Fields goto out_free_stat; 1318dbf847ecSJ. Bruce Fields retval = nfsd_export_init(); 1319dbf847ecSJ. Bruce Fields if (retval) 1320dbf847ecSJ. Bruce Fields goto out_free_cache; 13211da177e4SLinus Torvalds nfsd_lockd_init(); /* lockd->nfsd callbacks */ 1322dbf847ecSJ. Bruce Fields retval = nfsd_idmap_init(); 1323dbf847ecSJ. Bruce Fields if (retval) 1324dbf847ecSJ. Bruce Fields goto out_free_lockd; 1325e331f606SJ. Bruce Fields retval = create_proc_exports_entry(); 1326e331f606SJ. Bruce Fields if (retval) 1327e331f606SJ. Bruce Fields goto out_free_idmap; 13281da177e4SLinus Torvalds retval = register_filesystem(&nfsd_fs_type); 132926808d3fSJ. Bruce Fields if (retval) 133026808d3fSJ. Bruce Fields goto out_free_all; 133126808d3fSJ. Bruce Fields return 0; 133226808d3fSJ. Bruce Fields out_free_all: 13331da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 13341da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 1335e331f606SJ. Bruce Fields out_free_idmap: 1336dbf847ecSJ. Bruce Fields nfsd_idmap_shutdown(); 1337dbf847ecSJ. Bruce Fields out_free_lockd: 13381da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1339e331f606SJ. Bruce Fields nfsd_export_shutdown(); 1340dbf847ecSJ. Bruce Fields out_free_cache: 1341e331f606SJ. Bruce Fields nfsd_reply_cache_shutdown(); 1342d5c3428bSJ. Bruce Fields out_free_stat: 1343d5c3428bSJ. Bruce Fields nfsd_stat_shutdown(); 134446b25895SJ. Bruce Fields nfsd4_free_slabs(); 13451da177e4SLinus Torvalds return retval; 13461da177e4SLinus Torvalds } 13471da177e4SLinus Torvalds 13481da177e4SLinus Torvalds static void __exit exit_nfsd(void) 13491da177e4SLinus Torvalds { 13501da177e4SLinus Torvalds nfsd_export_shutdown(); 1351d5c3428bSJ. Bruce Fields nfsd_reply_cache_shutdown(); 13521da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 13531da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 13541da177e4SLinus Torvalds nfsd_stat_shutdown(); 13551da177e4SLinus Torvalds nfsd_lockd_shutdown(); 13561da177e4SLinus Torvalds nfsd_idmap_shutdown(); 1357e8ff2a84SJ. Bruce Fields nfsd4_free_slabs(); 13581da177e4SLinus Torvalds unregister_filesystem(&nfsd_fs_type); 13591da177e4SLinus Torvalds } 13601da177e4SLinus Torvalds 13611da177e4SLinus Torvalds MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); 13621da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 13631da177e4SLinus Torvalds module_init(init_nfsd) 13641da177e4SLinus Torvalds module_exit(exit_nfsd) 1365