Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README |
| 3 | * |
| 4 | * Trivial changes by Alan Cox to add the LFS fixes |
| 5 | * |
| 6 | * Trivial Changes: |
| 7 | * Rights granted to Hans Reiser to redistribute under other terms providing |
| 8 | * he accepts all liability including but not limited to patent, fitness |
| 9 | * for purpose, and direct or indirect claims arising from failure to perform. |
| 10 | * |
| 11 | * NO WARRANTY |
| 12 | */ |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/vmalloc.h> |
| 17 | #include <linux/time.h> |
| 18 | #include <asm/uaccess.h> |
Al Viro | f466c6f | 2012-03-17 01:16:43 -0400 | [diff] [blame] | 19 | #include "reiserfs.h" |
Al Viro | a3063ab | 2012-03-17 01:03:10 -0400 | [diff] [blame] | 20 | #include "acl.h" |
Al Viro | c45ac88 | 2012-03-17 00:59:06 -0400 | [diff] [blame] | 21 | #include "xattr.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/blkdev.h> |
| 24 | #include <linux/buffer_head.h> |
Christoph Hellwig | a569425 | 2007-07-17 04:04:28 -0700 | [diff] [blame] | 25 | #include <linux/exportfs.h> |
Jan Kara | 74abb98 | 2008-07-25 01:46:51 -0700 | [diff] [blame] | 26 | #include <linux/quotaops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/vfs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/mount.h> |
| 29 | #include <linux/namei.h> |
Coly Li | 651d062 | 2009-04-02 16:59:41 -0700 | [diff] [blame] | 30 | #include <linux/crc32.h> |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 31 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | struct file_system_type reiserfs_fs_type; |
| 34 | |
| 35 | static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING; |
| 36 | static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING; |
| 37 | static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING; |
| 38 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 39 | int is_reiserfs_3_5(struct reiserfs_super_block *rs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 41 | return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string, |
| 42 | strlen(reiserfs_3_5_magic_string)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 45 | int is_reiserfs_3_6(struct reiserfs_super_block *rs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 47 | return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string, |
| 48 | strlen(reiserfs_3_6_magic_string)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 51 | int is_reiserfs_jr(struct reiserfs_super_block *rs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 53 | return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string, |
| 54 | strlen(reiserfs_jr_magic_string)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 57 | static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 59 | return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) || |
| 60 | is_reiserfs_jr(rs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 63 | static int reiserfs_remount(struct super_block *s, int *flags, char *data); |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 64 | static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 66 | static int reiserfs_sync_fs(struct super_block *s, int wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
Christoph Hellwig | 5af7926 | 2009-05-05 15:41:25 +0200 | [diff] [blame] | 68 | struct reiserfs_transaction_handle th; |
| 69 | |
Jan Kara | a117782 | 2012-07-03 16:45:29 +0200 | [diff] [blame] | 70 | /* |
| 71 | * Writeback quota in non-journalled quota case - journalled quota has |
| 72 | * no dirty dquots |
| 73 | */ |
| 74 | dquot_writeback_dquots(s, -1); |
Christoph Hellwig | 5af7926 | 2009-05-05 15:41:25 +0200 | [diff] [blame] | 75 | reiserfs_write_lock(s); |
| 76 | if (!journal_begin(&th, s, 1)) |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 77 | if (!journal_end_sync(&th)) |
Christoph Hellwig | 5af7926 | 2009-05-05 15:41:25 +0200 | [diff] [blame] | 78 | reiserfs_flush_old_commits(s); |
Christoph Hellwig | 5af7926 | 2009-05-05 15:41:25 +0200 | [diff] [blame] | 79 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 80 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 83 | static void flush_old_commits(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 85 | struct reiserfs_sb_info *sbi; |
| 86 | struct super_block *s; |
| 87 | |
| 88 | sbi = container_of(work, struct reiserfs_sb_info, old_work.work); |
| 89 | s = sbi->s_journal->j_work_sb; |
| 90 | |
| 91 | spin_lock(&sbi->old_work_lock); |
| 92 | sbi->work_queued = 0; |
| 93 | spin_unlock(&sbi->old_work_lock); |
| 94 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 95 | reiserfs_sync_fs(s, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 98 | void reiserfs_schedule_old_flush(struct super_block *s) |
| 99 | { |
| 100 | struct reiserfs_sb_info *sbi = REISERFS_SB(s); |
| 101 | unsigned long delay; |
| 102 | |
| 103 | if (s->s_flags & MS_RDONLY) |
| 104 | return; |
| 105 | |
| 106 | spin_lock(&sbi->old_work_lock); |
| 107 | if (!sbi->work_queued) { |
| 108 | delay = msecs_to_jiffies(dirty_writeback_interval * 10); |
| 109 | queue_delayed_work(system_long_wq, &sbi->old_work, delay); |
| 110 | sbi->work_queued = 1; |
| 111 | } |
| 112 | spin_unlock(&sbi->old_work_lock); |
| 113 | } |
| 114 | |
| 115 | static void cancel_old_flush(struct super_block *s) |
| 116 | { |
| 117 | struct reiserfs_sb_info *sbi = REISERFS_SB(s); |
| 118 | |
| 119 | cancel_delayed_work_sync(&REISERFS_SB(s)->old_work); |
| 120 | spin_lock(&sbi->old_work_lock); |
| 121 | sbi->work_queued = 0; |
| 122 | spin_unlock(&sbi->old_work_lock); |
| 123 | } |
| 124 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 125 | static int reiserfs_freeze(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 127 | struct reiserfs_transaction_handle th; |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 128 | |
| 129 | cancel_old_flush(s); |
| 130 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 131 | reiserfs_write_lock(s); |
| 132 | if (!(s->s_flags & MS_RDONLY)) { |
| 133 | int err = journal_begin(&th, s, 1); |
| 134 | if (err) { |
| 135 | reiserfs_block_writes(&th); |
| 136 | } else { |
| 137 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), |
| 138 | 1); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 139 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 140 | reiserfs_block_writes(&th); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 141 | journal_end_sync(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 144 | reiserfs_write_unlock(s); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 145 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 148 | static int reiserfs_unfreeze(struct super_block *s) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 149 | { |
| 150 | reiserfs_allow_writes(s); |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 151 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 154 | extern const struct in_core_key MAX_IN_CORE_KEY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 156 | /* |
| 157 | * this is used to delete "save link" when there are no items of a |
| 158 | * file it points to. It can either happen if unlink is completed but |
| 159 | * "save unlink" removal, or if file has both unlink and truncate |
| 160 | * pending and as unlink completes first (because key of "save link" |
| 161 | * protecting unlink is bigger that a key lf "save link" which |
| 162 | * protects truncate), so there left no items to make truncate |
| 163 | * completion on |
| 164 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 165 | static int remove_save_link_only(struct super_block *s, |
| 166 | struct reiserfs_key *key, int oid_free) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 168 | struct reiserfs_transaction_handle th; |
| 169 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 171 | /* we are going to do one balancing */ |
| 172 | err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT); |
| 173 | if (err) |
| 174 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 176 | reiserfs_delete_solid_item(&th, NULL, key); |
| 177 | if (oid_free) |
| 178 | /* removals are protected by direct items */ |
| 179 | reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid)); |
| 180 | |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 181 | return journal_end(&th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #ifdef CONFIG_QUOTA |
| 185 | static int reiserfs_quota_on_mount(struct super_block *, int); |
| 186 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | /* look for uncompleted unlinks and truncates and complete them */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 189 | static int finish_unfinished(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 191 | INITIALIZE_PATH(path); |
| 192 | struct cpu_key max_cpu_key, obj_key; |
Lepton Wu | fb46f34 | 2007-10-16 23:30:04 -0700 | [diff] [blame] | 193 | struct reiserfs_key save_link_key, last_inode_key; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 194 | int retval = 0; |
| 195 | struct item_head *ih; |
| 196 | struct buffer_head *bh; |
| 197 | int item_pos; |
| 198 | char *item; |
| 199 | int done; |
| 200 | struct inode *inode; |
| 201 | int truncate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 203 | int i; |
| 204 | int ms_active_set; |
Jan Kara | f4b113a | 2010-05-21 19:12:51 +0200 | [diff] [blame] | 205 | int quota_enabled[MAXQUOTAS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 207 | |
| 208 | /* compose key to look for "save" links */ |
| 209 | max_cpu_key.version = KEY_FORMAT_3_5; |
| 210 | max_cpu_key.on_disk_key.k_dir_id = ~0U; |
| 211 | max_cpu_key.on_disk_key.k_objectid = ~0U; |
| 212 | set_cpu_key_k_offset(&max_cpu_key, ~0U); |
| 213 | max_cpu_key.key_length = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Lepton Wu | fb46f34 | 2007-10-16 23:30:04 -0700 | [diff] [blame] | 215 | memset(&last_inode_key, 0, sizeof(last_inode_key)); |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 218 | /* Needed for iput() to work correctly and not trash data */ |
| 219 | if (s->s_flags & MS_ACTIVE) { |
| 220 | ms_active_set = 0; |
| 221 | } else { |
| 222 | ms_active_set = 1; |
| 223 | s->s_flags |= MS_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 225 | /* Turn on quotas so that they are updated correctly */ |
| 226 | for (i = 0; i < MAXQUOTAS; i++) { |
Jan Kara | f4b113a | 2010-05-21 19:12:51 +0200 | [diff] [blame] | 227 | quota_enabled[i] = 1; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 228 | if (REISERFS_SB(s)->s_qf_names[i]) { |
Jan Kara | f4b113a | 2010-05-21 19:12:51 +0200 | [diff] [blame] | 229 | int ret; |
| 230 | |
| 231 | if (sb_has_quota_active(s, i)) { |
| 232 | quota_enabled[i] = 0; |
| 233 | continue; |
| 234 | } |
| 235 | ret = reiserfs_quota_on_mount(s, i); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 236 | if (ret < 0) |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 237 | reiserfs_warning(s, "reiserfs-2500", |
| 238 | "cannot turn on journaled " |
| 239 | "quota: error %d", ret); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 240 | } |
| 241 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 244 | done = 0; |
| 245 | REISERFS_SB(s)->s_is_unlinked_ok = 1; |
| 246 | while (!retval) { |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 247 | int depth; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 248 | retval = search_item(s, &max_cpu_key, &path); |
| 249 | if (retval != ITEM_NOT_FOUND) { |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 250 | reiserfs_error(s, "vs-2140", |
| 251 | "search_by_key returned %d", retval); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 252 | break; |
| 253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 255 | bh = get_last_bh(&path); |
| 256 | item_pos = get_item_pos(&path); |
| 257 | if (item_pos != B_NR_ITEMS(bh)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 258 | reiserfs_warning(s, "vs-2060", |
| 259 | "wrong position found"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 260 | break; |
| 261 | } |
| 262 | item_pos--; |
Jeff Mahoney | 4cf5f7a | 2014-04-23 10:00:35 -0400 | [diff] [blame] | 263 | ih = item_head(bh, item_pos); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 264 | |
| 265 | if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID) |
| 266 | /* there are no "save" links anymore */ |
| 267 | break; |
| 268 | |
| 269 | save_link_key = ih->ih_key; |
| 270 | if (is_indirect_le_ih(ih)) |
| 271 | truncate = 1; |
| 272 | else |
| 273 | truncate = 0; |
| 274 | |
| 275 | /* reiserfs_iget needs k_dirid and k_objectid only */ |
Jeff Mahoney | 4cf5f7a | 2014-04-23 10:00:35 -0400 | [diff] [blame] | 276 | item = ih_item_body(bh, ih); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 277 | obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item); |
| 278 | obj_key.on_disk_key.k_objectid = |
| 279 | le32_to_cpu(ih->ih_key.k_objectid); |
| 280 | obj_key.on_disk_key.k_offset = 0; |
| 281 | obj_key.on_disk_key.k_type = 0; |
| 282 | |
| 283 | pathrelse(&path); |
| 284 | |
| 285 | inode = reiserfs_iget(s, &obj_key); |
| 286 | if (!inode) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 287 | /* |
| 288 | * the unlink almost completed, it just did not |
| 289 | * manage to remove "save" link and release objectid |
| 290 | */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 291 | reiserfs_warning(s, "vs-2180", "iget failed for %K", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 292 | &obj_key); |
| 293 | retval = remove_save_link_only(s, &save_link_key, 1); |
| 294 | continue; |
| 295 | } |
| 296 | |
| 297 | if (!truncate && inode->i_nlink) { |
| 298 | /* file is not unlinked */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 299 | reiserfs_warning(s, "vs-2185", |
| 300 | "file %K is not unlinked", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 301 | &obj_key); |
| 302 | retval = remove_save_link_only(s, &save_link_key, 0); |
| 303 | continue; |
| 304 | } |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 305 | depth = reiserfs_write_unlock_nested(inode->i_sb); |
Christoph Hellwig | 871a293 | 2010-03-03 09:05:07 -0500 | [diff] [blame] | 306 | dquot_initialize(inode); |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 307 | reiserfs_write_lock_nested(inode->i_sb, depth); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 308 | |
| 309 | if (truncate && S_ISDIR(inode->i_mode)) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 310 | /* |
| 311 | * We got a truncate request for a dir which |
| 312 | * is impossible. The only imaginable way is to |
| 313 | * execute unfinished truncate request then boot |
| 314 | * into old kernel, remove the file and create dir |
| 315 | * with the same key. |
| 316 | */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 317 | reiserfs_warning(s, "green-2101", |
| 318 | "impossible truncate on a " |
| 319 | "directory %k. Please report", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 320 | INODE_PKEY(inode)); |
| 321 | retval = remove_save_link_only(s, &save_link_key, 0); |
| 322 | truncate = 0; |
| 323 | iput(inode); |
| 324 | continue; |
| 325 | } |
| 326 | |
| 327 | if (truncate) { |
| 328 | REISERFS_I(inode)->i_flags |= |
| 329 | i_link_saved_truncate_mask; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 330 | /* |
| 331 | * not completed truncate found. New size was |
| 332 | * committed together with "save" link |
| 333 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 334 | reiserfs_info(s, "Truncating %k to %Ld ..", |
| 335 | INODE_PKEY(inode), inode->i_size); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 336 | |
| 337 | /* don't update modification time */ |
| 338 | reiserfs_truncate_file(inode, 0); |
| 339 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 340 | retval = remove_save_link(inode, truncate); |
| 341 | } else { |
| 342 | REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask; |
| 343 | /* not completed unlink (rmdir) found */ |
| 344 | reiserfs_info(s, "Removing %k..", INODE_PKEY(inode)); |
Lepton Wu | fb46f34 | 2007-10-16 23:30:04 -0700 | [diff] [blame] | 345 | if (memcmp(&last_inode_key, INODE_PKEY(inode), |
| 346 | sizeof(last_inode_key))){ |
| 347 | last_inode_key = *INODE_PKEY(inode); |
| 348 | /* removal gets completed in iput */ |
| 349 | retval = 0; |
| 350 | } else { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 351 | reiserfs_warning(s, "super-2189", "Dead loop " |
| 352 | "in finish_unfinished " |
| 353 | "detected, just remove " |
| 354 | "save link\n"); |
Lepton Wu | fb46f34 | 2007-10-16 23:30:04 -0700 | [diff] [blame] | 355 | retval = remove_save_link_only(s, |
| 356 | &save_link_key, 0); |
| 357 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | iput(inode); |
| 361 | printk("done\n"); |
| 362 | done++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 364 | REISERFS_SB(s)->s_is_unlinked_ok = 0; |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 367 | /* Turn quotas off */ |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 368 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 369 | for (i = 0; i < MAXQUOTAS; i++) { |
Jan Kara | f4b113a | 2010-05-21 19:12:51 +0200 | [diff] [blame] | 370 | if (sb_dqopt(s)->files[i] && quota_enabled[i]) |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 371 | dquot_quota_off(s, i); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 372 | } |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 373 | reiserfs_write_lock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 374 | if (ms_active_set) |
| 375 | /* Restore the flag back */ |
| 376 | s->s_flags &= ~MS_ACTIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 378 | pathrelse(&path); |
| 379 | if (done) |
| 380 | reiserfs_info(s, "There were %d uncompleted unlinks/truncates. " |
| 381 | "Completed\n", done); |
| 382 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 384 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 385 | /* |
| 386 | * to protect file being unlinked from getting lost we "safe" link files |
| 387 | * being unlinked. This link will be deleted in the same transaction with last |
| 388 | * item of file. mounting the filesystem we scan all these links and remove |
| 389 | * files which almost got lost |
| 390 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 391 | void add_save_link(struct reiserfs_transaction_handle *th, |
| 392 | struct inode *inode, int truncate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 394 | INITIALIZE_PATH(path); |
| 395 | int retval; |
| 396 | struct cpu_key key; |
| 397 | struct item_head ih; |
| 398 | __le32 link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 400 | BUG_ON(!th->t_trans_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 402 | /* file can only get one "save link" of each kind */ |
| 403 | RFALSE(truncate && |
| 404 | (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask), |
| 405 | "saved link already exists for truncated inode %lx", |
| 406 | (long)inode->i_ino); |
| 407 | RFALSE(!truncate && |
| 408 | (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask), |
| 409 | "saved link already exists for unlinked inode %lx", |
| 410 | (long)inode->i_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 412 | /* setup key of "save" link */ |
| 413 | key.version = KEY_FORMAT_3_5; |
| 414 | key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID; |
| 415 | key.on_disk_key.k_objectid = inode->i_ino; |
| 416 | if (!truncate) { |
| 417 | /* unlink, rmdir, rename */ |
| 418 | set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize); |
| 419 | set_cpu_key_k_type(&key, TYPE_DIRECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 421 | /* item head of "safe" link */ |
| 422 | make_le_item_head(&ih, &key, key.version, |
| 423 | 1 + inode->i_sb->s_blocksize, TYPE_DIRECT, |
| 424 | 4 /*length */ , 0xffff /*free space */ ); |
| 425 | } else { |
| 426 | /* truncate */ |
| 427 | if (S_ISDIR(inode->i_mode)) |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 428 | reiserfs_warning(inode->i_sb, "green-2102", |
| 429 | "Adding a truncate savelink for " |
| 430 | "a directory %k! Please report", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 431 | INODE_PKEY(inode)); |
| 432 | set_cpu_key_k_offset(&key, 1); |
| 433 | set_cpu_key_k_type(&key, TYPE_INDIRECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 435 | /* item head of "safe" link */ |
| 436 | make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT, |
| 437 | 4 /*length */ , 0 /*free space */ ); |
| 438 | } |
| 439 | key.key_length = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 441 | /* look for its place in the tree */ |
| 442 | retval = search_item(inode->i_sb, &key, &path); |
| 443 | if (retval != ITEM_NOT_FOUND) { |
| 444 | if (retval != -ENOSPC) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 445 | reiserfs_error(inode->i_sb, "vs-2100", |
| 446 | "search_by_key (%K) returned %d", &key, |
| 447 | retval); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 448 | pathrelse(&path); |
| 449 | return; |
| 450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 452 | /* body of "save" link */ |
| 453 | link = INODE_PKEY(inode)->k_dir_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 455 | /* put "save" link into tree, don't charge quota to anyone */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 456 | retval = |
| 457 | reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link); |
| 458 | if (retval) { |
| 459 | if (retval != -ENOSPC) |
Jeff Mahoney | 0030b64 | 2009-03-30 14:02:28 -0400 | [diff] [blame] | 460 | reiserfs_error(inode->i_sb, "vs-2120", |
| 461 | "insert_item returned %d", retval); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 462 | } else { |
| 463 | if (truncate) |
| 464 | REISERFS_I(inode)->i_flags |= |
| 465 | i_link_saved_truncate_mask; |
| 466 | else |
| 467 | REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask; |
| 468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* this opens transaction unlike add_save_link */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 472 | int remove_save_link(struct inode *inode, int truncate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 474 | struct reiserfs_transaction_handle th; |
| 475 | struct reiserfs_key key; |
| 476 | int err; |
| 477 | |
| 478 | /* we are going to do one balancing only */ |
| 479 | err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT); |
| 480 | if (err) |
| 481 | return err; |
| 482 | |
| 483 | /* setup key of "save" link */ |
| 484 | key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID); |
| 485 | key.k_objectid = INODE_PKEY(inode)->k_objectid; |
| 486 | if (!truncate) { |
| 487 | /* unlink, rmdir, rename */ |
| 488 | set_le_key_k_offset(KEY_FORMAT_3_5, &key, |
| 489 | 1 + inode->i_sb->s_blocksize); |
| 490 | set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT); |
| 491 | } else { |
| 492 | /* truncate */ |
| 493 | set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1); |
| 494 | set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT); |
| 495 | } |
| 496 | |
| 497 | if ((truncate && |
| 498 | (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) || |
| 499 | (!truncate && |
| 500 | (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask))) |
| 501 | /* don't take quota bytes from anywhere */ |
| 502 | reiserfs_delete_solid_item(&th, NULL, &key); |
| 503 | if (!truncate) { |
| 504 | reiserfs_release_objectid(&th, inode->i_ino); |
| 505 | REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask; |
| 506 | } else |
| 507 | REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask; |
| 508 | |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 509 | return journal_end(&th); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | |
David Howells | edc666e | 2006-10-11 01:22:14 -0700 | [diff] [blame] | 512 | static void reiserfs_kill_sb(struct super_block *s) |
| 513 | { |
| 514 | if (REISERFS_SB(s)) { |
Al Viro | 672fe15 | 2013-08-05 17:37:37 +0400 | [diff] [blame] | 515 | reiserfs_proc_info_done(s); |
Jeff Mahoney | a9e36da | 2011-12-21 21:18:43 +0100 | [diff] [blame] | 516 | /* |
| 517 | * Force any pending inode evictions to occur now. Any |
| 518 | * inodes to be removed that have extended attributes |
| 519 | * associated with them need to clean them up before |
| 520 | * we can release the extended attribute root dentries. |
| 521 | * shrink_dcache_for_umount will BUG if we don't release |
| 522 | * those before it's called so ->put_super is too late. |
| 523 | */ |
| 524 | shrink_dcache_sb(s); |
| 525 | |
| 526 | dput(REISERFS_SB(s)->xattr_root); |
| 527 | REISERFS_SB(s)->xattr_root = NULL; |
| 528 | dput(REISERFS_SB(s)->priv_root); |
| 529 | REISERFS_SB(s)->priv_root = NULL; |
David Howells | edc666e | 2006-10-11 01:22:14 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | kill_block_super(s); |
| 533 | } |
| 534 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 535 | static void reiserfs_put_super(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 537 | struct reiserfs_transaction_handle th; |
| 538 | th.t_trans_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
Christoph Hellwig | e0ccfd9 | 2010-05-19 07:16:42 -0400 | [diff] [blame] | 540 | dquot_disable(s, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); |
| 541 | |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 542 | reiserfs_write_lock(s); |
Christoph Hellwig | 6cfd014 | 2009-05-05 15:40:36 +0200 | [diff] [blame] | 543 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 544 | /* |
| 545 | * change file system state to current state if it was mounted |
| 546 | * with read-write permissions |
| 547 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 548 | if (!(s->s_flags & MS_RDONLY)) { |
| 549 | if (!journal_begin(&th, s, 10)) { |
| 550 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), |
| 551 | 1); |
| 552 | set_sb_umount_state(SB_DISK_SUPER_BLOCK(s), |
| 553 | REISERFS_SB(s)->s_mount_state); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 554 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 558 | /* |
| 559 | * note, journal_release checks for readonly mount, and can |
| 560 | * decide not to do a journal_end |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 561 | */ |
| 562 | journal_release(&th, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Jeff Mahoney | 5065227 | 2006-09-30 23:28:44 -0700 | [diff] [blame] | 564 | reiserfs_free_bitmap_cache(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 566 | brelse(SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 568 | print_statistics(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 570 | if (REISERFS_SB(s)->reserved_blocks != 0) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 571 | reiserfs_warning(s, "green-2005", "reserved blocks left %d", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 572 | REISERFS_SB(s)->reserved_blocks); |
| 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 575 | reiserfs_write_unlock(s); |
| 576 | mutex_destroy(&REISERFS_SB(s)->lock); |
Jeff Mahoney | 797d901 | 2014-04-23 10:00:34 -0400 | [diff] [blame] | 577 | destroy_workqueue(REISERFS_SB(s)->commit_wq); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 578 | kfree(s->s_fs_info); |
| 579 | s->s_fs_info = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 582 | static struct kmem_cache *reiserfs_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
| 584 | static struct inode *reiserfs_alloc_inode(struct super_block *sb) |
| 585 | { |
| 586 | struct reiserfs_inode_info *ei; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 587 | ei = (struct reiserfs_inode_info *) |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 588 | kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | if (!ei) |
| 590 | return NULL; |
Al Viro | 0e4f6a7 | 2010-07-04 12:18:57 +0400 | [diff] [blame] | 591 | atomic_set(&ei->openers, 0); |
| 592 | mutex_init(&ei->tailpack); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | return &ei->vfs_inode; |
| 594 | } |
| 595 | |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 596 | static void reiserfs_i_callback(struct rcu_head *head) |
| 597 | { |
| 598 | struct inode *inode = container_of(head, struct inode, i_rcu); |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 599 | kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode)); |
| 600 | } |
| 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | static void reiserfs_destroy_inode(struct inode *inode) |
| 603 | { |
Nick Piggin | fa0d7e3d | 2011-01-07 17:49:49 +1100 | [diff] [blame] | 604 | call_rcu(&inode->i_rcu, reiserfs_i_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 607 | static void init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 609 | struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 611 | INIT_LIST_HEAD(&ei->i_prealloc_list); |
| 612 | inode_init_once(&ei->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 614 | |
Fabian Frederick | 31e1436 | 2014-04-03 14:50:37 -0700 | [diff] [blame] | 615 | static int __init init_inodecache(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
| 617 | reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 618 | sizeof(struct |
| 619 | reiserfs_inode_info), |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 620 | 0, (SLAB_RECLAIM_ACCOUNT| |
| 621 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 622 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | if (reiserfs_inode_cachep == NULL) |
| 624 | return -ENOMEM; |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static void destroy_inodecache(void) |
| 629 | { |
Kirill A. Shutemov | 8c0a853 | 2012-09-26 11:33:07 +1000 | [diff] [blame] | 630 | /* |
| 631 | * Make sure all delayed rcu free inodes are flushed before we |
| 632 | * destroy cache. |
| 633 | */ |
| 634 | rcu_barrier(); |
Alexey Dobriyan | 1a1d92c | 2006-09-27 01:49:40 -0700 | [diff] [blame] | 635 | kmem_cache_destroy(reiserfs_inode_cachep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* we don't mark inodes dirty, we just log them */ |
Christoph Hellwig | aa38572 | 2011-05-27 06:53:02 -0400 | [diff] [blame] | 639 | static void reiserfs_dirty_inode(struct inode *inode, int flags) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 640 | { |
| 641 | struct reiserfs_transaction_handle th; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 643 | int err = 0; |
Frederic Weisbecker | dc8f6d8 | 2009-04-14 05:34:25 +0200 | [diff] [blame] | 644 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 645 | if (inode->i_sb->s_flags & MS_RDONLY) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 646 | reiserfs_warning(inode->i_sb, "clm-6006", |
| 647 | "writing inode %lu on readonly FS", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 648 | inode->i_ino); |
| 649 | return; |
| 650 | } |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 651 | reiserfs_write_lock(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 653 | /* |
| 654 | * this is really only used for atime updates, so they don't have |
| 655 | * to be included in O_SYNC or fsync |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 656 | */ |
| 657 | err = journal_begin(&th, inode->i_sb, 1); |
Frederic Weisbecker | dc8f6d8 | 2009-04-14 05:34:25 +0200 | [diff] [blame] | 658 | if (err) |
| 659 | goto out; |
| 660 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 661 | reiserfs_update_sd(&th, inode); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 662 | journal_end(&th); |
Frederic Weisbecker | dc8f6d8 | 2009-04-14 05:34:25 +0200 | [diff] [blame] | 663 | |
| 664 | out: |
Jeff Mahoney | 278f667 | 2013-08-08 17:34:46 -0400 | [diff] [blame] | 665 | reiserfs_write_unlock(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 668 | static int reiserfs_show_options(struct seq_file *seq, struct dentry *root) |
| 669 | { |
| 670 | struct super_block *s = root->d_sb; |
| 671 | struct reiserfs_journal *journal = SB_JOURNAL(s); |
| 672 | long opts = REISERFS_SB(s)->s_mount_opt; |
| 673 | |
| 674 | if (opts & (1 << REISERFS_LARGETAIL)) |
| 675 | seq_puts(seq, ",tails=on"); |
| 676 | else if (!(opts & (1 << REISERFS_SMALLTAIL))) |
| 677 | seq_puts(seq, ",notail"); |
| 678 | /* tails=small is default so we don't show it */ |
| 679 | |
| 680 | if (!(opts & (1 << REISERFS_BARRIER_FLUSH))) |
| 681 | seq_puts(seq, ",barrier=none"); |
| 682 | /* barrier=flush is default so we don't show it */ |
| 683 | |
| 684 | if (opts & (1 << REISERFS_ERROR_CONTINUE)) |
| 685 | seq_puts(seq, ",errors=continue"); |
| 686 | else if (opts & (1 << REISERFS_ERROR_PANIC)) |
| 687 | seq_puts(seq, ",errors=panic"); |
| 688 | /* errors=ro is default so we don't show it */ |
| 689 | |
| 690 | if (opts & (1 << REISERFS_DATA_LOG)) |
| 691 | seq_puts(seq, ",data=journal"); |
| 692 | else if (opts & (1 << REISERFS_DATA_WRITEBACK)) |
| 693 | seq_puts(seq, ",data=writeback"); |
| 694 | /* data=ordered is default so we don't show it */ |
| 695 | |
| 696 | if (opts & (1 << REISERFS_ATTRS)) |
| 697 | seq_puts(seq, ",attrs"); |
| 698 | |
| 699 | if (opts & (1 << REISERFS_XATTRS_USER)) |
| 700 | seq_puts(seq, ",user_xattr"); |
| 701 | |
| 702 | if (opts & (1 << REISERFS_EXPOSE_PRIVROOT)) |
| 703 | seq_puts(seq, ",expose_privroot"); |
| 704 | |
| 705 | if (opts & (1 << REISERFS_POSIXACL)) |
| 706 | seq_puts(seq, ",acl"); |
| 707 | |
| 708 | if (REISERFS_SB(s)->s_jdev) |
| 709 | seq_printf(seq, ",jdev=%s", REISERFS_SB(s)->s_jdev); |
| 710 | |
| 711 | if (journal->j_max_commit_age != journal->j_default_max_commit_age) |
| 712 | seq_printf(seq, ",commit=%d", journal->j_max_commit_age); |
| 713 | |
| 714 | #ifdef CONFIG_QUOTA |
| 715 | if (REISERFS_SB(s)->s_qf_names[USRQUOTA]) |
| 716 | seq_printf(seq, ",usrjquota=%s", REISERFS_SB(s)->s_qf_names[USRQUOTA]); |
| 717 | else if (opts & (1 << REISERFS_USRQUOTA)) |
| 718 | seq_puts(seq, ",usrquota"); |
| 719 | if (REISERFS_SB(s)->s_qf_names[GRPQUOTA]) |
| 720 | seq_printf(seq, ",grpjquota=%s", REISERFS_SB(s)->s_qf_names[GRPQUOTA]); |
| 721 | else if (opts & (1 << REISERFS_GRPQUOTA)) |
| 722 | seq_puts(seq, ",grpquota"); |
| 723 | if (REISERFS_SB(s)->s_jquota_fmt) { |
| 724 | if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_OLD) |
| 725 | seq_puts(seq, ",jqfmt=vfsold"); |
| 726 | else if (REISERFS_SB(s)->s_jquota_fmt == QFMT_VFS_V0) |
| 727 | seq_puts(seq, ",jqfmt=vfsv0"); |
| 728 | } |
| 729 | #endif |
| 730 | |
| 731 | /* Block allocator options */ |
| 732 | if (opts & (1 << REISERFS_NO_BORDER)) |
| 733 | seq_puts(seq, ",block-allocator=noborder"); |
| 734 | if (opts & (1 << REISERFS_NO_UNHASHED_RELOCATION)) |
| 735 | seq_puts(seq, ",block-allocator=no_unhashed_relocation"); |
| 736 | if (opts & (1 << REISERFS_HASHED_RELOCATION)) |
| 737 | seq_puts(seq, ",block-allocator=hashed_relocation"); |
| 738 | if (opts & (1 << REISERFS_TEST4)) |
| 739 | seq_puts(seq, ",block-allocator=test4"); |
| 740 | show_alloc_options(seq, s); |
| 741 | return 0; |
| 742 | } |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 745 | static ssize_t reiserfs_quota_write(struct super_block *, int, const char *, |
| 746 | size_t, loff_t); |
| 747 | static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t, |
| 748 | loff_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | #endif |
| 750 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 751 | static const struct super_operations reiserfs_sops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 752 | .alloc_inode = reiserfs_alloc_inode, |
| 753 | .destroy_inode = reiserfs_destroy_inode, |
| 754 | .write_inode = reiserfs_write_inode, |
| 755 | .dirty_inode = reiserfs_dirty_inode, |
Al Viro | 845a2cc | 2010-06-07 11:37:37 -0400 | [diff] [blame] | 756 | .evict_inode = reiserfs_evict_inode, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 757 | .put_super = reiserfs_put_super, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 758 | .sync_fs = reiserfs_sync_fs, |
Takashi Sato | c4be0c1 | 2009-01-09 16:40:58 -0800 | [diff] [blame] | 759 | .freeze_fs = reiserfs_freeze, |
| 760 | .unfreeze_fs = reiserfs_unfreeze, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 761 | .statfs = reiserfs_statfs, |
| 762 | .remount_fs = reiserfs_remount, |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 763 | .show_options = reiserfs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 765 | .quota_read = reiserfs_quota_read, |
| 766 | .quota_write = reiserfs_quota_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | #endif |
| 768 | }; |
| 769 | |
| 770 | #ifdef CONFIG_QUOTA |
| 771 | #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") |
| 772 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | static int reiserfs_write_dquot(struct dquot *); |
| 774 | static int reiserfs_acquire_dquot(struct dquot *); |
| 775 | static int reiserfs_release_dquot(struct dquot *); |
| 776 | static int reiserfs_mark_dquot_dirty(struct dquot *); |
| 777 | static int reiserfs_write_info(struct super_block *, int); |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 778 | static int reiserfs_quota_on(struct super_block *, int, int, struct path *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | |
Alexey Dobriyan | 61e225d | 2009-09-21 17:01:08 -0700 | [diff] [blame] | 780 | static const struct dquot_operations reiserfs_quota_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 781 | .write_dquot = reiserfs_write_dquot, |
| 782 | .acquire_dquot = reiserfs_acquire_dquot, |
| 783 | .release_dquot = reiserfs_release_dquot, |
| 784 | .mark_dirty = reiserfs_mark_dquot_dirty, |
| 785 | .write_info = reiserfs_write_info, |
Jan Kara | 4103003 | 2008-11-25 15:31:33 +0100 | [diff] [blame] | 786 | .alloc_dquot = dquot_alloc, |
| 787 | .destroy_dquot = dquot_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | }; |
| 789 | |
Alexey Dobriyan | 0d54b21 | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 790 | static const struct quotactl_ops reiserfs_qctl_operations = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 791 | .quota_on = reiserfs_quota_on, |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 792 | .quota_off = dquot_quota_off, |
| 793 | .quota_sync = dquot_quota_sync, |
| 794 | .get_info = dquot_get_dqinfo, |
| 795 | .set_info = dquot_set_dqinfo, |
| 796 | .get_dqblk = dquot_get_dqblk, |
| 797 | .set_dqblk = dquot_set_dqblk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | }; |
| 799 | #endif |
| 800 | |
Christoph Hellwig | 3965516 | 2007-10-21 16:42:17 -0700 | [diff] [blame] | 801 | static const struct export_operations reiserfs_export_ops = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 802 | .encode_fh = reiserfs_encode_fh, |
Christoph Hellwig | be55caf | 2007-10-21 16:42:13 -0700 | [diff] [blame] | 803 | .fh_to_dentry = reiserfs_fh_to_dentry, |
| 804 | .fh_to_parent = reiserfs_fh_to_parent, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 805 | .get_parent = reiserfs_get_parent, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 806 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 808 | /* |
| 809 | * this struct is used in reiserfs_getopt () for containing the value for |
| 810 | * those mount options that have values rather than being toggles. |
| 811 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | typedef struct { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 813 | char *value; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 814 | /* |
| 815 | * bitmask which is to set on mount_options bitmask |
| 816 | * when this value is found, 0 is no bits are to be changed. |
| 817 | */ |
| 818 | int setmask; |
| 819 | /* |
| 820 | * bitmask which is to clear on mount_options bitmask |
| 821 | * when this value is found, 0 is no bits are to be changed. |
| 822 | * This is applied BEFORE setmask |
| 823 | */ |
| 824 | int clrmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | } arg_desc_t; |
| 826 | |
| 827 | /* Set this bit in arg_required to allow empty arguments */ |
| 828 | #define REISERFS_OPT_ALLOWEMPTY 31 |
| 829 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 830 | /* |
| 831 | * this struct is used in reiserfs_getopt() for describing the |
| 832 | * set of reiserfs mount options |
| 833 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | typedef struct { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 835 | char *option_name; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 836 | |
| 837 | /* 0 if argument is not required, not 0 otherwise */ |
| 838 | int arg_required; |
| 839 | |
| 840 | /* list of values accepted by an option */ |
| 841 | const arg_desc_t *values; |
| 842 | |
| 843 | /* |
| 844 | * bitmask which is to set on mount_options bitmask |
| 845 | * when this value is found, 0 is no bits are to be changed. |
| 846 | */ |
| 847 | int setmask; |
| 848 | |
| 849 | /* |
| 850 | * bitmask which is to clear on mount_options bitmask |
| 851 | * when this value is found, 0 is no bits are to be changed. |
| 852 | * This is applied BEFORE setmask |
| 853 | */ |
| 854 | int clrmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | } opt_desc_t; |
| 856 | |
| 857 | /* possible values for -o data= */ |
| 858 | static const arg_desc_t logging_mode[] = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 859 | {"ordered", 1 << REISERFS_DATA_ORDERED, |
| 860 | (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)}, |
| 861 | {"journal", 1 << REISERFS_DATA_LOG, |
| 862 | (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)}, |
| 863 | {"writeback", 1 << REISERFS_DATA_WRITEBACK, |
| 864 | (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)}, |
Vladimir V. Saveliev | cd02b96 | 2006-03-25 03:07:15 -0800 | [diff] [blame] | 865 | {.value = NULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | }; |
| 867 | |
| 868 | /* possible values for -o barrier= */ |
| 869 | static const arg_desc_t barrier_mode[] = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 870 | {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH}, |
| 871 | {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE}, |
Vladimir V. Saveliev | cd02b96 | 2006-03-25 03:07:15 -0800 | [diff] [blame] | 872 | {.value = NULL} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | }; |
| 874 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 875 | /* |
| 876 | * possible values for "-o block-allocator=" and bits which are to be set in |
| 877 | * s_mount_opt of reiserfs specific part of in-core super block |
| 878 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | static const arg_desc_t balloc[] = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 880 | {"noborder", 1 << REISERFS_NO_BORDER, 0}, |
| 881 | {"border", 0, 1 << REISERFS_NO_BORDER}, |
| 882 | {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0}, |
| 883 | {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0}, |
| 884 | {"test4", 1 << REISERFS_TEST4, 0}, |
| 885 | {"notest4", 0, 1 << REISERFS_TEST4}, |
| 886 | {NULL, 0, 0} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | static const arg_desc_t tails[] = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 890 | {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL}, |
| 891 | {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)}, |
| 892 | {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL}, |
| 893 | {NULL, 0, 0} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | }; |
| 895 | |
| 896 | static const arg_desc_t error_actions[] = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 897 | {"panic", 1 << REISERFS_ERROR_PANIC, |
| 898 | (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)}, |
| 899 | {"ro-remount", 1 << REISERFS_ERROR_RO, |
| 900 | (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 902 | {"continue", 1 << REISERFS_ERROR_CONTINUE, |
| 903 | (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | #endif |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 905 | {NULL, 0, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | }; |
| 907 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 908 | /* |
| 909 | * proceed only one option from a list *cur - string containing of mount |
| 910 | * options |
| 911 | * opts - array of options which are accepted |
| 912 | * opt_arg - if option is found and requires an argument and if it is specifed |
| 913 | * in the input - pointer to the argument is stored here |
| 914 | * bit_flags - if option requires to set a certain bit - it is set here |
| 915 | * return -1 if unknown option is found, opt->arg_required otherwise |
| 916 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 917 | static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts, |
| 918 | char **opt_arg, unsigned long *bit_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 920 | char *p; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 921 | /* |
| 922 | * foo=bar, |
| 923 | * ^ ^ ^ |
| 924 | * | | +-- option_end |
| 925 | * | +-- arg_start |
| 926 | * +-- option_start |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 927 | */ |
| 928 | const opt_desc_t *opt; |
| 929 | const arg_desc_t *arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 931 | p = *cur; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 933 | /* assume argument cannot contain commas */ |
| 934 | *cur = strchr(p, ','); |
| 935 | if (*cur) { |
| 936 | *(*cur) = '\0'; |
| 937 | (*cur)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 940 | if (!strncmp(p, "alloc=", 6)) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 941 | /* |
| 942 | * Ugly special case, probably we should redo options |
| 943 | * parser so that it can understand several arguments for |
| 944 | * some options, also so that it can fill several bitfields |
| 945 | * with option values. |
| 946 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 947 | if (reiserfs_parse_alloc_options(s, p + 6)) { |
| 948 | return -1; |
| 949 | } else { |
| 950 | return 0; |
| 951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 953 | |
| 954 | /* for every option in the list */ |
| 955 | for (opt = opts; opt->option_name; opt++) { |
| 956 | if (!strncmp(p, opt->option_name, strlen(opt->option_name))) { |
| 957 | if (bit_flags) { |
| 958 | if (opt->clrmask == |
| 959 | (1 << REISERFS_UNSUPPORTED_OPT)) |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 960 | reiserfs_warning(s, "super-6500", |
| 961 | "%s not supported.\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 962 | p); |
| 963 | else |
| 964 | *bit_flags &= ~opt->clrmask; |
| 965 | if (opt->setmask == |
| 966 | (1 << REISERFS_UNSUPPORTED_OPT)) |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 967 | reiserfs_warning(s, "super-6501", |
| 968 | "%s not supported.\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 969 | p); |
| 970 | else |
| 971 | *bit_flags |= opt->setmask; |
| 972 | } |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | if (!opt->option_name) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 977 | reiserfs_warning(s, "super-6502", |
| 978 | "unknown mount option \"%s\"", p); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 979 | return -1; |
| 980 | } |
| 981 | |
| 982 | p += strlen(opt->option_name); |
| 983 | switch (*p) { |
| 984 | case '=': |
| 985 | if (!opt->arg_required) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 986 | reiserfs_warning(s, "super-6503", |
| 987 | "the option \"%s\" does not " |
| 988 | "require an argument\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 989 | opt->option_name); |
| 990 | return -1; |
| 991 | } |
| 992 | break; |
| 993 | |
| 994 | case 0: |
| 995 | if (opt->arg_required) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 996 | reiserfs_warning(s, "super-6504", |
| 997 | "the option \"%s\" requires an " |
| 998 | "argument\n", opt->option_name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 999 | return -1; |
| 1000 | } |
| 1001 | break; |
| 1002 | default: |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1003 | reiserfs_warning(s, "super-6505", |
| 1004 | "head of option \"%s\" is only correct\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1005 | opt->option_name); |
| 1006 | return -1; |
| 1007 | } |
| 1008 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1009 | /* |
| 1010 | * move to the argument, or to next option if argument is not |
| 1011 | * required |
| 1012 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1013 | p++; |
| 1014 | |
| 1015 | if (opt->arg_required |
| 1016 | && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY)) |
| 1017 | && !strlen(p)) { |
| 1018 | /* this catches "option=," if not allowed */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1019 | reiserfs_warning(s, "super-6506", |
| 1020 | "empty argument for \"%s\"\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1021 | opt->option_name); |
| 1022 | return -1; |
| 1023 | } |
| 1024 | |
| 1025 | if (!opt->values) { |
| 1026 | /* *=NULLopt_arg contains pointer to argument */ |
| 1027 | *opt_arg = p; |
| 1028 | return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY); |
| 1029 | } |
| 1030 | |
| 1031 | /* values possible for this option are listed in opt->values */ |
| 1032 | for (arg = opt->values; arg->value; arg++) { |
| 1033 | if (!strcmp(p, arg->value)) { |
| 1034 | if (bit_flags) { |
| 1035 | *bit_flags &= ~arg->clrmask; |
| 1036 | *bit_flags |= arg->setmask; |
| 1037 | } |
| 1038 | return opt->arg_required; |
| 1039 | } |
| 1040 | } |
| 1041 | |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1042 | reiserfs_warning(s, "super-6506", |
| 1043 | "bad value \"%s\" for option \"%s\"\n", p, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1044 | opt->option_name); |
| 1045 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /* returns 0 if something is wrong in option string, 1 - otherwise */ |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1049 | static int reiserfs_parse_options(struct super_block *s, |
| 1050 | |
| 1051 | /* string given via mount's -o */ |
| 1052 | char *options, |
| 1053 | |
| 1054 | /* |
| 1055 | * after the parsing phase, contains the |
| 1056 | * collection of bitflags defining what |
| 1057 | * mount options were selected. |
| 1058 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1059 | unsigned long *mount_options, |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1060 | |
| 1061 | /* strtol-ed from NNN of resize=NNN */ |
| 1062 | unsigned long *blocks, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1063 | char **jdev_name, |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1064 | unsigned int *commit_max_age, |
| 1065 | char **qf_names, |
| 1066 | unsigned int *qfmt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1068 | int c; |
| 1069 | char *arg = NULL; |
| 1070 | char *pos; |
| 1071 | opt_desc_t opts[] = { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1072 | /* |
| 1073 | * Compatibility stuff, so that -o notail for old |
| 1074 | * setups still work |
| 1075 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1076 | {"tails",.arg_required = 't',.values = tails}, |
| 1077 | {"notail",.clrmask = |
| 1078 | (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)}, |
| 1079 | {"conv",.setmask = 1 << REISERFS_CONVERT}, |
| 1080 | {"attrs",.setmask = 1 << REISERFS_ATTRS}, |
| 1081 | {"noattrs",.clrmask = 1 << REISERFS_ATTRS}, |
Jeff Mahoney | 7342281 | 2009-05-10 16:05:39 -0400 | [diff] [blame] | 1082 | {"expose_privroot", .setmask = 1 << REISERFS_EXPOSE_PRIVROOT}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | #ifdef CONFIG_REISERFS_FS_XATTR |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1084 | {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER}, |
| 1085 | {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | #else |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1087 | {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT}, |
| 1088 | {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | #endif |
| 1090 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1091 | {"acl",.setmask = 1 << REISERFS_POSIXACL}, |
| 1092 | {"noacl",.clrmask = 1 << REISERFS_POSIXACL}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | #else |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1094 | {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT}, |
| 1095 | {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | #endif |
Vladimir V. Saveliev | cd02b96 | 2006-03-25 03:07:15 -0800 | [diff] [blame] | 1097 | {.option_name = "nolog"}, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1098 | {"replayonly",.setmask = 1 << REPLAYONLY}, |
| 1099 | {"block-allocator",.arg_required = 'a',.values = balloc}, |
| 1100 | {"data",.arg_required = 'd',.values = logging_mode}, |
| 1101 | {"barrier",.arg_required = 'b',.values = barrier_mode}, |
| 1102 | {"resize",.arg_required = 'r',.values = NULL}, |
| 1103 | {"jdev",.arg_required = 'j',.values = NULL}, |
| 1104 | {"nolargeio",.arg_required = 'w',.values = NULL}, |
| 1105 | {"commit",.arg_required = 'c',.values = NULL}, |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1106 | {"usrquota",.setmask = 1 << REISERFS_USRQUOTA}, |
| 1107 | {"grpquota",.setmask = 1 << REISERFS_GRPQUOTA}, |
| 1108 | {"noquota",.clrmask = 1 << REISERFS_USRQUOTA | 1 << REISERFS_GRPQUOTA}, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1109 | {"errors",.arg_required = 'e',.values = error_actions}, |
| 1110 | {"usrjquota",.arg_required = |
| 1111 | 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL}, |
| 1112 | {"grpjquota",.arg_required = |
| 1113 | 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL}, |
| 1114 | {"jqfmt",.arg_required = 'f',.values = NULL}, |
Vladimir V. Saveliev | cd02b96 | 2006-03-25 03:07:15 -0800 | [diff] [blame] | 1115 | {.option_name = NULL} |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1116 | }; |
| 1117 | |
| 1118 | *blocks = 0; |
| 1119 | if (!options || !*options) |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1120 | /* |
| 1121 | * use default configuration: create tails, journaling on, no |
| 1122 | * conversion to newest format |
| 1123 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1124 | return 1; |
| 1125 | |
| 1126 | for (pos = options; pos;) { |
| 1127 | c = reiserfs_getopt(s, &pos, opts, &arg, mount_options); |
| 1128 | if (c == -1) |
| 1129 | /* wrong option is given */ |
| 1130 | return 0; |
| 1131 | |
| 1132 | if (c == 'r') { |
| 1133 | char *p; |
| 1134 | |
| 1135 | p = NULL; |
| 1136 | /* "resize=NNN" or "resize=auto" */ |
| 1137 | |
| 1138 | if (!strcmp(arg, "auto")) { |
| 1139 | /* From JFS code, to auto-get the size. */ |
| 1140 | *blocks = |
| 1141 | s->s_bdev->bd_inode->i_size >> s-> |
| 1142 | s_blocksize_bits; |
| 1143 | } else { |
| 1144 | *blocks = simple_strtoul(arg, &p, 0); |
| 1145 | if (*p != '\0') { |
| 1146 | /* NNN does not look like a number */ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1147 | reiserfs_warning(s, "super-6507", |
| 1148 | "bad value %s for " |
| 1149 | "-oresize\n", arg); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (c == 'c') { |
| 1156 | char *p = NULL; |
| 1157 | unsigned long val = simple_strtoul(arg, &p, 0); |
| 1158 | /* commit=NNN (time in seconds) */ |
| 1159 | if (*p != '\0' || val >= (unsigned int)-1) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1160 | reiserfs_warning(s, "super-6508", |
| 1161 | "bad value %s for -ocommit\n", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1162 | arg); |
| 1163 | return 0; |
| 1164 | } |
| 1165 | *commit_max_age = (unsigned int)val; |
| 1166 | } |
| 1167 | |
| 1168 | if (c == 'w') { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1169 | reiserfs_warning(s, "super-6509", "nolargeio option " |
| 1170 | "is no longer supported"); |
Adrian Bunk | 36b756f | 2006-09-27 01:50:50 -0700 | [diff] [blame] | 1171 | return 0; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | if (c == 'j') { |
| 1175 | if (arg && *arg && jdev_name) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1176 | /* Hm, already assigned? */ |
| 1177 | if (*jdev_name) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1178 | reiserfs_warning(s, "super-6510", |
| 1179 | "journal device was " |
| 1180 | "already specified to " |
| 1181 | "be %s", *jdev_name); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1182 | return 0; |
| 1183 | } |
| 1184 | *jdev_name = arg; |
| 1185 | } |
| 1186 | } |
| 1187 | #ifdef CONFIG_QUOTA |
| 1188 | if (c == 'u' || c == 'g') { |
| 1189 | int qtype = c == 'u' ? USRQUOTA : GRPQUOTA; |
| 1190 | |
Jan Kara | 6929f89 | 2008-08-20 18:16:36 +0200 | [diff] [blame] | 1191 | if (sb_any_quota_loaded(s) && |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1192 | (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1193 | reiserfs_warning(s, "super-6511", |
| 1194 | "cannot change journaled " |
| 1195 | "quota options when quota " |
| 1196 | "turned on."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1197 | return 0; |
| 1198 | } |
| 1199 | if (*arg) { /* Some filename specified? */ |
| 1200 | if (REISERFS_SB(s)->s_qf_names[qtype] |
| 1201 | && strcmp(REISERFS_SB(s)->s_qf_names[qtype], |
| 1202 | arg)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1203 | reiserfs_warning(s, "super-6512", |
| 1204 | "%s quota file " |
| 1205 | "already specified.", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1206 | QTYPE2NAME(qtype)); |
| 1207 | return 0; |
| 1208 | } |
| 1209 | if (strchr(arg, '/')) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1210 | reiserfs_warning(s, "super-6513", |
| 1211 | "quotafile must be " |
| 1212 | "on filesystem root."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1213 | return 0; |
| 1214 | } |
Ionut-Gabriel Radu | af591ad | 2013-03-10 15:06:23 +0200 | [diff] [blame] | 1215 | qf_names[qtype] = kstrdup(arg, GFP_KERNEL); |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1216 | if (!qf_names[qtype]) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1217 | reiserfs_warning(s, "reiserfs-2502", |
| 1218 | "not enough memory " |
| 1219 | "for storing " |
| 1220 | "quotafile name."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1221 | return 0; |
| 1222 | } |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1223 | if (qtype == USRQUOTA) |
| 1224 | *mount_options |= 1 << REISERFS_USRQUOTA; |
| 1225 | else |
| 1226 | *mount_options |= 1 << REISERFS_GRPQUOTA; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1227 | } else { |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1228 | if (qf_names[qtype] != |
| 1229 | REISERFS_SB(s)->s_qf_names[qtype]) |
| 1230 | kfree(qf_names[qtype]); |
| 1231 | qf_names[qtype] = NULL; |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1232 | if (qtype == USRQUOTA) |
| 1233 | *mount_options &= ~(1 << REISERFS_USRQUOTA); |
| 1234 | else |
| 1235 | *mount_options &= ~(1 << REISERFS_GRPQUOTA); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | if (c == 'f') { |
| 1239 | if (!strcmp(arg, "vfsold")) |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1240 | *qfmt = QFMT_VFS_OLD; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1241 | else if (!strcmp(arg, "vfsv0")) |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1242 | *qfmt = QFMT_VFS_V0; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1243 | else { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1244 | reiserfs_warning(s, "super-6514", |
| 1245 | "unknown quota format " |
| 1246 | "specified."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1247 | return 0; |
| 1248 | } |
Jan Kara | 6929f89 | 2008-08-20 18:16:36 +0200 | [diff] [blame] | 1249 | if (sb_any_quota_loaded(s) && |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1250 | *qfmt != REISERFS_SB(s)->s_jquota_fmt) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1251 | reiserfs_warning(s, "super-6515", |
| 1252 | "cannot change journaled " |
| 1253 | "quota options when quota " |
| 1254 | "turned on."); |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1255 | return 0; |
| 1256 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1257 | } |
| 1258 | #else |
| 1259 | if (c == 'u' || c == 'g' || c == 'f') { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1260 | reiserfs_warning(s, "reiserfs-2503", "journaled " |
| 1261 | "quota options not supported."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1262 | return 0; |
| 1263 | } |
| 1264 | #endif |
| 1265 | } |
| 1266 | |
| 1267 | #ifdef CONFIG_QUOTA |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1268 | if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt |
| 1269 | && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1270 | reiserfs_warning(s, "super-6515", |
| 1271 | "journaled quota format not specified."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1272 | return 0; |
| 1273 | } |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1274 | if ((!(*mount_options & (1 << REISERFS_USRQUOTA)) && |
| 1275 | sb_has_quota_loaded(s, USRQUOTA)) || |
| 1276 | (!(*mount_options & (1 << REISERFS_GRPQUOTA)) && |
| 1277 | sb_has_quota_loaded(s, GRPQUOTA))) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1278 | reiserfs_warning(s, "super-6516", "quota options must " |
| 1279 | "be present when quota is turned on."); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1280 | return 0; |
| 1281 | } |
| 1282 | #endif |
| 1283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1287 | static void switch_data_mode(struct super_block *s, unsigned long mode) |
| 1288 | { |
| 1289 | REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) | |
| 1290 | (1 << REISERFS_DATA_ORDERED) | |
| 1291 | (1 << REISERFS_DATA_WRITEBACK)); |
| 1292 | REISERFS_SB(s)->s_mount_opt |= (1 << mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | static void handle_data_mode(struct super_block *s, unsigned long mount_options) |
| 1296 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1297 | if (mount_options & (1 << REISERFS_DATA_LOG)) { |
| 1298 | if (!reiserfs_data_log(s)) { |
| 1299 | switch_data_mode(s, REISERFS_DATA_LOG); |
| 1300 | reiserfs_info(s, "switching to journaled data mode\n"); |
| 1301 | } |
| 1302 | } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) { |
| 1303 | if (!reiserfs_data_ordered(s)) { |
| 1304 | switch_data_mode(s, REISERFS_DATA_ORDERED); |
| 1305 | reiserfs_info(s, "switching to ordered data mode\n"); |
| 1306 | } |
| 1307 | } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) { |
| 1308 | if (!reiserfs_data_writeback(s)) { |
| 1309 | switch_data_mode(s, REISERFS_DATA_WRITEBACK); |
| 1310 | reiserfs_info(s, "switching to writeback data mode\n"); |
| 1311 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1315 | static void handle_barrier_mode(struct super_block *s, unsigned long bits) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1317 | int flush = (1 << REISERFS_BARRIER_FLUSH); |
| 1318 | int none = (1 << REISERFS_BARRIER_NONE); |
| 1319 | int all_barrier = flush | none; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1321 | if (bits & all_barrier) { |
| 1322 | REISERFS_SB(s)->s_mount_opt &= ~all_barrier; |
| 1323 | if (bits & flush) { |
| 1324 | REISERFS_SB(s)->s_mount_opt |= flush; |
| 1325 | printk("reiserfs: enabling write barrier flush mode\n"); |
| 1326 | } else if (bits & none) { |
| 1327 | REISERFS_SB(s)->s_mount_opt |= none; |
| 1328 | printk("reiserfs: write barriers turned off\n"); |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | static void handle_attrs(struct super_block *s) |
| 1334 | { |
| 1335 | struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s); |
| 1336 | |
| 1337 | if (reiserfs_attrs(s)) { |
| 1338 | if (old_format_only(s)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1339 | reiserfs_warning(s, "super-6517", "cannot support " |
| 1340 | "attributes on 3.5.x disk format"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1341 | REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | return; |
| 1343 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1344 | if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1345 | reiserfs_warning(s, "super-6518", "cannot support " |
| 1346 | "attributes until flag is set in " |
| 1347 | "super-block"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1348 | REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | } |
| 1352 | |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1353 | #ifdef CONFIG_QUOTA |
| 1354 | static void handle_quota_files(struct super_block *s, char **qf_names, |
| 1355 | unsigned int *qfmt) |
| 1356 | { |
| 1357 | int i; |
| 1358 | |
| 1359 | for (i = 0; i < MAXQUOTAS; i++) { |
| 1360 | if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i]) |
| 1361 | kfree(REISERFS_SB(s)->s_qf_names[i]); |
| 1362 | REISERFS_SB(s)->s_qf_names[i] = qf_names[i]; |
| 1363 | } |
Jan Kara | a06d789 | 2011-12-21 17:35:34 +0100 | [diff] [blame] | 1364 | if (*qfmt) |
| 1365 | REISERFS_SB(s)->s_jquota_fmt = *qfmt; |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1366 | } |
| 1367 | #endif |
| 1368 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1369 | static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1371 | struct reiserfs_super_block *rs; |
| 1372 | struct reiserfs_transaction_handle th; |
| 1373 | unsigned long blocks; |
| 1374 | unsigned long mount_options = REISERFS_SB(s)->s_mount_opt; |
| 1375 | unsigned long safe_mask = 0; |
| 1376 | unsigned int commit_max_age = (unsigned int)-1; |
| 1377 | struct reiserfs_journal *journal = SB_JOURNAL(s); |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1378 | char *new_opts = kstrdup(arg, GFP_KERNEL); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1379 | int err; |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1380 | char *qf_names[MAXQUOTAS]; |
| 1381 | unsigned int qfmt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1383 | int i; |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 1384 | #endif |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1385 | |
Theodore Ts'o | 02b9984 | 2014-03-13 10:14:33 -0400 | [diff] [blame] | 1386 | sync_filesystem(s); |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 1387 | reiserfs_write_lock(s); |
| 1388 | |
| 1389 | #ifdef CONFIG_QUOTA |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1390 | memcpy(qf_names, REISERFS_SB(s)->s_qf_names, sizeof(qf_names)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | #endif |
| 1392 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1393 | rs = SB_DISK_SUPER_BLOCK(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1395 | if (!reiserfs_parse_options |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1396 | (s, arg, &mount_options, &blocks, NULL, &commit_max_age, |
| 1397 | qf_names, &qfmt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | #ifdef CONFIG_QUOTA |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1399 | for (i = 0; i < MAXQUOTAS; i++) |
| 1400 | if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i]) |
| 1401 | kfree(qf_names[i]); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1402 | #endif |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1403 | err = -EINVAL; |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1404 | goto out_err_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | } |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1406 | #ifdef CONFIG_QUOTA |
| 1407 | handle_quota_files(s, qf_names, &qfmt); |
| 1408 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1410 | handle_attrs(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1412 | /* Add options that are safe here */ |
| 1413 | safe_mask |= 1 << REISERFS_SMALLTAIL; |
| 1414 | safe_mask |= 1 << REISERFS_LARGETAIL; |
| 1415 | safe_mask |= 1 << REISERFS_NO_BORDER; |
| 1416 | safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION; |
| 1417 | safe_mask |= 1 << REISERFS_HASHED_RELOCATION; |
| 1418 | safe_mask |= 1 << REISERFS_TEST4; |
| 1419 | safe_mask |= 1 << REISERFS_ATTRS; |
| 1420 | safe_mask |= 1 << REISERFS_XATTRS_USER; |
| 1421 | safe_mask |= 1 << REISERFS_POSIXACL; |
| 1422 | safe_mask |= 1 << REISERFS_BARRIER_FLUSH; |
| 1423 | safe_mask |= 1 << REISERFS_BARRIER_NONE; |
| 1424 | safe_mask |= 1 << REISERFS_ERROR_RO; |
| 1425 | safe_mask |= 1 << REISERFS_ERROR_CONTINUE; |
| 1426 | safe_mask |= 1 << REISERFS_ERROR_PANIC; |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1427 | safe_mask |= 1 << REISERFS_USRQUOTA; |
| 1428 | safe_mask |= 1 << REISERFS_GRPQUOTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1430 | /* |
| 1431 | * Update the bitmask, taking care to keep |
| 1432 | * the bits we're not allowed to change here |
| 1433 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1434 | REISERFS_SB(s)->s_mount_opt = |
| 1435 | (REISERFS_SB(s)-> |
| 1436 | s_mount_opt & ~safe_mask) | (mount_options & safe_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1438 | if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) { |
| 1439 | journal->j_max_commit_age = commit_max_age; |
| 1440 | journal->j_max_trans_age = commit_max_age; |
| 1441 | } else if (commit_max_age == 0) { |
| 1442 | /* 0 means restore defaults. */ |
| 1443 | journal->j_max_commit_age = journal->j_default_max_commit_age; |
| 1444 | journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE; |
| 1445 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1447 | if (blocks) { |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1448 | err = reiserfs_resize(s, blocks); |
| 1449 | if (err != 0) |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1450 | goto out_err_unlock; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1453 | if (*mount_flags & MS_RDONLY) { |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1454 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1455 | reiserfs_xattr_init(s, *mount_flags); |
| 1456 | /* remount read-only */ |
| 1457 | if (s->s_flags & MS_RDONLY) |
| 1458 | /* it is read-only already */ |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1459 | goto out_ok_unlocked; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 1460 | |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 1461 | err = dquot_suspend(s, -1); |
| 1462 | if (err < 0) |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 1463 | goto out_err; |
Christoph Hellwig | c79d967 | 2010-05-19 07:16:40 -0400 | [diff] [blame] | 1464 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1465 | /* try to remount file system with read-only permissions */ |
| 1466 | if (sb_umount_state(rs) == REISERFS_VALID_FS |
| 1467 | || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) { |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1468 | goto out_ok_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1471 | reiserfs_write_lock(s); |
| 1472 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1473 | err = journal_begin(&th, s, 10); |
| 1474 | if (err) |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1475 | goto out_err_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1477 | /* Mounting a rw partition read-only. */ |
| 1478 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); |
| 1479 | set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 1480 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1481 | } else { |
| 1482 | /* remount read-write */ |
| 1483 | if (!(s->s_flags & MS_RDONLY)) { |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1484 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1485 | reiserfs_xattr_init(s, *mount_flags); |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1486 | goto out_ok_unlocked; /* We are read-write already */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1489 | if (reiserfs_is_journal_aborted(journal)) { |
| 1490 | err = journal->j_errno; |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1491 | goto out_err_unlock; |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1494 | handle_data_mode(s, mount_options); |
| 1495 | handle_barrier_mode(s, mount_options); |
| 1496 | REISERFS_SB(s)->s_mount_state = sb_umount_state(rs); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1497 | |
| 1498 | /* now it is safe to call journal_begin */ |
| 1499 | s->s_flags &= ~MS_RDONLY; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1500 | err = journal_begin(&th, s, 10); |
| 1501 | if (err) |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1502 | goto out_err_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1504 | /* Mount a partition which is read-only, read-write */ |
| 1505 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); |
| 1506 | REISERFS_SB(s)->s_mount_state = sb_umount_state(rs); |
| 1507 | s->s_flags &= ~MS_RDONLY; |
| 1508 | set_sb_umount_state(rs, REISERFS_ERROR_FS); |
Jeff Mahoney | 702d21c | 2009-03-30 14:02:16 -0400 | [diff] [blame] | 1509 | if (!old_format_only(s)) |
| 1510 | set_sb_mnt_count(rs, sb_mnt_count(rs) + 1); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1511 | /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */ |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 1512 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1513 | REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS; |
| 1514 | } |
| 1515 | /* this will force a full flush of all journal lists */ |
| 1516 | SB_JOURNAL(s)->j_must_wait = 1; |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 1517 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1518 | if (err) |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1519 | goto out_err_unlock; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1520 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1521 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1522 | if (!(*mount_flags & MS_RDONLY)) { |
Christoph Hellwig | 0f0dd62 | 2010-05-19 07:16:41 -0400 | [diff] [blame] | 1523 | dquot_resume(s, -1); |
Jan Kara | 3bb3e1f | 2012-11-13 14:55:52 +0100 | [diff] [blame] | 1524 | reiserfs_write_lock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1525 | finish_unfinished(s); |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1526 | reiserfs_write_unlock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1527 | reiserfs_xattr_init(s, *mount_flags); |
| 1528 | } |
| 1529 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1530 | out_ok_unlocked: |
Al Viro | 2a32ceb | 2009-05-08 16:05:57 -0400 | [diff] [blame] | 1531 | replace_mount_options(s, new_opts); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1532 | return 0; |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1533 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 1534 | out_err_unlock: |
Jan Kara | 3bb3e1f | 2012-11-13 14:55:52 +0100 | [diff] [blame] | 1535 | reiserfs_write_unlock(s); |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1536 | out_err: |
| 1537 | kfree(new_opts); |
| 1538 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1541 | static int read_super_block(struct super_block *s, int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1543 | struct buffer_head *bh; |
| 1544 | struct reiserfs_super_block *rs; |
| 1545 | int fs_blocksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1547 | bh = sb_bread(s, offset / s->s_blocksize); |
| 1548 | if (!bh) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1549 | reiserfs_warning(s, "sh-2006", |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1550 | "bread failed (dev %s, block %lu, size %lu)", |
Al Viro | 2ccdc41 | 2013-11-22 13:25:39 -0500 | [diff] [blame] | 1551 | s->s_id, offset / s->s_blocksize, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1552 | s->s_blocksize); |
| 1553 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1556 | rs = (struct reiserfs_super_block *)bh->b_data; |
| 1557 | if (!is_any_reiserfs_magic_string(rs)) { |
| 1558 | brelse(bh); |
| 1559 | return 1; |
| 1560 | } |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1561 | /* |
| 1562 | * ok, reiserfs signature (old or new) found in at the given offset |
| 1563 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1564 | fs_blocksize = sb_blocksize(rs); |
| 1565 | brelse(bh); |
| 1566 | sb_set_blocksize(s, fs_blocksize); |
| 1567 | |
| 1568 | bh = sb_bread(s, offset / s->s_blocksize); |
| 1569 | if (!bh) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1570 | reiserfs_warning(s, "sh-2007", |
| 1571 | "bread failed (dev %s, block %lu, size %lu)", |
Al Viro | 2ccdc41 | 2013-11-22 13:25:39 -0500 | [diff] [blame] | 1572 | s->s_id, offset / s->s_blocksize, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1573 | s->s_blocksize); |
| 1574 | return 1; |
| 1575 | } |
| 1576 | |
| 1577 | rs = (struct reiserfs_super_block *)bh->b_data; |
| 1578 | if (sb_blocksize(rs) != s->s_blocksize) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1579 | reiserfs_warning(s, "sh-2011", "can't find a reiserfs " |
| 1580 | "filesystem on (dev %s, block %Lu, size %lu)", |
Al Viro | 2ccdc41 | 2013-11-22 13:25:39 -0500 | [diff] [blame] | 1581 | s->s_id, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1582 | (unsigned long long)bh->b_blocknr, |
| 1583 | s->s_blocksize); |
| 1584 | brelse(bh); |
| 1585 | return 1; |
| 1586 | } |
| 1587 | |
| 1588 | if (rs->s_v1.s_root_block == cpu_to_le32(-1)) { |
| 1589 | brelse(bh); |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1590 | reiserfs_warning(s, "super-6519", "Unfinished reiserfsck " |
| 1591 | "--rebuild-tree run detected. Please run\n" |
| 1592 | "reiserfsck --rebuild-tree and wait for a " |
| 1593 | "completion. If that fails\n" |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1594 | "get newer reiserfsprogs package"); |
| 1595 | return 1; |
| 1596 | } |
| 1597 | |
| 1598 | SB_BUFFER_WITH_SB(s) = bh; |
| 1599 | SB_DISK_SUPER_BLOCK(s) = rs; |
| 1600 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1601 | /* |
| 1602 | * magic is of non-standard journal filesystem, look at s_version to |
| 1603 | * find which format is in use |
| 1604 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1605 | if (is_reiserfs_jr(rs)) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1606 | if (sb_version(rs) == REISERFS_VERSION_2) |
Jeff Mahoney | 1d889d9 | 2009-03-30 14:02:20 -0400 | [diff] [blame] | 1607 | reiserfs_info(s, "found reiserfs format \"3.6\"" |
| 1608 | " with non-standard journal\n"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1609 | else if (sb_version(rs) == REISERFS_VERSION_1) |
Jeff Mahoney | 1d889d9 | 2009-03-30 14:02:20 -0400 | [diff] [blame] | 1610 | reiserfs_info(s, "found reiserfs format \"3.5\"" |
| 1611 | " with non-standard journal\n"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1612 | else { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1613 | reiserfs_warning(s, "sh-2012", "found unknown " |
| 1614 | "format \"%u\" of reiserfs with " |
| 1615 | "non-standard magic", sb_version(rs)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1616 | return 1; |
| 1617 | } |
| 1618 | } else |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1619 | /* |
| 1620 | * s_version of standard format may contain incorrect |
| 1621 | * information, so we just look at the magic string |
| 1622 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1623 | reiserfs_info(s, |
| 1624 | "found reiserfs format \"%s\" with standard journal\n", |
| 1625 | is_reiserfs_3_5(rs) ? "3.5" : "3.6"); |
| 1626 | |
| 1627 | s->s_op = &reiserfs_sops; |
| 1628 | s->s_export_op = &reiserfs_export_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | #ifdef CONFIG_QUOTA |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1630 | s->s_qcop = &reiserfs_qctl_operations; |
| 1631 | s->dq_op = &reiserfs_quota_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | #endif |
| 1633 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1634 | /* |
| 1635 | * new format is limited by the 32 bit wide i_blocks field, want to |
| 1636 | * be one full block below that. |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1637 | */ |
| 1638 | s->s_maxbytes = (512LL << 32) - s->s_blocksize; |
| 1639 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | /* after journal replay, reread all bitmap and super blocks */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1643 | static int reread_meta_blocks(struct super_block *s) |
| 1644 | { |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 1645 | ll_rw_block(READ, 1, &SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1646 | wait_on_buffer(SB_BUFFER_WITH_SB(s)); |
| 1647 | if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1648 | reiserfs_warning(s, "reiserfs-2504", "error reading the super"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1649 | return 1; |
| 1650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1652 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1655 | /* hash detection stuff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1657 | /* |
| 1658 | * if root directory is empty - we set default - Yura's - hash and |
| 1659 | * warn about it |
| 1660 | * FIXME: we look for only one name in a directory. If tea and yura |
| 1661 | * both have the same value - we ask user to send report to the |
| 1662 | * mailing list |
| 1663 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1664 | static __u32 find_hash_out(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1666 | int retval; |
| 1667 | struct inode *inode; |
| 1668 | struct cpu_key key; |
| 1669 | INITIALIZE_PATH(path); |
| 1670 | struct reiserfs_dir_entry de; |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1671 | struct reiserfs_de_head *deh; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1672 | __u32 hash = DEFAULT_HASH; |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1673 | __u32 deh_hashval, teahash, r5hash, yurahash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1675 | inode = s->s_root->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1677 | make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3); |
| 1678 | retval = search_by_entry_key(s, &key, &path, &de); |
| 1679 | if (retval == IO_ERROR) { |
| 1680 | pathrelse(&path); |
| 1681 | return UNSET_HASH; |
| 1682 | } |
| 1683 | if (retval == NAME_NOT_FOUND) |
| 1684 | de.de_entry_num--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1686 | set_de_name_and_namelen(&de); |
| 1687 | deh = de.de_deh + de.de_entry_num; |
| 1688 | |
| 1689 | if (deh_offset(deh) == DOT_DOT_OFFSET) { |
| 1690 | /* allow override in this case */ |
| 1691 | if (reiserfs_rupasov_hash(s)) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1692 | hash = YURA_HASH; |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1693 | reiserfs_info(s, "FS seems to be empty, autodetect is using the default hash\n"); |
| 1694 | goto out; |
| 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
Jeff Mahoney | c48138c | 2014-04-23 10:00:44 -0400 | [diff] [blame] | 1697 | deh_hashval = GET_HASH_VALUE(deh_offset(deh)); |
| 1698 | r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen)); |
| 1699 | teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen)); |
| 1700 | yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen)); |
| 1701 | |
| 1702 | if ((teahash == r5hash && deh_hashval == r5hash) || |
| 1703 | (teahash == yurahash && deh_hashval == yurahash) || |
| 1704 | (r5hash == yurahash && deh_hashval == yurahash)) { |
| 1705 | reiserfs_warning(s, "reiserfs-2506", |
| 1706 | "Unable to automatically detect hash " |
| 1707 | "function. Please mount with -o " |
| 1708 | "hash={tea,rupasov,r5}"); |
| 1709 | hash = UNSET_HASH; |
| 1710 | goto out; |
| 1711 | } |
| 1712 | |
| 1713 | if (deh_hashval == yurahash) |
| 1714 | hash = YURA_HASH; |
| 1715 | else if (deh_hashval == teahash) |
| 1716 | hash = TEA_HASH; |
| 1717 | else if (deh_hashval == r5hash) |
| 1718 | hash = R5_HASH; |
| 1719 | else { |
| 1720 | reiserfs_warning(s, "reiserfs-2506", |
| 1721 | "Unrecognised hash function"); |
| 1722 | hash = UNSET_HASH; |
| 1723 | } |
| 1724 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1725 | pathrelse(&path); |
| 1726 | return hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | } |
| 1728 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1729 | /* finds out which hash names are sorted with */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1730 | static int what_hash(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1732 | __u32 code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1734 | code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1736 | /* |
| 1737 | * reiserfs_hash_detect() == true if any of the hash mount options |
| 1738 | * were used. We must check them to make sure the user isn't |
| 1739 | * using a bad hash value |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1740 | */ |
| 1741 | if (code == UNSET_HASH || reiserfs_hash_detect(s)) |
| 1742 | code = find_hash_out(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1744 | if (code != UNSET_HASH && reiserfs_hash_detect(s)) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1745 | /* |
| 1746 | * detection has found the hash, and we must check against the |
| 1747 | * mount options |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1748 | */ |
| 1749 | if (reiserfs_rupasov_hash(s) && code != YURA_HASH) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1750 | reiserfs_warning(s, "reiserfs-2507", |
| 1751 | "Error, %s hash detected, " |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1752 | "unable to force rupasov hash", |
| 1753 | reiserfs_hashname(code)); |
| 1754 | code = UNSET_HASH; |
| 1755 | } else if (reiserfs_tea_hash(s) && code != TEA_HASH) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1756 | reiserfs_warning(s, "reiserfs-2508", |
| 1757 | "Error, %s hash detected, " |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1758 | "unable to force tea hash", |
| 1759 | reiserfs_hashname(code)); |
| 1760 | code = UNSET_HASH; |
| 1761 | } else if (reiserfs_r5_hash(s) && code != R5_HASH) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1762 | reiserfs_warning(s, "reiserfs-2509", |
| 1763 | "Error, %s hash detected, " |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1764 | "unable to force r5 hash", |
| 1765 | reiserfs_hashname(code)); |
| 1766 | code = UNSET_HASH; |
| 1767 | } |
| 1768 | } else { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1769 | /* |
| 1770 | * find_hash_out was not called or |
| 1771 | * could not determine the hash |
| 1772 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1773 | if (reiserfs_rupasov_hash(s)) { |
| 1774 | code = YURA_HASH; |
| 1775 | } else if (reiserfs_tea_hash(s)) { |
| 1776 | code = TEA_HASH; |
| 1777 | } else if (reiserfs_r5_hash(s)) { |
| 1778 | code = R5_HASH; |
| 1779 | } |
| 1780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1782 | /* |
| 1783 | * if we are mounted RW, and we have a new valid hash code, update |
| 1784 | * the super |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1785 | */ |
| 1786 | if (code != UNSET_HASH && |
| 1787 | !(s->s_flags & MS_RDONLY) && |
| 1788 | code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) { |
| 1789 | set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code); |
| 1790 | } |
| 1791 | return code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | } |
| 1793 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1794 | /* return pointer to appropriate function */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1795 | static hashf_t hash_function(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1797 | switch (what_hash(s)) { |
| 1798 | case TEA_HASH: |
| 1799 | reiserfs_info(s, "Using tea hash to sort names\n"); |
| 1800 | return keyed_hash; |
| 1801 | case YURA_HASH: |
| 1802 | reiserfs_info(s, "Using rupasov hash to sort names\n"); |
| 1803 | return yura_hash; |
| 1804 | case R5_HASH: |
| 1805 | reiserfs_info(s, "Using r5 hash to sort names\n"); |
| 1806 | return r5_hash; |
| 1807 | } |
| 1808 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1811 | /* this is used to set up correct value for old partitions */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1812 | static int function2code(hashf_t func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1814 | if (func == keyed_hash) |
| 1815 | return TEA_HASH; |
| 1816 | if (func == yura_hash) |
| 1817 | return YURA_HASH; |
| 1818 | if (func == r5_hash) |
| 1819 | return R5_HASH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1821 | BUG(); /* should never happen */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1823 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1826 | #define SWARN(silent, s, id, ...) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | if (!(silent)) \ |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1828 | reiserfs_warning(s, id, __VA_ARGS__) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1830 | static int reiserfs_fill_super(struct super_block *s, void *data, int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1832 | struct inode *root_inode; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1833 | struct reiserfs_transaction_handle th; |
| 1834 | int old_format = 0; |
| 1835 | unsigned long blocks; |
| 1836 | unsigned int commit_max_age = 0; |
| 1837 | int jinit_done = 0; |
| 1838 | struct reiserfs_iget_args args; |
| 1839 | struct reiserfs_super_block *rs; |
| 1840 | char *jdev_name; |
| 1841 | struct reiserfs_sb_info *sbi; |
| 1842 | int errval = -EINVAL; |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1843 | char *qf_names[MAXQUOTAS] = {}; |
| 1844 | unsigned int qfmt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | |
Miklos Szeredi | cdf6ccc | 2008-02-08 04:21:47 -0800 | [diff] [blame] | 1846 | save_mount_options(s, data); |
| 1847 | |
Yan Burman | 01afb21 | 2006-12-06 20:39:01 -0800 | [diff] [blame] | 1848 | sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL); |
Jeff Mahoney | b7b7fa4 | 2010-03-29 15:12:39 -0400 | [diff] [blame] | 1849 | if (!sbi) |
| 1850 | return -ENOMEM; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1851 | s->s_fs_info = sbi; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1852 | /* Set default values for options: non-aggressive tails, RO on errors */ |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1853 | sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL); |
| 1854 | sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO); |
| 1855 | sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1856 | /* no preallocation minimum, be smart in reiserfs_file_write instead */ |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1857 | sbi->s_alloc_options.preallocmin = 0; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1858 | /* Preallocate by 16 blocks (17-1) at once */ |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1859 | sbi->s_alloc_options.preallocsize = 17; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1860 | /* setup default block allocator options */ |
| 1861 | reiserfs_init_alloc_options(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 1863 | spin_lock_init(&sbi->old_work_lock); |
| 1864 | INIT_DELAYED_WORK(&sbi->old_work, flush_old_commits); |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1865 | mutex_init(&sbi->lock); |
| 1866 | sbi->lock_depth = -1; |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 1867 | |
Jeff Mahoney | 797d901 | 2014-04-23 10:00:34 -0400 | [diff] [blame] | 1868 | sbi->commit_wq = alloc_workqueue("reiserfs/%s", WQ_MEM_RECLAIM, 0, |
| 1869 | s->s_id); |
| 1870 | if (!sbi->commit_wq) { |
| 1871 | SWARN(silent, s, "", "Cannot allocate commit workqueue"); |
| 1872 | errval = -ENOMEM; |
| 1873 | goto error_unlocked; |
| 1874 | } |
| 1875 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1876 | jdev_name = NULL; |
| 1877 | if (reiserfs_parse_options |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 1878 | (s, (char *)data, &sbi->s_mount_opt, &blocks, &jdev_name, |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1879 | &commit_max_age, qf_names, &qfmt) == 0) { |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1880 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1881 | } |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1882 | if (jdev_name && jdev_name[0]) { |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1883 | sbi->s_jdev = kstrdup(jdev_name, GFP_KERNEL); |
| 1884 | if (!sbi->s_jdev) { |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 1885 | SWARN(silent, s, "", "Cannot allocate memory for " |
| 1886 | "journal device name"); |
| 1887 | goto error; |
| 1888 | } |
| 1889 | } |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 1890 | #ifdef CONFIG_QUOTA |
| 1891 | handle_quota_files(s, qf_names, &qfmt); |
| 1892 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1894 | if (blocks) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1895 | SWARN(silent, s, "jmacd-7", "resize option for remount only"); |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1896 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1899 | /* |
| 1900 | * try old format (undistributed bitmap, super block in 8-th 1k |
| 1901 | * block of a device) |
| 1902 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1903 | if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES)) |
| 1904 | old_format = 1; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1905 | |
| 1906 | /* |
| 1907 | * try new format (64-th 1k block), which can contain reiserfs |
| 1908 | * super block |
| 1909 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1910 | else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1911 | SWARN(silent, s, "sh-2021", "can not find reiserfs on %s", |
Al Viro | 2ccdc41 | 2013-11-22 13:25:39 -0500 | [diff] [blame] | 1912 | s->s_id); |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1913 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1914 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1916 | rs = SB_DISK_SUPER_BLOCK(s); |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1917 | /* |
| 1918 | * Let's do basic sanity check to verify that underlying device is not |
| 1919 | * smaller than the filesystem. If the check fails then abort and |
| 1920 | * scream, because bad stuff will happen otherwise. |
| 1921 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1922 | if (s->s_bdev && s->s_bdev->bd_inode |
| 1923 | && i_size_read(s->s_bdev->bd_inode) < |
| 1924 | sb_block_count(rs) * sb_blocksize(rs)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1925 | SWARN(silent, s, "", "Filesystem cannot be " |
| 1926 | "mounted because it is bigger than the device"); |
| 1927 | SWARN(silent, s, "", "You may need to run fsck " |
| 1928 | "or increase size of your LVM partition"); |
| 1929 | SWARN(silent, s, "", "Or may be you forgot to " |
| 1930 | "reboot after fdisk when it told you to"); |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1931 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1932 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1934 | sbi->s_mount_state = SB_REISERFS_STATE(s); |
| 1935 | sbi->s_mount_state = REISERFS_VALID_FS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | |
Jeff Mahoney | 6f01046 | 2006-09-30 23:28:43 -0700 | [diff] [blame] | 1937 | if ((errval = reiserfs_init_bitmap_cache(s))) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1938 | SWARN(silent, s, "jmacd-8", "unable to read bitmap"); |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1939 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1940 | } |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1941 | |
Jeff Mahoney | d2c89a4 | 2006-11-02 22:07:20 -0800 | [diff] [blame] | 1942 | errval = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | #ifdef CONFIG_REISERFS_CHECK |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1944 | SWARN(silent, s, "", "CONFIG_REISERFS_CHECK is set ON"); |
| 1945 | SWARN(silent, s, "", "- it is slow mode for debugging."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | #endif |
| 1947 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1948 | /* make data=ordered the default */ |
| 1949 | if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) && |
| 1950 | !reiserfs_data_writeback(s)) { |
Artem Bityutskiy | efaa33e | 2012-06-01 17:18:04 +0300 | [diff] [blame] | 1951 | sbi->s_mount_opt |= (1 << REISERFS_DATA_ORDERED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1954 | if (reiserfs_data_log(s)) { |
| 1955 | reiserfs_info(s, "using journaled data mode\n"); |
| 1956 | } else if (reiserfs_data_ordered(s)) { |
| 1957 | reiserfs_info(s, "using ordered data mode\n"); |
| 1958 | } else { |
| 1959 | reiserfs_info(s, "using writeback data mode\n"); |
| 1960 | } |
| 1961 | if (reiserfs_barrier_flush(s)) { |
| 1962 | printk("reiserfs: using flush barriers\n"); |
| 1963 | } |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 1964 | |
Frederic Weisbecker | 37c69b9 | 2012-01-10 15:11:09 -0800 | [diff] [blame] | 1965 | if (journal_init(s, jdev_name, old_format, commit_max_age)) { |
| 1966 | SWARN(silent, s, "sh-2022", |
| 1967 | "unable to initialize journal space"); |
| 1968 | goto error_unlocked; |
| 1969 | } else { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 1970 | /* |
| 1971 | * once this is set, journal_release must be called |
| 1972 | * if we error out of the mount |
| 1973 | */ |
| 1974 | jinit_done = 1; |
Frederic Weisbecker | 37c69b9 | 2012-01-10 15:11:09 -0800 | [diff] [blame] | 1975 | } |
| 1976 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1977 | if (reread_meta_blocks(s)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1978 | SWARN(silent, s, "jmacd-9", |
| 1979 | "unable to reread meta blocks after journal init"); |
Frederic Weisbecker | 9b467e6 | 2012-01-10 15:11:11 -0800 | [diff] [blame] | 1980 | goto error_unlocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1983 | if (replay_only(s)) |
Frederic Weisbecker | 9b467e6 | 2012-01-10 15:11:11 -0800 | [diff] [blame] | 1984 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1985 | |
| 1986 | if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1987 | SWARN(silent, s, "clm-7000", |
| 1988 | "Detected readonly device, marking FS readonly"); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1989 | s->s_flags |= MS_RDONLY; |
| 1990 | } |
| 1991 | args.objectid = REISERFS_ROOT_OBJECTID; |
| 1992 | args.dirid = REISERFS_ROOT_PARENT_OBJECTID; |
| 1993 | root_inode = |
| 1994 | iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 1995 | reiserfs_init_locked_inode, (void *)&args); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 1996 | if (!root_inode) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 1997 | SWARN(silent, s, "jmacd-10", "get root inode failed"); |
Frederic Weisbecker | 9b467e6 | 2012-01-10 15:11:11 -0800 | [diff] [blame] | 1998 | goto error_unlocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Frederic Weisbecker | 9b467e6 | 2012-01-10 15:11:11 -0800 | [diff] [blame] | 2001 | /* |
| 2002 | * This path assumed to be called with the BKL in the old times. |
| 2003 | * Now we have inherited the big reiserfs lock from it and many |
| 2004 | * reiserfs helpers called in the mount path and elsewhere require |
| 2005 | * this lock to be held even if it's not always necessary. Let's be |
| 2006 | * conservative and hold it early. The window can be reduced after |
| 2007 | * careful review of the code. |
| 2008 | */ |
| 2009 | reiserfs_write_lock(s); |
| 2010 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2011 | if (root_inode->i_state & I_NEW) { |
| 2012 | reiserfs_read_locked_inode(root_inode, &args); |
| 2013 | unlock_new_inode(root_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Al Viro | 48fde70 | 2012-01-08 22:15:13 -0500 | [diff] [blame] | 2016 | s->s_root = d_make_root(root_inode); |
| 2017 | if (!s->s_root) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2018 | goto error; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2019 | /* define and initialize hash function */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2020 | sbi->s_hash_function = hash_function(s); |
| 2021 | if (sbi->s_hash_function == NULL) { |
| 2022 | dput(s->s_root); |
| 2023 | s->s_root = NULL; |
| 2024 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2026 | |
| 2027 | if (is_reiserfs_3_5(rs) |
| 2028 | || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1)) |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 2029 | set_bit(REISERFS_3_5, &sbi->s_properties); |
Jeff Mahoney | e1fabd3 | 2006-09-30 23:28:40 -0700 | [diff] [blame] | 2030 | else if (old_format) |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 2031 | set_bit(REISERFS_OLD_FORMAT, &sbi->s_properties); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2032 | else |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 2033 | set_bit(REISERFS_3_6, &sbi->s_properties); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2034 | |
| 2035 | if (!(s->s_flags & MS_RDONLY)) { |
| 2036 | |
| 2037 | errval = journal_begin(&th, s, 1); |
| 2038 | if (errval) { |
| 2039 | dput(s->s_root); |
| 2040 | s->s_root = NULL; |
| 2041 | goto error; |
| 2042 | } |
| 2043 | reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); |
| 2044 | |
| 2045 | set_sb_umount_state(rs, REISERFS_ERROR_FS); |
| 2046 | set_sb_fs_state(rs, 0); |
| 2047 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2048 | /* |
| 2049 | * Clear out s_bmap_nr if it would wrap. We can handle this |
Jeff Mahoney | cb680c1 | 2007-10-18 23:39:27 -0700 | [diff] [blame] | 2050 | * case, but older revisions can't. This will cause the |
| 2051 | * file system to fail mount on those older implementations, |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2052 | * avoiding corruption. -jeffm |
| 2053 | */ |
Jeff Mahoney | cb680c1 | 2007-10-18 23:39:27 -0700 | [diff] [blame] | 2054 | if (bmap_would_wrap(reiserfs_bmap_count(s)) && |
| 2055 | sb_bmap_nr(rs) != 0) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 2056 | reiserfs_warning(s, "super-2030", "This file system " |
Jeff Mahoney | cb680c1 | 2007-10-18 23:39:27 -0700 | [diff] [blame] | 2057 | "claims to use %u bitmap blocks in " |
| 2058 | "its super block, but requires %u. " |
| 2059 | "Clearing to zero.", sb_bmap_nr(rs), |
| 2060 | reiserfs_bmap_count(s)); |
| 2061 | |
| 2062 | set_sb_bmap_nr(rs, 0); |
| 2063 | } |
| 2064 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2065 | if (old_format_only(s)) { |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2066 | /* |
| 2067 | * filesystem of format 3.5 either with standard |
| 2068 | * or non-standard journal |
| 2069 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2070 | if (convert_reiserfs(s)) { |
| 2071 | /* and -o conv is given */ |
| 2072 | if (!silent) |
| 2073 | reiserfs_info(s, |
| 2074 | "converting 3.5 filesystem to the 3.6 format"); |
| 2075 | |
| 2076 | if (is_reiserfs_3_5(rs)) |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2077 | /* |
| 2078 | * put magic string of 3.6 format. |
| 2079 | * 2.2 will not be able to |
| 2080 | * mount this filesystem anymore |
| 2081 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2082 | memcpy(rs->s_v1.s_magic, |
| 2083 | reiserfs_3_6_magic_string, |
| 2084 | sizeof |
| 2085 | (reiserfs_3_6_magic_string)); |
| 2086 | |
| 2087 | set_sb_version(rs, REISERFS_VERSION_2); |
| 2088 | reiserfs_convert_objectid_map_v1(s); |
Jeff Mahoney | a228bf8 | 2014-04-23 10:00:42 -0400 | [diff] [blame] | 2089 | set_bit(REISERFS_3_6, &sbi->s_properties); |
| 2090 | clear_bit(REISERFS_3_5, &sbi->s_properties); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2091 | } else if (!silent) { |
| 2092 | reiserfs_info(s, "using 3.5.x disk format\n"); |
| 2093 | } |
Jeff Mahoney | 702d21c | 2009-03-30 14:02:16 -0400 | [diff] [blame] | 2094 | } else |
| 2095 | set_sb_mnt_count(rs, sb_mnt_count(rs) + 1); |
| 2096 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2097 | |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 2098 | journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s)); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2099 | errval = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2100 | if (errval) { |
| 2101 | dput(s->s_root); |
| 2102 | s->s_root = NULL; |
| 2103 | goto error; |
| 2104 | } |
| 2105 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2106 | reiserfs_write_unlock(s); |
Al Viro | edcc37a | 2009-05-03 06:00:05 -0400 | [diff] [blame] | 2107 | if ((errval = reiserfs_lookup_privroot(s)) || |
| 2108 | (errval = reiserfs_xattr_init(s, s->s_flags))) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2109 | dput(s->s_root); |
| 2110 | s->s_root = NULL; |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2111 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2112 | } |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2113 | reiserfs_write_lock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2114 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2115 | /* |
| 2116 | * look for files which were to be removed in previous session |
| 2117 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2118 | finish_unfinished(s); |
| 2119 | } else { |
| 2120 | if (old_format_only(s) && !silent) { |
| 2121 | reiserfs_info(s, "using 3.5.x disk format\n"); |
| 2122 | } |
| 2123 | |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2124 | reiserfs_write_unlock(s); |
Al Viro | edcc37a | 2009-05-03 06:00:05 -0400 | [diff] [blame] | 2125 | if ((errval = reiserfs_lookup_privroot(s)) || |
| 2126 | (errval = reiserfs_xattr_init(s, s->s_flags))) { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2127 | dput(s->s_root); |
| 2128 | s->s_root = NULL; |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2129 | goto error_unlocked; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2130 | } |
Jeff Mahoney | 4c05141 | 2013-08-08 17:27:19 -0400 | [diff] [blame] | 2131 | reiserfs_write_lock(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2132 | } |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2133 | /* |
| 2134 | * mark hash in super block: it could be unset. overwrite should be ok |
| 2135 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2136 | set_sb_hash_function_code(rs, function2code(sbi->s_hash_function)); |
| 2137 | |
| 2138 | handle_attrs(s); |
| 2139 | |
| 2140 | reiserfs_proc_info_init(s); |
| 2141 | |
| 2142 | init_waitqueue_head(&(sbi->s_wait)); |
| 2143 | spin_lock_init(&sbi->bitmap_lock); |
| 2144 | |
Frederic Weisbecker | 8ebc423 | 2009-04-07 04:19:49 +0200 | [diff] [blame] | 2145 | reiserfs_write_unlock(s); |
| 2146 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2147 | return (0); |
| 2148 | |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 2149 | error: |
Jeff Mahoney | b7b7fa4 | 2010-03-29 15:12:39 -0400 | [diff] [blame] | 2150 | reiserfs_write_unlock(s); |
| 2151 | |
Frederic Weisbecker | f32485b | 2012-01-10 15:11:07 -0800 | [diff] [blame] | 2152 | error_unlocked: |
| 2153 | /* kill the commit thread, free journal ram */ |
| 2154 | if (jinit_done) { |
| 2155 | reiserfs_write_lock(s); |
| 2156 | journal_release_error(NULL, s); |
| 2157 | reiserfs_write_unlock(s); |
| 2158 | } |
| 2159 | |
Artem Bityutskiy | 033369d | 2012-06-01 17:18:08 +0300 | [diff] [blame] | 2160 | cancel_delayed_work_sync(&REISERFS_SB(s)->old_work); |
| 2161 | |
Jeff Mahoney | 5065227 | 2006-09-30 23:28:44 -0700 | [diff] [blame] | 2162 | reiserfs_free_bitmap_cache(s); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2163 | if (SB_BUFFER_WITH_SB(s)) |
| 2164 | brelse(SB_BUFFER_WITH_SB(s)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | #ifdef CONFIG_QUOTA |
Jeff Mahoney | 5065227 | 2006-09-30 23:28:44 -0700 | [diff] [blame] | 2166 | { |
| 2167 | int j; |
Jan Kara | 00b4419 | 2008-07-25 01:46:38 -0700 | [diff] [blame] | 2168 | for (j = 0; j < MAXQUOTAS; j++) |
| 2169 | kfree(qf_names[j]); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | #endif |
James Lamanna | 833d304 | 2005-10-30 15:00:16 -0800 | [diff] [blame] | 2172 | kfree(sbi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2174 | s->s_fs_info = NULL; |
| 2175 | return errval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | } |
| 2177 | |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2178 | static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | { |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2180 | struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2181 | |
| 2182 | buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize)); |
| 2183 | buf->f_bfree = sb_free_blocks(rs); |
| 2184 | buf->f_bavail = buf->f_bfree; |
| 2185 | buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1; |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 2186 | buf->f_bsize = dentry->d_sb->s_blocksize; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2187 | /* changed to accommodate gcc folks. */ |
| 2188 | buf->f_type = REISERFS_SUPER_MAGIC; |
Coly Li | 651d062 | 2009-04-02 16:59:41 -0700 | [diff] [blame] | 2189 | buf->f_fsid.val[0] = (u32)crc32_le(0, rs->s_uuid, sizeof(rs->s_uuid)/2); |
| 2190 | buf->f_fsid.val[1] = (u32)crc32_le(0, rs->s_uuid + sizeof(rs->s_uuid)/2, |
| 2191 | sizeof(rs->s_uuid)/2); |
| 2192 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | #ifdef CONFIG_QUOTA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | static int reiserfs_write_dquot(struct dquot *dquot) |
| 2198 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2199 | struct reiserfs_transaction_handle th; |
| 2200 | int ret, err; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2201 | int depth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2203 | reiserfs_write_lock(dquot->dq_sb); |
| 2204 | ret = |
| 2205 | journal_begin(&th, dquot->dq_sb, |
| 2206 | REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); |
| 2207 | if (ret) |
| 2208 | goto out; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2209 | depth = reiserfs_write_unlock_nested(dquot->dq_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2210 | ret = dquot_commit(dquot); |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2211 | reiserfs_write_lock_nested(dquot->dq_sb, depth); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2212 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2213 | if (!ret && err) |
| 2214 | ret = err; |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2215 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2216 | reiserfs_write_unlock(dquot->dq_sb); |
| 2217 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | static int reiserfs_acquire_dquot(struct dquot *dquot) |
| 2221 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2222 | struct reiserfs_transaction_handle th; |
| 2223 | int ret, err; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2224 | int depth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2226 | reiserfs_write_lock(dquot->dq_sb); |
| 2227 | ret = |
| 2228 | journal_begin(&th, dquot->dq_sb, |
| 2229 | REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb)); |
| 2230 | if (ret) |
| 2231 | goto out; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2232 | depth = reiserfs_write_unlock_nested(dquot->dq_sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2233 | ret = dquot_acquire(dquot); |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2234 | reiserfs_write_lock_nested(dquot->dq_sb, depth); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2235 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2236 | if (!ret && err) |
| 2237 | ret = err; |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2238 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2239 | reiserfs_write_unlock(dquot->dq_sb); |
| 2240 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | static int reiserfs_release_dquot(struct dquot *dquot) |
| 2244 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2245 | struct reiserfs_transaction_handle th; |
| 2246 | int ret, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2248 | reiserfs_write_lock(dquot->dq_sb); |
| 2249 | ret = |
| 2250 | journal_begin(&th, dquot->dq_sb, |
| 2251 | REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb)); |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2252 | reiserfs_write_unlock(dquot->dq_sb); |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2253 | if (ret) { |
| 2254 | /* Release dquot anyway to avoid endless cycle in dqput() */ |
| 2255 | dquot_release(dquot); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2256 | goto out; |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2257 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2258 | ret = dquot_release(dquot); |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2259 | reiserfs_write_lock(dquot->dq_sb); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2260 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2261 | if (!ret && err) |
| 2262 | ret = err; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2263 | reiserfs_write_unlock(dquot->dq_sb); |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2264 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2265 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | static int reiserfs_mark_dquot_dirty(struct dquot *dquot) |
| 2269 | { |
Jan Kara | 4506567 | 2008-07-25 01:46:37 -0700 | [diff] [blame] | 2270 | /* Are we journaling quotas? */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2271 | if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] || |
| 2272 | REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) { |
| 2273 | dquot_mark_dquot_dirty(dquot); |
| 2274 | return reiserfs_write_dquot(dquot); |
| 2275 | } else |
| 2276 | return dquot_mark_dquot_dirty(dquot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
| 2279 | static int reiserfs_write_info(struct super_block *sb, int type) |
| 2280 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2281 | struct reiserfs_transaction_handle th; |
| 2282 | int ret, err; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2283 | int depth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2285 | /* Data block + inode block */ |
| 2286 | reiserfs_write_lock(sb); |
| 2287 | ret = journal_begin(&th, sb, 2); |
| 2288 | if (ret) |
| 2289 | goto out; |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2290 | depth = reiserfs_write_unlock_nested(sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2291 | ret = dquot_commit_info(sb, type); |
Jeff Mahoney | d2d0395 | 2013-08-08 17:34:47 -0400 | [diff] [blame] | 2292 | reiserfs_write_lock_nested(sb, depth); |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2293 | err = journal_end(&th); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2294 | if (!ret && err) |
| 2295 | ret = err; |
Jan Kara | 7af1168 | 2012-11-13 17:05:14 +0100 | [diff] [blame] | 2296 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2297 | reiserfs_write_unlock(sb); |
| 2298 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | /* |
Christoph Hellwig | 84de856 | 2005-06-23 00:09:16 -0700 | [diff] [blame] | 2302 | * Turn on quotas during mount time - we need to find the quota file and such... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | */ |
| 2304 | static int reiserfs_quota_on_mount(struct super_block *sb, int type) |
| 2305 | { |
Christoph Hellwig | 287a809 | 2010-05-19 07:16:45 -0400 | [diff] [blame] | 2306 | return dquot_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type], |
| 2307 | REISERFS_SB(sb)->s_jquota_fmt, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /* |
| 2311 | * Standard function to be called on quota_on |
| 2312 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2313 | static int reiserfs_quota_on(struct super_block *sb, int type, int format_id, |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2314 | struct path *path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2316 | int err; |
Jan Kara | d5dee5c | 2008-04-28 02:16:23 -0700 | [diff] [blame] | 2317 | struct inode *inode; |
Jan Kara | 5d4f7fd | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 2318 | struct reiserfs_transaction_handle th; |
Jan Kara | c3aa077 | 2011-12-21 20:17:10 +0100 | [diff] [blame] | 2319 | int opt = type == USRQUOTA ? REISERFS_USRQUOTA : REISERFS_GRPQUOTA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2320 | |
Jan Kara | b9e06ef | 2012-11-13 16:34:17 +0100 | [diff] [blame] | 2321 | reiserfs_write_lock(sb); |
| 2322 | if (!(REISERFS_SB(sb)->s_mount_opt & (1 << opt))) { |
| 2323 | err = -EINVAL; |
| 2324 | goto out; |
| 2325 | } |
Christoph Hellwig | 307ae18 | 2010-05-19 07:16:43 -0400 | [diff] [blame] | 2326 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2327 | /* Quotafile not on the same filesystem? */ |
Al Viro | d8c9584 | 2011-12-07 18:16:57 -0500 | [diff] [blame] | 2328 | if (path->dentry->d_sb != sb) { |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2329 | err = -EXDEV; |
| 2330 | goto out; |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2331 | } |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2332 | inode = path->dentry->d_inode; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2333 | /* |
| 2334 | * We must not pack tails for quota files on reiserfs for quota |
| 2335 | * IO to work |
| 2336 | */ |
Jan Kara | d5dee5c | 2008-04-28 02:16:23 -0700 | [diff] [blame] | 2337 | if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) { |
| 2338 | err = reiserfs_unpack(inode, NULL); |
| 2339 | if (err) { |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 2340 | reiserfs_warning(sb, "super-6520", |
| 2341 | "Unpacking tail of quota file failed" |
Jan Kara | d5dee5c | 2008-04-28 02:16:23 -0700 | [diff] [blame] | 2342 | " (%d). Cannot turn on quotas.", err); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2343 | err = -EINVAL; |
| 2344 | goto out; |
Jan Kara | d5dee5c | 2008-04-28 02:16:23 -0700 | [diff] [blame] | 2345 | } |
| 2346 | mark_inode_dirty(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2347 | } |
Jan Kara | 5d4f7fd | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 2348 | /* Journaling quota? */ |
| 2349 | if (REISERFS_SB(sb)->s_qf_names[type]) { |
| 2350 | /* Quotafile not of fs root? */ |
Jan Kara | f00c9e4 | 2010-09-15 17:38:58 +0200 | [diff] [blame] | 2351 | if (path->dentry->d_parent != sb->s_root) |
Jeff Mahoney | 45b03d5 | 2009-03-30 14:02:21 -0400 | [diff] [blame] | 2352 | reiserfs_warning(sb, "super-6521", |
| 2353 | "Quota file not on filesystem root. " |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2354 | "Journalled quota will not work."); |
Jan Kara | 5d4f7fd | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | /* |
| 2358 | * When we journal data on quota file, we have to flush journal to see |
| 2359 | * all updates to the file when we bypass pagecache... |
| 2360 | */ |
| 2361 | if (reiserfs_file_data_log(inode)) { |
| 2362 | /* Just start temporary transaction and finish it */ |
| 2363 | err = journal_begin(&th, sb, 1); |
| 2364 | if (err) |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2365 | goto out; |
Jeff Mahoney | 58d8542 | 2014-04-23 10:00:38 -0400 | [diff] [blame] | 2366 | err = journal_end_sync(&th); |
Jan Kara | 5d4f7fd | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 2367 | if (err) |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2368 | goto out; |
Jan Kara | 5d4f7fd | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 2369 | } |
Jan Kara | b9e06ef | 2012-11-13 16:34:17 +0100 | [diff] [blame] | 2370 | reiserfs_write_unlock(sb); |
| 2371 | return dquot_quota_on(sb, type, format_id, path); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2372 | out: |
Jan Kara | b9e06ef | 2012-11-13 16:34:17 +0100 | [diff] [blame] | 2373 | reiserfs_write_unlock(sb); |
Al Viro | 77e69da | 2008-08-01 04:29:18 -0400 | [diff] [blame] | 2374 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2377 | /* |
| 2378 | * Read data from quotafile - avoid pagecache and such because we cannot afford |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | * 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] | 2380 | * itself serializes the operations (and no one else should touch the files) |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2381 | * we don't have to be afraid of races |
| 2382 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data, |
| 2384 | size_t len, loff_t off) |
| 2385 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2386 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2387 | unsigned long blk = off >> sb->s_blocksize_bits; |
| 2388 | int err = 0, offset = off & (sb->s_blocksize - 1), tocopy; |
| 2389 | size_t toread; |
| 2390 | struct buffer_head tmp_bh, *bh; |
| 2391 | loff_t i_size = i_size_read(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2393 | if (off > i_size) |
| 2394 | return 0; |
| 2395 | if (off + len > i_size) |
| 2396 | len = i_size - off; |
| 2397 | toread = len; |
| 2398 | while (toread > 0) { |
| 2399 | tocopy = |
| 2400 | sb->s_blocksize - offset < |
| 2401 | toread ? sb->s_blocksize - offset : toread; |
| 2402 | tmp_bh.b_state = 0; |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2403 | /* |
| 2404 | * Quota files are without tails so we can safely |
| 2405 | * use this function |
| 2406 | */ |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2407 | reiserfs_write_lock(sb); |
| 2408 | err = reiserfs_get_block(inode, blk, &tmp_bh, 0); |
| 2409 | reiserfs_write_unlock(sb); |
| 2410 | if (err) |
| 2411 | return err; |
| 2412 | if (!buffer_mapped(&tmp_bh)) /* A hole? */ |
| 2413 | memset(data, 0, tocopy); |
| 2414 | else { |
| 2415 | bh = sb_bread(sb, tmp_bh.b_blocknr); |
| 2416 | if (!bh) |
| 2417 | return -EIO; |
| 2418 | memcpy(data, bh->b_data + offset, tocopy); |
| 2419 | brelse(bh); |
| 2420 | } |
| 2421 | offset = 0; |
| 2422 | toread -= tocopy; |
| 2423 | data += tocopy; |
| 2424 | blk++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2426 | return len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Jeff Mahoney | 098297b | 2014-04-23 10:00:36 -0400 | [diff] [blame] | 2429 | /* |
| 2430 | * Write to quotafile (we know the transaction is already started and has |
| 2431 | * enough credits) |
| 2432 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | static ssize_t reiserfs_quota_write(struct super_block *sb, int type, |
| 2434 | const char *data, size_t len, loff_t off) |
| 2435 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2436 | struct inode *inode = sb_dqopt(sb)->files[type]; |
| 2437 | unsigned long blk = off >> sb->s_blocksize_bits; |
| 2438 | int err = 0, offset = off & (sb->s_blocksize - 1), tocopy; |
| 2439 | int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL; |
| 2440 | size_t towrite = len; |
| 2441 | struct buffer_head tmp_bh, *bh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2443 | if (!current->journal_info) { |
| 2444 | printk(KERN_WARNING "reiserfs: Quota write (off=%Lu, len=%Lu)" |
| 2445 | " cancelled because transaction is not started.\n", |
| 2446 | (unsigned long long)off, (unsigned long long)len); |
| 2447 | return -EIO; |
| 2448 | } |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2449 | while (towrite > 0) { |
| 2450 | tocopy = sb->s_blocksize - offset < towrite ? |
| 2451 | sb->s_blocksize - offset : towrite; |
| 2452 | tmp_bh.b_state = 0; |
Jan Kara | 361d94a | 2012-11-13 18:25:38 +0100 | [diff] [blame] | 2453 | reiserfs_write_lock(sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2454 | err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE); |
Jan Kara | 361d94a | 2012-11-13 18:25:38 +0100 | [diff] [blame] | 2455 | reiserfs_write_unlock(sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2456 | if (err) |
| 2457 | goto out; |
| 2458 | if (offset || tocopy != sb->s_blocksize) |
| 2459 | bh = sb_bread(sb, tmp_bh.b_blocknr); |
| 2460 | else |
| 2461 | bh = sb_getblk(sb, tmp_bh.b_blocknr); |
| 2462 | if (!bh) { |
| 2463 | err = -EIO; |
| 2464 | goto out; |
| 2465 | } |
| 2466 | lock_buffer(bh); |
| 2467 | memcpy(bh->b_data + offset, data, tocopy); |
| 2468 | flush_dcache_page(bh->b_page); |
| 2469 | set_buffer_uptodate(bh); |
| 2470 | unlock_buffer(bh); |
Jan Kara | 361d94a | 2012-11-13 18:25:38 +0100 | [diff] [blame] | 2471 | reiserfs_write_lock(sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2472 | reiserfs_prepare_for_journal(sb, bh, 1); |
Jeff Mahoney | 09f1b80 | 2014-04-23 10:00:39 -0400 | [diff] [blame] | 2473 | journal_mark_dirty(current->journal_info, bh); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2474 | if (!journal_quota) |
| 2475 | reiserfs_add_ordered_list(inode, bh); |
Jan Kara | 361d94a | 2012-11-13 18:25:38 +0100 | [diff] [blame] | 2476 | reiserfs_write_unlock(sb); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2477 | brelse(bh); |
| 2478 | offset = 0; |
| 2479 | towrite -= tocopy; |
| 2480 | data += tocopy; |
| 2481 | blk++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | } |
Jan Kara | 9c3013e | 2007-09-11 15:23:29 -0700 | [diff] [blame] | 2483 | out: |
Jan Kara | 67f1648 | 2012-04-25 21:28:12 +0200 | [diff] [blame] | 2484 | if (len == towrite) |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2485 | return err; |
| 2486 | if (inode->i_size < off + len - towrite) |
| 2487 | i_size_write(inode, off + len - towrite); |
| 2488 | inode->i_version++; |
| 2489 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 2490 | mark_inode_dirty(inode); |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2491 | return len - towrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | #endif |
| 2495 | |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 2496 | static struct dentry *get_super_block(struct file_system_type *fs_type, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 2497 | int flags, const char *dev_name, |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 2498 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | { |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 2500 | return mount_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2503 | static int __init init_reiserfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | { |
| 2505 | int ret; |
| 2506 | |
Jeff Mahoney | 797d901 | 2014-04-23 10:00:34 -0400 | [diff] [blame] | 2507 | ret = init_inodecache(); |
| 2508 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2511 | reiserfs_proc_info_global_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2513 | ret = register_filesystem(&reiserfs_fs_type); |
Jeff Mahoney | 797d901 | 2014-04-23 10:00:34 -0400 | [diff] [blame] | 2514 | if (ret) |
| 2515 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | |
Jeff Mahoney | 797d901 | 2014-04-23 10:00:34 -0400 | [diff] [blame] | 2517 | return 0; |
| 2518 | out: |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2519 | reiserfs_proc_info_global_done(); |
| 2520 | destroy_inodecache(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | |
| 2522 | return ret; |
| 2523 | } |
| 2524 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2525 | static void __exit exit_reiserfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2527 | reiserfs_proc_info_global_done(); |
| 2528 | unregister_filesystem(&reiserfs_fs_type); |
| 2529 | destroy_inodecache(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | struct file_system_type reiserfs_fs_type = { |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2533 | .owner = THIS_MODULE, |
| 2534 | .name = "reiserfs", |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 2535 | .mount = get_super_block, |
David Howells | edc666e | 2006-10-11 01:22:14 -0700 | [diff] [blame] | 2536 | .kill_sb = reiserfs_kill_sb, |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2537 | .fs_flags = FS_REQUIRES_DEV, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 2539 | MODULE_ALIAS_FS("reiserfs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2541 | MODULE_DESCRIPTION("ReiserFS journaled filesystem"); |
| 2542 | MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>"); |
| 2543 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Linus Torvalds | bd4c625 | 2005-07-12 20:21:28 -0700 | [diff] [blame] | 2545 | module_init(init_reiserfs_fs); |
| 2546 | module_exit(exit_reiserfs_fs); |