powerpc/mm: Merge various PTE bits and accessors definitions
[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>
8491945f 17#include "internal.h"
1da177e4
LT
18
19#ifdef RPC_DEBUG
3ea97309 20# define NFSDBG_FACILITY NFSDBG_MOUNT
1da177e4
LT
21#endif
22
1da177e4
LT
23static struct rpc_program mnt_program;
24
25struct mnt_fhstatus {
19207231
CL
26 u32 status;
27 struct nfs_fh *fh;
1da177e4
LT
28};
29
3ea97309
CL
30/**
31 * nfs_mount - Obtain an NFS file handle for the given host and path
c5d120f8 32 * @info: pointer to mount request arguments
3ea97309
CL
33 *
34 * Uses default timeout parameters specified by underlying transport.
1da177e4 35 */
c5d120f8 36int nfs_mount(struct nfs_mount_request *info)
1da177e4 37{
1da177e4 38 struct mnt_fhstatus result = {
c5d120f8 39 .fh = info->fh
1da177e4 40 };
dead28da 41 struct rpc_message msg = {
c5d120f8 42 .rpc_argp = info->dirpath,
dead28da
CL
43 .rpc_resp = &result,
44 };
3ea97309 45 struct rpc_create_args args = {
c5d120f8
CL
46 .protocol = info->protocol,
47 .address = info->sap,
48 .addrsize = info->salen,
49 .servername = info->hostname,
3ea97309 50 .program = &mnt_program,
c5d120f8 51 .version = info->version,
3ea97309 52 .authflavor = RPC_AUTH_UNIX,
3ea97309
CL
53 };
54 struct rpc_clnt *mnt_clnt;
1da177e4 55 int status;
1da177e4 56
3ea97309 57 dprintk("NFS: sending MNT request for %s:%s\n",
c5d120f8
CL
58 (info->hostname ? info->hostname : "server"),
59 info->dirpath);
1da177e4 60
50a737f8
CL
61 if (info->noresvport)
62 args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
63
3ea97309 64 mnt_clnt = rpc_create(&args);
1da177e4 65 if (IS_ERR(mnt_clnt))
013a8c1a 66 goto out_clnt_err;
1da177e4 67
c5d120f8 68 if (info->version == NFS_MNT3_VERSION)
dead28da
CL
69 msg.rpc_proc = &mnt_clnt->cl_procinfo[MOUNTPROC3_MNT];
70 else
71 msg.rpc_proc = &mnt_clnt->cl_procinfo[MNTPROC_MNT];
72
73 status = rpc_call_sync(mnt_clnt, &msg, 0);
90c5755f 74 rpc_shutdown_client(mnt_clnt);
013a8c1a
CL
75
76 if (status < 0)
77 goto out_call_err;
78 if (result.status != 0)
79 goto out_mnt_err;
80
81 dprintk("NFS: MNT request succeeded\n");
82 status = 0;
83
84out:
85 return status;
86
87out_clnt_err:
88 status = PTR_ERR(mnt_clnt);
89 dprintk("NFS: failed to create RPC client, status=%d\n", status);
90 goto out;
91
92out_call_err:
93 dprintk("NFS: failed to start MNT request, status=%d\n", status);
94 goto out;
95
96out_mnt_err:
97 dprintk("NFS: MNT server returned result %d\n", result.status);
8491945f 98 status = nfs_stat_to_errno(result.status);
013a8c1a 99 goto out;
1da177e4
LT
100}
101
1da177e4
LT
102/*
103 * XDR encode/decode functions for MOUNT
104 */
19207231
CL
105static int xdr_encode_dirpath(struct rpc_rqst *req, __be32 *p,
106 const char *path)
1da177e4
LT
107{
108 p = xdr_encode_string(p, path);
109
110 req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
111 return 0;
112}
113
19207231
CL
114static int xdr_decode_fhstatus(struct rpc_rqst *req, __be32 *p,
115 struct mnt_fhstatus *res)
1da177e4
LT
116{
117 struct nfs_fh *fh = res->fh;
118
119 if ((res->status = ntohl(*p++)) == 0) {
120 fh->size = NFS2_FHSIZE;
121 memcpy(fh->data, p, NFS2_FHSIZE);
122 }
123 return 0;
124}
125
19207231
CL
126static int xdr_decode_fhstatus3(struct rpc_rqst *req, __be32 *p,
127 struct mnt_fhstatus *res)
1da177e4
LT
128{
129 struct nfs_fh *fh = res->fh;
b7e24457 130 unsigned size;
1da177e4
LT
131
132 if ((res->status = ntohl(*p++)) == 0) {
b7e24457
TM
133 size = ntohl(*p++);
134 if (size <= NFS3_FHSIZE && size != 0) {
1da177e4
LT
135 fh->size = size;
136 memcpy(fh->data, p, size);
137 } else
138 res->status = -EBADHANDLE;
139 }
140 return 0;
141}
142
143#define MNT_dirpath_sz (1 + 256)
144#define MNT_fhstatus_sz (1 + 8)
2bea90d4 145#define MNT_fhstatus3_sz (1 + 16)
1da177e4 146
19207231
CL
147static struct rpc_procinfo mnt_procedures[] = {
148 [MNTPROC_MNT] = {
149 .p_proc = MNTPROC_MNT,
150 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
151 .p_decode = (kxdrproc_t) xdr_decode_fhstatus,
152 .p_arglen = MNT_dirpath_sz,
153 .p_replen = MNT_fhstatus_sz,
154 .p_statidx = MNTPROC_MNT,
155 .p_name = "MOUNT",
1da177e4
LT
156 },
157};
158
159static struct rpc_procinfo mnt3_procedures[] = {
19207231
CL
160 [MOUNTPROC3_MNT] = {
161 .p_proc = MOUNTPROC3_MNT,
162 .p_encode = (kxdrproc_t) xdr_encode_dirpath,
163 .p_decode = (kxdrproc_t) xdr_decode_fhstatus3,
164 .p_arglen = MNT_dirpath_sz,
165 .p_replen = MNT_fhstatus3_sz,
166 .p_statidx = MOUNTPROC3_MNT,
167 .p_name = "MOUNT",
1da177e4
LT
168 },
169};
170
171
19207231
CL
172static struct rpc_version mnt_version1 = {
173 .number = 1,
174 .nrprocs = 2,
175 .procs = mnt_procedures,
1da177e4
LT
176};
177
19207231
CL
178static struct rpc_version mnt_version3 = {
179 .number = 3,
180 .nrprocs = 2,
181 .procs = mnt3_procedures,
1da177e4
LT
182};
183
19207231 184static struct rpc_version *mnt_version[] = {
1da177e4
LT
185 NULL,
186 &mnt_version1,
187 NULL,
188 &mnt_version3,
189};
190
19207231 191static struct rpc_stat mnt_stats;
1da177e4 192
19207231 193static struct rpc_program mnt_program = {
1da177e4
LT
194 .name = "mount",
195 .number = NFS_MNT_PROGRAM,
e8c96f8c 196 .nrvers = ARRAY_SIZE(mnt_version),
1da177e4
LT
197 .version = mnt_version,
198 .stats = &mnt_stats,
199};
This page took 0.383159 seconds and 5 git commands to generate.