summaryrefslogtreecommitdiffstats
path: root/fs/nfs/proc.c
blob: bb55ce6d691753f944995def95746136e5a57876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 *  linux/fs/nfs/proc.c
 *
 *  Copyright (C) 1992, 1993, 1994  Rick Sladkey
 *
 *  OS-independent nfs remote procedure call functions
 *
 *  Tuned by Alan Cox <A.Cox@swansea.ac.uk> for >3K buffers
 *  so at last we can have decent(ish) throughput off a 
 *  Sun server.
 *
 *  Coding optimized and cleaned up by Florian La Roche.
 *  Note: Error returns are optimized for NFS_OK, which isn't translated via
 *  nfs_stat_to_errno(), but happens to be already the right return code.
 *
 *  FixMe: We ought to define a sensible small max size for
 *  things like getattr that are tiny packets and use the
 *  old get_free_page stuff with it.
 *
 *  Also, the code currently doesn't check the size of the packet, when
 *  it decodes the packet.
 *
 *  Feel free to fix it and mail me the diffs if it worries you.
 *
 *  Completely rewritten to support the new RPC call interface;
 *  rewrote and moved the entire XDR stuff to xdr.c
 *  --Olaf Kirch June 1996
 */

#define NFS_NEED_XDR_TYPES

#include <linux/param.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/malloc.h>
#include <linux/utsname.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/in.h>
#include <linux/pagemap.h>
#include <linux/sunrpc/clnt.h>
#include <linux/nfs_fs.h>

#include <asm/segment.h>

#ifdef NFS_DEBUG
# define NFSDBG_FACILITY	NFSDBG_PROC
#endif


/*
 * One function for each procedure in the NFS protocol.
 */
int
nfs_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle,
			struct nfs_fattr *fattr)
{
	int	status;

	dprintk("NFS call  getattr\n");
	status = rpc_call(server->client, NFSPROC_GETATTR, fhandle, fattr, 0);
	dprintk("NFS reply getattr\n");
	return status;
}

int
nfs_proc_setattr(struct nfs_server *server, struct nfs_fh *fhandle,
			struct nfs_fattr *fattr, struct iattr *sattr)
{
	struct nfs_sattrargs	arg = { fhandle, sattr };
	int	status;

	dprintk("NFS call  setattr\n");
	status = rpc_call(server->client, NFSPROC_SETATTR, &arg, fattr, 0);
	dprintk("NFS reply setattr\n");
	return status;
}

int
nfs_proc_lookup(struct nfs_server *server, struct nfs_fh *dir, const char *name,
		    struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
	struct nfs_diropargs	arg = { dir, name };
	struct nfs_diropok	res = { fhandle, fattr };
	int			status;

	dprintk("NFS call  lookup %s\n", name);
	status = rpc_call(server->client, NFSPROC_LOOKUP, &arg, &res, 0);
	dprintk("NFS reply lookup: %d\n", status);
	return status;
}

int
nfs_proc_read(struct nfs_server *server, struct nfs_fh *fhandle, int swap,
			  unsigned long offset, unsigned int count,
			  void *buffer, struct nfs_fattr *fattr)
{
	struct nfs_readargs	arg = { fhandle, offset, count, buffer };
	struct nfs_readres	res = { fattr, count };
	int			status;

	dprintk("NFS call  read %d @ %ld\n", count, offset);
	status = rpc_call(server->client, NFSPROC_READ, &arg, &res,
			swap? NFS_RPC_SWAPFLAGS : 0);
	dprintk("NFS reply read: %d\n", status);
	return status;
}

int
nfs_proc_write(struct nfs_server *server, struct nfs_fh *fhandle, int swap,
			unsigned long offset, unsigned int count,
			const void *buffer, struct nfs_fattr *fattr)
{
	struct nfs_writeargs	arg = { fhandle, offset, count, buffer };
	int			status;

	dprintk("NFS call  write %d @ %ld\n", count, offset);
	status = rpc_call(server->client, NFSPROC_WRITE, &arg, fattr,
			swap? (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS) : 0);
	dprintk("NFS reply read: %d\n", status);
	return status < 0? status : count;
}

int
nfs_proc_create(struct nfs_server *server, struct nfs_fh *dir,
			const char *name, struct iattr *sattr,
			struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
	struct nfs_createargs	arg = { dir, name, sattr };
	struct nfs_diropok	res = { fhandle, fattr };
	int			status;

	dprintk("NFS call  create %s\n", name);
	status = rpc_call(server->client, NFSPROC_CREATE, &arg, &res, 0);
	dprintk("NFS reply create: %d\n", status);
	return status;
}

int
nfs_proc_remove(struct nfs_server *server, struct nfs_fh *dir, const char *name)
{
	struct nfs_diropargs	arg = { dir, name };
	int			status;

	dprintk("NFS call  remove %s\n", name);
	status = rpc_call(server->client, NFSPROC_REMOVE, &arg, NULL, 0);
	dprintk("NFS reply remove: %d\n", status);
	return status;
}

int
nfs_proc_rename(struct nfs_server *server,
		struct nfs_fh *old_dir, const char *old_name,
		struct nfs_fh *new_dir, const char *new_name)
{
	struct nfs_renameargs	arg = { old_dir, old_name, new_dir, new_name };
	int			status;

	dprintk("NFS call  rename %s -> %s\n", old_name, new_name);
	status = rpc_call(server->client, NFSPROC_RENAME, &arg, NULL, 0);
	dprintk("NFS reply rename: %d\n", status);
	return status;
}

int
nfs_proc_link(struct nfs_server *server, struct nfs_fh *fhandle,
			struct nfs_fh *dir, const char *name)
{
	struct nfs_linkargs	arg = { fhandle, dir, name };
	int			status;

	dprintk("NFS call  link %s\n", name);
	status = rpc_call(server->client, NFSPROC_LINK, &arg, NULL, 0);
	dprintk("NFS reply link: %d\n", status);
	return status;
}

int
nfs_proc_symlink(struct nfs_server *server, struct nfs_fh *dir,
			const char *name, const char *path,
			struct iattr *sattr)
{
	struct nfs_symlinkargs	arg = { dir, name, path, sattr };
	int			status;

	dprintk("NFS call  symlink %s -> %s\n", name, path);
	status = rpc_call(server->client, NFSPROC_SYMLINK, &arg, NULL, 0);
	dprintk("NFS reply symlink: %d\n", status);
	return status;
}

int
nfs_proc_mkdir(struct nfs_server *server, struct nfs_fh *dir,
			const char *name, struct iattr *sattr,
			struct nfs_fh *fhandle, struct nfs_fattr *fattr)
{
	struct nfs_createargs	arg = { dir, name, sattr };
	struct nfs_diropok	res = { fhandle, fattr };
	int			status;

	dprintk("NFS call  mkdir %s\n", name);
	status = rpc_call(server->client, NFSPROC_MKDIR, &arg, &res, 0);
	dprintk("NFS reply mkdir: %d\n", status);
	return status;
}

int
nfs_proc_rmdir(struct nfs_server *server, struct nfs_fh *dir, const char *name)
{
	struct nfs_diropargs	arg = { dir, name };
	int			status;

	dprintk("NFS call  rmdir %s\n", name);
	status = rpc_call(server->client, NFSPROC_RMDIR, &arg, NULL, 0);
	dprintk("NFS reply rmdir: %d\n", status);
	return status;
}

int
nfs_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle,
			struct nfs_fsinfo *info)
{
	int	status;

	dprintk("NFS call  statfs\n");
	status = rpc_call(server->client, NFSPROC_STATFS, fhandle, info, 0);
	dprintk("NFS reply statfs: %d\n", status);
	return status;
}