2 * Copyright (c) International Business Machines Corp., 2000-2003
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.
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
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/completion.h>
24 #include <linux/vfs.h>
25 #include <asm/uaccess.h>
27 #include "jfs_incore.h"
28 #include "jfs_filsys.h"
29 #include "jfs_metapage.h"
30 #include "jfs_superblock.h"
34 #include "jfs_debug.h"
36 MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
37 MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
38 MODULE_LICENSE("GPL");
40 static kmem_cache_t
* jfs_inode_cachep
;
42 static struct super_operations jfs_super_operations
;
43 static struct export_operations jfs_export_operations
;
44 static struct file_system_type jfs_fs_type
;
47 static pid_t jfsIOthread
;
48 static pid_t jfsCommitThread
;
49 static pid_t jfsSyncThread
;
50 DECLARE_COMPLETION(jfsIOwait
);
52 #ifdef CONFIG_JFS_DEBUG
53 int jfsloglevel
= JFS_LOGLEVEL_WARN
;
54 MODULE_PARM(jfsloglevel
, "i");
55 MODULE_PARM_DESC(jfsloglevel
, "Specify JFS loglevel (0, 1 or 2)");
59 * External declarations
61 extern int jfs_mount(struct super_block
*);
62 extern int jfs_mount_rw(struct super_block
*, int);
63 extern int jfs_umount(struct super_block
*);
64 extern int jfs_umount_rw(struct super_block
*);
66 extern int jfsIOWait(void *);
67 extern int jfs_lazycommit(void *);
68 extern int jfs_sync(void *);
70 extern void jfs_read_inode(struct inode
*inode
);
71 extern void jfs_dirty_inode(struct inode
*inode
);
72 extern void jfs_delete_inode(struct inode
*inode
);
73 extern void jfs_write_inode(struct inode
*inode
, int wait
);
75 extern struct dentry
*jfs_get_parent(struct dentry
*dentry
);
76 extern int jfs_extendfs(struct super_block
*, s64
, int);
78 #ifdef PROC_FS_JFS /* see jfs_debug.h */
79 extern void jfs_proc_init(void);
80 extern void jfs_proc_clean(void);
83 extern wait_queue_head_t jfs_IO_thread_wait
;
84 extern wait_queue_head_t jfs_commit_thread_wait
;
85 extern wait_queue_head_t jfs_sync_thread_wait
;
87 static struct inode
*jfs_alloc_inode(struct super_block
*sb
)
89 struct jfs_inode_info
*jfs_inode
;
91 jfs_inode
= kmem_cache_alloc(jfs_inode_cachep
, GFP_NOFS
);
94 return &jfs_inode
->vfs_inode
;
97 static void jfs_destroy_inode(struct inode
*inode
)
99 struct jfs_inode_info
*ji
= JFS_IP(inode
);
101 if (ji
->active_ag
!= -1) {
102 struct bmap
*bmap
= JFS_SBI(inode
->i_sb
)->bmap
;
103 atomic_dec(&bmap
->db_active
[ji
->active_ag
]);
106 #ifdef CONFIG_JFS_POSIX_ACL
107 if (ji
->i_acl
!= JFS_ACL_NOT_CACHED
) {
108 posix_acl_release(ji
->i_acl
);
109 ji
->i_acl
= JFS_ACL_NOT_CACHED
;
111 if (ji
->i_default_acl
!= JFS_ACL_NOT_CACHED
) {
112 posix_acl_release(ji
->i_default_acl
);
113 ji
->i_default_acl
= JFS_ACL_NOT_CACHED
;
117 kmem_cache_free(jfs_inode_cachep
, ji
);
120 static int jfs_statfs(struct super_block
*sb
, struct kstatfs
*buf
)
122 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
124 struct inomap
*imap
= JFS_IP(sbi
->ipimap
)->i_imap
;
126 jfs_info("In jfs_statfs");
127 buf
->f_type
= JFS_SUPER_MAGIC
;
128 buf
->f_bsize
= sbi
->bsize
;
129 buf
->f_blocks
= sbi
->bmap
->db_mapsize
;
130 buf
->f_bfree
= sbi
->bmap
->db_nfree
;
131 buf
->f_bavail
= sbi
->bmap
->db_nfree
;
133 * If we really return the number of allocated & free inodes, some
134 * applications will fail because they won't see enough free inodes.
135 * We'll try to calculate some guess as to how may inodes we can
138 * buf->f_files = atomic_read(&imap->im_numinos);
139 * buf->f_ffree = atomic_read(&imap->im_numfree);
141 maxinodes
= min((s64
) atomic_read(&imap
->im_numinos
) +
142 ((sbi
->bmap
->db_nfree
>> imap
->im_l2nbperiext
)
143 << L2INOSPEREXT
), (s64
) 0xffffffffLL
);
144 buf
->f_files
= maxinodes
;
145 buf
->f_ffree
= maxinodes
- (atomic_read(&imap
->im_numinos
) -
146 atomic_read(&imap
->im_numfree
));
148 buf
->f_namelen
= JFS_NAME_MAX
;
152 static void jfs_put_super(struct super_block
*sb
)
154 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
157 jfs_info("In jfs_put_super");
160 jfs_err("jfs_umount failed with return code %d", rc
);
161 unload_nls(sbi
->nls_tab
);
167 static int parse_options(char *options
, struct super_block
*sb
, s64
*newLVSize
,
170 void *nls_map
= NULL
;
173 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
179 while ((this_char
= strsep(&options
, ",")) != NULL
) {
182 if ((value
= strchr(this_char
, '=')) != NULL
)
184 if (!strcmp(this_char
, "integrity")) {
185 *flag
&= ~JFS_NOINTEGRITY
;
186 } else if (!strcmp(this_char
, "nointegrity")) {
187 *flag
|= JFS_NOINTEGRITY
;
188 } else if (!strcmp(this_char
, "iocharset")) {
189 if (!value
|| !*value
)
191 if (nls_map
) /* specified iocharset twice! */
193 nls_map
= load_nls(value
);
195 printk(KERN_ERR
"JFS: charset not found\n");
198 } else if (!strcmp(this_char
, "resize")) {
199 if (!value
|| !*value
) {
200 *newLVSize
= sb
->s_bdev
->bd_inode
->i_size
>>
201 sb
->s_blocksize_bits
;
204 "JFS: Cannot determine volume size\n");
206 *newLVSize
= simple_strtoull(value
, &value
, 0);
208 /* Silently ignore the quota options */
209 } else if (!strcmp(this_char
, "grpquota")
210 || !strcmp(this_char
, "noquota")
211 || !strcmp(this_char
, "quota")
212 || !strcmp(this_char
, "usrquota"))
213 /* Don't do anything ;-) */ ;
215 printk("jfs: Unrecognized mount option %s\n",
221 /* Discard old (if remount) */
223 unload_nls(sbi
->nls_tab
);
224 sbi
->nls_tab
= nls_map
;
228 printk(KERN_ERR
"JFS: %s needs an argument\n", this_char
);
235 int jfs_remount(struct super_block
*sb
, int *flags
, char *data
)
239 int flag
= JFS_SBI(sb
)->flag
;
241 if (!parse_options(data
, sb
, &newLVSize
, &flag
)) {
245 if (sb
->s_flags
& MS_RDONLY
) {
247 "JFS: resize requires volume to be mounted read-write\n");
250 rc
= jfs_extendfs(sb
, newLVSize
, 0);
255 if ((sb
->s_flags
& MS_RDONLY
) && !(*flags
& MS_RDONLY
)) {
256 JFS_SBI(sb
)->flag
= flag
;
257 return jfs_mount_rw(sb
, 1);
259 if ((!(sb
->s_flags
& MS_RDONLY
)) && (*flags
& MS_RDONLY
)) {
260 rc
= jfs_umount_rw(sb
);
261 JFS_SBI(sb
)->flag
= flag
;
264 if ((JFS_SBI(sb
)->flag
& JFS_NOINTEGRITY
) != (flag
& JFS_NOINTEGRITY
))
265 if (!(sb
->s_flags
& MS_RDONLY
)) {
266 rc
= jfs_umount_rw(sb
);
269 JFS_SBI(sb
)->flag
= flag
;
270 return jfs_mount_rw(sb
, 1);
272 JFS_SBI(sb
)->flag
= flag
;
277 static int jfs_fill_super(struct super_block
*sb
, void *data
, int silent
)
279 struct jfs_sb_info
*sbi
;
285 jfs_info("In jfs_read_super: s_flags=0x%lx", sb
->s_flags
);
287 sbi
= kmalloc(sizeof (struct jfs_sb_info
), GFP_KERNEL
);
290 memset(sbi
, 0, sizeof (struct jfs_sb_info
));
294 if (!parse_options((char *) data
, sb
, &newLVSize
, &flag
)) {
301 printk(KERN_ERR
"resize option for remount only\n");
306 * Initialize blocksize to 4K.
308 sb_set_blocksize(sb
, PSIZE
);
311 * Set method vectors.
313 sb
->s_op
= &jfs_super_operations
;
314 sb
->s_export_op
= &jfs_export_operations
;
319 jfs_err("jfs_mount failed w/return code = %d", rc
);
323 if (sb
->s_flags
& MS_RDONLY
)
326 rc
= jfs_mount_rw(sb
, 0);
329 jfs_err("jfs_mount_rw failed, return code = %d",
336 sb
->s_magic
= JFS_SUPER_MAGIC
;
338 inode
= iget(sb
, ROOT_I
);
339 if (!inode
|| is_bad_inode(inode
))
341 sb
->s_root
= d_alloc_root(inode
);
346 sbi
->nls_tab
= load_nls_default();
348 /* logical blocks are represented by 40 bits in pxd_t, etc. */
349 sb
->s_maxbytes
= ((u64
) sb
->s_blocksize
) << 40;
350 #if BITS_PER_LONG == 32
352 * Page cache is indexed by long.
353 * I would use MAX_LFS_FILESIZE, but it's only half as big
355 sb
->s_maxbytes
= min(((u64
) PAGE_CACHE_SIZE
<< 32) - 1, sb
->s_maxbytes
);
361 jfs_err("jfs_read_super: get root inode failed");
368 jfs_err("jfs_umount failed with return code %d", rc
);
372 unload_nls(sbi
->nls_tab
);
377 static void jfs_write_super_lockfs(struct super_block
*sb
)
379 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
380 struct jfs_log
*log
= sbi
->log
;
382 if (!(sb
->s_flags
& MS_RDONLY
)) {
388 static void jfs_unlockfs(struct super_block
*sb
)
390 struct jfs_sb_info
*sbi
= JFS_SBI(sb
);
391 struct jfs_log
*log
= sbi
->log
;
394 if (!(sb
->s_flags
& MS_RDONLY
)) {
395 if ((rc
= lmLogInit(log
)))
396 jfs_err("jfs_unlock failed with return code %d", rc
);
402 static struct super_block
*jfs_get_sb(struct file_system_type
*fs_type
,
403 int flags
, const char *dev_name
, void *data
)
405 return get_sb_bdev(fs_type
, flags
, dev_name
, data
, jfs_fill_super
);
408 static int jfs_sync_fs(struct super_block
*sb
, int wait
)
410 struct jfs_log
*log
= JFS_SBI(sb
)->log
;
412 /* log == NULL indicates read-only mount */
414 jfs_flush_journal(log
, wait
);
419 static struct super_operations jfs_super_operations
= {
420 .alloc_inode
= jfs_alloc_inode
,
421 .destroy_inode
= jfs_destroy_inode
,
422 .read_inode
= jfs_read_inode
,
423 .dirty_inode
= jfs_dirty_inode
,
424 .write_inode
= jfs_write_inode
,
425 .delete_inode
= jfs_delete_inode
,
426 .put_super
= jfs_put_super
,
427 .sync_fs
= jfs_sync_fs
,
428 .write_super_lockfs
= jfs_write_super_lockfs
,
429 .unlockfs
= jfs_unlockfs
,
430 .statfs
= jfs_statfs
,
431 .remount_fs
= jfs_remount
,
434 static struct export_operations jfs_export_operations
= {
435 .get_parent
= jfs_get_parent
,
438 static struct file_system_type jfs_fs_type
= {
439 .owner
= THIS_MODULE
,
441 .get_sb
= jfs_get_sb
,
442 .kill_sb
= kill_block_super
,
443 .fs_flags
= FS_REQUIRES_DEV
,
446 extern int metapage_init(void);
447 extern int txInit(void);
448 extern void txExit(void);
449 extern void metapage_exit(void);
451 static void init_once(void *foo
, kmem_cache_t
* cachep
, unsigned long flags
)
453 struct jfs_inode_info
*jfs_ip
= (struct jfs_inode_info
*) foo
;
455 if ((flags
& (SLAB_CTOR_VERIFY
| SLAB_CTOR_CONSTRUCTOR
)) ==
456 SLAB_CTOR_CONSTRUCTOR
) {
457 INIT_LIST_HEAD(&jfs_ip
->anon_inode_list
);
458 init_rwsem(&jfs_ip
->rdwrlock
);
459 init_MUTEX(&jfs_ip
->commit_sem
);
461 jfs_ip
->active_ag
= -1;
462 #ifdef CONFIG_JFS_POSIX_ACL
463 jfs_ip
->i_acl
= JFS_ACL_NOT_CACHED
;
464 jfs_ip
->i_default_acl
= JFS_ACL_NOT_CACHED
;
466 inode_init_once(&jfs_ip
->vfs_inode
);
470 static int __init
init_jfs_fs(void)
475 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info
), 0,
476 SLAB_RECLAIM_ACCOUNT
, init_once
, NULL
);
477 if (jfs_inode_cachep
== NULL
)
481 * Metapage initialization
483 rc
= metapage_init();
485 jfs_err("metapage_init failed w/rc = %d", rc
);
490 * Transaction Manager initialization
494 jfs_err("txInit failed w/rc = %d", rc
);
499 * I/O completion thread (endio)
501 jfsIOthread
= kernel_thread(jfsIOWait
, 0,
502 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
503 if (jfsIOthread
< 0) {
504 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread
);
507 wait_for_completion(&jfsIOwait
); /* Wait until thread starts */
509 jfsCommitThread
= kernel_thread(jfs_lazycommit
, 0,
510 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
511 if (jfsCommitThread
< 0) {
512 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsCommitThread
);
515 wait_for_completion(&jfsIOwait
); /* Wait until thread starts */
517 jfsSyncThread
= kernel_thread(jfs_sync
, 0,
518 CLONE_FS
| CLONE_FILES
| CLONE_SIGHAND
);
519 if (jfsSyncThread
< 0) {
520 jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread
);
521 goto kill_committask
;
523 wait_for_completion(&jfsIOwait
); /* Wait until thread starts */
529 return register_filesystem(&jfs_fs_type
);
532 jfs_stop_threads
= 1;
533 wake_up(&jfs_commit_thread_wait
);
534 wait_for_completion(&jfsIOwait
); /* Wait for thread exit */
536 jfs_stop_threads
= 1;
537 wake_up(&jfs_IO_thread_wait
);
538 wait_for_completion(&jfsIOwait
); /* Wait for thread exit */
544 kmem_cache_destroy(jfs_inode_cachep
);
548 static void __exit
exit_jfs_fs(void)
550 jfs_info("exit_jfs_fs called");
552 jfs_stop_threads
= 1;
555 wake_up(&jfs_IO_thread_wait
);
556 wait_for_completion(&jfsIOwait
); /* Wait until IO thread exits */
557 wake_up(&jfs_commit_thread_wait
);
558 wait_for_completion(&jfsIOwait
); /* Wait until Commit thread exits */
559 wake_up(&jfs_sync_thread_wait
);
560 wait_for_completion(&jfsIOwait
); /* Wait until Sync thread exits */
564 unregister_filesystem(&jfs_fs_type
);
565 kmem_cache_destroy(jfs_inode_cachep
);
568 module_init(init_jfs_fs
)
569 module_exit(exit_jfs_fs
)