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