]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/nfs/mount_clnt.c
NFS: remove unused function in fs/nfs/mount_clnt.c
[mirror_ubuntu-zesty-kernel.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>
8491945f 17#include "internal.h"
1da177e4
LT
18
19#ifdef RPC_DEBUG
3ea97309 20# define NFSDBG_FACILITY NFSDBG_MOUNT
1da177e4
LT
21#endif
22
29a1bd6b
CL
23/*
24 * Defined by RFC 1094, section A.3; and RFC 1813, section 5.1.4
25 */
26#define MNTPATHLEN (1024)
27
28/*
29 * XDR data type sizes
30 */
31#define encode_dirpath_sz (1 + XDR_QUADLEN(MNTPATHLEN))
32
33/*
34 * XDR argument and result sizes
35 */
36#define MNT_enc_dirpath_sz encode_dirpath_sz
37
2ad78097
CL
38/*
39 * Defined by RFC 1094, section A.5
40 */
41enum {
42 MOUNTPROC_NULL = 0,
43 MOUNTPROC_MNT = 1,
44 MOUNTPROC_DUMP = 2,
45 MOUNTPROC_UMNT = 3,
46 MOUNTPROC_UMNTALL = 4,
47 MOUNTPROC_EXPORT = 5,
48};
49
50/*
51 * Defined by RFC 1813, section 5.2
52 */
53enum {
54 MOUNTPROC3_NULL = 0,
55 MOUNTPROC3_MNT = 1,
56 MOUNTPROC3_DUMP = 2,
57 MOUNTPROC3_UMNT = 3,
58 MOUNTPROC3_UMNTALL = 4,
59 MOUNTPROC3_EXPORT = 5,
60};
61
1da177e4
LT
62static struct rpc_program mnt_program;
63
64struct mnt_fhstatus {
19207231
CL
65 u32 status;
66 struct nfs_fh *fh;
1da177e4
LT
67};
68
3ea97309
CL
69/**
70 * nfs_mount - Obtain an NFS file handle for the given host and path
c5d120f8 71 * @info: pointer to mount request arguments
3ea97309
CL
72 *
73 * Uses default timeout parameters specified by underlying transport.
1da177e4 74 */
c5d120f8 75int nfs_mount(struct nfs_mount_request *info)
1da177e4 76{
1da177e4 77 struct mnt_fhstatus result = {
c5d120f8 78 .fh = info->fh
1da177e4 79 };
dead28da 80 struct rpc_message msg = {
c5d120f8 81 .rpc_argp = info->dirpath,
dead28da
CL
82 .rpc_resp = &result,
83 };
3ea97309 84 struct rpc_create_args args = {
c5d120f8
CL
85 .protocol = info->protocol,
86 .address = info->sap,
87 .addrsize = info->salen,
88 .servername = info->hostname,
3ea97309 89 .program = &mnt_program,
c5d120f8 90 .version = info->version,
3ea97309 91 .authflavor = RPC_AUTH_UNIX,
3ea97309
CL
92 };
93 struct rpc_clnt *mnt_clnt;
1da177e4 94 int status;
1da177e4 95
3ea97309 96 dprintk("NFS: sending MNT request for %s:%s\n",
c5d120f8
CL
97 (info->hostname ? info->hostname : "server"),
98 info->dirpath);
1da177e4 99
50a737f8
CL
100 if (info->noresvport)
101 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
102
3ea97309 103 mnt_clnt = rpc_create(&args);
1da177e4 104 if (IS_ERR(mnt_clnt))
013a8c1a 105 goto out_clnt_err;
1da177e4 106
c5d120f8 107 if (info->version == NFS_MNT3_VERSION)
dead28da
CL
108 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC3_MNT];
109 else
2ad78097 110 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC_MNT];
dead28da
CL
111
112 status = rpc_call_sync(mnt_clnt, &msg, 0);
90c5755f 113 rpc_shutdown_client(mnt_clnt);
013a8c1a
CL
114
115 if (status < 0)
116 goto out_call_err;
117 if (result.status != 0)
118 goto out_mnt_err;
119
120 dprintk("NFS: MNT request succeeded\n");
121 status = 0;
122
123out:
124 return status;
125
126out_clnt_err:
127 status = PTR_ERR(mnt_clnt);
128 dprintk("NFS: failed to create RPC client, status=%d\n", status);
129 goto out;
130
131out_call_err:
132 dprintk("NFS: failed to start MNT request, status=%d\n", status);
133 goto out;
134
135out_mnt_err:
136 dprintk("NFS: MNT server returned result %d\n", result.status);
8491945f 137 status = nfs_stat_to_errno(result.status);
013a8c1a 138 goto out;
1da177e4
LT
139}
140
1da177e4
LT
141/*
142 * XDR encode/decode functions for MOUNT
143 */
1da177e4 144
29a1bd6b
CL
145static int encode_mntdirpath(struct xdr_stream *xdr, const char *pathname)
146{
147 const u32 pathname_len = strlen(pathname);
148 __be32 *p;
149
150 if (unlikely(pathname_len > MNTPATHLEN))
151 return -EIO;
152
153 p = xdr_reserve_space(xdr, sizeof(u32) + pathname_len);
154 if (unlikely(p == NULL))
155 return -EIO;
156 xdr_encode_opaque(p, pathname, pathname_len);
157
158 return 0;
159}
160
161static int mnt_enc_dirpath(struct rpc_rqst *req, __be32 *p,
162 const char *dirpath)
163{
164 struct xdr_stream xdr;
165
166 xdr_init_encode(&xdr, &req->rq_snd_buf, p);
167 return encode_mntdirpath(&xdr, dirpath);
168}
169
19207231
CL
170static int xdr_decode_fhstatus(struct rpc_rqst *req, __be32 *p,
171 struct mnt_fhstatus *res)
1da177e4
LT
172{
173 struct nfs_fh *fh = res->fh;
174
175 if ((res->status = ntohl(*p++)) == 0) {
176 fh->size = NFS2_FHSIZE;
177 memcpy(fh->data, p, NFS2_FHSIZE);
178 }
179 return 0;
180}
181
19207231
CL
182static int xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p,
183 struct mnt_fhstatus *res)
1da177e4
LT
184{
185 struct nfs_fh *fh = res->fh;
b7e24457 186 unsigned size;
1da177e4
LT
187
188 if ((res->status = ntohl(*p++)) == 0) {
b7e24457
TM
189 size = ntohl(*p++);
190 if (size <= NFS3_FHSIZE && size != 0) {
1da177e4
LT
191 fh->size = size;
192 memcpy(fh->data, p, size);
193 } else
194 res->status = -EBADHANDLE;
195 }
196 return 0;
197}
198
1da177e4 199#define MNT_fhstatus_sz (1 + 8)
2bea90d4 200#define MNT_fhstatus3_sz (1 + 16)
1da177e4 201
19207231 202static struct rpc_procinfo mnt_procedures[] = {
2ad78097
CL
203 [MOUNTPROC_MNT] = {
204 .p_proc = MOUNTPROC_MNT,
29a1bd6b 205 .p_encode = (kxdrproc_t)mnt_enc_dirpath,
19207231 206 .p_decode = (kxdrproc_t) xdr_decode_fhstatus,
29a1bd6b 207 .p_arglen = MNT_enc_dirpath_sz,
19207231 208 .p_replen = MNT_fhstatus_sz,
2ad78097 209 .p_statidx = MOUNTPROC_MNT,
19207231 210 .p_name = "MOUNT",
1da177e4
LT
211 },
212};
213
214static struct rpc_procinfo mnt3_procedures[] = {
19207231
CL
215 [MOUNTPROC3_MNT] = {
216 .p_proc = MOUNTPROC3_MNT,
29a1bd6b 217 .p_encode = (kxdrproc_t)mnt_enc_dirpath,
19207231 218 .p_decode = (kxdrproc_t) xdr_decode_fhstatus3,
29a1bd6b 219 .p_arglen = MNT_enc_dirpath_sz,
19207231
CL
220 .p_replen = MNT_fhstatus3_sz,
221 .p_statidx = MOUNTPROC3_MNT,
222 .p_name = "MOUNT",
1da177e4
LT
223 },
224};
225
226
19207231
CL
227static struct rpc_version mnt_version1 = {
228 .number = 1,
229 .nrprocs = 2,
230 .procs = mnt_procedures,
1da177e4
LT
231};
232
19207231
CL
233static struct rpc_version mnt_version3 = {
234 .number = 3,
235 .nrprocs = 2,
236 .procs = mnt3_procedures,
1da177e4
LT
237};
238
19207231 239static struct rpc_version *mnt_version[] = {
1da177e4
LT
240 NULL,
241 &mnt_version1,
242 NULL,
243 &mnt_version3,
244};
245
19207231 246static struct rpc_stat mnt_stats;
1da177e4 247
19207231 248static struct rpc_program mnt_program = {
1da177e4
LT
249 .name = "mount",
250 .number = NFS_MNT_PROGRAM,
e8c96f8c 251 .nrvers = ARRAY_SIZE(mnt_version),
1da177e4
LT
252 .version = mnt_version,
253 .stats = &mnt_stats,
254};