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, 35e8e8753fSJ. Bruce Fields NFSD_Export_features, 361da177e4SLinus Torvalds NFSD_Fh, 374373ea84SWendy Cheng NFSD_FO_UnlockIP, 3817efa372SWendy Cheng NFSD_FO_UnlockFS, 391da177e4SLinus Torvalds NFSD_Threads, 40eed2965aSGreg Banks NFSD_Pool_Threads, 4103cf6c9fSGreg Banks NFSD_Pool_Stats, 42a2f999a3SJeff Layton NFSD_Reply_Cache_Stats, 4370c3b76cSNeilBrown NFSD_Versions, 4480212d59SNeilBrown NFSD_Ports, 45596bbe53SNeilBrown NFSD_MaxBlkSize, 465b8db00bSJeff Layton NFSD_MaxConnections, 47b0b0c0a2SKevin Coffman NFSD_SupportedEnctypes, 4870c3b76cSNeilBrown /* 4970c3b76cSNeilBrown * The below MUST come last. Otherwise we leave a hole in nfsd_files[] 5070c3b76cSNeilBrown * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops 5170c3b76cSNeilBrown */ 5270c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 531da177e4SLinus Torvalds NFSD_Leasetime, 54efc4bb4fSJ. Bruce Fields NFSD_Gracetime, 550964a3d3SNeilBrown NFSD_RecoveryDir, 567f5ef2e9SJeff Layton NFSD_V4EndGrace, 5770c3b76cSNeilBrown #endif 58e8a79fb1SJ. Bruce Fields NFSD_MaxReserved 591da177e4SLinus Torvalds }; 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds /* 621da177e4SLinus Torvalds * write() for these nodes. 631da177e4SLinus Torvalds */ 641da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size); 65b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); 66b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); 671da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size); 68eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); 6970c3b76cSNeilBrown static ssize_t write_versions(struct file *file, char *buf, size_t size); 7080212d59SNeilBrown static ssize_t write_ports(struct file *file, char *buf, size_t size); 71596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); 725b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size); 7370c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 741da177e4SLinus Torvalds static ssize_t write_leasetime(struct file *file, char *buf, size_t size); 75efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size); 760964a3d3SNeilBrown static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); 777f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size); 7870c3b76cSNeilBrown #endif 791da177e4SLinus Torvalds 80c2cdc2abSEric Biggers static ssize_t (*const write_op[])(struct file *, char *, size_t) = { 811da177e4SLinus Torvalds [NFSD_Fh] = write_filehandle, 82b046ccdcSChuck Lever [NFSD_FO_UnlockIP] = write_unlock_ip, 83b046ccdcSChuck Lever [NFSD_FO_UnlockFS] = write_unlock_fs, 841da177e4SLinus Torvalds [NFSD_Threads] = write_threads, 85eed2965aSGreg Banks [NFSD_Pool_Threads] = write_pool_threads, 8670c3b76cSNeilBrown [NFSD_Versions] = write_versions, 8780212d59SNeilBrown [NFSD_Ports] = write_ports, 88596bbe53SNeilBrown [NFSD_MaxBlkSize] = write_maxblksize, 895b8db00bSJeff Layton [NFSD_MaxConnections] = write_maxconn, 9070c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 911da177e4SLinus Torvalds [NFSD_Leasetime] = write_leasetime, 92efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = write_gracetime, 930964a3d3SNeilBrown [NFSD_RecoveryDir] = write_recoverydir, 947f5ef2e9SJeff Layton [NFSD_V4EndGrace] = write_v4_end_grace, 9570c3b76cSNeilBrown #endif 961da177e4SLinus Torvalds }; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 991da177e4SLinus Torvalds { 100496ad9aaSAl Viro ino_t ino = file_inode(file)->i_ino; 1011da177e4SLinus Torvalds char *data; 1021da177e4SLinus Torvalds ssize_t rv; 1031da177e4SLinus Torvalds 104e8c96f8cSTobias Klauser if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) 1051da177e4SLinus Torvalds return -EINVAL; 1061da177e4SLinus Torvalds 1071da177e4SLinus Torvalds data = simple_transaction_get(file, buf, size); 1081da177e4SLinus Torvalds if (IS_ERR(data)) 1091da177e4SLinus Torvalds return PTR_ERR(data); 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds rv = write_op[ino](file, data, size); 1128971a101SNeilBrown if (rv >= 0) { 1131da177e4SLinus Torvalds simple_transaction_set(file, rv); 1141da177e4SLinus Torvalds rv = size; 1151da177e4SLinus Torvalds } 1161da177e4SLinus Torvalds return rv; 1171da177e4SLinus Torvalds } 1181da177e4SLinus Torvalds 1197390022dSNeilBrown static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) 1207390022dSNeilBrown { 1217390022dSNeilBrown if (! file->private_data) { 1227390022dSNeilBrown /* An attempt to read a transaction file without writing 1237390022dSNeilBrown * causes a 0-byte write so that the file can return 1247390022dSNeilBrown * state information 1257390022dSNeilBrown */ 1267390022dSNeilBrown ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); 1277390022dSNeilBrown if (rv < 0) 1287390022dSNeilBrown return rv; 1297390022dSNeilBrown } 1307390022dSNeilBrown return simple_transaction_read(file, buf, size, pos); 1317390022dSNeilBrown } 1327390022dSNeilBrown 1334b6f5d20SArjan van de Ven static const struct file_operations transaction_ops = { 1341da177e4SLinus Torvalds .write = nfsctl_transaction_write, 1357390022dSNeilBrown .read = nfsctl_transaction_read, 1361da177e4SLinus Torvalds .release = simple_transaction_release, 1376038f373SArnd Bergmann .llseek = default_llseek, 1381da177e4SLinus Torvalds }; 1391da177e4SLinus Torvalds 14096d851c4SStanislav Kinsbursky static int exports_net_open(struct net *net, struct file *file) 1411da177e4SLinus Torvalds { 142f2c7ea10SStanislav Kinsbursky int err; 143f2c7ea10SStanislav Kinsbursky struct seq_file *seq; 14496d851c4SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 145f2c7ea10SStanislav Kinsbursky 146f2c7ea10SStanislav Kinsbursky err = seq_open(file, &nfs_exports_op); 147f2c7ea10SStanislav Kinsbursky if (err) 148f2c7ea10SStanislav Kinsbursky return err; 149f2c7ea10SStanislav Kinsbursky 150f2c7ea10SStanislav Kinsbursky seq = file->private_data; 151e5f06f72SStanislav Kinsbursky seq->private = nn->svc_export_cache; 152f2c7ea10SStanislav Kinsbursky return 0; 1531da177e4SLinus Torvalds } 1541da177e4SLinus Torvalds 15596d851c4SStanislav Kinsbursky static int exports_proc_open(struct inode *inode, struct file *file) 15696d851c4SStanislav Kinsbursky { 15796d851c4SStanislav Kinsbursky return exports_net_open(current->nsproxy->net_ns, file); 15896d851c4SStanislav Kinsbursky } 15996d851c4SStanislav Kinsbursky 160*97a32539SAlexey Dobriyan static const struct proc_ops exports_proc_ops = { 161*97a32539SAlexey Dobriyan .proc_open = exports_proc_open, 162*97a32539SAlexey Dobriyan .proc_read = seq_read, 163*97a32539SAlexey Dobriyan .proc_lseek = seq_lseek, 164*97a32539SAlexey Dobriyan .proc_release = seq_release, 16596d851c4SStanislav Kinsbursky }; 16696d851c4SStanislav Kinsbursky 16796d851c4SStanislav Kinsbursky static int exports_nfsd_open(struct inode *inode, struct file *file) 16896d851c4SStanislav Kinsbursky { 16996d851c4SStanislav Kinsbursky return exports_net_open(inode->i_sb->s_fs_info, file); 17096d851c4SStanislav Kinsbursky } 17196d851c4SStanislav Kinsbursky 17296d851c4SStanislav Kinsbursky static const struct file_operations exports_nfsd_operations = { 17396d851c4SStanislav Kinsbursky .open = exports_nfsd_open, 1741da177e4SLinus Torvalds .read = seq_read, 1751da177e4SLinus Torvalds .llseek = seq_lseek, 1761da177e4SLinus Torvalds .release = seq_release, 1771da177e4SLinus Torvalds }; 1781da177e4SLinus Torvalds 179e8e8753fSJ. Bruce Fields static int export_features_show(struct seq_file *m, void *v) 180e8e8753fSJ. Bruce Fields { 181e8e8753fSJ. Bruce Fields seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); 182e8e8753fSJ. Bruce Fields return 0; 183e8e8753fSJ. Bruce Fields } 184e8e8753fSJ. Bruce Fields 185e8e8753fSJ. Bruce Fields static int export_features_open(struct inode *inode, struct file *file) 186e8e8753fSJ. Bruce Fields { 187e8e8753fSJ. Bruce Fields return single_open(file, export_features_show, NULL); 188e8e8753fSJ. Bruce Fields } 189e8e8753fSJ. Bruce Fields 19075ef9de1SAl Viro static const struct file_operations export_features_operations = { 191e8e8753fSJ. Bruce Fields .open = export_features_open, 192e8e8753fSJ. Bruce Fields .read = seq_read, 193e8e8753fSJ. Bruce Fields .llseek = seq_lseek, 194e8e8753fSJ. Bruce Fields .release = single_release, 195e8e8753fSJ. Bruce Fields }; 196e8e8753fSJ. Bruce Fields 197b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 198b0b0c0a2SKevin Coffman static int supported_enctypes_show(struct seq_file *m, void *v) 199b0b0c0a2SKevin Coffman { 200b084f598SJ. Bruce Fields seq_printf(m, KRB5_SUPPORTED_ENCTYPES); 201b0b0c0a2SKevin Coffman return 0; 202b0b0c0a2SKevin Coffman } 203b0b0c0a2SKevin Coffman 204b0b0c0a2SKevin Coffman static int supported_enctypes_open(struct inode *inode, struct file *file) 205b0b0c0a2SKevin Coffman { 206b0b0c0a2SKevin Coffman return single_open(file, supported_enctypes_show, NULL); 207b0b0c0a2SKevin Coffman } 208b0b0c0a2SKevin Coffman 20975ef9de1SAl Viro static const struct file_operations supported_enctypes_ops = { 210b0b0c0a2SKevin Coffman .open = supported_enctypes_open, 211b0b0c0a2SKevin Coffman .read = seq_read, 212b0b0c0a2SKevin Coffman .llseek = seq_lseek, 213b0b0c0a2SKevin Coffman .release = single_release, 214b0b0c0a2SKevin Coffman }; 215b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 216b0b0c0a2SKevin Coffman 217828c0950SAlexey Dobriyan static const struct file_operations pool_stats_operations = { 21803cf6c9fSGreg Banks .open = nfsd_pool_stats_open, 21903cf6c9fSGreg Banks .read = seq_read, 22003cf6c9fSGreg Banks .llseek = seq_lseek, 221ed2d8aedSRyusei Yamaguchi .release = nfsd_pool_stats_release, 22203cf6c9fSGreg Banks }; 22303cf6c9fSGreg Banks 2247ba630f5SJulia Lawall static const struct file_operations reply_cache_stats_operations = { 225a2f999a3SJeff Layton .open = nfsd_reply_cache_stats_open, 226a2f999a3SJeff Layton .read = seq_read, 227a2f999a3SJeff Layton .llseek = seq_lseek, 228a2f999a3SJeff Layton .release = single_release, 229a2f999a3SJeff Layton }; 230a2f999a3SJeff Layton 2311da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 2321da177e4SLinus Torvalds /* 2331da177e4SLinus Torvalds * payload - write methods 2341da177e4SLinus Torvalds */ 2351da177e4SLinus Torvalds 236244c7d44SAl Viro static inline struct net *netns(struct file *file) 237244c7d44SAl Viro { 238244c7d44SAl Viro return file_inode(file)->i_sb->s_fs_info; 239244c7d44SAl Viro } 2401da177e4SLinus Torvalds 241262a0982SChuck Lever /** 242262a0982SChuck Lever * write_unlock_ip - Release all locks used by a client 243262a0982SChuck Lever * 244262a0982SChuck Lever * Experimental. 245262a0982SChuck Lever * 246262a0982SChuck Lever * Input: 247262a0982SChuck Lever * buf: '\n'-terminated C string containing a 2484116092bSChuck Lever * presentation format IP address 249262a0982SChuck Lever * size: length of C string in @buf 250262a0982SChuck Lever * Output: 251262a0982SChuck Lever * On success: returns zero if all specified locks were released; 252262a0982SChuck Lever * returns one if one or more locks were not released 253262a0982SChuck Lever * On error: return code is negative errno value 254262a0982SChuck Lever */ 255b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) 2564373ea84SWendy Cheng { 2574116092bSChuck Lever struct sockaddr_storage address; 2584116092bSChuck Lever struct sockaddr *sap = (struct sockaddr *)&address; 2594116092bSChuck Lever size_t salen = sizeof(address); 260367c8c7bSChuck Lever char *fo_path; 261244c7d44SAl Viro struct net *net = netns(file); 2624373ea84SWendy Cheng 2634373ea84SWendy Cheng /* sanity check */ 2644373ea84SWendy Cheng if (size == 0) 2654373ea84SWendy Cheng return -EINVAL; 2664373ea84SWendy Cheng 2674373ea84SWendy Cheng if (buf[size-1] != '\n') 2684373ea84SWendy Cheng return -EINVAL; 2694373ea84SWendy Cheng 2704373ea84SWendy Cheng fo_path = buf; 2714373ea84SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 2724373ea84SWendy Cheng return -EINVAL; 2734373ea84SWendy Cheng 27411f77942SStanislav Kinsbursky if (rpc_pton(net, fo_path, size, sap, salen) == 0) 2754373ea84SWendy Cheng return -EINVAL; 2764373ea84SWendy Cheng 2774116092bSChuck Lever return nlmsvc_unlock_all_by_ip(sap); 2784373ea84SWendy Cheng } 2794373ea84SWendy Cheng 280262a0982SChuck Lever /** 281262a0982SChuck Lever * write_unlock_fs - Release all locks on a local file system 282262a0982SChuck Lever * 283262a0982SChuck Lever * Experimental. 284262a0982SChuck Lever * 285262a0982SChuck Lever * Input: 286262a0982SChuck Lever * buf: '\n'-terminated C string containing the 287262a0982SChuck Lever * absolute pathname of a local file system 288262a0982SChuck Lever * size: length of C string in @buf 289262a0982SChuck Lever * Output: 290262a0982SChuck Lever * On success: returns zero if all specified locks were released; 291262a0982SChuck Lever * returns one if one or more locks were not released 292262a0982SChuck Lever * On error: return code is negative errno value 293262a0982SChuck Lever */ 294b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) 29517efa372SWendy Cheng { 296a63bb996SAl Viro struct path path; 29717efa372SWendy Cheng char *fo_path; 29817efa372SWendy Cheng int error; 29917efa372SWendy Cheng 30017efa372SWendy Cheng /* sanity check */ 30117efa372SWendy Cheng if (size == 0) 30217efa372SWendy Cheng return -EINVAL; 30317efa372SWendy Cheng 30417efa372SWendy Cheng if (buf[size-1] != '\n') 30517efa372SWendy Cheng return -EINVAL; 30617efa372SWendy Cheng 30717efa372SWendy Cheng fo_path = buf; 30817efa372SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 30917efa372SWendy Cheng return -EINVAL; 31017efa372SWendy Cheng 311a63bb996SAl Viro error = kern_path(fo_path, 0, &path); 31217efa372SWendy Cheng if (error) 31317efa372SWendy Cheng return error; 31417efa372SWendy Cheng 315262a0982SChuck Lever /* 316262a0982SChuck Lever * XXX: Needs better sanity checking. Otherwise we could end up 317262a0982SChuck Lever * releasing locks on the wrong file system. 318262a0982SChuck Lever * 319262a0982SChuck Lever * For example: 320262a0982SChuck Lever * 1. Does the path refer to a directory? 321262a0982SChuck Lever * 2. Is that directory a mount point, or 322262a0982SChuck Lever * 3. Is that directory the root of an exported file system? 323262a0982SChuck Lever */ 324d8c9584eSAl Viro error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb); 32517efa372SWendy Cheng 326a63bb996SAl Viro path_put(&path); 32717efa372SWendy Cheng return error; 32817efa372SWendy Cheng } 32917efa372SWendy Cheng 330262a0982SChuck Lever /** 331262a0982SChuck Lever * write_filehandle - Get a variable-length NFS file handle by path 332262a0982SChuck Lever * 333262a0982SChuck Lever * On input, the buffer contains a '\n'-terminated C string comprised of 334262a0982SChuck Lever * three alphanumeric words separated by whitespace. The string may 335262a0982SChuck Lever * contain escape sequences. 336262a0982SChuck Lever * 337262a0982SChuck Lever * Input: 338262a0982SChuck Lever * buf: 339262a0982SChuck Lever * domain: client domain name 340262a0982SChuck Lever * path: export pathname 341262a0982SChuck Lever * maxsize: numeric maximum size of 342262a0982SChuck Lever * @buf 343262a0982SChuck Lever * size: length of C string in @buf 344262a0982SChuck Lever * Output: 345262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 346262a0982SChuck Lever * string containing a ASCII hex text version 347262a0982SChuck Lever * of the NFS file handle; 348262a0982SChuck Lever * return code is the size in bytes of the string 349262a0982SChuck Lever * On error: return code is negative errno value 350262a0982SChuck Lever */ 3511da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size) 3521da177e4SLinus Torvalds { 3531da177e4SLinus Torvalds char *dname, *path; 354246d95baSAndrew Morton int uninitialized_var(maxsize); 3551da177e4SLinus Torvalds char *mesg = buf; 3561da177e4SLinus Torvalds int len; 3571da177e4SLinus Torvalds struct auth_domain *dom; 3581da177e4SLinus Torvalds struct knfsd_fh fh; 3591da177e4SLinus Torvalds 36087d26ea7SJ. Bruce Fields if (size == 0) 36187d26ea7SJ. Bruce Fields return -EINVAL; 36287d26ea7SJ. Bruce Fields 3631da177e4SLinus Torvalds if (buf[size-1] != '\n') 3641da177e4SLinus Torvalds return -EINVAL; 3651da177e4SLinus Torvalds buf[size-1] = 0; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds dname = mesg; 3681da177e4SLinus Torvalds len = qword_get(&mesg, dname, size); 36954224f04SChuck Lever if (len <= 0) 37054224f04SChuck Lever return -EINVAL; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds path = dname+len+1; 3731da177e4SLinus Torvalds len = qword_get(&mesg, path, size); 37454224f04SChuck Lever if (len <= 0) 37554224f04SChuck Lever return -EINVAL; 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvalds len = get_int(&mesg, &maxsize); 3781da177e4SLinus Torvalds if (len) 3791da177e4SLinus Torvalds return len; 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds if (maxsize < NFS_FHSIZE) 3821da177e4SLinus Torvalds return -EINVAL; 3833c7aa15dSKinglong Mee maxsize = min(maxsize, NFS3_FHSIZE); 3841da177e4SLinus Torvalds 3851da177e4SLinus Torvalds if (qword_get(&mesg, mesg, size)>0) 3861da177e4SLinus Torvalds return -EINVAL; 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds /* we have all the words, they are in buf.. */ 3891da177e4SLinus Torvalds dom = unix_domain_find(dname); 3901da177e4SLinus Torvalds if (!dom) 3911da177e4SLinus Torvalds return -ENOMEM; 3921da177e4SLinus Torvalds 393244c7d44SAl Viro len = exp_rootfh(netns(file), dom, path, &fh, maxsize); 3941da177e4SLinus Torvalds auth_domain_put(dom); 3951da177e4SLinus Torvalds if (len) 3961da177e4SLinus Torvalds return len; 3971da177e4SLinus Torvalds 39854224f04SChuck Lever mesg = buf; 39954224f04SChuck Lever len = SIMPLE_TRANSACTION_LIMIT; 4001da177e4SLinus Torvalds qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); 4011da177e4SLinus Torvalds mesg[-1] = '\n'; 4021da177e4SLinus Torvalds return mesg - buf; 4031da177e4SLinus Torvalds } 4041da177e4SLinus Torvalds 405262a0982SChuck Lever /** 406262a0982SChuck Lever * write_threads - Start NFSD, or report the current number of running threads 407262a0982SChuck Lever * 408262a0982SChuck Lever * Input: 409262a0982SChuck Lever * buf: ignored 410262a0982SChuck Lever * size: zero 411262a0982SChuck Lever * Output: 412262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 413262a0982SChuck Lever * string numeric value representing the number of 414262a0982SChuck Lever * running NFSD threads; 415262a0982SChuck Lever * return code is the size in bytes of the string 416262a0982SChuck Lever * On error: return code is zero 417262a0982SChuck Lever * 418262a0982SChuck Lever * OR 419262a0982SChuck Lever * 420262a0982SChuck Lever * Input: 421262a0982SChuck Lever * buf: C string containing an unsigned 422262a0982SChuck Lever * integer value representing the 423262a0982SChuck Lever * number of NFSD threads to start 424262a0982SChuck Lever * size: non-zero length of C string in @buf 425262a0982SChuck Lever * Output: 426262a0982SChuck Lever * On success: NFS service is started; 427262a0982SChuck Lever * passed-in buffer filled with '\n'-terminated C 428262a0982SChuck Lever * string numeric value representing the number of 429262a0982SChuck Lever * running NFSD threads; 430262a0982SChuck Lever * return code is the size in bytes of the string 431262a0982SChuck Lever * On error: return code is zero or a negative errno value 432262a0982SChuck Lever */ 4331da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size) 4341da177e4SLinus Torvalds { 4351da177e4SLinus Torvalds char *mesg = buf; 4361da177e4SLinus Torvalds int rv; 437244c7d44SAl Viro struct net *net = netns(file); 438d41a9417SStanislav Kinsbursky 4391da177e4SLinus Torvalds if (size > 0) { 4401da177e4SLinus Torvalds int newthreads; 4411da177e4SLinus Torvalds rv = get_int(&mesg, &newthreads); 4421da177e4SLinus Torvalds if (rv) 4431da177e4SLinus Torvalds return rv; 4441da177e4SLinus Torvalds if (newthreads < 0) 4451da177e4SLinus Torvalds return -EINVAL; 4464df493a2STrond Myklebust rv = nfsd_svc(newthreads, net, file->f_cred); 44782e12fe9SNeilBrown if (rv < 0) 4481da177e4SLinus Torvalds return rv; 44982e12fe9SNeilBrown } else 4509dd9845fSStanislav Kinsbursky rv = nfsd_nrthreads(net); 451e06b6405SChuck Lever 45282e12fe9SNeilBrown return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); 4531da177e4SLinus Torvalds } 4541da177e4SLinus Torvalds 455262a0982SChuck Lever /** 456262a0982SChuck Lever * write_pool_threads - Set or report the current number of threads per pool 457262a0982SChuck Lever * 458262a0982SChuck Lever * Input: 459262a0982SChuck Lever * buf: ignored 460262a0982SChuck Lever * size: zero 461262a0982SChuck Lever * 462262a0982SChuck Lever * OR 463262a0982SChuck Lever * 464262a0982SChuck Lever * Input: 465262a0982SChuck Lever * buf: C string containing whitespace- 466262a0982SChuck Lever * separated unsigned integer values 467262a0982SChuck Lever * representing the number of NFSD 468262a0982SChuck Lever * threads to start in each pool 469262a0982SChuck Lever * size: non-zero length of C string in @buf 470262a0982SChuck Lever * Output: 471262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 472262a0982SChuck Lever * string containing integer values representing the 473262a0982SChuck Lever * number of NFSD threads in each pool; 474262a0982SChuck Lever * return code is the size in bytes of the string 475262a0982SChuck Lever * On error: return code is zero or a negative errno value 476262a0982SChuck Lever */ 477eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) 478eed2965aSGreg Banks { 479eed2965aSGreg Banks /* if size > 0, look for an array of number of threads per node 480eed2965aSGreg Banks * and apply them then write out number of threads per node as reply 481eed2965aSGreg Banks */ 482eed2965aSGreg Banks char *mesg = buf; 483eed2965aSGreg Banks int i; 484eed2965aSGreg Banks int rv; 485eed2965aSGreg Banks int len; 486bedbdd8bSNeil Brown int npools; 487eed2965aSGreg Banks int *nthreads; 488244c7d44SAl Viro struct net *net = netns(file); 489eed2965aSGreg Banks 490bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 4919dd9845fSStanislav Kinsbursky npools = nfsd_nrpools(net); 492eed2965aSGreg Banks if (npools == 0) { 493eed2965aSGreg Banks /* 494eed2965aSGreg Banks * NFS is shut down. The admin can start it by 495eed2965aSGreg Banks * writing to the threads file but NOT the pool_threads 496eed2965aSGreg Banks * file, sorry. Report zero threads. 497eed2965aSGreg Banks */ 498bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 499eed2965aSGreg Banks strcpy(buf, "0\n"); 500eed2965aSGreg Banks return strlen(buf); 501eed2965aSGreg Banks } 502eed2965aSGreg Banks 503eed2965aSGreg Banks nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); 504bedbdd8bSNeil Brown rv = -ENOMEM; 505eed2965aSGreg Banks if (nthreads == NULL) 506bedbdd8bSNeil Brown goto out_free; 507eed2965aSGreg Banks 508eed2965aSGreg Banks if (size > 0) { 509eed2965aSGreg Banks for (i = 0; i < npools; i++) { 510eed2965aSGreg Banks rv = get_int(&mesg, &nthreads[i]); 511eed2965aSGreg Banks if (rv == -ENOENT) 512eed2965aSGreg Banks break; /* fewer numbers than pools */ 513eed2965aSGreg Banks if (rv) 514eed2965aSGreg Banks goto out_free; /* syntax error */ 515eed2965aSGreg Banks rv = -EINVAL; 516eed2965aSGreg Banks if (nthreads[i] < 0) 517eed2965aSGreg Banks goto out_free; 518eed2965aSGreg Banks } 5193938a0d5SStanislav Kinsbursky rv = nfsd_set_nrthreads(i, nthreads, net); 520eed2965aSGreg Banks if (rv) 521eed2965aSGreg Banks goto out_free; 522eed2965aSGreg Banks } 523eed2965aSGreg Banks 5249dd9845fSStanislav Kinsbursky rv = nfsd_get_nrthreads(npools, nthreads, net); 525eed2965aSGreg Banks if (rv) 526eed2965aSGreg Banks goto out_free; 527eed2965aSGreg Banks 528eed2965aSGreg Banks mesg = buf; 529eed2965aSGreg Banks size = SIMPLE_TRANSACTION_LIMIT; 530eed2965aSGreg Banks for (i = 0; i < npools && size > 0; i++) { 531eed2965aSGreg Banks snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); 532eed2965aSGreg Banks len = strlen(mesg); 533eed2965aSGreg Banks size -= len; 534eed2965aSGreg Banks mesg += len; 535eed2965aSGreg Banks } 536413d63d7SJ. Bruce Fields rv = mesg - buf; 537eed2965aSGreg Banks out_free: 538eed2965aSGreg Banks kfree(nthreads); 539bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 540eed2965aSGreg Banks return rv; 541eed2965aSGreg Banks } 542eed2965aSGreg Banks 543ff7d1179STrond Myklebust static ssize_t 544e333f3bbSTrond Myklebust nfsd_print_version_support(struct nfsd_net *nn, char *buf, int remaining, 545e333f3bbSTrond Myklebust const char *sep, unsigned vers, int minor) 546ff7d1179STrond Myklebust { 547abcb4dacSNeilBrown const char *format = minor < 0 ? "%s%c%u" : "%s%c%u.%u"; 548e333f3bbSTrond Myklebust bool supported = !!nfsd_vers(nn, vers, NFSD_TEST); 549ff7d1179STrond Myklebust 550abcb4dacSNeilBrown if (vers == 4 && minor >= 0 && 551e333f3bbSTrond Myklebust !nfsd_minorversion(nn, minor, NFSD_TEST)) 552ff7d1179STrond Myklebust supported = false; 553abcb4dacSNeilBrown if (minor == 0 && supported) 554abcb4dacSNeilBrown /* 555abcb4dacSNeilBrown * special case for backward compatability. 556abcb4dacSNeilBrown * +4.0 is never reported, it is implied by 557abcb4dacSNeilBrown * +4, unless -4.0 is present. 558abcb4dacSNeilBrown */ 559abcb4dacSNeilBrown return 0; 560ff7d1179STrond Myklebust return snprintf(buf, remaining, format, sep, 561ff7d1179STrond Myklebust supported ? '+' : '-', vers, minor); 562ff7d1179STrond Myklebust } 563ff7d1179STrond Myklebust 5643dd98a3bSJeff Layton static ssize_t __write_versions(struct file *file, char *buf, size_t size) 56570c3b76cSNeilBrown { 56670c3b76cSNeilBrown char *mesg = buf; 5678daf220aSBenny Halevy char *vers, *minorp, sign; 568261758b5SChuck Lever int len, num, remaining; 56970c3b76cSNeilBrown ssize_t tlen = 0; 57070c3b76cSNeilBrown char *sep; 571244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 57270c3b76cSNeilBrown 57370c3b76cSNeilBrown if (size>0) { 5749dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 5756658d3a7SNeilBrown /* Cannot change versions without updating 5769dd9845fSStanislav Kinsbursky * nn->nfsd_serv->sv_xdrsize, and reallocing 5776658d3a7SNeilBrown * rq_argp and rq_resp 5786658d3a7SNeilBrown */ 57970c3b76cSNeilBrown return -EBUSY; 58070c3b76cSNeilBrown if (buf[size-1] != '\n') 58170c3b76cSNeilBrown return -EINVAL; 58270c3b76cSNeilBrown buf[size-1] = 0; 58370c3b76cSNeilBrown 58470c3b76cSNeilBrown vers = mesg; 58570c3b76cSNeilBrown len = qword_get(&mesg, vers, size); 58670c3b76cSNeilBrown if (len <= 0) return -EINVAL; 58770c3b76cSNeilBrown do { 588d3635ff0STrond Myklebust enum vers_op cmd; 589abcb4dacSNeilBrown unsigned minor; 59070c3b76cSNeilBrown sign = *vers; 59170c3b76cSNeilBrown if (sign == '+' || sign == '-') 5928daf220aSBenny Halevy num = simple_strtol((vers+1), &minorp, 0); 59370c3b76cSNeilBrown else 5948daf220aSBenny Halevy num = simple_strtol(vers, &minorp, 0); 5958daf220aSBenny Halevy if (*minorp == '.') { 596ff89be87SJ. Bruce Fields if (num != 4) 5978daf220aSBenny Halevy return -EINVAL; 598e35659f1SNeilBrown if (kstrtouint(minorp+1, 0, &minor) < 0) 5998daf220aSBenny Halevy return -EINVAL; 600abcb4dacSNeilBrown } 601abcb4dacSNeilBrown 602d3635ff0STrond Myklebust cmd = sign == '-' ? NFSD_CLEAR : NFSD_SET; 60370c3b76cSNeilBrown switch(num) { 60470c3b76cSNeilBrown case 2: 60570c3b76cSNeilBrown case 3: 606e333f3bbSTrond Myklebust nfsd_vers(nn, num, cmd); 607d3635ff0STrond Myklebust break; 60870c3b76cSNeilBrown case 4: 609abcb4dacSNeilBrown if (*minorp == '.') { 610e333f3bbSTrond Myklebust if (nfsd_minorversion(nn, minor, cmd) < 0) 611abcb4dacSNeilBrown return -EINVAL; 612e333f3bbSTrond Myklebust } else if ((cmd == NFSD_SET) != nfsd_vers(nn, num, NFSD_TEST)) { 613abcb4dacSNeilBrown /* 614abcb4dacSNeilBrown * Either we have +4 and no minors are enabled, 615abcb4dacSNeilBrown * or we have -4 and at least one minor is enabled. 616abcb4dacSNeilBrown * In either case, propagate 'cmd' to all minors. 617abcb4dacSNeilBrown */ 618abcb4dacSNeilBrown minor = 0; 619e333f3bbSTrond Myklebust while (nfsd_minorversion(nn, minor, cmd) >= 0) 620abcb4dacSNeilBrown minor++; 621abcb4dacSNeilBrown } 62270c3b76cSNeilBrown break; 62370c3b76cSNeilBrown default: 62470c3b76cSNeilBrown return -EINVAL; 62570c3b76cSNeilBrown } 62670c3b76cSNeilBrown vers += len + 1; 62770c3b76cSNeilBrown } while ((len = qword_get(&mesg, vers, size)) > 0); 62870c3b76cSNeilBrown /* If all get turned off, turn them back on, as 62970c3b76cSNeilBrown * having no versions is BAD 63070c3b76cSNeilBrown */ 631e333f3bbSTrond Myklebust nfsd_reset_versions(nn); 63270c3b76cSNeilBrown } 633261758b5SChuck Lever 63470c3b76cSNeilBrown /* Now write current state into reply buffer */ 63570c3b76cSNeilBrown len = 0; 63670c3b76cSNeilBrown sep = ""; 637261758b5SChuck Lever remaining = SIMPLE_TRANSACTION_LIMIT; 638ff7d1179STrond Myklebust for (num=2 ; num <= 4 ; num++) { 639abcb4dacSNeilBrown int minor; 640e333f3bbSTrond Myklebust if (!nfsd_vers(nn, num, NFSD_AVAIL)) 641e35659f1SNeilBrown continue; 642abcb4dacSNeilBrown 643abcb4dacSNeilBrown minor = -1; 644ff7d1179STrond Myklebust do { 645e333f3bbSTrond Myklebust len = nfsd_print_version_support(nn, buf, remaining, 646ff7d1179STrond Myklebust sep, num, minor); 647818f2f57SDan Carpenter if (len >= remaining) 648ff7d1179STrond Myklebust goto out; 649261758b5SChuck Lever remaining -= len; 650261758b5SChuck Lever buf += len; 651261758b5SChuck Lever tlen += len; 652ff7d1179STrond Myklebust minor++; 653abcb4dacSNeilBrown if (len) 654ff7d1179STrond Myklebust sep = " "; 655ff7d1179STrond Myklebust } while (num == 4 && minor <= NFSD_SUPPORTED_MINOR_VERSION); 656261758b5SChuck Lever } 657ff7d1179STrond Myklebust out: 658261758b5SChuck Lever len = snprintf(buf, remaining, "\n"); 659818f2f57SDan Carpenter if (len >= remaining) 660261758b5SChuck Lever return -EINVAL; 661261758b5SChuck Lever return tlen + len; 66270c3b76cSNeilBrown } 66370c3b76cSNeilBrown 664262a0982SChuck Lever /** 665262a0982SChuck Lever * write_versions - Set or report the available NFS protocol versions 666262a0982SChuck Lever * 667262a0982SChuck Lever * Input: 668262a0982SChuck Lever * buf: ignored 669262a0982SChuck Lever * size: zero 670262a0982SChuck Lever * Output: 671262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 672262a0982SChuck Lever * string containing positive or negative integer 673262a0982SChuck Lever * values representing the current status of each 674262a0982SChuck Lever * protocol version; 675262a0982SChuck Lever * return code is the size in bytes of the string 676262a0982SChuck Lever * On error: return code is zero or a negative errno value 677262a0982SChuck Lever * 678262a0982SChuck Lever * OR 679262a0982SChuck Lever * 680262a0982SChuck Lever * Input: 681262a0982SChuck Lever * buf: C string containing whitespace- 682262a0982SChuck Lever * separated positive or negative 683262a0982SChuck Lever * integer values representing NFS 684262a0982SChuck Lever * protocol versions to enable ("+n") 685262a0982SChuck Lever * or disable ("-n") 686262a0982SChuck Lever * size: non-zero length of C string in @buf 687262a0982SChuck Lever * Output: 688262a0982SChuck Lever * On success: status of zero or more protocol versions has 689262a0982SChuck Lever * been updated; passed-in buffer filled with 690262a0982SChuck Lever * '\n'-terminated C string containing positive 691262a0982SChuck Lever * or negative integer values representing the 692262a0982SChuck Lever * current status of each protocol version; 693262a0982SChuck Lever * return code is the size in bytes of the string 694262a0982SChuck Lever * On error: return code is zero or a negative errno value 695262a0982SChuck Lever */ 6963dd98a3bSJeff Layton static ssize_t write_versions(struct file *file, char *buf, size_t size) 6973dd98a3bSJeff Layton { 6983dd98a3bSJeff Layton ssize_t rv; 6993dd98a3bSJeff Layton 7003dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 7013dd98a3bSJeff Layton rv = __write_versions(file, buf, size); 7023dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 7033dd98a3bSJeff Layton return rv; 7043dd98a3bSJeff Layton } 7053dd98a3bSJeff Layton 7064cd5dc75SChuck Lever /* 7070a5372d8SChuck Lever * Zero-length write. Return a list of NFSD's current listener 7080a5372d8SChuck Lever * transports. 7090a5372d8SChuck Lever */ 7109dd9845fSStanislav Kinsbursky static ssize_t __write_ports_names(char *buf, struct net *net) 7110a5372d8SChuck Lever { 7129dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7139dd9845fSStanislav Kinsbursky 7149dd9845fSStanislav Kinsbursky if (nn->nfsd_serv == NULL) 7150a5372d8SChuck Lever return 0; 7169dd9845fSStanislav Kinsbursky return svc_xprt_names(nn->nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); 7170a5372d8SChuck Lever } 7180a5372d8SChuck Lever 7190a5372d8SChuck Lever /* 7200b7c2f6fSChuck Lever * A single 'fd' number was written, in which case it must be for 7210b7c2f6fSChuck Lever * a socket of a supported family/protocol, and we use it as an 7220b7c2f6fSChuck Lever * nfsd listener. 7230b7c2f6fSChuck Lever */ 7244df493a2STrond Myklebust static ssize_t __write_ports_addfd(char *buf, struct net *net, const struct cred *cred) 7250b7c2f6fSChuck Lever { 7260b7c2f6fSChuck Lever char *mesg = buf; 7270b7c2f6fSChuck Lever int fd, err; 7289dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7290b7c2f6fSChuck Lever 7300b7c2f6fSChuck Lever err = get_int(&mesg, &fd); 7310b7c2f6fSChuck Lever if (err != 0 || fd < 0) 7320b7c2f6fSChuck Lever return -EINVAL; 7330b7c2f6fSChuck Lever 73430646394SStanislav Kinsbursky if (svc_alien_sock(net, fd)) { 73530646394SStanislav Kinsbursky printk(KERN_ERR "%s: socket net is different to NFSd's one\n", __func__); 73630646394SStanislav Kinsbursky return -EINVAL; 73730646394SStanislav Kinsbursky } 73830646394SStanislav Kinsbursky 7396777436bSStanislav Kinsbursky err = nfsd_create_serv(net); 7400b7c2f6fSChuck Lever if (err != 0) 7410b7c2f6fSChuck Lever return err; 7420b7c2f6fSChuck Lever 7434df493a2STrond Myklebust err = svc_addsock(nn->nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT, cred); 74478a8d7c8SJeff Layton if (err < 0) { 74519f7e2caSStanislav Kinsbursky nfsd_destroy(net); 74678a8d7c8SJeff Layton return err; 74778a8d7c8SJeff Layton } 748ea068badSChuck Lever 7490b7c2f6fSChuck Lever /* Decrease the count, but don't shut down the service */ 7509dd9845fSStanislav Kinsbursky nn->nfsd_serv->sv_nrthreads--; 751ea068badSChuck Lever return err; 7520b7c2f6fSChuck Lever } 7530b7c2f6fSChuck Lever 7540b7c2f6fSChuck Lever /* 7554eb68c26SChuck Lever * A transport listener is added by writing it's transport name and 7564eb68c26SChuck Lever * a port number. 7574eb68c26SChuck Lever */ 7584df493a2STrond Myklebust static ssize_t __write_ports_addxprt(char *buf, struct net *net, const struct cred *cred) 7594eb68c26SChuck Lever { 7604eb68c26SChuck Lever char transport[16]; 76137498292SChuck Lever struct svc_xprt *xprt; 7624eb68c26SChuck Lever int port, err; 7639dd9845fSStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 7644eb68c26SChuck Lever 765a10fded1SJ. Bruce Fields if (sscanf(buf, "%15s %5u", transport, &port) != 2) 7664eb68c26SChuck Lever return -EINVAL; 7674eb68c26SChuck Lever 7684be929beSAlexey Dobriyan if (port < 1 || port > USHRT_MAX) 7694eb68c26SChuck Lever return -EINVAL; 7704eb68c26SChuck Lever 7716777436bSStanislav Kinsbursky err = nfsd_create_serv(net); 7724eb68c26SChuck Lever if (err != 0) 7734eb68c26SChuck Lever return err; 7744eb68c26SChuck Lever 7759dd9845fSStanislav Kinsbursky err = svc_create_xprt(nn->nfsd_serv, transport, net, 7764df493a2STrond Myklebust PF_INET, port, SVC_SOCK_ANONYMOUS, cred); 77768717908SChuck Lever if (err < 0) 77837498292SChuck Lever goto out_err; 77937498292SChuck Lever 7809dd9845fSStanislav Kinsbursky err = svc_create_xprt(nn->nfsd_serv, transport, net, 7814df493a2STrond Myklebust PF_INET6, port, SVC_SOCK_ANONYMOUS, cred); 78237498292SChuck Lever if (err < 0 && err != -EAFNOSUPPORT) 78337498292SChuck Lever goto out_close; 7840cd14a06SJeff Layton 7850cd14a06SJeff Layton /* Decrease the count, but don't shut down the service */ 7869dd9845fSStanislav Kinsbursky nn->nfsd_serv->sv_nrthreads--; 7874eb68c26SChuck Lever return 0; 78837498292SChuck Lever out_close: 7899dd9845fSStanislav Kinsbursky xprt = svc_find_xprt(nn->nfsd_serv, transport, net, PF_INET, port); 79037498292SChuck Lever if (xprt != NULL) { 79137498292SChuck Lever svc_close_xprt(xprt); 79237498292SChuck Lever svc_xprt_put(xprt); 79337498292SChuck Lever } 79437498292SChuck Lever out_err: 79519f7e2caSStanislav Kinsbursky nfsd_destroy(net); 79637498292SChuck Lever return err; 7974eb68c26SChuck Lever } 7984eb68c26SChuck Lever 79908160352SStanislav Kinsbursky static ssize_t __write_ports(struct file *file, char *buf, size_t size, 80008160352SStanislav Kinsbursky struct net *net) 80180212d59SNeilBrown { 8020a5372d8SChuck Lever if (size == 0) 8039dd9845fSStanislav Kinsbursky return __write_ports_names(buf, net); 8040b7c2f6fSChuck Lever 8050b7c2f6fSChuck Lever if (isdigit(buf[0])) 8064df493a2STrond Myklebust return __write_ports_addfd(buf, net, file->f_cred); 80782d56591SChuck Lever 8084eb68c26SChuck Lever if (isalpha(buf[0])) 8094df493a2STrond Myklebust return __write_ports_addxprt(buf, net, file->f_cred); 8104cd5dc75SChuck Lever 811b41b66d6SNeilBrown return -EINVAL; 812b41b66d6SNeilBrown } 81380212d59SNeilBrown 814262a0982SChuck Lever /** 815262a0982SChuck Lever * write_ports - Pass a socket file descriptor or transport name to listen on 816262a0982SChuck Lever * 817262a0982SChuck Lever * Input: 818262a0982SChuck Lever * buf: ignored 819262a0982SChuck Lever * size: zero 820262a0982SChuck Lever * Output: 821262a0982SChuck Lever * On success: passed-in buffer filled with a '\n'-terminated C 822262a0982SChuck Lever * string containing a whitespace-separated list of 823262a0982SChuck Lever * named NFSD listeners; 824262a0982SChuck Lever * return code is the size in bytes of the string 825262a0982SChuck Lever * On error: return code is zero or a negative errno value 826262a0982SChuck Lever * 827262a0982SChuck Lever * OR 828262a0982SChuck Lever * 829262a0982SChuck Lever * Input: 830262a0982SChuck Lever * buf: C string containing an unsigned 831262a0982SChuck Lever * integer value representing a bound 832262a0982SChuck Lever * but unconnected socket that is to be 833c71206a7SChuck Lever * used as an NFSD listener; listen(3) 834c71206a7SChuck Lever * must be called for a SOCK_STREAM 835c71206a7SChuck Lever * socket, otherwise it is ignored 836262a0982SChuck Lever * size: non-zero length of C string in @buf 837262a0982SChuck Lever * Output: 838262a0982SChuck Lever * On success: NFS service is started; 839262a0982SChuck Lever * passed-in buffer filled with a '\n'-terminated C 840262a0982SChuck Lever * string containing a unique alphanumeric name of 841262a0982SChuck Lever * the listener; 842262a0982SChuck Lever * return code is the size in bytes of the string 843262a0982SChuck Lever * On error: return code is a negative errno value 844262a0982SChuck Lever * 845262a0982SChuck Lever * OR 846262a0982SChuck Lever * 847262a0982SChuck Lever * Input: 848262a0982SChuck Lever * buf: C string containing a transport 849262a0982SChuck Lever * name and an unsigned integer value 850262a0982SChuck Lever * representing the port to listen on, 851262a0982SChuck Lever * separated by whitespace 852262a0982SChuck Lever * size: non-zero length of C string in @buf 853262a0982SChuck Lever * Output: 854262a0982SChuck Lever * On success: returns zero; NFS service is started 855262a0982SChuck Lever * On error: return code is a negative errno value 856262a0982SChuck Lever */ 857bedbdd8bSNeil Brown static ssize_t write_ports(struct file *file, char *buf, size_t size) 858bedbdd8bSNeil Brown { 859bedbdd8bSNeil Brown ssize_t rv; 8603dd98a3bSJeff Layton 861bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 862244c7d44SAl Viro rv = __write_ports(file, buf, size, netns(file)); 863bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 864bedbdd8bSNeil Brown return rv; 865bedbdd8bSNeil Brown } 866bedbdd8bSNeil Brown 867bedbdd8bSNeil Brown 868596bbe53SNeilBrown int nfsd_max_blksize; 869596bbe53SNeilBrown 870262a0982SChuck Lever /** 871262a0982SChuck Lever * write_maxblksize - Set or report the current NFS blksize 872262a0982SChuck Lever * 873262a0982SChuck Lever * Input: 874262a0982SChuck Lever * buf: ignored 875262a0982SChuck Lever * size: zero 876262a0982SChuck Lever * 877262a0982SChuck Lever * OR 878262a0982SChuck Lever * 879262a0982SChuck Lever * Input: 880262a0982SChuck Lever * buf: C string containing an unsigned 881262a0982SChuck Lever * integer value representing the new 882262a0982SChuck Lever * NFS blksize 883262a0982SChuck Lever * size: non-zero length of C string in @buf 884262a0982SChuck Lever * Output: 885262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 886262a0982SChuck Lever * containing numeric value of the current NFS blksize 887262a0982SChuck Lever * setting; 888262a0982SChuck Lever * return code is the size in bytes of the string 889262a0982SChuck Lever * On error: return code is zero or a negative errno value 890262a0982SChuck Lever */ 891596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) 892596bbe53SNeilBrown { 893596bbe53SNeilBrown char *mesg = buf; 894244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 8959dd9845fSStanislav Kinsbursky 896596bbe53SNeilBrown if (size > 0) { 897596bbe53SNeilBrown int bsize; 898596bbe53SNeilBrown int rv = get_int(&mesg, &bsize); 899596bbe53SNeilBrown if (rv) 900596bbe53SNeilBrown return rv; 901596bbe53SNeilBrown /* force bsize into allowed range and 902596bbe53SNeilBrown * required alignment. 903596bbe53SNeilBrown */ 9043c7aa15dSKinglong Mee bsize = max_t(int, bsize, 1024); 9053c7aa15dSKinglong Mee bsize = min_t(int, bsize, NFSSVC_MAXBLKSIZE); 906596bbe53SNeilBrown bsize &= ~(1024-1); 907bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 9089dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) { 909bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 910596bbe53SNeilBrown return -EBUSY; 911596bbe53SNeilBrown } 912596bbe53SNeilBrown nfsd_max_blksize = bsize; 913bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 914596bbe53SNeilBrown } 915e06b6405SChuck Lever 916e06b6405SChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", 917e06b6405SChuck Lever nfsd_max_blksize); 918596bbe53SNeilBrown } 919596bbe53SNeilBrown 9205b8db00bSJeff Layton /** 9215b8db00bSJeff Layton * write_maxconn - Set or report the current max number of connections 9225b8db00bSJeff Layton * 9235b8db00bSJeff Layton * Input: 9245b8db00bSJeff Layton * buf: ignored 9255b8db00bSJeff Layton * size: zero 9265b8db00bSJeff Layton * OR 9275b8db00bSJeff Layton * 9285b8db00bSJeff Layton * Input: 9295b8db00bSJeff Layton * buf: C string containing an unsigned 9305b8db00bSJeff Layton * integer value representing the new 9315b8db00bSJeff Layton * number of max connections 9325b8db00bSJeff Layton * size: non-zero length of C string in @buf 9335b8db00bSJeff Layton * Output: 9345b8db00bSJeff Layton * On success: passed-in buffer filled with '\n'-terminated C string 9355b8db00bSJeff Layton * containing numeric value of max_connections setting 9365b8db00bSJeff Layton * for this net namespace; 9375b8db00bSJeff Layton * return code is the size in bytes of the string 9385b8db00bSJeff Layton * On error: return code is zero or a negative errno value 9395b8db00bSJeff Layton */ 9405b8db00bSJeff Layton static ssize_t write_maxconn(struct file *file, char *buf, size_t size) 9415b8db00bSJeff Layton { 9425b8db00bSJeff Layton char *mesg = buf; 943244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 9445b8db00bSJeff Layton unsigned int maxconn = nn->max_connections; 9455b8db00bSJeff Layton 9465b8db00bSJeff Layton if (size > 0) { 9475b8db00bSJeff Layton int rv = get_uint(&mesg, &maxconn); 9485b8db00bSJeff Layton 9495b8db00bSJeff Layton if (rv) 9505b8db00bSJeff Layton return rv; 9515b8db00bSJeff Layton nn->max_connections = maxconn; 9525b8db00bSJeff Layton } 9535b8db00bSJeff Layton 9545b8db00bSJeff Layton return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%u\n", maxconn); 9555b8db00bSJeff Layton } 9565b8db00bSJeff Layton 95770c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 9589dd9845fSStanislav Kinsbursky static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, 9599dd9845fSStanislav Kinsbursky time_t *time, struct nfsd_net *nn) 9601da177e4SLinus Torvalds { 9611da177e4SLinus Torvalds char *mesg = buf; 962f0135740SJ. Bruce Fields int rv, i; 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds if (size > 0) { 9659dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 9663dd98a3bSJeff Layton return -EBUSY; 967f0135740SJ. Bruce Fields rv = get_int(&mesg, &i); 9681da177e4SLinus Torvalds if (rv) 9691da177e4SLinus Torvalds return rv; 970e7b184f1SJ. Bruce Fields /* 971e7b184f1SJ. Bruce Fields * Some sanity checking. We don't have a reason for 972e7b184f1SJ. Bruce Fields * these particular numbers, but problems with the 973e7b184f1SJ. Bruce Fields * extremes are: 974e7b184f1SJ. Bruce Fields * - Too short: the briefest network outage may 975e7b184f1SJ. Bruce Fields * cause clients to lose all their locks. Also, 976e7b184f1SJ. Bruce Fields * the frequent polling may be wasteful. 977e7b184f1SJ. Bruce Fields * - Too long: do you really want reboot recovery 978e7b184f1SJ. Bruce Fields * to take more than an hour? Or to make other 979e7b184f1SJ. Bruce Fields * clients wait an hour before being able to 980e7b184f1SJ. Bruce Fields * revoke a dead client's locks? 981e7b184f1SJ. Bruce Fields */ 982f0135740SJ. Bruce Fields if (i < 10 || i > 3600) 9831da177e4SLinus Torvalds return -EINVAL; 984f0135740SJ. Bruce Fields *time = i; 9851da177e4SLinus Torvalds } 986e06b6405SChuck Lever 987f0135740SJ. Bruce Fields return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time); 988f0135740SJ. Bruce Fields } 989f0135740SJ. Bruce Fields 9909dd9845fSStanislav Kinsbursky static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, 9919dd9845fSStanislav Kinsbursky time_t *time, struct nfsd_net *nn) 992f0135740SJ. Bruce Fields { 993f0135740SJ. Bruce Fields ssize_t rv; 994f0135740SJ. Bruce Fields 995f0135740SJ. Bruce Fields mutex_lock(&nfsd_mutex); 9969dd9845fSStanislav Kinsbursky rv = __nfsd4_write_time(file, buf, size, time, nn); 997f0135740SJ. Bruce Fields mutex_unlock(&nfsd_mutex); 998f0135740SJ. Bruce Fields return rv; 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 1001262a0982SChuck Lever /** 1002262a0982SChuck Lever * write_leasetime - Set or report the current NFSv4 lease time 1003262a0982SChuck Lever * 1004262a0982SChuck Lever * Input: 1005262a0982SChuck Lever * buf: ignored 1006262a0982SChuck Lever * size: zero 1007262a0982SChuck Lever * 1008262a0982SChuck Lever * OR 1009262a0982SChuck Lever * 1010262a0982SChuck Lever * Input: 1011262a0982SChuck Lever * buf: C string containing an unsigned 1012262a0982SChuck Lever * integer value representing the new 1013262a0982SChuck Lever * NFSv4 lease expiry time 1014262a0982SChuck Lever * size: non-zero length of C string in @buf 1015262a0982SChuck Lever * Output: 1016262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 1017262a0982SChuck Lever * string containing unsigned integer value of the 1018262a0982SChuck Lever * current lease expiry time; 1019262a0982SChuck Lever * return code is the size in bytes of the string 1020262a0982SChuck Lever * On error: return code is zero or a negative errno value 1021262a0982SChuck Lever */ 10223dd98a3bSJeff Layton static ssize_t write_leasetime(struct file *file, char *buf, size_t size) 10233dd98a3bSJeff Layton { 1024244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10259dd9845fSStanislav Kinsbursky return nfsd4_write_time(file, buf, size, &nn->nfsd4_lease, nn); 10263dd98a3bSJeff Layton } 10273dd98a3bSJeff Layton 1028efc4bb4fSJ. Bruce Fields /** 1029efc4bb4fSJ. Bruce Fields * write_gracetime - Set or report current NFSv4 grace period time 1030efc4bb4fSJ. Bruce Fields * 1031efc4bb4fSJ. Bruce Fields * As above, but sets the time of the NFSv4 grace period. 1032efc4bb4fSJ. Bruce Fields * 1033efc4bb4fSJ. Bruce Fields * Note this should never be set to less than the *previous* 1034efc4bb4fSJ. Bruce Fields * lease-period time, but we don't try to enforce this. (In the common 1035efc4bb4fSJ. Bruce Fields * case (a new boot), we don't know what the previous lease time was 1036efc4bb4fSJ. Bruce Fields * anyway.) 1037efc4bb4fSJ. Bruce Fields */ 1038efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size) 1039efc4bb4fSJ. Bruce Fields { 1040244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10419dd9845fSStanislav Kinsbursky return nfsd4_write_time(file, buf, size, &nn->nfsd4_grace, nn); 1042efc4bb4fSJ. Bruce Fields } 1043efc4bb4fSJ. Bruce Fields 10449dd9845fSStanislav Kinsbursky static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size, 10459dd9845fSStanislav Kinsbursky struct nfsd_net *nn) 10460964a3d3SNeilBrown { 10470964a3d3SNeilBrown char *mesg = buf; 10480964a3d3SNeilBrown char *recdir; 10490964a3d3SNeilBrown int len, status; 10500964a3d3SNeilBrown 10513dd98a3bSJeff Layton if (size > 0) { 10529dd9845fSStanislav Kinsbursky if (nn->nfsd_serv) 10533dd98a3bSJeff Layton return -EBUSY; 10543dd98a3bSJeff Layton if (size > PATH_MAX || buf[size-1] != '\n') 10550964a3d3SNeilBrown return -EINVAL; 10560964a3d3SNeilBrown buf[size-1] = 0; 10570964a3d3SNeilBrown 10580964a3d3SNeilBrown recdir = mesg; 10590964a3d3SNeilBrown len = qword_get(&mesg, recdir, size); 10600964a3d3SNeilBrown if (len <= 0) 10610964a3d3SNeilBrown return -EINVAL; 10620964a3d3SNeilBrown 10630964a3d3SNeilBrown status = nfs4_reset_recoverydir(recdir); 106469049961SAndi Kleen if (status) 106569049961SAndi Kleen return status; 10663dd98a3bSJeff Layton } 10673d72ab8fSChuck Lever 10683d72ab8fSChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", 10693d72ab8fSChuck Lever nfs4_recoverydir()); 10700964a3d3SNeilBrown } 10713dd98a3bSJeff Layton 1072262a0982SChuck Lever /** 1073262a0982SChuck Lever * write_recoverydir - Set or report the pathname of the recovery directory 1074262a0982SChuck Lever * 1075262a0982SChuck Lever * Input: 1076262a0982SChuck Lever * buf: ignored 1077262a0982SChuck Lever * size: zero 1078262a0982SChuck Lever * 1079262a0982SChuck Lever * OR 1080262a0982SChuck Lever * 1081262a0982SChuck Lever * Input: 1082262a0982SChuck Lever * buf: C string containing the pathname 1083262a0982SChuck Lever * of the directory on a local file 1084262a0982SChuck Lever * system containing permanent NFSv4 1085262a0982SChuck Lever * recovery data 1086262a0982SChuck Lever * size: non-zero length of C string in @buf 1087262a0982SChuck Lever * Output: 1088262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 1089262a0982SChuck Lever * containing the current recovery pathname setting; 1090262a0982SChuck Lever * return code is the size in bytes of the string 1091262a0982SChuck Lever * On error: return code is zero or a negative errno value 1092262a0982SChuck Lever */ 10933dd98a3bSJeff Layton static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) 10943dd98a3bSJeff Layton { 10953dd98a3bSJeff Layton ssize_t rv; 1096244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 10973dd98a3bSJeff Layton 10983dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 10999dd9845fSStanislav Kinsbursky rv = __write_recoverydir(file, buf, size, nn); 11003dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 11013dd98a3bSJeff Layton return rv; 11023dd98a3bSJeff Layton } 11033dd98a3bSJeff Layton 11047f5ef2e9SJeff Layton /** 11057f5ef2e9SJeff Layton * write_v4_end_grace - release grace period for nfsd's v4.x lock manager 11067f5ef2e9SJeff Layton * 11077f5ef2e9SJeff Layton * Input: 11087f5ef2e9SJeff Layton * buf: ignored 11097f5ef2e9SJeff Layton * size: zero 11107f5ef2e9SJeff Layton * OR 11117f5ef2e9SJeff Layton * 11127f5ef2e9SJeff Layton * Input: 11137f5ef2e9SJeff Layton * buf: any value 11147f5ef2e9SJeff Layton * size: non-zero length of C string in @buf 11157f5ef2e9SJeff Layton * Output: 11167f5ef2e9SJeff Layton * passed-in buffer filled with "Y" or "N" with a newline 11177f5ef2e9SJeff Layton * and NULL-terminated C string. This indicates whether 11187f5ef2e9SJeff Layton * the grace period has ended in the current net 11197f5ef2e9SJeff Layton * namespace. Return code is the size in bytes of the 11207f5ef2e9SJeff Layton * string. Writing a string that starts with 'Y', 'y', or 11217f5ef2e9SJeff Layton * '1' to the file will end the grace period for nfsd's v4 11227f5ef2e9SJeff Layton * lock manager. 11237f5ef2e9SJeff Layton */ 11247f5ef2e9SJeff Layton static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) 11257f5ef2e9SJeff Layton { 1126244c7d44SAl Viro struct nfsd_net *nn = net_generic(netns(file), nfsd_net_id); 11277f5ef2e9SJeff Layton 11287f5ef2e9SJeff Layton if (size > 0) { 11297f5ef2e9SJeff Layton switch(buf[0]) { 11307f5ef2e9SJeff Layton case 'Y': 11317f5ef2e9SJeff Layton case 'y': 11327f5ef2e9SJeff Layton case '1': 1133dd838821SYihao Wu if (!nn->nfsd_serv) 113462a063b8SJ. Bruce Fields return -EBUSY; 11357f5ef2e9SJeff Layton nfsd4_end_grace(nn); 11367f5ef2e9SJeff Layton break; 11377f5ef2e9SJeff Layton default: 11387f5ef2e9SJeff Layton return -EINVAL; 11397f5ef2e9SJeff Layton } 11407f5ef2e9SJeff Layton } 11417f5ef2e9SJeff Layton 11427f5ef2e9SJeff Layton return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%c\n", 11437f5ef2e9SJeff Layton nn->grace_ended ? 'Y' : 'N'); 11447f5ef2e9SJeff Layton } 11457f5ef2e9SJeff Layton 114670c3b76cSNeilBrown #endif 11470964a3d3SNeilBrown 11481da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 11491da177e4SLinus Torvalds /* 11501da177e4SLinus Torvalds * populating the filesystem. 11511da177e4SLinus Torvalds */ 11521da177e4SLinus Torvalds 1153e8a79fb1SJ. Bruce Fields /* Basically copying rpc_get_inode. */ 1154e8a79fb1SJ. Bruce Fields static struct inode *nfsd_get_inode(struct super_block *sb, umode_t mode) 1155e8a79fb1SJ. Bruce Fields { 1156e8a79fb1SJ. Bruce Fields struct inode *inode = new_inode(sb); 1157e8a79fb1SJ. Bruce Fields if (!inode) 1158e8a79fb1SJ. Bruce Fields return NULL; 1159e8a79fb1SJ. Bruce Fields /* Following advice from simple_fill_super documentation: */ 1160e8a79fb1SJ. Bruce Fields inode->i_ino = iunique(sb, NFSD_MaxReserved); 1161e8a79fb1SJ. Bruce Fields inode->i_mode = mode; 1162e8a79fb1SJ. Bruce Fields inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); 1163e8a79fb1SJ. Bruce Fields switch (mode & S_IFMT) { 1164e8a79fb1SJ. Bruce Fields case S_IFDIR: 1165e8a79fb1SJ. Bruce Fields inode->i_fop = &simple_dir_operations; 1166e8a79fb1SJ. Bruce Fields inode->i_op = &simple_dir_inode_operations; 1167e8a79fb1SJ. Bruce Fields inc_nlink(inode); 1168e8a79fb1SJ. Bruce Fields default: 1169e8a79fb1SJ. Bruce Fields break; 1170e8a79fb1SJ. Bruce Fields } 1171e8a79fb1SJ. Bruce Fields return inode; 1172e8a79fb1SJ. Bruce Fields } 1173e8a79fb1SJ. Bruce Fields 1174bebd6997SJ. Bruce Fields static int __nfsd_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode, struct nfsdfs_client *ncl) 1175e8a79fb1SJ. Bruce Fields { 1176e8a79fb1SJ. Bruce Fields struct inode *inode; 1177e8a79fb1SJ. Bruce Fields 1178e8a79fb1SJ. Bruce Fields inode = nfsd_get_inode(dir->i_sb, mode); 1179e8a79fb1SJ. Bruce Fields if (!inode) 1180e8a79fb1SJ. Bruce Fields return -ENOMEM; 1181bebd6997SJ. Bruce Fields if (ncl) { 1182bebd6997SJ. Bruce Fields inode->i_private = ncl; 1183bebd6997SJ. Bruce Fields kref_get(&ncl->cl_ref); 1184bebd6997SJ. Bruce Fields } 1185e8a79fb1SJ. Bruce Fields d_add(dentry, inode); 1186e8a79fb1SJ. Bruce Fields inc_nlink(dir); 1187e8a79fb1SJ. Bruce Fields fsnotify_mkdir(dir, dentry); 1188e8a79fb1SJ. Bruce Fields return 0; 1189e8a79fb1SJ. Bruce Fields } 1190e8a79fb1SJ. Bruce Fields 1191e8a79fb1SJ. Bruce Fields static struct dentry *nfsd_mkdir(struct dentry *parent, struct nfsdfs_client *ncl, char *name) 1192e8a79fb1SJ. Bruce Fields { 1193e8a79fb1SJ. Bruce Fields struct inode *dir = parent->d_inode; 1194e8a79fb1SJ. Bruce Fields struct dentry *dentry; 1195e8a79fb1SJ. Bruce Fields int ret = -ENOMEM; 1196e8a79fb1SJ. Bruce Fields 1197e8a79fb1SJ. Bruce Fields inode_lock(dir); 1198e8a79fb1SJ. Bruce Fields dentry = d_alloc_name(parent, name); 1199e8a79fb1SJ. Bruce Fields if (!dentry) 1200e8a79fb1SJ. Bruce Fields goto out_err; 1201bebd6997SJ. Bruce Fields ret = __nfsd_mkdir(d_inode(parent), dentry, S_IFDIR | 0600, ncl); 1202e8a79fb1SJ. Bruce Fields if (ret) 1203e8a79fb1SJ. Bruce Fields goto out_err; 1204e8a79fb1SJ. Bruce Fields out: 1205e8a79fb1SJ. Bruce Fields inode_unlock(dir); 1206e8a79fb1SJ. Bruce Fields return dentry; 1207e8a79fb1SJ. Bruce Fields out_err: 1208d6846bfbSTetsuo Handa dput(dentry); 1209e8a79fb1SJ. Bruce Fields dentry = ERR_PTR(ret); 1210e8a79fb1SJ. Bruce Fields goto out; 1211e8a79fb1SJ. Bruce Fields } 1212e8a79fb1SJ. Bruce Fields 121397ad4031SJ. Bruce Fields static void clear_ncl(struct inode *inode) 1214e8a79fb1SJ. Bruce Fields { 121597ad4031SJ. Bruce Fields struct nfsdfs_client *ncl = inode->i_private; 121697ad4031SJ. Bruce Fields 121797ad4031SJ. Bruce Fields inode->i_private = NULL; 121897ad4031SJ. Bruce Fields kref_put(&ncl->cl_ref, ncl->cl_release); 121997ad4031SJ. Bruce Fields } 122097ad4031SJ. Bruce Fields 1221b78fa45dSYueHaibing static struct nfsdfs_client *__get_nfsdfs_client(struct inode *inode) 122297ad4031SJ. Bruce Fields { 122397ad4031SJ. Bruce Fields struct nfsdfs_client *nc = inode->i_private; 122497ad4031SJ. Bruce Fields 122597ad4031SJ. Bruce Fields if (nc) 122697ad4031SJ. Bruce Fields kref_get(&nc->cl_ref); 122797ad4031SJ. Bruce Fields return nc; 122897ad4031SJ. Bruce Fields } 122997ad4031SJ. Bruce Fields 123097ad4031SJ. Bruce Fields struct nfsdfs_client *get_nfsdfs_client(struct inode *inode) 123197ad4031SJ. Bruce Fields { 123297ad4031SJ. Bruce Fields struct nfsdfs_client *nc; 123397ad4031SJ. Bruce Fields 1234dc46bba7SJ. Bruce Fields inode_lock_shared(inode); 123597ad4031SJ. Bruce Fields nc = __get_nfsdfs_client(inode); 1236dc46bba7SJ. Bruce Fields inode_unlock_shared(inode); 123797ad4031SJ. Bruce Fields return nc; 123897ad4031SJ. Bruce Fields } 123997ad4031SJ. Bruce Fields /* from __rpc_unlink */ 124097ad4031SJ. Bruce Fields static void nfsdfs_remove_file(struct inode *dir, struct dentry *dentry) 124197ad4031SJ. Bruce Fields { 124297ad4031SJ. Bruce Fields int ret; 124397ad4031SJ. Bruce Fields 124497ad4031SJ. Bruce Fields clear_ncl(d_inode(dentry)); 124597ad4031SJ. Bruce Fields dget(dentry); 124697ad4031SJ. Bruce Fields ret = simple_unlink(dir, dentry); 124797ad4031SJ. Bruce Fields d_delete(dentry); 124897ad4031SJ. Bruce Fields dput(dentry); 124997ad4031SJ. Bruce Fields WARN_ON_ONCE(ret); 125097ad4031SJ. Bruce Fields } 125197ad4031SJ. Bruce Fields 125297ad4031SJ. Bruce Fields static void nfsdfs_remove_files(struct dentry *root) 125397ad4031SJ. Bruce Fields { 125497ad4031SJ. Bruce Fields struct dentry *dentry, *tmp; 125597ad4031SJ. Bruce Fields 125697ad4031SJ. Bruce Fields list_for_each_entry_safe(dentry, tmp, &root->d_subdirs, d_child) { 125797ad4031SJ. Bruce Fields if (!simple_positive(dentry)) { 125897ad4031SJ. Bruce Fields WARN_ON_ONCE(1); /* I think this can't happen? */ 125997ad4031SJ. Bruce Fields continue; 126097ad4031SJ. Bruce Fields } 126197ad4031SJ. Bruce Fields nfsdfs_remove_file(d_inode(root), dentry); 126297ad4031SJ. Bruce Fields } 126397ad4031SJ. Bruce Fields } 126497ad4031SJ. Bruce Fields 126597ad4031SJ. Bruce Fields /* XXX: cut'n'paste from simple_fill_super; figure out if we could share 126697ad4031SJ. Bruce Fields * code instead. */ 126797ad4031SJ. Bruce Fields static int nfsdfs_create_files(struct dentry *root, 126897ad4031SJ. Bruce Fields const struct tree_descr *files) 126997ad4031SJ. Bruce Fields { 127097ad4031SJ. Bruce Fields struct inode *dir = d_inode(root); 127197ad4031SJ. Bruce Fields struct inode *inode; 127297ad4031SJ. Bruce Fields struct dentry *dentry; 127397ad4031SJ. Bruce Fields int i; 127497ad4031SJ. Bruce Fields 127597ad4031SJ. Bruce Fields inode_lock(dir); 127697ad4031SJ. Bruce Fields for (i = 0; files->name && files->name[0]; i++, files++) { 127797ad4031SJ. Bruce Fields if (!files->name) 127897ad4031SJ. Bruce Fields continue; 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); 129297ad4031SJ. Bruce Fields } 129397ad4031SJ. Bruce Fields inode_unlock(dir); 129497ad4031SJ. Bruce Fields return 0; 129597ad4031SJ. Bruce Fields out: 129697ad4031SJ. Bruce Fields nfsdfs_remove_files(root); 129797ad4031SJ. Bruce Fields inode_unlock(dir); 129897ad4031SJ. Bruce Fields return -ENOMEM; 129997ad4031SJ. Bruce Fields } 130097ad4031SJ. Bruce Fields 130197ad4031SJ. Bruce Fields /* on success, returns positive number unique to that client. */ 130297ad4031SJ. Bruce Fields struct dentry *nfsd_client_mkdir(struct nfsd_net *nn, 130397ad4031SJ. Bruce Fields struct nfsdfs_client *ncl, u32 id, 130497ad4031SJ. Bruce Fields const struct tree_descr *files) 130597ad4031SJ. Bruce Fields { 130697ad4031SJ. Bruce Fields struct dentry *dentry; 1307e8a79fb1SJ. Bruce Fields char name[11]; 130897ad4031SJ. Bruce Fields int ret; 1309e8a79fb1SJ. Bruce Fields 1310bf5ed3e3SJ. Bruce Fields sprintf(name, "%u", id); 1311e8a79fb1SJ. Bruce Fields 131297ad4031SJ. Bruce Fields dentry = nfsd_mkdir(nn->nfsd_client_dir, ncl, name); 131397ad4031SJ. Bruce Fields if (IS_ERR(dentry)) /* XXX: tossing errors? */ 131497ad4031SJ. Bruce Fields return NULL; 131597ad4031SJ. Bruce Fields ret = nfsdfs_create_files(dentry, files); 131697ad4031SJ. Bruce Fields if (ret) { 131797ad4031SJ. Bruce Fields nfsd_client_rmdir(dentry); 131897ad4031SJ. Bruce Fields return NULL; 131997ad4031SJ. Bruce Fields } 132097ad4031SJ. Bruce Fields return dentry; 1321e8a79fb1SJ. Bruce Fields } 1322e8a79fb1SJ. Bruce Fields 1323e8a79fb1SJ. Bruce Fields /* Taken from __rpc_rmdir: */ 1324e8a79fb1SJ. Bruce Fields void nfsd_client_rmdir(struct dentry *dentry) 1325e8a79fb1SJ. Bruce Fields { 1326e8a79fb1SJ. Bruce Fields struct inode *dir = d_inode(dentry->d_parent); 1327e8a79fb1SJ. Bruce Fields struct inode *inode = d_inode(dentry); 1328e8a79fb1SJ. Bruce Fields int ret; 1329e8a79fb1SJ. Bruce Fields 133097ad4031SJ. Bruce Fields inode_lock(dir); 133197ad4031SJ. Bruce Fields nfsdfs_remove_files(dentry); 133297ad4031SJ. Bruce Fields clear_ncl(inode); 1333e8a79fb1SJ. Bruce Fields dget(dentry); 1334e8a79fb1SJ. Bruce Fields ret = simple_rmdir(dir, dentry); 1335e8a79fb1SJ. Bruce Fields WARN_ON_ONCE(ret); 1336e8a79fb1SJ. Bruce Fields d_delete(dentry); 133797ad4031SJ. Bruce Fields inode_unlock(dir); 1338e8a79fb1SJ. Bruce Fields } 1339e8a79fb1SJ. Bruce Fields 134096a374a3SDavid Howells static int nfsd_fill_super(struct super_block *sb, struct fs_context *fc) 13411da177e4SLinus Torvalds { 1342e8a79fb1SJ. Bruce Fields struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, 1343e8a79fb1SJ. Bruce Fields nfsd_net_id); 1344e8a79fb1SJ. Bruce Fields struct dentry *dentry; 1345e8a79fb1SJ. Bruce Fields int ret; 1346e8a79fb1SJ. Bruce Fields 1347cda37124SEric Biggers static const struct tree_descr nfsd_files[] = { 134896d851c4SStanislav Kinsbursky [NFSD_List] = {"exports", &exports_nfsd_operations, S_IRUGO}, 1349e8e8753fSJ. Bruce Fields [NFSD_Export_features] = {"export_features", 1350e8e8753fSJ. Bruce Fields &export_features_operations, S_IRUGO}, 13514373ea84SWendy Cheng [NFSD_FO_UnlockIP] = {"unlock_ip", 13524373ea84SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 135317efa372SWendy Cheng [NFSD_FO_UnlockFS] = {"unlock_filesystem", 135417efa372SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 13551da177e4SLinus Torvalds [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 13561da177e4SLinus Torvalds [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 1357eed2965aSGreg Banks [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, 135803cf6c9fSGreg Banks [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, 1359a2f999a3SJeff Layton [NFSD_Reply_Cache_Stats] = {"reply_cache_stats", &reply_cache_stats_operations, S_IRUGO}, 136070c3b76cSNeilBrown [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, 136180212d59SNeilBrown [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, 1362596bbe53SNeilBrown [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, 13635b8db00bSJeff Layton [NFSD_MaxConnections] = {"max_connections", &transaction_ops, S_IWUSR|S_IRUGO}, 1364b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 1365b0b0c0a2SKevin Coffman [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO}, 1366b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 13671da177e4SLinus Torvalds #ifdef CONFIG_NFSD_V4 13681da177e4SLinus Torvalds [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, 1369efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, 13700964a3d3SNeilBrown [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, 13717f5ef2e9SJeff Layton [NFSD_V4EndGrace] = {"v4_end_grace", &transaction_ops, S_IWUSR|S_IRUGO}, 13721da177e4SLinus Torvalds #endif 13731da177e4SLinus Torvalds /* last one */ {""} 13741da177e4SLinus Torvalds }; 137596a374a3SDavid Howells 1376e8a79fb1SJ. Bruce Fields ret = simple_fill_super(sb, 0x6e667364, nfsd_files); 1377e8a79fb1SJ. Bruce Fields if (ret) 1378e8a79fb1SJ. Bruce Fields return ret; 1379e8a79fb1SJ. Bruce Fields dentry = nfsd_mkdir(sb->s_root, NULL, "clients"); 1380e8a79fb1SJ. Bruce Fields if (IS_ERR(dentry)) 1381e8a79fb1SJ. Bruce Fields return PTR_ERR(dentry); 1382e8a79fb1SJ. Bruce Fields nn->nfsd_client_dir = dentry; 1383e8a79fb1SJ. Bruce Fields return 0; 13841da177e4SLinus Torvalds } 13851da177e4SLinus Torvalds 138696a374a3SDavid Howells static int nfsd_fs_get_tree(struct fs_context *fc) 13871da177e4SLinus Torvalds { 1388533770ccSAl Viro return get_tree_keyed(fc, nfsd_fill_super, get_net(fc->net_ns)); 138996a374a3SDavid Howells } 139096a374a3SDavid Howells 139196a374a3SDavid Howells static void nfsd_fs_free_fc(struct fs_context *fc) 139296a374a3SDavid Howells { 139396a374a3SDavid Howells if (fc->s_fs_info) 139496a374a3SDavid Howells put_net(fc->s_fs_info); 139596a374a3SDavid Howells } 139696a374a3SDavid Howells 139796a374a3SDavid Howells static const struct fs_context_operations nfsd_fs_context_ops = { 139896a374a3SDavid Howells .free = nfsd_fs_free_fc, 139996a374a3SDavid Howells .get_tree = nfsd_fs_get_tree, 140096a374a3SDavid Howells }; 140196a374a3SDavid Howells 140296a374a3SDavid Howells static int nfsd_init_fs_context(struct fs_context *fc) 140396a374a3SDavid Howells { 140496a374a3SDavid Howells put_user_ns(fc->user_ns); 140596a374a3SDavid Howells fc->user_ns = get_user_ns(fc->net_ns->user_ns); 140696a374a3SDavid Howells fc->ops = &nfsd_fs_context_ops; 140796a374a3SDavid Howells return 0; 140811f77942SStanislav Kinsbursky } 140911f77942SStanislav Kinsbursky 141011f77942SStanislav Kinsbursky static void nfsd_umount(struct super_block *sb) 141111f77942SStanislav Kinsbursky { 141211f77942SStanislav Kinsbursky struct net *net = sb->s_fs_info; 141311f77942SStanislav Kinsbursky 141411f77942SStanislav Kinsbursky kill_litter_super(sb); 141511f77942SStanislav Kinsbursky put_net(net); 14161da177e4SLinus Torvalds } 14171da177e4SLinus Torvalds 14181da177e4SLinus Torvalds static struct file_system_type nfsd_fs_type = { 14191da177e4SLinus Torvalds .owner = THIS_MODULE, 14201da177e4SLinus Torvalds .name = "nfsd", 142196a374a3SDavid Howells .init_fs_context = nfsd_init_fs_context, 142211f77942SStanislav Kinsbursky .kill_sb = nfsd_umount, 14231da177e4SLinus Torvalds }; 14247f78e035SEric W. Biederman MODULE_ALIAS_FS("nfsd"); 14251da177e4SLinus Torvalds 1426e331f606SJ. Bruce Fields #ifdef CONFIG_PROC_FS 1427e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1428e331f606SJ. Bruce Fields { 1429e331f606SJ. Bruce Fields struct proc_dir_entry *entry; 1430e331f606SJ. Bruce Fields 1431e331f606SJ. Bruce Fields entry = proc_mkdir("fs/nfs", NULL); 1432e331f606SJ. Bruce Fields if (!entry) 1433e331f606SJ. Bruce Fields return -ENOMEM; 1434*97a32539SAlexey Dobriyan entry = proc_create("exports", 0, entry, &exports_proc_ops); 1435ff7c4b36Sfanchaoting if (!entry) { 1436ff7c4b36Sfanchaoting remove_proc_entry("fs/nfs", NULL); 1437e331f606SJ. Bruce Fields return -ENOMEM; 1438ff7c4b36Sfanchaoting } 1439e331f606SJ. Bruce Fields return 0; 1440e331f606SJ. Bruce Fields } 1441e331f606SJ. Bruce Fields #else /* CONFIG_PROC_FS */ 1442e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1443e331f606SJ. Bruce Fields { 1444e331f606SJ. Bruce Fields return 0; 1445e331f606SJ. Bruce Fields } 1446e331f606SJ. Bruce Fields #endif 1447e331f606SJ. Bruce Fields 1448c7d03a00SAlexey Dobriyan unsigned int nfsd_net_id; 14495717e012SStanislav Kinsbursky 14505717e012SStanislav Kinsbursky static __net_init int nfsd_init_net(struct net *net) 14515717e012SStanislav Kinsbursky { 14525717e012SStanislav Kinsbursky int retval; 14532c830dd7SJ. Bruce Fields struct vfsmount *mnt; 14543d733711SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 14555717e012SStanislav Kinsbursky 14565717e012SStanislav Kinsbursky retval = nfsd_export_init(net); 14575717e012SStanislav Kinsbursky if (retval) 14585717e012SStanislav Kinsbursky goto out_export_error; 1459f69adb2fSStanislav Kinsbursky retval = nfsd_idmap_init(net); 1460f69adb2fSStanislav Kinsbursky if (retval) 1461f69adb2fSStanislav Kinsbursky goto out_idmap_error; 1462e333f3bbSTrond Myklebust nn->nfsd_versions = NULL; 1463e333f3bbSTrond Myklebust nn->nfsd4_minorversions = NULL; 14643ba75830SJ. Bruce Fields retval = nfsd_reply_cache_init(nn); 14653ba75830SJ. Bruce Fields if (retval) 14663ba75830SJ. Bruce Fields goto out_drc_error; 14673bf6b57eSJ. Bruce Fields nn->nfsd4_lease = 90; /* default lease time */ 14683bf6b57eSJ. Bruce Fields nn->nfsd4_grace = 90; 146903f318caSJ. Bruce Fields nn->somebody_reclaimed = false; 1470362063a5SScott Mayhew nn->track_reclaim_completes = false; 1471ebd7c72cSJ. Bruce Fields nn->clverifier_counter = prandom_u32(); 1472bf5ed3e3SJ. Bruce Fields nn->clientid_base = prandom_u32(); 1473bf5ed3e3SJ. Bruce Fields nn->clientid_counter = nn->clientid_base + 1; 1474e0639dc5SOlga Kornievskaia nn->s2s_cp_cl_id = nn->clientid_counter++; 14752317dc55SVasily Averin 14762317dc55SVasily Averin atomic_set(&nn->ntf_refcnt, 0); 14772317dc55SVasily Averin init_waitqueue_head(&nn->ntf_wq); 147827c438f5STrond Myklebust seqlock_init(&nn->boot_lock); 14792c830dd7SJ. Bruce Fields 14802c830dd7SJ. Bruce Fields mnt = vfs_kern_mount(&nfsd_fs_type, SB_KERNMOUNT, "nfsd", NULL); 14812c830dd7SJ. Bruce Fields if (IS_ERR(mnt)) { 14822c830dd7SJ. Bruce Fields retval = PTR_ERR(mnt); 14832c830dd7SJ. Bruce Fields goto out_mount_err; 14842c830dd7SJ. Bruce Fields } 14852c830dd7SJ. Bruce Fields nn->nfsd_mnt = mnt; 14865717e012SStanislav Kinsbursky return 0; 14875717e012SStanislav Kinsbursky 14882c830dd7SJ. Bruce Fields out_mount_err: 14892c830dd7SJ. Bruce Fields nfsd_reply_cache_shutdown(nn); 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 15022c830dd7SJ. Bruce Fields mntput(nn->nfsd_mnt); 15033ba75830SJ. Bruce Fields nfsd_reply_cache_shutdown(nn); 1504f69adb2fSStanislav Kinsbursky nfsd_idmap_shutdown(net); 15055717e012SStanislav Kinsbursky nfsd_export_shutdown(net); 1506e333f3bbSTrond Myklebust nfsd_netns_free_versions(net_generic(net, nfsd_net_id)); 15075717e012SStanislav Kinsbursky } 15085717e012SStanislav Kinsbursky 15097ea34ac1SJeff Layton static struct pernet_operations nfsd_net_ops = { 15105717e012SStanislav Kinsbursky .init = nfsd_init_net, 15115717e012SStanislav Kinsbursky .exit = nfsd_exit_net, 15127ea34ac1SJeff Layton .id = &nfsd_net_id, 15137ea34ac1SJeff Layton .size = sizeof(struct nfsd_net), 15147ea34ac1SJeff Layton }; 15157ea34ac1SJeff Layton 15161da177e4SLinus Torvalds static int __init init_nfsd(void) 15171da177e4SLinus Torvalds { 15181da177e4SLinus Torvalds int retval; 15191da177e4SLinus Torvalds printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 15201da177e4SLinus Torvalds 15217ea34ac1SJeff Layton retval = register_pernet_subsys(&nfsd_net_ops); 15227ea34ac1SJeff Layton if (retval < 0) 1523bb7ffbf2SGiuseppe Cantavenera return retval; 1524bb7ffbf2SGiuseppe Cantavenera retval = register_cld_notifier(); 1525e8ff2a84SJ. Bruce Fields if (retval) 15267ea34ac1SJeff Layton goto out_unregister_pernet; 1527bb7ffbf2SGiuseppe Cantavenera retval = nfsd4_init_slabs(); 1528bb7ffbf2SGiuseppe Cantavenera if (retval) 1529bb7ffbf2SGiuseppe Cantavenera goto out_unregister_notifier; 15309cf514ccSChristoph Hellwig retval = nfsd4_init_pnfs(); 153165178db4SBryan Schumaker if (retval) 153265178db4SBryan Schumaker goto out_free_slabs; 153315b6ff95SGreg Kroah-Hartman nfsd_fault_inject_init(); /* nfsd fault injection controls */ 15341da177e4SLinus Torvalds nfsd_stat_init(); /* Statistics */ 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) 154126808d3fSJ. Bruce Fields goto out_free_all; 154226808d3fSJ. Bruce Fields return 0; 154326808d3fSJ. Bruce Fields out_free_all: 15441da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 15451da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 1546dbf847ecSJ. Bruce Fields out_free_lockd: 15471da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1548d5c3428bSJ. Bruce Fields nfsd_stat_shutdown(); 154965178db4SBryan Schumaker nfsd_fault_inject_cleanup(); 15509cf514ccSChristoph Hellwig nfsd4_exit_pnfs(); 155165178db4SBryan Schumaker out_free_slabs: 155246b25895SJ. Bruce Fields nfsd4_free_slabs(); 1553813fd320SJeff Layton out_unregister_notifier: 1554797a9d79SJeff Layton unregister_cld_notifier(); 1555bb7ffbf2SGiuseppe Cantavenera out_unregister_pernet: 1556bb7ffbf2SGiuseppe Cantavenera unregister_pernet_subsys(&nfsd_net_ops); 15571da177e4SLinus Torvalds return retval; 15581da177e4SLinus Torvalds } 15591da177e4SLinus Torvalds 15601da177e4SLinus Torvalds static void __exit exit_nfsd(void) 15611da177e4SLinus Torvalds { 15621da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 15631da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 15641da177e4SLinus Torvalds nfsd_stat_shutdown(); 15651da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1566e8ff2a84SJ. Bruce Fields nfsd4_free_slabs(); 15679cf514ccSChristoph Hellwig nfsd4_exit_pnfs(); 156865178db4SBryan Schumaker nfsd_fault_inject_cleanup(); 15691da177e4SLinus Torvalds unregister_filesystem(&nfsd_fs_type); 1570797a9d79SJeff Layton unregister_cld_notifier(); 1571bb7ffbf2SGiuseppe Cantavenera unregister_pernet_subsys(&nfsd_net_ops); 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); 15751da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 15761da177e4SLinus Torvalds module_init(init_nfsd) 15771da177e4SLinus Torvalds module_exit(exit_nfsd) 1578