Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
d3870398 | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved. |
1da177e4 LT |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of version 2 of the GNU General Public License as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it would be useful, but | |
9 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 | * | |
12 | * Further, this software is distributed without any warranty that it is | |
13 | * free of the rightful claim of any third person regarding infringement | |
14 | * or the like. Any license provided herein, whether implied or | |
15 | * otherwise, applies only to this software file. Patent licenses, if | |
16 | * any, provided herein do not apply to combinations of this program with | |
17 | * other software, or any other product whatsoever. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write the Free Software Foundation, Inc., 59 | |
21 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | ||
33 | #include "xfs.h" | |
34 | ||
35 | #include "xfs_inum.h" | |
36 | #include "xfs_log.h" | |
37 | #include "xfs_clnt.h" | |
38 | #include "xfs_trans.h" | |
39 | #include "xfs_sb.h" | |
40 | #include "xfs_dir.h" | |
41 | #include "xfs_dir2.h" | |
42 | #include "xfs_alloc.h" | |
43 | #include "xfs_dmapi.h" | |
44 | #include "xfs_quota.h" | |
45 | #include "xfs_mount.h" | |
46 | #include "xfs_alloc_btree.h" | |
47 | #include "xfs_bmap_btree.h" | |
48 | #include "xfs_ialloc_btree.h" | |
49 | #include "xfs_btree.h" | |
50 | #include "xfs_ialloc.h" | |
51 | #include "xfs_attr_sf.h" | |
52 | #include "xfs_dir_sf.h" | |
53 | #include "xfs_dir2_sf.h" | |
54 | #include "xfs_dinode.h" | |
55 | #include "xfs_inode.h" | |
56 | #include "xfs_bmap.h" | |
57 | #include "xfs_bit.h" | |
58 | #include "xfs_rtalloc.h" | |
59 | #include "xfs_error.h" | |
60 | #include "xfs_itable.h" | |
61 | #include "xfs_rw.h" | |
62 | #include "xfs_acl.h" | |
63 | #include "xfs_cap.h" | |
64 | #include "xfs_mac.h" | |
65 | #include "xfs_attr.h" | |
66 | #include "xfs_buf_item.h" | |
67 | #include "xfs_utils.h" | |
68 | #include "xfs_version.h" | |
1da177e4 LT |
69 | |
70 | #include <linux/namei.h> | |
71 | #include <linux/init.h> | |
72 | #include <linux/mount.h> | |
0829c360 | 73 | #include <linux/mempool.h> |
1da177e4 LT |
74 | #include <linux/writeback.h> |
75 | ||
76 | STATIC struct quotactl_ops linvfs_qops; | |
77 | STATIC struct super_operations linvfs_sops; | |
0829c360 CH |
78 | STATIC kmem_zone_t *xfs_vnode_zone; |
79 | STATIC kmem_zone_t *xfs_ioend_zone; | |
80 | mempool_t *xfs_ioend_pool; | |
1da177e4 LT |
81 | |
82 | STATIC struct xfs_mount_args * | |
83 | xfs_args_allocate( | |
84 | struct super_block *sb) | |
85 | { | |
86 | struct xfs_mount_args *args; | |
87 | ||
88 | args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP); | |
89 | args->logbufs = args->logbufsize = -1; | |
90 | strncpy(args->fsname, sb->s_id, MAXNAMELEN); | |
91 | ||
92 | /* Copy the already-parsed mount(2) flags we're interested in */ | |
93 | if (sb->s_flags & MS_NOATIME) | |
94 | args->flags |= XFSMNT_NOATIME; | |
95 | if (sb->s_flags & MS_DIRSYNC) | |
96 | args->flags |= XFSMNT_DIRSYNC; | |
97 | if (sb->s_flags & MS_SYNCHRONOUS) | |
98 | args->flags |= XFSMNT_WSYNC; | |
99 | ||
100 | /* Default to 32 bit inodes on Linux all the time */ | |
101 | args->flags |= XFSMNT_32BITINODES; | |
102 | ||
103 | return args; | |
104 | } | |
105 | ||
106 | __uint64_t | |
107 | xfs_max_file_offset( | |
108 | unsigned int blockshift) | |
109 | { | |
110 | unsigned int pagefactor = 1; | |
111 | unsigned int bitshift = BITS_PER_LONG - 1; | |
112 | ||
113 | /* Figure out maximum filesize, on Linux this can depend on | |
114 | * the filesystem blocksize (on 32 bit platforms). | |
115 | * __block_prepare_write does this in an [unsigned] long... | |
116 | * page->index << (PAGE_CACHE_SHIFT - bbits) | |
117 | * So, for page sized blocks (4K on 32 bit platforms), | |
118 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is | |
119 | * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) | |
120 | * but for smaller blocksizes it is less (bbits = log2 bsize). | |
121 | * Note1: get_block_t takes a long (implicit cast from above) | |
122 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch | |
123 | * can optionally convert the [unsigned] long from above into | |
124 | * an [unsigned] long long. | |
125 | */ | |
126 | ||
127 | #if BITS_PER_LONG == 32 | |
128 | # if defined(CONFIG_LBD) | |
129 | ASSERT(sizeof(sector_t) == 8); | |
130 | pagefactor = PAGE_CACHE_SIZE; | |
131 | bitshift = BITS_PER_LONG; | |
132 | # else | |
133 | pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); | |
134 | # endif | |
135 | #endif | |
136 | ||
137 | return (((__uint64_t)pagefactor) << bitshift) - 1; | |
138 | } | |
139 | ||
140 | STATIC __inline__ void | |
141 | xfs_set_inodeops( | |
142 | struct inode *inode) | |
143 | { | |
0432dab2 CH |
144 | switch (inode->i_mode & S_IFMT) { |
145 | case S_IFREG: | |
1da177e4 LT |
146 | inode->i_op = &linvfs_file_inode_operations; |
147 | inode->i_fop = &linvfs_file_operations; | |
148 | inode->i_mapping->a_ops = &linvfs_aops; | |
0432dab2 CH |
149 | break; |
150 | case S_IFDIR: | |
1da177e4 LT |
151 | inode->i_op = &linvfs_dir_inode_operations; |
152 | inode->i_fop = &linvfs_dir_operations; | |
0432dab2 CH |
153 | break; |
154 | case S_IFLNK: | |
1da177e4 LT |
155 | inode->i_op = &linvfs_symlink_inode_operations; |
156 | if (inode->i_blocks) | |
157 | inode->i_mapping->a_ops = &linvfs_aops; | |
0432dab2 CH |
158 | break; |
159 | default: | |
1da177e4 LT |
160 | inode->i_op = &linvfs_file_inode_operations; |
161 | init_special_inode(inode, inode->i_mode, inode->i_rdev); | |
0432dab2 | 162 | break; |
1da177e4 LT |
163 | } |
164 | } | |
165 | ||
166 | STATIC __inline__ void | |
167 | xfs_revalidate_inode( | |
168 | xfs_mount_t *mp, | |
169 | vnode_t *vp, | |
170 | xfs_inode_t *ip) | |
171 | { | |
172 | struct inode *inode = LINVFS_GET_IP(vp); | |
173 | ||
0432dab2 | 174 | inode->i_mode = ip->i_d.di_mode; |
1da177e4 LT |
175 | inode->i_nlink = ip->i_d.di_nlink; |
176 | inode->i_uid = ip->i_d.di_uid; | |
177 | inode->i_gid = ip->i_d.di_gid; | |
0432dab2 CH |
178 | |
179 | switch (inode->i_mode & S_IFMT) { | |
180 | case S_IFBLK: | |
181 | case S_IFCHR: | |
182 | inode->i_rdev = | |
183 | MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff, | |
184 | sysv_minor(ip->i_df.if_u2.if_rdev)); | |
185 | break; | |
186 | default: | |
1da177e4 | 187 | inode->i_rdev = 0; |
0432dab2 | 188 | break; |
1da177e4 | 189 | } |
0432dab2 | 190 | |
1da177e4 LT |
191 | inode->i_blksize = PAGE_CACHE_SIZE; |
192 | inode->i_generation = ip->i_d.di_gen; | |
193 | i_size_write(inode, ip->i_d.di_size); | |
194 | inode->i_blocks = | |
195 | XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks); | |
196 | inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec; | |
197 | inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec; | |
198 | inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec; | |
199 | inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec; | |
200 | inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec; | |
201 | inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec; | |
202 | if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE) | |
203 | inode->i_flags |= S_IMMUTABLE; | |
204 | else | |
205 | inode->i_flags &= ~S_IMMUTABLE; | |
206 | if (ip->i_d.di_flags & XFS_DIFLAG_APPEND) | |
207 | inode->i_flags |= S_APPEND; | |
208 | else | |
209 | inode->i_flags &= ~S_APPEND; | |
210 | if (ip->i_d.di_flags & XFS_DIFLAG_SYNC) | |
211 | inode->i_flags |= S_SYNC; | |
212 | else | |
213 | inode->i_flags &= ~S_SYNC; | |
214 | if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME) | |
215 | inode->i_flags |= S_NOATIME; | |
216 | else | |
217 | inode->i_flags &= ~S_NOATIME; | |
218 | vp->v_flag &= ~VMODIFIED; | |
219 | } | |
220 | ||
221 | void | |
222 | xfs_initialize_vnode( | |
223 | bhv_desc_t *bdp, | |
224 | vnode_t *vp, | |
225 | bhv_desc_t *inode_bhv, | |
226 | int unlock) | |
227 | { | |
228 | xfs_inode_t *ip = XFS_BHVTOI(inode_bhv); | |
229 | struct inode *inode = LINVFS_GET_IP(vp); | |
230 | ||
231 | if (!inode_bhv->bd_vobj) { | |
232 | vp->v_vfsp = bhvtovfs(bdp); | |
233 | bhv_desc_init(inode_bhv, ip, vp, &xfs_vnodeops); | |
234 | bhv_insert(VN_BHV_HEAD(vp), inode_bhv); | |
235 | } | |
236 | ||
237 | /* | |
238 | * We need to set the ops vectors, and unlock the inode, but if | |
239 | * we have been called during the new inode create process, it is | |
240 | * too early to fill in the Linux inode. We will get called a | |
241 | * second time once the inode is properly set up, and then we can | |
242 | * finish our work. | |
243 | */ | |
244 | if (ip->i_d.di_mode != 0 && unlock && (inode->i_state & I_NEW)) { | |
1da177e4 LT |
245 | xfs_revalidate_inode(XFS_BHVTOM(bdp), vp, ip); |
246 | xfs_set_inodeops(inode); | |
247 | ||
248 | ip->i_flags &= ~XFS_INEW; | |
249 | barrier(); | |
250 | ||
251 | unlock_new_inode(inode); | |
252 | } | |
253 | } | |
254 | ||
255 | int | |
256 | xfs_blkdev_get( | |
257 | xfs_mount_t *mp, | |
258 | const char *name, | |
259 | struct block_device **bdevp) | |
260 | { | |
261 | int error = 0; | |
262 | ||
263 | *bdevp = open_bdev_excl(name, 0, mp); | |
264 | if (IS_ERR(*bdevp)) { | |
265 | error = PTR_ERR(*bdevp); | |
266 | printk("XFS: Invalid device [%s], error=%d\n", name, error); | |
267 | } | |
268 | ||
269 | return -error; | |
270 | } | |
271 | ||
272 | void | |
273 | xfs_blkdev_put( | |
274 | struct block_device *bdev) | |
275 | { | |
276 | if (bdev) | |
277 | close_bdev_excl(bdev); | |
278 | } | |
279 | ||
280 | ||
281 | STATIC struct inode * | |
282 | linvfs_alloc_inode( | |
283 | struct super_block *sb) | |
284 | { | |
285 | vnode_t *vp; | |
286 | ||
0829c360 | 287 | vp = kmem_cache_alloc(xfs_vnode_zone, kmem_flags_convert(KM_SLEEP)); |
1da177e4 LT |
288 | if (!vp) |
289 | return NULL; | |
290 | return LINVFS_GET_IP(vp); | |
291 | } | |
292 | ||
293 | STATIC void | |
294 | linvfs_destroy_inode( | |
295 | struct inode *inode) | |
296 | { | |
0829c360 | 297 | kmem_zone_free(xfs_vnode_zone, LINVFS_GET_VP(inode)); |
1da177e4 LT |
298 | } |
299 | ||
300 | STATIC void | |
0829c360 | 301 | linvfs_inode_init_once( |
1da177e4 LT |
302 | void *data, |
303 | kmem_cache_t *cachep, | |
304 | unsigned long flags) | |
305 | { | |
306 | vnode_t *vp = (vnode_t *)data; | |
307 | ||
308 | if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == | |
309 | SLAB_CTOR_CONSTRUCTOR) | |
310 | inode_init_once(LINVFS_GET_IP(vp)); | |
311 | } | |
312 | ||
313 | STATIC int | |
0829c360 | 314 | linvfs_init_zones(void) |
1da177e4 | 315 | { |
0829c360 | 316 | xfs_vnode_zone = kmem_cache_create("xfs_vnode", |
1da177e4 | 317 | sizeof(vnode_t), 0, SLAB_RECLAIM_ACCOUNT, |
0829c360 CH |
318 | linvfs_inode_init_once, NULL); |
319 | if (!xfs_vnode_zone) | |
320 | goto out; | |
321 | ||
322 | xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend"); | |
323 | if (!xfs_ioend_zone) | |
324 | goto out_destroy_vnode_zone; | |
325 | ||
326 | xfs_ioend_pool = mempool_create(4 * MAX_BUF_PER_PAGE, | |
327 | mempool_alloc_slab, mempool_free_slab, | |
328 | xfs_ioend_zone); | |
329 | if (!xfs_ioend_pool) | |
330 | goto out_free_ioend_zone; | |
331 | ||
1da177e4 | 332 | return 0; |
0829c360 CH |
333 | |
334 | ||
335 | out_free_ioend_zone: | |
336 | kmem_zone_destroy(xfs_ioend_zone); | |
337 | out_destroy_vnode_zone: | |
338 | kmem_zone_destroy(xfs_vnode_zone); | |
339 | out: | |
340 | return -ENOMEM; | |
1da177e4 LT |
341 | } |
342 | ||
343 | STATIC void | |
0829c360 | 344 | linvfs_destroy_zones(void) |
1da177e4 | 345 | { |
0829c360 CH |
346 | mempool_destroy(xfs_ioend_pool); |
347 | kmem_zone_destroy(xfs_vnode_zone); | |
348 | kmem_zone_destroy(xfs_ioend_zone); | |
1da177e4 LT |
349 | } |
350 | ||
351 | /* | |
352 | * Attempt to flush the inode, this will actually fail | |
353 | * if the inode is pinned, but we dirty the inode again | |
354 | * at the point when it is unpinned after a log write, | |
355 | * since this is when the inode itself becomes flushable. | |
356 | */ | |
357 | STATIC int | |
358 | linvfs_write_inode( | |
359 | struct inode *inode, | |
360 | int sync) | |
361 | { | |
362 | vnode_t *vp = LINVFS_GET_VP(inode); | |
363 | int error = 0, flags = FLUSH_INODE; | |
364 | ||
365 | if (vp) { | |
366 | vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address); | |
367 | if (sync) | |
368 | flags |= FLUSH_SYNC; | |
369 | VOP_IFLUSH(vp, flags, error); | |
370 | if (error == EAGAIN) { | |
371 | if (sync) | |
372 | VOP_IFLUSH(vp, flags | FLUSH_LOG, error); | |
373 | else | |
374 | error = 0; | |
375 | } | |
376 | } | |
377 | ||
378 | return -error; | |
379 | } | |
380 | ||
381 | STATIC void | |
382 | linvfs_clear_inode( | |
383 | struct inode *inode) | |
384 | { | |
385 | vnode_t *vp = LINVFS_GET_VP(inode); | |
386 | ||
387 | if (vp) { | |
388 | vn_rele(vp); | |
389 | vn_trace_entry(vp, __FUNCTION__, (inst_t *)__return_address); | |
390 | /* | |
391 | * Do all our cleanup, and remove this vnode. | |
392 | */ | |
393 | vn_remove(vp); | |
394 | } | |
395 | } | |
396 | ||
397 | ||
398 | /* | |
399 | * Enqueue a work item to be picked up by the vfs xfssyncd thread. | |
400 | * Doing this has two advantages: | |
401 | * - It saves on stack space, which is tight in certain situations | |
402 | * - It can be used (with care) as a mechanism to avoid deadlocks. | |
403 | * Flushing while allocating in a full filesystem requires both. | |
404 | */ | |
405 | STATIC void | |
406 | xfs_syncd_queue_work( | |
407 | struct vfs *vfs, | |
408 | void *data, | |
409 | void (*syncer)(vfs_t *, void *)) | |
410 | { | |
411 | vfs_sync_work_t *work; | |
412 | ||
413 | work = kmem_alloc(sizeof(struct vfs_sync_work), KM_SLEEP); | |
414 | INIT_LIST_HEAD(&work->w_list); | |
415 | work->w_syncer = syncer; | |
416 | work->w_data = data; | |
417 | work->w_vfs = vfs; | |
418 | spin_lock(&vfs->vfs_sync_lock); | |
419 | list_add_tail(&work->w_list, &vfs->vfs_sync_list); | |
420 | spin_unlock(&vfs->vfs_sync_lock); | |
421 | wake_up_process(vfs->vfs_sync_task); | |
422 | } | |
423 | ||
424 | /* | |
425 | * Flush delayed allocate data, attempting to free up reserved space | |
426 | * from existing allocations. At this point a new allocation attempt | |
427 | * has failed with ENOSPC and we are in the process of scratching our | |
428 | * heads, looking about for more room... | |
429 | */ | |
430 | STATIC void | |
431 | xfs_flush_inode_work( | |
432 | vfs_t *vfs, | |
433 | void *inode) | |
434 | { | |
435 | filemap_flush(((struct inode *)inode)->i_mapping); | |
436 | iput((struct inode *)inode); | |
437 | } | |
438 | ||
439 | void | |
440 | xfs_flush_inode( | |
441 | xfs_inode_t *ip) | |
442 | { | |
443 | struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip)); | |
444 | struct vfs *vfs = XFS_MTOVFS(ip->i_mount); | |
445 | ||
446 | igrab(inode); | |
447 | xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work); | |
448 | delay(HZ/2); | |
449 | } | |
450 | ||
451 | /* | |
452 | * This is the "bigger hammer" version of xfs_flush_inode_work... | |
453 | * (IOW, "If at first you don't succeed, use a Bigger Hammer"). | |
454 | */ | |
455 | STATIC void | |
456 | xfs_flush_device_work( | |
457 | vfs_t *vfs, | |
458 | void *inode) | |
459 | { | |
460 | sync_blockdev(vfs->vfs_super->s_bdev); | |
461 | iput((struct inode *)inode); | |
462 | } | |
463 | ||
464 | void | |
465 | xfs_flush_device( | |
466 | xfs_inode_t *ip) | |
467 | { | |
468 | struct inode *inode = LINVFS_GET_IP(XFS_ITOV(ip)); | |
469 | struct vfs *vfs = XFS_MTOVFS(ip->i_mount); | |
470 | ||
471 | igrab(inode); | |
472 | xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work); | |
473 | delay(HZ/2); | |
474 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); | |
475 | } | |
476 | ||
477 | #define SYNCD_FLAGS (SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR) | |
478 | STATIC void | |
479 | vfs_sync_worker( | |
480 | vfs_t *vfsp, | |
481 | void *unused) | |
482 | { | |
483 | int error; | |
484 | ||
485 | if (!(vfsp->vfs_flag & VFS_RDONLY)) | |
486 | VFS_SYNC(vfsp, SYNCD_FLAGS, NULL, error); | |
487 | vfsp->vfs_sync_seq++; | |
488 | wmb(); | |
489 | wake_up(&vfsp->vfs_wait_single_sync_task); | |
490 | } | |
491 | ||
492 | STATIC int | |
493 | xfssyncd( | |
494 | void *arg) | |
495 | { | |
496 | long timeleft; | |
497 | vfs_t *vfsp = (vfs_t *) arg; | |
498 | struct list_head tmp; | |
499 | struct vfs_sync_work *work, *n; | |
500 | ||
501 | daemonize("xfssyncd"); | |
502 | ||
503 | vfsp->vfs_sync_work.w_vfs = vfsp; | |
504 | vfsp->vfs_sync_work.w_syncer = vfs_sync_worker; | |
505 | vfsp->vfs_sync_task = current; | |
506 | wmb(); | |
507 | wake_up(&vfsp->vfs_wait_sync_task); | |
508 | ||
509 | INIT_LIST_HEAD(&tmp); | |
510 | timeleft = (xfs_syncd_centisecs * HZ) / 100; | |
511 | for (;;) { | |
512 | set_current_state(TASK_INTERRUPTIBLE); | |
513 | timeleft = schedule_timeout(timeleft); | |
514 | /* swsusp */ | |
3e1d1d28 | 515 | try_to_freeze(); |
1da177e4 LT |
516 | if (vfsp->vfs_flag & VFS_UMOUNT) |
517 | break; | |
518 | ||
519 | spin_lock(&vfsp->vfs_sync_lock); | |
520 | /* | |
521 | * We can get woken by laptop mode, to do a sync - | |
522 | * that's the (only!) case where the list would be | |
523 | * empty with time remaining. | |
524 | */ | |
525 | if (!timeleft || list_empty(&vfsp->vfs_sync_list)) { | |
526 | if (!timeleft) | |
527 | timeleft = (xfs_syncd_centisecs * HZ) / 100; | |
528 | INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list); | |
529 | list_add_tail(&vfsp->vfs_sync_work.w_list, | |
530 | &vfsp->vfs_sync_list); | |
531 | } | |
532 | list_for_each_entry_safe(work, n, &vfsp->vfs_sync_list, w_list) | |
533 | list_move(&work->w_list, &tmp); | |
534 | spin_unlock(&vfsp->vfs_sync_lock); | |
535 | ||
536 | list_for_each_entry_safe(work, n, &tmp, w_list) { | |
537 | (*work->w_syncer)(vfsp, work->w_data); | |
538 | list_del(&work->w_list); | |
539 | if (work == &vfsp->vfs_sync_work) | |
540 | continue; | |
541 | kmem_free(work, sizeof(struct vfs_sync_work)); | |
542 | } | |
543 | } | |
544 | ||
545 | vfsp->vfs_sync_task = NULL; | |
546 | wmb(); | |
547 | wake_up(&vfsp->vfs_wait_sync_task); | |
548 | ||
549 | return 0; | |
550 | } | |
551 | ||
552 | STATIC int | |
553 | linvfs_start_syncd( | |
554 | vfs_t *vfsp) | |
555 | { | |
556 | int pid; | |
557 | ||
558 | pid = kernel_thread(xfssyncd, (void *) vfsp, | |
559 | CLONE_VM | CLONE_FS | CLONE_FILES); | |
560 | if (pid < 0) | |
561 | return -pid; | |
562 | wait_event(vfsp->vfs_wait_sync_task, vfsp->vfs_sync_task); | |
563 | return 0; | |
564 | } | |
565 | ||
566 | STATIC void | |
567 | linvfs_stop_syncd( | |
568 | vfs_t *vfsp) | |
569 | { | |
570 | vfsp->vfs_flag |= VFS_UMOUNT; | |
571 | wmb(); | |
572 | ||
573 | wake_up_process(vfsp->vfs_sync_task); | |
574 | wait_event(vfsp->vfs_wait_sync_task, !vfsp->vfs_sync_task); | |
575 | } | |
576 | ||
577 | STATIC void | |
578 | linvfs_put_super( | |
579 | struct super_block *sb) | |
580 | { | |
581 | vfs_t *vfsp = LINVFS_GET_VFS(sb); | |
582 | int error; | |
583 | ||
584 | linvfs_stop_syncd(vfsp); | |
585 | VFS_SYNC(vfsp, SYNC_ATTR|SYNC_DELWRI, NULL, error); | |
586 | if (!error) | |
587 | VFS_UNMOUNT(vfsp, 0, NULL, error); | |
588 | if (error) { | |
589 | printk("XFS unmount got error %d\n", error); | |
590 | printk("%s: vfsp/0x%p left dangling!\n", __FUNCTION__, vfsp); | |
591 | return; | |
592 | } | |
593 | ||
594 | vfs_deallocate(vfsp); | |
595 | } | |
596 | ||
597 | STATIC void | |
598 | linvfs_write_super( | |
599 | struct super_block *sb) | |
600 | { | |
601 | vfs_t *vfsp = LINVFS_GET_VFS(sb); | |
602 | int error; | |
603 | ||
604 | if (sb->s_flags & MS_RDONLY) { | |
605 | sb->s_dirt = 0; /* paranoia */ | |
606 | return; | |
607 | } | |
608 | /* Push the log and superblock a little */ | |
609 | VFS_SYNC(vfsp, SYNC_FSDATA, NULL, error); | |
610 | sb->s_dirt = 0; | |
611 | } | |
612 | ||
613 | STATIC int | |
614 | linvfs_sync_super( | |
615 | struct super_block *sb, | |
616 | int wait) | |
617 | { | |
618 | vfs_t *vfsp = LINVFS_GET_VFS(sb); | |
619 | int error; | |
620 | int flags = SYNC_FSDATA; | |
621 | ||
f898d6c0 CH |
622 | if (unlikely(sb->s_frozen == SB_FREEZE_WRITE)) |
623 | flags = SYNC_QUIESCE; | |
624 | else | |
625 | flags = SYNC_FSDATA | (wait ? SYNC_WAIT : 0); | |
1da177e4 LT |
626 | |
627 | VFS_SYNC(vfsp, flags, NULL, error); | |
628 | sb->s_dirt = 0; | |
629 | ||
630 | if (unlikely(laptop_mode)) { | |
631 | int prev_sync_seq = vfsp->vfs_sync_seq; | |
632 | ||
633 | /* | |
634 | * The disk must be active because we're syncing. | |
635 | * We schedule xfssyncd now (now that the disk is | |
636 | * active) instead of later (when it might not be). | |
637 | */ | |
638 | wake_up_process(vfsp->vfs_sync_task); | |
639 | /* | |
640 | * We have to wait for the sync iteration to complete. | |
641 | * If we don't, the disk activity caused by the sync | |
642 | * will come after the sync is completed, and that | |
643 | * triggers another sync from laptop mode. | |
644 | */ | |
645 | wait_event(vfsp->vfs_wait_single_sync_task, | |
646 | vfsp->vfs_sync_seq != prev_sync_seq); | |
647 | } | |
648 | ||
649 | return -error; | |
650 | } | |
651 | ||
652 | STATIC int | |
653 | linvfs_statfs( | |
654 | struct super_block *sb, | |
655 | struct kstatfs *statp) | |
656 | { | |
657 | vfs_t *vfsp = LINVFS_GET_VFS(sb); | |
658 | int error; | |
659 | ||
660 | VFS_STATVFS(vfsp, statp, NULL, error); | |
661 | return -error; | |
662 | } | |
663 | ||
664 | STATIC int | |
665 | linvfs_remount( | |
666 | struct super_block *sb, | |
667 | int *flags, | |
668 | char *options) | |
669 | { | |
670 | vfs_t *vfsp = LINVFS_GET_VFS(sb); | |
671 | struct xfs_mount_args *args = xfs_args_allocate(sb); | |
672 | int error; | |
673 | ||
674 | VFS_PARSEARGS(vfsp, options, args, 1, error); | |
675 | if (!error) | |
676 | VFS_MNTUPDATE(vfsp, flags, args, error); | |
677 | kmem_free(args, sizeof(*args)); | |
678 | return -error; | |
679 | } | |
680 | ||
681 | STATIC void | |
682 | linvfs_freeze_fs( | |
683 | struct super_block *sb) | |
684 | { | |
685 | VFS_FREEZE(LINVFS_GET_VFS(sb)); | |
686 | } | |
687 | ||
688 | STATIC int | |
689 | linvfs_show_options( | |
690 | struct seq_file *m, | |
691 | struct vfsmount *mnt) | |
692 | { | |
693 | struct vfs *vfsp = LINVFS_GET_VFS(mnt->mnt_sb); | |
694 | int error; | |
695 | ||
696 | VFS_SHOWARGS(vfsp, m, error); | |
697 | return error; | |
698 | } | |
699 | ||
700 | STATIC int | |
701 | linvfs_getxstate( | |
702 | struct super_block *sb, | |
703 | struct fs_quota_stat *fqs) | |
704 | { | |
705 | struct vfs *vfsp = LINVFS_GET_VFS(sb); | |
706 | int error; | |
707 | ||
708 | VFS_QUOTACTL(vfsp, Q_XGETQSTAT, 0, (caddr_t)fqs, error); | |
709 | return -error; | |
710 | } | |
711 | ||
712 | STATIC int | |
713 | linvfs_setxstate( | |
714 | struct super_block *sb, | |
715 | unsigned int flags, | |
716 | int op) | |
717 | { | |
718 | struct vfs *vfsp = LINVFS_GET_VFS(sb); | |
719 | int error; | |
720 | ||
721 | VFS_QUOTACTL(vfsp, op, 0, (caddr_t)&flags, error); | |
722 | return -error; | |
723 | } | |
724 | ||
725 | STATIC int | |
726 | linvfs_getxquota( | |
727 | struct super_block *sb, | |
728 | int type, | |
729 | qid_t id, | |
730 | struct fs_disk_quota *fdq) | |
731 | { | |
732 | struct vfs *vfsp = LINVFS_GET_VFS(sb); | |
733 | int error, getmode; | |
734 | ||
c8ad20ff NS |
735 | getmode = (type == USRQUOTA) ? Q_XGETQUOTA : |
736 | ((type == GRPQUOTA) ? Q_XGETGQUOTA : Q_XGETPQUOTA); | |
1da177e4 LT |
737 | VFS_QUOTACTL(vfsp, getmode, id, (caddr_t)fdq, error); |
738 | return -error; | |
739 | } | |
740 | ||
741 | STATIC int | |
742 | linvfs_setxquota( | |
743 | struct super_block *sb, | |
744 | int type, | |
745 | qid_t id, | |
746 | struct fs_disk_quota *fdq) | |
747 | { | |
748 | struct vfs *vfsp = LINVFS_GET_VFS(sb); | |
749 | int error, setmode; | |
750 | ||
c8ad20ff NS |
751 | setmode = (type == USRQUOTA) ? Q_XSETQLIM : |
752 | ((type == GRPQUOTA) ? Q_XSETGQLIM : Q_XSETPQLIM); | |
1da177e4 LT |
753 | VFS_QUOTACTL(vfsp, setmode, id, (caddr_t)fdq, error); |
754 | return -error; | |
755 | } | |
756 | ||
757 | STATIC int | |
758 | linvfs_fill_super( | |
759 | struct super_block *sb, | |
760 | void *data, | |
761 | int silent) | |
762 | { | |
763 | vnode_t *rootvp; | |
764 | struct vfs *vfsp = vfs_allocate(); | |
765 | struct xfs_mount_args *args = xfs_args_allocate(sb); | |
766 | struct kstatfs statvfs; | |
767 | int error, error2; | |
768 | ||
769 | vfsp->vfs_super = sb; | |
770 | LINVFS_SET_VFS(sb, vfsp); | |
771 | if (sb->s_flags & MS_RDONLY) | |
772 | vfsp->vfs_flag |= VFS_RDONLY; | |
773 | bhv_insert_all_vfsops(vfsp); | |
774 | ||
775 | VFS_PARSEARGS(vfsp, (char *)data, args, 0, error); | |
776 | if (error) { | |
777 | bhv_remove_all_vfsops(vfsp, 1); | |
778 | goto fail_vfsop; | |
779 | } | |
780 | ||
781 | sb_min_blocksize(sb, BBSIZE); | |
782 | #ifdef CONFIG_XFS_EXPORT | |
783 | sb->s_export_op = &linvfs_export_ops; | |
784 | #endif | |
785 | sb->s_qcop = &linvfs_qops; | |
786 | sb->s_op = &linvfs_sops; | |
787 | ||
788 | VFS_MOUNT(vfsp, args, NULL, error); | |
789 | if (error) { | |
790 | bhv_remove_all_vfsops(vfsp, 1); | |
791 | goto fail_vfsop; | |
792 | } | |
793 | ||
794 | VFS_STATVFS(vfsp, &statvfs, NULL, error); | |
795 | if (error) | |
796 | goto fail_unmount; | |
797 | ||
798 | sb->s_dirt = 1; | |
799 | sb->s_magic = statvfs.f_type; | |
800 | sb->s_blocksize = statvfs.f_bsize; | |
801 | sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1; | |
802 | sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); | |
803 | sb->s_time_gran = 1; | |
804 | set_posix_acl_flag(sb); | |
805 | ||
806 | VFS_ROOT(vfsp, &rootvp, error); | |
807 | if (error) | |
808 | goto fail_unmount; | |
809 | ||
810 | sb->s_root = d_alloc_root(LINVFS_GET_IP(rootvp)); | |
811 | if (!sb->s_root) { | |
812 | error = ENOMEM; | |
813 | goto fail_vnrele; | |
814 | } | |
815 | if (is_bad_inode(sb->s_root->d_inode)) { | |
816 | error = EINVAL; | |
817 | goto fail_vnrele; | |
818 | } | |
819 | if ((error = linvfs_start_syncd(vfsp))) | |
820 | goto fail_vnrele; | |
821 | vn_trace_exit(rootvp, __FUNCTION__, (inst_t *)__return_address); | |
822 | ||
823 | kmem_free(args, sizeof(*args)); | |
824 | return 0; | |
825 | ||
826 | fail_vnrele: | |
827 | if (sb->s_root) { | |
828 | dput(sb->s_root); | |
829 | sb->s_root = NULL; | |
830 | } else { | |
831 | VN_RELE(rootvp); | |
832 | } | |
833 | ||
834 | fail_unmount: | |
835 | VFS_UNMOUNT(vfsp, 0, NULL, error2); | |
836 | ||
837 | fail_vfsop: | |
838 | vfs_deallocate(vfsp); | |
839 | kmem_free(args, sizeof(*args)); | |
840 | return -error; | |
841 | } | |
842 | ||
843 | STATIC struct super_block * | |
844 | linvfs_get_sb( | |
845 | struct file_system_type *fs_type, | |
846 | int flags, | |
847 | const char *dev_name, | |
848 | void *data) | |
849 | { | |
850 | return get_sb_bdev(fs_type, flags, dev_name, data, linvfs_fill_super); | |
851 | } | |
852 | ||
853 | STATIC struct super_operations linvfs_sops = { | |
854 | .alloc_inode = linvfs_alloc_inode, | |
855 | .destroy_inode = linvfs_destroy_inode, | |
856 | .write_inode = linvfs_write_inode, | |
857 | .clear_inode = linvfs_clear_inode, | |
858 | .put_super = linvfs_put_super, | |
859 | .write_super = linvfs_write_super, | |
860 | .sync_fs = linvfs_sync_super, | |
861 | .write_super_lockfs = linvfs_freeze_fs, | |
862 | .statfs = linvfs_statfs, | |
863 | .remount_fs = linvfs_remount, | |
864 | .show_options = linvfs_show_options, | |
865 | }; | |
866 | ||
867 | STATIC struct quotactl_ops linvfs_qops = { | |
868 | .get_xstate = linvfs_getxstate, | |
869 | .set_xstate = linvfs_setxstate, | |
870 | .get_xquota = linvfs_getxquota, | |
871 | .set_xquota = linvfs_setxquota, | |
872 | }; | |
873 | ||
874 | STATIC struct file_system_type xfs_fs_type = { | |
875 | .owner = THIS_MODULE, | |
876 | .name = "xfs", | |
877 | .get_sb = linvfs_get_sb, | |
878 | .kill_sb = kill_block_super, | |
879 | .fs_flags = FS_REQUIRES_DEV, | |
880 | }; | |
881 | ||
882 | ||
883 | STATIC int __init | |
884 | init_xfs_fs( void ) | |
885 | { | |
886 | int error; | |
887 | struct sysinfo si; | |
888 | static char message[] __initdata = KERN_INFO \ | |
889 | XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n"; | |
890 | ||
891 | printk(message); | |
892 | ||
893 | si_meminfo(&si); | |
894 | xfs_physmem = si.totalram; | |
895 | ||
896 | ktrace_init(64); | |
897 | ||
0829c360 | 898 | error = linvfs_init_zones(); |
1da177e4 | 899 | if (error < 0) |
0829c360 | 900 | goto undo_zones; |
1da177e4 LT |
901 | |
902 | error = pagebuf_init(); | |
903 | if (error < 0) | |
904 | goto undo_pagebuf; | |
905 | ||
906 | vn_init(); | |
907 | xfs_init(); | |
908 | uuid_init(); | |
909 | vfs_initquota(); | |
910 | ||
911 | error = register_filesystem(&xfs_fs_type); | |
912 | if (error) | |
913 | goto undo_register; | |
914 | XFS_DM_INIT(&xfs_fs_type); | |
915 | return 0; | |
916 | ||
917 | undo_register: | |
918 | pagebuf_terminate(); | |
919 | ||
920 | undo_pagebuf: | |
0829c360 | 921 | linvfs_destroy_zones(); |
1da177e4 | 922 | |
0829c360 | 923 | undo_zones: |
1da177e4 LT |
924 | return error; |
925 | } | |
926 | ||
927 | STATIC void __exit | |
928 | exit_xfs_fs( void ) | |
929 | { | |
930 | vfs_exitquota(); | |
931 | XFS_DM_EXIT(&xfs_fs_type); | |
932 | unregister_filesystem(&xfs_fs_type); | |
933 | xfs_cleanup(); | |
934 | pagebuf_terminate(); | |
0829c360 | 935 | linvfs_destroy_zones(); |
1da177e4 LT |
936 | ktrace_uninit(); |
937 | } | |
938 | ||
939 | module_init(init_xfs_fs); | |
940 | module_exit(exit_xfs_fs); | |
941 | ||
942 | MODULE_AUTHOR("Silicon Graphics, Inc."); | |
943 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); | |
944 | MODULE_LICENSE("GPL"); |