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