This source file includes following definitions.
- nfs_read_inode
- nfs_put_inode
- nfs_put_super
- nfs_read_super
- nfs_statfs
- nfs_fhget
- nfs_notify_change
- run_nfsiod
- init_nfs_fs
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/module.h>
17
18 #include <linux/sched.h>
19 #include <linux/nfs_fs.h>
20 #include <linux/nfsiod.h>
21 #include <linux/kernel.h>
22 #include <linux/mm.h>
23 #include <linux/string.h>
24 #include <linux/stat.h>
25 #include <linux/errno.h>
26 #include <linux/locks.h>
27 #include <linux/smp.h>
28 #include <linux/smp_lock.h>
29
30 #include <asm/system.h>
31 #include <asm/segment.h>
32
33
34 #define __KERNEL_SYSCALLS__
35 #include <linux/unistd.h>
36
37 extern int close_fp(struct file *filp);
38
39 static int nfs_notify_change(struct inode *, struct iattr *);
40 static void nfs_put_inode(struct inode *);
41 static void nfs_put_super(struct super_block *);
42 static void nfs_read_inode(struct inode *);
43 static void nfs_statfs(struct super_block *, struct statfs *, int bufsiz);
44
45 static struct super_operations nfs_sops = {
46 nfs_read_inode,
47 nfs_notify_change,
48 NULL,
49 nfs_put_inode,
50 nfs_put_super,
51 NULL,
52 nfs_statfs,
53 NULL
54 };
55
56
57
58
59
60
61
62
63 static void nfs_read_inode(struct inode * inode)
64 {
65 int rsize = inode->i_sb->u.nfs_sb.s_server.rsize;
66 int size = inode->i_sb->u.nfs_sb.s_server.wsize;
67
68 if (rsize > size)
69 size = rsize;
70 inode->i_blksize = size;
71 inode->i_mode = 0;
72 inode->i_op = NULL;
73 NFS_CACHEINV(inode);
74 }
75
76 static void nfs_put_inode(struct inode * inode)
77 {
78 if (NFS_RENAMED_DIR(inode))
79 nfs_sillyrename_cleanup(inode);
80 if (inode->i_pipe)
81 clear_inode(inode);
82 }
83
84 void nfs_put_super(struct super_block *sb)
85 {
86 close_fp(sb->u.nfs_sb.s_server.file);
87 rpc_closesock(sb->u.nfs_sb.s_server.rsock);
88 lock_super(sb);
89 sb->s_dev = 0;
90 unlock_super(sb);
91 MOD_DEC_USE_COUNT;
92 }
93
94
95
96
97
98
99
100
101
102 struct super_block *nfs_read_super(struct super_block *sb, void *raw_data,
103 int silent)
104 {
105 struct nfs_mount_data *data = (struct nfs_mount_data *) raw_data;
106 struct nfs_server *server;
107 unsigned int fd;
108 struct file *filp;
109
110 kdev_t dev = sb->s_dev;
111
112 MOD_INC_USE_COUNT;
113 if (!data) {
114 printk("nfs_read_super: missing data argument\n");
115 sb->s_dev = 0;
116 MOD_DEC_USE_COUNT;
117 return NULL;
118 }
119 fd = data->fd;
120 if (data->version != NFS_MOUNT_VERSION) {
121 printk("nfs warning: mount version %s than kernel\n",
122 data->version < NFS_MOUNT_VERSION ? "older" : "newer");
123 }
124 if (fd >= NR_OPEN || !(filp = current->files->fd[fd])) {
125 printk("nfs_read_super: invalid file descriptor\n");
126 sb->s_dev = 0;
127 MOD_DEC_USE_COUNT;
128 return NULL;
129 }
130 if (!S_ISSOCK(filp->f_inode->i_mode)) {
131 printk("nfs_read_super: not a socket\n");
132 sb->s_dev = 0;
133 MOD_DEC_USE_COUNT;
134 return NULL;
135 }
136 filp->f_count++;
137 lock_super(sb);
138
139 sb->s_blocksize = 1024;
140 sb->s_blocksize_bits = 10;
141 sb->s_magic = NFS_SUPER_MAGIC;
142 sb->s_dev = dev;
143 sb->s_op = &nfs_sops;
144 server = &sb->u.nfs_sb.s_server;
145 server->file = filp;
146 server->lock = 0;
147 server->wait = NULL;
148 server->flags = data->flags;
149 server->rsize = data->rsize;
150 if (server->rsize <= 0)
151 server->rsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
152 else if (server->rsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
153 server->rsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
154 server->wsize = data->wsize;
155 if (server->wsize <= 0)
156 server->wsize = NFS_DEF_FILE_IO_BUFFER_SIZE;
157 else if (server->wsize >= NFS_MAX_FILE_IO_BUFFER_SIZE)
158 server->wsize = NFS_MAX_FILE_IO_BUFFER_SIZE;
159 server->timeo = data->timeo*HZ/10;
160 server->retrans = data->retrans;
161 server->acregmin = data->acregmin*HZ;
162 server->acregmax = data->acregmax*HZ;
163 server->acdirmin = data->acdirmin*HZ;
164 server->acdirmax = data->acdirmax*HZ;
165 strcpy(server->hostname, data->hostname);
166
167
168
169 if (data->addr.sin_addr.s_addr == INADDR_ANY) {
170 if (((struct sockaddr_in *)(&server->toaddr))->sin_addr.s_addr == INADDR_ANY) {
171 printk("NFS: Error passed unconnected socket and no address\n") ;
172 MOD_DEC_USE_COUNT;
173 return NULL ;
174 } else {
175
176 struct socket *sock;
177 int dummylen ;
178
179
180
181 sock = &((filp->f_inode)->u.socket_i);
182
183
184 sock->ops->getname(sock, &(server->toaddr), &dummylen, 1) ;
185 }
186 } else {
187
188 memcpy((char *)&(server->toaddr),(char *)(&data->addr),sizeof(server->toaddr));
189 }
190
191
192 if ((server->rsock = rpc_makesock(filp)) == NULL) {
193 printk("NFS: cannot create RPC socket.\n");
194 MOD_DEC_USE_COUNT;
195 return NULL;
196 }
197
198 sb->u.nfs_sb.s_root = data->root;
199 unlock_super(sb);
200 if (!(sb->s_mounted = nfs_fhget(sb, &data->root, NULL))) {
201 sb->s_dev = 0;
202 printk("nfs_read_super: get root inode failed\n");
203 MOD_DEC_USE_COUNT;
204 return NULL;
205 }
206 return sb;
207 }
208
209 void nfs_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
210 {
211 int error;
212 struct nfs_fsinfo res;
213 struct statfs tmp;
214
215 error = nfs_proc_statfs(&sb->u.nfs_sb.s_server, &sb->u.nfs_sb.s_root,
216 &res);
217 if (error) {
218 printk("nfs_statfs: statfs error = %d\n", -error);
219 res.bsize = res.blocks = res.bfree = res.bavail = 0;
220 }
221 tmp.f_type = NFS_SUPER_MAGIC;
222 tmp.f_bsize = res.bsize;
223 tmp.f_blocks = res.blocks;
224 tmp.f_bfree = res.bfree;
225 tmp.f_bavail = res.bavail;
226 tmp.f_files = 0;
227 tmp.f_ffree = 0;
228 tmp.f_namelen = NAME_MAX;
229 memcpy_tofs(buf, &tmp, bufsiz);
230 }
231
232
233
234
235
236
237
238
239
240
241 struct inode *nfs_fhget(struct super_block *sb, struct nfs_fh *fhandle,
242 struct nfs_fattr *fattr)
243 {
244 struct nfs_fattr newfattr;
245 int error;
246 struct inode *inode;
247
248 if (!sb) {
249 printk("nfs_fhget: super block is NULL\n");
250 return NULL;
251 }
252 if (!fattr) {
253 error = nfs_proc_getattr(&sb->u.nfs_sb.s_server, fhandle,
254 &newfattr);
255 if (error) {
256 printk("nfs_fhget: getattr error = %d\n", -error);
257 return NULL;
258 }
259 fattr = &newfattr;
260 }
261 if (!(inode = iget(sb, fattr->fileid))) {
262 printk("nfs_fhget: iget failed\n");
263 return NULL;
264 }
265 if (inode->i_dev == sb->s_dev) {
266 if (inode->i_ino != fattr->fileid) {
267 printk("nfs_fhget: unexpected inode from iget\n");
268 return inode;
269 }
270 *NFS_FH(inode) = *fhandle;
271 nfs_refresh_inode(inode, fattr);
272 }
273 return inode;
274 }
275
276 int nfs_notify_change(struct inode *inode, struct iattr *attr)
277 {
278 struct nfs_sattr sattr;
279 struct nfs_fattr fattr;
280 int error;
281
282 sattr.mode = (unsigned) -1;
283 if (attr->ia_valid & ATTR_MODE)
284 sattr.mode = attr->ia_mode;
285
286 sattr.uid = (unsigned) -1;
287 if (attr->ia_valid & ATTR_UID)
288 sattr.uid = attr->ia_uid;
289
290 sattr.gid = (unsigned) -1;
291 if (attr->ia_valid & ATTR_GID)
292 sattr.gid = attr->ia_gid;
293
294
295 sattr.size = (unsigned) -1;
296 if (attr->ia_valid & ATTR_SIZE)
297 sattr.size = S_ISREG(inode->i_mode) ? attr->ia_size : -1;
298
299 sattr.mtime.seconds = sattr.mtime.useconds = (unsigned) -1;
300 if (attr->ia_valid & ATTR_MTIME) {
301 sattr.mtime.seconds = attr->ia_mtime;
302 sattr.mtime.useconds = 0;
303 }
304
305 sattr.atime.seconds = sattr.atime.useconds = (unsigned) -1;
306 if (attr->ia_valid & ATTR_ATIME) {
307 sattr.atime.seconds = attr->ia_atime;
308 sattr.atime.useconds = 0;
309 }
310
311 error = nfs_proc_setattr(NFS_SERVER(inode), NFS_FH(inode),
312 &sattr, &fattr);
313 if (!error)
314 nfs_refresh_inode(inode, &fattr);
315 inode->i_dirt = 0;
316 return error;
317 }
318
319
320
321 static struct file_system_type nfs_fs_type = {
322 nfs_read_super, "nfs", 0, NULL
323 };
324
325
326
327
328
329
330
331
332
333 static int run_nfsiod(void *dummy)
334 {
335 int ret;
336
337 #ifdef __SMP__
338 lock_kernel();
339 syscall_count++;
340 #endif
341
342 MOD_INC_USE_COUNT;
343 current->session = 1;
344 current->pgrp = 1;
345 sprintf(current->comm, "nfsiod");
346 ret = nfsiod();
347 MOD_DEC_USE_COUNT;
348 return ret;
349 }
350
351 int init_nfs_fs(void)
352 {
353
354 kernel_thread(run_nfsiod, NULL, 0);
355 kernel_thread(run_nfsiod, NULL, 0);
356 kernel_thread(run_nfsiod, NULL, 0);
357 kernel_thread(run_nfsiod, NULL, 0);
358 return register_filesystem(&nfs_fs_type);
359 }
360
361 #ifdef MODULE
362 int init_module(void)
363 {
364 int status;
365
366 if ((status = init_nfs_fs()) == 0)
367 register_symtab(0);
368 return status;
369 }
370
371 void cleanup_module(void)
372 {
373 unregister_filesystem(&nfs_fs_type);
374 nfs_kfree_cache();
375 }
376
377 #endif