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