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