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