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