11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Syscall interface to knfsd. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> 51da177e4SLinus Torvalds */ 61da177e4SLinus Torvalds 75a0e3ad6STejun Heo #include <linux/slab.h> 83f8206d4SAl Viro #include <linux/namei.h> 9b41b66d6SNeilBrown #include <linux/ctype.h> 101da177e4SLinus Torvalds 1180212d59SNeilBrown #include <linux/sunrpc/svcsock.h> 124373ea84SWendy Cheng #include <linux/lockd/lockd.h> 134116092bSChuck Lever #include <linux/sunrpc/clnt.h> 14b0b0c0a2SKevin Coffman #include <linux/sunrpc/gss_api.h> 15b084f598SJ. Bruce Fields #include <linux/sunrpc/gss_krb5_enctypes.h> 16813fd320SJeff Layton #include <linux/sunrpc/rpc_pipe_fs.h> 17143cb494SPaul Gortmaker #include <linux/module.h> 181da177e4SLinus Torvalds 192ca72e17SJ. Bruce Fields #include "idmap.h" 209a74af21SBoaz Harrosh #include "nfsd.h" 219a74af21SBoaz Harrosh #include "cache.h" 2265178db4SBryan Schumaker #include "fault_inject.h" 237ea34ac1SJeff Layton #include "netns.h" 249a74af21SBoaz Harrosh 251da177e4SLinus Torvalds /* 26b0b0c0a2SKevin Coffman * We have a single directory with several nodes in it. 271da177e4SLinus Torvalds */ 281da177e4SLinus Torvalds enum { 291da177e4SLinus Torvalds NFSD_Root = 1, 301da177e4SLinus Torvalds NFSD_List, 31e8e8753fSJ. Bruce Fields NFSD_Export_features, 321da177e4SLinus Torvalds NFSD_Fh, 334373ea84SWendy Cheng NFSD_FO_UnlockIP, 3417efa372SWendy Cheng NFSD_FO_UnlockFS, 351da177e4SLinus Torvalds NFSD_Threads, 36eed2965aSGreg Banks NFSD_Pool_Threads, 3703cf6c9fSGreg Banks NFSD_Pool_Stats, 3870c3b76cSNeilBrown NFSD_Versions, 3980212d59SNeilBrown NFSD_Ports, 40596bbe53SNeilBrown NFSD_MaxBlkSize, 41b0b0c0a2SKevin Coffman NFSD_SupportedEnctypes, 4270c3b76cSNeilBrown /* 4370c3b76cSNeilBrown * The below MUST come last. Otherwise we leave a hole in nfsd_files[] 4470c3b76cSNeilBrown * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops 4570c3b76cSNeilBrown */ 4670c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 471da177e4SLinus Torvalds NFSD_Leasetime, 48efc4bb4fSJ. Bruce Fields NFSD_Gracetime, 490964a3d3SNeilBrown NFSD_RecoveryDir, 5070c3b76cSNeilBrown #endif 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * write() for these nodes. 551da177e4SLinus Torvalds */ 561da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size); 57b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size); 58b046ccdcSChuck Lever static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size); 591da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size); 60eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size); 6170c3b76cSNeilBrown static ssize_t write_versions(struct file *file, char *buf, size_t size); 6280212d59SNeilBrown static ssize_t write_ports(struct file *file, char *buf, size_t size); 63596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size); 6470c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 651da177e4SLinus Torvalds static ssize_t write_leasetime(struct file *file, char *buf, size_t size); 66efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size); 670964a3d3SNeilBrown static ssize_t write_recoverydir(struct file *file, char *buf, size_t size); 6870c3b76cSNeilBrown #endif 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds static ssize_t (*write_op[])(struct file *, char *, size_t) = { 711da177e4SLinus Torvalds [NFSD_Fh] = write_filehandle, 72b046ccdcSChuck Lever [NFSD_FO_UnlockIP] = write_unlock_ip, 73b046ccdcSChuck Lever [NFSD_FO_UnlockFS] = write_unlock_fs, 741da177e4SLinus Torvalds [NFSD_Threads] = write_threads, 75eed2965aSGreg Banks [NFSD_Pool_Threads] = write_pool_threads, 7670c3b76cSNeilBrown [NFSD_Versions] = write_versions, 7780212d59SNeilBrown [NFSD_Ports] = write_ports, 78596bbe53SNeilBrown [NFSD_MaxBlkSize] = write_maxblksize, 7970c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 801da177e4SLinus Torvalds [NFSD_Leasetime] = write_leasetime, 81efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = write_gracetime, 820964a3d3SNeilBrown [NFSD_RecoveryDir] = write_recoverydir, 8370c3b76cSNeilBrown #endif 841da177e4SLinus Torvalds }; 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 871da177e4SLinus Torvalds { 887eaa36e2SJosef "Jeff" Sipek ino_t ino = file->f_path.dentry->d_inode->i_ino; 891da177e4SLinus Torvalds char *data; 901da177e4SLinus Torvalds ssize_t rv; 911da177e4SLinus Torvalds 92e8c96f8cSTobias Klauser if (ino >= ARRAY_SIZE(write_op) || !write_op[ino]) 931da177e4SLinus Torvalds return -EINVAL; 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds data = simple_transaction_get(file, buf, size); 961da177e4SLinus Torvalds if (IS_ERR(data)) 971da177e4SLinus Torvalds return PTR_ERR(data); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds rv = write_op[ino](file, data, size); 1008971a101SNeilBrown if (rv >= 0) { 1011da177e4SLinus Torvalds simple_transaction_set(file, rv); 1021da177e4SLinus Torvalds rv = size; 1031da177e4SLinus Torvalds } 1041da177e4SLinus Torvalds return rv; 1051da177e4SLinus Torvalds } 1061da177e4SLinus Torvalds 1077390022dSNeilBrown static ssize_t nfsctl_transaction_read(struct file *file, char __user *buf, size_t size, loff_t *pos) 1087390022dSNeilBrown { 1097390022dSNeilBrown if (! file->private_data) { 1107390022dSNeilBrown /* An attempt to read a transaction file without writing 1117390022dSNeilBrown * causes a 0-byte write so that the file can return 1127390022dSNeilBrown * state information 1137390022dSNeilBrown */ 1147390022dSNeilBrown ssize_t rv = nfsctl_transaction_write(file, buf, 0, pos); 1157390022dSNeilBrown if (rv < 0) 1167390022dSNeilBrown return rv; 1177390022dSNeilBrown } 1187390022dSNeilBrown return simple_transaction_read(file, buf, size, pos); 1197390022dSNeilBrown } 1207390022dSNeilBrown 1214b6f5d20SArjan van de Ven static const struct file_operations transaction_ops = { 1221da177e4SLinus Torvalds .write = nfsctl_transaction_write, 1237390022dSNeilBrown .read = nfsctl_transaction_read, 1241da177e4SLinus Torvalds .release = simple_transaction_release, 1256038f373SArnd Bergmann .llseek = default_llseek, 1261da177e4SLinus Torvalds }; 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds static int exports_open(struct inode *inode, struct file *file) 1291da177e4SLinus Torvalds { 130f2c7ea10SStanislav Kinsbursky int err; 131f2c7ea10SStanislav Kinsbursky struct seq_file *seq; 132e5f06f72SStanislav Kinsbursky struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id); 133f2c7ea10SStanislav Kinsbursky 134f2c7ea10SStanislav Kinsbursky err = seq_open(file, &nfs_exports_op); 135f2c7ea10SStanislav Kinsbursky if (err) 136f2c7ea10SStanislav Kinsbursky return err; 137f2c7ea10SStanislav Kinsbursky 138f2c7ea10SStanislav Kinsbursky seq = file->private_data; 139e5f06f72SStanislav Kinsbursky seq->private = nn->svc_export_cache; 140f2c7ea10SStanislav Kinsbursky return 0; 1411da177e4SLinus Torvalds } 1421da177e4SLinus Torvalds 1434b6f5d20SArjan van de Ven static const struct file_operations exports_operations = { 1441da177e4SLinus Torvalds .open = exports_open, 1451da177e4SLinus Torvalds .read = seq_read, 1461da177e4SLinus Torvalds .llseek = seq_lseek, 1471da177e4SLinus Torvalds .release = seq_release, 1489ef2db26SDenis V. Lunev .owner = THIS_MODULE, 1491da177e4SLinus Torvalds }; 1501da177e4SLinus Torvalds 151e8e8753fSJ. Bruce Fields static int export_features_show(struct seq_file *m, void *v) 152e8e8753fSJ. Bruce Fields { 153e8e8753fSJ. Bruce Fields seq_printf(m, "0x%x 0x%x\n", NFSEXP_ALLFLAGS, NFSEXP_SECINFO_FLAGS); 154e8e8753fSJ. Bruce Fields return 0; 155e8e8753fSJ. Bruce Fields } 156e8e8753fSJ. Bruce Fields 157e8e8753fSJ. Bruce Fields static int export_features_open(struct inode *inode, struct file *file) 158e8e8753fSJ. Bruce Fields { 159e8e8753fSJ. Bruce Fields return single_open(file, export_features_show, NULL); 160e8e8753fSJ. Bruce Fields } 161e8e8753fSJ. Bruce Fields 162e8e8753fSJ. Bruce Fields static struct file_operations export_features_operations = { 163e8e8753fSJ. Bruce Fields .open = export_features_open, 164e8e8753fSJ. Bruce Fields .read = seq_read, 165e8e8753fSJ. Bruce Fields .llseek = seq_lseek, 166e8e8753fSJ. Bruce Fields .release = single_release, 167e8e8753fSJ. Bruce Fields }; 168e8e8753fSJ. Bruce Fields 169b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 170b0b0c0a2SKevin Coffman static int supported_enctypes_show(struct seq_file *m, void *v) 171b0b0c0a2SKevin Coffman { 172b084f598SJ. Bruce Fields seq_printf(m, KRB5_SUPPORTED_ENCTYPES); 173b0b0c0a2SKevin Coffman return 0; 174b0b0c0a2SKevin Coffman } 175b0b0c0a2SKevin Coffman 176b0b0c0a2SKevin Coffman static int supported_enctypes_open(struct inode *inode, struct file *file) 177b0b0c0a2SKevin Coffman { 178b0b0c0a2SKevin Coffman return single_open(file, supported_enctypes_show, NULL); 179b0b0c0a2SKevin Coffman } 180b0b0c0a2SKevin Coffman 181b0b0c0a2SKevin Coffman static struct file_operations supported_enctypes_ops = { 182b0b0c0a2SKevin Coffman .open = supported_enctypes_open, 183b0b0c0a2SKevin Coffman .read = seq_read, 184b0b0c0a2SKevin Coffman .llseek = seq_lseek, 185b0b0c0a2SKevin Coffman .release = single_release, 186b0b0c0a2SKevin Coffman }; 187b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 188b0b0c0a2SKevin Coffman 189828c0950SAlexey Dobriyan static const struct file_operations pool_stats_operations = { 19003cf6c9fSGreg Banks .open = nfsd_pool_stats_open, 19103cf6c9fSGreg Banks .read = seq_read, 19203cf6c9fSGreg Banks .llseek = seq_lseek, 193ed2d8aedSRyusei Yamaguchi .release = nfsd_pool_stats_release, 19403cf6c9fSGreg Banks .owner = THIS_MODULE, 19503cf6c9fSGreg Banks }; 19603cf6c9fSGreg Banks 1971da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 1981da177e4SLinus Torvalds /* 1991da177e4SLinus Torvalds * payload - write methods 2001da177e4SLinus Torvalds */ 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds 203262a0982SChuck Lever /** 204262a0982SChuck Lever * write_unlock_ip - Release all locks used by a client 205262a0982SChuck Lever * 206262a0982SChuck Lever * Experimental. 207262a0982SChuck Lever * 208262a0982SChuck Lever * Input: 209262a0982SChuck Lever * buf: '\n'-terminated C string containing a 2104116092bSChuck Lever * presentation format IP address 211262a0982SChuck Lever * size: length of C string in @buf 212262a0982SChuck Lever * Output: 213262a0982SChuck Lever * On success: returns zero if all specified locks were released; 214262a0982SChuck Lever * returns one if one or more locks were not released 215262a0982SChuck Lever * On error: return code is negative errno value 216262a0982SChuck Lever */ 217b046ccdcSChuck Lever static ssize_t write_unlock_ip(struct file *file, char *buf, size_t size) 2184373ea84SWendy Cheng { 2194116092bSChuck Lever struct sockaddr_storage address; 2204116092bSChuck Lever struct sockaddr *sap = (struct sockaddr *)&address; 2214116092bSChuck Lever size_t salen = sizeof(address); 222367c8c7bSChuck Lever char *fo_path; 2234373ea84SWendy Cheng 2244373ea84SWendy Cheng /* sanity check */ 2254373ea84SWendy Cheng if (size == 0) 2264373ea84SWendy Cheng return -EINVAL; 2274373ea84SWendy Cheng 2284373ea84SWendy Cheng if (buf[size-1] != '\n') 2294373ea84SWendy Cheng return -EINVAL; 2304373ea84SWendy Cheng 2314373ea84SWendy Cheng fo_path = buf; 2324373ea84SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 2334373ea84SWendy Cheng return -EINVAL; 2344373ea84SWendy Cheng 23590100b17SStanislav Kinsbursky if (rpc_pton(&init_net, fo_path, size, sap, salen) == 0) 2364373ea84SWendy Cheng return -EINVAL; 2374373ea84SWendy Cheng 2384116092bSChuck Lever return nlmsvc_unlock_all_by_ip(sap); 2394373ea84SWendy Cheng } 2404373ea84SWendy Cheng 241262a0982SChuck Lever /** 242262a0982SChuck Lever * write_unlock_fs - Release all locks on a local file system 243262a0982SChuck Lever * 244262a0982SChuck Lever * Experimental. 245262a0982SChuck Lever * 246262a0982SChuck Lever * Input: 247262a0982SChuck Lever * buf: '\n'-terminated C string containing the 248262a0982SChuck Lever * absolute pathname of a local file system 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_fs(struct file *file, char *buf, size_t size) 25617efa372SWendy Cheng { 257a63bb996SAl Viro struct path path; 25817efa372SWendy Cheng char *fo_path; 25917efa372SWendy Cheng int error; 26017efa372SWendy Cheng 26117efa372SWendy Cheng /* sanity check */ 26217efa372SWendy Cheng if (size == 0) 26317efa372SWendy Cheng return -EINVAL; 26417efa372SWendy Cheng 26517efa372SWendy Cheng if (buf[size-1] != '\n') 26617efa372SWendy Cheng return -EINVAL; 26717efa372SWendy Cheng 26817efa372SWendy Cheng fo_path = buf; 26917efa372SWendy Cheng if (qword_get(&buf, fo_path, size) < 0) 27017efa372SWendy Cheng return -EINVAL; 27117efa372SWendy Cheng 272a63bb996SAl Viro error = kern_path(fo_path, 0, &path); 27317efa372SWendy Cheng if (error) 27417efa372SWendy Cheng return error; 27517efa372SWendy Cheng 276262a0982SChuck Lever /* 277262a0982SChuck Lever * XXX: Needs better sanity checking. Otherwise we could end up 278262a0982SChuck Lever * releasing locks on the wrong file system. 279262a0982SChuck Lever * 280262a0982SChuck Lever * For example: 281262a0982SChuck Lever * 1. Does the path refer to a directory? 282262a0982SChuck Lever * 2. Is that directory a mount point, or 283262a0982SChuck Lever * 3. Is that directory the root of an exported file system? 284262a0982SChuck Lever */ 285d8c9584eSAl Viro error = nlmsvc_unlock_all_by_sb(path.dentry->d_sb); 28617efa372SWendy Cheng 287a63bb996SAl Viro path_put(&path); 28817efa372SWendy Cheng return error; 28917efa372SWendy Cheng } 29017efa372SWendy Cheng 291262a0982SChuck Lever /** 292262a0982SChuck Lever * write_filehandle - Get a variable-length NFS file handle by path 293262a0982SChuck Lever * 294262a0982SChuck Lever * On input, the buffer contains a '\n'-terminated C string comprised of 295262a0982SChuck Lever * three alphanumeric words separated by whitespace. The string may 296262a0982SChuck Lever * contain escape sequences. 297262a0982SChuck Lever * 298262a0982SChuck Lever * Input: 299262a0982SChuck Lever * buf: 300262a0982SChuck Lever * domain: client domain name 301262a0982SChuck Lever * path: export pathname 302262a0982SChuck Lever * maxsize: numeric maximum size of 303262a0982SChuck Lever * @buf 304262a0982SChuck Lever * size: length of C string in @buf 305262a0982SChuck Lever * Output: 306262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 307262a0982SChuck Lever * string containing a ASCII hex text version 308262a0982SChuck Lever * of the NFS file handle; 309262a0982SChuck Lever * return code is the size in bytes of the string 310262a0982SChuck Lever * On error: return code is negative errno value 311262a0982SChuck Lever */ 3121da177e4SLinus Torvalds static ssize_t write_filehandle(struct file *file, char *buf, size_t size) 3131da177e4SLinus Torvalds { 3141da177e4SLinus Torvalds char *dname, *path; 315246d95baSAndrew Morton int uninitialized_var(maxsize); 3161da177e4SLinus Torvalds char *mesg = buf; 3171da177e4SLinus Torvalds int len; 3181da177e4SLinus Torvalds struct auth_domain *dom; 3191da177e4SLinus Torvalds struct knfsd_fh fh; 3201da177e4SLinus Torvalds 32187d26ea7SJ. Bruce Fields if (size == 0) 32287d26ea7SJ. Bruce Fields return -EINVAL; 32387d26ea7SJ. Bruce Fields 3241da177e4SLinus Torvalds if (buf[size-1] != '\n') 3251da177e4SLinus Torvalds return -EINVAL; 3261da177e4SLinus Torvalds buf[size-1] = 0; 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds dname = mesg; 3291da177e4SLinus Torvalds len = qword_get(&mesg, dname, size); 33054224f04SChuck Lever if (len <= 0) 33154224f04SChuck Lever return -EINVAL; 3321da177e4SLinus Torvalds 3331da177e4SLinus Torvalds path = dname+len+1; 3341da177e4SLinus Torvalds len = qword_get(&mesg, path, size); 33554224f04SChuck Lever if (len <= 0) 33654224f04SChuck Lever return -EINVAL; 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds len = get_int(&mesg, &maxsize); 3391da177e4SLinus Torvalds if (len) 3401da177e4SLinus Torvalds return len; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds if (maxsize < NFS_FHSIZE) 3431da177e4SLinus Torvalds return -EINVAL; 3441da177e4SLinus Torvalds if (maxsize > NFS3_FHSIZE) 3451da177e4SLinus Torvalds maxsize = NFS3_FHSIZE; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds if (qword_get(&mesg, mesg, size)>0) 3481da177e4SLinus Torvalds return -EINVAL; 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds /* we have all the words, they are in buf.. */ 3511da177e4SLinus Torvalds dom = unix_domain_find(dname); 3521da177e4SLinus Torvalds if (!dom) 3531da177e4SLinus Torvalds return -ENOMEM; 3541da177e4SLinus Torvalds 355b3853e0eSStanislav Kinsbursky len = exp_rootfh(&init_net, dom, path, &fh, maxsize); 3561da177e4SLinus Torvalds auth_domain_put(dom); 3571da177e4SLinus Torvalds if (len) 3581da177e4SLinus Torvalds return len; 3591da177e4SLinus Torvalds 36054224f04SChuck Lever mesg = buf; 36154224f04SChuck Lever len = SIMPLE_TRANSACTION_LIMIT; 3621da177e4SLinus Torvalds qword_addhex(&mesg, &len, (char*)&fh.fh_base, fh.fh_size); 3631da177e4SLinus Torvalds mesg[-1] = '\n'; 3641da177e4SLinus Torvalds return mesg - buf; 3651da177e4SLinus Torvalds } 3661da177e4SLinus Torvalds 367262a0982SChuck Lever /** 368262a0982SChuck Lever * write_threads - Start NFSD, or report the current number of running threads 369262a0982SChuck Lever * 370262a0982SChuck Lever * Input: 371262a0982SChuck Lever * buf: ignored 372262a0982SChuck Lever * size: zero 373262a0982SChuck Lever * Output: 374262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 375262a0982SChuck Lever * string numeric value representing the number of 376262a0982SChuck Lever * running NFSD threads; 377262a0982SChuck Lever * return code is the size in bytes of the string 378262a0982SChuck Lever * On error: return code is zero 379262a0982SChuck Lever * 380262a0982SChuck Lever * OR 381262a0982SChuck Lever * 382262a0982SChuck Lever * Input: 383262a0982SChuck Lever * buf: C string containing an unsigned 384262a0982SChuck Lever * integer value representing the 385262a0982SChuck Lever * number of NFSD threads to start 386262a0982SChuck Lever * size: non-zero length of C string in @buf 387262a0982SChuck Lever * Output: 388262a0982SChuck Lever * On success: NFS service is started; 389262a0982SChuck Lever * passed-in buffer filled with '\n'-terminated C 390262a0982SChuck Lever * string numeric value representing the number of 391262a0982SChuck Lever * running NFSD threads; 392262a0982SChuck Lever * return code is the size in bytes of the string 393262a0982SChuck Lever * On error: return code is zero or a negative errno value 394262a0982SChuck Lever */ 3951da177e4SLinus Torvalds static ssize_t write_threads(struct file *file, char *buf, size_t size) 3961da177e4SLinus Torvalds { 3971da177e4SLinus Torvalds char *mesg = buf; 3981da177e4SLinus Torvalds int rv; 3991da177e4SLinus Torvalds if (size > 0) { 4001da177e4SLinus Torvalds int newthreads; 4011da177e4SLinus Torvalds rv = get_int(&mesg, &newthreads); 4021da177e4SLinus Torvalds if (rv) 4031da177e4SLinus Torvalds return rv; 4041da177e4SLinus Torvalds if (newthreads < 0) 4051da177e4SLinus Torvalds return -EINVAL; 40638af2cabSJ. Bruce Fields rv = nfsd_svc(newthreads); 40782e12fe9SNeilBrown if (rv < 0) 4081da177e4SLinus Torvalds return rv; 40982e12fe9SNeilBrown } else 41082e12fe9SNeilBrown rv = nfsd_nrthreads(); 411e06b6405SChuck Lever 41282e12fe9SNeilBrown return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", rv); 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds 415262a0982SChuck Lever /** 416262a0982SChuck Lever * write_pool_threads - Set or report the current number of threads per pool 417262a0982SChuck Lever * 418262a0982SChuck Lever * Input: 419262a0982SChuck Lever * buf: ignored 420262a0982SChuck Lever * size: zero 421262a0982SChuck Lever * 422262a0982SChuck Lever * OR 423262a0982SChuck Lever * 424262a0982SChuck Lever * Input: 425262a0982SChuck Lever * buf: C string containing whitespace- 426262a0982SChuck Lever * separated unsigned integer values 427262a0982SChuck Lever * representing the number of NFSD 428262a0982SChuck Lever * threads to start in each pool 429262a0982SChuck Lever * size: non-zero length of C string in @buf 430262a0982SChuck Lever * Output: 431262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 432262a0982SChuck Lever * string containing integer values representing the 433262a0982SChuck Lever * number of NFSD threads in each pool; 434262a0982SChuck Lever * return code is the size in bytes of the string 435262a0982SChuck Lever * On error: return code is zero or a negative errno value 436262a0982SChuck Lever */ 437eed2965aSGreg Banks static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) 438eed2965aSGreg Banks { 439eed2965aSGreg Banks /* if size > 0, look for an array of number of threads per node 440eed2965aSGreg Banks * and apply them then write out number of threads per node as reply 441eed2965aSGreg Banks */ 442eed2965aSGreg Banks char *mesg = buf; 443eed2965aSGreg Banks int i; 444eed2965aSGreg Banks int rv; 445eed2965aSGreg Banks int len; 446bedbdd8bSNeil Brown int npools; 447eed2965aSGreg Banks int *nthreads; 448eed2965aSGreg Banks 449bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 450bedbdd8bSNeil Brown npools = nfsd_nrpools(); 451eed2965aSGreg Banks if (npools == 0) { 452eed2965aSGreg Banks /* 453eed2965aSGreg Banks * NFS is shut down. The admin can start it by 454eed2965aSGreg Banks * writing to the threads file but NOT the pool_threads 455eed2965aSGreg Banks * file, sorry. Report zero threads. 456eed2965aSGreg Banks */ 457bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 458eed2965aSGreg Banks strcpy(buf, "0\n"); 459eed2965aSGreg Banks return strlen(buf); 460eed2965aSGreg Banks } 461eed2965aSGreg Banks 462eed2965aSGreg Banks nthreads = kcalloc(npools, sizeof(int), GFP_KERNEL); 463bedbdd8bSNeil Brown rv = -ENOMEM; 464eed2965aSGreg Banks if (nthreads == NULL) 465bedbdd8bSNeil Brown goto out_free; 466eed2965aSGreg Banks 467eed2965aSGreg Banks if (size > 0) { 468eed2965aSGreg Banks for (i = 0; i < npools; i++) { 469eed2965aSGreg Banks rv = get_int(&mesg, &nthreads[i]); 470eed2965aSGreg Banks if (rv == -ENOENT) 471eed2965aSGreg Banks break; /* fewer numbers than pools */ 472eed2965aSGreg Banks if (rv) 473eed2965aSGreg Banks goto out_free; /* syntax error */ 474eed2965aSGreg Banks rv = -EINVAL; 475eed2965aSGreg Banks if (nthreads[i] < 0) 476eed2965aSGreg Banks goto out_free; 477eed2965aSGreg Banks } 478eed2965aSGreg Banks rv = nfsd_set_nrthreads(i, nthreads); 479eed2965aSGreg Banks if (rv) 480eed2965aSGreg Banks goto out_free; 481eed2965aSGreg Banks } 482eed2965aSGreg Banks 483eed2965aSGreg Banks rv = nfsd_get_nrthreads(npools, nthreads); 484eed2965aSGreg Banks if (rv) 485eed2965aSGreg Banks goto out_free; 486eed2965aSGreg Banks 487eed2965aSGreg Banks mesg = buf; 488eed2965aSGreg Banks size = SIMPLE_TRANSACTION_LIMIT; 489eed2965aSGreg Banks for (i = 0; i < npools && size > 0; i++) { 490eed2965aSGreg Banks snprintf(mesg, size, "%d%c", nthreads[i], (i == npools-1 ? '\n' : ' ')); 491eed2965aSGreg Banks len = strlen(mesg); 492eed2965aSGreg Banks size -= len; 493eed2965aSGreg Banks mesg += len; 494eed2965aSGreg Banks } 495413d63d7SJ. Bruce Fields rv = mesg - buf; 496eed2965aSGreg Banks out_free: 497eed2965aSGreg Banks kfree(nthreads); 498bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 499eed2965aSGreg Banks return rv; 500eed2965aSGreg Banks } 501eed2965aSGreg Banks 5023dd98a3bSJeff Layton static ssize_t __write_versions(struct file *file, char *buf, size_t size) 50370c3b76cSNeilBrown { 50470c3b76cSNeilBrown char *mesg = buf; 5058daf220aSBenny Halevy char *vers, *minorp, sign; 506261758b5SChuck Lever int len, num, remaining; 5078daf220aSBenny Halevy unsigned minor; 50870c3b76cSNeilBrown ssize_t tlen = 0; 50970c3b76cSNeilBrown char *sep; 51070c3b76cSNeilBrown 51170c3b76cSNeilBrown if (size>0) { 51270c3b76cSNeilBrown if (nfsd_serv) 5136658d3a7SNeilBrown /* Cannot change versions without updating 5146658d3a7SNeilBrown * nfsd_serv->sv_xdrsize, and reallocing 5156658d3a7SNeilBrown * rq_argp and rq_resp 5166658d3a7SNeilBrown */ 51770c3b76cSNeilBrown return -EBUSY; 51870c3b76cSNeilBrown if (buf[size-1] != '\n') 51970c3b76cSNeilBrown return -EINVAL; 52070c3b76cSNeilBrown buf[size-1] = 0; 52170c3b76cSNeilBrown 52270c3b76cSNeilBrown vers = mesg; 52370c3b76cSNeilBrown len = qword_get(&mesg, vers, size); 52470c3b76cSNeilBrown if (len <= 0) return -EINVAL; 52570c3b76cSNeilBrown do { 52670c3b76cSNeilBrown sign = *vers; 52770c3b76cSNeilBrown if (sign == '+' || sign == '-') 5288daf220aSBenny Halevy num = simple_strtol((vers+1), &minorp, 0); 52970c3b76cSNeilBrown else 5308daf220aSBenny Halevy num = simple_strtol(vers, &minorp, 0); 5318daf220aSBenny Halevy if (*minorp == '.') { 5328daf220aSBenny Halevy if (num < 4) 5338daf220aSBenny Halevy return -EINVAL; 5348daf220aSBenny Halevy minor = simple_strtoul(minorp+1, NULL, 0); 5358daf220aSBenny Halevy if (minor == 0) 5368daf220aSBenny Halevy return -EINVAL; 5378daf220aSBenny Halevy if (nfsd_minorversion(minor, sign == '-' ? 5388daf220aSBenny Halevy NFSD_CLEAR : NFSD_SET) < 0) 5398daf220aSBenny Halevy return -EINVAL; 5408daf220aSBenny Halevy goto next; 5418daf220aSBenny Halevy } 54270c3b76cSNeilBrown switch(num) { 54370c3b76cSNeilBrown case 2: 54470c3b76cSNeilBrown case 3: 54570c3b76cSNeilBrown case 4: 5466658d3a7SNeilBrown nfsd_vers(num, sign == '-' ? NFSD_CLEAR : NFSD_SET); 54770c3b76cSNeilBrown break; 54870c3b76cSNeilBrown default: 54970c3b76cSNeilBrown return -EINVAL; 55070c3b76cSNeilBrown } 5518daf220aSBenny Halevy next: 55270c3b76cSNeilBrown vers += len + 1; 55370c3b76cSNeilBrown } while ((len = qword_get(&mesg, vers, size)) > 0); 55470c3b76cSNeilBrown /* If all get turned off, turn them back on, as 55570c3b76cSNeilBrown * having no versions is BAD 55670c3b76cSNeilBrown */ 5576658d3a7SNeilBrown nfsd_reset_versions(); 55870c3b76cSNeilBrown } 559261758b5SChuck Lever 56070c3b76cSNeilBrown /* Now write current state into reply buffer */ 56170c3b76cSNeilBrown len = 0; 56270c3b76cSNeilBrown sep = ""; 563261758b5SChuck Lever remaining = SIMPLE_TRANSACTION_LIMIT; 56470c3b76cSNeilBrown for (num=2 ; num <= 4 ; num++) 5656658d3a7SNeilBrown if (nfsd_vers(num, NFSD_AVAIL)) { 566261758b5SChuck Lever len = snprintf(buf, remaining, "%s%c%d", sep, 5676658d3a7SNeilBrown nfsd_vers(num, NFSD_TEST)?'+':'-', 56870c3b76cSNeilBrown num); 56970c3b76cSNeilBrown sep = " "; 570261758b5SChuck Lever 571261758b5SChuck Lever if (len > remaining) 572261758b5SChuck Lever break; 573261758b5SChuck Lever remaining -= len; 574261758b5SChuck Lever buf += len; 575261758b5SChuck Lever tlen += len; 57670c3b76cSNeilBrown } 5778daf220aSBenny Halevy if (nfsd_vers(4, NFSD_AVAIL)) 578261758b5SChuck Lever for (minor = 1; minor <= NFSD_SUPPORTED_MINOR_VERSION; 579261758b5SChuck Lever minor++) { 580261758b5SChuck Lever len = snprintf(buf, remaining, " %c4.%u", 5818daf220aSBenny Halevy (nfsd_vers(4, NFSD_TEST) && 5828daf220aSBenny Halevy nfsd_minorversion(minor, NFSD_TEST)) ? 5838daf220aSBenny Halevy '+' : '-', 5848daf220aSBenny Halevy minor); 585261758b5SChuck Lever 586261758b5SChuck Lever if (len > remaining) 587261758b5SChuck Lever break; 588261758b5SChuck Lever remaining -= len; 589261758b5SChuck Lever buf += len; 590261758b5SChuck Lever tlen += len; 591261758b5SChuck Lever } 592261758b5SChuck Lever 593261758b5SChuck Lever len = snprintf(buf, remaining, "\n"); 594261758b5SChuck Lever if (len > remaining) 595261758b5SChuck Lever return -EINVAL; 596261758b5SChuck Lever return tlen + len; 59770c3b76cSNeilBrown } 59870c3b76cSNeilBrown 599262a0982SChuck Lever /** 600262a0982SChuck Lever * write_versions - Set or report the available NFS protocol versions 601262a0982SChuck Lever * 602262a0982SChuck Lever * Input: 603262a0982SChuck Lever * buf: ignored 604262a0982SChuck Lever * size: zero 605262a0982SChuck Lever * Output: 606262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 607262a0982SChuck Lever * string containing positive or negative integer 608262a0982SChuck Lever * values representing the current status of each 609262a0982SChuck Lever * protocol version; 610262a0982SChuck Lever * return code is the size in bytes of the string 611262a0982SChuck Lever * On error: return code is zero or a negative errno value 612262a0982SChuck Lever * 613262a0982SChuck Lever * OR 614262a0982SChuck Lever * 615262a0982SChuck Lever * Input: 616262a0982SChuck Lever * buf: C string containing whitespace- 617262a0982SChuck Lever * separated positive or negative 618262a0982SChuck Lever * integer values representing NFS 619262a0982SChuck Lever * protocol versions to enable ("+n") 620262a0982SChuck Lever * or disable ("-n") 621262a0982SChuck Lever * size: non-zero length of C string in @buf 622262a0982SChuck Lever * Output: 623262a0982SChuck Lever * On success: status of zero or more protocol versions has 624262a0982SChuck Lever * been updated; passed-in buffer filled with 625262a0982SChuck Lever * '\n'-terminated C string containing positive 626262a0982SChuck Lever * or negative integer values representing the 627262a0982SChuck Lever * current status of each protocol version; 628262a0982SChuck Lever * return code is the size in bytes of the string 629262a0982SChuck Lever * On error: return code is zero or a negative errno value 630262a0982SChuck Lever */ 6313dd98a3bSJeff Layton static ssize_t write_versions(struct file *file, char *buf, size_t size) 6323dd98a3bSJeff Layton { 6333dd98a3bSJeff Layton ssize_t rv; 6343dd98a3bSJeff Layton 6353dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 6363dd98a3bSJeff Layton rv = __write_versions(file, buf, size); 6373dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 6383dd98a3bSJeff Layton return rv; 6393dd98a3bSJeff Layton } 6403dd98a3bSJeff Layton 6414cd5dc75SChuck Lever /* 6420a5372d8SChuck Lever * Zero-length write. Return a list of NFSD's current listener 6430a5372d8SChuck Lever * transports. 6440a5372d8SChuck Lever */ 6450a5372d8SChuck Lever static ssize_t __write_ports_names(char *buf) 6460a5372d8SChuck Lever { 6470a5372d8SChuck Lever if (nfsd_serv == NULL) 6480a5372d8SChuck Lever return 0; 649335c54bdSChuck Lever return svc_xprt_names(nfsd_serv, buf, SIMPLE_TRANSACTION_LIMIT); 6500a5372d8SChuck Lever } 6510a5372d8SChuck Lever 6520a5372d8SChuck Lever /* 6530b7c2f6fSChuck Lever * A single 'fd' number was written, in which case it must be for 6540b7c2f6fSChuck Lever * a socket of a supported family/protocol, and we use it as an 6550b7c2f6fSChuck Lever * nfsd listener. 6560b7c2f6fSChuck Lever */ 6570b7c2f6fSChuck Lever static ssize_t __write_ports_addfd(char *buf) 6580b7c2f6fSChuck Lever { 6590b7c2f6fSChuck Lever char *mesg = buf; 6600b7c2f6fSChuck Lever int fd, err; 661786185b5SStanislav Kinsbursky struct net *net = &init_net; 6620b7c2f6fSChuck Lever 6630b7c2f6fSChuck Lever err = get_int(&mesg, &fd); 6640b7c2f6fSChuck Lever if (err != 0 || fd < 0) 6650b7c2f6fSChuck Lever return -EINVAL; 6660b7c2f6fSChuck Lever 6670b7c2f6fSChuck Lever err = nfsd_create_serv(); 6680b7c2f6fSChuck Lever if (err != 0) 6690b7c2f6fSChuck Lever return err; 6700b7c2f6fSChuck Lever 671bfba9ab4SChuck Lever err = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT); 67278a8d7c8SJeff Layton if (err < 0) { 67319f7e2caSStanislav Kinsbursky nfsd_destroy(net); 67478a8d7c8SJeff Layton return err; 67578a8d7c8SJeff Layton } 676ea068badSChuck Lever 6770b7c2f6fSChuck Lever /* Decrease the count, but don't shut down the service */ 6780b7c2f6fSChuck Lever nfsd_serv->sv_nrthreads--; 679ea068badSChuck Lever return err; 6800b7c2f6fSChuck Lever } 6810b7c2f6fSChuck Lever 6820b7c2f6fSChuck Lever /* 6834eb68c26SChuck Lever * A transport listener is added by writing it's transport name and 6844eb68c26SChuck Lever * a port number. 6854eb68c26SChuck Lever */ 6864eb68c26SChuck Lever static ssize_t __write_ports_addxprt(char *buf) 6874eb68c26SChuck Lever { 6884eb68c26SChuck Lever char transport[16]; 68937498292SChuck Lever struct svc_xprt *xprt; 6904eb68c26SChuck Lever int port, err; 691786185b5SStanislav Kinsbursky struct net *net = &init_net; 6924eb68c26SChuck Lever 693a10fded1SJ. Bruce Fields if (sscanf(buf, "%15s %5u", transport, &port) != 2) 6944eb68c26SChuck Lever return -EINVAL; 6954eb68c26SChuck Lever 6964be929beSAlexey Dobriyan if (port < 1 || port > USHRT_MAX) 6974eb68c26SChuck Lever return -EINVAL; 6984eb68c26SChuck Lever 6994eb68c26SChuck Lever err = nfsd_create_serv(); 7004eb68c26SChuck Lever if (err != 0) 7014eb68c26SChuck Lever return err; 7024eb68c26SChuck Lever 703786185b5SStanislav Kinsbursky err = svc_create_xprt(nfsd_serv, transport, net, 7044eb68c26SChuck Lever PF_INET, port, SVC_SOCK_ANONYMOUS); 70568717908SChuck Lever if (err < 0) 70637498292SChuck Lever goto out_err; 70737498292SChuck Lever 708786185b5SStanislav Kinsbursky err = svc_create_xprt(nfsd_serv, transport, net, 70937498292SChuck Lever PF_INET6, port, SVC_SOCK_ANONYMOUS); 71037498292SChuck Lever if (err < 0 && err != -EAFNOSUPPORT) 71137498292SChuck Lever goto out_close; 7120cd14a06SJeff Layton 7130cd14a06SJeff Layton /* Decrease the count, but don't shut down the service */ 7140cd14a06SJeff Layton nfsd_serv->sv_nrthreads--; 7154eb68c26SChuck Lever return 0; 71637498292SChuck Lever out_close: 717786185b5SStanislav Kinsbursky xprt = svc_find_xprt(nfsd_serv, transport, net, PF_INET, port); 71837498292SChuck Lever if (xprt != NULL) { 71937498292SChuck Lever svc_close_xprt(xprt); 72037498292SChuck Lever svc_xprt_put(xprt); 72137498292SChuck Lever } 72237498292SChuck Lever out_err: 72319f7e2caSStanislav Kinsbursky nfsd_destroy(net); 72437498292SChuck Lever return err; 7254eb68c26SChuck Lever } 7264eb68c26SChuck Lever 727bedbdd8bSNeil Brown static ssize_t __write_ports(struct file *file, char *buf, size_t size) 72880212d59SNeilBrown { 7290a5372d8SChuck Lever if (size == 0) 7300a5372d8SChuck Lever return __write_ports_names(buf); 7310b7c2f6fSChuck Lever 7320b7c2f6fSChuck Lever if (isdigit(buf[0])) 7330b7c2f6fSChuck Lever return __write_ports_addfd(buf); 73482d56591SChuck Lever 7354eb68c26SChuck Lever if (isalpha(buf[0])) 7364eb68c26SChuck Lever return __write_ports_addxprt(buf); 7374cd5dc75SChuck Lever 738b41b66d6SNeilBrown return -EINVAL; 739b41b66d6SNeilBrown } 74080212d59SNeilBrown 741262a0982SChuck Lever /** 742262a0982SChuck Lever * write_ports - Pass a socket file descriptor or transport name to listen on 743262a0982SChuck Lever * 744262a0982SChuck Lever * Input: 745262a0982SChuck Lever * buf: ignored 746262a0982SChuck Lever * size: zero 747262a0982SChuck Lever * Output: 748262a0982SChuck Lever * On success: passed-in buffer filled with a '\n'-terminated C 749262a0982SChuck Lever * string containing a whitespace-separated list of 750262a0982SChuck Lever * named NFSD listeners; 751262a0982SChuck Lever * return code is the size in bytes of the string 752262a0982SChuck Lever * On error: return code is zero or a negative errno value 753262a0982SChuck Lever * 754262a0982SChuck Lever * OR 755262a0982SChuck Lever * 756262a0982SChuck Lever * Input: 757262a0982SChuck Lever * buf: C string containing an unsigned 758262a0982SChuck Lever * integer value representing a bound 759262a0982SChuck Lever * but unconnected socket that is to be 760c71206a7SChuck Lever * used as an NFSD listener; listen(3) 761c71206a7SChuck Lever * must be called for a SOCK_STREAM 762c71206a7SChuck Lever * socket, otherwise it is ignored 763262a0982SChuck Lever * size: non-zero length of C string in @buf 764262a0982SChuck Lever * Output: 765262a0982SChuck Lever * On success: NFS service is started; 766262a0982SChuck Lever * passed-in buffer filled with a '\n'-terminated C 767262a0982SChuck Lever * string containing a unique alphanumeric name of 768262a0982SChuck Lever * the listener; 769262a0982SChuck Lever * return code is the size in bytes of the string 770262a0982SChuck Lever * On error: return code is a negative errno value 771262a0982SChuck Lever * 772262a0982SChuck Lever * OR 773262a0982SChuck Lever * 774262a0982SChuck Lever * Input: 775262a0982SChuck Lever * buf: C string containing a transport 776262a0982SChuck Lever * name and an unsigned integer value 777262a0982SChuck Lever * representing the port to listen on, 778262a0982SChuck Lever * separated by whitespace 779262a0982SChuck Lever * size: non-zero length of C string in @buf 780262a0982SChuck Lever * Output: 781262a0982SChuck Lever * On success: returns zero; NFS service is started 782262a0982SChuck Lever * On error: return code is a negative errno value 783262a0982SChuck Lever */ 784bedbdd8bSNeil Brown static ssize_t write_ports(struct file *file, char *buf, size_t size) 785bedbdd8bSNeil Brown { 786bedbdd8bSNeil Brown ssize_t rv; 7873dd98a3bSJeff Layton 788bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 789bedbdd8bSNeil Brown rv = __write_ports(file, buf, size); 790bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 791bedbdd8bSNeil Brown return rv; 792bedbdd8bSNeil Brown } 793bedbdd8bSNeil Brown 794bedbdd8bSNeil Brown 795596bbe53SNeilBrown int nfsd_max_blksize; 796596bbe53SNeilBrown 797262a0982SChuck Lever /** 798262a0982SChuck Lever * write_maxblksize - Set or report the current NFS blksize 799262a0982SChuck Lever * 800262a0982SChuck Lever * Input: 801262a0982SChuck Lever * buf: ignored 802262a0982SChuck Lever * size: zero 803262a0982SChuck Lever * 804262a0982SChuck Lever * OR 805262a0982SChuck Lever * 806262a0982SChuck Lever * Input: 807262a0982SChuck Lever * buf: C string containing an unsigned 808262a0982SChuck Lever * integer value representing the new 809262a0982SChuck Lever * NFS blksize 810262a0982SChuck Lever * size: non-zero length of C string in @buf 811262a0982SChuck Lever * Output: 812262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 813262a0982SChuck Lever * containing numeric value of the current NFS blksize 814262a0982SChuck Lever * setting; 815262a0982SChuck Lever * return code is the size in bytes of the string 816262a0982SChuck Lever * On error: return code is zero or a negative errno value 817262a0982SChuck Lever */ 818596bbe53SNeilBrown static ssize_t write_maxblksize(struct file *file, char *buf, size_t size) 819596bbe53SNeilBrown { 820596bbe53SNeilBrown char *mesg = buf; 821596bbe53SNeilBrown if (size > 0) { 822596bbe53SNeilBrown int bsize; 823596bbe53SNeilBrown int rv = get_int(&mesg, &bsize); 824596bbe53SNeilBrown if (rv) 825596bbe53SNeilBrown return rv; 826596bbe53SNeilBrown /* force bsize into allowed range and 827596bbe53SNeilBrown * required alignment. 828596bbe53SNeilBrown */ 829596bbe53SNeilBrown if (bsize < 1024) 830596bbe53SNeilBrown bsize = 1024; 831596bbe53SNeilBrown if (bsize > NFSSVC_MAXBLKSIZE) 832596bbe53SNeilBrown bsize = NFSSVC_MAXBLKSIZE; 833596bbe53SNeilBrown bsize &= ~(1024-1); 834bedbdd8bSNeil Brown mutex_lock(&nfsd_mutex); 8357fa53cc8SJ. Bruce Fields if (nfsd_serv) { 836bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 837596bbe53SNeilBrown return -EBUSY; 838596bbe53SNeilBrown } 839596bbe53SNeilBrown nfsd_max_blksize = bsize; 840bedbdd8bSNeil Brown mutex_unlock(&nfsd_mutex); 841596bbe53SNeilBrown } 842e06b6405SChuck Lever 843e06b6405SChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n", 844e06b6405SChuck Lever nfsd_max_blksize); 845596bbe53SNeilBrown } 846596bbe53SNeilBrown 84770c3b76cSNeilBrown #ifdef CONFIG_NFSD_V4 848f0135740SJ. Bruce Fields static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) 8491da177e4SLinus Torvalds { 8501da177e4SLinus Torvalds char *mesg = buf; 851f0135740SJ. Bruce Fields int rv, i; 8521da177e4SLinus Torvalds 8531da177e4SLinus Torvalds if (size > 0) { 8543dd98a3bSJeff Layton if (nfsd_serv) 8553dd98a3bSJeff Layton return -EBUSY; 856f0135740SJ. Bruce Fields rv = get_int(&mesg, &i); 8571da177e4SLinus Torvalds if (rv) 8581da177e4SLinus Torvalds return rv; 859e7b184f1SJ. Bruce Fields /* 860e7b184f1SJ. Bruce Fields * Some sanity checking. We don't have a reason for 861e7b184f1SJ. Bruce Fields * these particular numbers, but problems with the 862e7b184f1SJ. Bruce Fields * extremes are: 863e7b184f1SJ. Bruce Fields * - Too short: the briefest network outage may 864e7b184f1SJ. Bruce Fields * cause clients to lose all their locks. Also, 865e7b184f1SJ. Bruce Fields * the frequent polling may be wasteful. 866e7b184f1SJ. Bruce Fields * - Too long: do you really want reboot recovery 867e7b184f1SJ. Bruce Fields * to take more than an hour? Or to make other 868e7b184f1SJ. Bruce Fields * clients wait an hour before being able to 869e7b184f1SJ. Bruce Fields * revoke a dead client's locks? 870e7b184f1SJ. Bruce Fields */ 871f0135740SJ. Bruce Fields if (i < 10 || i > 3600) 8721da177e4SLinus Torvalds return -EINVAL; 873f0135740SJ. Bruce Fields *time = i; 8741da177e4SLinus Torvalds } 875e06b6405SChuck Lever 876f0135740SJ. Bruce Fields return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time); 877f0135740SJ. Bruce Fields } 878f0135740SJ. Bruce Fields 879f0135740SJ. Bruce Fields static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time) 880f0135740SJ. Bruce Fields { 881f0135740SJ. Bruce Fields ssize_t rv; 882f0135740SJ. Bruce Fields 883f0135740SJ. Bruce Fields mutex_lock(&nfsd_mutex); 884f0135740SJ. Bruce Fields rv = __nfsd4_write_time(file, buf, size, time); 885f0135740SJ. Bruce Fields mutex_unlock(&nfsd_mutex); 886f0135740SJ. Bruce Fields return rv; 8871da177e4SLinus Torvalds } 8881da177e4SLinus Torvalds 889262a0982SChuck Lever /** 890262a0982SChuck Lever * write_leasetime - Set or report the current NFSv4 lease time 891262a0982SChuck Lever * 892262a0982SChuck Lever * Input: 893262a0982SChuck Lever * buf: ignored 894262a0982SChuck Lever * size: zero 895262a0982SChuck Lever * 896262a0982SChuck Lever * OR 897262a0982SChuck Lever * 898262a0982SChuck Lever * Input: 899262a0982SChuck Lever * buf: C string containing an unsigned 900262a0982SChuck Lever * integer value representing the new 901262a0982SChuck Lever * NFSv4 lease expiry time 902262a0982SChuck Lever * size: non-zero length of C string in @buf 903262a0982SChuck Lever * Output: 904262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C 905262a0982SChuck Lever * string containing unsigned integer value of the 906262a0982SChuck Lever * current lease expiry time; 907262a0982SChuck Lever * return code is the size in bytes of the string 908262a0982SChuck Lever * On error: return code is zero or a negative errno value 909262a0982SChuck Lever */ 9103dd98a3bSJeff Layton static ssize_t write_leasetime(struct file *file, char *buf, size_t size) 9113dd98a3bSJeff Layton { 9123d733711SStanislav Kinsbursky struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id); 9133d733711SStanislav Kinsbursky return nfsd4_write_time(file, buf, size, &nn->nfsd4_lease); 9143dd98a3bSJeff Layton } 9153dd98a3bSJeff Layton 916efc4bb4fSJ. Bruce Fields /** 917efc4bb4fSJ. Bruce Fields * write_gracetime - Set or report current NFSv4 grace period time 918efc4bb4fSJ. Bruce Fields * 919efc4bb4fSJ. Bruce Fields * As above, but sets the time of the NFSv4 grace period. 920efc4bb4fSJ. Bruce Fields * 921efc4bb4fSJ. Bruce Fields * Note this should never be set to less than the *previous* 922efc4bb4fSJ. Bruce Fields * lease-period time, but we don't try to enforce this. (In the common 923efc4bb4fSJ. Bruce Fields * case (a new boot), we don't know what the previous lease time was 924efc4bb4fSJ. Bruce Fields * anyway.) 925efc4bb4fSJ. Bruce Fields */ 926efc4bb4fSJ. Bruce Fields static ssize_t write_gracetime(struct file *file, char *buf, size_t size) 927efc4bb4fSJ. Bruce Fields { 928efc4bb4fSJ. Bruce Fields return nfsd4_write_time(file, buf, size, &nfsd4_grace); 929efc4bb4fSJ. Bruce Fields } 930efc4bb4fSJ. Bruce Fields 9313dd98a3bSJeff Layton static ssize_t __write_recoverydir(struct file *file, char *buf, size_t size) 9320964a3d3SNeilBrown { 9330964a3d3SNeilBrown char *mesg = buf; 9340964a3d3SNeilBrown char *recdir; 9350964a3d3SNeilBrown int len, status; 9360964a3d3SNeilBrown 9373dd98a3bSJeff Layton if (size > 0) { 9383dd98a3bSJeff Layton if (nfsd_serv) 9393dd98a3bSJeff Layton return -EBUSY; 9403dd98a3bSJeff Layton if (size > PATH_MAX || buf[size-1] != '\n') 9410964a3d3SNeilBrown return -EINVAL; 9420964a3d3SNeilBrown buf[size-1] = 0; 9430964a3d3SNeilBrown 9440964a3d3SNeilBrown recdir = mesg; 9450964a3d3SNeilBrown len = qword_get(&mesg, recdir, size); 9460964a3d3SNeilBrown if (len <= 0) 9470964a3d3SNeilBrown return -EINVAL; 9480964a3d3SNeilBrown 9490964a3d3SNeilBrown status = nfs4_reset_recoverydir(recdir); 95069049961SAndi Kleen if (status) 95169049961SAndi Kleen return status; 9523dd98a3bSJeff Layton } 9533d72ab8fSChuck Lever 9543d72ab8fSChuck Lever return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%s\n", 9553d72ab8fSChuck Lever nfs4_recoverydir()); 9560964a3d3SNeilBrown } 9573dd98a3bSJeff Layton 958262a0982SChuck Lever /** 959262a0982SChuck Lever * write_recoverydir - Set or report the pathname of the recovery directory 960262a0982SChuck Lever * 961262a0982SChuck Lever * Input: 962262a0982SChuck Lever * buf: ignored 963262a0982SChuck Lever * size: zero 964262a0982SChuck Lever * 965262a0982SChuck Lever * OR 966262a0982SChuck Lever * 967262a0982SChuck Lever * Input: 968262a0982SChuck Lever * buf: C string containing the pathname 969262a0982SChuck Lever * of the directory on a local file 970262a0982SChuck Lever * system containing permanent NFSv4 971262a0982SChuck Lever * recovery data 972262a0982SChuck Lever * size: non-zero length of C string in @buf 973262a0982SChuck Lever * Output: 974262a0982SChuck Lever * On success: passed-in buffer filled with '\n'-terminated C string 975262a0982SChuck Lever * containing the current recovery pathname setting; 976262a0982SChuck Lever * return code is the size in bytes of the string 977262a0982SChuck Lever * On error: return code is zero or a negative errno value 978262a0982SChuck Lever */ 9793dd98a3bSJeff Layton static ssize_t write_recoverydir(struct file *file, char *buf, size_t size) 9803dd98a3bSJeff Layton { 9813dd98a3bSJeff Layton ssize_t rv; 9823dd98a3bSJeff Layton 9833dd98a3bSJeff Layton mutex_lock(&nfsd_mutex); 9843dd98a3bSJeff Layton rv = __write_recoverydir(file, buf, size); 9853dd98a3bSJeff Layton mutex_unlock(&nfsd_mutex); 9863dd98a3bSJeff Layton return rv; 9873dd98a3bSJeff Layton } 9883dd98a3bSJeff Layton 98970c3b76cSNeilBrown #endif 9900964a3d3SNeilBrown 9911da177e4SLinus Torvalds /*----------------------------------------------------------------------------*/ 9921da177e4SLinus Torvalds /* 9931da177e4SLinus Torvalds * populating the filesystem. 9941da177e4SLinus Torvalds */ 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds static int nfsd_fill_super(struct super_block * sb, void * data, int silent) 9971da177e4SLinus Torvalds { 9981da177e4SLinus Torvalds static struct tree_descr nfsd_files[] = { 9991da177e4SLinus Torvalds [NFSD_List] = {"exports", &exports_operations, S_IRUGO}, 1000e8e8753fSJ. Bruce Fields [NFSD_Export_features] = {"export_features", 1001e8e8753fSJ. Bruce Fields &export_features_operations, S_IRUGO}, 10024373ea84SWendy Cheng [NFSD_FO_UnlockIP] = {"unlock_ip", 10034373ea84SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 100417efa372SWendy Cheng [NFSD_FO_UnlockFS] = {"unlock_filesystem", 100517efa372SWendy Cheng &transaction_ops, S_IWUSR|S_IRUSR}, 10061da177e4SLinus Torvalds [NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR}, 10071da177e4SLinus Torvalds [NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR}, 1008eed2965aSGreg Banks [NFSD_Pool_Threads] = {"pool_threads", &transaction_ops, S_IWUSR|S_IRUSR}, 100903cf6c9fSGreg Banks [NFSD_Pool_Stats] = {"pool_stats", &pool_stats_operations, S_IRUGO}, 101070c3b76cSNeilBrown [NFSD_Versions] = {"versions", &transaction_ops, S_IWUSR|S_IRUSR}, 101180212d59SNeilBrown [NFSD_Ports] = {"portlist", &transaction_ops, S_IWUSR|S_IRUGO}, 1012596bbe53SNeilBrown [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO}, 1013b084f598SJ. Bruce Fields #if defined(CONFIG_SUNRPC_GSS) || defined(CONFIG_SUNRPC_GSS_MODULE) 1014b0b0c0a2SKevin Coffman [NFSD_SupportedEnctypes] = {"supported_krb5_enctypes", &supported_enctypes_ops, S_IRUGO}, 1015b084f598SJ. Bruce Fields #endif /* CONFIG_SUNRPC_GSS or CONFIG_SUNRPC_GSS_MODULE */ 10161da177e4SLinus Torvalds #ifdef CONFIG_NFSD_V4 10171da177e4SLinus Torvalds [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR}, 1018efc4bb4fSJ. Bruce Fields [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR}, 10190964a3d3SNeilBrown [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR}, 10201da177e4SLinus Torvalds #endif 10211da177e4SLinus Torvalds /* last one */ {""} 10221da177e4SLinus Torvalds }; 10231da177e4SLinus Torvalds return simple_fill_super(sb, 0x6e667364, nfsd_files); 10241da177e4SLinus Torvalds } 10251da177e4SLinus Torvalds 1026fc14f2feSAl Viro static struct dentry *nfsd_mount(struct file_system_type *fs_type, 1027fc14f2feSAl Viro int flags, const char *dev_name, void *data) 10281da177e4SLinus Torvalds { 1029fc14f2feSAl Viro return mount_single(fs_type, flags, data, nfsd_fill_super); 10301da177e4SLinus Torvalds } 10311da177e4SLinus Torvalds 10321da177e4SLinus Torvalds static struct file_system_type nfsd_fs_type = { 10331da177e4SLinus Torvalds .owner = THIS_MODULE, 10341da177e4SLinus Torvalds .name = "nfsd", 1035fc14f2feSAl Viro .mount = nfsd_mount, 10361da177e4SLinus Torvalds .kill_sb = kill_litter_super, 10371da177e4SLinus Torvalds }; 10381da177e4SLinus Torvalds 1039e331f606SJ. Bruce Fields #ifdef CONFIG_PROC_FS 1040e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1041e331f606SJ. Bruce Fields { 1042e331f606SJ. Bruce Fields struct proc_dir_entry *entry; 1043e331f606SJ. Bruce Fields 1044e331f606SJ. Bruce Fields entry = proc_mkdir("fs/nfs", NULL); 1045e331f606SJ. Bruce Fields if (!entry) 1046e331f606SJ. Bruce Fields return -ENOMEM; 10479ef2db26SDenis V. Lunev entry = proc_create("exports", 0, entry, &exports_operations); 1048e331f606SJ. Bruce Fields if (!entry) 1049e331f606SJ. Bruce Fields return -ENOMEM; 1050e331f606SJ. Bruce Fields return 0; 1051e331f606SJ. Bruce Fields } 1052e331f606SJ. Bruce Fields #else /* CONFIG_PROC_FS */ 1053e331f606SJ. Bruce Fields static int create_proc_exports_entry(void) 1054e331f606SJ. Bruce Fields { 1055e331f606SJ. Bruce Fields return 0; 1056e331f606SJ. Bruce Fields } 1057e331f606SJ. Bruce Fields #endif 1058e331f606SJ. Bruce Fields 10597ea34ac1SJeff Layton int nfsd_net_id; 10605717e012SStanislav Kinsbursky 10615717e012SStanislav Kinsbursky static __net_init int nfsd_init_net(struct net *net) 10625717e012SStanislav Kinsbursky { 10635717e012SStanislav Kinsbursky int retval; 10643d733711SStanislav Kinsbursky struct nfsd_net *nn = net_generic(net, nfsd_net_id); 10655717e012SStanislav Kinsbursky 10665717e012SStanislav Kinsbursky retval = nfsd_export_init(net); 10675717e012SStanislav Kinsbursky if (retval) 10685717e012SStanislav Kinsbursky goto out_export_error; 1069f69adb2fSStanislav Kinsbursky retval = nfsd_idmap_init(net); 1070f69adb2fSStanislav Kinsbursky if (retval) 1071f69adb2fSStanislav Kinsbursky goto out_idmap_error; 10723d733711SStanislav Kinsbursky nn->nfsd4_lease = 90; /* default lease time */ 10735717e012SStanislav Kinsbursky return 0; 10745717e012SStanislav Kinsbursky 1075f69adb2fSStanislav Kinsbursky out_idmap_error: 1076f69adb2fSStanislav Kinsbursky nfsd_export_shutdown(net); 10775717e012SStanislav Kinsbursky out_export_error: 10785717e012SStanislav Kinsbursky return retval; 10795717e012SStanislav Kinsbursky } 10805717e012SStanislav Kinsbursky 10815717e012SStanislav Kinsbursky static __net_exit void nfsd_exit_net(struct net *net) 10825717e012SStanislav Kinsbursky { 1083f69adb2fSStanislav Kinsbursky nfsd_idmap_shutdown(net); 10845717e012SStanislav Kinsbursky nfsd_export_shutdown(net); 10855717e012SStanislav Kinsbursky } 10865717e012SStanislav Kinsbursky 10877ea34ac1SJeff Layton static struct pernet_operations nfsd_net_ops = { 10885717e012SStanislav Kinsbursky .init = nfsd_init_net, 10895717e012SStanislav Kinsbursky .exit = nfsd_exit_net, 10907ea34ac1SJeff Layton .id = &nfsd_net_id, 10917ea34ac1SJeff Layton .size = sizeof(struct nfsd_net), 10927ea34ac1SJeff Layton }; 10937ea34ac1SJeff Layton 10941da177e4SLinus Torvalds static int __init init_nfsd(void) 10951da177e4SLinus Torvalds { 10961da177e4SLinus Torvalds int retval; 10971da177e4SLinus Torvalds printk(KERN_INFO "Installing knfsd (copyright (C) 1996 okir@monad.swb.de).\n"); 10981da177e4SLinus Torvalds 1099797a9d79SJeff Layton retval = register_cld_notifier(); 1100813fd320SJeff Layton if (retval) 1101813fd320SJeff Layton return retval; 11027ea34ac1SJeff Layton retval = register_pernet_subsys(&nfsd_net_ops); 11037ea34ac1SJeff Layton if (retval < 0) 1104813fd320SJeff Layton goto out_unregister_notifier; 110572083396SBryan Schumaker retval = nfsd4_init_slabs(); 1106e8ff2a84SJ. Bruce Fields if (retval) 11077ea34ac1SJeff Layton goto out_unregister_pernet; 110872083396SBryan Schumaker nfs4_state_init(); 110965178db4SBryan Schumaker retval = nfsd_fault_inject_init(); /* nfsd fault injection controls */ 111065178db4SBryan Schumaker if (retval) 111165178db4SBryan Schumaker goto out_free_slabs; 11121da177e4SLinus Torvalds nfsd_stat_init(); /* Statistics */ 1113d5c3428bSJ. Bruce Fields retval = nfsd_reply_cache_init(); 1114d5c3428bSJ. Bruce Fields if (retval) 1115d5c3428bSJ. Bruce Fields goto out_free_stat; 11161da177e4SLinus Torvalds nfsd_lockd_init(); /* lockd->nfsd callbacks */ 1117e331f606SJ. Bruce Fields retval = create_proc_exports_entry(); 1118e331f606SJ. Bruce Fields if (retval) 1119f69adb2fSStanislav Kinsbursky goto out_free_lockd; 11201da177e4SLinus Torvalds retval = register_filesystem(&nfsd_fs_type); 112126808d3fSJ. Bruce Fields if (retval) 112226808d3fSJ. Bruce Fields goto out_free_all; 112326808d3fSJ. Bruce Fields return 0; 112426808d3fSJ. Bruce Fields out_free_all: 11251da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 11261da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 1127dbf847ecSJ. Bruce Fields out_free_lockd: 11281da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1129e331f606SJ. Bruce Fields nfsd_reply_cache_shutdown(); 1130d5c3428bSJ. Bruce Fields out_free_stat: 1131d5c3428bSJ. Bruce Fields nfsd_stat_shutdown(); 113265178db4SBryan Schumaker nfsd_fault_inject_cleanup(); 113365178db4SBryan Schumaker out_free_slabs: 113446b25895SJ. Bruce Fields nfsd4_free_slabs(); 11357ea34ac1SJeff Layton out_unregister_pernet: 11367ea34ac1SJeff Layton unregister_pernet_subsys(&nfsd_net_ops); 1137813fd320SJeff Layton out_unregister_notifier: 1138797a9d79SJeff Layton unregister_cld_notifier(); 11391da177e4SLinus Torvalds return retval; 11401da177e4SLinus Torvalds } 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds static void __exit exit_nfsd(void) 11431da177e4SLinus Torvalds { 1144d5c3428bSJ. Bruce Fields nfsd_reply_cache_shutdown(); 11451da177e4SLinus Torvalds remove_proc_entry("fs/nfs/exports", NULL); 11461da177e4SLinus Torvalds remove_proc_entry("fs/nfs", NULL); 11471da177e4SLinus Torvalds nfsd_stat_shutdown(); 11481da177e4SLinus Torvalds nfsd_lockd_shutdown(); 1149e8ff2a84SJ. Bruce Fields nfsd4_free_slabs(); 115065178db4SBryan Schumaker nfsd_fault_inject_cleanup(); 11511da177e4SLinus Torvalds unregister_filesystem(&nfsd_fs_type); 11527ea34ac1SJeff Layton unregister_pernet_subsys(&nfsd_net_ops); 1153797a9d79SJeff Layton unregister_cld_notifier(); 11541da177e4SLinus Torvalds } 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds MODULE_AUTHOR("Olaf Kirch <okir@monad.swb.de>"); 11571da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 11581da177e4SLinus Torvalds module_init(init_nfsd) 11591da177e4SLinus Torvalds module_exit(exit_nfsd) 1160