Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/ext3/super.c |
| 3 | * |
| 4 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 5 | * Remy Card (card@masi.ibp.fr) |
| 6 | * Laboratoire MASI - Institut Blaise Pascal |
| 7 | * Universite Pierre et Marie Curie (Paris VI) |
| 8 | * |
| 9 | * from |
| 10 | * |
| 11 | * linux/fs/minix/inode.c |
| 12 | * |
| 13 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 14 | * |
| 15 | * Big-endian to little-endian byte-swapping/bitmaps by |
| 16 | * David S. Miller (davem@caip.rutgers.edu), 1995 |
| 17 | */ |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/blkdev.h> |
| 21 | #include <linux/parser.h> |
Christoph Hellwig | a569425 | 2007-07-17 04:04:28 -0700 | [diff] [blame] | 22 | #include <linux/exportfs.h> |
Al Viro | 4613ad1 | 2012-03-29 22:30:07 -0400 | [diff] [blame] | 23 | #include <linux/statfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/random.h> |
| 25 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/quotaops.h> |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 27 | #include <linux/seq_file.h> |
vignesh babu | 3fc7426 | 2007-07-15 23:41:17 -0700 | [diff] [blame] | 28 | #include <linux/log2.h> |
Dan Magenheimer | d71bc6d | 2011-05-26 10:01:49 -0600 | [diff] [blame] | 29 | #include <linux/cleancache.h> |
Ben Dooks | 381be25 | 2005-10-30 15:02:56 -0800 | [diff] [blame] | 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
Ben Dooks | 381be25 | 2005-10-30 15:02:56 -0800 | [diff] [blame] | 32 | |
Al Viro | 4613ad1 | 2012-03-29 22:30:07 -0400 | [diff] [blame] | 33 | #define CREATE_TRACE_POINTS |
| 34 | |
| 35 | #include "ext3.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "xattr.h" |
| 37 | #include "acl.h" |
Ben Dooks | 381be25 | 2005-10-30 15:02:56 -0800 | [diff] [blame] | 38 | #include "namei.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Linus Torvalds | bbae8bc | 2009-04-06 17:16:47 -0700 | [diff] [blame] | 40 | #ifdef CONFIG_EXT3_DEFAULTS_TO_ORDERED |
| 41 | #define EXT3_MOUNT_DEFAULT_DATA_MODE EXT3_MOUNT_ORDERED_DATA |
| 42 | #else |
| 43 | #define EXT3_MOUNT_DEFAULT_DATA_MODE EXT3_MOUNT_WRITEBACK_DATA |
| 44 | #endif |
| 45 | |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 46 | static int ext3_load_journal(struct super_block *, struct ext3_super_block *, |
| 47 | unsigned long journal_devnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | static int ext3_create_journal(struct super_block *, struct ext3_super_block *, |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 49 | unsigned int); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 50 | static int ext3_commit_super(struct super_block *sb, |
| 51 | struct ext3_super_block *es, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | int sync); |
| 53 | static void ext3_mark_recovery_complete(struct super_block * sb, |
| 54 | struct ext3_super_block * es); |
| 55 | static void ext3_clear_journal_err(struct super_block * sb, |
| 56 | struct ext3_super_block * es); |
| 57 | static int ext3_sync_fs(struct super_block *sb, int wait); |
| 58 | static const char *ext3_decode_error(struct super_block * sb, int errno, |
| 59 | char nbuf[16]); |
| 60 | static int ext3_remount (struct super_block * sb, int * flags, char * data); |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 61 | static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 62 | static int ext3_unfreeze(struct super_block *sb); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 63 | static int ext3_freeze(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 65 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * Wrappers for journal_start/end. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | */ |
| 68 | handle_t *ext3_journal_start_sb(struct super_block *sb, int nblocks) |
| 69 | { |
| 70 | journal_t *journal; |
| 71 | |
| 72 | if (sb->s_flags & MS_RDONLY) |
| 73 | return ERR_PTR(-EROFS); |
| 74 | |
| 75 | /* Special case here: if the journal has aborted behind our |
| 76 | * backs (eg. EIO in the commit thread), then we still need to |
| 77 | * take the FS itself readonly cleanly. */ |
| 78 | journal = EXT3_SB(sb)->s_journal; |
| 79 | if (is_journal_aborted(journal)) { |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 80 | ext3_abort(sb, __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | "Detected aborted journal"); |
| 82 | return ERR_PTR(-EROFS); |
| 83 | } |
| 84 | |
| 85 | return journal_start(journal, nblocks); |
| 86 | } |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | int __ext3_journal_stop(const char *where, handle_t *handle) |
| 89 | { |
| 90 | struct super_block *sb; |
| 91 | int err; |
| 92 | int rc; |
| 93 | |
| 94 | sb = handle->h_transaction->t_journal->j_private; |
| 95 | err = handle->h_err; |
| 96 | rc = journal_stop(handle); |
| 97 | |
| 98 | if (!err) |
| 99 | err = rc; |
| 100 | if (err) |
| 101 | __ext3_std_error(sb, where, err); |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | void ext3_journal_abort_handle(const char *caller, const char *err_fn, |
| 106 | struct buffer_head *bh, handle_t *handle, int err) |
| 107 | { |
| 108 | char nbuf[16]; |
| 109 | const char *errstr = ext3_decode_error(NULL, err, nbuf); |
| 110 | |
| 111 | if (bh) |
| 112 | BUFFER_TRACE(bh, "abort"); |
| 113 | |
| 114 | if (!handle->h_err) |
| 115 | handle->h_err = err; |
| 116 | |
| 117 | if (is_handle_aborted(handle)) |
| 118 | return; |
| 119 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 120 | printk(KERN_ERR "EXT3-fs: %s: aborting transaction: %s in %s\n", |
| 121 | caller, errstr, err_fn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | journal_abort_handle(handle); |
| 124 | } |
| 125 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 126 | void ext3_msg(struct super_block *sb, const char *prefix, |
| 127 | const char *fmt, ...) |
| 128 | { |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 129 | struct va_format vaf; |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 130 | va_list args; |
| 131 | |
| 132 | va_start(args, fmt); |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 133 | |
| 134 | vaf.fmt = fmt; |
| 135 | vaf.va = &args; |
| 136 | |
| 137 | printk("%sEXT3-fs (%s): %pV\n", prefix, sb->s_id, &vaf); |
| 138 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 139 | va_end(args); |
| 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Deal with the reporting of failure conditions on a filesystem such as |
| 143 | * inconsistencies detected or read IO failures. |
| 144 | * |
| 145 | * On ext2, we can store the error state of the filesystem in the |
| 146 | * superblock. That is not possible on ext3, because we may have other |
| 147 | * write ordering constraints on the superblock which prevent us from |
| 148 | * writing it out straight away; and given that the journal is about to |
| 149 | * be aborted, we can't rely on the current, or future, transactions to |
| 150 | * write out the superblock safely. |
| 151 | * |
| 152 | * We'll just use the journal_abort() error code to record an error in |
Thadeu Lima de Souza Cascardo | d6b198b | 2010-01-17 19:10:07 -0200 | [diff] [blame] | 153 | * the journal instead. On recovery, the journal will complain about |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | * that error until we've noted it down and cleared it. |
| 155 | */ |
| 156 | |
| 157 | static void ext3_handle_error(struct super_block *sb) |
| 158 | { |
| 159 | struct ext3_super_block *es = EXT3_SB(sb)->s_es; |
| 160 | |
| 161 | EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; |
| 162 | es->s_state |= cpu_to_le16(EXT3_ERROR_FS); |
| 163 | |
| 164 | if (sb->s_flags & MS_RDONLY) |
| 165 | return; |
| 166 | |
Vasily Averin | 7543fc7 | 2006-09-27 01:49:33 -0700 | [diff] [blame] | 167 | if (!test_opt (sb, ERRORS_CONT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | journal_t *journal = EXT3_SB(sb)->s_journal; |
| 169 | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 170 | set_opt(EXT3_SB(sb)->s_mount_opt, ABORT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | if (journal) |
| 172 | journal_abort(journal, -EIO); |
| 173 | } |
Vasily Averin | 7543fc7 | 2006-09-27 01:49:33 -0700 | [diff] [blame] | 174 | if (test_opt (sb, ERRORS_RO)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 175 | ext3_msg(sb, KERN_CRIT, |
| 176 | "error: remounting filesystem read-only"); |
Dmitry Monakhov | 3df3219 | 2013-05-28 13:19:01 +0400 | [diff] [blame] | 177 | /* |
| 178 | * Make sure updated value of ->s_mount_state will be visible |
| 179 | * before ->s_flags update. |
| 180 | */ |
| 181 | smp_wmb(); |
Vasily Averin | 7543fc7 | 2006-09-27 01:49:33 -0700 | [diff] [blame] | 182 | sb->s_flags |= MS_RDONLY; |
| 183 | } |
| 184 | ext3_commit_super(sb, es, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | if (test_opt(sb, ERRORS_PANIC)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 186 | panic("EXT3-fs (%s): panic forced after error\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | sb->s_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 190 | void ext3_error(struct super_block *sb, const char *function, |
| 191 | const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 193 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | va_list args; |
| 195 | |
| 196 | va_start(args, fmt); |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 197 | |
| 198 | vaf.fmt = fmt; |
| 199 | vaf.va = &args; |
| 200 | |
| 201 | printk(KERN_CRIT "EXT3-fs error (device %s): %s: %pV\n", |
| 202 | sb->s_id, function, &vaf); |
| 203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | va_end(args); |
| 205 | |
| 206 | ext3_handle_error(sb); |
| 207 | } |
| 208 | |
| 209 | static const char *ext3_decode_error(struct super_block * sb, int errno, |
| 210 | char nbuf[16]) |
| 211 | { |
| 212 | char *errstr = NULL; |
| 213 | |
| 214 | switch (errno) { |
| 215 | case -EIO: |
| 216 | errstr = "IO failure"; |
| 217 | break; |
| 218 | case -ENOMEM: |
| 219 | errstr = "Out of memory"; |
| 220 | break; |
| 221 | case -EROFS: |
| 222 | if (!sb || EXT3_SB(sb)->s_journal->j_flags & JFS_ABORT) |
| 223 | errstr = "Journal has aborted"; |
| 224 | else |
| 225 | errstr = "Readonly filesystem"; |
| 226 | break; |
| 227 | default: |
| 228 | /* If the caller passed in an extra buffer for unknown |
| 229 | * errors, textualise them now. Else we just return |
| 230 | * NULL. */ |
| 231 | if (nbuf) { |
| 232 | /* Check for truncated error codes... */ |
| 233 | if (snprintf(nbuf, 16, "error %d", -errno) >= 0) |
| 234 | errstr = nbuf; |
| 235 | } |
| 236 | break; |
| 237 | } |
| 238 | |
| 239 | return errstr; |
| 240 | } |
| 241 | |
| 242 | /* __ext3_std_error decodes expected errors from journaling functions |
| 243 | * automatically and invokes the appropriate error response. */ |
| 244 | |
| 245 | void __ext3_std_error (struct super_block * sb, const char * function, |
| 246 | int errno) |
| 247 | { |
| 248 | char nbuf[16]; |
Stephen Tweedie | 3012162 | 2005-05-18 11:47:17 -0400 | [diff] [blame] | 249 | const char *errstr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Stephen Tweedie | 3012162 | 2005-05-18 11:47:17 -0400 | [diff] [blame] | 251 | /* Special case: if the error is EROFS, and we're not already |
| 252 | * inside a transaction, then there's really no point in logging |
| 253 | * an error. */ |
| 254 | if (errno == -EROFS && journal_current_handle() == NULL && |
| 255 | (sb->s_flags & MS_RDONLY)) |
| 256 | return; |
| 257 | |
| 258 | errstr = ext3_decode_error(sb, errno, nbuf); |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 259 | ext3_msg(sb, KERN_CRIT, "error in %s: %s", function, errstr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | ext3_handle_error(sb); |
| 262 | } |
| 263 | |
| 264 | /* |
| 265 | * ext3_abort is a much stronger failure handler than ext3_error. The |
| 266 | * abort function may be used to deal with unrecoverable failures such |
| 267 | * as journal IO errors or ENOMEM at a critical moment in log management. |
| 268 | * |
| 269 | * We unconditionally force the filesystem into an ABORT|READONLY state, |
| 270 | * unless the error response on the fs has been set to panic in which |
| 271 | * case we take the easy way out and panic immediately. |
| 272 | */ |
| 273 | |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 274 | void ext3_abort(struct super_block *sb, const char *function, |
| 275 | const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 277 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | va_list args; |
| 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | va_start(args, fmt); |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 281 | |
| 282 | vaf.fmt = fmt; |
| 283 | vaf.va = &args; |
| 284 | |
| 285 | printk(KERN_CRIT "EXT3-fs (%s): error: %s: %pV\n", |
| 286 | sb->s_id, function, &vaf); |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | va_end(args); |
| 289 | |
| 290 | if (test_opt(sb, ERRORS_PANIC)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 291 | panic("EXT3-fs: panic from previous error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | if (sb->s_flags & MS_RDONLY) |
| 294 | return; |
| 295 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 296 | ext3_msg(sb, KERN_CRIT, |
| 297 | "error: remounting filesystem read-only"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 299 | set_opt(EXT3_SB(sb)->s_mount_opt, ABORT); |
Dmitry Monakhov | 3df3219 | 2013-05-28 13:19:01 +0400 | [diff] [blame] | 300 | /* |
| 301 | * Make sure updated value of ->s_mount_state will be visible |
| 302 | * before ->s_flags update. |
| 303 | */ |
| 304 | smp_wmb(); |
| 305 | sb->s_flags |= MS_RDONLY; |
| 306 | |
Hidehiro Kawai | 44d6f78 | 2008-10-27 22:51:46 -0400 | [diff] [blame] | 307 | if (EXT3_SB(sb)->s_journal) |
| 308 | journal_abort(EXT3_SB(sb)->s_journal, -EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 311 | void ext3_warning(struct super_block *sb, const char *function, |
| 312 | const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 314 | struct va_format vaf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | va_list args; |
| 316 | |
| 317 | va_start(args, fmt); |
Joe Perches | 99fbb1e | 2010-11-09 10:18:05 -0800 | [diff] [blame] | 318 | |
| 319 | vaf.fmt = fmt; |
| 320 | vaf.va = &args; |
| 321 | |
| 322 | printk(KERN_WARNING "EXT3-fs (%s): warning: %s: %pV\n", |
| 323 | sb->s_id, function, &vaf); |
| 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | va_end(args); |
| 326 | } |
| 327 | |
| 328 | void ext3_update_dynamic_rev(struct super_block *sb) |
| 329 | { |
| 330 | struct ext3_super_block *es = EXT3_SB(sb)->s_es; |
| 331 | |
| 332 | if (le32_to_cpu(es->s_rev_level) > EXT3_GOOD_OLD_REV) |
| 333 | return; |
| 334 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 335 | ext3_msg(sb, KERN_WARNING, |
| 336 | "warning: updating to rev %d because of " |
| 337 | "new feature flag, running e2fsck is recommended", |
| 338 | EXT3_DYNAMIC_REV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | es->s_first_ino = cpu_to_le32(EXT3_GOOD_OLD_FIRST_INO); |
| 341 | es->s_inode_size = cpu_to_le16(EXT3_GOOD_OLD_INODE_SIZE); |
| 342 | es->s_rev_level = cpu_to_le32(EXT3_DYNAMIC_REV); |
| 343 | /* leave es->s_feature_*compat flags alone */ |
| 344 | /* es->s_uuid will be set by e2fsck if empty */ |
| 345 | |
| 346 | /* |
| 347 | * The rest of the superblock fields should be zero, and if not it |
| 348 | * means they are likely already in use, so leave them alone. We |
| 349 | * can leave it up to e2fsck to clean up any inconsistencies there. |
| 350 | */ |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | * Open the external journal device |
| 355 | */ |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 356 | static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
| 358 | struct block_device *bdev; |
| 359 | char b[BDEVNAME_SIZE]; |
| 360 | |
Tejun Heo | d4d7762 | 2010-11-13 11:55:18 +0100 | [diff] [blame] | 361 | bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | if (IS_ERR(bdev)) |
| 363 | goto fail; |
| 364 | return bdev; |
| 365 | |
| 366 | fail: |
Lars-Peter Clausen | 8d0c2d1 | 2013-03-09 15:28:44 +0100 | [diff] [blame] | 367 | ext3_msg(sb, KERN_ERR, "error: failed to open journal device %s: %ld", |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 368 | __bdevname(dev, b), PTR_ERR(bdev)); |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return NULL; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Release the journal device |
| 375 | */ |
Al Viro | 4385bab | 2013-05-05 22:11:03 -0400 | [diff] [blame] | 376 | static void ext3_blkdev_put(struct block_device *bdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
Al Viro | 4385bab | 2013-05-05 22:11:03 -0400 | [diff] [blame] | 378 | blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Al Viro | 4385bab | 2013-05-05 22:11:03 -0400 | [diff] [blame] | 381 | static void ext3_blkdev_remove(struct ext3_sb_info *sbi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | struct block_device *bdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | bdev = sbi->journal_bdev; |
| 385 | if (bdev) { |
Al Viro | 4385bab | 2013-05-05 22:11:03 -0400 | [diff] [blame] | 386 | ext3_blkdev_put(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | sbi->journal_bdev = NULL; |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static inline struct inode *orphan_list_entry(struct list_head *l) |
| 392 | { |
| 393 | return &list_entry(l, struct ext3_inode_info, i_orphan)->vfs_inode; |
| 394 | } |
| 395 | |
| 396 | static void dump_orphan_list(struct super_block *sb, struct ext3_sb_info *sbi) |
| 397 | { |
| 398 | struct list_head *l; |
| 399 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 400 | ext3_msg(sb, KERN_ERR, "error: sb orphan head is %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | le32_to_cpu(sbi->s_es->s_last_orphan)); |
| 402 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 403 | ext3_msg(sb, KERN_ERR, "sb_info orphan list:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | list_for_each(l, &sbi->s_orphan) { |
| 405 | struct inode *inode = orphan_list_entry(l); |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 406 | ext3_msg(sb, KERN_ERR, " " |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 407 | "inode %s:%lu at %p: mode %o, nlink %d, next %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | inode->i_sb->s_id, inode->i_ino, inode, |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 409 | inode->i_mode, inode->i_nlink, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | NEXT_ORPHAN(inode)); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | static void ext3_put_super (struct super_block * sb) |
| 415 | { |
| 416 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 417 | struct ext3_super_block *es = sbi->s_es; |
Hidehiro Kawai | 44d6f78 | 2008-10-27 22:51:46 -0400 | [diff] [blame] | 418 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
Christoph Hellwig | e0ccfd9 | 2010-05-19 07:16:42 -0400 | [diff] [blame] | 420 | dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | ext3_xattr_put_super(sb); |
Hidehiro Kawai | 44d6f78 | 2008-10-27 22:51:46 -0400 | [diff] [blame] | 422 | err = journal_destroy(sbi->s_journal); |
| 423 | sbi->s_journal = NULL; |
| 424 | if (err < 0) |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 425 | ext3_abort(sb, __func__, "Couldn't clean up the journal"); |
Hidehiro Kawai | 44d6f78 | 2008-10-27 22:51:46 -0400 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (!(sb->s_flags & MS_RDONLY)) { |
| 428 | EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
| 429 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
| 430 | BUFFER_TRACE(sbi->s_sbh, "marking dirty"); |
| 431 | mark_buffer_dirty(sbi->s_sbh); |
| 432 | ext3_commit_super(sb, es, 1); |
| 433 | } |
| 434 | |
| 435 | for (i = 0; i < sbi->s_gdb_count; i++) |
| 436 | brelse(sbi->s_group_desc[i]); |
| 437 | kfree(sbi->s_group_desc); |
| 438 | percpu_counter_destroy(&sbi->s_freeblocks_counter); |
| 439 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
| 440 | percpu_counter_destroy(&sbi->s_dirs_counter); |
| 441 | brelse(sbi->s_sbh); |
| 442 | #ifdef CONFIG_QUOTA |
| 443 | for (i = 0; i < MAXQUOTAS; i++) |
| 444 | kfree(sbi->s_qf_names[i]); |
| 445 | #endif |
| 446 | |
| 447 | /* Debugging code just in case the in-memory inode orphan list |
| 448 | * isn't empty. The on-disk one can be non-empty if we've |
| 449 | * detected an error and taken the fs readonly, but the |
| 450 | * in-memory list had better be clean by this point. */ |
| 451 | if (!list_empty(&sbi->s_orphan)) |
| 452 | dump_orphan_list(sb, sbi); |
| 453 | J_ASSERT(list_empty(&sbi->s_orphan)); |
| 454 | |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 455 | invalidate_bdev(sb->s_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | if (sbi->journal_bdev && sbi->journal_bdev != sb->s_bdev) { |
| 457 | /* |
| 458 | * Invalidate the journal device's buffers. We don't want them |
| 459 | * floating about in memory - the physical journal device may |
| 460 | * hotswapped, and it breaks the `ro-after' testing code. |
| 461 | */ |
| 462 | sync_blockdev(sbi->journal_bdev); |
Peter Zijlstra | f98393a | 2007-05-06 14:49:54 -0700 | [diff] [blame] | 463 | invalidate_bdev(sbi->journal_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | ext3_blkdev_remove(sbi); |
| 465 | } |
| 466 | sb->s_fs_info = NULL; |
Pekka Enberg | 5df096d | 2009-01-07 18:07:25 -0800 | [diff] [blame] | 467 | kfree(sbi->s_blockgroup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | kfree(sbi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 471 | static struct kmem_cache *ext3_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * Called inside transaction, so use GFP_NOFS |
| 475 | */ |
| 476 | static struct inode *ext3_alloc_inode(struct super_block *sb) |
| 477 | { |
| 478 | struct ext3_inode_info *ei; |
| 479 | |
Christoph Lameter | e6b4f8d | 2006-12-06 20:33:14 -0800 | [diff] [blame] | 480 | ei = kmem_cache_alloc(ext3_inode_cachep, GFP_NOFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | if (!ei) |
| 482 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | ei->i_block_alloc_info = NULL; |
| 484 | ei->vfs_inode.i_version = 1; |
Jan Kara | fe8bc91 | 2009-10-16 19:26:15 +0200 | [diff] [blame] | 485 | atomic_set(&ei->i_datasync_tid, 0); |
| 486 | atomic_set(&ei->i_sync_tid, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | return &ei->vfs_inode; |
| 488 | } |
| 489 | |
Lukas Czerner | 785c4bc | 2011-05-23 18:33:01 +0200 | [diff] [blame] | 490 | static int ext3_drop_inode(struct inode *inode) |
| 491 | { |
| 492 | int drop = generic_drop_inode(inode); |
| 493 | |
| 494 | trace_ext3_drop_inode(inode, drop); |
| 495 | return drop; |
| 496 | } |
| 497 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 498 | static void ext3_i_callback(struct rcu_head *head) |
| 499 | { |
| 500 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 501 | kmem_cache_free(ext3_inode_cachep, EXT3_I(inode)); |
| 502 | } |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | static void ext3_destroy_inode(struct inode *inode) |
| 505 | { |
Vasily Averin | 9f7dd93 | 2007-07-15 23:40:45 -0700 | [diff] [blame] | 506 | if (!list_empty(&(EXT3_I(inode)->i_orphan))) { |
| 507 | printk("EXT3 Inode %p: orphan list check failed!\n", |
| 508 | EXT3_I(inode)); |
| 509 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, |
| 510 | EXT3_I(inode), sizeof(struct ext3_inode_info), |
| 511 | false); |
| 512 | dump_stack(); |
| 513 | } |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 514 | call_rcu(&inode->i_rcu, ext3_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 517 | static void init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { |
| 519 | struct ext3_inode_info *ei = (struct ext3_inode_info *) foo; |
| 520 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 521 | INIT_LIST_HEAD(&ei->i_orphan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | #ifdef CONFIG_EXT3_FS_XATTR |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 523 | init_rwsem(&ei->xattr_sem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | #endif |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 525 | mutex_init(&ei->truncate_mutex); |
| 526 | inode_init_once(&ei->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | static int init_inodecache(void) |
| 530 | { |
| 531 | ext3_inode_cachep = kmem_cache_create("ext3_inode_cache", |
| 532 | sizeof(struct ext3_inode_info), |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 533 | 0, (SLAB_RECLAIM_ACCOUNT| |
| 534 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 535 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (ext3_inode_cachep == NULL) |
| 537 | return -ENOMEM; |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | static void destroy_inodecache(void) |
| 542 | { |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 543 | /* |
| 544 | * Make sure all delayed rcu free inodes are flushed before we |
| 545 | * destroy cache. |
| 546 | */ |
| 547 | rcu_barrier(); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 548 | kmem_cache_destroy(ext3_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Peter Osterlund | 6cd37cd | 2005-10-28 20:23:39 +0200 | [diff] [blame] | 551 | static inline void ext3_show_quota_options(struct seq_file *seq, struct super_block *sb) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 552 | { |
Peter Osterlund | 6cd37cd | 2005-10-28 20:23:39 +0200 | [diff] [blame] | 553 | #if defined(CONFIG_QUOTA) |
OGAWA Hirofumi | 275abf5 | 2005-09-22 21:44:03 -0700 | [diff] [blame] | 554 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Jan Kara | 1aeec43 | 2009-11-30 22:22:41 +0100 | [diff] [blame] | 556 | if (sbi->s_jquota_fmt) { |
| 557 | char *fmtname = ""; |
| 558 | |
| 559 | switch (sbi->s_jquota_fmt) { |
| 560 | case QFMT_VFS_OLD: |
| 561 | fmtname = "vfsold"; |
| 562 | break; |
| 563 | case QFMT_VFS_V0: |
| 564 | fmtname = "vfsv0"; |
| 565 | break; |
| 566 | case QFMT_VFS_V1: |
| 567 | fmtname = "vfsv1"; |
| 568 | break; |
| 569 | } |
| 570 | seq_printf(seq, ",jqfmt=%s", fmtname); |
| 571 | } |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 572 | |
| 573 | if (sbi->s_qf_names[USRQUOTA]) |
| 574 | seq_printf(seq, ",usrjquota=%s", sbi->s_qf_names[USRQUOTA]); |
| 575 | |
| 576 | if (sbi->s_qf_names[GRPQUOTA]) |
| 577 | seq_printf(seq, ",grpjquota=%s", sbi->s_qf_names[GRPQUOTA]); |
| 578 | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 579 | if (test_opt(sb, USRQUOTA)) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 580 | seq_puts(seq, ",usrquota"); |
| 581 | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 582 | if (test_opt(sb, GRPQUOTA)) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 583 | seq_puts(seq, ",grpquota"); |
| 584 | #endif |
Peter Osterlund | 6cd37cd | 2005-10-28 20:23:39 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Jan Kara | 3c4cec6 | 2009-08-24 16:38:43 +0200 | [diff] [blame] | 587 | static char *data_mode_string(unsigned long mode) |
| 588 | { |
| 589 | switch (mode) { |
| 590 | case EXT3_MOUNT_JOURNAL_DATA: |
| 591 | return "journal"; |
| 592 | case EXT3_MOUNT_ORDERED_DATA: |
| 593 | return "ordered"; |
| 594 | case EXT3_MOUNT_WRITEBACK_DATA: |
| 595 | return "writeback"; |
| 596 | } |
| 597 | return "unknown"; |
| 598 | } |
| 599 | |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 600 | /* |
| 601 | * Show an option if |
| 602 | * - it's set to a non-default value OR |
| 603 | * - if the per-sb default is different from the global default |
| 604 | */ |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 605 | static int ext3_show_options(struct seq_file *seq, struct dentry *root) |
Peter Osterlund | 6cd37cd | 2005-10-28 20:23:39 +0200 | [diff] [blame] | 606 | { |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 607 | struct super_block *sb = root->d_sb; |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 608 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 609 | struct ext3_super_block *es = sbi->s_es; |
| 610 | unsigned long def_mount_opts; |
| 611 | |
| 612 | def_mount_opts = le32_to_cpu(es->s_default_mount_opts); |
| 613 | |
| 614 | if (sbi->s_sb_block != 1) |
| 615 | seq_printf(seq, ",sb=%lu", sbi->s_sb_block); |
| 616 | if (test_opt(sb, MINIX_DF)) |
| 617 | seq_puts(seq, ",minixdf"); |
| 618 | if (test_opt(sb, GRPID)) |
| 619 | seq_puts(seq, ",grpid"); |
| 620 | if (!test_opt(sb, GRPID) && (def_mount_opts & EXT3_DEFM_BSDGROUPS)) |
| 621 | seq_puts(seq, ",nogrpid"); |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 622 | if (!uid_eq(sbi->s_resuid, make_kuid(&init_user_ns, EXT3_DEF_RESUID)) || |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 623 | le16_to_cpu(es->s_def_resuid) != EXT3_DEF_RESUID) { |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 624 | seq_printf(seq, ",resuid=%u", |
| 625 | from_kuid_munged(&init_user_ns, sbi->s_resuid)); |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 626 | } |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 627 | if (!gid_eq(sbi->s_resgid, make_kgid(&init_user_ns, EXT3_DEF_RESGID)) || |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 628 | le16_to_cpu(es->s_def_resgid) != EXT3_DEF_RESGID) { |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 629 | seq_printf(seq, ",resgid=%u", |
| 630 | from_kgid_munged(&init_user_ns, sbi->s_resgid)); |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 631 | } |
Aneesh Kumar K.V | 1eca93f | 2008-02-06 01:40:14 -0800 | [diff] [blame] | 632 | if (test_opt(sb, ERRORS_RO)) { |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 633 | int def_errors = le16_to_cpu(es->s_errors); |
| 634 | |
| 635 | if (def_errors == EXT3_ERRORS_PANIC || |
Aneesh Kumar K.V | 1eca93f | 2008-02-06 01:40:14 -0800 | [diff] [blame] | 636 | def_errors == EXT3_ERRORS_CONTINUE) { |
| 637 | seq_puts(seq, ",errors=remount-ro"); |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 638 | } |
| 639 | } |
Aneesh Kumar K.V | 1eca93f | 2008-02-06 01:40:14 -0800 | [diff] [blame] | 640 | if (test_opt(sb, ERRORS_CONT)) |
| 641 | seq_puts(seq, ",errors=continue"); |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 642 | if (test_opt(sb, ERRORS_PANIC)) |
| 643 | seq_puts(seq, ",errors=panic"); |
| 644 | if (test_opt(sb, NO_UID32)) |
| 645 | seq_puts(seq, ",nouid32"); |
| 646 | if (test_opt(sb, DEBUG)) |
| 647 | seq_puts(seq, ",debug"); |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 648 | #ifdef CONFIG_EXT3_FS_XATTR |
| 649 | if (test_opt(sb, XATTR_USER)) |
| 650 | seq_puts(seq, ",user_xattr"); |
| 651 | if (!test_opt(sb, XATTR_USER) && |
| 652 | (def_mount_opts & EXT3_DEFM_XATTR_USER)) { |
| 653 | seq_puts(seq, ",nouser_xattr"); |
| 654 | } |
| 655 | #endif |
| 656 | #ifdef CONFIG_EXT3_FS_POSIX_ACL |
| 657 | if (test_opt(sb, POSIX_ACL)) |
| 658 | seq_puts(seq, ",acl"); |
| 659 | if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT3_DEFM_ACL)) |
| 660 | seq_puts(seq, ",noacl"); |
| 661 | #endif |
| 662 | if (!test_opt(sb, RESERVATION)) |
| 663 | seq_puts(seq, ",noreservation"); |
| 664 | if (sbi->s_commit_interval) { |
| 665 | seq_printf(seq, ",commit=%u", |
| 666 | (unsigned) (sbi->s_commit_interval / HZ)); |
| 667 | } |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 668 | |
| 669 | /* |
| 670 | * Always display barrier state so it's clear what the status is. |
| 671 | */ |
| 672 | seq_puts(seq, ",barrier="); |
| 673 | seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0"); |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 674 | seq_printf(seq, ",data=%s", data_mode_string(test_opt(sb, DATA_FLAGS))); |
Hidehiro Kawai | 0e4fb5e | 2008-10-18 20:27:57 -0700 | [diff] [blame] | 675 | if (test_opt(sb, DATA_ERR_ABORT)) |
| 676 | seq_puts(seq, ",data_err=abort"); |
| 677 | |
Eric Sandeen | dee1d3b | 2009-11-16 16:50:49 -0600 | [diff] [blame] | 678 | if (test_opt(sb, NOLOAD)) |
| 679 | seq_puts(seq, ",norecovery"); |
| 680 | |
Peter Osterlund | 6cd37cd | 2005-10-28 20:23:39 +0200 | [diff] [blame] | 681 | ext3_show_quota_options(seq, sb); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 682 | |
| 683 | return 0; |
| 684 | } |
| 685 | |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 686 | |
Christoph Hellwig | 74af0ba | 2007-10-21 16:42:07 -0700 | [diff] [blame] | 687 | static struct inode *ext3_nfs_get_inode(struct super_block *sb, |
| 688 | u64 ino, u32 generation) |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 689 | { |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 690 | struct inode *inode; |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 691 | |
| 692 | if (ino < EXT3_FIRST_INO(sb) && ino != EXT3_ROOT_INO) |
| 693 | return ERR_PTR(-ESTALE); |
| 694 | if (ino > le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)) |
| 695 | return ERR_PTR(-ESTALE); |
| 696 | |
| 697 | /* iget isn't really right if the inode is currently unallocated!! |
| 698 | * |
| 699 | * ext3_read_inode will return a bad_inode if the inode had been |
| 700 | * deleted, so we should be safe. |
| 701 | * |
| 702 | * Currently we don't know the generation for parent directory, so |
| 703 | * a generation of 0 means "accept any" |
| 704 | */ |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 705 | inode = ext3_iget(sb, ino); |
| 706 | if (IS_ERR(inode)) |
| 707 | return ERR_CAST(inode); |
| 708 | if (generation && inode->i_generation != generation) { |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 709 | iput(inode); |
| 710 | return ERR_PTR(-ESTALE); |
| 711 | } |
Christoph Hellwig | 74af0ba | 2007-10-21 16:42:07 -0700 | [diff] [blame] | 712 | |
| 713 | return inode; |
| 714 | } |
| 715 | |
| 716 | static struct dentry *ext3_fh_to_dentry(struct super_block *sb, struct fid *fid, |
| 717 | int fh_len, int fh_type) |
| 718 | { |
| 719 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 720 | ext3_nfs_get_inode); |
| 721 | } |
| 722 | |
| 723 | static struct dentry *ext3_fh_to_parent(struct super_block *sb, struct fid *fid, |
| 724 | int fh_len, int fh_type) |
| 725 | { |
| 726 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 727 | ext3_nfs_get_inode); |
NeilBrown | fdb3667 | 2006-09-16 12:15:38 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Toshiyuki Okajima | 6b082b5 | 2009-01-05 22:38:14 -0500 | [diff] [blame] | 730 | /* |
| 731 | * Try to release metadata pages (indirect blocks, directories) which are |
| 732 | * mapped via the block device. Since these pages could have journal heads |
| 733 | * which would prevent try_to_free_buffers() from freeing them, we must use |
| 734 | * jbd layer's try_to_free_buffers() function to release them. |
| 735 | */ |
| 736 | static int bdev_try_to_free_page(struct super_block *sb, struct page *page, |
| 737 | gfp_t wait) |
| 738 | { |
| 739 | journal_t *journal = EXT3_SB(sb)->s_journal; |
| 740 | |
| 741 | WARN_ON(PageChecked(page)); |
| 742 | if (!page_has_buffers(page)) |
| 743 | return 0; |
| 744 | if (journal) |
| 745 | return journal_try_to_free_buffers(journal, page, |
| 746 | wait & ~__GFP_WAIT); |
| 747 | return try_to_free_buffers(page); |
| 748 | } |
| 749 | |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 750 | #ifdef CONFIG_QUOTA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") |
| 752 | #define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | static int ext3_write_dquot(struct dquot *dquot); |
| 755 | static int ext3_acquire_dquot(struct dquot *dquot); |
| 756 | static int ext3_release_dquot(struct dquot *dquot); |
| 757 | static int ext3_mark_dquot_dirty(struct dquot *dquot); |
| 758 | static int ext3_write_info(struct super_block *sb, int type); |
Jan Kara | 2fd83a4 | 2008-04-28 02:14:34 -0700 | [diff] [blame] | 759 | static int ext3_quota_on(struct super_block *sb, int type, int format_id, |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 760 | struct path *path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | static int ext3_quota_on_mount(struct super_block *sb, int type); |
| 762 | static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, |
| 763 | size_t len, loff_t off); |
| 764 | static ssize_t ext3_quota_write(struct super_block *sb, int type, |
| 765 | const char *data, size_t len, loff_t off); |
| 766 | |
Alexey Dobriyan | 61e225d | 2009-09-21 17:01:08 -0700 | [diff] [blame] | 767 | static const struct dquot_operations ext3_quota_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | .write_dquot = ext3_write_dquot, |
| 769 | .acquire_dquot = ext3_acquire_dquot, |
| 770 | .release_dquot = ext3_release_dquot, |
| 771 | .mark_dirty = ext3_mark_dquot_dirty, |
Jan Kara | 157091a | 2008-11-25 15:31:34 +0100 | [diff] [blame] | 772 | .write_info = ext3_write_info, |
| 773 | .alloc_dquot = dquot_alloc, |
| 774 | .destroy_dquot = dquot_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | }; |
| 776 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 777 | static const struct quotactl_ops ext3_qctl_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | .quota_on = ext3_quota_on, |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 779 | .quota_off = dquot_quota_off, |
| 780 | .quota_sync = dquot_quota_sync, |
| 781 | .get_info = dquot_get_dqinfo, |
| 782 | .set_info = dquot_set_dqinfo, |
| 783 | .get_dqblk = dquot_get_dqblk, |
| 784 | .set_dqblk = dquot_set_dqblk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | }; |
| 786 | #endif |
| 787 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 788 | static const struct super_operations ext3_sops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | .alloc_inode = ext3_alloc_inode, |
| 790 | .destroy_inode = ext3_destroy_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | .write_inode = ext3_write_inode, |
| 792 | .dirty_inode = ext3_dirty_inode, |
Lukas Czerner | 785c4bc | 2011-05-23 18:33:01 +0200 | [diff] [blame] | 793 | .drop_inode = ext3_drop_inode, |
Al Viro | ac14a95 | 2010-06-06 07:08:19 -0400 | [diff] [blame] | 794 | .evict_inode = ext3_evict_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | .put_super = ext3_put_super, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | .sync_fs = ext3_sync_fs, |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 797 | .freeze_fs = ext3_freeze, |
| 798 | .unfreeze_fs = ext3_unfreeze, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | .statfs = ext3_statfs, |
| 800 | .remount_fs = ext3_remount, |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 801 | .show_options = ext3_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | #ifdef CONFIG_QUOTA |
| 803 | .quota_read = ext3_quota_read, |
| 804 | .quota_write = ext3_quota_write, |
| 805 | #endif |
Toshiyuki Okajima | 6b082b5 | 2009-01-05 22:38:14 -0500 | [diff] [blame] | 806 | .bdev_try_to_free_page = bdev_try_to_free_page, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | }; |
| 808 | |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 809 | static const struct export_operations ext3_export_ops = { |
Christoph Hellwig | 74af0ba | 2007-10-21 16:42:07 -0700 | [diff] [blame] | 810 | .fh_to_dentry = ext3_fh_to_dentry, |
| 811 | .fh_to_parent = ext3_fh_to_parent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | .get_parent = ext3_get_parent, |
| 813 | }; |
| 814 | |
| 815 | enum { |
| 816 | Opt_bsd_df, Opt_minix_df, Opt_grpid, Opt_nogrpid, |
| 817 | Opt_resgid, Opt_resuid, Opt_sb, Opt_err_cont, Opt_err_panic, Opt_err_ro, |
Adrian Bunk | 2860b73 | 2005-11-08 21:34:59 -0800 | [diff] [blame] | 818 | Opt_nouid32, Opt_nocheck, Opt_debug, Opt_oldalloc, Opt_orlov, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, |
Badari Pulavarty | ade1a29 | 2006-06-26 00:25:04 -0700 | [diff] [blame] | 820 | Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 821 | Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, |
Hidehiro Kawai | 0e4fb5e | 2008-10-18 20:27:57 -0700 | [diff] [blame] | 823 | Opt_data_err_abort, Opt_data_err_ignore, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, |
Jan Kara | 1aeec43 | 2009-11-30 22:22:41 +0100 | [diff] [blame] | 825 | Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota, |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 826 | Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, |
| 827 | Opt_resize, Opt_usrquota, Opt_grpquota |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | }; |
| 829 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 830 | static const match_table_t tokens = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | {Opt_bsd_df, "bsddf"}, |
| 832 | {Opt_minix_df, "minixdf"}, |
| 833 | {Opt_grpid, "grpid"}, |
| 834 | {Opt_grpid, "bsdgroups"}, |
| 835 | {Opt_nogrpid, "nogrpid"}, |
| 836 | {Opt_nogrpid, "sysvgroups"}, |
| 837 | {Opt_resgid, "resgid=%u"}, |
| 838 | {Opt_resuid, "resuid=%u"}, |
| 839 | {Opt_sb, "sb=%u"}, |
| 840 | {Opt_err_cont, "errors=continue"}, |
| 841 | {Opt_err_panic, "errors=panic"}, |
| 842 | {Opt_err_ro, "errors=remount-ro"}, |
| 843 | {Opt_nouid32, "nouid32"}, |
| 844 | {Opt_nocheck, "nocheck"}, |
| 845 | {Opt_nocheck, "check=none"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | {Opt_debug, "debug"}, |
| 847 | {Opt_oldalloc, "oldalloc"}, |
| 848 | {Opt_orlov, "orlov"}, |
| 849 | {Opt_user_xattr, "user_xattr"}, |
| 850 | {Opt_nouser_xattr, "nouser_xattr"}, |
| 851 | {Opt_acl, "acl"}, |
| 852 | {Opt_noacl, "noacl"}, |
| 853 | {Opt_reservation, "reservation"}, |
| 854 | {Opt_noreservation, "noreservation"}, |
| 855 | {Opt_noload, "noload"}, |
Eric Sandeen | dee1d3b | 2009-11-16 16:50:49 -0600 | [diff] [blame] | 856 | {Opt_noload, "norecovery"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | {Opt_nobh, "nobh"}, |
Badari Pulavarty | ade1a29 | 2006-06-26 00:25:04 -0700 | [diff] [blame] | 858 | {Opt_bh, "bh"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | {Opt_commit, "commit=%u"}, |
| 860 | {Opt_journal_update, "journal=update"}, |
| 861 | {Opt_journal_inum, "journal=%u"}, |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 862 | {Opt_journal_dev, "journal_dev=%u"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | {Opt_abort, "abort"}, |
| 864 | {Opt_data_journal, "data=journal"}, |
| 865 | {Opt_data_ordered, "data=ordered"}, |
| 866 | {Opt_data_writeback, "data=writeback"}, |
Hidehiro Kawai | 0e4fb5e | 2008-10-18 20:27:57 -0700 | [diff] [blame] | 867 | {Opt_data_err_abort, "data_err=abort"}, |
| 868 | {Opt_data_err_ignore, "data_err=ignore"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | {Opt_offusrjquota, "usrjquota="}, |
| 870 | {Opt_usrjquota, "usrjquota=%s"}, |
| 871 | {Opt_offgrpjquota, "grpjquota="}, |
| 872 | {Opt_grpjquota, "grpjquota=%s"}, |
| 873 | {Opt_jqfmt_vfsold, "jqfmt=vfsold"}, |
| 874 | {Opt_jqfmt_vfsv0, "jqfmt=vfsv0"}, |
Jan Kara | 1aeec43 | 2009-11-30 22:22:41 +0100 | [diff] [blame] | 875 | {Opt_jqfmt_vfsv1, "jqfmt=vfsv1"}, |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 876 | {Opt_grpquota, "grpquota"}, |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 877 | {Opt_noquota, "noquota"}, |
| 878 | {Opt_quota, "quota"}, |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 879 | {Opt_usrquota, "usrquota"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | {Opt_barrier, "barrier=%u"}, |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 881 | {Opt_barrier, "barrier"}, |
| 882 | {Opt_nobarrier, "nobarrier"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | {Opt_resize, "resize"}, |
Josef Bacik | 92587216 | 2008-03-04 14:29:43 -0800 | [diff] [blame] | 884 | {Opt_err, NULL}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | }; |
| 886 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 887 | static ext3_fsblk_t get_sb_block(void **data, struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Dave Kleikamp | e9ad562 | 2006-09-27 01:49:35 -0700 | [diff] [blame] | 889 | ext3_fsblk_t sb_block; |
| 890 | char *options = (char *) *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
| 892 | if (!options || strncmp(options, "sb=", 3) != 0) |
| 893 | return 1; /* Default location */ |
| 894 | options += 3; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 895 | /*todo: use simple_strtoll with >32bit ext3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | sb_block = simple_strtoul(options, &options, 0); |
| 897 | if (*options && *options != ',') { |
Lars-Peter Clausen | 8d0c2d1 | 2013-03-09 15:28:44 +0100 | [diff] [blame] | 898 | ext3_msg(sb, KERN_ERR, "error: invalid sb specification: %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | (char *) *data); |
| 900 | return 1; |
| 901 | } |
| 902 | if (*options == ',') |
| 903 | options++; |
| 904 | *data = (void *) options; |
| 905 | return sb_block; |
| 906 | } |
| 907 | |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 908 | #ifdef CONFIG_QUOTA |
| 909 | static int set_qf_name(struct super_block *sb, int qtype, substring_t *args) |
| 910 | { |
| 911 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 912 | char *qname; |
| 913 | |
| 914 | if (sb_any_quota_loaded(sb) && |
| 915 | !sbi->s_qf_names[qtype]) { |
| 916 | ext3_msg(sb, KERN_ERR, |
| 917 | "Cannot change journaled " |
| 918 | "quota options when quota turned on"); |
| 919 | return 0; |
| 920 | } |
| 921 | qname = match_strdup(args); |
| 922 | if (!qname) { |
| 923 | ext3_msg(sb, KERN_ERR, |
| 924 | "Not enough memory for storing quotafile name"); |
| 925 | return 0; |
| 926 | } |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 927 | if (sbi->s_qf_names[qtype]) { |
| 928 | int same = !strcmp(sbi->s_qf_names[qtype], qname); |
| 929 | |
| 930 | kfree(qname); |
| 931 | if (!same) { |
| 932 | ext3_msg(sb, KERN_ERR, |
| 933 | "%s quota file already specified", |
| 934 | QTYPE2NAME(qtype)); |
| 935 | } |
| 936 | return same; |
| 937 | } |
| 938 | if (strchr(qname, '/')) { |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 939 | ext3_msg(sb, KERN_ERR, |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 940 | "quotafile must be on filesystem root"); |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 941 | kfree(qname); |
| 942 | return 0; |
| 943 | } |
| 944 | sbi->s_qf_names[qtype] = qname; |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 945 | set_opt(sbi->s_mount_opt, QUOTA); |
| 946 | return 1; |
| 947 | } |
| 948 | |
| 949 | static int clear_qf_name(struct super_block *sb, int qtype) { |
| 950 | |
| 951 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 952 | |
| 953 | if (sb_any_quota_loaded(sb) && |
| 954 | sbi->s_qf_names[qtype]) { |
| 955 | ext3_msg(sb, KERN_ERR, "Cannot change journaled quota options" |
| 956 | " when quota turned on"); |
| 957 | return 0; |
| 958 | } |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 959 | if (sbi->s_qf_names[qtype]) { |
| 960 | kfree(sbi->s_qf_names[qtype]); |
| 961 | sbi->s_qf_names[qtype] = NULL; |
| 962 | } |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 963 | return 1; |
| 964 | } |
| 965 | #endif |
| 966 | |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 967 | static int parse_options (char *options, struct super_block *sb, |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 968 | unsigned int *inum, unsigned long *journal_devnum, |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 969 | ext3_fsblk_t *n_blocks_count, int is_remount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | { |
| 971 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 972 | char * p; |
| 973 | substring_t args[MAX_OPT_ARGS]; |
| 974 | int data_opt = 0; |
| 975 | int option; |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 976 | kuid_t uid; |
| 977 | kgid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | #ifdef CONFIG_QUOTA |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 979 | int qfmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | #endif |
| 981 | |
| 982 | if (!options) |
| 983 | return 1; |
| 984 | |
| 985 | while ((p = strsep (&options, ",")) != NULL) { |
| 986 | int token; |
| 987 | if (!*p) |
| 988 | continue; |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 989 | /* |
| 990 | * Initialize args struct so we know whether arg was |
| 991 | * found; some options take optional arguments. |
| 992 | */ |
Sachin Kamat | 76f59b3 | 2012-09-04 13:42:00 +0530 | [diff] [blame] | 993 | args[0].to = args[0].from = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | token = match_token(p, tokens, args); |
| 995 | switch (token) { |
| 996 | case Opt_bsd_df: |
| 997 | clear_opt (sbi->s_mount_opt, MINIX_DF); |
| 998 | break; |
| 999 | case Opt_minix_df: |
| 1000 | set_opt (sbi->s_mount_opt, MINIX_DF); |
| 1001 | break; |
| 1002 | case Opt_grpid: |
| 1003 | set_opt (sbi->s_mount_opt, GRPID); |
| 1004 | break; |
| 1005 | case Opt_nogrpid: |
| 1006 | clear_opt (sbi->s_mount_opt, GRPID); |
| 1007 | break; |
| 1008 | case Opt_resuid: |
| 1009 | if (match_int(&args[0], &option)) |
| 1010 | return 0; |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 1011 | uid = make_kuid(current_user_ns(), option); |
| 1012 | if (!uid_valid(uid)) { |
| 1013 | ext3_msg(sb, KERN_ERR, "Invalid uid value %d", option); |
Zhao Hongjiang | 66415f6 | 2012-10-09 13:48:47 +0800 | [diff] [blame] | 1014 | return 0; |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 1015 | |
| 1016 | } |
| 1017 | sbi->s_resuid = uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | break; |
| 1019 | case Opt_resgid: |
| 1020 | if (match_int(&args[0], &option)) |
| 1021 | return 0; |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 1022 | gid = make_kgid(current_user_ns(), option); |
| 1023 | if (!gid_valid(gid)) { |
| 1024 | ext3_msg(sb, KERN_ERR, "Invalid gid value %d", option); |
Zhao Hongjiang | 66415f6 | 2012-10-09 13:48:47 +0800 | [diff] [blame] | 1025 | return 0; |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 1026 | } |
| 1027 | sbi->s_resgid = gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | break; |
| 1029 | case Opt_sb: |
| 1030 | /* handled by get_sb_block() instead of here */ |
| 1031 | /* *sb_block = match_int(&args[0]); */ |
| 1032 | break; |
| 1033 | case Opt_err_panic: |
| 1034 | clear_opt (sbi->s_mount_opt, ERRORS_CONT); |
| 1035 | clear_opt (sbi->s_mount_opt, ERRORS_RO); |
| 1036 | set_opt (sbi->s_mount_opt, ERRORS_PANIC); |
| 1037 | break; |
| 1038 | case Opt_err_ro: |
| 1039 | clear_opt (sbi->s_mount_opt, ERRORS_CONT); |
| 1040 | clear_opt (sbi->s_mount_opt, ERRORS_PANIC); |
| 1041 | set_opt (sbi->s_mount_opt, ERRORS_RO); |
| 1042 | break; |
| 1043 | case Opt_err_cont: |
| 1044 | clear_opt (sbi->s_mount_opt, ERRORS_RO); |
| 1045 | clear_opt (sbi->s_mount_opt, ERRORS_PANIC); |
| 1046 | set_opt (sbi->s_mount_opt, ERRORS_CONT); |
| 1047 | break; |
| 1048 | case Opt_nouid32: |
| 1049 | set_opt (sbi->s_mount_opt, NO_UID32); |
| 1050 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | case Opt_nocheck: |
| 1052 | clear_opt (sbi->s_mount_opt, CHECK); |
| 1053 | break; |
| 1054 | case Opt_debug: |
| 1055 | set_opt (sbi->s_mount_opt, DEBUG); |
| 1056 | break; |
| 1057 | case Opt_oldalloc: |
Lukas Czerner | fbc8540 | 2011-08-16 18:08:06 +0200 | [diff] [blame] | 1058 | ext3_msg(sb, KERN_WARNING, |
| 1059 | "Ignoring deprecated oldalloc option"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | break; |
| 1061 | case Opt_orlov: |
Lukas Czerner | fbc8540 | 2011-08-16 18:08:06 +0200 | [diff] [blame] | 1062 | ext3_msg(sb, KERN_WARNING, |
| 1063 | "Ignoring deprecated orlov option"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | break; |
| 1065 | #ifdef CONFIG_EXT3_FS_XATTR |
| 1066 | case Opt_user_xattr: |
| 1067 | set_opt (sbi->s_mount_opt, XATTR_USER); |
| 1068 | break; |
| 1069 | case Opt_nouser_xattr: |
| 1070 | clear_opt (sbi->s_mount_opt, XATTR_USER); |
| 1071 | break; |
| 1072 | #else |
| 1073 | case Opt_user_xattr: |
| 1074 | case Opt_nouser_xattr: |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1075 | ext3_msg(sb, KERN_INFO, |
| 1076 | "(no)user_xattr options not supported"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | break; |
| 1078 | #endif |
| 1079 | #ifdef CONFIG_EXT3_FS_POSIX_ACL |
| 1080 | case Opt_acl: |
| 1081 | set_opt(sbi->s_mount_opt, POSIX_ACL); |
| 1082 | break; |
| 1083 | case Opt_noacl: |
| 1084 | clear_opt(sbi->s_mount_opt, POSIX_ACL); |
| 1085 | break; |
| 1086 | #else |
| 1087 | case Opt_acl: |
| 1088 | case Opt_noacl: |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1089 | ext3_msg(sb, KERN_INFO, |
| 1090 | "(no)acl options not supported"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | break; |
| 1092 | #endif |
| 1093 | case Opt_reservation: |
| 1094 | set_opt(sbi->s_mount_opt, RESERVATION); |
| 1095 | break; |
| 1096 | case Opt_noreservation: |
| 1097 | clear_opt(sbi->s_mount_opt, RESERVATION); |
| 1098 | break; |
| 1099 | case Opt_journal_update: |
| 1100 | /* @@@ FIXME */ |
| 1101 | /* Eventually we will want to be able to create |
| 1102 | a journal file here. For now, only allow the |
| 1103 | user to specify an existing inode to be the |
| 1104 | journal file. */ |
| 1105 | if (is_remount) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1106 | ext3_msg(sb, KERN_ERR, "error: cannot specify " |
| 1107 | "journal on remount"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | return 0; |
| 1109 | } |
| 1110 | set_opt (sbi->s_mount_opt, UPDATE_JOURNAL); |
| 1111 | break; |
| 1112 | case Opt_journal_inum: |
| 1113 | if (is_remount) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1114 | ext3_msg(sb, KERN_ERR, "error: cannot specify " |
| 1115 | "journal on remount"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | if (match_int(&args[0], &option)) |
| 1119 | return 0; |
| 1120 | *inum = option; |
| 1121 | break; |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 1122 | case Opt_journal_dev: |
| 1123 | if (is_remount) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1124 | ext3_msg(sb, KERN_ERR, "error: cannot specify " |
| 1125 | "journal on remount"); |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | if (match_int(&args[0], &option)) |
| 1129 | return 0; |
| 1130 | *journal_devnum = option; |
| 1131 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | case Opt_noload: |
| 1133 | set_opt (sbi->s_mount_opt, NOLOAD); |
| 1134 | break; |
| 1135 | case Opt_commit: |
| 1136 | if (match_int(&args[0], &option)) |
| 1137 | return 0; |
| 1138 | if (option < 0) |
| 1139 | return 0; |
| 1140 | if (option == 0) |
| 1141 | option = JBD_DEFAULT_MAX_COMMIT_AGE; |
| 1142 | sbi->s_commit_interval = HZ * option; |
| 1143 | break; |
| 1144 | case Opt_data_journal: |
| 1145 | data_opt = EXT3_MOUNT_JOURNAL_DATA; |
| 1146 | goto datacheck; |
| 1147 | case Opt_data_ordered: |
| 1148 | data_opt = EXT3_MOUNT_ORDERED_DATA; |
| 1149 | goto datacheck; |
| 1150 | case Opt_data_writeback: |
| 1151 | data_opt = EXT3_MOUNT_WRITEBACK_DATA; |
| 1152 | datacheck: |
| 1153 | if (is_remount) { |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1154 | if (test_opt(sb, DATA_FLAGS) == data_opt) |
Jan Kara | 3c4cec6 | 2009-08-24 16:38:43 +0200 | [diff] [blame] | 1155 | break; |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1156 | ext3_msg(sb, KERN_ERR, |
| 1157 | "error: cannot change " |
Jan Kara | 3c4cec6 | 2009-08-24 16:38:43 +0200 | [diff] [blame] | 1158 | "data mode on remount. The filesystem " |
| 1159 | "is mounted in data=%s mode and you " |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1160 | "try to remount it in data=%s mode.", |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1161 | data_mode_string(test_opt(sb, |
| 1162 | DATA_FLAGS)), |
Jan Kara | 3c4cec6 | 2009-08-24 16:38:43 +0200 | [diff] [blame] | 1163 | data_mode_string(data_opt)); |
| 1164 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | } else { |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1166 | clear_opt(sbi->s_mount_opt, DATA_FLAGS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | sbi->s_mount_opt |= data_opt; |
| 1168 | } |
| 1169 | break; |
Hidehiro Kawai | 0e4fb5e | 2008-10-18 20:27:57 -0700 | [diff] [blame] | 1170 | case Opt_data_err_abort: |
| 1171 | set_opt(sbi->s_mount_opt, DATA_ERR_ABORT); |
| 1172 | break; |
| 1173 | case Opt_data_err_ignore: |
| 1174 | clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); |
| 1175 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | #ifdef CONFIG_QUOTA |
| 1177 | case Opt_usrjquota: |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 1178 | if (!set_qf_name(sb, USRQUOTA, &args[0])) |
| 1179 | return 0; |
| 1180 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | case Opt_grpjquota: |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 1182 | if (!set_qf_name(sb, GRPQUOTA, &args[0])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | break; |
| 1185 | case Opt_offusrjquota: |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 1186 | if (!clear_qf_name(sb, USRQUOTA)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | return 0; |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 1188 | break; |
| 1189 | case Opt_offgrpjquota: |
| 1190 | if (!clear_qf_name(sb, GRPQUOTA)) |
| 1191 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | break; |
| 1193 | case Opt_jqfmt_vfsold: |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1194 | qfmt = QFMT_VFS_OLD; |
| 1195 | goto set_qf_format; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | case Opt_jqfmt_vfsv0: |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1197 | qfmt = QFMT_VFS_V0; |
Jan Kara | 1aeec43 | 2009-11-30 22:22:41 +0100 | [diff] [blame] | 1198 | goto set_qf_format; |
| 1199 | case Opt_jqfmt_vfsv1: |
| 1200 | qfmt = QFMT_VFS_V1; |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1201 | set_qf_format: |
Jan Kara | ee0d5ff | 2008-08-20 18:11:50 +0200 | [diff] [blame] | 1202 | if (sb_any_quota_loaded(sb) && |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1203 | sbi->s_jquota_fmt != qfmt) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1204 | ext3_msg(sb, KERN_ERR, "error: cannot change " |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1205 | "journaled quota options when " |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1206 | "quota turned on."); |
Jan Kara | d06bf1d | 2008-07-25 01:46:18 -0700 | [diff] [blame] | 1207 | return 0; |
| 1208 | } |
| 1209 | sbi->s_jquota_fmt = qfmt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | break; |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1211 | case Opt_quota: |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1212 | case Opt_usrquota: |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1213 | set_opt(sbi->s_mount_opt, QUOTA); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1214 | set_opt(sbi->s_mount_opt, USRQUOTA); |
| 1215 | break; |
| 1216 | case Opt_grpquota: |
| 1217 | set_opt(sbi->s_mount_opt, QUOTA); |
| 1218 | set_opt(sbi->s_mount_opt, GRPQUOTA); |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1219 | break; |
| 1220 | case Opt_noquota: |
Jan Kara | ee0d5ff | 2008-08-20 18:11:50 +0200 | [diff] [blame] | 1221 | if (sb_any_quota_loaded(sb)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1222 | ext3_msg(sb, KERN_ERR, "error: cannot change " |
| 1223 | "quota options when quota turned on."); |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1224 | return 0; |
| 1225 | } |
| 1226 | clear_opt(sbi->s_mount_opt, QUOTA); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1227 | clear_opt(sbi->s_mount_opt, USRQUOTA); |
| 1228 | clear_opt(sbi->s_mount_opt, GRPQUOTA); |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1229 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | #else |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1231 | case Opt_quota: |
| 1232 | case Opt_usrquota: |
| 1233 | case Opt_grpquota: |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1234 | ext3_msg(sb, KERN_ERR, |
| 1235 | "error: quota options not supported."); |
Jan Kara | fa1ff1e | 2008-04-28 02:16:14 -0700 | [diff] [blame] | 1236 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | case Opt_usrjquota: |
| 1238 | case Opt_grpjquota: |
| 1239 | case Opt_offusrjquota: |
| 1240 | case Opt_offgrpjquota: |
| 1241 | case Opt_jqfmt_vfsold: |
| 1242 | case Opt_jqfmt_vfsv0: |
Jan Kara | 1aeec43 | 2009-11-30 22:22:41 +0100 | [diff] [blame] | 1243 | case Opt_jqfmt_vfsv1: |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1244 | ext3_msg(sb, KERN_ERR, |
| 1245 | "error: journaled quota options not " |
| 1246 | "supported."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | break; |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 1248 | case Opt_noquota: |
| 1249 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | #endif |
| 1251 | case Opt_abort: |
| 1252 | set_opt(sbi->s_mount_opt, ABORT); |
| 1253 | break; |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 1254 | case Opt_nobarrier: |
| 1255 | clear_opt(sbi->s_mount_opt, BARRIER); |
| 1256 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | case Opt_barrier: |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 1258 | if (args[0].from) { |
| 1259 | if (match_int(&args[0], &option)) |
| 1260 | return 0; |
| 1261 | } else |
| 1262 | option = 1; /* No argument, default to 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | if (option) |
| 1264 | set_opt(sbi->s_mount_opt, BARRIER); |
| 1265 | else |
| 1266 | clear_opt(sbi->s_mount_opt, BARRIER); |
| 1267 | break; |
| 1268 | case Opt_ignore: |
| 1269 | break; |
| 1270 | case Opt_resize: |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 1271 | if (!is_remount) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1272 | ext3_msg(sb, KERN_ERR, |
| 1273 | "error: resize option only available " |
| 1274 | "for remount"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return 0; |
| 1276 | } |
KAMBAROV, ZAUR | c7f1721 | 2005-06-28 20:45:11 -0700 | [diff] [blame] | 1277 | if (match_int(&args[0], &option) != 0) |
| 1278 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | *n_blocks_count = option; |
| 1280 | break; |
| 1281 | case Opt_nobh: |
Christoph Hellwig | 4c4d390 | 2010-06-07 10:20:39 +0200 | [diff] [blame] | 1282 | ext3_msg(sb, KERN_WARNING, |
| 1283 | "warning: ignoring deprecated nobh option"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | break; |
Badari Pulavarty | ade1a29 | 2006-06-26 00:25:04 -0700 | [diff] [blame] | 1285 | case Opt_bh: |
Christoph Hellwig | 4c4d390 | 2010-06-07 10:20:39 +0200 | [diff] [blame] | 1286 | ext3_msg(sb, KERN_WARNING, |
| 1287 | "warning: ignoring deprecated bh option"); |
Badari Pulavarty | ade1a29 | 2006-06-26 00:25:04 -0700 | [diff] [blame] | 1288 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | default: |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1290 | ext3_msg(sb, KERN_ERR, |
| 1291 | "error: unrecognized mount option \"%s\" " |
| 1292 | "or missing value", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | return 0; |
| 1294 | } |
| 1295 | } |
| 1296 | #ifdef CONFIG_QUOTA |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1297 | if (sbi->s_qf_names[USRQUOTA] || sbi->s_qf_names[GRPQUOTA]) { |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1298 | if (test_opt(sb, USRQUOTA) && sbi->s_qf_names[USRQUOTA]) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1299 | clear_opt(sbi->s_mount_opt, USRQUOTA); |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1300 | if (test_opt(sb, GRPQUOTA) && sbi->s_qf_names[GRPQUOTA]) |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1301 | clear_opt(sbi->s_mount_opt, GRPQUOTA); |
| 1302 | |
Dmitry Monakhov | e1f5c67 | 2010-02-02 16:05:53 +0300 | [diff] [blame] | 1303 | if (test_opt(sb, GRPQUOTA) || test_opt(sb, USRQUOTA)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1304 | ext3_msg(sb, KERN_ERR, "error: old and new quota " |
| 1305 | "format mixing."); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | if (!sbi->s_jquota_fmt) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1310 | ext3_msg(sb, KERN_ERR, "error: journaled quota format " |
| 1311 | "not specified."); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1312 | return 0; |
| 1313 | } |
| 1314 | } else { |
| 1315 | if (sbi->s_jquota_fmt) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1316 | ext3_msg(sb, KERN_ERR, "error: journaled quota format " |
Jan Kara | 99aeaf6 | 2008-07-25 01:46:17 -0700 | [diff] [blame] | 1317 | "specified with no journaling " |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1318 | "enabled."); |
Mark Bellon | 8fc2751 | 2005-09-06 15:16:54 -0700 | [diff] [blame] | 1319 | return 0; |
| 1320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | return 1; |
| 1324 | } |
| 1325 | |
| 1326 | static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es, |
| 1327 | int read_only) |
| 1328 | { |
| 1329 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 1330 | int res = 0; |
| 1331 | |
| 1332 | if (le32_to_cpu(es->s_rev_level) > EXT3_MAX_SUPP_REV) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1333 | ext3_msg(sb, KERN_ERR, |
| 1334 | "error: revision level too high, " |
| 1335 | "forcing read-only mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | res = MS_RDONLY; |
| 1337 | } |
| 1338 | if (read_only) |
| 1339 | return res; |
| 1340 | if (!(sbi->s_mount_state & EXT3_VALID_FS)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1341 | ext3_msg(sb, KERN_WARNING, |
| 1342 | "warning: mounting unchecked fs, " |
| 1343 | "running e2fsck is recommended"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | else if ((sbi->s_mount_state & EXT3_ERROR_FS)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1345 | ext3_msg(sb, KERN_WARNING, |
| 1346 | "warning: mounting fs with errors, " |
| 1347 | "running e2fsck is recommended"); |
Namhyung Kim | df0d6b8 | 2010-10-10 21:36:59 +0900 | [diff] [blame] | 1348 | else if ((__s16) le16_to_cpu(es->s_max_mnt_count) > 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | le16_to_cpu(es->s_mnt_count) >= |
Namhyung Kim | df0d6b8 | 2010-10-10 21:36:59 +0900 | [diff] [blame] | 1350 | le16_to_cpu(es->s_max_mnt_count)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1351 | ext3_msg(sb, KERN_WARNING, |
| 1352 | "warning: maximal mount count reached, " |
| 1353 | "running e2fsck is recommended"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | else if (le32_to_cpu(es->s_checkinterval) && |
| 1355 | (le32_to_cpu(es->s_lastcheck) + |
| 1356 | le32_to_cpu(es->s_checkinterval) <= get_seconds())) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1357 | ext3_msg(sb, KERN_WARNING, |
| 1358 | "warning: checktime reached, " |
| 1359 | "running e2fsck is recommended"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | #if 0 |
| 1361 | /* @@@ We _will_ want to clear the valid bit if we find |
| 1362 | inconsistencies, to force a fsck at reboot. But for |
| 1363 | a plain journaled filesystem we can keep it set as |
| 1364 | valid forever! :) */ |
Marcin Slusarz | e7f23eb | 2008-04-28 02:16:06 -0700 | [diff] [blame] | 1365 | es->s_state &= cpu_to_le16(~EXT3_VALID_FS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | #endif |
Namhyung Kim | df0d6b8 | 2010-10-10 21:36:59 +0900 | [diff] [blame] | 1367 | if (!le16_to_cpu(es->s_max_mnt_count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT); |
Marcin Slusarz | 50e8a28 | 2008-02-08 04:20:13 -0800 | [diff] [blame] | 1369 | le16_add_cpu(&es->s_mnt_count, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | es->s_mtime = cpu_to_le32(get_seconds()); |
| 1371 | ext3_update_dynamic_rev(sb); |
| 1372 | EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
| 1373 | |
| 1374 | ext3_commit_super(sb, es, 1); |
| 1375 | if (test_opt(sb, DEBUG)) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1376 | ext3_msg(sb, KERN_INFO, "[bs=%lu, gc=%lu, " |
| 1377 | "bpg=%lu, ipg=%lu, mo=%04lx]", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | sb->s_blocksize, |
| 1379 | sbi->s_groups_count, |
| 1380 | EXT3_BLOCKS_PER_GROUP(sb), |
| 1381 | EXT3_INODES_PER_GROUP(sb), |
| 1382 | sbi->s_mount_opt); |
| 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | if (EXT3_SB(sb)->s_journal->j_inode == NULL) { |
| 1385 | char b[BDEVNAME_SIZE]; |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1386 | ext3_msg(sb, KERN_INFO, "using external journal on %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | bdevname(EXT3_SB(sb)->s_journal->j_dev, b)); |
| 1388 | } else { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1389 | ext3_msg(sb, KERN_INFO, "using internal journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } |
Dan Magenheimer | d71bc6d | 2011-05-26 10:01:49 -0600 | [diff] [blame] | 1391 | cleancache_init_fs(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | return res; |
| 1393 | } |
| 1394 | |
| 1395 | /* Called at mount-time, super-block is locked */ |
Akinobu Mita | 197cd65a | 2008-02-06 01:40:16 -0800 | [diff] [blame] | 1396 | static int ext3_check_descriptors(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | { |
| 1398 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | int i; |
| 1400 | |
| 1401 | ext3_debug ("Checking group descriptors"); |
| 1402 | |
Akinobu Mita | 197cd65a | 2008-02-06 01:40:16 -0800 | [diff] [blame] | 1403 | for (i = 0; i < sbi->s_groups_count; i++) { |
| 1404 | struct ext3_group_desc *gdp = ext3_get_group_desc(sb, i, NULL); |
Akinobu Mita | 1eaafea | 2008-04-28 02:16:07 -0700 | [diff] [blame] | 1405 | ext3_fsblk_t first_block = ext3_group_first_block_no(sb, i); |
| 1406 | ext3_fsblk_t last_block; |
Akinobu Mita | 197cd65a | 2008-02-06 01:40:16 -0800 | [diff] [blame] | 1407 | |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1408 | if (i == sbi->s_groups_count - 1) |
| 1409 | last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; |
| 1410 | else |
| 1411 | last_block = first_block + |
| 1412 | (EXT3_BLOCKS_PER_GROUP(sb) - 1); |
| 1413 | |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1414 | if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || |
| 1415 | le32_to_cpu(gdp->bg_block_bitmap) > last_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | { |
| 1417 | ext3_error (sb, "ext3_check_descriptors", |
| 1418 | "Block bitmap for group %d" |
| 1419 | " not in group (block %lu)!", |
| 1420 | i, (unsigned long) |
| 1421 | le32_to_cpu(gdp->bg_block_bitmap)); |
| 1422 | return 0; |
| 1423 | } |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1424 | if (le32_to_cpu(gdp->bg_inode_bitmap) < first_block || |
| 1425 | le32_to_cpu(gdp->bg_inode_bitmap) > last_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
| 1427 | ext3_error (sb, "ext3_check_descriptors", |
| 1428 | "Inode bitmap for group %d" |
| 1429 | " not in group (block %lu)!", |
| 1430 | i, (unsigned long) |
| 1431 | le32_to_cpu(gdp->bg_inode_bitmap)); |
| 1432 | return 0; |
| 1433 | } |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1434 | if (le32_to_cpu(gdp->bg_inode_table) < first_block || |
Eric Sandeen | 780dcdb | 2007-07-26 10:41:11 -0700 | [diff] [blame] | 1435 | le32_to_cpu(gdp->bg_inode_table) + sbi->s_itb_per_group - 1 > |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1436 | last_block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | { |
| 1438 | ext3_error (sb, "ext3_check_descriptors", |
| 1439 | "Inode table for group %d" |
| 1440 | " not in group (block %lu)!", |
| 1441 | i, (unsigned long) |
| 1442 | le32_to_cpu(gdp->bg_inode_table)); |
| 1443 | return 0; |
| 1444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | sbi->s_es->s_free_blocks_count=cpu_to_le32(ext3_count_free_blocks(sb)); |
| 1448 | sbi->s_es->s_free_inodes_count=cpu_to_le32(ext3_count_free_inodes(sb)); |
| 1449 | return 1; |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | /* ext3_orphan_cleanup() walks a singly-linked list of inodes (starting at |
| 1454 | * the superblock) which were deleted from all directories, but held open by |
| 1455 | * a process at the time of a crash. We walk the list and try to delete these |
| 1456 | * inodes at recovery time (only with a read-write filesystem). |
| 1457 | * |
| 1458 | * In order to keep the orphan inode chain consistent during traversal (in |
| 1459 | * case of crash during recovery), we link each inode into the superblock |
| 1460 | * orphan list_head and handle it the same way as an inode deletion during |
| 1461 | * normal operation (which journals the operations for us). |
| 1462 | * |
| 1463 | * We only do an iget() and an iput() on each inode, which is very safe if we |
| 1464 | * accidentally point at an in-use or already deleted inode. The worst that |
| 1465 | * can happen in this case is that we get a "bit already cleared" message from |
| 1466 | * ext3_free_inode(). The only reason we would point at a wrong inode is if |
| 1467 | * e2fsck was run on this filesystem, and it must have already done the orphan |
| 1468 | * inode cleanup for us, so we can safely abort without any further action. |
| 1469 | */ |
| 1470 | static void ext3_orphan_cleanup (struct super_block * sb, |
| 1471 | struct ext3_super_block * es) |
| 1472 | { |
| 1473 | unsigned int s_flags = sb->s_flags; |
| 1474 | int nr_orphans = 0, nr_truncates = 0; |
| 1475 | #ifdef CONFIG_QUOTA |
| 1476 | int i; |
| 1477 | #endif |
| 1478 | if (!es->s_last_orphan) { |
| 1479 | jbd_debug(4, "no orphan inodes to clean up\n"); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
Eric Sandeen | a8f48a9 | 2006-12-06 20:40:13 -0800 | [diff] [blame] | 1483 | if (bdev_read_only(sb->s_bdev)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1484 | ext3_msg(sb, KERN_ERR, "error: write access " |
| 1485 | "unavailable, skipping orphan cleanup."); |
Eric Sandeen | a8f48a9 | 2006-12-06 20:40:13 -0800 | [diff] [blame] | 1486 | return; |
| 1487 | } |
| 1488 | |
Amir Goldstein | ce654b3 | 2011-02-26 22:40:19 +0200 | [diff] [blame] | 1489 | /* Check if feature set allows readwrite operations */ |
| 1490 | if (EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP)) { |
| 1491 | ext3_msg(sb, KERN_INFO, "Skipping orphan cleanup due to " |
| 1492 | "unknown ROCOMPAT features"); |
| 1493 | return; |
| 1494 | } |
| 1495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) { |
Eric Sandeen | e423010 | 2012-08-27 14:30:40 -0500 | [diff] [blame] | 1497 | /* don't clear list on RO mount w/ errors */ |
| 1498 | if (es->s_last_orphan && !(s_flags & MS_RDONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | jbd_debug(1, "Errors on filesystem, " |
| 1500 | "clearing orphan list.\n"); |
Eric Sandeen | e423010 | 2012-08-27 14:30:40 -0500 | [diff] [blame] | 1501 | es->s_last_orphan = 0; |
| 1502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | jbd_debug(1, "Skipping orphan recovery on fs with errors.\n"); |
| 1504 | return; |
| 1505 | } |
| 1506 | |
| 1507 | if (s_flags & MS_RDONLY) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1508 | ext3_msg(sb, KERN_INFO, "orphan cleanup on readonly fs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | sb->s_flags &= ~MS_RDONLY; |
| 1510 | } |
| 1511 | #ifdef CONFIG_QUOTA |
| 1512 | /* Needed for iput() to work correctly and not trash data */ |
| 1513 | sb->s_flags |= MS_ACTIVE; |
| 1514 | /* Turn on quotas so that they are updated correctly */ |
| 1515 | for (i = 0; i < MAXQUOTAS; i++) { |
| 1516 | if (EXT3_SB(sb)->s_qf_names[i]) { |
| 1517 | int ret = ext3_quota_on_mount(sb, i); |
| 1518 | if (ret < 0) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1519 | ext3_msg(sb, KERN_ERR, |
| 1520 | "error: cannot turn on journaled " |
| 1521 | "quota: %d", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | } |
| 1523 | } |
| 1524 | #endif |
| 1525 | |
| 1526 | while (es->s_last_orphan) { |
| 1527 | struct inode *inode; |
| 1528 | |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 1529 | inode = ext3_orphan_get(sb, le32_to_cpu(es->s_last_orphan)); |
| 1530 | if (IS_ERR(inode)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | es->s_last_orphan = 0; |
| 1532 | break; |
| 1533 | } |
| 1534 | |
| 1535 | list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 1536 | dquot_initialize(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | if (inode->i_nlink) { |
| 1538 | printk(KERN_DEBUG |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 1539 | "%s: truncating inode %lu to %Ld bytes\n", |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1540 | __func__, inode->i_ino, inode->i_size); |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 1541 | jbd_debug(2, "truncating inode %lu to %Ld bytes\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | inode->i_ino, inode->i_size); |
| 1543 | ext3_truncate(inode); |
| 1544 | nr_truncates++; |
| 1545 | } else { |
| 1546 | printk(KERN_DEBUG |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 1547 | "%s: deleting unreferenced inode %lu\n", |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 1548 | __func__, inode->i_ino); |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 1549 | jbd_debug(2, "deleting unreferenced inode %lu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | inode->i_ino); |
| 1551 | nr_orphans++; |
| 1552 | } |
| 1553 | iput(inode); /* The delete magic happens here! */ |
| 1554 | } |
| 1555 | |
| 1556 | #define PLURAL(x) (x), ((x)==1) ? "" : "s" |
| 1557 | |
| 1558 | if (nr_orphans) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1559 | ext3_msg(sb, KERN_INFO, "%d orphan inode%s deleted", |
| 1560 | PLURAL(nr_orphans)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | if (nr_truncates) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1562 | ext3_msg(sb, KERN_INFO, "%d truncate%s cleaned up", |
| 1563 | PLURAL(nr_truncates)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | #ifdef CONFIG_QUOTA |
| 1565 | /* Turn quotas off */ |
| 1566 | for (i = 0; i < MAXQUOTAS; i++) { |
| 1567 | if (sb_dqopt(sb)->files[i]) |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 1568 | dquot_quota_off(sb, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | #endif |
| 1571 | sb->s_flags = s_flags; /* Restore MS_RDONLY status */ |
| 1572 | } |
| 1573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | /* |
| 1575 | * Maximal file size. There is a direct, and {,double-,triple-}indirect |
| 1576 | * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. |
| 1577 | * We need to be 1 filesystem block less than the 2^32 sector limit. |
| 1578 | */ |
| 1579 | static loff_t ext3_max_size(int bits) |
| 1580 | { |
| 1581 | loff_t res = EXT3_NDIR_BLOCKS; |
Aneesh Kumar K.V | fe7fdc3 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1582 | int meta_blocks; |
| 1583 | loff_t upper_limit; |
| 1584 | |
| 1585 | /* This is calculated to be the largest file size for a |
| 1586 | * dense, file such that the total number of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | * sectors in the file, including data and all indirect blocks, |
Aneesh Kumar K.V | fe7fdc3 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1588 | * does not exceed 2^32 -1 |
| 1589 | * __u32 i_blocks representing the total number of |
| 1590 | * 512 bytes blocks of the file |
| 1591 | */ |
| 1592 | upper_limit = (1LL << 32) - 1; |
| 1593 | |
| 1594 | /* total blocks in file system block size */ |
| 1595 | upper_limit >>= (bits - 9); |
| 1596 | |
| 1597 | |
| 1598 | /* indirect blocks */ |
| 1599 | meta_blocks = 1; |
| 1600 | /* double indirect blocks */ |
| 1601 | meta_blocks += 1 + (1LL << (bits-2)); |
| 1602 | /* tripple indirect blocks */ |
| 1603 | meta_blocks += 1 + (1LL << (bits-2)) + (1LL << (2*(bits-2))); |
| 1604 | |
| 1605 | upper_limit -= meta_blocks; |
| 1606 | upper_limit <<= bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | |
| 1608 | res += 1LL << (bits-2); |
| 1609 | res += 1LL << (2*(bits-2)); |
| 1610 | res += 1LL << (3*(bits-2)); |
| 1611 | res <<= bits; |
| 1612 | if (res > upper_limit) |
| 1613 | res = upper_limit; |
Aneesh Kumar K.V | fe7fdc3 | 2008-01-28 23:58:26 -0500 | [diff] [blame] | 1614 | |
| 1615 | if (res > MAX_LFS_FILESIZE) |
| 1616 | res = MAX_LFS_FILESIZE; |
| 1617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | return res; |
| 1619 | } |
| 1620 | |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1621 | static ext3_fsblk_t descriptor_loc(struct super_block *sb, |
| 1622 | ext3_fsblk_t logic_sb_block, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | int nr) |
| 1624 | { |
| 1625 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1626 | unsigned long bg, first_meta_bg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | int has_super = 0; |
| 1628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | first_meta_bg = le32_to_cpu(sbi->s_es->s_first_meta_bg); |
| 1630 | |
| 1631 | if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_META_BG) || |
| 1632 | nr < first_meta_bg) |
| 1633 | return (logic_sb_block + nr + 1); |
| 1634 | bg = sbi->s_desc_per_block * nr; |
| 1635 | if (ext3_bg_has_super(sb, bg)) |
| 1636 | has_super = 1; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1637 | return (has_super + ext3_group_first_block_no(sb, bg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | |
| 1641 | static int ext3_fill_super (struct super_block *sb, void *data, int silent) |
| 1642 | { |
| 1643 | struct buffer_head * bh; |
| 1644 | struct ext3_super_block *es = NULL; |
| 1645 | struct ext3_sb_info *sbi; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1646 | ext3_fsblk_t block; |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1647 | ext3_fsblk_t sb_block = get_sb_block(&data, sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 1648 | ext3_fsblk_t logic_sb_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | unsigned long offset = 0; |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 1650 | unsigned int journal_inum = 0; |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 1651 | unsigned long journal_devnum = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | unsigned long def_mount_opts; |
| 1653 | struct inode *root; |
| 1654 | int blocksize; |
| 1655 | int hblock; |
| 1656 | int db_count; |
| 1657 | int i; |
| 1658 | int needs_recovery; |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 1659 | int ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | __le32 features; |
Peter Zijlstra | 833f407 | 2007-10-16 23:25:45 -0700 | [diff] [blame] | 1661 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
Panagiotis Issaris | f8314dc | 2006-09-27 01:49:37 -0700 | [diff] [blame] | 1663 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | if (!sbi) |
| 1665 | return -ENOMEM; |
Pekka Enberg | 5df096d | 2009-01-07 18:07:25 -0800 | [diff] [blame] | 1666 | |
| 1667 | sbi->s_blockgroup_lock = |
| 1668 | kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); |
| 1669 | if (!sbi->s_blockgroup_lock) { |
| 1670 | kfree(sbi); |
| 1671 | return -ENOMEM; |
| 1672 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | sb->s_fs_info = sbi; |
Miklos Szeredi | 571beed | 2007-10-16 23:26:26 -0700 | [diff] [blame] | 1674 | sbi->s_sb_block = sb_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | blocksize = sb_min_blocksize(sb, EXT3_MIN_BLOCK_SIZE); |
| 1677 | if (!blocksize) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1678 | ext3_msg(sb, KERN_ERR, "error: unable to set blocksize"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | goto out_fail; |
| 1680 | } |
| 1681 | |
| 1682 | /* |
| 1683 | * The ext3 superblock will not be buffer aligned for other than 1kB |
| 1684 | * block sizes. We need to calculate the offset from buffer start. |
| 1685 | */ |
| 1686 | if (blocksize != EXT3_MIN_BLOCK_SIZE) { |
| 1687 | logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; |
| 1688 | offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; |
| 1689 | } else { |
| 1690 | logic_sb_block = sb_block; |
| 1691 | } |
| 1692 | |
| 1693 | if (!(bh = sb_bread(sb, logic_sb_block))) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1694 | ext3_msg(sb, KERN_ERR, "error: unable to read superblock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | goto out_fail; |
| 1696 | } |
| 1697 | /* |
| 1698 | * Note: s_es must be initialized as soon as possible because |
| 1699 | * some ext3 macro-instructions depend on its value |
| 1700 | */ |
Namhyung Kim | 57e94d8 | 2010-10-11 02:10:45 +0900 | [diff] [blame] | 1701 | es = (struct ext3_super_block *) (bh->b_data + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | sbi->s_es = es; |
| 1703 | sb->s_magic = le16_to_cpu(es->s_magic); |
| 1704 | if (sb->s_magic != EXT3_SUPER_MAGIC) |
| 1705 | goto cantfind_ext3; |
| 1706 | |
| 1707 | /* Set defaults before we parse the mount options */ |
| 1708 | def_mount_opts = le32_to_cpu(es->s_default_mount_opts); |
| 1709 | if (def_mount_opts & EXT3_DEFM_DEBUG) |
| 1710 | set_opt(sbi->s_mount_opt, DEBUG); |
| 1711 | if (def_mount_opts & EXT3_DEFM_BSDGROUPS) |
| 1712 | set_opt(sbi->s_mount_opt, GRPID); |
| 1713 | if (def_mount_opts & EXT3_DEFM_UID16) |
| 1714 | set_opt(sbi->s_mount_opt, NO_UID32); |
Hugh Dickins | 2e7842b | 2007-02-10 01:46:13 -0800 | [diff] [blame] | 1715 | #ifdef CONFIG_EXT3_FS_XATTR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | if (def_mount_opts & EXT3_DEFM_XATTR_USER) |
| 1717 | set_opt(sbi->s_mount_opt, XATTR_USER); |
Hugh Dickins | 2e7842b | 2007-02-10 01:46:13 -0800 | [diff] [blame] | 1718 | #endif |
| 1719 | #ifdef CONFIG_EXT3_FS_POSIX_ACL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | if (def_mount_opts & EXT3_DEFM_ACL) |
| 1721 | set_opt(sbi->s_mount_opt, POSIX_ACL); |
Hugh Dickins | 2e7842b | 2007-02-10 01:46:13 -0800 | [diff] [blame] | 1722 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_DATA) |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1724 | set_opt(sbi->s_mount_opt, JOURNAL_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_ORDERED) |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1726 | set_opt(sbi->s_mount_opt, ORDERED_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | else if ((def_mount_opts & EXT3_DEFM_JMODE) == EXT3_DEFM_JMODE_WBACK) |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1728 | set_opt(sbi->s_mount_opt, WRITEBACK_DATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
| 1730 | if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_PANIC) |
| 1731 | set_opt(sbi->s_mount_opt, ERRORS_PANIC); |
Aneesh Kumar K.V | 1eca93f | 2008-02-06 01:40:14 -0800 | [diff] [blame] | 1732 | else if (le16_to_cpu(sbi->s_es->s_errors) == EXT3_ERRORS_CONTINUE) |
Dmitry Mishin | 2245d7c | 2006-10-11 01:21:49 -0700 | [diff] [blame] | 1733 | set_opt(sbi->s_mount_opt, ERRORS_CONT); |
Aneesh Kumar K.V | 1eca93f | 2008-02-06 01:40:14 -0800 | [diff] [blame] | 1734 | else |
| 1735 | set_opt(sbi->s_mount_opt, ERRORS_RO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | |
Eric W. Biederman | 1523299 | 2012-02-07 15:41:24 -0800 | [diff] [blame] | 1737 | sbi->s_resuid = make_kuid(&init_user_ns, le16_to_cpu(es->s_def_resuid)); |
| 1738 | sbi->s_resgid = make_kgid(&init_user_ns, le16_to_cpu(es->s_def_resgid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
Christoph Hellwig | 00eacd6 | 2011-07-16 16:46:50 -0400 | [diff] [blame] | 1740 | /* enable barriers by default */ |
| 1741 | set_opt(sbi->s_mount_opt, BARRIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | set_opt(sbi->s_mount_opt, RESERVATION); |
| 1743 | |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 1744 | if (!parse_options ((char *) data, sb, &journal_inum, &journal_devnum, |
| 1745 | NULL, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | goto failed_mount; |
| 1747 | |
| 1748 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 1749 | (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | |
| 1751 | if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV && |
| 1752 | (EXT3_HAS_COMPAT_FEATURE(sb, ~0U) || |
| 1753 | EXT3_HAS_RO_COMPAT_FEATURE(sb, ~0U) || |
| 1754 | EXT3_HAS_INCOMPAT_FEATURE(sb, ~0U))) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1755 | ext3_msg(sb, KERN_WARNING, |
| 1756 | "warning: feature flags set on rev 0 fs, " |
| 1757 | "running e2fsck is recommended"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | /* |
| 1759 | * Check feature flags regardless of the revision level, since we |
| 1760 | * previously didn't change the revision level when setting the flags, |
| 1761 | * so there is a chance incompat flags are set on a rev 0 filesystem. |
| 1762 | */ |
| 1763 | features = EXT3_HAS_INCOMPAT_FEATURE(sb, ~EXT3_FEATURE_INCOMPAT_SUPP); |
| 1764 | if (features) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1765 | ext3_msg(sb, KERN_ERR, |
| 1766 | "error: couldn't mount because of unsupported " |
| 1767 | "optional features (%x)", le32_to_cpu(features)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | goto failed_mount; |
| 1769 | } |
| 1770 | features = EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP); |
| 1771 | if (!(sb->s_flags & MS_RDONLY) && features) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1772 | ext3_msg(sb, KERN_ERR, |
| 1773 | "error: couldn't mount RDWR because of unsupported " |
| 1774 | "optional features (%x)", le32_to_cpu(features)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | goto failed_mount; |
| 1776 | } |
| 1777 | blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size); |
| 1778 | |
| 1779 | if (blocksize < EXT3_MIN_BLOCK_SIZE || |
| 1780 | blocksize > EXT3_MAX_BLOCK_SIZE) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1781 | ext3_msg(sb, KERN_ERR, |
| 1782 | "error: couldn't mount because of unsupported " |
| 1783 | "filesystem blocksize %d", blocksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | goto failed_mount; |
| 1785 | } |
| 1786 | |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 1787 | hblock = bdev_logical_block_size(sb->s_bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | if (sb->s_blocksize != blocksize) { |
| 1789 | /* |
| 1790 | * Make sure the blocksize for the filesystem is larger |
| 1791 | * than the hardware sectorsize for the machine. |
| 1792 | */ |
| 1793 | if (blocksize < hblock) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1794 | ext3_msg(sb, KERN_ERR, |
| 1795 | "error: fsblocksize %d too small for " |
| 1796 | "hardware sectorsize %d", blocksize, hblock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | goto failed_mount; |
| 1798 | } |
| 1799 | |
| 1800 | brelse (bh); |
Takashi Sato | 0f0a89e | 2007-10-18 03:06:56 -0700 | [diff] [blame] | 1801 | if (!sb_set_blocksize(sb, blocksize)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1802 | ext3_msg(sb, KERN_ERR, |
| 1803 | "error: bad blocksize %d", blocksize); |
Takashi Sato | 0f0a89e | 2007-10-18 03:06:56 -0700 | [diff] [blame] | 1804 | goto out_fail; |
| 1805 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | logic_sb_block = (sb_block * EXT3_MIN_BLOCK_SIZE) / blocksize; |
| 1807 | offset = (sb_block * EXT3_MIN_BLOCK_SIZE) % blocksize; |
| 1808 | bh = sb_bread(sb, logic_sb_block); |
| 1809 | if (!bh) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1810 | ext3_msg(sb, KERN_ERR, |
| 1811 | "error: can't read superblock on 2nd try"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | goto failed_mount; |
| 1813 | } |
Namhyung Kim | 57e94d8 | 2010-10-11 02:10:45 +0900 | [diff] [blame] | 1814 | es = (struct ext3_super_block *)(bh->b_data + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | sbi->s_es = es; |
| 1816 | if (es->s_magic != cpu_to_le16(EXT3_SUPER_MAGIC)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1817 | ext3_msg(sb, KERN_ERR, |
| 1818 | "error: magic mismatch"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | goto failed_mount; |
| 1820 | } |
| 1821 | } |
| 1822 | |
| 1823 | sb->s_maxbytes = ext3_max_size(sb->s_blocksize_bits); |
| 1824 | |
| 1825 | if (le32_to_cpu(es->s_rev_level) == EXT3_GOOD_OLD_REV) { |
| 1826 | sbi->s_inode_size = EXT3_GOOD_OLD_INODE_SIZE; |
| 1827 | sbi->s_first_ino = EXT3_GOOD_OLD_FIRST_INO; |
| 1828 | } else { |
| 1829 | sbi->s_inode_size = le16_to_cpu(es->s_inode_size); |
| 1830 | sbi->s_first_ino = le32_to_cpu(es->s_first_ino); |
| 1831 | if ((sbi->s_inode_size < EXT3_GOOD_OLD_INODE_SIZE) || |
vignesh babu | 3fc7426 | 2007-07-15 23:41:17 -0700 | [diff] [blame] | 1832 | (!is_power_of_2(sbi->s_inode_size)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | (sbi->s_inode_size > blocksize)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1834 | ext3_msg(sb, KERN_ERR, |
| 1835 | "error: unsupported inode size: %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | sbi->s_inode_size); |
| 1837 | goto failed_mount; |
| 1838 | } |
| 1839 | } |
| 1840 | sbi->s_frag_size = EXT3_MIN_FRAG_SIZE << |
| 1841 | le32_to_cpu(es->s_log_frag_size); |
| 1842 | if (blocksize != sbi->s_frag_size) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1843 | ext3_msg(sb, KERN_ERR, |
| 1844 | "error: fragsize %lu != blocksize %u (unsupported)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | sbi->s_frag_size, blocksize); |
| 1846 | goto failed_mount; |
| 1847 | } |
| 1848 | sbi->s_frags_per_block = 1; |
| 1849 | sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); |
| 1850 | sbi->s_frags_per_group = le32_to_cpu(es->s_frags_per_group); |
| 1851 | sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); |
Andries E. Brouwer | b47b6f3 | 2007-12-17 16:19:55 -0800 | [diff] [blame] | 1852 | if (EXT3_INODE_SIZE(sb) == 0 || EXT3_INODES_PER_GROUP(sb) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | goto cantfind_ext3; |
| 1854 | sbi->s_inodes_per_block = blocksize / EXT3_INODE_SIZE(sb); |
| 1855 | if (sbi->s_inodes_per_block == 0) |
| 1856 | goto cantfind_ext3; |
| 1857 | sbi->s_itb_per_group = sbi->s_inodes_per_group / |
| 1858 | sbi->s_inodes_per_block; |
| 1859 | sbi->s_desc_per_block = blocksize / sizeof(struct ext3_group_desc); |
| 1860 | sbi->s_sbh = bh; |
| 1861 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
David Howells | f0d1b0b | 2006-12-08 02:37:49 -0800 | [diff] [blame] | 1862 | sbi->s_addr_per_block_bits = ilog2(EXT3_ADDR_PER_BLOCK(sb)); |
| 1863 | sbi->s_desc_per_block_bits = ilog2(EXT3_DESC_PER_BLOCK(sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | for (i=0; i < 4; i++) |
| 1865 | sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); |
| 1866 | sbi->s_def_hash_version = es->s_def_hash_version; |
Theodore Ts'o | 5e1f8c9 | 2008-10-28 13:21:55 -0400 | [diff] [blame] | 1867 | i = le32_to_cpu(es->s_flags); |
| 1868 | if (i & EXT2_FLAGS_UNSIGNED_HASH) |
| 1869 | sbi->s_hash_unsigned = 3; |
| 1870 | else if ((i & EXT2_FLAGS_SIGNED_HASH) == 0) { |
| 1871 | #ifdef __CHAR_UNSIGNED__ |
| 1872 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_UNSIGNED_HASH); |
| 1873 | sbi->s_hash_unsigned = 3; |
| 1874 | #else |
| 1875 | es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH); |
| 1876 | #endif |
Theodore Ts'o | 5e1f8c9 | 2008-10-28 13:21:55 -0400 | [diff] [blame] | 1877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
| 1879 | if (sbi->s_blocks_per_group > blocksize * 8) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1880 | ext3_msg(sb, KERN_ERR, |
| 1881 | "#blocks per group too big: %lu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | sbi->s_blocks_per_group); |
| 1883 | goto failed_mount; |
| 1884 | } |
| 1885 | if (sbi->s_frags_per_group > blocksize * 8) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1886 | ext3_msg(sb, KERN_ERR, |
| 1887 | "error: #fragments per group too big: %lu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | sbi->s_frags_per_group); |
| 1889 | goto failed_mount; |
| 1890 | } |
| 1891 | if (sbi->s_inodes_per_group > blocksize * 8) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1892 | ext3_msg(sb, KERN_ERR, |
| 1893 | "error: #inodes per group too big: %lu", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | sbi->s_inodes_per_group); |
| 1895 | goto failed_mount; |
| 1896 | } |
| 1897 | |
Darrick J. Wong | ad692bf | 2010-11-16 22:57:44 +0000 | [diff] [blame] | 1898 | err = generic_check_addressable(sb->s_blocksize_bits, |
| 1899 | le32_to_cpu(es->s_blocks_count)); |
| 1900 | if (err) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1901 | ext3_msg(sb, KERN_ERR, |
| 1902 | "error: filesystem is too large to mount safely"); |
Mingming Cao | fcd5df3 | 2006-06-25 05:47:50 -0700 | [diff] [blame] | 1903 | if (sizeof(sector_t) < 8) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1904 | ext3_msg(sb, KERN_ERR, |
| 1905 | "error: CONFIG_LBDAF not enabled"); |
Darrick J. Wong | ad692bf | 2010-11-16 22:57:44 +0000 | [diff] [blame] | 1906 | ret = err; |
Mingming Cao | fcd5df3 | 2006-06-25 05:47:50 -0700 | [diff] [blame] | 1907 | goto failed_mount; |
| 1908 | } |
| 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | if (EXT3_BLOCKS_PER_GROUP(sb) == 0) |
| 1911 | goto cantfind_ext3; |
Eric Sandeen | 855565e | 2006-09-27 01:49:29 -0700 | [diff] [blame] | 1912 | sbi->s_groups_count = ((le32_to_cpu(es->s_blocks_count) - |
| 1913 | le32_to_cpu(es->s_first_data_block) - 1) |
| 1914 | / EXT3_BLOCKS_PER_GROUP(sb)) + 1; |
Namhyung Kim | 81a4e32 | 2010-10-11 19:38:39 +0900 | [diff] [blame] | 1915 | db_count = DIV_ROUND_UP(sbi->s_groups_count, EXT3_DESC_PER_BLOCK(sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *), |
| 1917 | GFP_KERNEL); |
| 1918 | if (sbi->s_group_desc == NULL) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1919 | ext3_msg(sb, KERN_ERR, |
| 1920 | "error: not enough memory"); |
Namhyung Kim | 4569cd1 | 2010-10-11 19:08:06 +0900 | [diff] [blame] | 1921 | ret = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | goto failed_mount; |
| 1923 | } |
| 1924 | |
Pekka Enberg | 5df096d | 2009-01-07 18:07:25 -0800 | [diff] [blame] | 1925 | bgl_lock_init(sbi->s_blockgroup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
| 1927 | for (i = 0; i < db_count; i++) { |
| 1928 | block = descriptor_loc(sb, logic_sb_block, i); |
| 1929 | sbi->s_group_desc[i] = sb_bread(sb, block); |
| 1930 | if (!sbi->s_group_desc[i]) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1931 | ext3_msg(sb, KERN_ERR, |
| 1932 | "error: can't read group descriptor %d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | db_count = i; |
| 1934 | goto failed_mount2; |
| 1935 | } |
| 1936 | } |
| 1937 | if (!ext3_check_descriptors (sb)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1938 | ext3_msg(sb, KERN_ERR, |
| 1939 | "error: group descriptors corrupted"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | goto failed_mount2; |
| 1941 | } |
| 1942 | sbi->s_gdb_count = db_count; |
| 1943 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 1944 | spin_lock_init(&sbi->s_next_gen_lock); |
Mingming Cao | 0216bfc | 2006-06-23 02:05:41 -0700 | [diff] [blame] | 1945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | /* per fileystem reservation list head & lock */ |
| 1947 | spin_lock_init(&sbi->s_rsv_window_lock); |
| 1948 | sbi->s_rsv_window_root = RB_ROOT; |
| 1949 | /* Add a single, static dummy reservation to the start of the |
| 1950 | * reservation window list --- it gives us a placeholder for |
| 1951 | * append-at-start-of-list which makes the allocation logic |
| 1952 | * _much_ simpler. */ |
| 1953 | sbi->s_rsv_window_head.rsv_start = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; |
| 1954 | sbi->s_rsv_window_head.rsv_end = EXT3_RESERVE_WINDOW_NOT_ALLOCATED; |
| 1955 | sbi->s_rsv_window_head.rsv_alloc_hit = 0; |
| 1956 | sbi->s_rsv_window_head.rsv_goal_size = 0; |
| 1957 | ext3_rsv_window_add(sb, &sbi->s_rsv_window_head); |
| 1958 | |
| 1959 | /* |
| 1960 | * set up enough so that it can read an inode |
| 1961 | */ |
| 1962 | sb->s_op = &ext3_sops; |
| 1963 | sb->s_export_op = &ext3_export_ops; |
| 1964 | sb->s_xattr = ext3_xattr_handlers; |
| 1965 | #ifdef CONFIG_QUOTA |
| 1966 | sb->s_qcop = &ext3_qctl_operations; |
| 1967 | sb->dq_op = &ext3_quota_operations; |
| 1968 | #endif |
Aneesh Kumar K.V | 03cb5f0 | 2011-01-29 18:43:39 +0530 | [diff] [blame] | 1969 | memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ |
Eric Sandeen | b8a052d | 2009-12-14 13:00:30 -0600 | [diff] [blame] | 1971 | mutex_init(&sbi->s_orphan_lock); |
Eric Sandeen | 96d2a49 | 2009-12-14 13:01:05 -0600 | [diff] [blame] | 1972 | mutex_init(&sbi->s_resize_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | |
| 1974 | sb->s_root = NULL; |
| 1975 | |
| 1976 | needs_recovery = (es->s_last_orphan != 0 || |
| 1977 | EXT3_HAS_INCOMPAT_FEATURE(sb, |
| 1978 | EXT3_FEATURE_INCOMPAT_RECOVER)); |
| 1979 | |
| 1980 | /* |
| 1981 | * The first inode we look at is the journal inode. Don't try |
| 1982 | * root first: it may be modified in the journal! |
| 1983 | */ |
| 1984 | if (!test_opt(sb, NOLOAD) && |
| 1985 | EXT3_HAS_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) { |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 1986 | if (ext3_load_journal(sb, es, journal_devnum)) |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 1987 | goto failed_mount2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | } else if (journal_inum) { |
| 1989 | if (ext3_create_journal(sb, es, journal_inum)) |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 1990 | goto failed_mount2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | } else { |
| 1992 | if (!silent) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 1993 | ext3_msg(sb, KERN_ERR, |
| 1994 | "error: no journal found. " |
| 1995 | "mounting ext3 over ext2?"); |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 1996 | goto failed_mount2; |
| 1997 | } |
| 1998 | err = percpu_counter_init(&sbi->s_freeblocks_counter, |
| 1999 | ext3_count_free_blocks(sb)); |
| 2000 | if (!err) { |
| 2001 | err = percpu_counter_init(&sbi->s_freeinodes_counter, |
| 2002 | ext3_count_free_inodes(sb)); |
| 2003 | } |
| 2004 | if (!err) { |
| 2005 | err = percpu_counter_init(&sbi->s_dirs_counter, |
| 2006 | ext3_count_dirs(sb)); |
| 2007 | } |
| 2008 | if (err) { |
| 2009 | ext3_msg(sb, KERN_ERR, "error: insufficient memory"); |
Namhyung Kim | 4569cd1 | 2010-10-11 19:08:06 +0900 | [diff] [blame] | 2010 | ret = err; |
Mingming Cao | 0216bfc | 2006-06-23 02:05:41 -0700 | [diff] [blame] | 2011 | goto failed_mount3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | /* We have now updated the journal if required, so we can |
| 2015 | * validate the data journaling mode. */ |
| 2016 | switch (test_opt(sb, DATA_FLAGS)) { |
| 2017 | case 0: |
| 2018 | /* No mode set, assume a default based on the journal |
| 2019 | capabilities: ORDERED_DATA if the journal can |
| 2020 | cope, else JOURNAL_DATA */ |
| 2021 | if (journal_check_available_features |
| 2022 | (sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) |
Linus Torvalds | bbae8bc | 2009-04-06 17:16:47 -0700 | [diff] [blame] | 2023 | set_opt(sbi->s_mount_opt, DEFAULT_DATA_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | else |
| 2025 | set_opt(sbi->s_mount_opt, JOURNAL_DATA); |
| 2026 | break; |
| 2027 | |
| 2028 | case EXT3_MOUNT_ORDERED_DATA: |
| 2029 | case EXT3_MOUNT_WRITEBACK_DATA: |
| 2030 | if (!journal_check_available_features |
| 2031 | (sbi->s_journal, 0, 0, JFS_FEATURE_INCOMPAT_REVOKE)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2032 | ext3_msg(sb, KERN_ERR, |
| 2033 | "error: journal does not support " |
| 2034 | "requested data journaling mode"); |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 2035 | goto failed_mount3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | default: |
| 2038 | break; |
| 2039 | } |
| 2040 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | /* |
| 2042 | * The journal_load will have done any necessary log recovery, |
| 2043 | * so we can safely mount the rest of the filesystem now. |
| 2044 | */ |
| 2045 | |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2046 | root = ext3_iget(sb, EXT3_ROOT_INO); |
| 2047 | if (IS_ERR(root)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2048 | ext3_msg(sb, KERN_ERR, "error: get root inode failed"); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2049 | ret = PTR_ERR(root); |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 2050 | goto failed_mount3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
| 2052 | if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2053 | iput(root); |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2054 | ext3_msg(sb, KERN_ERR, "error: corrupt root inode, run e2fsck"); |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 2055 | goto failed_mount3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | } |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 2057 | sb->s_root = d_make_root(root); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2058 | if (!sb->s_root) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2059 | ext3_msg(sb, KERN_ERR, "error: get root dentry failed"); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2060 | ret = -ENOMEM; |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 2061 | goto failed_mount3; |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2062 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Eric Sandeen | f007dbf | 2012-05-24 12:00:37 -0500 | [diff] [blame] | 2064 | if (ext3_setup_super(sb, es, sb->s_flags & MS_RDONLY)) |
| 2065 | sb->s_flags |= MS_RDONLY; |
Eric Sandeen | ed505ee | 2009-12-14 12:59:18 -0600 | [diff] [blame] | 2066 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; |
| 2068 | ext3_orphan_cleanup(sb, es); |
| 2069 | EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; |
Eryu Guan | 63894ab | 2011-11-01 10:06:19 +0800 | [diff] [blame] | 2070 | if (needs_recovery) { |
| 2071 | ext3_mark_recovery_complete(sb, es); |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2072 | ext3_msg(sb, KERN_INFO, "recovery complete"); |
Eryu Guan | 63894ab | 2011-11-01 10:06:19 +0800 | [diff] [blame] | 2073 | } |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2074 | ext3_msg(sb, KERN_INFO, "mounted filesystem with %s data mode", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_JOURNAL_DATA ? "journal": |
| 2076 | test_opt(sb,DATA_FLAGS) == EXT3_MOUNT_ORDERED_DATA ? "ordered": |
| 2077 | "writeback"); |
| 2078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return 0; |
| 2080 | |
| 2081 | cantfind_ext3: |
| 2082 | if (!silent) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2083 | ext3_msg(sb, KERN_INFO, |
| 2084 | "error: can't find ext3 filesystem on dev %s.", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | sb->s_id); |
| 2086 | goto failed_mount; |
| 2087 | |
Mingming Cao | 0216bfc | 2006-06-23 02:05:41 -0700 | [diff] [blame] | 2088 | failed_mount3: |
| 2089 | percpu_counter_destroy(&sbi->s_freeblocks_counter); |
| 2090 | percpu_counter_destroy(&sbi->s_freeinodes_counter); |
| 2091 | percpu_counter_destroy(&sbi->s_dirs_counter); |
Dmitry Monakhov | 41d1a63 | 2010-04-12 23:46:00 +0400 | [diff] [blame] | 2092 | journal_destroy(sbi->s_journal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | failed_mount2: |
| 2094 | for (i = 0; i < db_count; i++) |
| 2095 | brelse(sbi->s_group_desc[i]); |
| 2096 | kfree(sbi->s_group_desc); |
| 2097 | failed_mount: |
| 2098 | #ifdef CONFIG_QUOTA |
| 2099 | for (i = 0; i < MAXQUOTAS; i++) |
| 2100 | kfree(sbi->s_qf_names[i]); |
| 2101 | #endif |
| 2102 | ext3_blkdev_remove(sbi); |
| 2103 | brelse(bh); |
| 2104 | out_fail: |
| 2105 | sb->s_fs_info = NULL; |
Manish Katiyar | de5ce03 | 2009-05-17 23:52:47 -0400 | [diff] [blame] | 2106 | kfree(sbi->s_blockgroup_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | kfree(sbi); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2108 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | /* |
| 2112 | * Setup any per-fs journal parameters now. We'll do this both on |
| 2113 | * initial mount, once the journal has been initialised but before we've |
Mingming Cao | ae6ddcc | 2006-09-27 01:49:27 -0700 | [diff] [blame] | 2114 | * done any recovery; and again on any subsequent remount. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | */ |
| 2116 | static void ext3_init_journal_params(struct super_block *sb, journal_t *journal) |
| 2117 | { |
| 2118 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 2119 | |
| 2120 | if (sbi->s_commit_interval) |
| 2121 | journal->j_commit_interval = sbi->s_commit_interval; |
| 2122 | /* We could also set up an ext3-specific default for the commit |
| 2123 | * interval here, but for now we'll just fall back to the jbd |
| 2124 | * default. */ |
| 2125 | |
| 2126 | spin_lock(&journal->j_state_lock); |
| 2127 | if (test_opt(sb, BARRIER)) |
| 2128 | journal->j_flags |= JFS_BARRIER; |
| 2129 | else |
| 2130 | journal->j_flags &= ~JFS_BARRIER; |
Hidehiro Kawai | 0e4fb5e | 2008-10-18 20:27:57 -0700 | [diff] [blame] | 2131 | if (test_opt(sb, DATA_ERR_ABORT)) |
| 2132 | journal->j_flags |= JFS_ABORT_ON_SYNCDATA_ERR; |
| 2133 | else |
| 2134 | journal->j_flags &= ~JFS_ABORT_ON_SYNCDATA_ERR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | spin_unlock(&journal->j_state_lock); |
| 2136 | } |
| 2137 | |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 2138 | static journal_t *ext3_get_journal(struct super_block *sb, |
| 2139 | unsigned int journal_inum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | { |
| 2141 | struct inode *journal_inode; |
| 2142 | journal_t *journal; |
| 2143 | |
| 2144 | /* First, test for the existence of a valid inode on disk. Bad |
| 2145 | * things happen if we iget() an unused inode, as the subsequent |
| 2146 | * iput() will try to delete it. */ |
| 2147 | |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2148 | journal_inode = ext3_iget(sb, journal_inum); |
| 2149 | if (IS_ERR(journal_inode)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2150 | ext3_msg(sb, KERN_ERR, "error: no journal found"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | return NULL; |
| 2152 | } |
| 2153 | if (!journal_inode->i_nlink) { |
| 2154 | make_bad_inode(journal_inode); |
| 2155 | iput(journal_inode); |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2156 | ext3_msg(sb, KERN_ERR, "error: journal inode is deleted"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | return NULL; |
| 2158 | } |
| 2159 | |
| 2160 | jbd_debug(2, "Journal inode found at %p: %Ld bytes\n", |
| 2161 | journal_inode, journal_inode->i_size); |
David Howells | 473043d | 2008-02-07 00:15:36 -0800 | [diff] [blame] | 2162 | if (!S_ISREG(journal_inode->i_mode)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2163 | ext3_msg(sb, KERN_ERR, "error: invalid journal inode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | iput(journal_inode); |
| 2165 | return NULL; |
| 2166 | } |
| 2167 | |
| 2168 | journal = journal_init_inode(journal_inode); |
| 2169 | if (!journal) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2170 | ext3_msg(sb, KERN_ERR, "error: could not load journal inode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | iput(journal_inode); |
| 2172 | return NULL; |
| 2173 | } |
| 2174 | journal->j_private = sb; |
| 2175 | ext3_init_journal_params(sb, journal); |
| 2176 | return journal; |
| 2177 | } |
| 2178 | |
| 2179 | static journal_t *ext3_get_dev_journal(struct super_block *sb, |
| 2180 | dev_t j_dev) |
| 2181 | { |
| 2182 | struct buffer_head * bh; |
| 2183 | journal_t *journal; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 2184 | ext3_fsblk_t start; |
Mingming Cao | 1c2bf37 | 2006-06-25 05:48:06 -0700 | [diff] [blame] | 2185 | ext3_fsblk_t len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | int hblock, blocksize; |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 2187 | ext3_fsblk_t sb_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2188 | unsigned long offset; |
| 2189 | struct ext3_super_block * es; |
| 2190 | struct block_device *bdev; |
| 2191 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2192 | bdev = ext3_blkdev_get(j_dev, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | if (bdev == NULL) |
| 2194 | return NULL; |
| 2195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2196 | blocksize = sb->s_blocksize; |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 2197 | hblock = bdev_logical_block_size(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | if (blocksize < hblock) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2199 | ext3_msg(sb, KERN_ERR, |
| 2200 | "error: blocksize too small for journal device"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | goto out_bdev; |
| 2202 | } |
| 2203 | |
| 2204 | sb_block = EXT3_MIN_BLOCK_SIZE / blocksize; |
| 2205 | offset = EXT3_MIN_BLOCK_SIZE % blocksize; |
| 2206 | set_blocksize(bdev, blocksize); |
| 2207 | if (!(bh = __bread(bdev, sb_block, blocksize))) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2208 | ext3_msg(sb, KERN_ERR, "error: couldn't read superblock of " |
| 2209 | "external journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | goto out_bdev; |
| 2211 | } |
| 2212 | |
Namhyung Kim | 57e94d8 | 2010-10-11 02:10:45 +0900 | [diff] [blame] | 2213 | es = (struct ext3_super_block *) (bh->b_data + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2214 | if ((le16_to_cpu(es->s_magic) != EXT3_SUPER_MAGIC) || |
| 2215 | !(le32_to_cpu(es->s_feature_incompat) & |
| 2216 | EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2217 | ext3_msg(sb, KERN_ERR, "error: external journal has " |
| 2218 | "bad superblock"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | brelse(bh); |
| 2220 | goto out_bdev; |
| 2221 | } |
| 2222 | |
| 2223 | if (memcmp(EXT3_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2224 | ext3_msg(sb, KERN_ERR, "error: journal UUID does not match"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | brelse(bh); |
| 2226 | goto out_bdev; |
| 2227 | } |
| 2228 | |
| 2229 | len = le32_to_cpu(es->s_blocks_count); |
| 2230 | start = sb_block + 1; |
| 2231 | brelse(bh); /* we're done with the superblock */ |
| 2232 | |
| 2233 | journal = journal_init_dev(bdev, sb->s_bdev, |
| 2234 | start, len, blocksize); |
| 2235 | if (!journal) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2236 | ext3_msg(sb, KERN_ERR, |
| 2237 | "error: failed to create device journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | goto out_bdev; |
| 2239 | } |
| 2240 | journal->j_private = sb; |
Zheng Liu | d03e129 | 2011-12-05 15:55:11 +0800 | [diff] [blame] | 2241 | if (!bh_uptodate_or_lock(journal->j_sb_buffer)) { |
| 2242 | if (bh_submit_read(journal->j_sb_buffer)) { |
| 2243 | ext3_msg(sb, KERN_ERR, "I/O error on journal device"); |
| 2244 | goto out_journal; |
| 2245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | } |
| 2247 | if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2248 | ext3_msg(sb, KERN_ERR, |
| 2249 | "error: external journal has more than one " |
| 2250 | "user (unsupported) - %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | be32_to_cpu(journal->j_superblock->s_nr_users)); |
| 2252 | goto out_journal; |
| 2253 | } |
| 2254 | EXT3_SB(sb)->journal_bdev = bdev; |
| 2255 | ext3_init_journal_params(sb, journal); |
| 2256 | return journal; |
| 2257 | out_journal: |
| 2258 | journal_destroy(journal); |
| 2259 | out_bdev: |
| 2260 | ext3_blkdev_put(bdev); |
| 2261 | return NULL; |
| 2262 | } |
| 2263 | |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2264 | static int ext3_load_journal(struct super_block *sb, |
| 2265 | struct ext3_super_block *es, |
| 2266 | unsigned long journal_devnum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | { |
| 2268 | journal_t *journal; |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 2269 | unsigned int journal_inum = le32_to_cpu(es->s_journal_inum); |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2270 | dev_t journal_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | int err = 0; |
| 2272 | int really_read_only; |
| 2273 | |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2274 | if (journal_devnum && |
| 2275 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2276 | ext3_msg(sb, KERN_INFO, "external journal device major/minor " |
| 2277 | "numbers have changed"); |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2278 | journal_dev = new_decode_dev(journal_devnum); |
| 2279 | } else |
| 2280 | journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); |
| 2281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | really_read_only = bdev_read_only(sb->s_bdev); |
| 2283 | |
| 2284 | /* |
| 2285 | * Are we loading a blank journal or performing recovery after a |
| 2286 | * crash? For recovery, we need to check in advance whether we |
| 2287 | * can get read-write access to the device. |
| 2288 | */ |
| 2289 | |
| 2290 | if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) { |
| 2291 | if (sb->s_flags & MS_RDONLY) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2292 | ext3_msg(sb, KERN_INFO, |
| 2293 | "recovery required on readonly filesystem"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | if (really_read_only) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2295 | ext3_msg(sb, KERN_ERR, "error: write access " |
| 2296 | "unavailable, cannot proceed"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | return -EROFS; |
| 2298 | } |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2299 | ext3_msg(sb, KERN_INFO, |
| 2300 | "write access will be enabled during recovery"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | if (journal_inum && journal_dev) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2305 | ext3_msg(sb, KERN_ERR, "error: filesystem has both journal " |
| 2306 | "and inode journals"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | return -EINVAL; |
| 2308 | } |
| 2309 | |
| 2310 | if (journal_inum) { |
| 2311 | if (!(journal = ext3_get_journal(sb, journal_inum))) |
| 2312 | return -EINVAL; |
| 2313 | } else { |
| 2314 | if (!(journal = ext3_get_dev_journal(sb, journal_dev))) |
| 2315 | return -EINVAL; |
| 2316 | } |
| 2317 | |
Eric Sandeen | 0636c73 | 2010-04-30 11:09:34 -0500 | [diff] [blame] | 2318 | if (!(journal->j_flags & JFS_BARRIER)) |
| 2319 | printk(KERN_INFO "EXT3-fs: barriers not enabled\n"); |
| 2320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2321 | if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { |
| 2322 | err = journal_update_format(journal); |
| 2323 | if (err) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2324 | ext3_msg(sb, KERN_ERR, "error updating journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | journal_destroy(journal); |
| 2326 | return err; |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | if (!EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER)) |
| 2331 | err = journal_wipe(journal, !really_read_only); |
| 2332 | if (!err) |
| 2333 | err = journal_load(journal); |
| 2334 | |
| 2335 | if (err) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2336 | ext3_msg(sb, KERN_ERR, "error loading journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2337 | journal_destroy(journal); |
| 2338 | return err; |
| 2339 | } |
| 2340 | |
| 2341 | EXT3_SB(sb)->s_journal = journal; |
| 2342 | ext3_clear_journal_err(sb, es); |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2343 | |
Maciej Żenczykowski | 31d710a | 2010-09-26 12:38:28 +0000 | [diff] [blame] | 2344 | if (!really_read_only && journal_devnum && |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2345 | journal_devnum != le32_to_cpu(es->s_journal_dev)) { |
| 2346 | es->s_journal_dev = cpu_to_le32(journal_devnum); |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2347 | |
| 2348 | /* Make sure we flush the recovery flag to disk. */ |
| 2349 | ext3_commit_super(sb, es, 1); |
| 2350 | } |
| 2351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | return 0; |
| 2353 | } |
| 2354 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2355 | static int ext3_create_journal(struct super_block *sb, |
| 2356 | struct ext3_super_block *es, |
Eric Sandeen | eee194e | 2006-09-27 01:49:30 -0700 | [diff] [blame] | 2357 | unsigned int journal_inum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | { |
| 2359 | journal_t *journal; |
Borislav Petkov | 952d9de | 2007-07-15 23:41:45 -0700 | [diff] [blame] | 2360 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | |
| 2362 | if (sb->s_flags & MS_RDONLY) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2363 | ext3_msg(sb, KERN_ERR, |
| 2364 | "error: readonly filesystem when trying to " |
| 2365 | "create journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | return -EROFS; |
| 2367 | } |
| 2368 | |
Borislav Petkov | 952d9de | 2007-07-15 23:41:45 -0700 | [diff] [blame] | 2369 | journal = ext3_get_journal(sb, journal_inum); |
| 2370 | if (!journal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | return -EINVAL; |
| 2372 | |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2373 | ext3_msg(sb, KERN_INFO, "creating new journal on inode %u", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2374 | journal_inum); |
| 2375 | |
Borislav Petkov | 952d9de | 2007-07-15 23:41:45 -0700 | [diff] [blame] | 2376 | err = journal_create(journal); |
| 2377 | if (err) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2378 | ext3_msg(sb, KERN_ERR, "error creating journal"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | journal_destroy(journal); |
| 2380 | return -EIO; |
| 2381 | } |
| 2382 | |
| 2383 | EXT3_SB(sb)->s_journal = journal; |
| 2384 | |
| 2385 | ext3_update_dynamic_rev(sb); |
| 2386 | EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
| 2387 | EXT3_SET_COMPAT_FEATURE(sb, EXT3_FEATURE_COMPAT_HAS_JOURNAL); |
| 2388 | |
| 2389 | es->s_journal_inum = cpu_to_le32(journal_inum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
| 2391 | /* Make sure we flush the recovery flag to disk. */ |
| 2392 | ext3_commit_super(sb, es, 1); |
| 2393 | |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2397 | static int ext3_commit_super(struct super_block *sb, |
| 2398 | struct ext3_super_block *es, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | int sync) |
| 2400 | { |
| 2401 | struct buffer_head *sbh = EXT3_SB(sb)->s_sbh; |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2402 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | |
| 2404 | if (!sbh) |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2405 | return error; |
Darrick J. Wong | dff6825 | 2010-10-04 12:35:05 -0700 | [diff] [blame] | 2406 | |
| 2407 | if (buffer_write_io_error(sbh)) { |
| 2408 | /* |
| 2409 | * Oh, dear. A previous attempt to write the |
| 2410 | * superblock failed. This could happen because the |
| 2411 | * USB device was yanked out. Or it could happen to |
| 2412 | * be a transient write error and maybe the block will |
| 2413 | * be remapped. Nothing we can do but to retry the |
| 2414 | * write and hope for the best. |
| 2415 | */ |
| 2416 | ext3_msg(sb, KERN_ERR, "previous I/O error to " |
| 2417 | "superblock detected"); |
| 2418 | clear_buffer_write_io_error(sbh); |
| 2419 | set_buffer_uptodate(sbh); |
| 2420 | } |
Theodore Ts'o | 96ec2e0 | 2009-09-16 11:21:13 -0400 | [diff] [blame] | 2421 | /* |
| 2422 | * If the file system is mounted read-only, don't update the |
| 2423 | * superblock write time. This avoids updating the superblock |
| 2424 | * write time when we are mounting the root file system |
| 2425 | * read/only but we need to replay the journal; at that point, |
| 2426 | * for people who are east of GMT and who make their clock |
| 2427 | * tick in localtime for Windows bug-for-bug compatibility, |
| 2428 | * the clock is set in the future, and this will cause e2fsck |
| 2429 | * to complain and force a full file system check. |
| 2430 | */ |
| 2431 | if (!(sb->s_flags & MS_RDONLY)) |
| 2432 | es->s_wtime = cpu_to_le32(get_seconds()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | es->s_free_blocks_count = cpu_to_le32(ext3_count_free_blocks(sb)); |
| 2434 | es->s_free_inodes_count = cpu_to_le32(ext3_count_free_inodes(sb)); |
| 2435 | BUFFER_TRACE(sbh, "marking dirty"); |
| 2436 | mark_buffer_dirty(sbh); |
Darrick J. Wong | dff6825 | 2010-10-04 12:35:05 -0700 | [diff] [blame] | 2437 | if (sync) { |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2438 | error = sync_dirty_buffer(sbh); |
Darrick J. Wong | dff6825 | 2010-10-04 12:35:05 -0700 | [diff] [blame] | 2439 | if (buffer_write_io_error(sbh)) { |
| 2440 | ext3_msg(sb, KERN_ERR, "I/O error while writing " |
| 2441 | "superblock"); |
| 2442 | clear_buffer_write_io_error(sbh); |
| 2443 | set_buffer_uptodate(sbh); |
| 2444 | } |
| 2445 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2446 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | } |
| 2448 | |
| 2449 | |
| 2450 | /* |
| 2451 | * Have we just finished recovery? If so, and if we are mounting (or |
| 2452 | * remounting) the filesystem readonly, then we will end up with a |
| 2453 | * consistent fs on disk. Record that fact. |
| 2454 | */ |
| 2455 | static void ext3_mark_recovery_complete(struct super_block * sb, |
| 2456 | struct ext3_super_block * es) |
| 2457 | { |
| 2458 | journal_t *journal = EXT3_SB(sb)->s_journal; |
| 2459 | |
| 2460 | journal_lock_updates(journal); |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 2461 | if (journal_flush(journal) < 0) |
| 2462 | goto out; |
| 2463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && |
| 2465 | sb->s_flags & MS_RDONLY) { |
| 2466 | EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | ext3_commit_super(sb, es, 1); |
| 2468 | } |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 2469 | |
| 2470 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | journal_unlock_updates(journal); |
| 2472 | } |
| 2473 | |
| 2474 | /* |
| 2475 | * If we are mounting (or read-write remounting) a filesystem whose journal |
| 2476 | * has recorded an error from a previous lifetime, move that error to the |
| 2477 | * main filesystem now. |
| 2478 | */ |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2479 | static void ext3_clear_journal_err(struct super_block *sb, |
| 2480 | struct ext3_super_block *es) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | { |
| 2482 | journal_t *journal; |
| 2483 | int j_errno; |
| 2484 | const char *errstr; |
| 2485 | |
| 2486 | journal = EXT3_SB(sb)->s_journal; |
| 2487 | |
| 2488 | /* |
| 2489 | * Now check for any error status which may have been recorded in the |
| 2490 | * journal by a prior ext3_error() or ext3_abort() |
| 2491 | */ |
| 2492 | |
| 2493 | j_errno = journal_errno(journal); |
| 2494 | if (j_errno) { |
| 2495 | char nbuf[16]; |
| 2496 | |
| 2497 | errstr = ext3_decode_error(sb, j_errno, nbuf); |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 2498 | ext3_warning(sb, __func__, "Filesystem error recorded " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | "from previous mount: %s", errstr); |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 2500 | ext3_warning(sb, __func__, "Marking fs in need of " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | "filesystem check."); |
| 2502 | |
| 2503 | EXT3_SB(sb)->s_mount_state |= EXT3_ERROR_FS; |
| 2504 | es->s_state |= cpu_to_le16(EXT3_ERROR_FS); |
| 2505 | ext3_commit_super (sb, es, 1); |
| 2506 | |
| 2507 | journal_clear_err(journal); |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | /* |
| 2512 | * Force the running and committing transactions to commit, |
| 2513 | * and wait on the commit. |
| 2514 | */ |
| 2515 | int ext3_force_commit(struct super_block *sb) |
| 2516 | { |
| 2517 | journal_t *journal; |
| 2518 | int ret; |
| 2519 | |
| 2520 | if (sb->s_flags & MS_RDONLY) |
| 2521 | return 0; |
| 2522 | |
| 2523 | journal = EXT3_SB(sb)->s_journal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | ret = ext3_journal_force_commit(journal); |
| 2525 | return ret; |
| 2526 | } |
| 2527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | static int ext3_sync_fs(struct super_block *sb, int wait) |
| 2529 | { |
Jan Kara | 02ac597 | 2009-02-11 13:04:26 -0800 | [diff] [blame] | 2530 | tid_t target; |
Arthur Jones | c87591b | 2008-11-06 12:53:35 -0800 | [diff] [blame] | 2531 | |
Lukas Czerner | 785c4bc | 2011-05-23 18:33:01 +0200 | [diff] [blame] | 2532 | trace_ext3_sync_fs(sb, wait); |
Jan Kara | a117782 | 2012-07-03 16:45:29 +0200 | [diff] [blame] | 2533 | /* |
| 2534 | * Writeback quota in non-journalled quota case - journalled quota has |
| 2535 | * no dirty dquots |
| 2536 | */ |
| 2537 | dquot_writeback_dquots(sb, -1); |
Jan Kara | 02ac597 | 2009-02-11 13:04:26 -0800 | [diff] [blame] | 2538 | if (journal_start_commit(EXT3_SB(sb)->s_journal, &target)) { |
| 2539 | if (wait) |
| 2540 | log_wait_commit(EXT3_SB(sb)->s_journal, target); |
| 2541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | return 0; |
| 2543 | } |
| 2544 | |
| 2545 | /* |
| 2546 | * LVM calls this function before a (read-only) snapshot is created. This |
| 2547 | * gives us a chance to flush the journal completely and mark the fs clean. |
| 2548 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2549 | static int ext3_freeze(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | { |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2551 | int error = 0; |
| 2552 | journal_t *journal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2553 | |
| 2554 | if (!(sb->s_flags & MS_RDONLY)) { |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2555 | journal = EXT3_SB(sb)->s_journal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | |
| 2557 | /* Now we set up the journal barrier. */ |
| 2558 | journal_lock_updates(journal); |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 2559 | |
| 2560 | /* |
| 2561 | * We don't want to clear needs_recovery flag when we failed |
| 2562 | * to flush the journal. |
| 2563 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2564 | error = journal_flush(journal); |
| 2565 | if (error < 0) |
| 2566 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | |
| 2568 | /* Journal blocked and flushed, clear needs_recovery flag. */ |
| 2569 | EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2570 | error = ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); |
| 2571 | if (error) |
| 2572 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2574 | return 0; |
| 2575 | |
| 2576 | out: |
| 2577 | journal_unlock_updates(journal); |
| 2578 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | /* |
| 2582 | * Called by LVM after the snapshot is done. We need to reset the RECOVER |
| 2583 | * flag here, even though the filesystem is not technically dirty yet. |
| 2584 | */ |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2585 | static int ext3_unfreeze(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | { |
| 2587 | if (!(sb->s_flags & MS_RDONLY)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | /* Reser the needs_recovery flag before the fs is unlocked. */ |
| 2589 | EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); |
| 2590 | ext3_commit_super(sb, EXT3_SB(sb)->s_es, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | journal_unlock_updates(EXT3_SB(sb)->s_journal); |
| 2592 | } |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 2593 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | static int ext3_remount (struct super_block * sb, int * flags, char * data) |
| 2597 | { |
| 2598 | struct ext3_super_block * es; |
| 2599 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
Mingming Cao | 43d23f9 | 2006-06-25 05:48:07 -0700 | [diff] [blame] | 2600 | ext3_fsblk_t n_blocks_count = 0; |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2601 | unsigned long old_sb_flags; |
| 2602 | struct ext3_mount_options old_opts; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 2603 | int enable_quota = 0; |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2604 | int err; |
| 2605 | #ifdef CONFIG_QUOTA |
| 2606 | int i; |
| 2607 | #endif |
| 2608 | |
| 2609 | /* Store the original options */ |
| 2610 | old_sb_flags = sb->s_flags; |
| 2611 | old_opts.s_mount_opt = sbi->s_mount_opt; |
| 2612 | old_opts.s_resuid = sbi->s_resuid; |
| 2613 | old_opts.s_resgid = sbi->s_resgid; |
| 2614 | old_opts.s_commit_interval = sbi->s_commit_interval; |
| 2615 | #ifdef CONFIG_QUOTA |
| 2616 | old_opts.s_jquota_fmt = sbi->s_jquota_fmt; |
| 2617 | for (i = 0; i < MAXQUOTAS; i++) |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 2618 | if (sbi->s_qf_names[i]) { |
| 2619 | old_opts.s_qf_names[i] = kstrdup(sbi->s_qf_names[i], |
| 2620 | GFP_KERNEL); |
| 2621 | if (!old_opts.s_qf_names[i]) { |
| 2622 | int j; |
| 2623 | |
| 2624 | for (j = 0; j < i; j++) |
| 2625 | kfree(old_opts.s_qf_names[j]); |
| 2626 | return -ENOMEM; |
| 2627 | } |
| 2628 | } else |
| 2629 | old_opts.s_qf_names[i] = NULL; |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2630 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
| 2632 | /* |
| 2633 | * Allow the "check" option to be passed as a remount option. |
| 2634 | */ |
Johann Lombardi | 71b9625 | 2006-01-08 01:03:20 -0800 | [diff] [blame] | 2635 | if (!parse_options(data, sb, NULL, NULL, &n_blocks_count, 1)) { |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2636 | err = -EINVAL; |
| 2637 | goto restore_opts; |
| 2638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 2640 | if (test_opt(sb, ABORT)) |
Harvey Harrison | e05b6b5 | 2008-04-28 02:16:15 -0700 | [diff] [blame] | 2641 | ext3_abort(sb, __func__, "Abort forced by user"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2642 | |
| 2643 | sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 2644 | (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | |
| 2646 | es = sbi->s_es; |
| 2647 | |
| 2648 | ext3_init_journal_params(sb, sbi->s_journal); |
| 2649 | |
| 2650 | if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY) || |
| 2651 | n_blocks_count > le32_to_cpu(es->s_blocks_count)) { |
Dmitry Monakhov | e3c9643 | 2010-02-02 16:05:51 +0300 | [diff] [blame] | 2652 | if (test_opt(sb, ABORT)) { |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2653 | err = -EROFS; |
| 2654 | goto restore_opts; |
| 2655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | |
| 2657 | if (*flags & MS_RDONLY) { |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 2658 | err = dquot_suspend(sb, -1); |
| 2659 | if (err < 0) |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 2660 | goto restore_opts; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 2661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | /* |
| 2663 | * First of all, the unconditional stuff we have to do |
| 2664 | * to disable replay of the journal when we next remount |
| 2665 | */ |
| 2666 | sb->s_flags |= MS_RDONLY; |
| 2667 | |
| 2668 | /* |
| 2669 | * OK, test if we are remounting a valid rw partition |
| 2670 | * readonly, and if so set the rdonly flag and then |
| 2671 | * mark the partition as valid again. |
| 2672 | */ |
| 2673 | if (!(es->s_state & cpu_to_le16(EXT3_VALID_FS)) && |
| 2674 | (sbi->s_mount_state & EXT3_VALID_FS)) |
| 2675 | es->s_state = cpu_to_le16(sbi->s_mount_state); |
| 2676 | |
| 2677 | ext3_mark_recovery_complete(sb, es); |
| 2678 | } else { |
| 2679 | __le32 ret; |
| 2680 | if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb, |
| 2681 | ~EXT3_FEATURE_RO_COMPAT_SUPP))) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2682 | ext3_msg(sb, KERN_WARNING, |
| 2683 | "warning: couldn't remount RDWR " |
| 2684 | "because of unsupported optional " |
| 2685 | "features (%x)", le32_to_cpu(ret)); |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2686 | err = -EROFS; |
| 2687 | goto restore_opts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | } |
Eric Sandeen | ea9a05a | 2007-02-10 01:46:07 -0800 | [diff] [blame] | 2689 | |
| 2690 | /* |
| 2691 | * If we have an unprocessed orphan list hanging |
| 2692 | * around from a previously readonly bdev mount, |
Toshiyuki Okajima | 1cde201 | 2011-08-02 18:16:57 +0900 | [diff] [blame] | 2693 | * require a full umount & mount for now. |
Eric Sandeen | ea9a05a | 2007-02-10 01:46:07 -0800 | [diff] [blame] | 2694 | */ |
| 2695 | if (es->s_last_orphan) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2696 | ext3_msg(sb, KERN_WARNING, "warning: couldn't " |
Eric Sandeen | ea9a05a | 2007-02-10 01:46:07 -0800 | [diff] [blame] | 2697 | "remount RDWR because of unprocessed " |
| 2698 | "orphan inode list. Please " |
Toshiyuki Okajima | 1cde201 | 2011-08-02 18:16:57 +0900 | [diff] [blame] | 2699 | "umount & mount instead."); |
Eric Sandeen | ea9a05a | 2007-02-10 01:46:07 -0800 | [diff] [blame] | 2700 | err = -EINVAL; |
| 2701 | goto restore_opts; |
| 2702 | } |
| 2703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | /* |
| 2705 | * Mounting a RDONLY partition read-write, so reread |
| 2706 | * and store the current valid flag. (It may have |
| 2707 | * been changed by e2fsck since we originally mounted |
| 2708 | * the partition.) |
| 2709 | */ |
| 2710 | ext3_clear_journal_err(sb, es); |
| 2711 | sbi->s_mount_state = le16_to_cpu(es->s_state); |
Dave Kleikamp | a4e4de3 | 2006-09-27 01:49:36 -0700 | [diff] [blame] | 2712 | if ((err = ext3_group_extend(sb, es, n_blocks_count))) |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2713 | goto restore_opts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | if (!ext3_setup_super (sb, es, 0)) |
| 2715 | sb->s_flags &= ~MS_RDONLY; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 2716 | enable_quota = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | } |
| 2718 | } |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2719 | #ifdef CONFIG_QUOTA |
| 2720 | /* Release old quota file names */ |
| 2721 | for (i = 0; i < MAXQUOTAS; i++) |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 2722 | kfree(old_opts.s_qf_names[i]); |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2723 | #endif |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 2724 | if (enable_quota) |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 2725 | dquot_resume(sb, -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | return 0; |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2727 | restore_opts: |
| 2728 | sb->s_flags = old_sb_flags; |
| 2729 | sbi->s_mount_opt = old_opts.s_mount_opt; |
| 2730 | sbi->s_resuid = old_opts.s_resuid; |
| 2731 | sbi->s_resgid = old_opts.s_resgid; |
| 2732 | sbi->s_commit_interval = old_opts.s_commit_interval; |
| 2733 | #ifdef CONFIG_QUOTA |
| 2734 | sbi->s_jquota_fmt = old_opts.s_jquota_fmt; |
| 2735 | for (i = 0; i < MAXQUOTAS; i++) { |
Jan Kara | f56426a | 2012-12-31 12:38:36 +0100 | [diff] [blame] | 2736 | kfree(sbi->s_qf_names[i]); |
Jan Kara | 08c6a96 | 2005-07-12 13:58:28 -0700 | [diff] [blame] | 2737 | sbi->s_qf_names[i] = old_opts.s_qf_names[i]; |
| 2738 | } |
| 2739 | #endif |
| 2740 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2743 | static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2745 | struct super_block *sb = dentry->d_sb; |
Alex Tomas | 09fe316 | 2006-03-24 03:16:16 -0800 | [diff] [blame] | 2746 | struct ext3_sb_info *sbi = EXT3_SB(sb); |
| 2747 | struct ext3_super_block *es = sbi->s_es; |
Pekka Enberg | 50ee0a3 | 2006-12-06 20:35:28 -0800 | [diff] [blame] | 2748 | u64 fsid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | |
Badari Pulavarty | a71ce8c | 2007-07-15 23:41:59 -0700 | [diff] [blame] | 2750 | if (test_opt(sb, MINIX_DF)) { |
| 2751 | sbi->s_overhead_last = 0; |
| 2752 | } else if (sbi->s_blocks_last != le32_to_cpu(es->s_blocks_count)) { |
| 2753 | unsigned long ngroups = sbi->s_groups_count, i; |
| 2754 | ext3_fsblk_t overhead = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | smp_rmb(); |
| 2756 | |
| 2757 | /* |
Badari Pulavarty | a71ce8c | 2007-07-15 23:41:59 -0700 | [diff] [blame] | 2758 | * Compute the overhead (FS structures). This is constant |
| 2759 | * for a given filesystem unless the number of block groups |
| 2760 | * changes so we cache the previous value until it does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | */ |
| 2762 | |
| 2763 | /* |
| 2764 | * All of the blocks before first_data_block are |
| 2765 | * overhead |
| 2766 | */ |
| 2767 | overhead = le32_to_cpu(es->s_first_data_block); |
| 2768 | |
| 2769 | /* |
| 2770 | * Add the overhead attributed to the superblock and |
| 2771 | * block group descriptors. If the sparse superblocks |
| 2772 | * feature is turned on, then not all groups have this. |
| 2773 | */ |
| 2774 | for (i = 0; i < ngroups; i++) { |
| 2775 | overhead += ext3_bg_has_super(sb, i) + |
| 2776 | ext3_bg_num_gdb(sb, i); |
| 2777 | cond_resched(); |
| 2778 | } |
| 2779 | |
| 2780 | /* |
| 2781 | * Every block group has an inode bitmap, a block |
| 2782 | * bitmap, and an inode table. |
| 2783 | */ |
Badari Pulavarty | a71ce8c | 2007-07-15 23:41:59 -0700 | [diff] [blame] | 2784 | overhead += ngroups * (2 + sbi->s_itb_per_group); |
| 2785 | sbi->s_overhead_last = overhead; |
| 2786 | smp_wmb(); |
| 2787 | sbi->s_blocks_last = le32_to_cpu(es->s_blocks_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2788 | } |
| 2789 | |
| 2790 | buf->f_type = EXT3_SUPER_MAGIC; |
| 2791 | buf->f_bsize = sb->s_blocksize; |
Badari Pulavarty | a71ce8c | 2007-07-15 23:41:59 -0700 | [diff] [blame] | 2792 | buf->f_blocks = le32_to_cpu(es->s_blocks_count) - sbi->s_overhead_last; |
Peter Zijlstra | 52d9f3b | 2007-10-16 23:25:44 -0700 | [diff] [blame] | 2793 | buf->f_bfree = percpu_counter_sum_positive(&sbi->s_freeblocks_counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | buf->f_bavail = buf->f_bfree - le32_to_cpu(es->s_r_blocks_count); |
| 2795 | if (buf->f_bfree < le32_to_cpu(es->s_r_blocks_count)) |
| 2796 | buf->f_bavail = 0; |
| 2797 | buf->f_files = le32_to_cpu(es->s_inodes_count); |
Peter Zijlstra | 52d9f3b | 2007-10-16 23:25:44 -0700 | [diff] [blame] | 2798 | buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | buf->f_namelen = EXT3_NAME_LEN; |
Pekka Enberg | 50ee0a3 | 2006-12-06 20:35:28 -0800 | [diff] [blame] | 2800 | fsid = le64_to_cpup((void *)es->s_uuid) ^ |
| 2801 | le64_to_cpup((void *)es->s_uuid + sizeof(u64)); |
| 2802 | buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; |
| 2803 | buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | return 0; |
| 2805 | } |
| 2806 | |
| 2807 | /* Helper function for writing quotas on sync - we need to start transaction before quota file |
| 2808 | * is locked for write. Otherwise the are possible deadlocks: |
| 2809 | * Process 1 Process 2 |
| 2810 | * ext3_create() quota_sync() |
| 2811 | * journal_start() write_dquot() |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 2812 | * dquot_initialize() down(dqio_mutex) |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 2813 | * down(dqio_mutex) journal_start() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | * |
| 2815 | */ |
| 2816 | |
| 2817 | #ifdef CONFIG_QUOTA |
| 2818 | |
| 2819 | static inline struct inode *dquot_to_inode(struct dquot *dquot) |
| 2820 | { |
Eric W. Biederman | 4c376dc | 2012-09-16 03:56:19 -0700 | [diff] [blame] | 2821 | return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | static int ext3_write_dquot(struct dquot *dquot) |
| 2825 | { |
| 2826 | int ret, err; |
| 2827 | handle_t *handle; |
| 2828 | struct inode *inode; |
| 2829 | |
| 2830 | inode = dquot_to_inode(dquot); |
| 2831 | handle = ext3_journal_start(inode, |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 2832 | EXT3_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | if (IS_ERR(handle)) |
| 2834 | return PTR_ERR(handle); |
| 2835 | ret = dquot_commit(dquot); |
| 2836 | err = ext3_journal_stop(handle); |
| 2837 | if (!ret) |
| 2838 | ret = err; |
| 2839 | return ret; |
| 2840 | } |
| 2841 | |
| 2842 | static int ext3_acquire_dquot(struct dquot *dquot) |
| 2843 | { |
| 2844 | int ret, err; |
| 2845 | handle_t *handle; |
| 2846 | |
| 2847 | handle = ext3_journal_start(dquot_to_inode(dquot), |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 2848 | EXT3_QUOTA_INIT_BLOCKS(dquot->dq_sb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | if (IS_ERR(handle)) |
| 2850 | return PTR_ERR(handle); |
| 2851 | ret = dquot_acquire(dquot); |
| 2852 | err = ext3_journal_stop(handle); |
| 2853 | if (!ret) |
| 2854 | ret = err; |
| 2855 | return ret; |
| 2856 | } |
| 2857 | |
| 2858 | static int ext3_release_dquot(struct dquot *dquot) |
| 2859 | { |
| 2860 | int ret, err; |
| 2861 | handle_t *handle; |
| 2862 | |
| 2863 | handle = ext3_journal_start(dquot_to_inode(dquot), |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 2864 | EXT3_QUOTA_DEL_BLOCKS(dquot->dq_sb)); |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2865 | if (IS_ERR(handle)) { |
| 2866 | /* Release dquot anyway to avoid endless cycle in dqput() */ |
| 2867 | dquot_release(dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | return PTR_ERR(handle); |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2869 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | ret = dquot_release(dquot); |
| 2871 | err = ext3_journal_stop(handle); |
| 2872 | if (!ret) |
| 2873 | ret = err; |
| 2874 | return ret; |
| 2875 | } |
| 2876 | |
| 2877 | static int ext3_mark_dquot_dirty(struct dquot *dquot) |
| 2878 | { |
Jan Kara | 99aeaf6 | 2008-07-25 01:46:17 -0700 | [diff] [blame] | 2879 | /* Are we journaling quotas? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | if (EXT3_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || |
| 2881 | EXT3_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { |
| 2882 | dquot_mark_dquot_dirty(dquot); |
| 2883 | return ext3_write_dquot(dquot); |
| 2884 | } else { |
| 2885 | return dquot_mark_dquot_dirty(dquot); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | static int ext3_write_info(struct super_block *sb, int type) |
| 2890 | { |
| 2891 | int ret, err; |
| 2892 | handle_t *handle; |
| 2893 | |
| 2894 | /* Data block + inode block */ |
| 2895 | handle = ext3_journal_start(sb->s_root->d_inode, 2); |
| 2896 | if (IS_ERR(handle)) |
| 2897 | return PTR_ERR(handle); |
| 2898 | ret = dquot_commit_info(sb, type); |
| 2899 | err = ext3_journal_stop(handle); |
| 2900 | if (!ret) |
| 2901 | ret = err; |
| 2902 | return ret; |
| 2903 | } |
| 2904 | |
| 2905 | /* |
| 2906 | * Turn on quotas during mount time - we need to find |
| 2907 | * the quota file and such... |
| 2908 | */ |
| 2909 | static int ext3_quota_on_mount(struct super_block *sb, int type) |
| 2910 | { |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 2911 | return dquot_quota_on_mount(sb, EXT3_SB(sb)->s_qf_names[type], |
| 2912 | EXT3_SB(sb)->s_jquota_fmt, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
| 2915 | /* |
| 2916 | * Standard function to be called on quota_on |
| 2917 | */ |
| 2918 | static int ext3_quota_on(struct super_block *sb, int type, int format_id, |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2919 | struct path *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | { |
| 2921 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | |
Jan Kara | 1f54587 | 2005-06-23 22:01:04 -0700 | [diff] [blame] | 2923 | if (!test_opt(sb, QUOTA)) |
| 2924 | return -EINVAL; |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | /* Quotafile not on the same filesystem? */ |
Al Viro | d8c9584 | 2011-12-07 18:16:57 -0500 | [diff] [blame] | 2927 | if (path->dentry->d_sb != sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | return -EXDEV; |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2929 | /* Journaling quota? */ |
| 2930 | if (EXT3_SB(sb)->s_qf_names[type]) { |
| 2931 | /* Quotafile not of fs root? */ |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2932 | if (path->dentry->d_parent != sb->s_root) |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 2933 | ext3_msg(sb, KERN_WARNING, |
| 2934 | "warning: Quota file not on filesystem root. " |
| 2935 | "Journaled quota will not work."); |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | /* |
| 2939 | * When we journal data on quota file, we have to flush journal to see |
| 2940 | * all updates to the file when we bypass pagecache... |
| 2941 | */ |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2942 | if (ext3_should_journal_data(path->dentry->d_inode)) { |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2943 | /* |
| 2944 | * We don't need to lock updates but journal_flush() could |
| 2945 | * otherwise be livelocked... |
| 2946 | */ |
| 2947 | journal_lock_updates(EXT3_SB(sb)->s_journal); |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 2948 | err = journal_flush(EXT3_SB(sb)->s_journal); |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2949 | journal_unlock_updates(EXT3_SB(sb)->s_journal); |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2950 | if (err) |
Hidehiro Kawai | 2d7c820 | 2008-10-22 14:15:01 -0700 | [diff] [blame] | 2951 | return err; |
Jan Kara | 9cfe7b9 | 2008-07-25 01:46:16 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2954 | return dquot_quota_on(sb, type, format_id, path); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | /* Read data from quotafile - avoid pagecache and such because we cannot afford |
| 2958 | * 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] | 2959 | * itself serializes the operations (and no one else should touch the files) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | * we don't have to be afraid of races */ |
| 2961 | static ssize_t ext3_quota_read(struct super_block *sb, int type, char *data, |
| 2962 | size_t len, loff_t off) |
| 2963 | { |
| 2964 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2965 | sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); |
| 2966 | int err = 0; |
| 2967 | int offset = off & (sb->s_blocksize - 1); |
| 2968 | int tocopy; |
| 2969 | size_t toread; |
| 2970 | struct buffer_head *bh; |
| 2971 | loff_t i_size = i_size_read(inode); |
| 2972 | |
| 2973 | if (off > i_size) |
| 2974 | return 0; |
| 2975 | if (off+len > i_size) |
| 2976 | len = i_size-off; |
| 2977 | toread = len; |
| 2978 | while (toread > 0) { |
| 2979 | tocopy = sb->s_blocksize - offset < toread ? |
| 2980 | sb->s_blocksize - offset : toread; |
| 2981 | bh = ext3_bread(NULL, inode, blk, 0, &err); |
| 2982 | if (err) |
| 2983 | return err; |
| 2984 | if (!bh) /* A hole? */ |
| 2985 | memset(data, 0, tocopy); |
| 2986 | else |
| 2987 | memcpy(data, bh->b_data+offset, tocopy); |
| 2988 | brelse(bh); |
| 2989 | offset = 0; |
| 2990 | toread -= tocopy; |
| 2991 | data += tocopy; |
| 2992 | blk++; |
| 2993 | } |
| 2994 | return len; |
| 2995 | } |
| 2996 | |
| 2997 | /* Write to quotafile (we know the transaction is already started and has |
| 2998 | * enough credits) */ |
| 2999 | static ssize_t ext3_quota_write(struct super_block *sb, int type, |
| 3000 | const char *data, size_t len, loff_t off) |
| 3001 | { |
| 3002 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 3003 | sector_t blk = off >> EXT3_BLOCK_SIZE_BITS(sb); |
| 3004 | int err = 0; |
| 3005 | int offset = off & (sb->s_blocksize - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | int journal_quota = EXT3_SB(sb)->s_qf_names[type] != NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | struct buffer_head *bh; |
| 3008 | handle_t *handle = journal_current_handle(); |
| 3009 | |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 3010 | if (!handle) { |
Alexey Fisher | 4cf46b6 | 2009-11-22 20:38:55 +0100 | [diff] [blame] | 3011 | ext3_msg(sb, KERN_WARNING, |
| 3012 | "warning: quota write (off=%llu, len=%llu)" |
| 3013 | " cancelled because transaction is not started.", |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 3014 | (unsigned long long)off, (unsigned long long)len); |
| 3015 | return -EIO; |
| 3016 | } |
Dmitry Monakhov | e547214 | 2010-02-16 19:33:42 +0300 | [diff] [blame] | 3017 | |
| 3018 | /* |
| 3019 | * Since we account only one data block in transaction credits, |
| 3020 | * then it is impossible to cross a block boundary. |
| 3021 | */ |
| 3022 | if (sb->s_blocksize - offset < len) { |
| 3023 | ext3_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)" |
| 3024 | " cancelled because not block aligned", |
| 3025 | (unsigned long long)off, (unsigned long long)len); |
| 3026 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } |
Dmitry Monakhov | e547214 | 2010-02-16 19:33:42 +0300 | [diff] [blame] | 3028 | bh = ext3_bread(handle, inode, blk, 1, &err); |
| 3029 | if (!bh) |
| 3030 | goto out; |
| 3031 | if (journal_quota) { |
| 3032 | err = ext3_journal_get_write_access(handle, bh); |
| 3033 | if (err) { |
| 3034 | brelse(bh); |
| 3035 | goto out; |
| 3036 | } |
| 3037 | } |
| 3038 | lock_buffer(bh); |
| 3039 | memcpy(bh->b_data+offset, data, len); |
| 3040 | flush_dcache_page(bh->b_page); |
| 3041 | unlock_buffer(bh); |
| 3042 | if (journal_quota) |
| 3043 | err = ext3_journal_dirty_metadata(handle, bh); |
| 3044 | else { |
| 3045 | /* Always do at least ordered writes for quotas */ |
| 3046 | err = ext3_journal_dirty_data(handle, bh); |
| 3047 | mark_buffer_dirty(bh); |
| 3048 | } |
| 3049 | brelse(bh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3050 | out: |
Jan Kara | 905c393 | 2012-04-25 21:24:30 +0200 | [diff] [blame] | 3051 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | return err; |
Dmitry Monakhov | e547214 | 2010-02-16 19:33:42 +0300 | [diff] [blame] | 3053 | if (inode->i_size < off + len) { |
| 3054 | i_size_write(inode, off + len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | EXT3_I(inode)->i_disksize = inode->i_size; |
| 3056 | } |
| 3057 | inode->i_version++; |
| 3058 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 3059 | ext3_mark_inode_dirty(handle, inode); |
Dmitry Monakhov | e547214 | 2010-02-16 19:33:42 +0300 | [diff] [blame] | 3060 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | #endif |
| 3064 | |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 3065 | static struct dentry *ext3_mount(struct file_system_type *fs_type, |
| 3066 | int flags, const char *dev_name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | { |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 3068 | return mount_bdev(fs_type, flags, dev_name, data, ext3_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | static struct file_system_type ext3_fs_type = { |
| 3072 | .owner = THIS_MODULE, |
| 3073 | .name = "ext3", |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 3074 | .mount = ext3_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | .kill_sb = kill_block_super, |
| 3076 | .fs_flags = FS_REQUIRES_DEV, |
| 3077 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 3078 | MODULE_ALIAS_FS("ext3"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | |
| 3080 | static int __init init_ext3_fs(void) |
| 3081 | { |
| 3082 | int err = init_ext3_xattr(); |
| 3083 | if (err) |
| 3084 | return err; |
| 3085 | err = init_inodecache(); |
| 3086 | if (err) |
| 3087 | goto out1; |
| 3088 | err = register_filesystem(&ext3_fs_type); |
| 3089 | if (err) |
| 3090 | goto out; |
| 3091 | return 0; |
| 3092 | out: |
| 3093 | destroy_inodecache(); |
| 3094 | out1: |
Dave Kleikamp | e9ad562 | 2006-09-27 01:49:35 -0700 | [diff] [blame] | 3095 | exit_ext3_xattr(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | return err; |
| 3097 | } |
| 3098 | |
| 3099 | static void __exit exit_ext3_fs(void) |
| 3100 | { |
| 3101 | unregister_filesystem(&ext3_fs_type); |
| 3102 | destroy_inodecache(); |
| 3103 | exit_ext3_xattr(); |
| 3104 | } |
| 3105 | |
| 3106 | MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); |
| 3107 | MODULE_DESCRIPTION("Second Extended Filesystem with journaling extensions"); |
| 3108 | MODULE_LICENSE("GPL"); |
| 3109 | module_init(init_ext3_fs) |
| 3110 | module_exit(exit_ext3_fs) |