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