diff options
Diffstat (limited to 'fs/nfs')
-rw-r--r-- | fs/nfs/client.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 8b5f9b9685dd..d7f6d50442b7 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -93,22 +93,26 @@ struct rpc_program nfsacl_program = { | |||
93 | }; | 93 | }; |
94 | #endif /* CONFIG_NFS_V3_ACL */ | 94 | #endif /* CONFIG_NFS_V3_ACL */ |
95 | 95 | ||
96 | struct nfs_client_initdata { | ||
97 | const char *hostname; | ||
98 | const struct sockaddr_in *addr; | ||
99 | int version; | ||
100 | }; | ||
101 | |||
96 | /* | 102 | /* |
97 | * Allocate a shared client record | 103 | * Allocate a shared client record |
98 | * | 104 | * |
99 | * Since these are allocated/deallocated very rarely, we don't | 105 | * Since these are allocated/deallocated very rarely, we don't |
100 | * bother putting them in a slab cache... | 106 | * bother putting them in a slab cache... |
101 | */ | 107 | */ |
102 | static struct nfs_client *nfs_alloc_client(const char *hostname, | 108 | static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) |
103 | const struct sockaddr_in *addr, | ||
104 | int nfsversion) | ||
105 | { | 109 | { |
106 | struct nfs_client *clp; | 110 | struct nfs_client *clp; |
107 | 111 | ||
108 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) | 112 | if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) |
109 | goto error_0; | 113 | goto error_0; |
110 | 114 | ||
111 | if (nfsversion == 4) { | 115 | if (cl_init->version == 4) { |
112 | if (nfs_callback_up() < 0) | 116 | if (nfs_callback_up() < 0) |
113 | goto error_2; | 117 | goto error_2; |
114 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); | 118 | __set_bit(NFS_CS_CALLBACK, &clp->cl_res_state); |
@@ -117,11 +121,11 @@ static struct nfs_client *nfs_alloc_client(const char *hostname, | |||
117 | atomic_set(&clp->cl_count, 1); | 121 | atomic_set(&clp->cl_count, 1); |
118 | clp->cl_cons_state = NFS_CS_INITING; | 122 | clp->cl_cons_state = NFS_CS_INITING; |
119 | 123 | ||
120 | clp->cl_nfsversion = nfsversion; | 124 | clp->cl_nfsversion = cl_init->version; |
121 | memcpy(&clp->cl_addr, addr, sizeof(clp->cl_addr)); | 125 | memcpy(&clp->cl_addr, cl_init->addr, sizeof(clp->cl_addr)); |
122 | 126 | ||
123 | if (hostname) { | 127 | if (cl_init->hostname) { |
124 | clp->cl_hostname = kstrdup(hostname, GFP_KERNEL); | 128 | clp->cl_hostname = kstrdup(cl_init->hostname, GFP_KERNEL); |
125 | if (!clp->cl_hostname) | 129 | if (!clp->cl_hostname) |
126 | goto error_3; | 130 | goto error_3; |
127 | } | 131 | } |
@@ -256,22 +260,20 @@ struct nfs_client *nfs_find_client(const struct sockaddr_in *addr, int nfsversio | |||
256 | * Look up a client by IP address and protocol version | 260 | * Look up a client by IP address and protocol version |
257 | * - creates a new record if one doesn't yet exist | 261 | * - creates a new record if one doesn't yet exist |
258 | */ | 262 | */ |
259 | static struct nfs_client *nfs_get_client(const char *hostname, | 263 | static struct nfs_client *nfs_get_client(const struct nfs_client_initdata *cl_init) |
260 | const struct sockaddr_in *addr, | ||
261 | int nfsversion) | ||
262 | { | 264 | { |
263 | struct nfs_client *clp, *new = NULL; | 265 | struct nfs_client *clp, *new = NULL; |
264 | int error; | 266 | int error; |
265 | 267 | ||
266 | dprintk("--> nfs_get_client(%s,"NIPQUAD_FMT":%d,%d)\n", | 268 | dprintk("--> nfs_get_client(%s,"NIPQUAD_FMT":%d,%d)\n", |
267 | hostname ?: "", NIPQUAD(addr->sin_addr), | 269 | cl_init->hostname ?: "", NIPQUAD(cl_init->addr->sin_addr), |
268 | addr->sin_port, nfsversion); | 270 | cl_init->addr->sin_port, cl_init->version); |
269 | 271 | ||
270 | /* see if the client already exists */ | 272 | /* see if the client already exists */ |
271 | do { | 273 | do { |
272 | spin_lock(&nfs_client_lock); | 274 | spin_lock(&nfs_client_lock); |
273 | 275 | ||
274 | clp = __nfs_find_client(addr, nfsversion, 1); | 276 | clp = __nfs_find_client(cl_init->addr, cl_init->version, 1); |
275 | if (clp) | 277 | if (clp) |
276 | goto found_client; | 278 | goto found_client; |
277 | if (new) | 279 | if (new) |
@@ -279,7 +281,7 @@ static struct nfs_client *nfs_get_client(const char *hostname, | |||
279 | 281 | ||
280 | spin_unlock(&nfs_client_lock); | 282 | spin_unlock(&nfs_client_lock); |
281 | 283 | ||
282 | new = nfs_alloc_client(hostname, addr, nfsversion); | 284 | new = nfs_alloc_client(cl_init); |
283 | } while (new); | 285 | } while (new); |
284 | 286 | ||
285 | return ERR_PTR(-ENOMEM); | 287 | return ERR_PTR(-ENOMEM); |
@@ -540,19 +542,23 @@ error: | |||
540 | static int nfs_init_server(struct nfs_server *server, | 542 | static int nfs_init_server(struct nfs_server *server, |
541 | const struct nfs_parsed_mount_data *data) | 543 | const struct nfs_parsed_mount_data *data) |
542 | { | 544 | { |
545 | struct nfs_client_initdata cl_init = { | ||
546 | .hostname = data->nfs_server.hostname, | ||
547 | .addr = &data->nfs_server.address, | ||
548 | .version = 2, | ||
549 | }; | ||
543 | struct nfs_client *clp; | 550 | struct nfs_client *clp; |
544 | int error, nfsvers = 2; | 551 | int error; |
545 | 552 | ||
546 | dprintk("--> nfs_init_server()\n"); | 553 | dprintk("--> nfs_init_server()\n"); |
547 | 554 | ||
548 | #ifdef CONFIG_NFS_V3 | 555 | #ifdef CONFIG_NFS_V3 |
549 | if (data->flags & NFS_MOUNT_VER3) | 556 | if (data->flags & NFS_MOUNT_VER3) |
550 | nfsvers = 3; | 557 | cl_init.version = 3; |
551 | #endif | 558 | #endif |
552 | 559 | ||
553 | /* Allocate or find a client reference we can use */ | 560 | /* Allocate or find a client reference we can use */ |
554 | clp = nfs_get_client(data->nfs_server.hostname, | 561 | clp = nfs_get_client(&cl_init); |
555 | &data->nfs_server.address, nfsvers); | ||
556 | if (IS_ERR(clp)) { | 562 | if (IS_ERR(clp)) { |
557 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); | 563 | dprintk("<-- nfs_init_server() = error %ld\n", PTR_ERR(clp)); |
558 | return PTR_ERR(clp); | 564 | return PTR_ERR(clp); |
@@ -889,13 +895,18 @@ static int nfs4_set_client(struct nfs_server *server, | |||
889 | rpc_authflavor_t authflavour, | 895 | rpc_authflavor_t authflavour, |
890 | int proto, int timeo, int retrans) | 896 | int proto, int timeo, int retrans) |
891 | { | 897 | { |
898 | struct nfs_client_initdata cl_init = { | ||
899 | .hostname = hostname, | ||
900 | .addr = addr, | ||
901 | .version = 4, | ||
902 | }; | ||
892 | struct nfs_client *clp; | 903 | struct nfs_client *clp; |
893 | int error; | 904 | int error; |
894 | 905 | ||
895 | dprintk("--> nfs4_set_client()\n"); | 906 | dprintk("--> nfs4_set_client()\n"); |
896 | 907 | ||
897 | /* Allocate or find a client reference we can use */ | 908 | /* Allocate or find a client reference we can use */ |
898 | clp = nfs_get_client(hostname, addr, 4); | 909 | clp = nfs_get_client(&cl_init); |
899 | if (IS_ERR(clp)) { | 910 | if (IS_ERR(clp)) { |
900 | error = PTR_ERR(clp); | 911 | error = PTR_ERR(clp); |
901 | goto error; | 912 | goto error; |