Skip to content

Commit a8d54ba

Browse files
olgakorn1amschuma-ntap
authored andcommitted
NFSv4 handle port presence in fs_location server string
An fs_location attribute returns a string that can be ipv4, ipv6, or DNS name. An ip location can have a port appended to it and if no port is present a default port needs to be set. If rpc_pton() fails to parse, try calling rpc_uaddr2socaddr() that can convert an universal address. Signed-off-by: Olga Kornievskaia <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent f5b27cc commit a8d54ba

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

fs/nfs/nfs4_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ int nfs4_submount(struct fs_context *, struct nfs_server *);
281281
int nfs4_replace_transport(struct nfs_server *server,
282282
const struct nfs4_fs_locations *locations);
283283
size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr *sa,
284-
size_t salen, struct net *net);
284+
size_t salen, struct net *net, int port);
285285
/* nfs4proc.c */
286286
extern int nfs4_handle_exception(struct nfs_server *, int, struct nfs4_exception *);
287287
extern int nfs4_async_handle_error(struct rpc_task *task,

fs/nfs/nfs4namespace.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,20 @@ static int nfs4_validate_fspath(struct dentry *dentry,
165165
}
166166

167167
size_t nfs_parse_server_name(char *string, size_t len, struct sockaddr *sa,
168-
size_t salen, struct net *net)
168+
size_t salen, struct net *net, int port)
169169
{
170170
ssize_t ret;
171171

172172
ret = rpc_pton(net, string, len, sa, salen);
173173
if (ret == 0) {
174-
ret = nfs_dns_resolve_name(net, string, len, sa, salen);
175-
if (ret < 0)
176-
ret = 0;
174+
ret = rpc_uaddr2sockaddr(net, string, len, sa, salen);
175+
if (ret == 0) {
176+
ret = nfs_dns_resolve_name(net, string, len, sa, salen);
177+
if (ret < 0)
178+
ret = 0;
179+
}
180+
} else if (port) {
181+
rpc_set_port(sa, port);
177182
}
178183
return ret;
179184
}
@@ -328,7 +333,7 @@ static int try_location(struct fs_context *fc,
328333
nfs_parse_server_name(buf->data, buf->len,
329334
&ctx->nfs_server.address,
330335
sizeof(ctx->nfs_server._address),
331-
fc->net_ns);
336+
fc->net_ns, 0);
332337
if (ctx->nfs_server.addrlen == 0)
333338
continue;
334339

@@ -496,7 +501,7 @@ static int nfs4_try_replacing_one_location(struct nfs_server *server,
496501
continue;
497502

498503
salen = nfs_parse_server_name(buf->data, buf->len,
499-
sap, addr_bufsize, net);
504+
sap, addr_bufsize, net, 0);
500505
if (salen == 0)
501506
continue;
502507
rpc_set_port(sap, NFS_PORT);

0 commit comments

Comments
 (0)