NFS: Clean up in-kernel NFS mount
[deliverable/linux.git] / fs / nfs / mount_clnt.c
CommitLineData
1da177e4 1/*
19207231 2 * In-kernel MOUNT protocol client
1da177e4
LT
3 *
4 * Copyright (C) 1997, Olaf Kirch <okir@monad.swb.de>
5 */
6
7#include <linux/types.h>
8#include <linux/socket.h>
9#include <linux/kernel.h>
10#include <linux/errno.h>
11#include <linux/uio.h>
12#include <linux/net.h>
13#include <linux/in.h>
14#include <linux/sunrpc/clnt.h>
1da177e4
LT
15#include <linux/sunrpc/sched.h>
16#include <linux/nfs_fs.h>
17
18#ifdef RPC_DEBUG
3ea97309 19# define NFSDBG_FACILITY NFSDBG_MOUNT
1da177e4
LT
20#endif
21
1da177e4
LT
22static struct rpc_program mnt_program;
23
24struct mnt_fhstatus {
19207231
CL
25 u32 status;
26 struct nfs_fh *fh;
1da177e4
LT
27};
28
3ea97309
CL
29/**
30 * nfs_mount - Obtain an NFS file handle for the given host and path
31 * @addr: pointer to server's address
32 * @len: size of server's address
33 * @hostname: name of server host, or NULL
34 * @path: pointer to string containing export path to mount
35 * @version: mount version to use for this request
36 * @protocol: transport protocol to use for thie request
37 * @fh: pointer to location to place returned file handle
38 *
39 * Uses default timeout parameters specified by underlying transport.
1da177e4 40 */
3ea97309
CL
41int nfs_mount(struct sockaddr *addr, size_t len, char *hostname, char *path,
42 int version, int protocol, struct nfs_fh *fh)
1da177e4 43{
1da177e4
LT
44 struct mnt_fhstatus result = {
45 .fh = fh
46 };
dead28da
CL
47 struct rpc_message msg = {
48 .rpc_argp = path,
49 .rpc_resp = &result,
50 };
3ea97309
CL
51 struct rpc_create_args args = {
52 .protocol = protocol,
53 .address = addr,
54 .addrsize = len,
55 .servername = hostname,
56 .program = &mnt_program,
57 .version = version,
58 .authflavor = RPC_AUTH_UNIX,
59 .flags = RPC_CLNT_CREATE_INTR,
60 };
61 struct rpc_clnt *mnt_clnt;
1da177e4 62 int status;
1da177e4 63
3ea97309
CL
64 dprintk("NFS: sending MNT request for %s:%s\n",
65 (hostname ? hostname : "server"), path);
1da177e4 66
3ea97309 67 mnt_clnt = rpc_create(&args);
1da177e4
LT
68 if (IS_ERR(mnt_clnt))
69 return PTR_ERR(mnt_clnt);
70
dead28da
CL
71 if (version == NFS_MNT3_VERSION)
72 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC3_MNT];
73 else
74 msg.rpc_proc = &mnt_clnt->cl_procinfo[MNTPROC_MNT];
75
76 status = rpc_call_sync(mnt_clnt, &msg, 0);
90c5755f 77 rpc_shutdown_client(mnt_clnt);
1da177e4
LT
78 return status < 0? status : (result.status? -EACCES : 0);
79}
80
1da177e4
LT
81/*
82 * XDR encode/decode functions for MOUNT
83 */
19207231
CL
84static int xdr_encode_dirpath(struct rpc_rqst *req, __be32 *p,
85 const char *path)
1da177e4
LT
86{
87 p = xdr_encode_string(p, path);
88
89 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
90 return 0;
91}
92
19207231
CL
93static int xdr_decode_fhstatus(struct rpc_rqst *req, __be32 *p,
94 struct mnt_fhstatus *res)
1da177e4
LT
95{
96 struct nfs_fh *fh = res->fh;
97
98 if ((res->status = ntohl(*p++)) == 0) {
99 fh->size = NFS2_FHSIZE;
100 memcpy(fh->data, p, NFS2_FHSIZE);
101 }
102 return 0;
103}
104
19207231
CL
105static int xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p,
106 struct mnt_fhstatus *res)
1da177e4
LT
107{
108 struct nfs_fh *fh = res->fh;
109
110 if ((res->status = ntohl(*p++)) == 0) {
111 int size = ntohl(*p++);
112 if (size <= NFS3_FHSIZE) {
113 fh->size = size;
114 memcpy(fh->data, p, size);
115 } else
116 res->status = -EBADHANDLE;
117 }
118 return 0;
119}
120
121#define MNT_dirpath_sz (1 + 256)
122#define MNT_fhstatus_sz (1 + 8)
2bea90d4 123#define MNT_fhstatus3_sz (1 + 16)
1da177e4 124
19207231
CL
125static struct rpc_procinfo mnt_procedures[] = {
126 [MNTPROC_MNT] = {
127 .p_proc = MNTPROC_MNT,
128 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
129 .p_decode = (kxdrproc_t) xdr_decode_fhstatus,
130 .p_arglen = MNT_dirpath_sz,
131 .p_replen = MNT_fhstatus_sz,
132 .p_statidx = MNTPROC_MNT,
133 .p_name = "MOUNT",
1da177e4
LT
134 },
135};
136
137static struct rpc_procinfo mnt3_procedures[] = {
19207231
CL
138 [MOUNTPROC3_MNT] = {
139 .p_proc = MOUNTPROC3_MNT,
140 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
141 .p_decode = (kxdrproc_t) xdr_decode_fhstatus3,
142 .p_arglen = MNT_dirpath_sz,
143 .p_replen = MNT_fhstatus3_sz,
144 .p_statidx = MOUNTPROC3_MNT,
145 .p_name = "MOUNT",
1da177e4
LT
146 },
147};
148
149
19207231
CL
150static struct rpc_version mnt_version1 = {
151 .number = 1,
152 .nrprocs = 2,
153 .procs = mnt_procedures,
1da177e4
LT
154};
155
19207231
CL
156static struct rpc_version mnt_version3 = {
157 .number = 3,
158 .nrprocs = 2,
159 .procs = mnt3_procedures,
1da177e4
LT
160};
161
19207231 162static struct rpc_version *mnt_version[] = {
1da177e4
LT
163 NULL,
164 &mnt_version1,
165 NULL,
166 &mnt_version3,
167};
168
19207231 169static struct rpc_stat mnt_stats;
1da177e4 170
19207231 171static struct rpc_program mnt_program = {
1da177e4
LT
172 .name = "mount",
173 .number = NFS_MNT_PROGRAM,
e8c96f8c 174 .nrvers = ARRAY_SIZE(mnt_version),
1da177e4
LT
175 .version = mnt_version,
176 .stats = &mnt_stats,
177};
This page took 0.233413 seconds and 5 git commands to generate.