13 #include <linux/module.h>
15 #include <linux/sched.h>
16 #include <linux/time.h>
17 #include <linux/kernel.h>
19 #include <linux/string.h>
20 #include <linux/stat.h>
21 #include <linux/errno.h>
28 #include <linux/nfs_fs.h>
34 #include <linux/nfs_idmap.h>
37 #include <linux/in6.h>
38 #include <linux/slab.h>
57 #define NFSDBG_FACILITY NFSDBG_CLIENT
77 .version = nfs_version,
83 .program = &nfs_program
89 spin_lock(&nfs_version_lock);
92 if (nfs->
rpc_ops->version == version) {
93 spin_unlock(&nfs_version_lock);
98 spin_unlock(&nfs_version_lock);
108 request_module(
"nfsv%d", version);
109 nfs = find_nfs_version(version);
114 try_module_get(nfs->
owner);
120 module_put(nfs->
owner);
125 spin_lock(&nfs_version_lock);
127 list_add(&nfs->
list, &nfs_versions);
130 spin_unlock(&nfs_version_lock);
136 spin_lock(&nfs_version_lock);
141 spin_unlock(&nfs_version_lock);
154 struct rpc_cred *
cred;
199 #if IS_ENABLED(CONFIG_NFS_V4)
209 static void nfs_cb_idr_remove_locked(
struct nfs_client *clp)
213 if (clp->cl_cb_ident)
214 idr_remove(&nn->cb_ident_idr, clp->cl_cb_ident);
217 static void pnfs_init_server(
struct nfs_server *server)
227 static void nfs_cb_idr_remove_locked(
struct nfs_client *clp)
231 static void pnfs_init_server(
struct nfs_server *server)
258 dprintk(
"<-- nfs_free_client()\n");
277 nfs_cb_idr_remove_locked(clp);
282 clp->
rpc_ops->free_client(clp);
287 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
299 static int nfs_sockaddr_match_ipaddr6(
const struct sockaddr *sa1,
313 static int nfs_sockaddr_match_ipaddr6(
const struct sockaddr *sa1,
327 static int nfs_sockaddr_match_ipaddr4(
const struct sockaddr *sa1,
336 static int nfs_sockaddr_cmp_ip6(
const struct sockaddr *sa1,
342 return nfs_sockaddr_match_ipaddr6(sa1, sa2) &&
346 static int nfs_sockaddr_cmp_ip4(
const struct sockaddr *sa1,
352 return nfs_sockaddr_match_ipaddr4(sa1, sa2) &&
356 #if defined(CONFIG_NFS_V4_1)
361 int nfs_sockaddr_match_ipaddr(
const struct sockaddr *sa1,
369 return nfs_sockaddr_match_ipaddr4(sa1, sa2);
371 return nfs_sockaddr_match_ipaddr6(sa1, sa2);
382 static int nfs_sockaddr_cmp(
const struct sockaddr *sa1,
390 return nfs_sockaddr_cmp_ip4(sa1, sa2);
392 return nfs_sockaddr_cmp_ip6(sa1, sa2);
423 if (!nfs_sockaddr_cmp(sap, clap))
432 static bool nfs_client_init_is_complete(
const struct nfs_client *clp)
440 nfs_client_init_is_complete(clp));
462 return ERR_PTR(error);
467 dprintk(
"<-- %s found nfs_client %p for %s\n",
468 __func__, clp, cl_init->
hostname ?:
"");
478 const struct rpc_timeout *timeparms,
480 rpc_authflavor_t authflavour)
486 dprintk(
"--> nfs_get_client(%s,v%u)\n",
493 clp = nfs_match_client(cl_init);
497 new->rpc_ops->free_client(
new);
498 return nfs_found_client(cl_init, clp);
505 return rpc_ops->
init_client(
new, timeparms, ip_addr,
512 }
while (!IS_ERR(
new));
514 dprintk(
"<-- nfs_get_client() Failed to find %s (%ld)\n",
515 cl_init->
hostname ?:
"", PTR_ERR(
new));
535 unsigned int timeo,
unsigned int retrans)
537 to->to_initval = timeo *
HZ / 10;
538 to->to_retries = retrans;
541 case XPRT_TRANSPORT_TCP:
542 case XPRT_TRANSPORT_RDMA:
543 if (to->to_retries == 0)
545 if (to->to_initval == 0)
549 to->to_increment = to->to_initval;
550 to->to_maxval = to->to_initval + (to->to_increment * to->to_retries);
553 if (to->to_maxval < to->to_initval)
554 to->to_maxval = to->to_initval;
555 to->to_exponential = 0;
557 case XPRT_TRANSPORT_UDP:
558 if (to->to_retries == 0)
565 to->to_exponential = 1;
577 const struct rpc_timeout *timeparms,
578 rpc_authflavor_t flavor)
581 struct rpc_create_args args = {
586 .timeout = timeparms,
588 .program = &nfs_program,
590 .authflavor = flavor,
594 args.flags |= RPC_CLNT_CREATE_DISCRTRY;
596 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
603 dprintk(
"%s: cannot create RPC client. Error = %ld\n",
604 __func__, PTR_ERR(clnt));
605 return PTR_ERR(clnt);
616 static void nfs_destroy_server(
struct nfs_server *server)
626 static int nfs_start_lockd(
struct nfs_server *server)
628 struct nlm_host *
host;
634 .nfs_version = clp->
rpc_ops->version,
650 case XPRT_TRANSPORT_UDP:
656 return PTR_ERR(host);
659 server->
destroy = nfs_destroy_server;
667 const struct rpc_timeout *timeo,
668 rpc_authflavor_t pseudoflavour)
674 if (IS_ERR(server->
client)) {
675 dprintk(
"%s: couldn't create rpc_client!\n", __func__);
676 return PTR_ERR(server->
client);
681 sizeof(server->
client->cl_timeout_default));
682 server->
client->cl_timeout = &server->
client->cl_timeout_default;
683 server->
client->cl_softrtry = 0;
685 server->
client->cl_softrtry = 1;
702 const struct rpc_timeout *timeparms,
703 const char *
ip_addr, rpc_authflavor_t authflavour)
709 dprintk(
"<-- nfs_init_client() = 0 [already %p]\n", clp);
726 dprintk(
"<-- nfs_init_client() = xerror %d\n", error);
727 return ERR_PTR(error);
734 static int nfs_init_server(
struct nfs_server *server,
746 struct rpc_timeout timeparms;
750 dprintk(
"--> nfs_init_server()\n");
762 dprintk(
"<-- nfs_init_server() = error %ld\n", PTR_ERR(clp));
786 error = nfs_start_lockd(server);
807 dprintk(
"<-- nfs_init_server() = 0 [new %p]\n", clp);
813 dprintk(
"<-- nfs_init_server() = xerror %d\n", error);
820 static void nfs_server_set_fsinfo(
struct nfs_server *server,
824 unsigned long max_rpc_payload;
827 if (server->
rsize == 0)
829 if (server->
wsize == 0)
838 if (server->
rsize > max_rpc_payload)
839 server->
rsize = max_rpc_payload;
847 if (server->
wsize > max_rpc_payload)
848 server->
wsize = max_rpc_payload;
883 dprintk(
"--> nfs_probe_fsinfo()\n");
886 error = clp->
rpc_ops->set_capabilities(server, mntfh);
891 fsinfo.
fattr = fattr;
893 error = clp->
rpc_ops->fsinfo(server, mntfh, &fsinfo);
897 nfs_server_set_fsinfo(server, mntfh, &fsinfo);
906 if (clp->
rpc_ops->pathconf(server, mntfh, &pathinfo) >= 0)
910 dprintk(
"<-- nfs_probe_fsinfo() = 0\n");
914 dprintk(
"nfs_probe_fsinfo: error = %d\n", -error);
950 static void nfs_server_remove_lists(
struct nfs_server *server)
985 INIT_LIST_HEAD(&server->
layouts);
990 server->
io_stats = nfs_alloc_iostats();
1004 pnfs_init_server(server);
1015 dprintk(
"--> nfs_free_server()\n");
1017 nfs_server_remove_lists(server);
1024 if (!IS_ERR(server->
client))
1031 nfs_free_iostats(server->
io_stats);
1035 dprintk(
"<-- nfs_free_server()\n");
1060 error = nfs_init_server(server, mount_info->
parsed, nfs_mod);
1072 if (server->
nfs_client->rpc_ops->version == 3) {
1083 error = nfs_mod->
rpc_ops->getattr(server, mount_info->
mntfh, fattr);
1085 dprintk(
"nfs_create_server: getattr error = %d\n", -error);
1091 dprintk(
"Server FSID: %llx:%llx\n",
1092 (
unsigned long long) server->
fsid.major,
1093 (
unsigned long long) server->
fsid.minor);
1097 nfs_free_fattr(fattr);
1101 nfs_free_fattr(fattr);
1103 return ERR_PTR(error);
1113 rpc_authflavor_t flavor)
1119 dprintk(
"--> nfs_clone_server(,%llx:%llx,)\n",
1120 (
unsigned long long) fattr->
fsid.major,
1121 (
unsigned long long) fattr->
fsid.minor);
1129 if (fattr_fsinfo ==
NULL)
1130 goto out_free_server;
1141 source->
client->cl_timeout,
1144 goto out_free_server;
1149 goto out_free_server;
1154 dprintk(
"Cloned FSID: %llx:%llx\n",
1155 (
unsigned long long) server->
fsid.major,
1156 (
unsigned long long) server->
fsid.minor);
1158 error = nfs_start_lockd(server);
1160 goto out_free_server;
1165 nfs_free_fattr(fattr_fsinfo);
1166 dprintk(
"<-- nfs_clone_server() = %p\n", server);
1170 nfs_free_fattr(fattr_fsinfo);
1172 dprintk(
"<-- nfs_clone_server() = error %d\n", error);
1173 return ERR_PTR(error);
1183 #if IS_ENABLED(CONFIG_NFS_V4)
1190 #ifdef CONFIG_PROC_FS
1194 static void *nfs_server_list_start(
struct seq_file *
p, loff_t *
pos);
1195 static void *nfs_server_list_next(
struct seq_file *
p,
void *
v, loff_t *
pos);
1196 static void nfs_server_list_stop(
struct seq_file *
p,
void *
v);
1197 static int nfs_server_list_show(
struct seq_file *
m,
void *
v);
1200 .
start = nfs_server_list_start,
1201 .next = nfs_server_list_next,
1202 .stop = nfs_server_list_stop,
1203 .show = nfs_server_list_show,
1207 .
open = nfs_server_list_open,
1215 static void *nfs_volume_list_start(
struct seq_file *
p, loff_t *
pos);
1216 static void *nfs_volume_list_next(
struct seq_file *
p,
void *
v, loff_t *
pos);
1217 static void nfs_volume_list_stop(
struct seq_file *
p,
void *
v);
1218 static int nfs_volume_list_show(
struct seq_file *
m,
void *
v);
1221 .
start = nfs_volume_list_start,
1222 .next = nfs_volume_list_next,
1223 .stop = nfs_volume_list_stop,
1224 .show = nfs_volume_list_show,
1228 .
open = nfs_volume_list_open,
1243 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1246 ret =
seq_open(file, &nfs_server_list_ops);
1259 static void *nfs_server_list_start(
struct seq_file *m, loff_t *_pos)
1271 static void *nfs_server_list_next(
struct seq_file *
p,
void *
v, loff_t *
pos)
1281 static void nfs_server_list_stop(
struct seq_file *
p,
void *
v)
1291 static int nfs_server_list_show(
struct seq_file *m,
void *
v)
1298 seq_puts(m,
"NV SERVER PORT USE HOSTNAME\n");
1324 static int nfs_volume_list_open(
struct inode *inode,
struct file *file)
1328 struct pid_namespace *pid_ns = file->f_dentry->d_sb->s_fs_info;
1329 struct net *net = pid_ns->
child_reaper->nsproxy->net_ns;
1331 ret =
seq_open(file, &nfs_volume_list_ops);
1344 static void *nfs_volume_list_start(
struct seq_file *m, loff_t *_pos)
1356 static void *nfs_volume_list_next(
struct seq_file *
p,
void *v, loff_t *
pos)
1366 static void nfs_volume_list_stop(
struct seq_file *
p,
void *v)
1376 static int nfs_volume_list_show(
struct seq_file *m,
void *v)
1385 seq_puts(m,
"NV SERVER PORT DEV FSID FSC\n");
1396 (
unsigned long long) server->
fsid.major,
1397 (
unsigned long long) server->
fsid.minor);
1406 nfs_server_fscache_state(server));
1415 int __init nfs_fs_proc_init(
void)
1425 proc_fs_nfs, &nfs_server_list_fops);
1431 proc_fs_nfs, &nfs_volume_list_fops);
1447 void nfs_fs_proc_exit(
void)