Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) International Business Machines Corp., 2000-2004 |
| 3 | * Portions Copyright (C) Christoph Hellwig, 2001-2002 |
| 4 | * |
| 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. |
| 14 | * |
| 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 |
| 18 | */ |
| 19 | |
| 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 <asm/uaccess.h> |
| 28 | |
| 29 | #include "jfs_incore.h" |
| 30 | #include "jfs_filsys.h" |
| 31 | #include "jfs_metapage.h" |
| 32 | #include "jfs_superblock.h" |
| 33 | #include "jfs_dmap.h" |
| 34 | #include "jfs_imap.h" |
| 35 | #include "jfs_acl.h" |
| 36 | #include "jfs_debug.h" |
| 37 | |
| 38 | MODULE_DESCRIPTION("The Journaled Filesystem (JFS)"); |
| 39 | MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | static kmem_cache_t * jfs_inode_cachep; |
| 43 | |
| 44 | static struct super_operations jfs_super_operations; |
| 45 | static struct export_operations jfs_export_operations; |
| 46 | static struct file_system_type jfs_fs_type; |
| 47 | |
| 48 | #define MAX_COMMIT_THREADS 64 |
| 49 | static int commit_threads = 0; |
| 50 | module_param(commit_threads, int, 0); |
| 51 | MODULE_PARM_DESC(commit_threads, "Number of commit threads"); |
| 52 | |
| 53 | int jfs_stop_threads; |
| 54 | static pid_t jfsIOthread; |
| 55 | static pid_t jfsCommitThread[MAX_COMMIT_THREADS]; |
| 56 | static pid_t jfsSyncThread; |
| 57 | DECLARE_COMPLETION(jfsIOwait); |
| 58 | |
| 59 | #ifdef CONFIG_JFS_DEBUG |
| 60 | int jfsloglevel = JFS_LOGLEVEL_WARN; |
| 61 | module_param(jfsloglevel, int, 0644); |
| 62 | MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)"); |
| 63 | #endif |
| 64 | |
| 65 | /* |
| 66 | * External declarations |
| 67 | */ |
| 68 | extern int jfs_mount(struct super_block *); |
| 69 | extern int jfs_mount_rw(struct super_block *, int); |
| 70 | extern int jfs_umount(struct super_block *); |
| 71 | extern int jfs_umount_rw(struct super_block *); |
| 72 | |
| 73 | extern int jfsIOWait(void *); |
| 74 | extern int jfs_lazycommit(void *); |
| 75 | extern int jfs_sync(void *); |
| 76 | |
| 77 | extern void jfs_read_inode(struct inode *inode); |
| 78 | extern void jfs_dirty_inode(struct inode *inode); |
| 79 | extern void jfs_delete_inode(struct inode *inode); |
| 80 | extern int jfs_write_inode(struct inode *inode, int wait); |
| 81 | |
| 82 | extern struct dentry *jfs_get_parent(struct dentry *dentry); |
| 83 | extern int jfs_extendfs(struct super_block *, s64, int); |
| 84 | |
| 85 | extern struct dentry_operations jfs_ci_dentry_operations; |
| 86 | |
| 87 | #ifdef PROC_FS_JFS /* see jfs_debug.h */ |
| 88 | extern void jfs_proc_init(void); |
| 89 | extern void jfs_proc_clean(void); |
| 90 | #endif |
| 91 | |
| 92 | extern wait_queue_head_t jfs_IO_thread_wait; |
| 93 | extern wait_queue_head_t jfs_commit_thread_wait; |
| 94 | extern wait_queue_head_t jfs_sync_thread_wait; |
| 95 | |
| 96 | static void jfs_handle_error(struct super_block *sb) |
| 97 | { |
| 98 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 99 | |
| 100 | if (sb->s_flags & MS_RDONLY) |
| 101 | return; |
| 102 | |
| 103 | updateSuper(sb, FM_DIRTY); |
| 104 | |
| 105 | if (sbi->flag & JFS_ERR_PANIC) |
| 106 | panic("JFS (device %s): panic forced after error\n", |
| 107 | sb->s_id); |
| 108 | else if (sbi->flag & JFS_ERR_REMOUNT_RO) { |
| 109 | jfs_err("ERROR: (device %s): remounting filesystem " |
| 110 | "as read-only\n", |
| 111 | sb->s_id); |
| 112 | sb->s_flags |= MS_RDONLY; |
| 113 | } |
| 114 | |
| 115 | /* nothing is done for continue beyond marking the superblock dirty */ |
| 116 | } |
| 117 | |
| 118 | void jfs_error(struct super_block *sb, const char * function, ...) |
| 119 | { |
| 120 | static char error_buf[256]; |
| 121 | va_list args; |
| 122 | |
| 123 | va_start(args, function); |
| 124 | vsprintf(error_buf, function, args); |
| 125 | va_end(args); |
| 126 | |
| 127 | printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf); |
| 128 | |
| 129 | jfs_handle_error(sb); |
| 130 | } |
| 131 | |
| 132 | static struct inode *jfs_alloc_inode(struct super_block *sb) |
| 133 | { |
| 134 | struct jfs_inode_info *jfs_inode; |
| 135 | |
| 136 | jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS); |
| 137 | if (!jfs_inode) |
| 138 | return NULL; |
| 139 | return &jfs_inode->vfs_inode; |
| 140 | } |
| 141 | |
| 142 | static void jfs_destroy_inode(struct inode *inode) |
| 143 | { |
| 144 | struct jfs_inode_info *ji = JFS_IP(inode); |
| 145 | |
| 146 | spin_lock_irq(&ji->ag_lock); |
| 147 | if (ji->active_ag != -1) { |
| 148 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; |
| 149 | atomic_dec(&bmap->db_active[ji->active_ag]); |
| 150 | ji->active_ag = -1; |
| 151 | } |
| 152 | spin_unlock_irq(&ji->ag_lock); |
| 153 | |
| 154 | #ifdef CONFIG_JFS_POSIX_ACL |
| 155 | if (ji->i_acl != JFS_ACL_NOT_CACHED) { |
| 156 | posix_acl_release(ji->i_acl); |
| 157 | ji->i_acl = JFS_ACL_NOT_CACHED; |
| 158 | } |
| 159 | if (ji->i_default_acl != JFS_ACL_NOT_CACHED) { |
| 160 | posix_acl_release(ji->i_default_acl); |
| 161 | ji->i_default_acl = JFS_ACL_NOT_CACHED; |
| 162 | } |
| 163 | #endif |
| 164 | |
| 165 | kmem_cache_free(jfs_inode_cachep, ji); |
| 166 | } |
| 167 | |
| 168 | static int jfs_statfs(struct super_block *sb, struct kstatfs *buf) |
| 169 | { |
| 170 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 171 | s64 maxinodes; |
| 172 | struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap; |
| 173 | |
| 174 | jfs_info("In jfs_statfs"); |
| 175 | buf->f_type = JFS_SUPER_MAGIC; |
| 176 | buf->f_bsize = sbi->bsize; |
| 177 | buf->f_blocks = sbi->bmap->db_mapsize; |
| 178 | buf->f_bfree = sbi->bmap->db_nfree; |
| 179 | buf->f_bavail = sbi->bmap->db_nfree; |
| 180 | /* |
| 181 | * If we really return the number of allocated & free inodes, some |
| 182 | * applications will fail because they won't see enough free inodes. |
| 183 | * We'll try to calculate some guess as to how may inodes we can |
| 184 | * really allocate |
| 185 | * |
| 186 | * buf->f_files = atomic_read(&imap->im_numinos); |
| 187 | * buf->f_ffree = atomic_read(&imap->im_numfree); |
| 188 | */ |
| 189 | maxinodes = min((s64) atomic_read(&imap->im_numinos) + |
| 190 | ((sbi->bmap->db_nfree >> imap->im_l2nbperiext) |
| 191 | << L2INOSPEREXT), (s64) 0xffffffffLL); |
| 192 | buf->f_files = maxinodes; |
| 193 | buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - |
| 194 | atomic_read(&imap->im_numfree)); |
| 195 | |
| 196 | buf->f_namelen = JFS_NAME_MAX; |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static void jfs_put_super(struct super_block *sb) |
| 201 | { |
| 202 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 203 | int rc; |
| 204 | |
| 205 | jfs_info("In jfs_put_super"); |
| 206 | rc = jfs_umount(sb); |
| 207 | if (rc) |
| 208 | jfs_err("jfs_umount failed with return code %d", rc); |
| 209 | if (sbi->nls_tab) |
| 210 | unload_nls(sbi->nls_tab); |
| 211 | sbi->nls_tab = NULL; |
| 212 | |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 213 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
| 214 | iput(sbi->direct_inode); |
| 215 | sbi->direct_inode = NULL; |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | kfree(sbi); |
| 218 | } |
| 219 | |
| 220 | enum { |
| 221 | Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, |
| 222 | Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, |
| 223 | }; |
| 224 | |
| 225 | static match_table_t tokens = { |
| 226 | {Opt_integrity, "integrity"}, |
| 227 | {Opt_nointegrity, "nointegrity"}, |
| 228 | {Opt_iocharset, "iocharset=%s"}, |
| 229 | {Opt_resize, "resize=%u"}, |
| 230 | {Opt_resize_nosize, "resize"}, |
| 231 | {Opt_errors, "errors=%s"}, |
| 232 | {Opt_ignore, "noquota"}, |
| 233 | {Opt_ignore, "quota"}, |
| 234 | {Opt_ignore, "usrquota"}, |
| 235 | {Opt_ignore, "grpquota"}, |
| 236 | {Opt_err, NULL} |
| 237 | }; |
| 238 | |
| 239 | static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, |
| 240 | int *flag) |
| 241 | { |
| 242 | void *nls_map = (void *)-1; /* -1: no change; NULL: none */ |
| 243 | char *p; |
| 244 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 245 | |
| 246 | *newLVSize = 0; |
| 247 | |
| 248 | if (!options) |
| 249 | return 1; |
| 250 | |
| 251 | while ((p = strsep(&options, ",")) != NULL) { |
| 252 | substring_t args[MAX_OPT_ARGS]; |
| 253 | int token; |
| 254 | if (!*p) |
| 255 | continue; |
| 256 | |
| 257 | token = match_token(p, tokens, args); |
| 258 | switch (token) { |
| 259 | case Opt_integrity: |
| 260 | *flag &= ~JFS_NOINTEGRITY; |
| 261 | break; |
| 262 | case Opt_nointegrity: |
| 263 | *flag |= JFS_NOINTEGRITY; |
| 264 | break; |
| 265 | case Opt_ignore: |
| 266 | /* Silently ignore the quota options */ |
| 267 | /* Don't do anything ;-) */ |
| 268 | break; |
| 269 | case Opt_iocharset: |
| 270 | if (nls_map && nls_map != (void *) -1) |
| 271 | unload_nls(nls_map); |
| 272 | if (!strcmp(args[0].from, "none")) |
| 273 | nls_map = NULL; |
| 274 | else { |
| 275 | nls_map = load_nls(args[0].from); |
| 276 | if (!nls_map) { |
| 277 | printk(KERN_ERR |
| 278 | "JFS: charset not found\n"); |
| 279 | goto cleanup; |
| 280 | } |
| 281 | } |
| 282 | break; |
| 283 | case Opt_resize: |
| 284 | { |
| 285 | char *resize = args[0].from; |
| 286 | *newLVSize = simple_strtoull(resize, &resize, 0); |
| 287 | break; |
| 288 | } |
| 289 | case Opt_resize_nosize: |
| 290 | { |
| 291 | *newLVSize = sb->s_bdev->bd_inode->i_size >> |
| 292 | sb->s_blocksize_bits; |
| 293 | if (*newLVSize == 0) |
| 294 | printk(KERN_ERR |
| 295 | "JFS: Cannot determine volume size\n"); |
| 296 | break; |
| 297 | } |
| 298 | case Opt_errors: |
| 299 | { |
| 300 | char *errors = args[0].from; |
| 301 | if (!errors || !*errors) |
| 302 | goto cleanup; |
| 303 | if (!strcmp(errors, "continue")) { |
| 304 | *flag &= ~JFS_ERR_REMOUNT_RO; |
| 305 | *flag &= ~JFS_ERR_PANIC; |
| 306 | *flag |= JFS_ERR_CONTINUE; |
| 307 | } else if (!strcmp(errors, "remount-ro")) { |
| 308 | *flag &= ~JFS_ERR_CONTINUE; |
| 309 | *flag &= ~JFS_ERR_PANIC; |
| 310 | *flag |= JFS_ERR_REMOUNT_RO; |
| 311 | } else if (!strcmp(errors, "panic")) { |
| 312 | *flag &= ~JFS_ERR_CONTINUE; |
| 313 | *flag &= ~JFS_ERR_REMOUNT_RO; |
| 314 | *flag |= JFS_ERR_PANIC; |
| 315 | } else { |
| 316 | printk(KERN_ERR |
| 317 | "JFS: %s is an invalid error handler\n", |
| 318 | errors); |
| 319 | goto cleanup; |
| 320 | } |
| 321 | break; |
| 322 | } |
| 323 | default: |
| 324 | printk("jfs: Unrecognized mount option \"%s\" " |
| 325 | " or missing value\n", p); |
| 326 | goto cleanup; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | if (nls_map != (void *) -1) { |
| 331 | /* Discard old (if remount) */ |
| 332 | if (sbi->nls_tab) |
| 333 | unload_nls(sbi->nls_tab); |
| 334 | sbi->nls_tab = nls_map; |
| 335 | } |
| 336 | return 1; |
| 337 | |
| 338 | cleanup: |
| 339 | if (nls_map && nls_map != (void *) -1) |
| 340 | unload_nls(nls_map); |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | static int jfs_remount(struct super_block *sb, int *flags, char *data) |
| 345 | { |
| 346 | s64 newLVSize = 0; |
| 347 | int rc = 0; |
| 348 | int flag = JFS_SBI(sb)->flag; |
| 349 | |
| 350 | if (!parse_options(data, sb, &newLVSize, &flag)) { |
| 351 | return -EINVAL; |
| 352 | } |
| 353 | if (newLVSize) { |
| 354 | if (sb->s_flags & MS_RDONLY) { |
| 355 | printk(KERN_ERR |
| 356 | "JFS: resize requires volume to be mounted read-write\n"); |
| 357 | return -EROFS; |
| 358 | } |
| 359 | rc = jfs_extendfs(sb, newLVSize, 0); |
| 360 | if (rc) |
| 361 | return rc; |
| 362 | } |
| 363 | |
| 364 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 365 | /* |
| 366 | * Invalidate any previously read metadata. fsck may have |
| 367 | * changed the on-disk data since we mounted r/o |
| 368 | */ |
| 369 | truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0); |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | JFS_SBI(sb)->flag = flag; |
| 372 | return jfs_mount_rw(sb, 1); |
| 373 | } |
| 374 | if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) { |
| 375 | rc = jfs_umount_rw(sb); |
| 376 | JFS_SBI(sb)->flag = flag; |
| 377 | return rc; |
| 378 | } |
| 379 | if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) |
| 380 | if (!(sb->s_flags & MS_RDONLY)) { |
| 381 | rc = jfs_umount_rw(sb); |
| 382 | if (rc) |
| 383 | return rc; |
| 384 | JFS_SBI(sb)->flag = flag; |
| 385 | return jfs_mount_rw(sb, 1); |
| 386 | } |
| 387 | JFS_SBI(sb)->flag = flag; |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int jfs_fill_super(struct super_block *sb, void *data, int silent) |
| 393 | { |
| 394 | struct jfs_sb_info *sbi; |
| 395 | struct inode *inode; |
| 396 | int rc; |
| 397 | s64 newLVSize = 0; |
| 398 | int flag; |
| 399 | |
| 400 | jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); |
| 401 | |
| 402 | if (!new_valid_dev(sb->s_bdev->bd_dev)) |
| 403 | return -EOVERFLOW; |
| 404 | |
| 405 | sbi = kmalloc(sizeof (struct jfs_sb_info), GFP_KERNEL); |
| 406 | if (!sbi) |
| 407 | return -ENOSPC; |
| 408 | memset(sbi, 0, sizeof (struct jfs_sb_info)); |
| 409 | sb->s_fs_info = sbi; |
| 410 | sbi->sb = sb; |
| 411 | |
| 412 | /* initialize the mount flag and determine the default error handler */ |
| 413 | flag = JFS_ERR_REMOUNT_RO; |
| 414 | |
| 415 | if (!parse_options((char *) data, sb, &newLVSize, &flag)) { |
| 416 | kfree(sbi); |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | sbi->flag = flag; |
| 420 | |
| 421 | #ifdef CONFIG_JFS_POSIX_ACL |
| 422 | sb->s_flags |= MS_POSIXACL; |
| 423 | #endif |
| 424 | |
| 425 | if (newLVSize) { |
| 426 | printk(KERN_ERR "resize option for remount only\n"); |
| 427 | return -EINVAL; |
| 428 | } |
| 429 | |
| 430 | /* |
| 431 | * Initialize blocksize to 4K. |
| 432 | */ |
| 433 | sb_set_blocksize(sb, PSIZE); |
| 434 | |
| 435 | /* |
| 436 | * Set method vectors. |
| 437 | */ |
| 438 | sb->s_op = &jfs_super_operations; |
| 439 | sb->s_export_op = &jfs_export_operations; |
| 440 | |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 441 | /* |
| 442 | * Initialize direct-mapping inode/address-space |
| 443 | */ |
| 444 | inode = new_inode(sb); |
| 445 | if (inode == NULL) |
| 446 | goto out_kfree; |
| 447 | inode->i_ino = 0; |
| 448 | inode->i_nlink = 1; |
| 449 | inode->i_size = sb->s_bdev->bd_inode->i_size; |
| 450 | inode->i_mapping->a_ops = &jfs_metapage_aops; |
| 451 | mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); |
| 452 | |
| 453 | sbi->direct_inode = inode; |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | rc = jfs_mount(sb); |
| 456 | if (rc) { |
| 457 | if (!silent) { |
| 458 | jfs_err("jfs_mount failed w/return code = %d", rc); |
| 459 | } |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 460 | goto out_mount_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | if (sb->s_flags & MS_RDONLY) |
| 463 | sbi->log = NULL; |
| 464 | else { |
| 465 | rc = jfs_mount_rw(sb, 0); |
| 466 | if (rc) { |
| 467 | if (!silent) { |
| 468 | jfs_err("jfs_mount_rw failed, return code = %d", |
| 469 | rc); |
| 470 | } |
| 471 | goto out_no_rw; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | sb->s_magic = JFS_SUPER_MAGIC; |
| 476 | |
| 477 | inode = iget(sb, ROOT_I); |
| 478 | if (!inode || is_bad_inode(inode)) |
| 479 | goto out_no_root; |
| 480 | sb->s_root = d_alloc_root(inode); |
| 481 | if (!sb->s_root) |
| 482 | goto out_no_root; |
| 483 | |
| 484 | if (sbi->mntflag & JFS_OS2) |
| 485 | sb->s_root->d_op = &jfs_ci_dentry_operations; |
| 486 | |
| 487 | /* logical blocks are represented by 40 bits in pxd_t, etc. */ |
| 488 | sb->s_maxbytes = ((u64) sb->s_blocksize) << 40; |
| 489 | #if BITS_PER_LONG == 32 |
| 490 | /* |
| 491 | * Page cache is indexed by long. |
| 492 | * I would use MAX_LFS_FILESIZE, but it's only half as big |
| 493 | */ |
| 494 | sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes); |
| 495 | #endif |
| 496 | sb->s_time_gran = 1; |
| 497 | return 0; |
| 498 | |
| 499 | out_no_root: |
| 500 | jfs_err("jfs_read_super: get root inode failed"); |
| 501 | if (inode) |
| 502 | iput(inode); |
| 503 | |
| 504 | out_no_rw: |
| 505 | rc = jfs_umount(sb); |
| 506 | if (rc) { |
| 507 | jfs_err("jfs_umount failed with return code %d", rc); |
| 508 | } |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 509 | out_mount_failed: |
| 510 | filemap_fdatawrite(sbi->direct_inode->i_mapping); |
| 511 | filemap_fdatawait(sbi->direct_inode->i_mapping); |
| 512 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
| 513 | make_bad_inode(sbi->direct_inode); |
| 514 | iput(sbi->direct_inode); |
| 515 | sbi->direct_inode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | out_kfree: |
| 517 | if (sbi->nls_tab) |
| 518 | unload_nls(sbi->nls_tab); |
| 519 | kfree(sbi); |
| 520 | return -EINVAL; |
| 521 | } |
| 522 | |
| 523 | static void jfs_write_super_lockfs(struct super_block *sb) |
| 524 | { |
| 525 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 526 | struct jfs_log *log = sbi->log; |
| 527 | |
| 528 | if (!(sb->s_flags & MS_RDONLY)) { |
| 529 | txQuiesce(sb); |
| 530 | lmLogShutdown(log); |
| 531 | updateSuper(sb, FM_CLEAN); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static void jfs_unlockfs(struct super_block *sb) |
| 536 | { |
| 537 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 538 | struct jfs_log *log = sbi->log; |
| 539 | int rc = 0; |
| 540 | |
| 541 | if (!(sb->s_flags & MS_RDONLY)) { |
| 542 | updateSuper(sb, FM_MOUNT); |
| 543 | if ((rc = lmLogInit(log))) |
| 544 | jfs_err("jfs_unlock failed with return code %d", rc); |
| 545 | else |
| 546 | txResume(sb); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | static struct super_block *jfs_get_sb(struct file_system_type *fs_type, |
| 551 | int flags, const char *dev_name, void *data) |
| 552 | { |
| 553 | return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super); |
| 554 | } |
| 555 | |
| 556 | static int jfs_sync_fs(struct super_block *sb, int wait) |
| 557 | { |
| 558 | struct jfs_log *log = JFS_SBI(sb)->log; |
| 559 | |
| 560 | /* log == NULL indicates read-only mount */ |
Dave Kleikamp | 1c62782 | 2005-05-02 12:25:08 -0600 | [diff] [blame] | 561 | if (log) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | jfs_flush_journal(log, wait); |
Dave Kleikamp | 1c62782 | 2005-05-02 12:25:08 -0600 | [diff] [blame] | 563 | jfs_syncpt(log); |
| 564 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | static struct super_operations jfs_super_operations = { |
| 570 | .alloc_inode = jfs_alloc_inode, |
| 571 | .destroy_inode = jfs_destroy_inode, |
| 572 | .read_inode = jfs_read_inode, |
| 573 | .dirty_inode = jfs_dirty_inode, |
| 574 | .write_inode = jfs_write_inode, |
| 575 | .delete_inode = jfs_delete_inode, |
| 576 | .put_super = jfs_put_super, |
| 577 | .sync_fs = jfs_sync_fs, |
| 578 | .write_super_lockfs = jfs_write_super_lockfs, |
| 579 | .unlockfs = jfs_unlockfs, |
| 580 | .statfs = jfs_statfs, |
| 581 | .remount_fs = jfs_remount, |
| 582 | }; |
| 583 | |
| 584 | static struct export_operations jfs_export_operations = { |
| 585 | .get_parent = jfs_get_parent, |
| 586 | }; |
| 587 | |
| 588 | static struct file_system_type jfs_fs_type = { |
| 589 | .owner = THIS_MODULE, |
| 590 | .name = "jfs", |
| 591 | .get_sb = jfs_get_sb, |
| 592 | .kill_sb = kill_block_super, |
| 593 | .fs_flags = FS_REQUIRES_DEV, |
| 594 | }; |
| 595 | |
| 596 | extern int metapage_init(void); |
| 597 | extern int txInit(void); |
| 598 | extern void txExit(void); |
| 599 | extern void metapage_exit(void); |
| 600 | |
| 601 | static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags) |
| 602 | { |
| 603 | struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo; |
| 604 | |
| 605 | if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) == |
| 606 | SLAB_CTOR_CONSTRUCTOR) { |
| 607 | memset(jfs_ip, 0, sizeof(struct jfs_inode_info)); |
| 608 | INIT_LIST_HEAD(&jfs_ip->anon_inode_list); |
| 609 | init_rwsem(&jfs_ip->rdwrlock); |
| 610 | init_MUTEX(&jfs_ip->commit_sem); |
| 611 | init_rwsem(&jfs_ip->xattr_sem); |
| 612 | spin_lock_init(&jfs_ip->ag_lock); |
| 613 | jfs_ip->active_ag = -1; |
| 614 | #ifdef CONFIG_JFS_POSIX_ACL |
| 615 | jfs_ip->i_acl = JFS_ACL_NOT_CACHED; |
| 616 | jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED; |
| 617 | #endif |
| 618 | inode_init_once(&jfs_ip->vfs_inode); |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | static int __init init_jfs_fs(void) |
| 623 | { |
| 624 | int i; |
| 625 | int rc; |
| 626 | |
| 627 | jfs_inode_cachep = |
| 628 | kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0, |
| 629 | SLAB_RECLAIM_ACCOUNT, init_once, NULL); |
| 630 | if (jfs_inode_cachep == NULL) |
| 631 | return -ENOMEM; |
| 632 | |
| 633 | /* |
| 634 | * Metapage initialization |
| 635 | */ |
| 636 | rc = metapage_init(); |
| 637 | if (rc) { |
| 638 | jfs_err("metapage_init failed w/rc = %d", rc); |
| 639 | goto free_slab; |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | * Transaction Manager initialization |
| 644 | */ |
| 645 | rc = txInit(); |
| 646 | if (rc) { |
| 647 | jfs_err("txInit failed w/rc = %d", rc); |
| 648 | goto free_metapage; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * I/O completion thread (endio) |
| 653 | */ |
| 654 | jfsIOthread = kernel_thread(jfsIOWait, NULL, CLONE_KERNEL); |
| 655 | if (jfsIOthread < 0) { |
| 656 | jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsIOthread); |
| 657 | goto end_txmngr; |
| 658 | } |
| 659 | wait_for_completion(&jfsIOwait); /* Wait until thread starts */ |
| 660 | |
| 661 | if (commit_threads < 1) |
| 662 | commit_threads = num_online_cpus(); |
| 663 | if (commit_threads > MAX_COMMIT_THREADS) |
| 664 | commit_threads = MAX_COMMIT_THREADS; |
| 665 | |
| 666 | for (i = 0; i < commit_threads; i++) { |
| 667 | jfsCommitThread[i] = kernel_thread(jfs_lazycommit, NULL, |
| 668 | CLONE_KERNEL); |
| 669 | if (jfsCommitThread[i] < 0) { |
| 670 | jfs_err("init_jfs_fs: fork failed w/rc = %d", |
| 671 | jfsCommitThread[i]); |
| 672 | commit_threads = i; |
| 673 | goto kill_committask; |
| 674 | } |
| 675 | /* Wait until thread starts */ |
| 676 | wait_for_completion(&jfsIOwait); |
| 677 | } |
| 678 | |
| 679 | jfsSyncThread = kernel_thread(jfs_sync, NULL, CLONE_KERNEL); |
| 680 | if (jfsSyncThread < 0) { |
| 681 | jfs_err("init_jfs_fs: fork failed w/rc = %d", jfsSyncThread); |
| 682 | goto kill_committask; |
| 683 | } |
| 684 | wait_for_completion(&jfsIOwait); /* Wait until thread starts */ |
| 685 | |
| 686 | #ifdef PROC_FS_JFS |
| 687 | jfs_proc_init(); |
| 688 | #endif |
| 689 | |
| 690 | return register_filesystem(&jfs_fs_type); |
| 691 | |
| 692 | kill_committask: |
| 693 | jfs_stop_threads = 1; |
| 694 | wake_up_all(&jfs_commit_thread_wait); |
| 695 | for (i = 0; i < commit_threads; i++) |
| 696 | wait_for_completion(&jfsIOwait); |
| 697 | |
| 698 | wake_up(&jfs_IO_thread_wait); |
| 699 | wait_for_completion(&jfsIOwait); /* Wait for thread exit */ |
| 700 | end_txmngr: |
| 701 | txExit(); |
| 702 | free_metapage: |
| 703 | metapage_exit(); |
| 704 | free_slab: |
| 705 | kmem_cache_destroy(jfs_inode_cachep); |
| 706 | return rc; |
| 707 | } |
| 708 | |
| 709 | static void __exit exit_jfs_fs(void) |
| 710 | { |
| 711 | int i; |
| 712 | |
| 713 | jfs_info("exit_jfs_fs called"); |
| 714 | |
| 715 | jfs_stop_threads = 1; |
| 716 | txExit(); |
| 717 | metapage_exit(); |
| 718 | wake_up(&jfs_IO_thread_wait); |
| 719 | wait_for_completion(&jfsIOwait); /* Wait until IO thread exits */ |
| 720 | wake_up_all(&jfs_commit_thread_wait); |
| 721 | for (i = 0; i < commit_threads; i++) |
| 722 | wait_for_completion(&jfsIOwait); |
| 723 | wake_up(&jfs_sync_thread_wait); |
| 724 | wait_for_completion(&jfsIOwait); /* Wait until Sync thread exits */ |
| 725 | #ifdef PROC_FS_JFS |
| 726 | jfs_proc_clean(); |
| 727 | #endif |
| 728 | unregister_filesystem(&jfs_fs_type); |
| 729 | kmem_cache_destroy(jfs_inode_cachep); |
| 730 | } |
| 731 | |
| 732 | module_init(init_jfs_fs) |
| 733 | module_exit(exit_jfs_fs) |