[PATCH] ppc64: remove duplicate syscall reservation
[linux-2.6/mini2440.git] / fs / jfs / super.c
blobee32211288cefadc7b86c7d33129f6d279950ee3
1 /*
2 * Copyright (C) International Business Machines Corp., 2000-2004
3 * Portions Copyright (C) Christoph Hellwig, 2001-2002
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <linux/fs.h>
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/parser.h>
24 #include <linux/completion.h>
25 #include <linux/vfs.h>
26 #include <linux/moduleparam.h>
27 #include <linux/posix_acl.h>
28 #include <asm/uaccess.h>
30 #include "jfs_incore.h"
31 #include "jfs_filsys.h"
32 #include "jfs_inode.h"
33 #include "jfs_metapage.h"
34 #include "jfs_superblock.h"
35 #include "jfs_dmap.h"
36 #include "jfs_imap.h"
37 #include "jfs_acl.h"
38 #include "jfs_debug.h"
40 MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
41 MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
42 MODULE_LICENSE("GPL");
44 static kmem_cache_t * jfs_inode_cachep;
46 static struct super_operations jfs_super_operations;
47 static struct export_operations jfs_export_operations;
48 static struct file_system_type jfs_fs_type;
50 #define MAX_COMMIT_THREADS 64
51 static int commit_threads = 0;
52 module_param(commit_threads, int, 0);
53 MODULE_PARM_DESC(commit_threads, "Number of commit threads");
55 int jfs_stop_threads;
56 static pid_t jfsIOthread;
57 static pid_t jfsCommitThread[MAX_COMMIT_THREADS];
58 static pid_t jfsSyncThread;
59 DECLARE_COMPLETION(jfsIOwait);
61 #ifdef CONFIG_JFS_DEBUG
62 int jfsloglevel = JFS_LOGLEVEL_WARN;
63 module_param(jfsloglevel, int, 0644);
64 MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
65 #endif
67 static void jfs_handle_error(struct super_block *sb)
69 struct jfs_sb_info *sbi = JFS_SBI(sb);
71 if (sb->s_flags & MS_RDONLY)
72 return;
74 updateSuper(sb, FM_DIRTY);
76 if (sbi->flag & JFS_ERR_PANIC)
77 panic("JFS (device %s): panic forced after error\n",
78 sb->s_id);
79 else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
80 jfs_err("ERROR: (device %s): remounting filesystem "
81 "as read-only\n",
82 sb->s_id);
83 sb->s_flags |= MS_RDONLY;
86 /* nothing is done for continue beyond marking the superblock dirty */
89 void jfs_error(struct super_block *sb, const char * function, ...)
91 static char error_buf[256];
92 va_list args;
94 va_start(args, function);
95 vsprintf(error_buf, function, args);
96 va_end(args);
98 printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf);
100 jfs_handle_error(sb);
103 static struct inode *jfs_alloc_inode(struct super_block *sb)
105 struct jfs_inode_info *jfs_inode;
107 jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS);
108 if (!jfs_inode)
109 return NULL;
110 return &jfs_inode->vfs_inode;
113 static void jfs_destroy_inode(struct inode *inode)
115 struct jfs_inode_info *ji = JFS_IP(inode);
117 spin_lock_irq(&ji->ag_lock);
118 if (ji->active_ag != -1) {
119 struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap;
120 atomic_dec(&bmap->db_active[ji->active_ag]);
121 ji->active_ag = -1;
123 spin_unlock_irq(&ji->ag_lock);
125 #ifdef CONFIG_JFS_POSIX_ACL
126 if (ji->i_acl != JFS_ACL_NOT_CACHED) {
127 posix_acl_release(ji->i_acl);
128 ji->i_acl = JFS_ACL_NOT_CACHED;
130 if (ji->i_default_acl != JFS_ACL_NOT_CACHED) {
131 posix_acl_release(ji->i_default_acl);
132 ji->i_default_acl = JFS_ACL_NOT_CACHED;
134 #endif
136 kmem_cache_free(jfs_inode_cachep, ji);
139 static int jfs_statfs(struct super_block *sb, struct kstatfs *buf)
141 struct jfs_sb_info *sbi = JFS_SBI(sb);
142 s64 maxinodes;
143 struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
145 jfs_info("In jfs_statfs");
146 buf->f_type = JFS_SUPER_MAGIC;
147 buf->f_bsize = sbi->bsize;
148 buf->f_blocks = sbi->bmap->db_mapsize;
149 buf->f_bfree = sbi->bmap->db_nfree;
150 buf->f_bavail = sbi->bmap->db_nfree;
152 * If we really return the number of allocated & free inodes, some
153 * applications will fail because they won't see enough free inodes.
154 * We'll try to calculate some guess as to how may inodes we can
155 * really allocate
157 * buf->f_files = atomic_read(&imap->im_numinos);
158 * buf->f_ffree = atomic_read(&imap->im_numfree);
160 maxinodes = min((s64) atomic_read(&imap->im_numinos) +
161 ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
162 << L2INOSPEREXT), (s64) 0xffffffffLL);
163 buf->f_files = maxinodes;
164 buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
165 atomic_read(&imap->im_numfree));
167 buf->f_namelen = JFS_NAME_MAX;
168 return 0;
171 static void jfs_put_super(struct super_block *sb)
173 struct jfs_sb_info *sbi = JFS_SBI(sb);
174 int rc;
176 jfs_info("In jfs_put_super");
177 rc = jfs_umount(sb);
178 if (rc)
179 jfs_err("jfs_umount failed with return code %d", rc);
180 if (sbi->nls_tab)
181 unload_nls(sbi->nls_tab);
182 sbi->nls_tab = NULL;
184 truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
185 iput(sbi->direct_inode);
186 sbi->direct_inode = NULL;
188 kfree(sbi);
191 enum {
192 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
193 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err,
196 static match_table_t tokens = {
197 {Opt_integrity, "integrity"},
198 {Opt_nointegrity, "nointegrity"},
199 {Opt_iocharset, "iocharset=%s"},
200 {Opt_resize, "resize=%u"},
201 {Opt_resize_nosize, "resize"},
202 {Opt_errors, "errors=%s"},
203 {Opt_ignore, "noquota"},
204 {Opt_ignore, "quota"},
205 {Opt_ignore, "usrquota"},
206 {Opt_ignore, "grpquota"},
207 {Opt_err, NULL}
210 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
211 int *flag)
213 void *nls_map = (void *)-1; /* -1: no change; NULL: none */
214 char *p;
215 struct jfs_sb_info *sbi = JFS_SBI(sb);
217 *newLVSize = 0;
219 if (!options)
220 return 1;
222 while ((p = strsep(&options, ",")) != NULL) {
223 substring_t args[MAX_OPT_ARGS];
224 int token;
225 if (!*p)
226 continue;
228 token = match_token(p, tokens, args);
229 switch (token) {
230 case Opt_integrity:
231 *flag &= ~JFS_NOINTEGRITY;
232 break;
233 case Opt_nointegrity:
234 *flag |= JFS_NOINTEGRITY;
235 break;
236 case Opt_ignore:
237 /* Silently ignore the quota options */
238 /* Don't do anything ;-) */
239 break;
240 case Opt_iocharset:
241 if (nls_map && nls_map != (void *) -1)
242 unload_nls(nls_map);
243 if (!strcmp(args[0].from, "none"))
244 nls_map = NULL;
245 else {
246 nls_map = load_nls(args[0].from);
247 if (!nls_map) {
248 printk(KERN_ERR
249 "JFS: charset not found\n");
250 goto cleanup;
253 break;
254 case Opt_resize:
256 char *resize = args[0].from;
257 *newLVSize = simple_strtoull(resize, &resize, 0);
258 break;
260 case Opt_resize_nosize:
262 *newLVSize = sb->s_bdev->bd_inode->i_size >>
263 sb->s_blocksize_bits;
264 if (*newLVSize == 0)
265 printk(KERN_ERR
266 "JFS: Cannot determine volume size\n");
267 break;
269 case Opt_errors:
271 char *errors = args[0].from;
272 if (!errors || !*errors)
273 goto cleanup;
274 if (!strcmp(errors, "continue")) {
275 *flag &= ~JFS_ERR_REMOUNT_RO;
276 *flag &= ~JFS_ERR_PANIC;
277 *flag |= JFS_ERR_CONTINUE;
278 } else if (!strcmp(errors, "remount-ro")) {
279 *flag &= ~JFS_ERR_CONTINUE;
280 *flag &= ~JFS_ERR_PANIC;
281 *flag |= JFS_ERR_REMOUNT_RO;
282 } else if (!strcmp(errors, "panic")) {
283 *flag &= ~JFS_ERR_CONTINUE;
284 *flag &= ~JFS_ERR_REMOUNT_RO;
285 *flag |= JFS_ERR_PANIC;
286 } else {
287 printk(KERN_ERR
288 "JFS: %s is an invalid error handler\n",
289 errors);
290 goto cleanup;
292 break;
294 default:
295 printk("jfs: Unrecognized mount option \"%s\" "
296 " or missing value\n", p);
297 goto cleanup;
301 if (nls_map != (void *) -1) {
302 /* Discard old (if remount) */
303 if (sbi->nls_tab)
304 unload_nls(sbi->nls_tab);
305 sbi->nls_tab = nls_map;
307 return 1;
309 cleanup:
310 if (nls_map && nls_map != (void *) -1)
311 unload_nls(nls_map);
312 return 0;
315 static int jfs_remount(struct super_block *sb, int *flags, char *data)
317 s64 newLVSize = 0;
318 int rc = 0;
319 int flag = JFS_SBI(sb)->flag;
321 if (!parse_options(data, sb, &newLVSize, &flag)) {
322 return -EINVAL;
324 if (newLVSize) {
325 if (sb->s_flags & MS_RDONLY) {
326 printk(KERN_ERR
327 "JFS: resize requires volume to be mounted read-write\n");
328 return -EROFS;
330 rc = jfs_extendfs(sb, newLVSize, 0);
331 if (rc)
332 return rc;
335 if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
337 * Invalidate any previously read metadata. fsck may have
338 * changed the on-disk data since we mounted r/o
340 truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
342 JFS_SBI(sb)->flag = flag;
343 return jfs_mount_rw(sb, 1);
345 if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
346 rc = jfs_umount_rw(sb);
347 JFS_SBI(sb)->flag = flag;
348 return rc;
350 if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
351 if (!(sb->s_flags & MS_RDONLY)) {
352 rc = jfs_umount_rw(sb);
353 if (rc)
354 return rc;
355 JFS_SBI(sb)->flag = flag;
356 return jfs_mount_rw(sb, 1);
358 JFS_SBI(sb)->flag = flag;
360 return 0;
363 static int jfs_fill_super(struct super_block *sb, void *data, int silent)
365 struct jfs_sb_info *sbi;
366 struct inode *inode;
367 int rc;
368 s64 newLVSize = 0;
369 int flag;
371 jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
373 if (!new_valid_dev(sb->s_bdev->bd_dev))
374 return -EOVERFLOW;
376 sbi = kmalloc(sizeof (struct jfs_sb_info), GFP_KERNEL);
377 if (!sbi)
378 return -ENOSPC;
379 memset(sbi, 0, sizeof (struct jfs_sb_info));
380 sb->s_fs_info = sbi;
381 sbi->sb = sb;
383 /* initialize the mount flag and determine the default error handler */
384 flag = JFS_ERR_REMOUNT_RO;
386 if (!parse_options((char *) data, sb, &newLVSize, &flag)) {
387 kfree(sbi);
388 return -EINVAL;
390 sbi->flag = flag;
392 #ifdef CONFIG_JFS_POSIX_ACL
393 sb->s_flags |= MS_POSIXACL;
394 #endif
396 if (newLVSize) {
397 printk(KERN_ERR "resize option for remount only\n");
398 return -EINVAL;
402 * Initialize blocksize to 4K.
404 sb_set_blocksize(sb, PSIZE);
407 * Set method vectors.
409 sb->s_op = &jfs_super_operations;
410 sb->s_export_op = &jfs_export_operations;
413 * Initialize direct-mapping inode/address-space
415 inode = new_inode(sb);
416 if (inode == NULL)
417 goto out_kfree;
418 inode->i_ino = 0;
419 inode->i_nlink = 1;
420 inode->i_size = sb->s_bdev->bd_inode->i_size;
421 inode->i_mapping->a_ops = &jfs_metapage_aops;
422 mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
424 sbi->direct_inode = inode;
426 rc = jfs_mount(sb);
427 if (rc) {
428 if (!silent) {
429 jfs_err("jfs_mount failed w/return code = %d", rc);
431 goto out_mount_failed;
433 if (sb->s_flags & MS_RDONLY)
434 sbi->log = NULL;
435 else {
436 rc = jfs_mount_rw(sb, 0);
437 if (rc) {
438 if (!silent) {
439 jfs_err("jfs_mount_rw failed, return code = %d",
440 rc);
442 goto out_no_rw;
446 sb->s_magic = JFS_SUPER_MAGIC;
448 inode = iget(sb, ROOT_I);
449 if (!inode || is_bad_inode(inode))
450 goto out_no_root;
451 sb->s_root = d_alloc_root(inode);
452 if (!sb->s_root)
453 goto out_no_root;
455 if (sbi->mntflag & JFS_OS2)
456 sb->s_root->d_op = &jfs_ci_dentry_operations;
458 /* logical blocks are represented by 40 bits in pxd_t, etc. */
459 sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
460 #if BITS_PER_LONG == 32
462 * Page cache is indexed by long.
463 * I would use MAX_LFS_FILESIZE, but it's only half as big
465 sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes);
466 #endif
467 sb->s_time_gran = 1;
468 return 0;
470 out_no_root:
471 jfs_err("jfs_read_super: get root inode failed");
472 if (inode)
473 iput(inode);
475 out_no_rw:
476 rc = jfs_umount(sb);
477 if (rc) {
478 jfs_err("jfs_umount failed with return code %d", rc);
480 out_mount_failed:
481 filemap_fdatawrite(sbi->direct_inode->i_mapping);
482 filemap_fdatawait(sbi->direct_inode->i_mapping);
483 truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
484 make_bad_inode(sbi->direct_inode);
485 iput(sbi->direct_inode);
486 sbi->direct_inode = NULL;
487 out_kfree:
488 if (sbi->nls_tab)
489 unload_nls(sbi->nls_tab);
490 kfree(sbi);
491 return -EINVAL;
494 static void jfs_write_super_lockfs(struct super_block *sb)
496 struct jfs_sb_info *sbi = JFS_SBI(sb);
497 struct jfs_log *log = sbi->log;
499 if (!(sb->s_flags & MS_RDONLY)) {
500 txQuiesce(sb);
501 lmLogShutdown(log);
502 updateSuper(sb, FM_CLEAN);
506 static void jfs_unlockfs(struct super_block *sb)
508 struct jfs_sb_info *sbi = JFS_SBI(sb);
509 struct jfs_log *log = sbi->log;
510 int rc = 0;
512 if (!(sb->s_flags & MS_RDONLY)) {
513 updateSuper(sb, FM_MOUNT);
514 if ((rc = lmLogInit(log)))
515 jfs_err("jfs_unlock failed with return code %d", rc);
516 else
517 txResume(sb);
521 static struct super_block *jfs_get_sb(struct file_system_type *fs_type,
522 int flags, const char *dev_name, void *data)
524 return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
527 static int jfs_sync_fs(struct super_block *sb, int wait)
529 struct jfs_log *log = JFS_SBI(sb)->log;
531 /* log == NULL indicates read-only mount */
532 if (log) {
533 jfs_flush_journal(log, wait);
534 jfs_syncpt(log);
537 return 0;
540 static struct super_operations jfs_super_operations = {
541 .alloc_inode = jfs_alloc_inode,
542 .destroy_inode = jfs_destroy_inode,
543 .read_inode = jfs_read_inode,
544 .dirty_inode = jfs_dirty_inode,
545 .write_inode = jfs_write_inode,
546 .delete_inode = jfs_delete_inode,
547 .put_super = jfs_put_super,
548 .sync_fs = jfs_sync_fs,
549 .write_super_lockfs = jfs_write_super_lockfs,
550 .unlockfs = jfs_unlockfs,
551 .statfs = jfs_statfs,
552 .remount_fs = jfs_remount,
555 static struct export_operations jfs_export_operations = {
556 .get_parent = jfs_get_parent,
559 static struct file_system_type jfs_fs_type = {
560 .owner = THIS_MODULE,
561 .name = "jfs",
562 .get_sb = jfs_get_sb,
563 .kill_sb = kill_block_super,
564 .fs_flags = FS_REQUIRES_DEV,
567 static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
569 struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
571 if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
572 SLAB_CTOR_CONSTRUCTOR) {
573 memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
574 INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
575 init_rwsem(&jfs_ip->rdwrlock);
576 init_MUTEX(&jfs_ip->commit_sem);
577 init_rwsem(&jfs_ip->xattr_sem);
578 spin_lock_init(&jfs_ip->ag_lock);
579 jfs_ip->active_ag = -1;
580 #ifdef CONFIG_JFS_POSIX_ACL
581 jfs_ip->i_acl = JFS_ACL_NOT_CACHED;
582 jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED;
583 #endif
584 inode_init_once(&jfs_ip->vfs_inode);
588 static int __init init_jfs_fs(void)
590 int i;
591 int rc;
593 jfs_inode_cachep =
594 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
595 SLAB_RECLAIM_ACCOUNT, init_once, NULL);
596 if (jfs_inode_cachep == NULL)
597 return -ENOMEM;
600 * Metapage initialization
602 rc = metapage_init();
603 if (rc) {
604 jfs_err("metapage_init failed w/rc = %d", rc);
605 goto free_slab;
609 * Transaction Manager initialization
611 rc = txInit();
612 if (rc) {
613 jfs_err("txInit failed w/rc = %d", rc);
614 goto free_metapage;
618 * I/O completion thread (endio)
620 jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL);
621 if (jfsIOthread < 0) {
622 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread);
623 goto end_txmngr;
625 wait_for_completion(&jfsIOwait); /* Wait until thread starts */
627 if (commit_threads < 1)
628 commit_threads = num_online_cpus();
629 if (commit_threads > MAX_COMMIT_THREADS)
630 commit_threads = MAX_COMMIT_THREADS;
632 for (i = 0; i < commit_threads; i++) {
633 jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL,
634 CLONE_KERNEL);
635 if (jfsCommitThread[i] < 0) {
636 jfs_err("init_jfs_fs: fork failed w/rc = %d",
637 jfsCommitThread[i]);
638 commit_threads = i;
639 goto kill_committask;
641 /* Wait until thread starts */
642 wait_for_completion(&jfsIOwait);
645 jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL);
646 if (jfsSyncThread < 0) {
647 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread);
648 goto kill_committask;
650 wait_for_completion(&jfsIOwait); /* Wait until thread starts */
652 #ifdef PROC_FS_JFS
653 jfs_proc_init();
654 #endif
656 return register_filesystem(&jfs_fs_type);
658 kill_committask:
659 jfs_stop_threads = 1;
660 wake_up_all(&jfs_commit_thread_wait);
661 for (i = 0; i < commit_threads; i++)
662 wait_for_completion(&jfsIOwait);
664 wake_up(&jfs_IO_thread_wait);
665 wait_for_completion(&jfsIOwait); /* Wait for thread exit */
666 end_txmngr:
667 txExit();
668 free_metapage:
669 metapage_exit();
670 free_slab:
671 kmem_cache_destroy(jfs_inode_cachep);
672 return rc;
675 static void __exit exit_jfs_fs(void)
677 int i;
679 jfs_info("exit_jfs_fs called");
681 jfs_stop_threads = 1;
682 txExit();
683 metapage_exit();
684 wake_up(&jfs_IO_thread_wait);
685 wait_for_completion(&jfsIOwait); /* Wait until IO thread exits */
686 wake_up_all(&jfs_commit_thread_wait);
687 for (i = 0; i < commit_threads; i++)
688 wait_for_completion(&jfsIOwait);
689 wake_up(&jfs_sync_thread_wait);
690 wait_for_completion(&jfsIOwait); /* Wait until Sync thread exits */
691 #ifdef PROC_FS_JFS
692 jfs_proc_clean();
693 #endif
694 unregister_filesystem(&jfs_fs_type);
695 kmem_cache_destroy(jfs_inode_cachep);
698 module_init(init_jfs_fs)
699 module_exit(exit_jfs_fs)