109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Syscall interface to knfsd. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 85a0e3ad6STejun Heo #include <linux/slab.h> 93f8206d4SAl Viro #include <linux/namei.h> 10b41b66d6SNeilBrown #include <linux/ctype.h> 1196a374a3SDavid Howells #include <linux/fs_context.h> 121da177e4SLinus Torvalds 1380212d59SNeilBrown #include <linux/sunrpc/svcsock.h> 144373ea84SWendy Cheng #include <linux/lockd/lockd.h> 155976687aSJeff Layton #include <linux/sunrpc/addr.h> 16b0b0c0a2SKevin Coffman #include <linux/sunrpc/gss_api.h> 17b084f598SJ. Bruce Fields #include <linux/sunrpc/gss_krb5_enctypes.h> 18813fd320SJeff Layton #include <linux/sunrpc/rpc_pipe_fs.h> 19143cb494SPaul Gortmaker #include <linux/module.h> 20e8a79fb1SJ. Bruce Fields #include <linux/fsnotify.h> 211da177e4SLinus Torvalds 222ca72e17SJ. Bruce Fields #include "idmap.h" 239a74af21SBoaz Harrosh #include "nfsd.h" 249a74af21SBoaz Harrosh #include "cache.h" 25f3c7521fSBryan Schumaker #include "state.h" 267ea34ac1SJeff Layton #include "netns.h" 279cf514ccSChristoph Hellwig #include "pnfs.h" 289a74af21SBoaz Harrosh 291da177e4SLinus Torvalds /* 30b0b0c0a2SKevin Coffman * We have a single directory with several nodes in it. 311da177e4SLinus Torvalds */ 321da177e4SLinus Torvalds enum { 331da177e4SLinus Torvalds NFSD_Root = 1, 341da177e4SLinus Torvalds NFSD_List, 3520ad856eSAmir Goldstein NFSD_Export_Stats, 36e8e8753fSJ. Bruce Fields NFSD_Export_features, 371da177e4SLinus Torvalds NFSD_Fh, 384373ea84SWendy Cheng NFSD_FO_UnlockIP, 3917efa372SWendy Cheng NFSD_FO_UnlockFS, 401da177e4SLinus Torvalds NFSD_Threads, 41eed2965aSGreg Banks NFSD_Pool_Threads, 4203cf6c9fSGreg Banks NFSD_Pool_Stats, 43a2f999a3SJeff Layton NFSD_Reply_Cache_Stats, 4470c3b76cSNeilBrown NFSD_Versions, 4580212d59SNeilBrown NFSD_Ports, 46596bbe53SNeilBrown NFSD_MaxBlkSize, 475b8db00bSJeff Layton NFSD_MaxConnections, 48b0b0c0a2SKevin Coffman NFSD_SupportedEnctypes, 4970c3b76cSNeilBrown /* 5070c3b76cSNeilBrown * The below MUST come last. Otherwise we leave a hole in nfsd_files[] 5170c3b76cSNeilBrown * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops 5270c3b76cSNeilBrown */ 5370c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 541da177e4SLinus Torvalds NFSD_Leasetime, 55efc4bb4fSJ. Bruce Fields NFSD_Gracetime, 560964a3d3SNeilBrown NFSD_RecoveryDir, 577f5ef2e9SJeff Layton NFSD_V4EndGrace, 5870c3b76cSNeilBrown #endif 59e8a79fb1SJ. Bruce Fields NFSD_MaxReserved 601da177e4SLinus Torvalds }; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds /* 631da177e4SLinus Torvalds * write() for these nodes. 641da177e4SLinus Torvalds */ 651da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size); 66b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); 67b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); 681da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size); 69eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); 7070c3b76cSNeilBrown static ssize_t write_versions(struct file *file, char *buf, size_t size); 7180212d59SNeilBrown static ssize_t write_ports(struct file *file, char *buf, size_t size); 72596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); 735b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size); 7470c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 751da177e4SLinus Torvalds static ssize_t write_leasetime(struct file *file, char *buf, size_t size); 76efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size); 770964a3d3SNeilBrown static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); 787f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size); 7970c3b76cSNeilBrown #endif 801da177e4SLinus Torvalds 81c2cdc2abSEric Biggers static ssize_t (*const write_op[])(struct file *, char *, size_t) = { 821da177e4SLinus Torvalds [NFSD_Fh] = write_filehandle, 83b046ccdcSChuck Lever [NFSD_FO_UnlockIP] = write_unlock_ip, 84b046ccdcSChuck Lever [NFSD_FO_UnlockFS] = write_unlock_fs, 851da177e4SLinus Torvalds [NFSD_Threads] = write_threads, 86eed2965aSGreg Banks [NFSD_Pool_Threads] = write_pool_threads, 8770c3b76cSNeilBrown [NFSD_Versions] = write_versions, 8880212d59SNeilBrown [NFSD_Ports] = write_ports, 89596bbe53SNeilBrown [NFSD_MaxBlkSize] = write_maxblksize, 905b8db00bSJeff Layton [NFSD_MaxConnections] = write_maxconn, 9170c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 921da177e4SLinus Torvalds [NFSD_Leasetime] = write_leasetime, 93efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = write_gracetime, 940964a3d3SNeilBrown [NFSD_RecoveryDir] = write_recoverydir, 957f5ef2e9SJeff Layton [NFSD_V4EndGrace] = write_v4_end_grace, 9670c3b76cSNeilBrown #endif 971da177e4SLinus Torvalds }; 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 1001da177e4SLinus Torvalds { 101496ad9aaSAl Viro ino_t ino = file_inode(file)->i_ino; 1021da177e4SLinus Torvalds char *data; 1031da177e4SLinus Torvalds ssize_t rv; 1041da177e4SLinus Torvalds 105e8c96f8cSTobias Klauser if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) 1061da177e4SLinus Torvalds return -EINVAL; 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds data = simple_transaction_get(file, buf, size); 1091da177e4SLinus Torvalds if (IS_ERR(data)) 1101da177e4SLinus Torvalds return PTR_ERR(data); 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds rv = write_op[ino](file, data, size); 1138971a101SNeilBrown if (rv >= 0) { 1141da177e4SLinus Torvalds simple_transaction_set(file, rv); 1151da177e4SLinus Torvalds rv = size; 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds return rv; 1181da177e4SLinus Torvalds } 1191da177e4SLinus Torvalds 1207390022dSNeilBrown static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) 1217390022dSNeilBrown { 1227390022dSNeilBrown if (! file->private_data) { 1237390022dSNeilBrown /* An attempt to read a transaction file without writing 1247390022dSNeilBrown * causes a 0-byte write so that the file can return 1257390022dSNeilBrown * state information 1267390022dSNeilBrown */ 1277390022dSNeilBrown ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); 1287390022dSNeilBrown if (rv < 0) 1297390022dSNeilBrown return rv; 1307390022dSNeilBrown } 1317390022dSNeilBrown return simple_transaction_read(file, buf, size, pos); 1327390022dSNeilBrown } 1337390022dSNeilBrown 1344b6f5d20SArjan van de Ven static const struct file_operations transaction_ops = { 1351da177e4SLinus Torvalds .write = nfsctl_transaction_write, 1367390022dSNeilBrown .read = nfsctl_transaction_read, 1371da177e4SLinus Torvalds .release = simple_transaction_release, 1386038f373SArnd Bergmann .llseek = default_llseek, 1391da177e4SLinus Torvalds }; 1401da177e4SLinus Torvalds 14196d851c4SStanislav Kinsbursky static int exports_net_open(struct net *net, struct file *file) 1421da177e4SLinus Torvalds { 143f2c7ea10SStanislav Kinsbursky int err; 144f2c7ea10SStanislav Kinsbursky struct seq_file *seq; 14596d851c4SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 146f2c7ea10SStanislav Kinsbursky 147f2c7ea10SStanislav Kinsbursky err = seq_open(file, &nfs_exports_op); 148f2c7ea10SStanislav Kinsbursky if (err) 149f2c7ea10SStanislav Kinsbursky return err; 150f2c7ea10SStanislav Kinsbursky 151f2c7ea10SStanislav Kinsbursky seq = file->private_data; 152e5f06f72SStanislav Kinsbursky seq->private = nn->svc_export_cache; 153f2c7ea10SStanislav Kinsbursky return 0; 1541da177e4SLinus Torvalds } 1551da177e4SLinus Torvalds 15696d851c4SStanislav Kinsbursky static int exports_proc_open(struct inode *inode, struct file *file) 15796d851c4SStanislav Kinsbursky { 15896d851c4SStanislav Kinsbursky return exports_net_open(current->nsproxy->net_ns, file); 15996d851c4SStanislav Kinsbursky } 16096d851c4SStanislav Kinsbursky 16197a32539SAlexey Dobriyan static const struct proc_ops exports_proc_ops = { 16297a32539SAlexey Dobriyan .proc_open = exports_proc_open, 16397a32539SAlexey Dobriyan .proc_read = seq_read, 16497a32539SAlexey Dobriyan .proc_lseek = seq_lseek, 16597a32539SAlexey Dobriyan .proc_release = seq_release, 16696d851c4SStanislav Kinsbursky }; 16796d851c4SStanislav Kinsbursky 16896d851c4SStanislav Kinsbursky static int exports_nfsd_open(struct inode *inode, struct file *file) 16996d851c4SStanislav Kinsbursky { 17096d851c4SStanislav Kinsbursky return exports_net_open(inode->i_sb->s_fs_info, file); 17196d851c4SStanislav Kinsbursky } 17296d851c4SStanislav Kinsbursky 17396d851c4SStanislav Kinsbursky static const struct file_operations exports_nfsd_operations = { 17496d851c4SStanislav Kinsbursky .open = exports_nfsd_open, 1751da177e4SLinus Torvalds .read = seq_read, 1761da177e4SLinus Torvalds .llseek = seq_lseek, 1771da177e4SLinus Torvalds .release = seq_release, 1781da177e4SLinus Torvalds }; 1791da177e4SLinus Torvalds 180e8e8753fSJ. Bruce Fields static int export_features_show(struct seq_file *m, void *v) 181e8e8753fSJ. Bruce Fields { 182e8e8753fSJ. Bruce Fields seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); 183e8e8753fSJ. Bruce Fields return 0; 184e8e8753fSJ. Bruce Fields } 185e8e8753fSJ. Bruce Fields 186e8e8753fSJ. Bruce Fields static int export_features_open(struct inode *inode, struct file *file) 187e8e8753fSJ. Bruce Fields { 188e8e8753fSJ. Bruce Fields return single_open(file, export_features_show, NULL); 189e8e8753fSJ. Bruce Fields } 190e8e8753fSJ. Bruce Fields 19175ef9de1SAl Viro static const struct file_operations export_features_operations = { 192e8e8753fSJ. Bruce Fields .open = export_features_open, 193e8e8753fSJ. Bruce Fields .read = seq_read, 194e8e8753fSJ. Bruce Fields .llseek = seq_lseek, 195e8e8753fSJ. Bruce Fields .release = single_release, 196e8e8753fSJ. Bruce Fields }; 197e8e8753fSJ. Bruce Fields 198b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 199b0b0c0a2SKevin Coffman static int supported_enctypes_show(struct seq_file *m, void *v) 200b0b0c0a2SKevin Coffman { 201b084f598SJ. Bruce Fields seq_printf(m, KRB5_SUPPORTED_ENCTYPES); 202b0b0c0a2SKevin Coffman return 0; 203b0b0c0a2SKevin Coffman } 204b0b0c0a2SKevin Coffman 205b0b0c0a2SKevin Coffman static int supported_enctypes_open(struct inode *inode, struct file *file) 206b0b0c0a2SKevin Coffman { 207b0b0c0a2SKevin Coffman return single_open(file, supported_enctypes_show, NULL); 208b0b0c0a2SKevin Coffman } 209b0b0c0a2SKevin Coffman 21075ef9de1SAl Viro static const struct file_operations supported_enctypes_ops = { 211b0b0c0a2SKevin Coffman .open = supported_enctypes_open, 212b0b0c0a2SKevin Coffman .read = seq_read, 213b0b0c0a2SKevin Coffman .llseek = seq_lseek, 214b0b0c0a2SKevin Coffman .release = single_release, 215b0b0c0a2SKevin Coffman }; 216b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 217b0b0c0a2SKevin Coffman 218828c0950SAlexey Dobriyan static const struct file_operations pool_stats_operations = { 21903cf6c9fSGreg Banks .open = nfsd_pool_stats_open, 22003cf6c9fSGreg Banks .read = seq_read, 22103cf6c9fSGreg Banks .llseek = seq_lseek, 222ed2d8aedSRyusei Yamaguchi .release = nfsd_pool_stats_release, 22303cf6c9fSGreg Banks }; 22403cf6c9fSGreg Banks 2257ba630f5SJulia Lawall static const struct file_operations reply_cache_stats_operations = { 226a2f999a3SJeff Layton .open = nfsd_reply_cache_stats_open, 227a2f999a3SJeff Layton .read = seq_read, 228a2f999a3SJeff Layton .llseek = seq_lseek, 229a2f999a3SJeff Layton .release = single_release, 230a2f999a3SJeff Layton }; 231a2f999a3SJeff Layton 2321da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 2331da177e4SLinus Torvalds /* 2341da177e4SLinus Torvalds * payload - write methods 2351da177e4SLinus Torvalds */ 2361da177e4SLinus Torvalds 237244c7d44SAl Viro static inline struct net *netns(struct file *file) 238244c7d44SAl Viro { 239244c7d44SAl Viro return file_inode(file)->i_sb->s_fs_info; 240244c7d44SAl Viro } 2411da177e4SLinus Torvalds 242f2453978SChuck Lever /* 243262a0982SChuck Lever * write_unlock_ip - Release all locks used by a client 244262a0982SChuck Lever * 245262a0982SChuck Lever * Experimental. 246262a0982SChuck Lever * 247262a0982SChuck Lever * Input: 248262a0982SChuck Lever * buf: '\n'-terminated C string containing a 2494116092bSChuck Lever * presentation format IP address 250262a0982SChuck Lever * size: length of C string in @buf 251262a0982SChuck Lever * Output: 252262a0982SChuck Lever * On success: returns zero if all specified locks were released; 253262a0982SChuck Lever * returns one if one or more locks were not released 254262a0982SChuck Lever * On error: return code is negative errno value 255262a0982SChuck Lever */ 256b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) 2574373ea84SWendy Cheng { 2584116092bSChuck Lever struct sockaddr_storage address; 2594116092bSChuck Lever struct sockaddr *sap = (struct sockaddr *)&address; 2604116092bSChuck Lever size_t salen = sizeof(address); 261367c8c7bSChuck Lever char *fo_path; 262244c7d44SAl Viro struct net *net = netns(file); 2634373ea84SWendy Cheng 2644373ea84SWendy Cheng /* sanity check */ 2654373ea84SWendy Cheng if (size == 0) 2664373ea84SWendy Cheng return -EINVAL; 2674373ea84SWendy Cheng 2684373ea84SWendy Cheng if (buf[size-1] != '\n') 2694373ea84SWendy Cheng return -EINVAL; 2704373ea84SWendy Cheng 2714373ea84SWendy Cheng fo_path = buf; 2724373ea84SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 2734373ea84SWendy Cheng return -EINVAL; 2744373ea84SWendy Cheng 27511f77942SStanislav Kinsbursky if (rpc_pton(net, fo_path, size, sap, salen) == 0) 2764373ea84SWendy Cheng return -EINVAL; 2774373ea84SWendy Cheng 2784116092bSChuck Lever return nlmsvc_unlock_all_by_ip(sap); 2794373ea84SWendy Cheng } 2804373ea84SWendy Cheng 281f2453978SChuck Lever /* 282262a0982SChuck Lever * write_unlock_fs - Release all locks on a local file system 283262a0982SChuck Lever * 284262a0982SChuck Lever * Experimental. 285262a0982SChuck Lever * 286262a0982SChuck Lever * Input: 287262a0982SChuck Lever * buf: '\n'-terminated C string containing the 288262a0982SChuck Lever * absolute pathname of a local file system 289262a0982SChuck Lever * size: length of C string in @buf 290262a0982SChuck Lever * Output: 291262a0982SChuck Lever * On success: returns zero if all specified locks were released; 292262a0982SChuck Lever * returns one if one or more locks were not released 293262a0982SChuck Lever * On error: return code is negative errno value 294262a0982SChuck Lever */ 295b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) 29617efa372SWendy Cheng { 297a63bb996SAl Viro struct path path; 29817efa372SWendy Cheng char *fo_path; 29917efa372SWendy Cheng int error; 30017efa372SWendy Cheng 30117efa372SWendy Cheng /* sanity check */ 30217efa372SWendy Cheng if (size == 0) 30317efa372SWendy Cheng return -EINVAL; 30417efa372SWendy Cheng 30517efa372SWendy Cheng if (buf[size-1] != '\n') 30617efa372SWendy Cheng return -EINVAL; 30717efa372SWendy Cheng 30817efa372SWendy Cheng fo_path = buf; 30917efa372SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 31017efa372SWendy Cheng return -EINVAL; 31117efa372SWendy Cheng 312a63bb996SAl Viro error = kern_path(fo_path, 0, &path); 31317efa372SWendy Cheng if (error) 31417efa372SWendy Cheng return error; 31517efa372SWendy Cheng 316262a0982SChuck Lever /* 317262a0982SChuck Lever * XXX: Needs better sanity checking. Otherwise we could end up 318262a0982SChuck Lever * releasing locks on the wrong file system. 319262a0982SChuck Lever * 320262a0982SChuck Lever * For example: 321262a0982SChuck Lever * 1. Does the path refer to a directory? 322262a0982SChuck Lever * 2. Is that directory a mount point, or 323262a0982SChuck Lever * 3. Is that directory the root of an exported file system? 324262a0982SChuck Lever */ 325d8c9584eSAl Viro error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb); 32617efa372SWendy Cheng 327a63bb996SAl Viro path_put(&path); 32817efa372SWendy Cheng return error; 32917efa372SWendy Cheng } 33017efa372SWendy Cheng 331f2453978SChuck Lever /* 332262a0982SChuck Lever * write_filehandle - Get a variable-length NFS file handle by path 333262a0982SChuck Lever * 334262a0982SChuck Lever * On input, the buffer contains a '\n'-terminated C string comprised of 335262a0982SChuck Lever * three alphanumeric words separated by whitespace. The string may 336262a0982SChuck Lever * contain escape sequences. 337262a0982SChuck Lever * 338262a0982SChuck Lever * Input: 339262a0982SChuck Lever * buf: 340262a0982SChuck Lever * domain: client domain name 341262a0982SChuck Lever * path: export pathname 342262a0982SChuck Lever * maxsize: numeric maximum size of 343262a0982SChuck Lever * @buf 344262a0982SChuck Lever * size: length of C string in @buf 345262a0982SChuck Lever * Output: 346262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 347262a0982SChuck Lever * string containing a ASCII hex text version 348262a0982SChuck Lever * of the NFS file handle; 349262a0982SChuck Lever * return code is the size in bytes of the string 350262a0982SChuck Lever * On error: return code is negative errno value 351262a0982SChuck Lever */ 3521da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size) 3531da177e4SLinus Torvalds { 3541da177e4SLinus Torvalds char *dname, *path; 3553f649ab7SKees Cook int maxsize; 3561da177e4SLinus Torvalds char *mesg = buf; 3571da177e4SLinus Torvalds int len; 3581da177e4SLinus Torvalds struct auth_domain *dom; 3591da177e4SLinus Torvalds struct knfsd_fh fh; 3601da177e4SLinus Torvalds 36187d26ea7SJ. Bruce Fields if (size == 0) 36287d26ea7SJ. Bruce Fields return -EINVAL; 36387d26ea7SJ. Bruce Fields 3641da177e4SLinus Torvalds if (buf[size-1] != '\n') 3651da177e4SLinus Torvalds return -EINVAL; 3661da177e4SLinus Torvalds buf[size-1] = 0; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds dname = mesg; 3691da177e4SLinus Torvalds len = qword_get(&mesg, dname, size); 37054224f04SChuck Lever if (len <= 0) 37154224f04SChuck Lever return -EINVAL; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds path = dname+len+1; 3741da177e4SLinus Torvalds len = qword_get(&mesg, path, size); 37554224f04SChuck Lever if (len <= 0) 37654224f04SChuck Lever return -EINVAL; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds len = get_int(&mesg, &maxsize); 3791da177e4SLinus Torvalds if (len) 3801da177e4SLinus Torvalds return len; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds if (maxsize < NFS_FHSIZE) 3831da177e4SLinus Torvalds return -EINVAL; 3843c7aa15dSKinglong Mee maxsize = min(maxsize, NFS3_FHSIZE); 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds if (qword_get(&mesg, mesg, size)>0) 3871da177e4SLinus Torvalds return -EINVAL; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds /* we have all the words, they are in buf.. */ 3901da177e4SLinus Torvalds dom = unix_domain_find(dname); 3911da177e4SLinus Torvalds if (!dom) 3921da177e4SLinus Torvalds return -ENOMEM; 3931da177e4SLinus Torvalds 394244c7d44SAl Viro len = exp_rootfh(netns(file), dom, path, &fh, maxsize); 3951da177e4SLinus Torvalds auth_domain_put(dom); 3961da177e4SLinus Torvalds if (len) 3971da177e4SLinus Torvalds return len; 3981da177e4SLinus Torvalds 39954224f04SChuck Lever mesg = buf; 40054224f04SChuck Lever len = SIMPLE_TRANSACTION_LIMIT; 4011da177e4SLinus Torvalds qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); 4021da177e4SLinus Torvalds mesg[-1] = '\n'; 4031da177e4SLinus Torvalds return mesg - buf; 4041da177e4SLinus Torvalds } 4051da177e4SLinus Torvalds 406f2453978SChuck Lever /* 407262a0982SChuck Lever * write_threads - Start NFSD, or report the current number of running threads 408262a0982SChuck Lever * 409262a0982SChuck Lever * Input: 410262a0982SChuck Lever * buf: ignored 411262a0982SChuck Lever * size: zero 412262a0982SChuck Lever * Output: 413262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 414262a0982SChuck Lever * string numeric value representing the number of 415262a0982SChuck Lever * running NFSD threads; 416262a0982SChuck Lever * return code is the size in bytes of the string 417262a0982SChuck Lever * On error: return code is zero 418262a0982SChuck Lever * 419262a0982SChuck Lever * OR 420262a0982SChuck Lever * 421262a0982SChuck Lever * Input: 422262a0982SChuck Lever * buf: C string containing an unsigned 423262a0982SChuck Lever * integer value representing the 424262a0982SChuck Lever * number of NFSD threads to start 425262a0982SChuck Lever * size: non-zero length of C string in @buf 426262a0982SChuck Lever * Output: 427262a0982SChuck Lever * On success: NFS service is started; 428262a0982SChuck Lever * passed-in buffer filled with '\n'-terminated C 429262a0982SChuck Lever * string numeric value representing the number of 430262a0982SChuck Lever * running NFSD threads; 431262a0982SChuck Lever * return code is the size in bytes of the string 432262a0982SChuck Lever * On error: return code is zero or a negative errno value 433262a0982SChuck Lever */ 4341da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size) 4351da177e4SLinus Torvalds { 4361da177e4SLinus Torvalds char *mesg = buf; 4371da177e4SLinus Torvalds int rv; 438244c7d44SAl Viro struct net *net = netns(file); 439d41a9417SStanislav Kinsbursky 4401da177e4SLinus Torvalds if (size > 0) { 4411da177e4SLinus Torvalds int newthreads; 4421da177e4SLinus Torvalds rv = get_int(&mesg, &newthreads); 4431da177e4SLinus Torvalds if (rv) 4441da177e4SLinus Torvalds return rv; 4451da177e4SLinus Torvalds if (newthreads < 0) 4461da177e4SLinus Torvalds return -EINVAL; 4474df493a2STrond Myklebust rv = nfsd_svc(newthreads, net, file->f_cred); 44882e12fe9SNeilBrown if (rv < 0) 4491da177e4SLinus Torvalds return rv; 45082e12fe9SNeilBrown } else 4519dd9845fSStanislav Kinsbursky rv = nfsd_nrthreads(net); 452e06b6405SChuck Lever 45382e12fe9SNeilBrown return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); 4541da177e4SLinus Torvalds } 4551da177e4SLinus Torvalds 456f2453978SChuck Lever /* 457262a0982SChuck Lever * write_pool_threads - Set or report the current number of threads per pool 458262a0982SChuck Lever * 459262a0982SChuck Lever * Input: 460262a0982SChuck Lever * buf: ignored 461262a0982SChuck Lever * size: zero 462262a0982SChuck Lever * 463262a0982SChuck Lever * OR 464262a0982SChuck Lever * 465262a0982SChuck Lever * Input: 466262a0982SChuck Lever * buf: C string containing whitespace- 467262a0982SChuck Lever * separated unsigned integer values 468262a0982SChuck Lever * representing the number of NFSD 469262a0982SChuck Lever * threads to start in each pool 470262a0982SChuck Lever * size: non-zero length of C string in @buf 471262a0982SChuck Lever * Output: 472262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 473262a0982SChuck Lever * string containing integer values representing the 474262a0982SChuck Lever * number of NFSD threads in each pool; 475262a0982SChuck Lever * return code is the size in bytes of the string 476262a0982SChuck Lever * On error: return code is zero or a negative errno value 477262a0982SChuck Lever */ 478eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) 479eed2965aSGreg Banks { 480eed2965aSGreg Banks /* if size > 0, look for an array of number of threads per node 481eed2965aSGreg Banks * and apply them then write out number of threads per node as reply 482eed2965aSGreg Banks */ 483eed2965aSGreg Banks char *mesg = buf; 484eed2965aSGreg Banks int i; 485eed2965aSGreg Banks int rv; 486eed2965aSGreg Banks int len; 487bedbdd8bSNeil Brown int npools; 488eed2965aSGreg Banks int *nthreads; 489244c7d44SAl Viro struct net *net = netns(file); 490eed2965aSGreg Banks 491bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 4929dd9845fSStanislav Kinsbursky npools = nfsd_nrpools(net); 493eed2965aSGreg Banks if (npools == 0) { 494eed2965aSGreg Banks /* 495eed2965aSGreg Banks * NFS is shut down. The admin can start it by 496eed2965aSGreg Banks * writing to the threads file but NOT the pool_threads 497eed2965aSGreg Banks * file, sorry. Report zero threads. 498eed2965aSGreg Banks */ 499bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 500eed2965aSGreg Banks strcpy(buf, "0\n"); 501eed2965aSGreg Banks return strlen(buf); 502eed2965aSGreg Banks } 503eed2965aSGreg Banks 504eed2965aSGreg Banks nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); 505bedbdd8bSNeil Brown rv = -ENOMEM; 506eed2965aSGreg Banks if (nthreads == NULL) 507bedbdd8bSNeil Brown goto out_free; 508eed2965aSGreg Banks 509eed2965aSGreg Banks if (size > 0) { 510eed2965aSGreg Banks for (i = 0; i < npools; i++) { 511eed2965aSGreg Banks rv = get_int(&mesg, &nthreads[i]); 512eed2965aSGreg Banks if (rv == -ENOENT) 513eed2965aSGreg Banks break; /* fewer numbers than pools */ 514eed2965aSGreg Banks if (rv) 515eed2965aSGreg Banks goto out_free; /* syntax error */ 516eed2965aSGreg Banks rv = -EINVAL; 517eed2965aSGreg Banks if (nthreads[i] < 0) 518eed2965aSGreg Banks goto out_free; 519eed2965aSGreg Banks } 5203938a0d5SStanislav Kinsbursky rv = nfsd_set_nrthreads(i, nthreads, net); 521eed2965aSGreg Banks if (rv) 522eed2965aSGreg Banks goto out_free; 523eed2965aSGreg Banks } 524eed2965aSGreg Banks 5259dd9845fSStanislav Kinsbursky rv = nfsd_get_nrthreads(npools, nthreads, net); 526eed2965aSGreg Banks if (rv) 527eed2965aSGreg Banks goto out_free; 528eed2965aSGreg Banks 529eed2965aSGreg Banks mesg = buf; 530eed2965aSGreg Banks size = SIMPLE_TRANSACTION_LIMIT; 531eed2965aSGreg Banks for (i = 0; i < npools && size > 0; i++) { 532eed2965aSGreg Banks snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); 533eed2965aSGreg Banks len = strlen(mesg); 534eed2965aSGreg Banks size -= len; 535eed2965aSGreg Banks mesg += len; 536eed2965aSGreg Banks } 537413d63d7SJ. Bruce Fields rv = mesg - buf; 538eed2965aSGreg Banks out_free: 539eed2965aSGreg Banks kfree(nthreads); 540bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 541eed2965aSGreg Banks return rv; 542eed2965aSGreg Banks } 543eed2965aSGreg Banks 544ff7d1179STrond Myklebust static ssize_t 545e333f3bbSTrond Myklebust nfsd_print_version_support(struct nfsd_net *nn, char *buf, int remaining, 546e333f3bbSTrond Myklebust const char *sep, unsigned vers, int minor) 547ff7d1179STrond Myklebust { 548abcb4dacSNeilBrown const char *format = minor < 0 ? "%s%c%u" : "%s%c%u.%u"; 549e333f3bbSTrond Myklebust bool supported = !!nfsd_vers(nn, vers, NFSD_TEST); 550ff7d1179STrond Myklebust 551abcb4dacSNeilBrown if (vers == 4 && minor >= 0 && 552e333f3bbSTrond Myklebust !nfsd_minorversion(nn, minor, NFSD_TEST)) 553ff7d1179STrond Myklebust supported = false; 554abcb4dacSNeilBrown if (minor == 0 && supported) 555abcb4dacSNeilBrown /* 556abcb4dacSNeilBrown * special case for backward compatability. 557abcb4dacSNeilBrown * +4.0 is never reported, it is implied by 558abcb4dacSNeilBrown * +4, unless -4.0 is present. 559abcb4dacSNeilBrown */ 560abcb4dacSNeilBrown return 0; 561ff7d1179STrond Myklebust return snprintf(buf, remaining, format, sep, 562ff7d1179STrond Myklebust supported ? '+' : '-', vers, minor); 563ff7d1179STrond Myklebust } 564ff7d1179STrond Myklebust 5653dd98a3bSJeff Layton static ssize_t __write_versions(struct file *file, char *buf, size_t size) 56670c3b76cSNeilBrown { 56770c3b76cSNeilBrown char *mesg = buf; 5688daf220aSBenny Halevy char *vers, *minorp, sign; 569261758b5SChuck Lever int len, num, remaining; 57070c3b76cSNeilBrown ssize_t tlen = 0; 57170c3b76cSNeilBrown char *sep; 572244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 57370c3b76cSNeilBrown 57470c3b76cSNeilBrown if (size>0) { 5759dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 5766658d3a7SNeilBrown /* Cannot change versions without updating 5779dd9845fSStanislav Kinsbursky * nn->nfsd_serv->sv_xdrsize, and reallocing 5786658d3a7SNeilBrown * rq_argp and rq_resp 5796658d3a7SNeilBrown */ 58070c3b76cSNeilBrown return -EBUSY; 58170c3b76cSNeilBrown if (buf[size-1] != '\n') 58270c3b76cSNeilBrown return -EINVAL; 58370c3b76cSNeilBrown buf[size-1] = 0; 58470c3b76cSNeilBrown 58570c3b76cSNeilBrown vers = mesg; 58670c3b76cSNeilBrown len = qword_get(&mesg, vers, size); 58770c3b76cSNeilBrown if (len <= 0) return -EINVAL; 58870c3b76cSNeilBrown do { 589d3635ff0STrond Myklebust enum vers_op cmd; 590abcb4dacSNeilBrown unsigned minor; 59170c3b76cSNeilBrown sign = *vers; 59270c3b76cSNeilBrown if (sign == '+' || sign == '-') 5938daf220aSBenny Halevy num = simple_strtol((vers+1), &minorp, 0); 59470c3b76cSNeilBrown else 5958daf220aSBenny Halevy num = simple_strtol(vers, &minorp, 0); 5968daf220aSBenny Halevy if (*minorp == '.') { 597ff89be87SJ. Bruce Fields if (num != 4) 5988daf220aSBenny Halevy return -EINVAL; 599e35659f1SNeilBrown if (kstrtouint(minorp+1, 0, &minor) < 0) 6008daf220aSBenny Halevy return -EINVAL; 601abcb4dacSNeilBrown } 602abcb4dacSNeilBrown 603d3635ff0STrond Myklebust cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET; 60470c3b76cSNeilBrown switch(num) { 60570c3b76cSNeilBrown case 2: 60670c3b76cSNeilBrown case 3: 607e333f3bbSTrond Myklebust nfsd_vers(nn, num, cmd); 608d3635ff0STrond Myklebust break; 60970c3b76cSNeilBrown case 4: 610abcb4dacSNeilBrown if (*minorp == '.') { 611e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, minor, cmd) < 0) 612abcb4dacSNeilBrown return -EINVAL; 613e333f3bbSTrond Myklebust } else if ((cmd == NFSD_SET) != nfsd_vers(nn, num, NFSD_TEST)) { 614abcb4dacSNeilBrown /* 615abcb4dacSNeilBrown * Either we have +4 and no minors are enabled, 616abcb4dacSNeilBrown * or we have -4 and at least one minor is enabled. 617abcb4dacSNeilBrown * In either case, propagate 'cmd' to all minors. 618abcb4dacSNeilBrown */ 619abcb4dacSNeilBrown minor = 0; 620e333f3bbSTrond Myklebust while (nfsd_minorversion(nn, minor, cmd) >= 0) 621abcb4dacSNeilBrown minor++; 622abcb4dacSNeilBrown } 62370c3b76cSNeilBrown break; 62470c3b76cSNeilBrown default: 62570c3b76cSNeilBrown return -EINVAL; 62670c3b76cSNeilBrown } 62770c3b76cSNeilBrown vers += len + 1; 62870c3b76cSNeilBrown } while ((len = qword_get(&mesg, vers, size)) > 0); 62970c3b76cSNeilBrown /* If all get turned off, turn them back on, as 63070c3b76cSNeilBrown * having no versions is BAD 63170c3b76cSNeilBrown */ 632e333f3bbSTrond Myklebust nfsd_reset_versions(nn); 63370c3b76cSNeilBrown } 634261758b5SChuck Lever 63570c3b76cSNeilBrown /* Now write current state into reply buffer */ 63670c3b76cSNeilBrown len = 0; 63770c3b76cSNeilBrown sep = ""; 638261758b5SChuck Lever remaining = SIMPLE_TRANSACTION_LIMIT; 639ff7d1179STrond Myklebust for (num=2 ; num <= 4 ; num++) { 640abcb4dacSNeilBrown int minor; 641e333f3bbSTrond Myklebust if (!nfsd_vers(nn, num, NFSD_AVAIL)) 642e35659f1SNeilBrown continue; 643abcb4dacSNeilBrown 644abcb4dacSNeilBrown minor = -1; 645ff7d1179STrond Myklebust do { 646e333f3bbSTrond Myklebust len = nfsd_print_version_support(nn, buf, remaining, 647ff7d1179STrond Myklebust sep, num, minor); 648818f2f57SDan Carpenter if (len >= remaining) 649ff7d1179STrond Myklebust goto out; 650261758b5SChuck Lever remaining -= len; 651261758b5SChuck Lever buf += len; 652261758b5SChuck Lever tlen += len; 653ff7d1179STrond Myklebust minor++; 654abcb4dacSNeilBrown if (len) 655ff7d1179STrond Myklebust sep = " "; 656ff7d1179STrond Myklebust } while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION); 657261758b5SChuck Lever } 658ff7d1179STrond Myklebust out: 659261758b5SChuck Lever len = snprintf(buf, remaining, "\n"); 660818f2f57SDan Carpenter if (len >= remaining) 661261758b5SChuck Lever return -EINVAL; 662261758b5SChuck Lever return tlen + len; 66370c3b76cSNeilBrown } 66470c3b76cSNeilBrown 665f2453978SChuck Lever /* 666262a0982SChuck Lever * write_versions - Set or report the available NFS protocol versions 667262a0982SChuck Lever * 668262a0982SChuck Lever * Input: 669262a0982SChuck Lever * buf: ignored 670262a0982SChuck Lever * size: zero 671262a0982SChuck Lever * Output: 672262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 673262a0982SChuck Lever * string containing positive or negative integer 674262a0982SChuck Lever * values representing the current status of each 675262a0982SChuck Lever * protocol version; 676262a0982SChuck Lever * return code is the size in bytes of the string 677262a0982SChuck Lever * On error: return code is zero or a negative errno value 678262a0982SChuck Lever * 679262a0982SChuck Lever * OR 680262a0982SChuck Lever * 681262a0982SChuck Lever * Input: 682262a0982SChuck Lever * buf: C string containing whitespace- 683262a0982SChuck Lever * separated positive or negative 684262a0982SChuck Lever * integer values representing NFS 685262a0982SChuck Lever * protocol versions to enable ("+n") 686262a0982SChuck Lever * or disable ("-n") 687262a0982SChuck Lever * size: non-zero length of C string in @buf 688262a0982SChuck Lever * Output: 689262a0982SChuck Lever * On success: status of zero or more protocol versions has 690262a0982SChuck Lever * been updated; passed-in buffer filled with 691262a0982SChuck Lever * '\n'-terminated C string containing positive 692262a0982SChuck Lever * or negative integer values representing the 693262a0982SChuck Lever * current status of each protocol version; 694262a0982SChuck Lever * return code is the size in bytes of the string 695262a0982SChuck Lever * On error: return code is zero or a negative errno value 696262a0982SChuck Lever */ 6973dd98a3bSJeff Layton static ssize_t write_versions(struct file *file, char *buf, size_t size) 6983dd98a3bSJeff Layton { 6993dd98a3bSJeff Layton ssize_t rv; 7003dd98a3bSJeff Layton 7013dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 7023dd98a3bSJeff Layton rv = __write_versions(file, buf, size); 7033dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 7043dd98a3bSJeff Layton return rv; 7053dd98a3bSJeff Layton } 7063dd98a3bSJeff Layton 7074cd5dc75SChuck Lever /* 7080a5372d8SChuck Lever * Zero-length write. Return a list of NFSD's current listener 7090a5372d8SChuck Lever * transports. 7100a5372d8SChuck Lever */ 7119dd9845fSStanislav Kinsbursky static ssize_t __write_ports_names(char *buf, struct net *net) 7120a5372d8SChuck Lever { 7139dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7149dd9845fSStanislav Kinsbursky 7159dd9845fSStanislav Kinsbursky if (nn->nfsd_serv == NULL) 7160a5372d8SChuck Lever return 0; 7179dd9845fSStanislav Kinsbursky return svc_xprt_names(nn->nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); 7180a5372d8SChuck Lever } 7190a5372d8SChuck Lever 7200a5372d8SChuck Lever /* 7210b7c2f6fSChuck Lever * A single 'fd' number was written, in which case it must be for 7220b7c2f6fSChuck Lever * a socket of a supported family/protocol, and we use it as an 7230b7c2f6fSChuck Lever * nfsd listener. 7240b7c2f6fSChuck Lever */ 7254df493a2STrond Myklebust static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred *cred) 7260b7c2f6fSChuck Lever { 7270b7c2f6fSChuck Lever char *mesg = buf; 7280b7c2f6fSChuck Lever int fd, err; 7299dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7300b7c2f6fSChuck Lever 7310b7c2f6fSChuck Lever err = get_int(&mesg, &fd); 7320b7c2f6fSChuck Lever if (err != 0 || fd < 0) 7330b7c2f6fSChuck Lever return -EINVAL; 7340b7c2f6fSChuck Lever 73530646394SStanislav Kinsbursky if (svc_alien_sock(net, fd)) { 73630646394SStanislav Kinsbursky printk(KERN_ERR "%s: socket net is different to NFSd's one\n", __func__); 73730646394SStanislav Kinsbursky return -EINVAL; 73830646394SStanislav Kinsbursky } 73930646394SStanislav Kinsbursky 7406777436bSStanislav Kinsbursky err = nfsd_create_serv(net); 7410b7c2f6fSChuck Lever if (err != 0) 7420b7c2f6fSChuck Lever return err; 7430b7c2f6fSChuck Lever 7444df493a2STrond Myklebust err = svc_addsock(nn->nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred); 74578a8d7c8SJeff Layton if (err < 0) { 74619f7e2caSStanislav Kinsbursky nfsd_destroy(net); 74778a8d7c8SJeff Layton return err; 74878a8d7c8SJeff Layton } 749ea068badSChuck Lever 7500b7c2f6fSChuck Lever /* Decrease the count, but don't shut down the service */ 7519dd9845fSStanislav Kinsbursky nn->nfsd_serv->sv_nrthreads--; 752ea068badSChuck Lever return err; 7530b7c2f6fSChuck Lever } 7540b7c2f6fSChuck Lever 7550b7c2f6fSChuck Lever /* 7564eb68c26SChuck Lever * A transport listener is added by writing it's transport name and 7574eb68c26SChuck Lever * a port number. 7584eb68c26SChuck Lever */ 7594df493a2STrond Myklebust static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cred *cred) 7604eb68c26SChuck Lever { 7614eb68c26SChuck Lever char transport[16]; 76237498292SChuck Lever struct svc_xprt *xprt; 7634eb68c26SChuck Lever int port, err; 7649dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7654eb68c26SChuck Lever 766a10fded1SJ. Bruce Fields if (sscanf(buf, "%15s %5u", transport, &port) != 2) 7674eb68c26SChuck Lever return -EINVAL; 7684eb68c26SChuck Lever 7694be929beSAlexey Dobriyan if (port < 1 || port > USHRT_MAX) 7704eb68c26SChuck Lever return -EINVAL; 7714eb68c26SChuck Lever 7726777436bSStanislav Kinsbursky err = nfsd_create_serv(net); 7734eb68c26SChuck Lever if (err != 0) 7744eb68c26SChuck Lever return err; 7754eb68c26SChuck Lever 7769dd9845fSStanislav Kinsbursky err = svc_create_xprt(nn->nfsd_serv, transport, net, 7774df493a2STrond Myklebust PF_INET, port, SVC_SOCK_ANONYMOUS, cred); 77868717908SChuck Lever if (err < 0) 77937498292SChuck Lever goto out_err; 78037498292SChuck Lever 7819dd9845fSStanislav Kinsbursky err = svc_create_xprt(nn->nfsd_serv, transport, net, 7824df493a2STrond Myklebust PF_INET6, port, SVC_SOCK_ANONYMOUS, cred); 78337498292SChuck Lever if (err < 0 && err != -EAFNOSUPPORT) 78437498292SChuck Lever goto out_close; 7850cd14a06SJeff Layton 7860cd14a06SJeff Layton /* Decrease the count, but don't shut down the service */ 7879dd9845fSStanislav Kinsbursky nn->nfsd_serv->sv_nrthreads--; 7884eb68c26SChuck Lever return 0; 78937498292SChuck Lever out_close: 7909dd9845fSStanislav Kinsbursky xprt = svc_find_xprt(nn->nfsd_serv, transport, net, PF_INET, port); 79137498292SChuck Lever if (xprt != NULL) { 79237498292SChuck Lever svc_close_xprt(xprt); 79337498292SChuck Lever svc_xprt_put(xprt); 79437498292SChuck Lever } 79537498292SChuck Lever out_err: 79619f7e2caSStanislav Kinsbursky nfsd_destroy(net); 79737498292SChuck Lever return err; 7984eb68c26SChuck Lever } 7994eb68c26SChuck Lever 80008160352SStanislav Kinsbursky static ssize_t __write_ports(struct file *file, char *buf, size_t size, 80108160352SStanislav Kinsbursky struct net *net) 80280212d59SNeilBrown { 8030a5372d8SChuck Lever if (size == 0) 8049dd9845fSStanislav Kinsbursky return __write_ports_names(buf, net); 8050b7c2f6fSChuck Lever 8060b7c2f6fSChuck Lever if (isdigit(buf[0])) 8074df493a2STrond Myklebust return __write_ports_addfd(buf, net, file->f_cred); 80882d56591SChuck Lever 8094eb68c26SChuck Lever if (isalpha(buf[0])) 8104df493a2STrond Myklebust return __write_ports_addxprt(buf, net, file->f_cred); 8114cd5dc75SChuck Lever 812b41b66d6SNeilBrown return -EINVAL; 813b41b66d6SNeilBrown } 81480212d59SNeilBrown 815f2453978SChuck Lever /* 816262a0982SChuck Lever * write_ports - Pass a socket file descriptor or transport name to listen on 817262a0982SChuck Lever * 818262a0982SChuck Lever * Input: 819262a0982SChuck Lever * buf: ignored 820262a0982SChuck Lever * size: zero 821262a0982SChuck Lever * Output: 822262a0982SChuck Lever * On success: passed-in buffer filled with a '\n'-terminated C 823262a0982SChuck Lever * string containing a whitespace-separated list of 824262a0982SChuck Lever * named NFSD listeners; 825262a0982SChuck Lever * return code is the size in bytes of the string 826262a0982SChuck Lever * On error: return code is zero or a negative errno value 827262a0982SChuck Lever * 828262a0982SChuck Lever * OR 829262a0982SChuck Lever * 830262a0982SChuck Lever * Input: 831262a0982SChuck Lever * buf: C string containing an unsigned 832262a0982SChuck Lever * integer value representing a bound 833262a0982SChuck Lever * but unconnected socket that is to be 834c71206a7SChuck Lever * used as an NFSD listener; listen(3) 835c71206a7SChuck Lever * must be called for a SOCK_STREAM 836c71206a7SChuck Lever * socket, otherwise it is ignored 837262a0982SChuck Lever * size: non-zero length of C string in @buf 838262a0982SChuck Lever * Output: 839262a0982SChuck Lever * On success: NFS service is started; 840262a0982SChuck Lever * passed-in buffer filled with a '\n'-terminated C 841262a0982SChuck Lever * string containing a unique alphanumeric name of 842262a0982SChuck Lever * the listener; 843262a0982SChuck Lever * return code is the size in bytes of the string 844262a0982SChuck Lever * On error: return code is a negative errno value 845262a0982SChuck Lever * 846262a0982SChuck Lever * OR 847262a0982SChuck Lever * 848262a0982SChuck Lever * Input: 849262a0982SChuck Lever * buf: C string containing a transport 850262a0982SChuck Lever * name and an unsigned integer value 851262a0982SChuck Lever * representing the port to listen on, 852262a0982SChuck Lever * separated by whitespace 853262a0982SChuck Lever * size: non-zero length of C string in @buf 854262a0982SChuck Lever * Output: 855262a0982SChuck Lever * On success: returns zero; NFS service is started 856262a0982SChuck Lever * On error: return code is a negative errno value 857262a0982SChuck Lever */ 858bedbdd8bSNeil Brown static ssize_t write_ports(struct file *file, char *buf, size_t size) 859bedbdd8bSNeil Brown { 860bedbdd8bSNeil Brown ssize_t rv; 8613dd98a3bSJeff Layton 862bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 863244c7d44SAl Viro rv = __write_ports(file, buf, size, netns(file)); 864bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 865bedbdd8bSNeil Brown return rv; 866bedbdd8bSNeil Brown } 867bedbdd8bSNeil Brown 868bedbdd8bSNeil Brown 869596bbe53SNeilBrown int nfsd_max_blksize; 870596bbe53SNeilBrown 871f2453978SChuck Lever /* 872262a0982SChuck Lever * write_maxblksize - Set or report the current NFS blksize 873262a0982SChuck Lever * 874262a0982SChuck Lever * Input: 875262a0982SChuck Lever * buf: ignored 876262a0982SChuck Lever * size: zero 877262a0982SChuck Lever * 878262a0982SChuck Lever * OR 879262a0982SChuck Lever * 880262a0982SChuck Lever * Input: 881262a0982SChuck Lever * buf: C string containing an unsigned 882262a0982SChuck Lever * integer value representing the new 883262a0982SChuck Lever * NFS blksize 884262a0982SChuck Lever * size: non-zero length of C string in @buf 885262a0982SChuck Lever * Output: 886262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 887262a0982SChuck Lever * containing numeric value of the current NFS blksize 888262a0982SChuck Lever * setting; 889262a0982SChuck Lever * return code is the size in bytes of the string 890262a0982SChuck Lever * On error: return code is zero or a negative errno value 891262a0982SChuck Lever */ 892596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) 893596bbe53SNeilBrown { 894596bbe53SNeilBrown char *mesg = buf; 895244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 8969dd9845fSStanislav Kinsbursky 897596bbe53SNeilBrown if (size > 0) { 898596bbe53SNeilBrown int bsize; 899596bbe53SNeilBrown int rv = get_int(&mesg, &bsize); 900596bbe53SNeilBrown if (rv) 901596bbe53SNeilBrown return rv; 902596bbe53SNeilBrown /* force bsize into allowed range and 903596bbe53SNeilBrown * required alignment. 904596bbe53SNeilBrown */ 9053c7aa15dSKinglong Mee bsize = max_t(int, bsize, 1024); 9063c7aa15dSKinglong Mee bsize = min_t(int, bsize, NFSSVC_MAXBLKSIZE); 907596bbe53SNeilBrown bsize &= ~(1024-1); 908bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 9099dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) { 910bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 911596bbe53SNeilBrown return -EBUSY; 912596bbe53SNeilBrown } 913596bbe53SNeilBrown nfsd_max_blksize = bsize; 914bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 915596bbe53SNeilBrown } 916e06b6405SChuck Lever 917e06b6405SChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", 918e06b6405SChuck Lever nfsd_max_blksize); 919596bbe53SNeilBrown } 920596bbe53SNeilBrown 921f2453978SChuck Lever /* 9225b8db00bSJeff Layton * write_maxconn - Set or report the current max number of connections 9235b8db00bSJeff Layton * 9245b8db00bSJeff Layton * Input: 9255b8db00bSJeff Layton * buf: ignored 9265b8db00bSJeff Layton * size: zero 9275b8db00bSJeff Layton * OR 9285b8db00bSJeff Layton * 9295b8db00bSJeff Layton * Input: 9305b8db00bSJeff Layton * buf: C string containing an unsigned 9315b8db00bSJeff Layton * integer value representing the new 9325b8db00bSJeff Layton * number of max connections 9335b8db00bSJeff Layton * size: non-zero length of C string in @buf 9345b8db00bSJeff Layton * Output: 9355b8db00bSJeff Layton * On success: passed-in buffer filled with '\n'-terminated C string 9365b8db00bSJeff Layton * containing numeric value of max_connections setting 9375b8db00bSJeff Layton * for this net namespace; 9385b8db00bSJeff Layton * return code is the size in bytes of the string 9395b8db00bSJeff Layton * On error: return code is zero or a negative errno value 9405b8db00bSJeff Layton */ 9415b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size) 9425b8db00bSJeff Layton { 9435b8db00bSJeff Layton char *mesg = buf; 944244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 9455b8db00bSJeff Layton unsigned int maxconn = nn->max_connections; 9465b8db00bSJeff Layton 9475b8db00bSJeff Layton if (size > 0) { 9485b8db00bSJeff Layton int rv = get_uint(&mesg, &maxconn); 9495b8db00bSJeff Layton 9505b8db00bSJeff Layton if (rv) 9515b8db00bSJeff Layton return rv; 9525b8db00bSJeff Layton nn->max_connections = maxconn; 9535b8db00bSJeff Layton } 9545b8db00bSJeff Layton 9555b8db00bSJeff Layton return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%u\n", maxconn); 9565b8db00bSJeff Layton } 9575b8db00bSJeff Layton 95870c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 9599dd9845fSStanislav Kinsbursky static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, 96020b7d86fSArnd Bergmann time64_t *time, struct nfsd_net *nn) 9611da177e4SLinus Torvalds { 9621da177e4SLinus Torvalds char *mesg = buf; 963f0135740SJ. Bruce Fields int rv, i; 9641da177e4SLinus Torvalds 9651da177e4SLinus Torvalds if (size > 0) { 9669dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 9673dd98a3bSJeff Layton return -EBUSY; 968f0135740SJ. Bruce Fields rv = get_int(&mesg, &i); 9691da177e4SLinus Torvalds if (rv) 9701da177e4SLinus Torvalds return rv; 971e7b184f1SJ. Bruce Fields /* 972e7b184f1SJ. Bruce Fields * Some sanity checking. We don't have a reason for 973e7b184f1SJ. Bruce Fields * these particular numbers, but problems with the 974e7b184f1SJ. Bruce Fields * extremes are: 975e7b184f1SJ. Bruce Fields * - Too short: the briefest network outage may 976e7b184f1SJ. Bruce Fields * cause clients to lose all their locks. Also, 977e7b184f1SJ. Bruce Fields * the frequent polling may be wasteful. 978e7b184f1SJ. Bruce Fields * - Too long: do you really want reboot recovery 979e7b184f1SJ. Bruce Fields * to take more than an hour? Or to make other 980e7b184f1SJ. Bruce Fields * clients wait an hour before being able to 981e7b184f1SJ. Bruce Fields * revoke a dead client's locks? 982e7b184f1SJ. Bruce Fields */ 983f0135740SJ. Bruce Fields if (i < 10 || i > 3600) 9841da177e4SLinus Torvalds return -EINVAL; 985f0135740SJ. Bruce Fields *time = i; 9861da177e4SLinus Torvalds } 987e06b6405SChuck Lever 98820b7d86fSArnd Bergmann return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%lld\n", *time); 989f0135740SJ. Bruce Fields } 990f0135740SJ. Bruce Fields 9919dd9845fSStanislav Kinsbursky static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, 99220b7d86fSArnd Bergmann time64_t *time, struct nfsd_net *nn) 993f0135740SJ. Bruce Fields { 994f0135740SJ. Bruce Fields ssize_t rv; 995f0135740SJ. Bruce Fields 996f0135740SJ. Bruce Fields mutex_lock(&nfsd_mutex); 9979dd9845fSStanislav Kinsbursky rv = __nfsd4_write_time(file, buf, size, time, nn); 998f0135740SJ. Bruce Fields mutex_unlock(&nfsd_mutex); 999f0135740SJ. Bruce Fields return rv; 10001da177e4SLinus Torvalds } 10011da177e4SLinus Torvalds 1002f2453978SChuck Lever /* 1003262a0982SChuck Lever * write_leasetime - Set or report the current NFSv4 lease time 1004262a0982SChuck Lever * 1005262a0982SChuck Lever * Input: 1006262a0982SChuck Lever * buf: ignored 1007262a0982SChuck Lever * size: zero 1008262a0982SChuck Lever * 1009262a0982SChuck Lever * OR 1010262a0982SChuck Lever * 1011262a0982SChuck Lever * Input: 1012262a0982SChuck Lever * buf: C string containing an unsigned 1013262a0982SChuck Lever * integer value representing the new 1014262a0982SChuck Lever * NFSv4 lease expiry time 1015262a0982SChuck Lever * size: non-zero length of C string in @buf 1016262a0982SChuck Lever * Output: 1017262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 1018262a0982SChuck Lever * string containing unsigned integer value of the 1019262a0982SChuck Lever * current lease expiry time; 1020262a0982SChuck Lever * return code is the size in bytes of the string 1021262a0982SChuck Lever * On error: return code is zero or a negative errno value 1022262a0982SChuck Lever */ 10233dd98a3bSJeff Layton static ssize_t write_leasetime(struct file *file, char *buf, size_t size) 10243dd98a3bSJeff Layton { 1025244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10269dd9845fSStanislav Kinsbursky return nfsd4_write_time(file, buf, size, &nn->nfsd4_lease, nn); 10273dd98a3bSJeff Layton } 10283dd98a3bSJeff Layton 1029f2453978SChuck Lever /* 1030efc4bb4fSJ. Bruce Fields * write_gracetime - Set or report current NFSv4 grace period time 1031efc4bb4fSJ. Bruce Fields * 1032efc4bb4fSJ. Bruce Fields * As above, but sets the time of the NFSv4 grace period. 1033efc4bb4fSJ. Bruce Fields * 1034efc4bb4fSJ. Bruce Fields * Note this should never be set to less than the *previous* 1035efc4bb4fSJ. Bruce Fields * lease-period time, but we don't try to enforce this. (In the common 1036efc4bb4fSJ. Bruce Fields * case (a new boot), we don't know what the previous lease time was 1037efc4bb4fSJ. Bruce Fields * anyway.) 1038efc4bb4fSJ. Bruce Fields */ 1039efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size) 1040efc4bb4fSJ. Bruce Fields { 1041244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10429dd9845fSStanislav Kinsbursky return nfsd4_write_time(file, buf, size, &nn->nfsd4_grace, nn); 1043efc4bb4fSJ. Bruce Fields } 1044efc4bb4fSJ. Bruce Fields 10459dd9845fSStanislav Kinsbursky static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size, 10469dd9845fSStanislav Kinsbursky struct nfsd_net *nn) 10470964a3d3SNeilBrown { 10480964a3d3SNeilBrown char *mesg = buf; 10490964a3d3SNeilBrown char *recdir; 10500964a3d3SNeilBrown int len, status; 10510964a3d3SNeilBrown 10523dd98a3bSJeff Layton if (size > 0) { 10539dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 10543dd98a3bSJeff Layton return -EBUSY; 10553dd98a3bSJeff Layton if (size > PATH_MAX || buf[size-1] != '\n') 10560964a3d3SNeilBrown return -EINVAL; 10570964a3d3SNeilBrown buf[size-1] = 0; 10580964a3d3SNeilBrown 10590964a3d3SNeilBrown recdir = mesg; 10600964a3d3SNeilBrown len = qword_get(&mesg, recdir, size); 10610964a3d3SNeilBrown if (len <= 0) 10620964a3d3SNeilBrown return -EINVAL; 10630964a3d3SNeilBrown 10640964a3d3SNeilBrown status = nfs4_reset_recoverydir(recdir); 106569049961SAndi Kleen if (status) 106669049961SAndi Kleen return status; 10673dd98a3bSJeff Layton } 10683d72ab8fSChuck Lever 10693d72ab8fSChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", 10703d72ab8fSChuck Lever nfs4_recoverydir()); 10710964a3d3SNeilBrown } 10723dd98a3bSJeff Layton 1073f2453978SChuck Lever /* 1074262a0982SChuck Lever * write_recoverydir - Set or report the pathname of the recovery directory 1075262a0982SChuck Lever * 1076262a0982SChuck Lever * Input: 1077262a0982SChuck Lever * buf: ignored 1078262a0982SChuck Lever * size: zero 1079262a0982SChuck Lever * 1080262a0982SChuck Lever * OR 1081262a0982SChuck Lever * 1082262a0982SChuck Lever * Input: 1083262a0982SChuck Lever * buf: C string containing the pathname 1084262a0982SChuck Lever * of the directory on a local file 1085262a0982SChuck Lever * system containing permanent NFSv4 1086262a0982SChuck Lever * recovery data 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 the current recovery pathname setting; 1091262a0982SChuck Lever * return code is the size in bytes of the string 1092262a0982SChuck Lever * On error: return code is zero or a negative errno value 1093262a0982SChuck Lever */ 10943dd98a3bSJeff Layton static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) 10953dd98a3bSJeff Layton { 10963dd98a3bSJeff Layton ssize_t rv; 1097244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10983dd98a3bSJeff Layton 10993dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 11009dd9845fSStanislav Kinsbursky rv = __write_recoverydir(file, buf, size, nn); 11013dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 11023dd98a3bSJeff Layton return rv; 11033dd98a3bSJeff Layton } 11043dd98a3bSJeff Layton 1105f2453978SChuck Lever /* 11067f5ef2e9SJeff Layton * write_v4_end_grace - release grace period for nfsd's v4.x lock manager 11077f5ef2e9SJeff Layton * 11087f5ef2e9SJeff Layton * Input: 11097f5ef2e9SJeff Layton * buf: ignored 11107f5ef2e9SJeff Layton * size: zero 11117f5ef2e9SJeff Layton * OR 11127f5ef2e9SJeff Layton * 11137f5ef2e9SJeff Layton * Input: 11147f5ef2e9SJeff Layton * buf: any value 11157f5ef2e9SJeff Layton * size: non-zero length of C string in @buf 11167f5ef2e9SJeff Layton * Output: 11177f5ef2e9SJeff Layton * passed-in buffer filled with "Y" or "N" with a newline 11187f5ef2e9SJeff Layton * and NULL-terminated C string. This indicates whether 11197f5ef2e9SJeff Layton * the grace period has ended in the current net 11207f5ef2e9SJeff Layton * namespace. Return code is the size in bytes of the 11217f5ef2e9SJeff Layton * string. Writing a string that starts with 'Y', 'y', or 11227f5ef2e9SJeff Layton * '1' to the file will end the grace period for nfsd's v4 11237f5ef2e9SJeff Layton * lock manager. 11247f5ef2e9SJeff Layton */ 11257f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) 11267f5ef2e9SJeff Layton { 1127244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 11287f5ef2e9SJeff Layton 11297f5ef2e9SJeff Layton if (size > 0) { 11307f5ef2e9SJeff Layton switch(buf[0]) { 11317f5ef2e9SJeff Layton case 'Y': 11327f5ef2e9SJeff Layton case 'y': 11337f5ef2e9SJeff Layton case '1': 1134dd838821SYihao Wu if (!nn->nfsd_serv) 113562a063b8SJ. Bruce Fields return -EBUSY; 11367f5ef2e9SJeff Layton nfsd4_end_grace(nn); 11377f5ef2e9SJeff Layton break; 11387f5ef2e9SJeff Layton default: 11397f5ef2e9SJeff Layton return -EINVAL; 11407f5ef2e9SJeff Layton } 11417f5ef2e9SJeff Layton } 11427f5ef2e9SJeff Layton 11437f5ef2e9SJeff Layton return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%c\n", 11447f5ef2e9SJeff Layton nn->grace_ended ? 'Y' : 'N'); 11457f5ef2e9SJeff Layton } 11467f5ef2e9SJeff Layton 114770c3b76cSNeilBrown #endif 11480964a3d3SNeilBrown 11491da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 11501da177e4SLinus Torvalds /* 11511da177e4SLinus Torvalds * populating the filesystem. 11521da177e4SLinus Torvalds */ 11531da177e4SLinus Torvalds 1154e8a79fb1SJ. Bruce Fields /* Basically copying rpc_get_inode. */ 1155e8a79fb1SJ. Bruce Fields static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode) 1156e8a79fb1SJ. Bruce Fields { 1157e8a79fb1SJ. Bruce Fields struct inode *inode = new_inode(sb); 1158e8a79fb1SJ. Bruce Fields if (!inode) 1159e8a79fb1SJ. Bruce Fields return NULL; 1160e8a79fb1SJ. Bruce Fields /* Following advice from simple_fill_super documentation: */ 1161e8a79fb1SJ. Bruce Fields inode->i_ino = iunique(sb, NFSD_MaxReserved); 1162e8a79fb1SJ. Bruce Fields inode->i_mode = mode; 1163e8a79fb1SJ. Bruce Fields inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); 1164e8a79fb1SJ. Bruce Fields switch (mode & S_IFMT) { 1165e8a79fb1SJ. Bruce Fields case S_IFDIR: 1166e8a79fb1SJ. Bruce Fields inode->i_fop = &simple_dir_operations; 1167e8a79fb1SJ. Bruce Fields inode->i_op = &simple_dir_inode_operations; 1168e8a79fb1SJ. Bruce Fields inc_nlink(inode); 1169e8a79fb1SJ. Bruce Fields default: 1170e8a79fb1SJ. Bruce Fields break; 1171e8a79fb1SJ. Bruce Fields } 1172e8a79fb1SJ. Bruce Fields return inode; 1173e8a79fb1SJ. Bruce Fields } 1174e8a79fb1SJ. Bruce Fields 1175bebd6997SJ. Bruce Fields static int __nfsd_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode, struct nfsdfs_client *ncl) 1176e8a79fb1SJ. Bruce Fields { 1177e8a79fb1SJ. Bruce Fields struct inode *inode; 1178e8a79fb1SJ. Bruce Fields 1179e8a79fb1SJ. Bruce Fields inode = nfsd_get_inode(dir->i_sb, mode); 1180e8a79fb1SJ. Bruce Fields if (!inode) 1181e8a79fb1SJ. Bruce Fields return -ENOMEM; 1182bebd6997SJ. Bruce Fields if (ncl) { 1183bebd6997SJ. Bruce Fields inode->i_private = ncl; 1184bebd6997SJ. Bruce Fields kref_get(&ncl->cl_ref); 1185bebd6997SJ. Bruce Fields } 1186e8a79fb1SJ. Bruce Fields d_add(dentry, inode); 1187e8a79fb1SJ. Bruce Fields inc_nlink(dir); 1188e8a79fb1SJ. Bruce Fields fsnotify_mkdir(dir, dentry); 1189e8a79fb1SJ. Bruce Fields return 0; 1190e8a79fb1SJ. Bruce Fields } 1191e8a79fb1SJ. Bruce Fields 1192e8a79fb1SJ. Bruce Fields static struct dentry *nfsd_mkdir(struct dentry *parent, struct nfsdfs_client *ncl, char *name) 1193e8a79fb1SJ. Bruce Fields { 1194e8a79fb1SJ. Bruce Fields struct inode *dir = parent->d_inode; 1195e8a79fb1SJ. Bruce Fields struct dentry *dentry; 1196e8a79fb1SJ. Bruce Fields int ret = -ENOMEM; 1197e8a79fb1SJ. Bruce Fields 1198e8a79fb1SJ. Bruce Fields inode_lock(dir); 1199e8a79fb1SJ. Bruce Fields dentry = d_alloc_name(parent, name); 1200e8a79fb1SJ. Bruce Fields if (!dentry) 1201e8a79fb1SJ. Bruce Fields goto out_err; 1202bebd6997SJ. Bruce Fields ret = __nfsd_mkdir(d_inode(parent), dentry, S_IFDIR | 0600, ncl); 1203e8a79fb1SJ. Bruce Fields if (ret) 1204e8a79fb1SJ. Bruce Fields goto out_err; 1205e8a79fb1SJ. Bruce Fields out: 1206e8a79fb1SJ. Bruce Fields inode_unlock(dir); 1207e8a79fb1SJ. Bruce Fields return dentry; 1208e8a79fb1SJ. Bruce Fields out_err: 1209d6846bfbSTetsuo Handa dput(dentry); 1210e8a79fb1SJ. Bruce Fields dentry = ERR_PTR(ret); 1211e8a79fb1SJ. Bruce Fields goto out; 1212e8a79fb1SJ. Bruce Fields } 1213e8a79fb1SJ. Bruce Fields 121497ad4031SJ. Bruce Fields static void clear_ncl(struct inode *inode) 1215e8a79fb1SJ. Bruce Fields { 121697ad4031SJ. Bruce Fields struct nfsdfs_client *ncl = inode->i_private; 121797ad4031SJ. Bruce Fields 121897ad4031SJ. Bruce Fields inode->i_private = NULL; 121997ad4031SJ. Bruce Fields kref_put(&ncl->cl_ref, ncl->cl_release); 122097ad4031SJ. Bruce Fields } 122197ad4031SJ. Bruce Fields 1222b78fa45dSYueHaibing static struct nfsdfs_client *__get_nfsdfs_client(struct inode *inode) 122397ad4031SJ. Bruce Fields { 122497ad4031SJ. Bruce Fields struct nfsdfs_client *nc = inode->i_private; 122597ad4031SJ. Bruce Fields 122697ad4031SJ. Bruce Fields if (nc) 122797ad4031SJ. Bruce Fields kref_get(&nc->cl_ref); 122897ad4031SJ. Bruce Fields return nc; 122997ad4031SJ. Bruce Fields } 123097ad4031SJ. Bruce Fields 123197ad4031SJ. Bruce Fields struct nfsdfs_client *get_nfsdfs_client(struct inode *inode) 123297ad4031SJ. Bruce Fields { 123397ad4031SJ. Bruce Fields struct nfsdfs_client *nc; 123497ad4031SJ. Bruce Fields 1235dc46bba7SJ. Bruce Fields inode_lock_shared(inode); 123697ad4031SJ. Bruce Fields nc = __get_nfsdfs_client(inode); 1237dc46bba7SJ. Bruce Fields inode_unlock_shared(inode); 123897ad4031SJ. Bruce Fields return nc; 123997ad4031SJ. Bruce Fields } 124097ad4031SJ. Bruce Fields /* from __rpc_unlink */ 124197ad4031SJ. Bruce Fields static void nfsdfs_remove_file(struct inode *dir, struct dentry *dentry) 124297ad4031SJ. Bruce Fields { 124397ad4031SJ. Bruce Fields int ret; 124497ad4031SJ. Bruce Fields 124597ad4031SJ. Bruce Fields clear_ncl(d_inode(dentry)); 124697ad4031SJ. Bruce Fields dget(dentry); 124797ad4031SJ. Bruce Fields ret = simple_unlink(dir, dentry); 124897ad4031SJ. Bruce Fields d_delete(dentry); 124997ad4031SJ. Bruce Fields dput(dentry); 125097ad4031SJ. Bruce Fields WARN_ON_ONCE(ret); 125197ad4031SJ. Bruce Fields } 125297ad4031SJ. Bruce Fields 125397ad4031SJ. Bruce Fields static void nfsdfs_remove_files(struct dentry *root) 125497ad4031SJ. Bruce Fields { 125597ad4031SJ. Bruce Fields struct dentry *dentry, *tmp; 125697ad4031SJ. Bruce Fields 125797ad4031SJ. Bruce Fields list_for_each_entry_safe(dentry, tmp, &root->d_subdirs, d_child) { 125897ad4031SJ. Bruce Fields if (!simple_positive(dentry)) { 125997ad4031SJ. Bruce Fields WARN_ON_ONCE(1); /* I think this can't happen? */ 126097ad4031SJ. Bruce Fields continue; 126197ad4031SJ. Bruce Fields } 126297ad4031SJ. Bruce Fields nfsdfs_remove_file(d_inode(root), dentry); 126397ad4031SJ. Bruce Fields } 126497ad4031SJ. Bruce Fields } 126597ad4031SJ. Bruce Fields 126697ad4031SJ. Bruce Fields /* XXX: cut'n'paste from simple_fill_super; figure out if we could share 126797ad4031SJ. Bruce Fields * code instead. */ 126897ad4031SJ. Bruce Fields static int nfsdfs_create_files(struct dentry *root, 1269*472d155aSNeilBrown const struct tree_descr *files, 1270*472d155aSNeilBrown struct dentry **fdentries) 127197ad4031SJ. Bruce Fields { 127297ad4031SJ. Bruce Fields struct inode *dir = d_inode(root); 127397ad4031SJ. Bruce Fields struct inode *inode; 127497ad4031SJ. Bruce Fields struct dentry *dentry; 127597ad4031SJ. Bruce Fields int i; 127697ad4031SJ. Bruce Fields 127797ad4031SJ. Bruce Fields inode_lock(dir); 127897ad4031SJ. Bruce Fields for (i = 0; files->name && files->name[0]; i++, files++) { 127997ad4031SJ. Bruce Fields dentry = d_alloc_name(root, files->name); 128097ad4031SJ. Bruce Fields if (!dentry) 128197ad4031SJ. Bruce Fields goto out; 128297ad4031SJ. Bruce Fields inode = nfsd_get_inode(d_inode(root)->i_sb, 128397ad4031SJ. Bruce Fields S_IFREG | files->mode); 128497ad4031SJ. Bruce Fields if (!inode) { 128597ad4031SJ. Bruce Fields dput(dentry); 128697ad4031SJ. Bruce Fields goto out; 128797ad4031SJ. Bruce Fields } 128897ad4031SJ. Bruce Fields inode->i_fop = files->ops; 128997ad4031SJ. Bruce Fields inode->i_private = __get_nfsdfs_client(dir); 129097ad4031SJ. Bruce Fields d_add(dentry, inode); 129197ad4031SJ. Bruce Fields fsnotify_create(dir, dentry); 1292*472d155aSNeilBrown if (fdentries) 1293*472d155aSNeilBrown fdentries[i] = dentry; 129497ad4031SJ. Bruce Fields } 129597ad4031SJ. Bruce Fields inode_unlock(dir); 129697ad4031SJ. Bruce Fields return 0; 129797ad4031SJ. Bruce Fields out: 129897ad4031SJ. Bruce Fields nfsdfs_remove_files(root); 129997ad4031SJ. Bruce Fields inode_unlock(dir); 130097ad4031SJ. Bruce Fields return -ENOMEM; 130197ad4031SJ. Bruce Fields } 130297ad4031SJ. Bruce Fields 130397ad4031SJ. Bruce Fields /* on success, returns positive number unique to that client. */ 130497ad4031SJ. Bruce Fields struct dentry *nfsd_client_mkdir(struct nfsd_net *nn, 130597ad4031SJ. Bruce Fields struct nfsdfs_client *ncl, u32 id, 1306*472d155aSNeilBrown const struct tree_descr *files, 1307*472d155aSNeilBrown struct dentry **fdentries) 130897ad4031SJ. Bruce Fields { 130997ad4031SJ. Bruce Fields struct dentry *dentry; 1310e8a79fb1SJ. Bruce Fields char name[11]; 131197ad4031SJ. Bruce Fields int ret; 1312e8a79fb1SJ. Bruce Fields 1313bf5ed3e3SJ. Bruce Fields sprintf(name, "%u", id); 1314e8a79fb1SJ. Bruce Fields 131597ad4031SJ. Bruce Fields dentry = nfsd_mkdir(nn->nfsd_client_dir, ncl, name); 131697ad4031SJ. Bruce Fields if (IS_ERR(dentry)) /* XXX: tossing errors? */ 131797ad4031SJ. Bruce Fields return NULL; 1318*472d155aSNeilBrown ret = nfsdfs_create_files(dentry, files, fdentries); 131997ad4031SJ. Bruce Fields if (ret) { 132097ad4031SJ. Bruce Fields nfsd_client_rmdir(dentry); 132197ad4031SJ. Bruce Fields return NULL; 132297ad4031SJ. Bruce Fields } 132397ad4031SJ. Bruce Fields return dentry; 1324e8a79fb1SJ. Bruce Fields } 1325e8a79fb1SJ. Bruce Fields 1326e8a79fb1SJ. Bruce Fields /* Taken from __rpc_rmdir: */ 1327e8a79fb1SJ. Bruce Fields void nfsd_client_rmdir(struct dentry *dentry) 1328e8a79fb1SJ. Bruce Fields { 1329e8a79fb1SJ. Bruce Fields struct inode *dir = d_inode(dentry->d_parent); 1330e8a79fb1SJ. Bruce Fields struct inode *inode = d_inode(dentry); 1331e8a79fb1SJ. Bruce Fields int ret; 1332e8a79fb1SJ. Bruce Fields 133397ad4031SJ. Bruce Fields inode_lock(dir); 133497ad4031SJ. Bruce Fields nfsdfs_remove_files(dentry); 133597ad4031SJ. Bruce Fields clear_ncl(inode); 1336e8a79fb1SJ. Bruce Fields dget(dentry); 1337e8a79fb1SJ. Bruce Fields ret = simple_rmdir(dir, dentry); 1338e8a79fb1SJ. Bruce Fields WARN_ON_ONCE(ret); 133969afd267SJ. Bruce Fields fsnotify_rmdir(dir, dentry); 1340e8a79fb1SJ. Bruce Fields d_delete(dentry); 1341bf265401SJ. Bruce Fields dput(dentry); 134297ad4031SJ. Bruce Fields inode_unlock(dir); 1343e8a79fb1SJ. Bruce Fields } 1344e8a79fb1SJ. Bruce Fields 134596a374a3SDavid Howells static int nfsd_fill_super(struct super_block *sb, struct fs_context *fc) 13461da177e4SLinus Torvalds { 1347e8a79fb1SJ. Bruce Fields struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, 1348e8a79fb1SJ. Bruce Fields nfsd_net_id); 1349e8a79fb1SJ. Bruce Fields struct dentry *dentry; 1350e8a79fb1SJ. Bruce Fields int ret; 1351e8a79fb1SJ. Bruce Fields 1352cda37124SEric Biggers static const struct tree_descr nfsd_files[] = { 135396d851c4SStanislav Kinsbursky [NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO}, 135420ad856eSAmir Goldstein /* Per-export io stats use same ops as exports file */ 135520ad856eSAmir Goldstein [NFSD_Export_Stats] = {"export_stats", &exports_nfsd_operations, S_IRUGO}, 1356e8e8753fSJ. Bruce Fields [NFSD_Export_features] = {"export_features", 1357e8e8753fSJ. Bruce Fields &export_features_operations, S_IRUGO}, 13584373ea84SWendy Cheng [NFSD_FO_UnlockIP] = {"unlock_ip", 13594373ea84SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 136017efa372SWendy Cheng [NFSD_FO_UnlockFS] = {"unlock_filesystem", 136117efa372SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 13621da177e4SLinus Torvalds [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 13631da177e4SLinus Torvalds [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 1364eed2965aSGreg Banks [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, 136503cf6c9fSGreg Banks [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, 1366a2f999a3SJeff Layton [NFSD_Reply_Cache_Stats] = {"reply_cache_stats", &reply_cache_stats_operations, S_IRUGO}, 136770c3b76cSNeilBrown [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, 136880212d59SNeilBrown [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, 1369596bbe53SNeilBrown [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, 13705b8db00bSJeff Layton [NFSD_MaxConnections] = {"max_connections", &transaction_ops, S_IWUSR|S_IRUGO}, 1371b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 1372b0b0c0a2SKevin Coffman [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO}, 1373b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 13741da177e4SLinus Torvalds #ifdef CONFIG_NFSD_V4 13751da177e4SLinus Torvalds [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, 1376efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, 13770964a3d3SNeilBrown [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, 13787f5ef2e9SJeff Layton [NFSD_V4EndGrace] = {"v4_end_grace", &transaction_ops, S_IWUSR|S_IRUGO}, 13791da177e4SLinus Torvalds #endif 13801da177e4SLinus Torvalds /* last one */ {""} 13811da177e4SLinus Torvalds }; 138296a374a3SDavid Howells 1383e8a79fb1SJ. Bruce Fields ret = simple_fill_super(sb, 0x6e667364, nfsd_files); 1384e8a79fb1SJ. Bruce Fields if (ret) 1385e8a79fb1SJ. Bruce Fields return ret; 1386e8a79fb1SJ. Bruce Fields dentry = nfsd_mkdir(sb->s_root, NULL, "clients"); 1387e8a79fb1SJ. Bruce Fields if (IS_ERR(dentry)) 1388e8a79fb1SJ. Bruce Fields return PTR_ERR(dentry); 1389e8a79fb1SJ. Bruce Fields nn->nfsd_client_dir = dentry; 1390e8a79fb1SJ. Bruce Fields return 0; 13911da177e4SLinus Torvalds } 13921da177e4SLinus Torvalds 139396a374a3SDavid Howells static int nfsd_fs_get_tree(struct fs_context *fc) 13941da177e4SLinus Torvalds { 1395533770ccSAl Viro return get_tree_keyed(fc, nfsd_fill_super, get_net(fc->net_ns)); 139696a374a3SDavid Howells } 139796a374a3SDavid Howells 139896a374a3SDavid Howells static void nfsd_fs_free_fc(struct fs_context *fc) 139996a374a3SDavid Howells { 140096a374a3SDavid Howells if (fc->s_fs_info) 140196a374a3SDavid Howells put_net(fc->s_fs_info); 140296a374a3SDavid Howells } 140396a374a3SDavid Howells 140496a374a3SDavid Howells static const struct fs_context_operations nfsd_fs_context_ops = { 140596a374a3SDavid Howells .free = nfsd_fs_free_fc, 140696a374a3SDavid Howells .get_tree = nfsd_fs_get_tree, 140796a374a3SDavid Howells }; 140896a374a3SDavid Howells 140996a374a3SDavid Howells static int nfsd_init_fs_context(struct fs_context *fc) 141096a374a3SDavid Howells { 141196a374a3SDavid Howells put_user_ns(fc->user_ns); 141296a374a3SDavid Howells fc->user_ns = get_user_ns(fc->net_ns->user_ns); 141396a374a3SDavid Howells fc->ops = &nfsd_fs_context_ops; 141496a374a3SDavid Howells return 0; 141511f77942SStanislav Kinsbursky } 141611f77942SStanislav Kinsbursky 141711f77942SStanislav Kinsbursky static void nfsd_umount(struct super_block *sb) 141811f77942SStanislav Kinsbursky { 141911f77942SStanislav Kinsbursky struct net *net = sb->s_fs_info; 142011f77942SStanislav Kinsbursky 1421c6c7f2a8STrond Myklebust nfsd_shutdown_threads(net); 1422c6c7f2a8STrond Myklebust 142311f77942SStanislav Kinsbursky kill_litter_super(sb); 142411f77942SStanislav Kinsbursky put_net(net); 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds 14271da177e4SLinus Torvalds static struct file_system_type nfsd_fs_type = { 14281da177e4SLinus Torvalds .owner = THIS_MODULE, 14291da177e4SLinus Torvalds .name = "nfsd", 143096a374a3SDavid Howells .init_fs_context = nfsd_init_fs_context, 143111f77942SStanislav Kinsbursky .kill_sb = nfsd_umount, 14321da177e4SLinus Torvalds }; 14337f78e035SEric W. Biederman MODULE_ALIAS_FS("nfsd"); 14341da177e4SLinus Torvalds 1435e331f606SJ. Bruce Fields #ifdef CONFIG_PROC_FS 1436e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1437e331f606SJ. Bruce Fields { 1438e331f606SJ. Bruce Fields struct proc_dir_entry *entry; 1439e331f606SJ. Bruce Fields 1440e331f606SJ. Bruce Fields entry = proc_mkdir("fs/nfs", NULL); 1441e331f606SJ. Bruce Fields if (!entry) 1442e331f606SJ. Bruce Fields return -ENOMEM; 144397a32539SAlexey Dobriyan entry = proc_create("exports", 0, entry, &exports_proc_ops); 1444ff7c4b36Sfanchaoting if (!entry) { 1445ff7c4b36Sfanchaoting remove_proc_entry("fs/nfs", NULL); 1446e331f606SJ. Bruce Fields return -ENOMEM; 1447ff7c4b36Sfanchaoting } 1448e331f606SJ. Bruce Fields return 0; 1449e331f606SJ. Bruce Fields } 1450e331f606SJ. Bruce Fields #else /* CONFIG_PROC_FS */ 1451e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1452e331f606SJ. Bruce Fields { 1453e331f606SJ. Bruce Fields return 0; 1454e331f606SJ. Bruce Fields } 1455e331f606SJ. Bruce Fields #endif 1456e331f606SJ. Bruce Fields 1457c7d03a00SAlexey Dobriyan unsigned int nfsd_net_id; 14585717e012SStanislav Kinsbursky 14595717e012SStanislav Kinsbursky static __net_init int nfsd_init_net(struct net *net) 14605717e012SStanislav Kinsbursky { 14615717e012SStanislav Kinsbursky int retval; 14623d733711SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 14635717e012SStanislav Kinsbursky 14645717e012SStanislav Kinsbursky retval = nfsd_export_init(net); 14655717e012SStanislav Kinsbursky if (retval) 14665717e012SStanislav Kinsbursky goto out_export_error; 1467f69adb2fSStanislav Kinsbursky retval = nfsd_idmap_init(net); 1468f69adb2fSStanislav Kinsbursky if (retval) 1469f69adb2fSStanislav Kinsbursky goto out_idmap_error; 1470e333f3bbSTrond Myklebust nn->nfsd_versions = NULL; 1471e333f3bbSTrond Myklebust nn->nfsd4_minorversions = NULL; 14723ba75830SJ. Bruce Fields retval = nfsd_reply_cache_init(nn); 14733ba75830SJ. Bruce Fields if (retval) 14743ba75830SJ. Bruce Fields goto out_drc_error; 14753bf6b57eSJ. Bruce Fields nn->nfsd4_lease = 90; /* default lease time */ 14763bf6b57eSJ. Bruce Fields nn->nfsd4_grace = 90; 147703f318caSJ. Bruce Fields nn->somebody_reclaimed = false; 1478362063a5SScott Mayhew nn->track_reclaim_completes = false; 1479ebd7c72cSJ. Bruce Fields nn->clverifier_counter = prandom_u32(); 1480bf5ed3e3SJ. Bruce Fields nn->clientid_base = prandom_u32(); 1481bf5ed3e3SJ. Bruce Fields nn->clientid_counter = nn->clientid_base + 1; 1482e0639dc5SOlga Kornievskaia nn->s2s_cp_cl_id = nn->clientid_counter++; 14832317dc55SVasily Averin 14842317dc55SVasily Averin atomic_set(&nn->ntf_refcnt, 0); 14852317dc55SVasily Averin init_waitqueue_head(&nn->ntf_wq); 148627c438f5STrond Myklebust seqlock_init(&nn->boot_lock); 14872c830dd7SJ. Bruce Fields 14885717e012SStanislav Kinsbursky return 0; 14895717e012SStanislav Kinsbursky 14903ba75830SJ. Bruce Fields out_drc_error: 14913ba75830SJ. Bruce Fields nfsd_idmap_shutdown(net); 1492f69adb2fSStanislav Kinsbursky out_idmap_error: 1493f69adb2fSStanislav Kinsbursky nfsd_export_shutdown(net); 14945717e012SStanislav Kinsbursky out_export_error: 14955717e012SStanislav Kinsbursky return retval; 14965717e012SStanislav Kinsbursky } 14975717e012SStanislav Kinsbursky 14985717e012SStanislav Kinsbursky static __net_exit void nfsd_exit_net(struct net *net) 14995717e012SStanislav Kinsbursky { 15003ba75830SJ. Bruce Fields struct nfsd_net *nn = net_generic(net, nfsd_net_id); 15013ba75830SJ. Bruce Fields 15023ba75830SJ. Bruce Fields nfsd_reply_cache_shutdown(nn); 1503f69adb2fSStanislav Kinsbursky nfsd_idmap_shutdown(net); 15045717e012SStanislav Kinsbursky nfsd_export_shutdown(net); 1505e333f3bbSTrond Myklebust nfsd_netns_free_versions(net_generic(net, nfsd_net_id)); 15065717e012SStanislav Kinsbursky } 15075717e012SStanislav Kinsbursky 15087ea34ac1SJeff Layton static struct pernet_operations nfsd_net_ops = { 15095717e012SStanislav Kinsbursky .init = nfsd_init_net, 15105717e012SStanislav Kinsbursky .exit = nfsd_exit_net, 15117ea34ac1SJeff Layton .id = &nfsd_net_id, 15127ea34ac1SJeff Layton .size = sizeof(struct nfsd_net), 15137ea34ac1SJeff Layton }; 15147ea34ac1SJeff Layton 15151da177e4SLinus Torvalds static int __init init_nfsd(void) 15161da177e4SLinus Torvalds { 15171da177e4SLinus Torvalds int retval; 15181da177e4SLinus Torvalds printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 15191da177e4SLinus Torvalds 1520bb7ffbf2SGiuseppe Cantavenera retval = register_cld_notifier(); 1521e8ff2a84SJ. Bruce Fields if (retval) 1522bd5ae928SJ. Bruce Fields return retval; 1523bb7ffbf2SGiuseppe Cantavenera retval = nfsd4_init_slabs(); 1524bb7ffbf2SGiuseppe Cantavenera if (retval) 1525bb7ffbf2SGiuseppe Cantavenera goto out_unregister_notifier; 15269cf514ccSChristoph Hellwig retval = nfsd4_init_pnfs(); 152765178db4SBryan Schumaker if (retval) 152865178db4SBryan Schumaker goto out_free_slabs; 1529e567b98cSAmir Goldstein retval = nfsd_stat_init(); /* Statistics */ 1530e567b98cSAmir Goldstein if (retval) 1531e567b98cSAmir Goldstein goto out_free_pnfs; 1532027690c7SJ. Bruce Fields retval = nfsd_drc_slab_create(); 1533027690c7SJ. Bruce Fields if (retval) 1534027690c7SJ. Bruce Fields goto out_free_stat; 15351da177e4SLinus Torvalds nfsd_lockd_init(); /* lockd->nfsd callbacks */ 1536e331f606SJ. Bruce Fields retval = create_proc_exports_entry(); 1537e331f606SJ. Bruce Fields if (retval) 1538f69adb2fSStanislav Kinsbursky goto out_free_lockd; 15391da177e4SLinus Torvalds retval = register_filesystem(&nfsd_fs_type); 154026808d3fSJ. Bruce Fields if (retval) 1541bd5ae928SJ. Bruce Fields goto out_free_exports; 1542bd5ae928SJ. Bruce Fields retval = register_pernet_subsys(&nfsd_net_ops); 1543bd5ae928SJ. Bruce Fields if (retval < 0) 154426808d3fSJ. Bruce Fields goto out_free_all; 154526808d3fSJ. Bruce Fields return 0; 154626808d3fSJ. Bruce Fields out_free_all: 1547bd5ae928SJ. Bruce Fields unregister_pernet_subsys(&nfsd_net_ops); 1548bd5ae928SJ. Bruce Fields out_free_exports: 15491da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 15501da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 1551dbf847ecSJ. Bruce Fields out_free_lockd: 15521da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1553027690c7SJ. Bruce Fields nfsd_drc_slab_free(); 1554027690c7SJ. Bruce Fields out_free_stat: 1555d5c3428bSJ. Bruce Fields nfsd_stat_shutdown(); 1556e567b98cSAmir Goldstein out_free_pnfs: 15579cf514ccSChristoph Hellwig nfsd4_exit_pnfs(); 155865178db4SBryan Schumaker out_free_slabs: 155946b25895SJ. Bruce Fields nfsd4_free_slabs(); 1560813fd320SJeff Layton out_unregister_notifier: 1561797a9d79SJeff Layton unregister_cld_notifier(); 15621da177e4SLinus Torvalds return retval; 15631da177e4SLinus Torvalds } 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds static void __exit exit_nfsd(void) 15661da177e4SLinus Torvalds { 1567bd5ae928SJ. Bruce Fields unregister_pernet_subsys(&nfsd_net_ops); 1568027690c7SJ. Bruce Fields nfsd_drc_slab_free(); 15691da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 15701da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 15711da177e4SLinus Torvalds nfsd_stat_shutdown(); 15721da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1573e8ff2a84SJ. Bruce Fields nfsd4_free_slabs(); 15749cf514ccSChristoph Hellwig nfsd4_exit_pnfs(); 15751da177e4SLinus Torvalds unregister_filesystem(&nfsd_fs_type); 1576797a9d79SJeff Layton unregister_cld_notifier(); 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds 15791da177e4SLinus Torvalds MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); 15801da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 15811da177e4SLinus Torvalds module_init(init_nfsd) 15821da177e4SLinus Torvalds module_exit(exit_nfsd) 1583