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