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