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