Commit 43780b87 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

SUNRPC: Add a convenient default for the hostname when calling rpc_create()

A couple of callers just use a stringified IP address for the rpc client's
hostname.  Move the logic for constructing this into rpc_create(), so it can
be shared.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 45160d62
...@@ -28,8 +28,7 @@ ...@@ -28,8 +28,7 @@
#define MOUNT_UMNT 3 #define MOUNT_UMNT 3
*/ */
static struct rpc_clnt * mnt_create(char *, struct sockaddr_in *, static struct rpc_clnt * mnt_create(struct sockaddr_in *, int, int);
int, int);
static struct rpc_program mnt_program; static struct rpc_program mnt_program;
struct mnt_fhstatus { struct mnt_fhstatus {
...@@ -52,14 +51,12 @@ nfsroot_mount(struct sockaddr_in *addr, char *path, struct nfs_fh *fh, ...@@ -52,14 +51,12 @@ nfsroot_mount(struct sockaddr_in *addr, char *path, struct nfs_fh *fh,
.rpc_argp = path, .rpc_argp = path,
.rpc_resp = &result, .rpc_resp = &result,
}; };
char hostname[32];
int status; int status;
dprintk("NFS: nfs_mount(%08x:%s)\n", dprintk("NFS: nfs_mount(%08x:%s)\n",
(unsigned)ntohl(addr->sin_addr.s_addr), path); (unsigned)ntohl(addr->sin_addr.s_addr), path);
sprintf(hostname, "%u.%u.%u.%u", NIPQUAD(addr->sin_addr.s_addr)); mnt_clnt = mnt_create(addr, version, protocol);
mnt_clnt = mnt_create(hostname, addr, version, protocol);
if (IS_ERR(mnt_clnt)) if (IS_ERR(mnt_clnt))
return PTR_ERR(mnt_clnt); return PTR_ERR(mnt_clnt);
...@@ -73,15 +70,13 @@ nfsroot_mount(struct sockaddr_in *addr, char *path, struct nfs_fh *fh, ...@@ -73,15 +70,13 @@ nfsroot_mount(struct sockaddr_in *addr, char *path, struct nfs_fh *fh,
return status < 0? status : (result.status? -EACCES : 0); return status < 0? status : (result.status? -EACCES : 0);
} }
static struct rpc_clnt * static struct rpc_clnt *mnt_create(struct sockaddr_in *srvaddr, int version,
mnt_create(char *hostname, struct sockaddr_in *srvaddr, int version, int protocol)
int protocol)
{ {
struct rpc_create_args args = { struct rpc_create_args args = {
.protocol = protocol, .protocol = protocol,
.address = (struct sockaddr *)srvaddr, .address = (struct sockaddr *)srvaddr,
.addrsize = sizeof(*srvaddr), .addrsize = sizeof(*srvaddr),
.servername = hostname,
.program = &mnt_program, .program = &mnt_program,
.version = version, .version = version,
.authflavor = RPC_AUTH_UNIX, .authflavor = RPC_AUTH_UNIX,
......
...@@ -394,7 +394,6 @@ nfsd4_probe_callback(struct nfs4_client *clp) ...@@ -394,7 +394,6 @@ nfsd4_probe_callback(struct nfs4_client *clp)
.rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL], .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL],
.rpc_argp = clp, .rpc_argp = clp,
}; };
char clientname[16];
int status; int status;
if (atomic_read(&cb->cb_set)) if (atomic_read(&cb->cb_set))
...@@ -417,11 +416,6 @@ nfsd4_probe_callback(struct nfs4_client *clp) ...@@ -417,11 +416,6 @@ nfsd4_probe_callback(struct nfs4_client *clp)
memset(program->stats, 0, sizeof(cb->cb_stat)); memset(program->stats, 0, sizeof(cb->cb_stat));
program->stats->program = program; program->stats->program = program;
/* Just here to make some printk's more useful: */
snprintf(clientname, sizeof(clientname),
"%u.%u.%u.%u", NIPQUAD(addr.sin_addr));
args.servername = clientname;
/* Create RPC client */ /* Create RPC client */
cb->cb_client = rpc_create(&args); cb->cb_client = rpc_create(&args);
if (IS_ERR(cb->cb_client)) { if (IS_ERR(cb->cb_client)) {
......
...@@ -234,12 +234,25 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args) ...@@ -234,12 +234,25 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
{ {
struct rpc_xprt *xprt; struct rpc_xprt *xprt;
struct rpc_clnt *clnt; struct rpc_clnt *clnt;
char servername[20];
xprt = xprt_create_transport(args->protocol, args->address, xprt = xprt_create_transport(args->protocol, args->address,
args->addrsize, args->timeout); args->addrsize, args->timeout);
if (IS_ERR(xprt)) if (IS_ERR(xprt))
return (struct rpc_clnt *)xprt; return (struct rpc_clnt *)xprt;
/*
* If the caller chooses not to specify a hostname, whip
* up a string representation of the passed-in address.
*/
if (args->servername == NULL) {
struct sockaddr_in *addr =
(struct sockaddr_in *) &args->address;
snprintf(servername, sizeof(servername), NIPQUAD_FMT,
NIPQUAD(addr->sin_addr.s_addr));
args->servername = servername;
}
/* /*
* By default, kernel RPC client connects from a reserved port. * By default, kernel RPC client connects from a reserved port.
* CAP_NET_BIND_SERVICE will not be set for unprivileged requesters, * CAP_NET_BIND_SERVICE will not be set for unprivileged requesters,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment