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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 7 | * the Free Software Foundation; either version 2 of the License, or |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * (at your option) any later version. |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 16 | * along with this program; if not, write to the Free Software |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
| 20 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/parser.h> |
| 23 | #include <linux/completion.h> |
| 24 | #include <linux/vfs.h> |
Jan Kara | 74abb98 | 2008-07-25 01:46:51 -0700 | [diff] [blame] | 25 | #include <linux/quotaops.h> |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 26 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/moduleparam.h> |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 28 | #include <linux/kthread.h> |
Christoph Hellwig | 9a59f45 | 2005-06-23 00:10:19 -0700 | [diff] [blame] | 29 | #include <linux/posix_acl.h> |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 30 | #include <linux/buffer_head.h> |
Christoph Hellwig | a569425 | 2007-07-17 04:04:28 -0700 | [diff] [blame] | 31 | #include <linux/exportfs.h> |
Coly Li | b5c816a | 2009-01-21 00:05:39 +0800 | [diff] [blame] | 32 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/uaccess.h> |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 35 | #include <linux/seq_file.h> |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 36 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include "jfs_incore.h" |
| 39 | #include "jfs_filsys.h" |
Dave Kleikamp | 1868f4a | 2005-05-04 15:29:35 -0500 | [diff] [blame] | 40 | #include "jfs_inode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "jfs_metapage.h" |
| 42 | #include "jfs_superblock.h" |
| 43 | #include "jfs_dmap.h" |
| 44 | #include "jfs_imap.h" |
| 45 | #include "jfs_acl.h" |
| 46 | #include "jfs_debug.h" |
| 47 | |
| 48 | MODULE_DESCRIPTION("The Journaled Filesystem (JFS)"); |
| 49 | MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM"); |
| 50 | MODULE_LICENSE("GPL"); |
| 51 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 52 | static struct kmem_cache * jfs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 54 | static const struct super_operations jfs_super_operations; |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 55 | static const struct export_operations jfs_export_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static struct file_system_type jfs_fs_type; |
| 57 | |
| 58 | #define MAX_COMMIT_THREADS 64 |
| 59 | static int commit_threads = 0; |
| 60 | module_param(commit_threads, int, 0); |
| 61 | MODULE_PARM_DESC(commit_threads, "Number of commit threads"); |
| 62 | |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 63 | static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS]; |
| 64 | struct task_struct *jfsIOthread; |
| 65 | struct task_struct *jfsSyncThread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_JFS_DEBUG |
| 68 | int jfsloglevel = JFS_LOGLEVEL_WARN; |
| 69 | module_param(jfsloglevel, int, 0644); |
| 70 | MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)"); |
| 71 | #endif |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static void jfs_handle_error(struct super_block *sb) |
| 74 | { |
| 75 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 76 | |
| 77 | if (sb->s_flags & MS_RDONLY) |
| 78 | return; |
| 79 | |
| 80 | updateSuper(sb, FM_DIRTY); |
| 81 | |
| 82 | if (sbi->flag & JFS_ERR_PANIC) |
| 83 | panic("JFS (device %s): panic forced after error\n", |
| 84 | sb->s_id); |
| 85 | else if (sbi->flag & JFS_ERR_REMOUNT_RO) { |
| 86 | jfs_err("ERROR: (device %s): remounting filesystem " |
| 87 | "as read-only\n", |
| 88 | sb->s_id); |
| 89 | sb->s_flags |= MS_RDONLY; |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | /* nothing is done for continue beyond marking the superblock dirty */ |
| 93 | } |
| 94 | |
| 95 | void jfs_error(struct super_block *sb, const char * function, ...) |
| 96 | { |
| 97 | static char error_buf[256]; |
| 98 | va_list args; |
| 99 | |
| 100 | va_start(args, function); |
Alexey Dobriyan | 4a6e617 | 2006-12-06 20:37:04 -0800 | [diff] [blame] | 101 | vsnprintf(error_buf, sizeof(error_buf), function, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | va_end(args); |
| 103 | |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 104 | pr_err("ERROR: (device %s): %s\n", sb->s_id, error_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | jfs_handle_error(sb); |
| 107 | } |
| 108 | |
| 109 | static struct inode *jfs_alloc_inode(struct super_block *sb) |
| 110 | { |
| 111 | struct jfs_inode_info *jfs_inode; |
| 112 | |
| 113 | jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS); |
| 114 | if (!jfs_inode) |
| 115 | return NULL; |
| 116 | return &jfs_inode->vfs_inode; |
| 117 | } |
| 118 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 119 | static void jfs_i_callback(struct rcu_head *head) |
| 120 | { |
| 121 | struct inode *inode = container_of(head, struct inode, i_rcu); |
| 122 | struct jfs_inode_info *ji = JFS_IP(inode); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 123 | kmem_cache_free(jfs_inode_cachep, ji); |
| 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | static void jfs_destroy_inode(struct inode *inode) |
| 127 | { |
| 128 | struct jfs_inode_info *ji = JFS_IP(inode); |
| 129 | |
Dave Kleikamp | 8a9cd6d | 2005-08-10 11:14:39 -0500 | [diff] [blame] | 130 | BUG_ON(!list_empty(&ji->anon_inode_list)); |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | spin_lock_irq(&ji->ag_lock); |
| 133 | if (ji->active_ag != -1) { |
| 134 | struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; |
| 135 | atomic_dec(&bmap->db_active[ji->active_ag]); |
| 136 | ji->active_ag = -1; |
| 137 | } |
| 138 | spin_unlock_irq(&ji->ag_lock); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 139 | call_rcu(&inode->i_rcu, jfs_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 142 | static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 144 | struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | s64 maxinodes; |
| 146 | struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap; |
| 147 | |
| 148 | jfs_info("In jfs_statfs"); |
| 149 | buf->f_type = JFS_SUPER_MAGIC; |
| 150 | buf->f_bsize = sbi->bsize; |
| 151 | buf->f_blocks = sbi->bmap->db_mapsize; |
| 152 | buf->f_bfree = sbi->bmap->db_nfree; |
| 153 | buf->f_bavail = sbi->bmap->db_nfree; |
| 154 | /* |
| 155 | * If we really return the number of allocated & free inodes, some |
| 156 | * applications will fail because they won't see enough free inodes. |
Philippe De Muyter | 4de8027 | 2013-01-16 22:55:48 +0100 | [diff] [blame] | 157 | * We'll try to calculate some guess as to how many inodes we can |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | * really allocate |
| 159 | * |
| 160 | * buf->f_files = atomic_read(&imap->im_numinos); |
| 161 | * buf->f_ffree = atomic_read(&imap->im_numfree); |
| 162 | */ |
| 163 | maxinodes = min((s64) atomic_read(&imap->im_numinos) + |
| 164 | ((sbi->bmap->db_nfree >> imap->im_l2nbperiext) |
| 165 | << L2INOSPEREXT), (s64) 0xffffffffLL); |
| 166 | buf->f_files = maxinodes; |
| 167 | buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - |
| 168 | atomic_read(&imap->im_numfree)); |
Coly Li | b5c816a | 2009-01-21 00:05:39 +0800 | [diff] [blame] | 169 | buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2); |
| 170 | buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2, |
| 171 | sizeof(sbi->uuid)/2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | buf->f_namelen = JFS_NAME_MAX; |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static void jfs_put_super(struct super_block *sb) |
| 178 | { |
| 179 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 180 | int rc; |
| 181 | |
| 182 | jfs_info("In jfs_put_super"); |
Christoph Hellwig | 6cfd014 | 2009-05-05 15:40:36 +0200 | [diff] [blame] | 183 | |
Christoph Hellwig | e0ccfd9 | 2010-05-19 07:16:42 -0400 | [diff] [blame] | 184 | dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | rc = jfs_umount(sb); |
| 187 | if (rc) |
| 188 | jfs_err("jfs_umount failed with return code %d", rc); |
Thomas Gleixner | 6d729e4 | 2009-08-16 21:05:08 +0000 | [diff] [blame] | 189 | |
| 190 | unload_nls(sbi->nls_tab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 192 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
| 193 | iput(sbi->direct_inode); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | kfree(sbi); |
| 196 | } |
| 197 | |
| 198 | enum { |
| 199 | Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 200 | Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota, |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 201 | Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask, |
| 202 | Opt_discard, Opt_nodiscard, Opt_discard_minblk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 205 | static const match_table_t tokens = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | {Opt_integrity, "integrity"}, |
| 207 | {Opt_nointegrity, "nointegrity"}, |
| 208 | {Opt_iocharset, "iocharset=%s"}, |
| 209 | {Opt_resize, "resize=%u"}, |
| 210 | {Opt_resize_nosize, "resize"}, |
| 211 | {Opt_errors, "errors=%s"}, |
| 212 | {Opt_ignore, "noquota"}, |
| 213 | {Opt_ignore, "quota"}, |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 214 | {Opt_usrquota, "usrquota"}, |
| 215 | {Opt_grpquota, "grpquota"}, |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 216 | {Opt_uid, "uid=%u"}, |
| 217 | {Opt_gid, "gid=%u"}, |
| 218 | {Opt_umask, "umask=%u"}, |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 219 | {Opt_discard, "discard"}, |
| 220 | {Opt_nodiscard, "nodiscard"}, |
| 221 | {Opt_discard_minblk, "discard=%u"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | {Opt_err, NULL} |
| 223 | }; |
| 224 | |
| 225 | static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, |
| 226 | int *flag) |
| 227 | { |
| 228 | void *nls_map = (void *)-1; /* -1: no change; NULL: none */ |
| 229 | char *p; |
| 230 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 231 | |
| 232 | *newLVSize = 0; |
| 233 | |
| 234 | if (!options) |
| 235 | return 1; |
| 236 | |
| 237 | while ((p = strsep(&options, ",")) != NULL) { |
| 238 | substring_t args[MAX_OPT_ARGS]; |
| 239 | int token; |
| 240 | if (!*p) |
| 241 | continue; |
| 242 | |
| 243 | token = match_token(p, tokens, args); |
| 244 | switch (token) { |
| 245 | case Opt_integrity: |
| 246 | *flag &= ~JFS_NOINTEGRITY; |
| 247 | break; |
| 248 | case Opt_nointegrity: |
| 249 | *flag |= JFS_NOINTEGRITY; |
| 250 | break; |
| 251 | case Opt_ignore: |
| 252 | /* Silently ignore the quota options */ |
| 253 | /* Don't do anything ;-) */ |
| 254 | break; |
| 255 | case Opt_iocharset: |
| 256 | if (nls_map && nls_map != (void *) -1) |
| 257 | unload_nls(nls_map); |
| 258 | if (!strcmp(args[0].from, "none")) |
| 259 | nls_map = NULL; |
| 260 | else { |
| 261 | nls_map = load_nls(args[0].from); |
| 262 | if (!nls_map) { |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 263 | pr_err("JFS: charset not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | goto cleanup; |
| 265 | } |
| 266 | } |
| 267 | break; |
| 268 | case Opt_resize: |
| 269 | { |
| 270 | char *resize = args[0].from; |
| 271 | *newLVSize = simple_strtoull(resize, &resize, 0); |
| 272 | break; |
| 273 | } |
| 274 | case Opt_resize_nosize: |
| 275 | { |
| 276 | *newLVSize = sb->s_bdev->bd_inode->i_size >> |
| 277 | sb->s_blocksize_bits; |
| 278 | if (*newLVSize == 0) |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 279 | pr_err("JFS: Cannot determine volume size\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | case Opt_errors: |
| 283 | { |
| 284 | char *errors = args[0].from; |
| 285 | if (!errors || !*errors) |
| 286 | goto cleanup; |
| 287 | if (!strcmp(errors, "continue")) { |
| 288 | *flag &= ~JFS_ERR_REMOUNT_RO; |
| 289 | *flag &= ~JFS_ERR_PANIC; |
| 290 | *flag |= JFS_ERR_CONTINUE; |
| 291 | } else if (!strcmp(errors, "remount-ro")) { |
| 292 | *flag &= ~JFS_ERR_CONTINUE; |
| 293 | *flag &= ~JFS_ERR_PANIC; |
| 294 | *flag |= JFS_ERR_REMOUNT_RO; |
| 295 | } else if (!strcmp(errors, "panic")) { |
| 296 | *flag &= ~JFS_ERR_CONTINUE; |
| 297 | *flag &= ~JFS_ERR_REMOUNT_RO; |
| 298 | *flag |= JFS_ERR_PANIC; |
| 299 | } else { |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 300 | pr_err("JFS: %s is an invalid error handler\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | errors); |
| 302 | goto cleanup; |
| 303 | } |
| 304 | break; |
| 305 | } |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 306 | |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 307 | #ifdef CONFIG_QUOTA |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 308 | case Opt_quota: |
| 309 | case Opt_usrquota: |
| 310 | *flag |= JFS_USRQUOTA; |
| 311 | break; |
| 312 | case Opt_grpquota: |
| 313 | *flag |= JFS_GRPQUOTA; |
| 314 | break; |
| 315 | #else |
| 316 | case Opt_usrquota: |
| 317 | case Opt_grpquota: |
| 318 | case Opt_quota: |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 319 | pr_err("JFS: quota operations not supported\n"); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 320 | break; |
| 321 | #endif |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 322 | case Opt_uid: |
| 323 | { |
| 324 | char *uid = args[0].from; |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 325 | uid_t val = simple_strtoul(uid, &uid, 0); |
| 326 | sbi->uid = make_kuid(current_user_ns(), val); |
| 327 | if (!uid_valid(sbi->uid)) |
| 328 | goto cleanup; |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 329 | break; |
| 330 | } |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 331 | |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 332 | case Opt_gid: |
| 333 | { |
| 334 | char *gid = args[0].from; |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 335 | gid_t val = simple_strtoul(gid, &gid, 0); |
| 336 | sbi->gid = make_kgid(current_user_ns(), val); |
| 337 | if (!gid_valid(sbi->gid)) |
| 338 | goto cleanup; |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 339 | break; |
| 340 | } |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 341 | |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 342 | case Opt_umask: |
| 343 | { |
| 344 | char *umask = args[0].from; |
| 345 | sbi->umask = simple_strtoul(umask, &umask, 8); |
| 346 | if (sbi->umask & ~0777) { |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 347 | pr_err("JFS: Invalid value of umask\n"); |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 348 | goto cleanup; |
| 349 | } |
| 350 | break; |
| 351 | } |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 352 | |
| 353 | case Opt_discard: |
| 354 | { |
| 355 | struct request_queue *q = bdev_get_queue(sb->s_bdev); |
| 356 | /* if set to 1, even copying files will cause |
| 357 | * trimming :O |
| 358 | * -> user has more control over the online trimming |
| 359 | */ |
| 360 | sbi->minblks_trim = 64; |
| 361 | if (blk_queue_discard(q)) { |
| 362 | *flag |= JFS_DISCARD; |
| 363 | } else { |
| 364 | pr_err("JFS: discard option " \ |
| 365 | "not supported on device\n"); |
| 366 | } |
| 367 | break; |
| 368 | } |
| 369 | |
| 370 | case Opt_nodiscard: |
| 371 | *flag &= ~JFS_DISCARD; |
| 372 | break; |
| 373 | |
| 374 | case Opt_discard_minblk: |
| 375 | { |
| 376 | struct request_queue *q = bdev_get_queue(sb->s_bdev); |
| 377 | char *minblks_trim = args[0].from; |
| 378 | if (blk_queue_discard(q)) { |
| 379 | *flag |= JFS_DISCARD; |
| 380 | sbi->minblks_trim = simple_strtoull( |
| 381 | minblks_trim, &minblks_trim, 0); |
| 382 | } else { |
| 383 | pr_err("JFS: discard option " \ |
| 384 | "not supported on device\n"); |
| 385 | } |
| 386 | break; |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | default: |
| 390 | printk("jfs: Unrecognized mount option \"%s\" " |
| 391 | " or missing value\n", p); |
| 392 | goto cleanup; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | if (nls_map != (void *) -1) { |
| 397 | /* Discard old (if remount) */ |
Thomas Gleixner | 6d729e4 | 2009-08-16 21:05:08 +0000 | [diff] [blame] | 398 | unload_nls(sbi->nls_tab); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | sbi->nls_tab = nls_map; |
| 400 | } |
| 401 | return 1; |
| 402 | |
| 403 | cleanup: |
| 404 | if (nls_map && nls_map != (void *) -1) |
| 405 | unload_nls(nls_map); |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static int jfs_remount(struct super_block *sb, int *flags, char *data) |
| 410 | { |
| 411 | s64 newLVSize = 0; |
| 412 | int rc = 0; |
| 413 | int flag = JFS_SBI(sb)->flag; |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 414 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | if (!parse_options(data, sb, &newLVSize, &flag)) { |
| 417 | return -EINVAL; |
| 418 | } |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | if (newLVSize) { |
| 421 | if (sb->s_flags & MS_RDONLY) { |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 422 | pr_err("JFS: resize requires volume" \ |
| 423 | " to be mounted read-write\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | return -EROFS; |
| 425 | } |
| 426 | rc = jfs_extendfs(sb, newLVSize, 0); |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 427 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | return rc; |
| 429 | } |
| 430 | |
| 431 | if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 432 | /* |
| 433 | * Invalidate any previously read metadata. fsck may have |
| 434 | * changed the on-disk data since we mounted r/o |
| 435 | */ |
| 436 | truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0); |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | JFS_SBI(sb)->flag = flag; |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 439 | ret = jfs_mount_rw(sb, 1); |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 440 | |
| 441 | /* mark the fs r/w for quota activity */ |
| 442 | sb->s_flags &= ~MS_RDONLY; |
| 443 | |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 444 | dquot_resume(sb, -1); |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 445 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) { |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 448 | rc = dquot_suspend(sb, -1); |
| 449 | if (rc < 0) { |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 450 | return rc; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | rc = jfs_umount_rw(sb); |
| 453 | JFS_SBI(sb)->flag = flag; |
| 454 | return rc; |
| 455 | } |
| 456 | if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) |
| 457 | if (!(sb->s_flags & MS_RDONLY)) { |
| 458 | rc = jfs_umount_rw(sb); |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 459 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | return rc; |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | JFS_SBI(sb)->flag = flag; |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 463 | ret = jfs_mount_rw(sb, 1); |
Alessio Igor Bogani | 337eb00 | 2009-05-12 15:10:54 +0200 | [diff] [blame] | 464 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | JFS_SBI(sb)->flag = flag; |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | static int jfs_fill_super(struct super_block *sb, void *data, int silent) |
| 472 | { |
| 473 | struct jfs_sb_info *sbi; |
| 474 | struct inode *inode; |
| 475 | int rc; |
| 476 | s64 newLVSize = 0; |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 477 | int flag, ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); |
| 480 | |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 481 | if (!new_valid_dev(sb->s_bdev->bd_dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return -EOVERFLOW; |
| 483 | |
Eric Sesterhenn | 5b3030e | 2006-02-23 09:47:13 -0600 | [diff] [blame] | 484 | sbi = kzalloc(sizeof (struct jfs_sb_info), GFP_KERNEL); |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 485 | if (!sbi) |
Akinobu Mita | 087387f | 2006-09-14 09:22:38 -0500 | [diff] [blame] | 486 | return -ENOMEM; |
Jan Blunck | 22b26db | 2010-02-24 13:25:31 +0100 | [diff] [blame] | 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | sb->s_fs_info = sbi; |
Al Viro | 8de5277 | 2012-02-06 12:45:27 -0500 | [diff] [blame] | 489 | sb->s_max_links = JFS_LINK_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | sbi->sb = sb; |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 491 | sbi->uid = INVALID_UID; |
| 492 | sbi->gid = INVALID_GID; |
| 493 | sbi->umask = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | /* initialize the mount flag and determine the default error handler */ |
| 496 | flag = JFS_ERR_REMOUNT_RO; |
| 497 | |
Jan Blunck | 684bdc7 | 2010-04-12 16:44:08 -0700 | [diff] [blame] | 498 | if (!parse_options((char *) data, sb, &newLVSize, &flag)) |
| 499 | goto out_kfree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | sbi->flag = flag; |
| 501 | |
| 502 | #ifdef CONFIG_JFS_POSIX_ACL |
| 503 | sb->s_flags |= MS_POSIXACL; |
| 504 | #endif |
| 505 | |
| 506 | if (newLVSize) { |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 507 | pr_err("resize option for remount only\n"); |
Jan Blunck | 684bdc7 | 2010-04-12 16:44:08 -0700 | [diff] [blame] | 508 | goto out_kfree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | /* |
| 512 | * Initialize blocksize to 4K. |
| 513 | */ |
| 514 | sb_set_blocksize(sb, PSIZE); |
| 515 | |
| 516 | /* |
| 517 | * Set method vectors. |
| 518 | */ |
| 519 | sb->s_op = &jfs_super_operations; |
| 520 | sb->s_export_op = &jfs_export_operations; |
Christoph Hellwig | 123e9ca | 2010-05-19 07:16:44 -0400 | [diff] [blame] | 521 | #ifdef CONFIG_QUOTA |
| 522 | sb->dq_op = &dquot_operations; |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 523 | sb->s_qcop = &dquot_quotactl_ops; |
Christoph Hellwig | 123e9ca | 2010-05-19 07:16:44 -0400 | [diff] [blame] | 524 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 526 | /* |
| 527 | * Initialize direct-mapping inode/address-space |
| 528 | */ |
| 529 | inode = new_inode(sb); |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 530 | if (inode == NULL) { |
| 531 | ret = -ENOMEM; |
Jan Blunck | 684bdc7 | 2010-04-12 16:44:08 -0700 | [diff] [blame] | 532 | goto out_unload; |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 533 | } |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 534 | inode->i_ino = 0; |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 535 | inode->i_size = sb->s_bdev->bd_inode->i_size; |
| 536 | inode->i_mapping->a_ops = &jfs_metapage_aops; |
Dave Kleikamp | ac17b8b | 2005-10-03 15:32:11 -0500 | [diff] [blame] | 537 | insert_inode_hash(inode); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 538 | mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); |
| 539 | |
| 540 | sbi->direct_inode = inode; |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | rc = jfs_mount(sb); |
| 543 | if (rc) { |
| 544 | if (!silent) { |
| 545 | jfs_err("jfs_mount failed w/return code = %d", rc); |
| 546 | } |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 547 | goto out_mount_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | if (sb->s_flags & MS_RDONLY) |
| 550 | sbi->log = NULL; |
| 551 | else { |
| 552 | rc = jfs_mount_rw(sb, 0); |
| 553 | if (rc) { |
| 554 | if (!silent) { |
| 555 | jfs_err("jfs_mount_rw failed, return code = %d", |
| 556 | rc); |
| 557 | } |
| 558 | goto out_no_rw; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | sb->s_magic = JFS_SUPER_MAGIC; |
| 563 | |
Al Viro | 94b77bd | 2010-12-18 10:59:31 -0500 | [diff] [blame] | 564 | if (sbi->mntflag & JFS_OS2) |
| 565 | sb->s_d_op = &jfs_ci_dentry_operations; |
| 566 | |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 567 | inode = jfs_iget(sb, ROOT_I); |
| 568 | if (IS_ERR(inode)) { |
| 569 | ret = PTR_ERR(inode); |
Dave Kleikamp | 6536d28 | 2008-05-21 10:45:16 -0500 | [diff] [blame] | 570 | goto out_no_rw; |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 571 | } |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 572 | sb->s_root = d_make_root(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | if (!sb->s_root) |
| 574 | goto out_no_root; |
| 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* logical blocks are represented by 40 bits in pxd_t, etc. */ |
| 577 | sb->s_maxbytes = ((u64) sb->s_blocksize) << 40; |
| 578 | #if BITS_PER_LONG == 32 |
| 579 | /* |
| 580 | * Page cache is indexed by long. |
| 581 | * I would use MAX_LFS_FILESIZE, but it's only half as big |
| 582 | */ |
Alan Cox | 28ba0ec | 2009-11-06 11:31:06 +0000 | [diff] [blame] | 583 | sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | #endif |
| 585 | sb->s_time_gran = 1; |
| 586 | return 0; |
| 587 | |
| 588 | out_no_root: |
Dave Kleikamp | 6536d28 | 2008-05-21 10:45:16 -0500 | [diff] [blame] | 589 | jfs_err("jfs_read_super: get root dentry failed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | out_no_rw: |
| 592 | rc = jfs_umount(sb); |
| 593 | if (rc) { |
| 594 | jfs_err("jfs_umount failed with return code %d", rc); |
| 595 | } |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 596 | out_mount_failed: |
OGAWA Hirofumi | 28fd129 | 2006-01-08 01:02:14 -0800 | [diff] [blame] | 597 | filemap_write_and_wait(sbi->direct_inode->i_mapping); |
Dave Kleikamp | 7fab479 | 2005-05-02 12:25:02 -0600 | [diff] [blame] | 598 | truncate_inode_pages(sbi->direct_inode->i_mapping, 0); |
| 599 | make_bad_inode(sbi->direct_inode); |
| 600 | iput(sbi->direct_inode); |
| 601 | sbi->direct_inode = NULL; |
Jan Blunck | 684bdc7 | 2010-04-12 16:44:08 -0700 | [diff] [blame] | 602 | out_unload: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | if (sbi->nls_tab) |
| 604 | unload_nls(sbi->nls_tab); |
Jan Blunck | 684bdc7 | 2010-04-12 16:44:08 -0700 | [diff] [blame] | 605 | out_kfree: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | kfree(sbi); |
David Howells | eab1df7 | 2008-02-07 00:15:43 -0800 | [diff] [blame] | 607 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 610 | static int jfs_freeze(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | { |
| 612 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 613 | struct jfs_log *log = sbi->log; |
Vahram Martirosyan | e9b3766 | 2013-05-24 13:57:12 +0500 | [diff] [blame] | 614 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | if (!(sb->s_flags & MS_RDONLY)) { |
| 617 | txQuiesce(sb); |
Vahram Martirosyan | e9b3766 | 2013-05-24 13:57:12 +0500 | [diff] [blame] | 618 | rc = lmLogShutdown(log); |
| 619 | if (rc) { |
| 620 | jfs_error(sb, "jfs_freeze: lmLogShutdown failed"); |
| 621 | |
| 622 | /* let operations fail rather than hang */ |
| 623 | txResume(sb); |
| 624 | |
| 625 | return rc; |
| 626 | } |
| 627 | rc = updateSuper(sb, FM_CLEAN); |
| 628 | if (rc) { |
| 629 | jfs_err("jfs_freeze: updateSuper failed\n"); |
| 630 | /* |
| 631 | * Don't fail here. Everything succeeded except |
| 632 | * marking the superblock clean, so there's really |
| 633 | * no harm in leaving it frozen for now. |
| 634 | */ |
| 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 637 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 640 | static int jfs_unfreeze(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
| 642 | struct jfs_sb_info *sbi = JFS_SBI(sb); |
| 643 | struct jfs_log *log = sbi->log; |
| 644 | int rc = 0; |
| 645 | |
| 646 | if (!(sb->s_flags & MS_RDONLY)) { |
Vahram Martirosyan | e9b3766 | 2013-05-24 13:57:12 +0500 | [diff] [blame] | 647 | rc = updateSuper(sb, FM_MOUNT); |
| 648 | if (rc) { |
| 649 | jfs_error(sb, "jfs_unfreeze: updateSuper failed"); |
| 650 | goto out; |
| 651 | } |
| 652 | rc = lmLogInit(log); |
| 653 | if (rc) |
| 654 | jfs_error(sb, "jfs_unfreeze: lmLogInit failed"); |
| 655 | out: |
| 656 | txResume(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
Vahram Martirosyan | e9b3766 | 2013-05-24 13:57:12 +0500 | [diff] [blame] | 658 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 661 | static struct dentry *jfs_do_mount(struct file_system_type *fs_type, |
| 662 | int flags, const char *dev_name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | { |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 664 | return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | static int jfs_sync_fs(struct super_block *sb, int wait) |
| 668 | { |
| 669 | struct jfs_log *log = JFS_SBI(sb)->log; |
| 670 | |
| 671 | /* log == NULL indicates read-only mount */ |
Dave Kleikamp | 1c62782 | 2005-05-02 12:25:08 -0600 | [diff] [blame] | 672 | if (log) { |
Jan Kara | a117782 | 2012-07-03 16:45:29 +0200 | [diff] [blame] | 673 | /* |
| 674 | * Write quota structures to quota file, sync_blockdev() will |
| 675 | * write them to disk later |
| 676 | */ |
| 677 | dquot_writeback_dquots(sb, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | jfs_flush_journal(log, wait); |
Dave Kleikamp | cbc3d65 | 2005-07-27 09:17:57 -0500 | [diff] [blame] | 679 | jfs_syncpt(log, 0); |
Dave Kleikamp | 1c62782 | 2005-05-02 12:25:08 -0600 | [diff] [blame] | 680 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 685 | static int jfs_show_options(struct seq_file *seq, struct dentry *root) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 686 | { |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 687 | struct jfs_sb_info *sbi = JFS_SBI(root->d_sb); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 688 | |
Eric W. Biederman | c18cdc1 | 2012-02-10 11:40:34 -0800 | [diff] [blame] | 689 | if (uid_valid(sbi->uid)) |
| 690 | seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid)); |
| 691 | if (gid_valid(sbi->gid)) |
| 692 | seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid)); |
Dave Kleikamp | 69eb66d | 2006-03-09 13:59:30 -0600 | [diff] [blame] | 693 | if (sbi->umask != -1) |
| 694 | seq_printf(seq, ",umask=%03o", sbi->umask); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 695 | if (sbi->flag & JFS_NOINTEGRITY) |
| 696 | seq_puts(seq, ",nointegrity"); |
Tino Reichardt | b40c2e6 | 2012-09-17 11:58:19 -0500 | [diff] [blame] | 697 | if (sbi->flag & JFS_DISCARD) |
| 698 | seq_printf(seq, ",discard=%u", sbi->minblks_trim); |
Miklos Szeredi | 5c5e32c | 2008-01-24 16:13:21 -0600 | [diff] [blame] | 699 | if (sbi->nls_tab) |
| 700 | seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset); |
| 701 | if (sbi->flag & JFS_ERR_CONTINUE) |
| 702 | seq_printf(seq, ",errors=continue"); |
| 703 | if (sbi->flag & JFS_ERR_PANIC) |
| 704 | seq_printf(seq, ",errors=panic"); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 705 | |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 706 | #ifdef CONFIG_QUOTA |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 707 | if (sbi->flag & JFS_USRQUOTA) |
| 708 | seq_puts(seq, ",usrquota"); |
| 709 | |
| 710 | if (sbi->flag & JFS_GRPQUOTA) |
| 711 | seq_puts(seq, ",grpquota"); |
| 712 | #endif |
| 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 717 | #ifdef CONFIG_QUOTA |
| 718 | |
| 719 | /* Read data from quotafile - avoid pagecache and such because we cannot afford |
| 720 | * acquiring the locks... As quota files are never truncated and quota code |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 721 | * itself serializes the operations (and no one else should touch the files) |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 722 | * we don't have to be afraid of races */ |
| 723 | static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data, |
| 724 | size_t len, loff_t off) |
| 725 | { |
| 726 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 727 | sector_t blk = off >> sb->s_blocksize_bits; |
| 728 | int err = 0; |
| 729 | int offset = off & (sb->s_blocksize - 1); |
| 730 | int tocopy; |
| 731 | size_t toread; |
| 732 | struct buffer_head tmp_bh; |
| 733 | struct buffer_head *bh; |
| 734 | loff_t i_size = i_size_read(inode); |
| 735 | |
| 736 | if (off > i_size) |
| 737 | return 0; |
| 738 | if (off+len > i_size) |
| 739 | len = i_size-off; |
| 740 | toread = len; |
| 741 | while (toread > 0) { |
| 742 | tocopy = sb->s_blocksize - offset < toread ? |
| 743 | sb->s_blocksize - offset : toread; |
| 744 | |
| 745 | tmp_bh.b_state = 0; |
| 746 | tmp_bh.b_size = 1 << inode->i_blkbits; |
| 747 | err = jfs_get_block(inode, blk, &tmp_bh, 0); |
| 748 | if (err) |
| 749 | return err; |
| 750 | if (!buffer_mapped(&tmp_bh)) /* A hole? */ |
| 751 | memset(data, 0, tocopy); |
| 752 | else { |
| 753 | bh = sb_bread(sb, tmp_bh.b_blocknr); |
| 754 | if (!bh) |
| 755 | return -EIO; |
| 756 | memcpy(data, bh->b_data+offset, tocopy); |
| 757 | brelse(bh); |
| 758 | } |
| 759 | offset = 0; |
| 760 | toread -= tocopy; |
| 761 | data += tocopy; |
| 762 | blk++; |
| 763 | } |
| 764 | return len; |
| 765 | } |
| 766 | |
| 767 | /* Write to quotafile */ |
| 768 | static ssize_t jfs_quota_write(struct super_block *sb, int type, |
| 769 | const char *data, size_t len, loff_t off) |
| 770 | { |
| 771 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 772 | sector_t blk = off >> sb->s_blocksize_bits; |
| 773 | int err = 0; |
| 774 | int offset = off & (sb->s_blocksize - 1); |
| 775 | int tocopy; |
| 776 | size_t towrite = len; |
| 777 | struct buffer_head tmp_bh; |
| 778 | struct buffer_head *bh; |
| 779 | |
| 780 | mutex_lock(&inode->i_mutex); |
| 781 | while (towrite > 0) { |
| 782 | tocopy = sb->s_blocksize - offset < towrite ? |
| 783 | sb->s_blocksize - offset : towrite; |
| 784 | |
| 785 | tmp_bh.b_state = 0; |
Dave Kleikamp | 8bcb283 | 2006-07-28 08:46:05 -0500 | [diff] [blame] | 786 | tmp_bh.b_size = 1 << inode->i_blkbits; |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 787 | err = jfs_get_block(inode, blk, &tmp_bh, 1); |
| 788 | if (err) |
| 789 | goto out; |
| 790 | if (offset || tocopy != sb->s_blocksize) |
| 791 | bh = sb_bread(sb, tmp_bh.b_blocknr); |
| 792 | else |
| 793 | bh = sb_getblk(sb, tmp_bh.b_blocknr); |
| 794 | if (!bh) { |
| 795 | err = -EIO; |
| 796 | goto out; |
| 797 | } |
| 798 | lock_buffer(bh); |
| 799 | memcpy(bh->b_data+offset, data, tocopy); |
| 800 | flush_dcache_page(bh->b_page); |
| 801 | set_buffer_uptodate(bh); |
| 802 | mark_buffer_dirty(bh); |
| 803 | unlock_buffer(bh); |
| 804 | brelse(bh); |
| 805 | offset = 0; |
| 806 | towrite -= tocopy; |
| 807 | data += tocopy; |
| 808 | blk++; |
| 809 | } |
| 810 | out: |
Dan Carpenter | 9c83633 | 2009-04-07 14:48:16 +0300 | [diff] [blame] | 811 | if (len == towrite) { |
| 812 | mutex_unlock(&inode->i_mutex); |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 813 | return err; |
Dan Carpenter | 9c83633 | 2009-04-07 14:48:16 +0300 | [diff] [blame] | 814 | } |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 815 | if (inode->i_size < off+len-towrite) |
| 816 | i_size_write(inode, off+len-towrite); |
| 817 | inode->i_version++; |
| 818 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 819 | mark_inode_dirty(inode); |
| 820 | mutex_unlock(&inode->i_mutex); |
| 821 | return len - towrite; |
| 822 | } |
| 823 | |
| 824 | #endif |
| 825 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 826 | static const struct super_operations jfs_super_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | .alloc_inode = jfs_alloc_inode, |
| 828 | .destroy_inode = jfs_destroy_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | .dirty_inode = jfs_dirty_inode, |
| 830 | .write_inode = jfs_write_inode, |
Al Viro | 62aff86 | 2010-06-07 00:28:54 -0400 | [diff] [blame] | 831 | .evict_inode = jfs_evict_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | .put_super = jfs_put_super, |
| 833 | .sync_fs = jfs_sync_fs, |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 834 | .freeze_fs = jfs_freeze, |
| 835 | .unfreeze_fs = jfs_unfreeze, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | .statfs = jfs_statfs, |
| 837 | .remount_fs = jfs_remount, |
Dave Kleikamp | 115ff50 | 2006-07-26 14:52:13 -0500 | [diff] [blame] | 838 | .show_options = jfs_show_options, |
| 839 | #ifdef CONFIG_QUOTA |
| 840 | .quota_read = jfs_quota_read, |
| 841 | .quota_write = jfs_quota_write, |
| 842 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | }; |
| 844 | |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 845 | static const struct export_operations jfs_export_operations = { |
Christoph Hellwig | d425de7 | 2007-10-21 16:42:09 -0700 | [diff] [blame] | 846 | .fh_to_dentry = jfs_fh_to_dentry, |
| 847 | .fh_to_parent = jfs_fh_to_parent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | .get_parent = jfs_get_parent, |
| 849 | }; |
| 850 | |
| 851 | static struct file_system_type jfs_fs_type = { |
| 852 | .owner = THIS_MODULE, |
| 853 | .name = "jfs", |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 854 | .mount = jfs_do_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | .kill_sb = kill_block_super, |
| 856 | .fs_flags = FS_REQUIRES_DEV, |
| 857 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 858 | MODULE_ALIAS_FS("jfs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 860 | static void init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
| 862 | struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo; |
| 863 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 864 | memset(jfs_ip, 0, sizeof(struct jfs_inode_info)); |
| 865 | INIT_LIST_HEAD(&jfs_ip->anon_inode_list); |
| 866 | init_rwsem(&jfs_ip->rdwrlock); |
| 867 | mutex_init(&jfs_ip->commit_mutex); |
| 868 | init_rwsem(&jfs_ip->xattr_sem); |
| 869 | spin_lock_init(&jfs_ip->ag_lock); |
| 870 | jfs_ip->active_ag = -1; |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 871 | inode_init_once(&jfs_ip->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | static int __init init_jfs_fs(void) |
| 875 | { |
| 876 | int i; |
| 877 | int rc; |
| 878 | |
| 879 | jfs_inode_cachep = |
Dave Kleikamp | 63f83c9 | 2006-10-02 09:55:27 -0500 | [diff] [blame] | 880 | kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0, |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 881 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 882 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | if (jfs_inode_cachep == NULL) |
| 884 | return -ENOMEM; |
| 885 | |
| 886 | /* |
| 887 | * Metapage initialization |
| 888 | */ |
| 889 | rc = metapage_init(); |
| 890 | if (rc) { |
| 891 | jfs_err("metapage_init failed w/rc = %d", rc); |
| 892 | goto free_slab; |
| 893 | } |
| 894 | |
| 895 | /* |
| 896 | * Transaction Manager initialization |
| 897 | */ |
| 898 | rc = txInit(); |
| 899 | if (rc) { |
| 900 | jfs_err("txInit failed w/rc = %d", rc); |
| 901 | goto free_metapage; |
| 902 | } |
| 903 | |
| 904 | /* |
| 905 | * I/O completion thread (endio) |
| 906 | */ |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 907 | jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO"); |
| 908 | if (IS_ERR(jfsIOthread)) { |
| 909 | rc = PTR_ERR(jfsIOthread); |
| 910 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | goto end_txmngr; |
| 912 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
| 914 | if (commit_threads < 1) |
| 915 | commit_threads = num_online_cpus(); |
| 916 | if (commit_threads > MAX_COMMIT_THREADS) |
| 917 | commit_threads = MAX_COMMIT_THREADS; |
| 918 | |
| 919 | for (i = 0; i < commit_threads; i++) { |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 920 | jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit"); |
| 921 | if (IS_ERR(jfsCommitThread[i])) { |
| 922 | rc = PTR_ERR(jfsCommitThread[i]); |
| 923 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | commit_threads = i; |
| 925 | goto kill_committask; |
| 926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 929 | jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync"); |
| 930 | if (IS_ERR(jfsSyncThread)) { |
| 931 | rc = PTR_ERR(jfsSyncThread); |
| 932 | jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | goto kill_committask; |
| 934 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | #ifdef PROC_FS_JFS |
| 937 | jfs_proc_init(); |
| 938 | #endif |
| 939 | |
Al Viro | 76bf09f | 2012-03-17 18:14:34 -0400 | [diff] [blame] | 940 | rc = register_filesystem(&jfs_fs_type); |
| 941 | if (!rc) |
| 942 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | |
Al Viro | 76bf09f | 2012-03-17 18:14:34 -0400 | [diff] [blame] | 944 | #ifdef PROC_FS_JFS |
| 945 | jfs_proc_clean(); |
| 946 | #endif |
| 947 | kthread_stop(jfsSyncThread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | kill_committask: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | for (i = 0; i < commit_threads; i++) |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 950 | kthread_stop(jfsCommitThread[i]); |
| 951 | kthread_stop(jfsIOthread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | end_txmngr: |
| 953 | txExit(); |
| 954 | free_metapage: |
| 955 | metapage_exit(); |
| 956 | free_slab: |
| 957 | kmem_cache_destroy(jfs_inode_cachep); |
| 958 | return rc; |
| 959 | } |
| 960 | |
| 961 | static void __exit exit_jfs_fs(void) |
| 962 | { |
| 963 | int i; |
| 964 | |
| 965 | jfs_info("exit_jfs_fs called"); |
| 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | txExit(); |
| 968 | metapage_exit(); |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 969 | |
| 970 | kthread_stop(jfsIOthread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | for (i = 0; i < commit_threads; i++) |
Christoph Hellwig | 91dbb4d | 2006-02-15 12:49:04 -0600 | [diff] [blame] | 972 | kthread_stop(jfsCommitThread[i]); |
| 973 | kthread_stop(jfsSyncThread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | #ifdef PROC_FS_JFS |
| 975 | jfs_proc_clean(); |
| 976 | #endif |
| 977 | unregister_filesystem(&jfs_fs_type); |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * Make sure all delayed rcu free inodes are flushed before we |
| 981 | * destroy cache. |
| 982 | */ |
| 983 | rcu_barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | kmem_cache_destroy(jfs_inode_cachep); |
| 985 | } |
| 986 | |
| 987 | module_init(init_jfs_fs) |
| 988 | module_exit(exit_jfs_fs) |