2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
4 * Trivial changes by Alan Cox to add the LFS fixes
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.
14 #include <linux/module.h>
15 #include <linux/slab.h>
16 #include <linux/vmalloc.h>
17 #include <linux/time.h>
18 #include <linux/uaccess.h>
22 #include <linux/init.h>
23 #include <linux/blkdev.h>
24 #include <linux/backing-dev.h>
25 #include <linux/buffer_head.h>
26 #include <linux/exportfs.h>
27 #include <linux/quotaops.h>
28 #include <linux/vfs.h>
29 #include <linux/mount.h>
30 #include <linux/namei.h>
31 #include <linux/crc32.h>
32 #include <linux/seq_file.h>
34 struct file_system_type reiserfs_fs_type
;
36 static const char reiserfs_3_5_magic_string
[] = REISERFS_SUPER_MAGIC_STRING
;
37 static const char reiserfs_3_6_magic_string
[] = REISER2FS_SUPER_MAGIC_STRING
;
38 static const char reiserfs_jr_magic_string
[] = REISER2FS_JR_SUPER_MAGIC_STRING
;
40 int is_reiserfs_3_5(struct reiserfs_super_block
*rs
)
42 return !strncmp(rs
->s_v1
.s_magic
, reiserfs_3_5_magic_string
,
43 strlen(reiserfs_3_5_magic_string
));
46 int is_reiserfs_3_6(struct reiserfs_super_block
*rs
)
48 return !strncmp(rs
->s_v1
.s_magic
, reiserfs_3_6_magic_string
,
49 strlen(reiserfs_3_6_magic_string
));
52 int is_reiserfs_jr(struct reiserfs_super_block
*rs
)
54 return !strncmp(rs
->s_v1
.s_magic
, reiserfs_jr_magic_string
,
55 strlen(reiserfs_jr_magic_string
));
58 static int is_any_reiserfs_magic_string(struct reiserfs_super_block
*rs
)
60 return (is_reiserfs_3_5(rs
) || is_reiserfs_3_6(rs
) ||
64 static int reiserfs_remount(struct super_block
*s
, int *flags
, char *data
);
65 static int reiserfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
);
67 static int reiserfs_sync_fs(struct super_block
*s
, int wait
)
69 struct reiserfs_transaction_handle th
;
72 * Writeback quota in non-journalled quota case - journalled quota has
75 dquot_writeback_dquots(s
, -1);
76 reiserfs_write_lock(s
);
77 if (!journal_begin(&th
, s
, 1))
78 if (!journal_end_sync(&th
))
79 reiserfs_flush_old_commits(s
);
80 reiserfs_write_unlock(s
);
84 static void flush_old_commits(struct work_struct
*work
)
86 struct reiserfs_sb_info
*sbi
;
87 struct super_block
*s
;
89 sbi
= container_of(work
, struct reiserfs_sb_info
, old_work
.work
);
90 s
= sbi
->s_journal
->j_work_sb
;
92 spin_lock(&sbi
->old_work_lock
);
94 spin_unlock(&sbi
->old_work_lock
);
96 reiserfs_sync_fs(s
, 1);
99 void reiserfs_schedule_old_flush(struct super_block
*s
)
101 struct reiserfs_sb_info
*sbi
= REISERFS_SB(s
);
105 * Avoid scheduling flush when sb is being shut down. It can race
106 * with journal shutdown and free still queued delayed work.
108 if (s
->s_flags
& MS_RDONLY
|| !(s
->s_flags
& MS_ACTIVE
))
111 spin_lock(&sbi
->old_work_lock
);
112 if (!sbi
->work_queued
) {
113 delay
= msecs_to_jiffies(dirty_writeback_interval
* 10);
114 queue_delayed_work(system_long_wq
, &sbi
->old_work
, delay
);
115 sbi
->work_queued
= 1;
117 spin_unlock(&sbi
->old_work_lock
);
120 static void cancel_old_flush(struct super_block
*s
)
122 struct reiserfs_sb_info
*sbi
= REISERFS_SB(s
);
124 cancel_delayed_work_sync(&REISERFS_SB(s
)->old_work
);
125 spin_lock(&sbi
->old_work_lock
);
126 sbi
->work_queued
= 0;
127 spin_unlock(&sbi
->old_work_lock
);
130 static int reiserfs_freeze(struct super_block
*s
)
132 struct reiserfs_transaction_handle th
;
136 reiserfs_write_lock(s
);
137 if (!(s
->s_flags
& MS_RDONLY
)) {
138 int err
= journal_begin(&th
, s
, 1);
140 reiserfs_block_writes(&th
);
142 reiserfs_prepare_for_journal(s
, SB_BUFFER_WITH_SB(s
),
144 journal_mark_dirty(&th
, SB_BUFFER_WITH_SB(s
));
145 reiserfs_block_writes(&th
);
146 journal_end_sync(&th
);
149 reiserfs_write_unlock(s
);
153 static int reiserfs_unfreeze(struct super_block
*s
)
155 reiserfs_allow_writes(s
);
159 extern const struct in_core_key MAX_IN_CORE_KEY
;
162 * this is used to delete "save link" when there are no items of a
163 * file it points to. It can either happen if unlink is completed but
164 * "save unlink" removal, or if file has both unlink and truncate
165 * pending and as unlink completes first (because key of "save link"
166 * protecting unlink is bigger that a key lf "save link" which
167 * protects truncate), so there left no items to make truncate
170 static int remove_save_link_only(struct super_block
*s
,
171 struct reiserfs_key
*key
, int oid_free
)
173 struct reiserfs_transaction_handle th
;
176 /* we are going to do one balancing */
177 err
= journal_begin(&th
, s
, JOURNAL_PER_BALANCE_CNT
);
181 reiserfs_delete_solid_item(&th
, NULL
, key
);
183 /* removals are protected by direct items */
184 reiserfs_release_objectid(&th
, le32_to_cpu(key
->k_objectid
));
186 return journal_end(&th
);
190 static int reiserfs_quota_on_mount(struct super_block
*, int);
193 /* look for uncompleted unlinks and truncates and complete them */
194 static int finish_unfinished(struct super_block
*s
)
196 INITIALIZE_PATH(path
);
197 struct cpu_key max_cpu_key
, obj_key
;
198 struct reiserfs_key save_link_key
, last_inode_key
;
200 struct item_head
*ih
;
201 struct buffer_head
*bh
;
210 int quota_enabled
[REISERFS_MAXQUOTAS
];
213 /* compose key to look for "save" links */
214 max_cpu_key
.version
= KEY_FORMAT_3_5
;
215 max_cpu_key
.on_disk_key
.k_dir_id
= ~0U;
216 max_cpu_key
.on_disk_key
.k_objectid
= ~0U;
217 set_cpu_key_k_offset(&max_cpu_key
, ~0U);
218 max_cpu_key
.key_length
= 3;
220 memset(&last_inode_key
, 0, sizeof(last_inode_key
));
223 /* Needed for iput() to work correctly and not trash data */
224 if (s
->s_flags
& MS_ACTIVE
) {
228 s
->s_flags
|= MS_ACTIVE
;
230 /* Turn on quotas so that they are updated correctly */
231 for (i
= 0; i
< REISERFS_MAXQUOTAS
; i
++) {
232 quota_enabled
[i
] = 1;
233 if (REISERFS_SB(s
)->s_qf_names
[i
]) {
236 if (sb_has_quota_active(s
, i
)) {
237 quota_enabled
[i
] = 0;
240 ret
= reiserfs_quota_on_mount(s
, i
);
242 reiserfs_warning(s
, "reiserfs-2500",
243 "cannot turn on journaled "
244 "quota: error %d", ret
);
250 REISERFS_SB(s
)->s_is_unlinked_ok
= 1;
253 retval
= search_item(s
, &max_cpu_key
, &path
);
254 if (retval
!= ITEM_NOT_FOUND
) {
255 reiserfs_error(s
, "vs-2140",
256 "search_by_key returned %d", retval
);
260 bh
= get_last_bh(&path
);
261 item_pos
= get_item_pos(&path
);
262 if (item_pos
!= B_NR_ITEMS(bh
)) {
263 reiserfs_warning(s
, "vs-2060",
264 "wrong position found");
268 ih
= item_head(bh
, item_pos
);
270 if (le32_to_cpu(ih
->ih_key
.k_dir_id
) != MAX_KEY_OBJECTID
)
271 /* there are no "save" links anymore */
274 save_link_key
= ih
->ih_key
;
275 if (is_indirect_le_ih(ih
))
280 /* reiserfs_iget needs k_dirid and k_objectid only */
281 item
= ih_item_body(bh
, ih
);
282 obj_key
.on_disk_key
.k_dir_id
= le32_to_cpu(*(__le32
*) item
);
283 obj_key
.on_disk_key
.k_objectid
=
284 le32_to_cpu(ih
->ih_key
.k_objectid
);
285 obj_key
.on_disk_key
.k_offset
= 0;
286 obj_key
.on_disk_key
.k_type
= 0;
290 inode
= reiserfs_iget(s
, &obj_key
);
293 * the unlink almost completed, it just did not
294 * manage to remove "save" link and release objectid
296 reiserfs_warning(s
, "vs-2180", "iget failed for %K",
298 retval
= remove_save_link_only(s
, &save_link_key
, 1);
302 if (!truncate
&& inode
->i_nlink
) {
303 /* file is not unlinked */
304 reiserfs_warning(s
, "vs-2185",
305 "file %K is not unlinked",
307 retval
= remove_save_link_only(s
, &save_link_key
, 0);
310 depth
= reiserfs_write_unlock_nested(inode
->i_sb
);
311 dquot_initialize(inode
);
312 reiserfs_write_lock_nested(inode
->i_sb
, depth
);
314 if (truncate
&& S_ISDIR(inode
->i_mode
)) {
316 * We got a truncate request for a dir which
317 * is impossible. The only imaginable way is to
318 * execute unfinished truncate request then boot
319 * into old kernel, remove the file and create dir
322 reiserfs_warning(s
, "green-2101",
323 "impossible truncate on a "
324 "directory %k. Please report",
326 retval
= remove_save_link_only(s
, &save_link_key
, 0);
333 REISERFS_I(inode
)->i_flags
|=
334 i_link_saved_truncate_mask
;
336 * not completed truncate found. New size was
337 * committed together with "save" link
339 reiserfs_info(s
, "Truncating %k to %lld ..",
340 INODE_PKEY(inode
), inode
->i_size
);
342 /* don't update modification time */
343 reiserfs_truncate_file(inode
, 0);
345 retval
= remove_save_link(inode
, truncate
);
347 REISERFS_I(inode
)->i_flags
|= i_link_saved_unlink_mask
;
348 /* not completed unlink (rmdir) found */
349 reiserfs_info(s
, "Removing %k..", INODE_PKEY(inode
));
350 if (memcmp(&last_inode_key
, INODE_PKEY(inode
),
351 sizeof(last_inode_key
))){
352 last_inode_key
= *INODE_PKEY(inode
);
353 /* removal gets completed in iput */
356 reiserfs_warning(s
, "super-2189", "Dead loop "
357 "in finish_unfinished "
358 "detected, just remove "
360 retval
= remove_save_link_only(s
,
369 REISERFS_SB(s
)->s_is_unlinked_ok
= 0;
372 /* Turn quotas off */
373 reiserfs_write_unlock(s
);
374 for (i
= 0; i
< REISERFS_MAXQUOTAS
; i
++) {
375 if (sb_dqopt(s
)->files
[i
] && quota_enabled
[i
])
376 dquot_quota_off(s
, i
);
378 reiserfs_write_lock(s
);
380 /* Restore the flag back */
381 s
->s_flags
&= ~MS_ACTIVE
;
385 reiserfs_info(s
, "There were %d uncompleted unlinks/truncates. "
386 "Completed\n", done
);
391 * to protect file being unlinked from getting lost we "safe" link files
392 * being unlinked. This link will be deleted in the same transaction with last
393 * item of file. mounting the filesystem we scan all these links and remove
394 * files which almost got lost
396 void add_save_link(struct reiserfs_transaction_handle
*th
,
397 struct inode
*inode
, int truncate
)
399 INITIALIZE_PATH(path
);
405 BUG_ON(!th
->t_trans_id
);
407 /* file can only get one "save link" of each kind */
409 (REISERFS_I(inode
)->i_flags
& i_link_saved_truncate_mask
),
410 "saved link already exists for truncated inode %lx",
413 (REISERFS_I(inode
)->i_flags
& i_link_saved_unlink_mask
),
414 "saved link already exists for unlinked inode %lx",
417 /* setup key of "save" link */
418 key
.version
= KEY_FORMAT_3_5
;
419 key
.on_disk_key
.k_dir_id
= MAX_KEY_OBJECTID
;
420 key
.on_disk_key
.k_objectid
= inode
->i_ino
;
422 /* unlink, rmdir, rename */
423 set_cpu_key_k_offset(&key
, 1 + inode
->i_sb
->s_blocksize
);
424 set_cpu_key_k_type(&key
, TYPE_DIRECT
);
426 /* item head of "safe" link */
427 make_le_item_head(&ih
, &key
, key
.version
,
428 1 + inode
->i_sb
->s_blocksize
, TYPE_DIRECT
,
429 4 /*length */ , 0xffff /*free space */ );
432 if (S_ISDIR(inode
->i_mode
))
433 reiserfs_warning(inode
->i_sb
, "green-2102",
434 "Adding a truncate savelink for "
435 "a directory %k! Please report",
437 set_cpu_key_k_offset(&key
, 1);
438 set_cpu_key_k_type(&key
, TYPE_INDIRECT
);
440 /* item head of "safe" link */
441 make_le_item_head(&ih
, &key
, key
.version
, 1, TYPE_INDIRECT
,
442 4 /*length */ , 0 /*free space */ );
446 /* look for its place in the tree */
447 retval
= search_item(inode
->i_sb
, &key
, &path
);
448 if (retval
!= ITEM_NOT_FOUND
) {
449 if (retval
!= -ENOSPC
)
450 reiserfs_error(inode
->i_sb
, "vs-2100",
451 "search_by_key (%K) returned %d", &key
,
457 /* body of "save" link */
458 link
= INODE_PKEY(inode
)->k_dir_id
;
460 /* put "save" link into tree, don't charge quota to anyone */
462 reiserfs_insert_item(th
, &path
, &key
, &ih
, NULL
, (char *)&link
);
464 if (retval
!= -ENOSPC
)
465 reiserfs_error(inode
->i_sb
, "vs-2120",
466 "insert_item returned %d", retval
);
469 REISERFS_I(inode
)->i_flags
|=
470 i_link_saved_truncate_mask
;
472 REISERFS_I(inode
)->i_flags
|= i_link_saved_unlink_mask
;
476 /* this opens transaction unlike add_save_link */
477 int remove_save_link(struct inode
*inode
, int truncate
)
479 struct reiserfs_transaction_handle th
;
480 struct reiserfs_key key
;
483 /* we are going to do one balancing only */
484 err
= journal_begin(&th
, inode
->i_sb
, JOURNAL_PER_BALANCE_CNT
);
488 /* setup key of "save" link */
489 key
.k_dir_id
= cpu_to_le32(MAX_KEY_OBJECTID
);
490 key
.k_objectid
= INODE_PKEY(inode
)->k_objectid
;
492 /* unlink, rmdir, rename */
493 set_le_key_k_offset(KEY_FORMAT_3_5
, &key
,
494 1 + inode
->i_sb
->s_blocksize
);
495 set_le_key_k_type(KEY_FORMAT_3_5
, &key
, TYPE_DIRECT
);
498 set_le_key_k_offset(KEY_FORMAT_3_5
, &key
, 1);
499 set_le_key_k_type(KEY_FORMAT_3_5
, &key
, TYPE_INDIRECT
);
503 (REISERFS_I(inode
)->i_flags
& i_link_saved_truncate_mask
)) ||
505 (REISERFS_I(inode
)->i_flags
& i_link_saved_unlink_mask
)))
506 /* don't take quota bytes from anywhere */
507 reiserfs_delete_solid_item(&th
, NULL
, &key
);
509 reiserfs_release_objectid(&th
, inode
->i_ino
);
510 REISERFS_I(inode
)->i_flags
&= ~i_link_saved_unlink_mask
;
512 REISERFS_I(inode
)->i_flags
&= ~i_link_saved_truncate_mask
;
514 return journal_end(&th
);
517 static void reiserfs_kill_sb(struct super_block
*s
)
519 if (REISERFS_SB(s
)) {
520 reiserfs_proc_info_done(s
);
522 * Force any pending inode evictions to occur now. Any
523 * inodes to be removed that have extended attributes
524 * associated with them need to clean them up before
525 * we can release the extended attribute root dentries.
526 * shrink_dcache_for_umount will BUG if we don't release
527 * those before it's called so ->put_super is too late.
531 dput(REISERFS_SB(s
)->xattr_root
);
532 REISERFS_SB(s
)->xattr_root
= NULL
;
533 dput(REISERFS_SB(s
)->priv_root
);
534 REISERFS_SB(s
)->priv_root
= NULL
;
540 static void reiserfs_put_super(struct super_block
*s
)
542 struct reiserfs_transaction_handle th
;
545 dquot_disable(s
, -1, DQUOT_USAGE_ENABLED
| DQUOT_LIMITS_ENABLED
);
547 reiserfs_write_lock(s
);
550 * change file system state to current state if it was mounted
551 * with read-write permissions
553 if (!(s
->s_flags
& MS_RDONLY
)) {
554 if (!journal_begin(&th
, s
, 10)) {
555 reiserfs_prepare_for_journal(s
, SB_BUFFER_WITH_SB(s
),
557 set_sb_umount_state(SB_DISK_SUPER_BLOCK(s
),
558 REISERFS_SB(s
)->s_mount_state
);
559 journal_mark_dirty(&th
, SB_BUFFER_WITH_SB(s
));
564 * note, journal_release checks for readonly mount, and can
565 * decide not to do a journal_end
567 journal_release(&th
, s
);
569 reiserfs_free_bitmap_cache(s
);
571 brelse(SB_BUFFER_WITH_SB(s
));
575 if (REISERFS_SB(s
)->reserved_blocks
!= 0) {
576 reiserfs_warning(s
, "green-2005", "reserved blocks left %d",
577 REISERFS_SB(s
)->reserved_blocks
);
580 reiserfs_write_unlock(s
);
581 mutex_destroy(&REISERFS_SB(s
)->lock
);
582 destroy_workqueue(REISERFS_SB(s
)->commit_wq
);
587 static struct kmem_cache
*reiserfs_inode_cachep
;
589 static struct inode
*reiserfs_alloc_inode(struct super_block
*sb
)
591 struct reiserfs_inode_info
*ei
;
592 ei
= kmem_cache_alloc(reiserfs_inode_cachep
, GFP_KERNEL
);
595 atomic_set(&ei
->openers
, 0);
596 mutex_init(&ei
->tailpack
);
598 memset(&ei
->i_dquot
, 0, sizeof(ei
->i_dquot
));
601 return &ei
->vfs_inode
;
604 static void reiserfs_i_callback(struct rcu_head
*head
)
606 struct inode
*inode
= container_of(head
, struct inode
, i_rcu
);
607 kmem_cache_free(reiserfs_inode_cachep
, REISERFS_I(inode
));
610 static void reiserfs_destroy_inode(struct inode
*inode
)
612 call_rcu(&inode
->i_rcu
, reiserfs_i_callback
);
615 static void init_once(void *foo
)
617 struct reiserfs_inode_info
*ei
= (struct reiserfs_inode_info
*)foo
;
619 INIT_LIST_HEAD(&ei
->i_prealloc_list
);
620 inode_init_once(&ei
->vfs_inode
);
623 static int __init
init_inodecache(void)
625 reiserfs_inode_cachep
= kmem_cache_create("reiser_inode_cache",
627 reiserfs_inode_info
),
628 0, (SLAB_RECLAIM_ACCOUNT
|
631 if (reiserfs_inode_cachep
== NULL
)
636 static void destroy_inodecache(void)
639 * Make sure all delayed rcu free inodes are flushed before we
643 kmem_cache_destroy(reiserfs_inode_cachep
);
646 /* we don't mark inodes dirty, we just log them */
647 static void reiserfs_dirty_inode(struct inode
*inode
, int flags
)
649 struct reiserfs_transaction_handle th
;
653 if (inode
->i_sb
->s_flags
& MS_RDONLY
) {
654 reiserfs_warning(inode
->i_sb
, "clm-6006",
655 "writing inode %lu on readonly FS",
659 reiserfs_write_lock(inode
->i_sb
);
662 * this is really only used for atime updates, so they don't have
663 * to be included in O_SYNC or fsync
665 err
= journal_begin(&th
, inode
->i_sb
, 1);
669 reiserfs_update_sd(&th
, inode
);
673 reiserfs_write_unlock(inode
->i_sb
);
676 static int reiserfs_show_options(struct seq_file
*seq
, struct dentry
*root
)
678 struct super_block
*s
= root
->d_sb
;
679 struct reiserfs_journal
*journal
= SB_JOURNAL(s
);
680 long opts
= REISERFS_SB(s
)->s_mount_opt
;
682 if (opts
& (1 << REISERFS_LARGETAIL
))
683 seq_puts(seq
, ",tails=on");
684 else if (!(opts
& (1 << REISERFS_SMALLTAIL
)))
685 seq_puts(seq
, ",notail");
686 /* tails=small is default so we don't show it */
688 if (!(opts
& (1 << REISERFS_BARRIER_FLUSH
)))
689 seq_puts(seq
, ",barrier=none");
690 /* barrier=flush is default so we don't show it */
692 if (opts
& (1 << REISERFS_ERROR_CONTINUE
))
693 seq_puts(seq
, ",errors=continue");
694 else if (opts
& (1 << REISERFS_ERROR_PANIC
))
695 seq_puts(seq
, ",errors=panic");
696 /* errors=ro is default so we don't show it */
698 if (opts
& (1 << REISERFS_DATA_LOG
))
699 seq_puts(seq
, ",data=journal");
700 else if (opts
& (1 << REISERFS_DATA_WRITEBACK
))
701 seq_puts(seq
, ",data=writeback");
702 /* data=ordered is default so we don't show it */
704 if (opts
& (1 << REISERFS_ATTRS
))
705 seq_puts(seq
, ",attrs");
707 if (opts
& (1 << REISERFS_XATTRS_USER
))
708 seq_puts(seq
, ",user_xattr");
710 if (opts
& (1 << REISERFS_EXPOSE_PRIVROOT
))
711 seq_puts(seq
, ",expose_privroot");
713 if (opts
& (1 << REISERFS_POSIXACL
))
714 seq_puts(seq
, ",acl");
716 if (REISERFS_SB(s
)->s_jdev
)
717 seq_printf(seq
, ",jdev=%s", REISERFS_SB(s
)->s_jdev
);
719 if (journal
->j_max_commit_age
!= journal
->j_default_max_commit_age
)
720 seq_printf(seq
, ",commit=%d", journal
->j_max_commit_age
);
723 if (REISERFS_SB(s
)->s_qf_names
[USRQUOTA
])
724 seq_printf(seq
, ",usrjquota=%s", REISERFS_SB(s
)->s_qf_names
[USRQUOTA
]);
725 else if (opts
& (1 << REISERFS_USRQUOTA
))
726 seq_puts(seq
, ",usrquota");
727 if (REISERFS_SB(s
)->s_qf_names
[GRPQUOTA
])
728 seq_printf(seq
, ",grpjquota=%s", REISERFS_SB(s
)->s_qf_names
[GRPQUOTA
]);
729 else if (opts
& (1 << REISERFS_GRPQUOTA
))
730 seq_puts(seq
, ",grpquota");
731 if (REISERFS_SB(s
)->s_jquota_fmt
) {
732 if (REISERFS_SB(s
)->s_jquota_fmt
== QFMT_VFS_OLD
)
733 seq_puts(seq
, ",jqfmt=vfsold");
734 else if (REISERFS_SB(s
)->s_jquota_fmt
== QFMT_VFS_V0
)
735 seq_puts(seq
, ",jqfmt=vfsv0");
739 /* Block allocator options */
740 if (opts
& (1 << REISERFS_NO_BORDER
))
741 seq_puts(seq
, ",block-allocator=noborder");
742 if (opts
& (1 << REISERFS_NO_UNHASHED_RELOCATION
))
743 seq_puts(seq
, ",block-allocator=no_unhashed_relocation");
744 if (opts
& (1 << REISERFS_HASHED_RELOCATION
))
745 seq_puts(seq
, ",block-allocator=hashed_relocation");
746 if (opts
& (1 << REISERFS_TEST4
))
747 seq_puts(seq
, ",block-allocator=test4");
748 show_alloc_options(seq
, s
);
753 static ssize_t
reiserfs_quota_write(struct super_block
*, int, const char *,
755 static ssize_t
reiserfs_quota_read(struct super_block
*, int, char *, size_t,
758 static struct dquot
**reiserfs_get_dquots(struct inode
*inode
)
760 return REISERFS_I(inode
)->i_dquot
;
764 static const struct super_operations reiserfs_sops
= {
765 .alloc_inode
= reiserfs_alloc_inode
,
766 .destroy_inode
= reiserfs_destroy_inode
,
767 .write_inode
= reiserfs_write_inode
,
768 .dirty_inode
= reiserfs_dirty_inode
,
769 .evict_inode
= reiserfs_evict_inode
,
770 .put_super
= reiserfs_put_super
,
771 .sync_fs
= reiserfs_sync_fs
,
772 .freeze_fs
= reiserfs_freeze
,
773 .unfreeze_fs
= reiserfs_unfreeze
,
774 .statfs
= reiserfs_statfs
,
775 .remount_fs
= reiserfs_remount
,
776 .show_options
= reiserfs_show_options
,
778 .quota_read
= reiserfs_quota_read
,
779 .quota_write
= reiserfs_quota_write
,
780 .get_dquots
= reiserfs_get_dquots
,
785 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
787 static int reiserfs_write_dquot(struct dquot
*);
788 static int reiserfs_acquire_dquot(struct dquot
*);
789 static int reiserfs_release_dquot(struct dquot
*);
790 static int reiserfs_mark_dquot_dirty(struct dquot
*);
791 static int reiserfs_write_info(struct super_block
*, int);
792 static int reiserfs_quota_on(struct super_block
*, int, int, struct path
*);
794 static const struct dquot_operations reiserfs_quota_operations
= {
795 .write_dquot
= reiserfs_write_dquot
,
796 .acquire_dquot
= reiserfs_acquire_dquot
,
797 .release_dquot
= reiserfs_release_dquot
,
798 .mark_dirty
= reiserfs_mark_dquot_dirty
,
799 .write_info
= reiserfs_write_info
,
800 .alloc_dquot
= dquot_alloc
,
801 .destroy_dquot
= dquot_destroy
,
804 static const struct quotactl_ops reiserfs_qctl_operations
= {
805 .quota_on
= reiserfs_quota_on
,
806 .quota_off
= dquot_quota_off
,
807 .quota_sync
= dquot_quota_sync
,
808 .get_state
= dquot_get_state
,
809 .set_info
= dquot_set_dqinfo
,
810 .get_dqblk
= dquot_get_dqblk
,
811 .set_dqblk
= dquot_set_dqblk
,
815 static const struct export_operations reiserfs_export_ops
= {
816 .encode_fh
= reiserfs_encode_fh
,
817 .fh_to_dentry
= reiserfs_fh_to_dentry
,
818 .fh_to_parent
= reiserfs_fh_to_parent
,
819 .get_parent
= reiserfs_get_parent
,
823 * this struct is used in reiserfs_getopt () for containing the value for
824 * those mount options that have values rather than being toggles.
829 * bitmask which is to set on mount_options bitmask
830 * when this value is found, 0 is no bits are to be changed.
834 * bitmask which is to clear on mount_options bitmask
835 * when this value is found, 0 is no bits are to be changed.
836 * This is applied BEFORE setmask
841 /* Set this bit in arg_required to allow empty arguments */
842 #define REISERFS_OPT_ALLOWEMPTY 31
845 * this struct is used in reiserfs_getopt() for describing the
846 * set of reiserfs mount options
851 /* 0 if argument is not required, not 0 otherwise */
854 /* list of values accepted by an option */
855 const arg_desc_t
*values
;
858 * bitmask which is to set on mount_options bitmask
859 * when this value is found, 0 is no bits are to be changed.
864 * bitmask which is to clear on mount_options bitmask
865 * when this value is found, 0 is no bits are to be changed.
866 * This is applied BEFORE setmask
871 /* possible values for -o data= */
872 static const arg_desc_t logging_mode
[] = {
873 {"ordered", 1 << REISERFS_DATA_ORDERED
,
874 (1 << REISERFS_DATA_LOG
| 1 << REISERFS_DATA_WRITEBACK
)},
875 {"journal", 1 << REISERFS_DATA_LOG
,
876 (1 << REISERFS_DATA_ORDERED
| 1 << REISERFS_DATA_WRITEBACK
)},
877 {"writeback", 1 << REISERFS_DATA_WRITEBACK
,
878 (1 << REISERFS_DATA_ORDERED
| 1 << REISERFS_DATA_LOG
)},
882 /* possible values for -o barrier= */
883 static const arg_desc_t barrier_mode
[] = {
884 {"none", 1 << REISERFS_BARRIER_NONE
, 1 << REISERFS_BARRIER_FLUSH
},
885 {"flush", 1 << REISERFS_BARRIER_FLUSH
, 1 << REISERFS_BARRIER_NONE
},
890 * possible values for "-o block-allocator=" and bits which are to be set in
891 * s_mount_opt of reiserfs specific part of in-core super block
893 static const arg_desc_t balloc
[] = {
894 {"noborder", 1 << REISERFS_NO_BORDER
, 0},
895 {"border", 0, 1 << REISERFS_NO_BORDER
},
896 {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION
, 0},
897 {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION
, 0},
898 {"test4", 1 << REISERFS_TEST4
, 0},
899 {"notest4", 0, 1 << REISERFS_TEST4
},
903 static const arg_desc_t tails
[] = {
904 {"on", 1 << REISERFS_LARGETAIL
, 1 << REISERFS_SMALLTAIL
},
905 {"off", 0, (1 << REISERFS_LARGETAIL
) | (1 << REISERFS_SMALLTAIL
)},
906 {"small", 1 << REISERFS_SMALLTAIL
, 1 << REISERFS_LARGETAIL
},
910 static const arg_desc_t error_actions
[] = {
911 {"panic", 1 << REISERFS_ERROR_PANIC
,
912 (1 << REISERFS_ERROR_RO
| 1 << REISERFS_ERROR_CONTINUE
)},
913 {"ro-remount", 1 << REISERFS_ERROR_RO
,
914 (1 << REISERFS_ERROR_PANIC
| 1 << REISERFS_ERROR_CONTINUE
)},
915 #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
916 {"continue", 1 << REISERFS_ERROR_CONTINUE
,
917 (1 << REISERFS_ERROR_PANIC
| 1 << REISERFS_ERROR_RO
)},
923 * proceed only one option from a list *cur - string containing of mount
925 * opts - array of options which are accepted
926 * opt_arg - if option is found and requires an argument and if it is specifed
927 * in the input - pointer to the argument is stored here
928 * bit_flags - if option requires to set a certain bit - it is set here
929 * return -1 if unknown option is found, opt->arg_required otherwise
931 static int reiserfs_getopt(struct super_block
*s
, char **cur
, opt_desc_t
* opts
,
932 char **opt_arg
, unsigned long *bit_flags
)
942 const opt_desc_t
*opt
;
943 const arg_desc_t
*arg
;
947 /* assume argument cannot contain commas */
948 *cur
= strchr(p
, ',');
954 if (!strncmp(p
, "alloc=", 6)) {
956 * Ugly special case, probably we should redo options
957 * parser so that it can understand several arguments for
958 * some options, also so that it can fill several bitfields
959 * with option values.
961 if (reiserfs_parse_alloc_options(s
, p
+ 6)) {
968 /* for every option in the list */
969 for (opt
= opts
; opt
->option_name
; opt
++) {
970 if (!strncmp(p
, opt
->option_name
, strlen(opt
->option_name
))) {
973 (1 << REISERFS_UNSUPPORTED_OPT
))
974 reiserfs_warning(s
, "super-6500",
975 "%s not supported.\n",
978 *bit_flags
&= ~opt
->clrmask
;
980 (1 << REISERFS_UNSUPPORTED_OPT
))
981 reiserfs_warning(s
, "super-6501",
982 "%s not supported.\n",
985 *bit_flags
|= opt
->setmask
;
990 if (!opt
->option_name
) {
991 reiserfs_warning(s
, "super-6502",
992 "unknown mount option \"%s\"", p
);
996 p
+= strlen(opt
->option_name
);
999 if (!opt
->arg_required
) {
1000 reiserfs_warning(s
, "super-6503",
1001 "the option \"%s\" does not "
1002 "require an argument\n",
1009 if (opt
->arg_required
) {
1010 reiserfs_warning(s
, "super-6504",
1011 "the option \"%s\" requires an "
1012 "argument\n", opt
->option_name
);
1017 reiserfs_warning(s
, "super-6505",
1018 "head of option \"%s\" is only correct\n",
1024 * move to the argument, or to next option if argument is not
1029 if (opt
->arg_required
1030 && !(opt
->arg_required
& (1 << REISERFS_OPT_ALLOWEMPTY
))
1032 /* this catches "option=," if not allowed */
1033 reiserfs_warning(s
, "super-6506",
1034 "empty argument for \"%s\"\n",
1040 /* *=NULLopt_arg contains pointer to argument */
1042 return opt
->arg_required
& ~(1 << REISERFS_OPT_ALLOWEMPTY
);
1045 /* values possible for this option are listed in opt->values */
1046 for (arg
= opt
->values
; arg
->value
; arg
++) {
1047 if (!strcmp(p
, arg
->value
)) {
1049 *bit_flags
&= ~arg
->clrmask
;
1050 *bit_flags
|= arg
->setmask
;
1052 return opt
->arg_required
;
1056 reiserfs_warning(s
, "super-6506",
1057 "bad value \"%s\" for option \"%s\"\n", p
,
1062 /* returns 0 if something is wrong in option string, 1 - otherwise */
1063 static int reiserfs_parse_options(struct super_block
*s
,
1065 /* string given via mount's -o */
1069 * after the parsing phase, contains the
1070 * collection of bitflags defining what
1071 * mount options were selected.
1073 unsigned long *mount_options
,
1075 /* strtol-ed from NNN of resize=NNN */
1076 unsigned long *blocks
,
1078 unsigned int *commit_max_age
,
1085 opt_desc_t opts
[] = {
1087 * Compatibility stuff, so that -o notail for old
1090 {"tails",.arg_required
= 't',.values
= tails
},
1091 {"notail",.clrmask
=
1092 (1 << REISERFS_LARGETAIL
) | (1 << REISERFS_SMALLTAIL
)},
1093 {"conv",.setmask
= 1 << REISERFS_CONVERT
},
1094 {"attrs",.setmask
= 1 << REISERFS_ATTRS
},
1095 {"noattrs",.clrmask
= 1 << REISERFS_ATTRS
},
1096 {"expose_privroot", .setmask
= 1 << REISERFS_EXPOSE_PRIVROOT
},
1097 #ifdef CONFIG_REISERFS_FS_XATTR
1098 {"user_xattr",.setmask
= 1 << REISERFS_XATTRS_USER
},
1099 {"nouser_xattr",.clrmask
= 1 << REISERFS_XATTRS_USER
},
1101 {"user_xattr",.setmask
= 1 << REISERFS_UNSUPPORTED_OPT
},
1102 {"nouser_xattr",.clrmask
= 1 << REISERFS_UNSUPPORTED_OPT
},
1104 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
1105 {"acl",.setmask
= 1 << REISERFS_POSIXACL
},
1106 {"noacl",.clrmask
= 1 << REISERFS_POSIXACL
},
1108 {"acl",.setmask
= 1 << REISERFS_UNSUPPORTED_OPT
},
1109 {"noacl",.clrmask
= 1 << REISERFS_UNSUPPORTED_OPT
},
1111 {.option_name
= "nolog"},
1112 {"replayonly",.setmask
= 1 << REPLAYONLY
},
1113 {"block-allocator",.arg_required
= 'a',.values
= balloc
},
1114 {"data",.arg_required
= 'd',.values
= logging_mode
},
1115 {"barrier",.arg_required
= 'b',.values
= barrier_mode
},
1116 {"resize",.arg_required
= 'r',.values
= NULL
},
1117 {"jdev",.arg_required
= 'j',.values
= NULL
},
1118 {"nolargeio",.arg_required
= 'w',.values
= NULL
},
1119 {"commit",.arg_required
= 'c',.values
= NULL
},
1120 {"usrquota",.setmask
= 1 << REISERFS_USRQUOTA
},
1121 {"grpquota",.setmask
= 1 << REISERFS_GRPQUOTA
},
1122 {"noquota",.clrmask
= 1 << REISERFS_USRQUOTA
| 1 << REISERFS_GRPQUOTA
},
1123 {"errors",.arg_required
= 'e',.values
= error_actions
},
1124 {"usrjquota",.arg_required
=
1125 'u' | (1 << REISERFS_OPT_ALLOWEMPTY
),.values
= NULL
},
1126 {"grpjquota",.arg_required
=
1127 'g' | (1 << REISERFS_OPT_ALLOWEMPTY
),.values
= NULL
},
1128 {"jqfmt",.arg_required
= 'f',.values
= NULL
},
1129 {.option_name
= NULL
}
1133 if (!options
|| !*options
)
1135 * use default configuration: create tails, journaling on, no
1136 * conversion to newest format
1140 for (pos
= options
; pos
;) {
1141 c
= reiserfs_getopt(s
, &pos
, opts
, &arg
, mount_options
);
1143 /* wrong option is given */
1150 /* "resize=NNN" or "resize=auto" */
1152 if (!strcmp(arg
, "auto")) {
1153 /* From JFS code, to auto-get the size. */
1155 s
->s_bdev
->bd_inode
->i_size
>> s
->
1158 *blocks
= simple_strtoul(arg
, &p
, 0);
1160 /* NNN does not look like a number */
1161 reiserfs_warning(s
, "super-6507",
1171 unsigned long val
= simple_strtoul(arg
, &p
, 0);
1172 /* commit=NNN (time in seconds) */
1173 if (*p
!= '\0' || val
>= (unsigned int)-1) {
1174 reiserfs_warning(s
, "super-6508",
1175 "bad value %s for -ocommit\n",
1179 *commit_max_age
= (unsigned int)val
;
1183 reiserfs_warning(s
, "super-6509", "nolargeio option "
1184 "is no longer supported");
1189 if (arg
&& *arg
&& jdev_name
) {
1190 /* Hm, already assigned? */
1192 reiserfs_warning(s
, "super-6510",
1193 "journal device was "
1194 "already specified to "
1195 "be %s", *jdev_name
);
1202 if (c
== 'u' || c
== 'g') {
1203 int qtype
= c
== 'u' ? USRQUOTA
: GRPQUOTA
;
1205 if (sb_any_quota_loaded(s
) &&
1206 (!*arg
!= !REISERFS_SB(s
)->s_qf_names
[qtype
])) {
1207 reiserfs_warning(s
, "super-6511",
1208 "cannot change journaled "
1209 "quota options when quota "
1213 if (*arg
) { /* Some filename specified? */
1214 if (REISERFS_SB(s
)->s_qf_names
[qtype
]
1215 && strcmp(REISERFS_SB(s
)->s_qf_names
[qtype
],
1217 reiserfs_warning(s
, "super-6512",
1219 "already specified.",
1223 if (strchr(arg
, '/')) {
1224 reiserfs_warning(s
, "super-6513",
1225 "quotafile must be "
1226 "on filesystem root.");
1229 qf_names
[qtype
] = kstrdup(arg
, GFP_KERNEL
);
1230 if (!qf_names
[qtype
]) {
1231 reiserfs_warning(s
, "reiserfs-2502",
1232 "not enough memory "
1237 if (qtype
== USRQUOTA
)
1238 *mount_options
|= 1 << REISERFS_USRQUOTA
;
1240 *mount_options
|= 1 << REISERFS_GRPQUOTA
;
1242 if (qf_names
[qtype
] !=
1243 REISERFS_SB(s
)->s_qf_names
[qtype
])
1244 kfree(qf_names
[qtype
]);
1245 qf_names
[qtype
] = NULL
;
1246 if (qtype
== USRQUOTA
)
1247 *mount_options
&= ~(1 << REISERFS_USRQUOTA
);
1249 *mount_options
&= ~(1 << REISERFS_GRPQUOTA
);
1253 if (!strcmp(arg
, "vfsold"))
1254 *qfmt
= QFMT_VFS_OLD
;
1255 else if (!strcmp(arg
, "vfsv0"))
1256 *qfmt
= QFMT_VFS_V0
;
1258 reiserfs_warning(s
, "super-6514",
1259 "unknown quota format "
1263 if (sb_any_quota_loaded(s
) &&
1264 *qfmt
!= REISERFS_SB(s
)->s_jquota_fmt
) {
1265 reiserfs_warning(s
, "super-6515",
1266 "cannot change journaled "
1267 "quota options when quota "
1273 if (c
== 'u' || c
== 'g' || c
== 'f') {
1274 reiserfs_warning(s
, "reiserfs-2503", "journaled "
1275 "quota options not supported.");
1282 if (!REISERFS_SB(s
)->s_jquota_fmt
&& !*qfmt
1283 && (qf_names
[USRQUOTA
] || qf_names
[GRPQUOTA
])) {
1284 reiserfs_warning(s
, "super-6515",
1285 "journaled quota format not specified.");
1288 if ((!(*mount_options
& (1 << REISERFS_USRQUOTA
)) &&
1289 sb_has_quota_loaded(s
, USRQUOTA
)) ||
1290 (!(*mount_options
& (1 << REISERFS_GRPQUOTA
)) &&
1291 sb_has_quota_loaded(s
, GRPQUOTA
))) {
1292 reiserfs_warning(s
, "super-6516", "quota options must "
1293 "be present when quota is turned on.");
1301 static void switch_data_mode(struct super_block
*s
, unsigned long mode
)
1303 REISERFS_SB(s
)->s_mount_opt
&= ~((1 << REISERFS_DATA_LOG
) |
1304 (1 << REISERFS_DATA_ORDERED
) |
1305 (1 << REISERFS_DATA_WRITEBACK
));
1306 REISERFS_SB(s
)->s_mount_opt
|= (1 << mode
);
1309 static void handle_data_mode(struct super_block
*s
, unsigned long mount_options
)
1311 if (mount_options
& (1 << REISERFS_DATA_LOG
)) {
1312 if (!reiserfs_data_log(s
)) {
1313 switch_data_mode(s
, REISERFS_DATA_LOG
);
1314 reiserfs_info(s
, "switching to journaled data mode\n");
1316 } else if (mount_options
& (1 << REISERFS_DATA_ORDERED
)) {
1317 if (!reiserfs_data_ordered(s
)) {
1318 switch_data_mode(s
, REISERFS_DATA_ORDERED
);
1319 reiserfs_info(s
, "switching to ordered data mode\n");
1321 } else if (mount_options
& (1 << REISERFS_DATA_WRITEBACK
)) {
1322 if (!reiserfs_data_writeback(s
)) {
1323 switch_data_mode(s
, REISERFS_DATA_WRITEBACK
);
1324 reiserfs_info(s
, "switching to writeback data mode\n");
1329 static void handle_barrier_mode(struct super_block
*s
, unsigned long bits
)
1331 int flush
= (1 << REISERFS_BARRIER_FLUSH
);
1332 int none
= (1 << REISERFS_BARRIER_NONE
);
1333 int all_barrier
= flush
| none
;
1335 if (bits
& all_barrier
) {
1336 REISERFS_SB(s
)->s_mount_opt
&= ~all_barrier
;
1338 REISERFS_SB(s
)->s_mount_opt
|= flush
;
1339 printk("reiserfs: enabling write barrier flush mode\n");
1340 } else if (bits
& none
) {
1341 REISERFS_SB(s
)->s_mount_opt
|= none
;
1342 printk("reiserfs: write barriers turned off\n");
1347 static void handle_attrs(struct super_block
*s
)
1349 struct reiserfs_super_block
*rs
= SB_DISK_SUPER_BLOCK(s
);
1351 if (reiserfs_attrs(s
)) {
1352 if (old_format_only(s
)) {
1353 reiserfs_warning(s
, "super-6517", "cannot support "
1354 "attributes on 3.5.x disk format");
1355 REISERFS_SB(s
)->s_mount_opt
&= ~(1 << REISERFS_ATTRS
);
1358 if (!(le32_to_cpu(rs
->s_flags
) & reiserfs_attrs_cleared
)) {
1359 reiserfs_warning(s
, "super-6518", "cannot support "
1360 "attributes until flag is set in "
1362 REISERFS_SB(s
)->s_mount_opt
&= ~(1 << REISERFS_ATTRS
);
1368 static void handle_quota_files(struct super_block
*s
, char **qf_names
,
1373 for (i
= 0; i
< REISERFS_MAXQUOTAS
; i
++) {
1374 if (qf_names
[i
] != REISERFS_SB(s
)->s_qf_names
[i
])
1375 kfree(REISERFS_SB(s
)->s_qf_names
[i
]);
1376 REISERFS_SB(s
)->s_qf_names
[i
] = qf_names
[i
];
1379 REISERFS_SB(s
)->s_jquota_fmt
= *qfmt
;
1383 static int reiserfs_remount(struct super_block
*s
, int *mount_flags
, char *arg
)
1385 struct reiserfs_super_block
*rs
;
1386 struct reiserfs_transaction_handle th
;
1387 unsigned long blocks
;
1388 unsigned long mount_options
= REISERFS_SB(s
)->s_mount_opt
;
1389 unsigned long safe_mask
= 0;
1390 unsigned int commit_max_age
= (unsigned int)-1;
1391 struct reiserfs_journal
*journal
= SB_JOURNAL(s
);
1392 char *new_opts
= kstrdup(arg
, GFP_KERNEL
);
1394 char *qf_names
[REISERFS_MAXQUOTAS
];
1395 unsigned int qfmt
= 0;
1401 reiserfs_write_lock(s
);
1404 memcpy(qf_names
, REISERFS_SB(s
)->s_qf_names
, sizeof(qf_names
));
1407 rs
= SB_DISK_SUPER_BLOCK(s
);
1409 if (!reiserfs_parse_options
1410 (s
, arg
, &mount_options
, &blocks
, NULL
, &commit_max_age
,
1413 for (i
= 0; i
< REISERFS_MAXQUOTAS
; i
++)
1414 if (qf_names
[i
] != REISERFS_SB(s
)->s_qf_names
[i
])
1418 goto out_err_unlock
;
1421 handle_quota_files(s
, qf_names
, &qfmt
);
1426 /* Add options that are safe here */
1427 safe_mask
|= 1 << REISERFS_SMALLTAIL
;
1428 safe_mask
|= 1 << REISERFS_LARGETAIL
;
1429 safe_mask
|= 1 << REISERFS_NO_BORDER
;
1430 safe_mask
|= 1 << REISERFS_NO_UNHASHED_RELOCATION
;
1431 safe_mask
|= 1 << REISERFS_HASHED_RELOCATION
;
1432 safe_mask
|= 1 << REISERFS_TEST4
;
1433 safe_mask
|= 1 << REISERFS_ATTRS
;
1434 safe_mask
|= 1 << REISERFS_XATTRS_USER
;
1435 safe_mask
|= 1 << REISERFS_POSIXACL
;
1436 safe_mask
|= 1 << REISERFS_BARRIER_FLUSH
;
1437 safe_mask
|= 1 << REISERFS_BARRIER_NONE
;
1438 safe_mask
|= 1 << REISERFS_ERROR_RO
;
1439 safe_mask
|= 1 << REISERFS_ERROR_CONTINUE
;
1440 safe_mask
|= 1 << REISERFS_ERROR_PANIC
;
1441 safe_mask
|= 1 << REISERFS_USRQUOTA
;
1442 safe_mask
|= 1 << REISERFS_GRPQUOTA
;
1445 * Update the bitmask, taking care to keep
1446 * the bits we're not allowed to change here
1448 REISERFS_SB(s
)->s_mount_opt
=
1450 s_mount_opt
& ~safe_mask
) | (mount_options
& safe_mask
);
1452 if (commit_max_age
!= 0 && commit_max_age
!= (unsigned int)-1) {
1453 journal
->j_max_commit_age
= commit_max_age
;
1454 journal
->j_max_trans_age
= commit_max_age
;
1455 } else if (commit_max_age
== 0) {
1456 /* 0 means restore defaults. */
1457 journal
->j_max_commit_age
= journal
->j_default_max_commit_age
;
1458 journal
->j_max_trans_age
= JOURNAL_MAX_TRANS_AGE
;
1462 err
= reiserfs_resize(s
, blocks
);
1464 goto out_err_unlock
;
1467 if (*mount_flags
& MS_RDONLY
) {
1468 reiserfs_write_unlock(s
);
1469 reiserfs_xattr_init(s
, *mount_flags
);
1470 /* remount read-only */
1471 if (s
->s_flags
& MS_RDONLY
)
1472 /* it is read-only already */
1473 goto out_ok_unlocked
;
1475 err
= dquot_suspend(s
, -1);
1479 /* try to remount file system with read-only permissions */
1480 if (sb_umount_state(rs
) == REISERFS_VALID_FS
1481 || REISERFS_SB(s
)->s_mount_state
!= REISERFS_VALID_FS
) {
1482 goto out_ok_unlocked
;
1485 reiserfs_write_lock(s
);
1487 err
= journal_begin(&th
, s
, 10);
1489 goto out_err_unlock
;
1491 /* Mounting a rw partition read-only. */
1492 reiserfs_prepare_for_journal(s
, SB_BUFFER_WITH_SB(s
), 1);
1493 set_sb_umount_state(rs
, REISERFS_SB(s
)->s_mount_state
);
1494 journal_mark_dirty(&th
, SB_BUFFER_WITH_SB(s
));
1496 /* remount read-write */
1497 if (!(s
->s_flags
& MS_RDONLY
)) {
1498 reiserfs_write_unlock(s
);
1499 reiserfs_xattr_init(s
, *mount_flags
);
1500 goto out_ok_unlocked
; /* We are read-write already */
1503 if (reiserfs_is_journal_aborted(journal
)) {
1504 err
= journal
->j_errno
;
1505 goto out_err_unlock
;
1508 handle_data_mode(s
, mount_options
);
1509 handle_barrier_mode(s
, mount_options
);
1510 REISERFS_SB(s
)->s_mount_state
= sb_umount_state(rs
);
1512 /* now it is safe to call journal_begin */
1513 s
->s_flags
&= ~MS_RDONLY
;
1514 err
= journal_begin(&th
, s
, 10);
1516 goto out_err_unlock
;
1518 /* Mount a partition which is read-only, read-write */
1519 reiserfs_prepare_for_journal(s
, SB_BUFFER_WITH_SB(s
), 1);
1520 REISERFS_SB(s
)->s_mount_state
= sb_umount_state(rs
);
1521 s
->s_flags
&= ~MS_RDONLY
;
1522 set_sb_umount_state(rs
, REISERFS_ERROR_FS
);
1523 if (!old_format_only(s
))
1524 set_sb_mnt_count(rs
, sb_mnt_count(rs
) + 1);
1525 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1526 journal_mark_dirty(&th
, SB_BUFFER_WITH_SB(s
));
1527 REISERFS_SB(s
)->s_mount_state
= REISERFS_VALID_FS
;
1529 /* this will force a full flush of all journal lists */
1530 SB_JOURNAL(s
)->j_must_wait
= 1;
1531 err
= journal_end(&th
);
1533 goto out_err_unlock
;
1535 reiserfs_write_unlock(s
);
1536 if (!(*mount_flags
& MS_RDONLY
)) {
1537 dquot_resume(s
, -1);
1538 reiserfs_write_lock(s
);
1539 finish_unfinished(s
);
1540 reiserfs_write_unlock(s
);
1541 reiserfs_xattr_init(s
, *mount_flags
);
1545 replace_mount_options(s
, new_opts
);
1549 reiserfs_write_unlock(s
);
1555 static int read_super_block(struct super_block
*s
, int offset
)
1557 struct buffer_head
*bh
;
1558 struct reiserfs_super_block
*rs
;
1561 bh
= sb_bread(s
, offset
/ s
->s_blocksize
);
1563 reiserfs_warning(s
, "sh-2006",
1564 "bread failed (dev %s, block %lu, size %lu)",
1565 s
->s_id
, offset
/ s
->s_blocksize
,
1570 rs
= (struct reiserfs_super_block
*)bh
->b_data
;
1571 if (!is_any_reiserfs_magic_string(rs
)) {
1576 * ok, reiserfs signature (old or new) found in at the given offset
1578 fs_blocksize
= sb_blocksize(rs
);
1580 sb_set_blocksize(s
, fs_blocksize
);
1582 bh
= sb_bread(s
, offset
/ s
->s_blocksize
);
1584 reiserfs_warning(s
, "sh-2007",
1585 "bread failed (dev %s, block %lu, size %lu)",
1586 s
->s_id
, offset
/ s
->s_blocksize
,
1591 rs
= (struct reiserfs_super_block
*)bh
->b_data
;
1592 if (sb_blocksize(rs
) != s
->s_blocksize
) {
1593 reiserfs_warning(s
, "sh-2011", "can't find a reiserfs "
1594 "filesystem on (dev %s, block %llu, size %lu)",
1596 (unsigned long long)bh
->b_blocknr
,
1602 if (rs
->s_v1
.s_root_block
== cpu_to_le32(-1)) {
1604 reiserfs_warning(s
, "super-6519", "Unfinished reiserfsck "
1605 "--rebuild-tree run detected. Please run\n"
1606 "reiserfsck --rebuild-tree and wait for a "
1607 "completion. If that fails\n"
1608 "get newer reiserfsprogs package");
1612 SB_BUFFER_WITH_SB(s
) = bh
;
1613 SB_DISK_SUPER_BLOCK(s
) = rs
;
1616 * magic is of non-standard journal filesystem, look at s_version to
1617 * find which format is in use
1619 if (is_reiserfs_jr(rs
)) {
1620 if (sb_version(rs
) == REISERFS_VERSION_2
)
1621 reiserfs_info(s
, "found reiserfs format \"3.6\""
1622 " with non-standard journal\n");
1623 else if (sb_version(rs
) == REISERFS_VERSION_1
)
1624 reiserfs_info(s
, "found reiserfs format \"3.5\""
1625 " with non-standard journal\n");
1627 reiserfs_warning(s
, "sh-2012", "found unknown "
1628 "format \"%u\" of reiserfs with "
1629 "non-standard magic", sb_version(rs
));
1634 * s_version of standard format may contain incorrect
1635 * information, so we just look at the magic string
1638 "found reiserfs format \"%s\" with standard journal\n",
1639 is_reiserfs_3_5(rs
) ? "3.5" : "3.6");
1641 s
->s_op
= &reiserfs_sops
;
1642 s
->s_export_op
= &reiserfs_export_ops
;
1644 s
->s_qcop
= &reiserfs_qctl_operations
;
1645 s
->dq_op
= &reiserfs_quota_operations
;
1646 s
->s_quota_types
= QTYPE_MASK_USR
| QTYPE_MASK_GRP
;
1650 * new format is limited by the 32 bit wide i_blocks field, want to
1651 * be one full block below that.
1653 s
->s_maxbytes
= (512LL << 32) - s
->s_blocksize
;
1657 /* after journal replay, reread all bitmap and super blocks */
1658 static int reread_meta_blocks(struct super_block
*s
)
1660 ll_rw_block(READ
, 1, &SB_BUFFER_WITH_SB(s
));
1661 wait_on_buffer(SB_BUFFER_WITH_SB(s
));
1662 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s
))) {
1663 reiserfs_warning(s
, "reiserfs-2504", "error reading the super");
1670 /* hash detection stuff */
1673 * if root directory is empty - we set default - Yura's - hash and
1675 * FIXME: we look for only one name in a directory. If tea and yura
1676 * both have the same value - we ask user to send report to the
1679 static __u32
find_hash_out(struct super_block
*s
)
1682 struct inode
*inode
;
1684 INITIALIZE_PATH(path
);
1685 struct reiserfs_dir_entry de
;
1686 struct reiserfs_de_head
*deh
;
1687 __u32 hash
= DEFAULT_HASH
;
1688 __u32 deh_hashval
, teahash
, r5hash
, yurahash
;
1690 inode
= d_inode(s
->s_root
);
1692 make_cpu_key(&key
, inode
, ~0, TYPE_DIRENTRY
, 3);
1693 retval
= search_by_entry_key(s
, &key
, &path
, &de
);
1694 if (retval
== IO_ERROR
) {
1698 if (retval
== NAME_NOT_FOUND
)
1701 set_de_name_and_namelen(&de
);
1702 deh
= de
.de_deh
+ de
.de_entry_num
;
1704 if (deh_offset(deh
) == DOT_DOT_OFFSET
) {
1705 /* allow override in this case */
1706 if (reiserfs_rupasov_hash(s
))
1708 reiserfs_info(s
, "FS seems to be empty, autodetect is using the default hash\n");
1712 deh_hashval
= GET_HASH_VALUE(deh_offset(deh
));
1713 r5hash
= GET_HASH_VALUE(r5_hash(de
.de_name
, de
.de_namelen
));
1714 teahash
= GET_HASH_VALUE(keyed_hash(de
.de_name
, de
.de_namelen
));
1715 yurahash
= GET_HASH_VALUE(yura_hash(de
.de_name
, de
.de_namelen
));
1717 if ((teahash
== r5hash
&& deh_hashval
== r5hash
) ||
1718 (teahash
== yurahash
&& deh_hashval
== yurahash
) ||
1719 (r5hash
== yurahash
&& deh_hashval
== yurahash
)) {
1720 reiserfs_warning(s
, "reiserfs-2506",
1721 "Unable to automatically detect hash "
1722 "function. Please mount with -o "
1723 "hash={tea,rupasov,r5}");
1728 if (deh_hashval
== yurahash
)
1730 else if (deh_hashval
== teahash
)
1732 else if (deh_hashval
== r5hash
)
1735 reiserfs_warning(s
, "reiserfs-2506",
1736 "Unrecognised hash function");
1744 /* finds out which hash names are sorted with */
1745 static int what_hash(struct super_block
*s
)
1749 code
= sb_hash_function_code(SB_DISK_SUPER_BLOCK(s
));
1752 * reiserfs_hash_detect() == true if any of the hash mount options
1753 * were used. We must check them to make sure the user isn't
1754 * using a bad hash value
1756 if (code
== UNSET_HASH
|| reiserfs_hash_detect(s
))
1757 code
= find_hash_out(s
);
1759 if (code
!= UNSET_HASH
&& reiserfs_hash_detect(s
)) {
1761 * detection has found the hash, and we must check against the
1764 if (reiserfs_rupasov_hash(s
) && code
!= YURA_HASH
) {
1765 reiserfs_warning(s
, "reiserfs-2507",
1766 "Error, %s hash detected, "
1767 "unable to force rupasov hash",
1768 reiserfs_hashname(code
));
1770 } else if (reiserfs_tea_hash(s
) && code
!= TEA_HASH
) {
1771 reiserfs_warning(s
, "reiserfs-2508",
1772 "Error, %s hash detected, "
1773 "unable to force tea hash",
1774 reiserfs_hashname(code
));
1776 } else if (reiserfs_r5_hash(s
) && code
!= R5_HASH
) {
1777 reiserfs_warning(s
, "reiserfs-2509",
1778 "Error, %s hash detected, "
1779 "unable to force r5 hash",
1780 reiserfs_hashname(code
));
1785 * find_hash_out was not called or
1786 * could not determine the hash
1788 if (reiserfs_rupasov_hash(s
)) {
1790 } else if (reiserfs_tea_hash(s
)) {
1792 } else if (reiserfs_r5_hash(s
)) {
1798 * if we are mounted RW, and we have a new valid hash code, update
1801 if (code
!= UNSET_HASH
&&
1802 !(s
->s_flags
& MS_RDONLY
) &&
1803 code
!= sb_hash_function_code(SB_DISK_SUPER_BLOCK(s
))) {
1804 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s
), code
);
1809 /* return pointer to appropriate function */
1810 static hashf_t
hash_function(struct super_block
*s
)
1812 switch (what_hash(s
)) {
1814 reiserfs_info(s
, "Using tea hash to sort names\n");
1817 reiserfs_info(s
, "Using rupasov hash to sort names\n");
1820 reiserfs_info(s
, "Using r5 hash to sort names\n");
1826 /* this is used to set up correct value for old partitions */
1827 static int function2code(hashf_t func
)
1829 if (func
== keyed_hash
)
1831 if (func
== yura_hash
)
1833 if (func
== r5_hash
)
1836 BUG(); /* should never happen */
1841 #define SWARN(silent, s, id, ...) \
1843 reiserfs_warning(s, id, __VA_ARGS__)
1845 static int reiserfs_fill_super(struct super_block
*s
, void *data
, int silent
)
1847 struct inode
*root_inode
;
1848 struct reiserfs_transaction_handle th
;
1850 unsigned long blocks
;
1851 unsigned int commit_max_age
= 0;
1853 struct reiserfs_iget_args args
;
1854 struct reiserfs_super_block
*rs
;
1856 struct reiserfs_sb_info
*sbi
;
1857 int errval
= -EINVAL
;
1858 char *qf_names
[REISERFS_MAXQUOTAS
] = {};
1859 unsigned int qfmt
= 0;
1861 save_mount_options(s
, data
);
1863 sbi
= kzalloc(sizeof(struct reiserfs_sb_info
), GFP_KERNEL
);
1867 /* Set default values for options: non-aggressive tails, RO on errors */
1868 sbi
->s_mount_opt
|= (1 << REISERFS_SMALLTAIL
);
1869 sbi
->s_mount_opt
|= (1 << REISERFS_ERROR_RO
);
1870 sbi
->s_mount_opt
|= (1 << REISERFS_BARRIER_FLUSH
);
1871 /* no preallocation minimum, be smart in reiserfs_file_write instead */
1872 sbi
->s_alloc_options
.preallocmin
= 0;
1873 /* Preallocate by 16 blocks (17-1) at once */
1874 sbi
->s_alloc_options
.preallocsize
= 17;
1875 /* setup default block allocator options */
1876 reiserfs_init_alloc_options(s
);
1878 spin_lock_init(&sbi
->old_work_lock
);
1879 INIT_DELAYED_WORK(&sbi
->old_work
, flush_old_commits
);
1880 mutex_init(&sbi
->lock
);
1881 sbi
->lock_depth
= -1;
1883 sbi
->commit_wq
= alloc_workqueue("reiserfs/%s", WQ_MEM_RECLAIM
, 0,
1885 if (!sbi
->commit_wq
) {
1886 SWARN(silent
, s
, "", "Cannot allocate commit workqueue");
1888 goto error_unlocked
;
1892 if (reiserfs_parse_options
1893 (s
, (char *)data
, &sbi
->s_mount_opt
, &blocks
, &jdev_name
,
1894 &commit_max_age
, qf_names
, &qfmt
) == 0) {
1895 goto error_unlocked
;
1897 if (jdev_name
&& jdev_name
[0]) {
1898 sbi
->s_jdev
= kstrdup(jdev_name
, GFP_KERNEL
);
1900 SWARN(silent
, s
, "", "Cannot allocate memory for "
1901 "journal device name");
1906 handle_quota_files(s
, qf_names
, &qfmt
);
1910 SWARN(silent
, s
, "jmacd-7", "resize option for remount only");
1911 goto error_unlocked
;
1915 * try old format (undistributed bitmap, super block in 8-th 1k
1916 * block of a device)
1918 if (!read_super_block(s
, REISERFS_OLD_DISK_OFFSET_IN_BYTES
))
1922 * try new format (64-th 1k block), which can contain reiserfs
1925 else if (read_super_block(s
, REISERFS_DISK_OFFSET_IN_BYTES
)) {
1926 SWARN(silent
, s
, "sh-2021", "can not find reiserfs on %s",
1928 goto error_unlocked
;
1931 rs
= SB_DISK_SUPER_BLOCK(s
);
1933 * Let's do basic sanity check to verify that underlying device is not
1934 * smaller than the filesystem. If the check fails then abort and
1935 * scream, because bad stuff will happen otherwise.
1937 if (s
->s_bdev
&& s
->s_bdev
->bd_inode
1938 && i_size_read(s
->s_bdev
->bd_inode
) <
1939 sb_block_count(rs
) * sb_blocksize(rs
)) {
1940 SWARN(silent
, s
, "", "Filesystem cannot be "
1941 "mounted because it is bigger than the device");
1942 SWARN(silent
, s
, "", "You may need to run fsck "
1943 "or increase size of your LVM partition");
1944 SWARN(silent
, s
, "", "Or may be you forgot to "
1945 "reboot after fdisk when it told you to");
1946 goto error_unlocked
;
1949 sbi
->s_mount_state
= SB_REISERFS_STATE(s
);
1950 sbi
->s_mount_state
= REISERFS_VALID_FS
;
1952 if ((errval
= reiserfs_init_bitmap_cache(s
))) {
1953 SWARN(silent
, s
, "jmacd-8", "unable to read bitmap");
1954 goto error_unlocked
;
1958 #ifdef CONFIG_REISERFS_CHECK
1959 SWARN(silent
, s
, "", "CONFIG_REISERFS_CHECK is set ON");
1960 SWARN(silent
, s
, "", "- it is slow mode for debugging.");
1963 /* make data=ordered the default */
1964 if (!reiserfs_data_log(s
) && !reiserfs_data_ordered(s
) &&
1965 !reiserfs_data_writeback(s
)) {
1966 sbi
->s_mount_opt
|= (1 << REISERFS_DATA_ORDERED
);
1969 if (reiserfs_data_log(s
)) {
1970 reiserfs_info(s
, "using journaled data mode\n");
1971 } else if (reiserfs_data_ordered(s
)) {
1972 reiserfs_info(s
, "using ordered data mode\n");
1974 reiserfs_info(s
, "using writeback data mode\n");
1976 if (reiserfs_barrier_flush(s
)) {
1977 printk("reiserfs: using flush barriers\n");
1980 if (journal_init(s
, jdev_name
, old_format
, commit_max_age
)) {
1981 SWARN(silent
, s
, "sh-2022",
1982 "unable to initialize journal space");
1983 goto error_unlocked
;
1986 * once this is set, journal_release must be called
1987 * if we error out of the mount
1992 if (reread_meta_blocks(s
)) {
1993 SWARN(silent
, s
, "jmacd-9",
1994 "unable to reread meta blocks after journal init");
1995 goto error_unlocked
;
1999 goto error_unlocked
;
2001 if (bdev_read_only(s
->s_bdev
) && !(s
->s_flags
& MS_RDONLY
)) {
2002 SWARN(silent
, s
, "clm-7000",
2003 "Detected readonly device, marking FS readonly");
2004 s
->s_flags
|= MS_RDONLY
;
2006 args
.objectid
= REISERFS_ROOT_OBJECTID
;
2007 args
.dirid
= REISERFS_ROOT_PARENT_OBJECTID
;
2009 iget5_locked(s
, REISERFS_ROOT_OBJECTID
, reiserfs_find_actor
,
2010 reiserfs_init_locked_inode
, (void *)&args
);
2012 SWARN(silent
, s
, "jmacd-10", "get root inode failed");
2013 goto error_unlocked
;
2017 * This path assumed to be called with the BKL in the old times.
2018 * Now we have inherited the big reiserfs lock from it and many
2019 * reiserfs helpers called in the mount path and elsewhere require
2020 * this lock to be held even if it's not always necessary. Let's be
2021 * conservative and hold it early. The window can be reduced after
2022 * careful review of the code.
2024 reiserfs_write_lock(s
);
2026 if (root_inode
->i_state
& I_NEW
) {
2027 reiserfs_read_locked_inode(root_inode
, &args
);
2028 unlock_new_inode(root_inode
);
2031 s
->s_root
= d_make_root(root_inode
);
2034 /* define and initialize hash function */
2035 sbi
->s_hash_function
= hash_function(s
);
2036 if (sbi
->s_hash_function
== NULL
) {
2042 if (is_reiserfs_3_5(rs
)
2043 || (is_reiserfs_jr(rs
) && SB_VERSION(s
) == REISERFS_VERSION_1
))
2044 set_bit(REISERFS_3_5
, &sbi
->s_properties
);
2045 else if (old_format
)
2046 set_bit(REISERFS_OLD_FORMAT
, &sbi
->s_properties
);
2048 set_bit(REISERFS_3_6
, &sbi
->s_properties
);
2050 if (!(s
->s_flags
& MS_RDONLY
)) {
2052 errval
= journal_begin(&th
, s
, 1);
2058 reiserfs_prepare_for_journal(s
, SB_BUFFER_WITH_SB(s
), 1);
2060 set_sb_umount_state(rs
, REISERFS_ERROR_FS
);
2061 set_sb_fs_state(rs
, 0);
2064 * Clear out s_bmap_nr if it would wrap. We can handle this
2065 * case, but older revisions can't. This will cause the
2066 * file system to fail mount on those older implementations,
2067 * avoiding corruption. -jeffm
2069 if (bmap_would_wrap(reiserfs_bmap_count(s
)) &&
2070 sb_bmap_nr(rs
) != 0) {
2071 reiserfs_warning(s
, "super-2030", "This file system "
2072 "claims to use %u bitmap blocks in "
2073 "its super block, but requires %u. "
2074 "Clearing to zero.", sb_bmap_nr(rs
),
2075 reiserfs_bmap_count(s
));
2077 set_sb_bmap_nr(rs
, 0);
2080 if (old_format_only(s
)) {
2082 * filesystem of format 3.5 either with standard
2083 * or non-standard journal
2085 if (convert_reiserfs(s
)) {
2086 /* and -o conv is given */
2089 "converting 3.5 filesystem to the 3.6 format");
2091 if (is_reiserfs_3_5(rs
))
2093 * put magic string of 3.6 format.
2094 * 2.2 will not be able to
2095 * mount this filesystem anymore
2097 memcpy(rs
->s_v1
.s_magic
,
2098 reiserfs_3_6_magic_string
,
2100 (reiserfs_3_6_magic_string
));
2102 set_sb_version(rs
, REISERFS_VERSION_2
);
2103 reiserfs_convert_objectid_map_v1(s
);
2104 set_bit(REISERFS_3_6
, &sbi
->s_properties
);
2105 clear_bit(REISERFS_3_5
, &sbi
->s_properties
);
2106 } else if (!silent
) {
2107 reiserfs_info(s
, "using 3.5.x disk format\n");
2110 set_sb_mnt_count(rs
, sb_mnt_count(rs
) + 1);
2113 journal_mark_dirty(&th
, SB_BUFFER_WITH_SB(s
));
2114 errval
= journal_end(&th
);
2121 reiserfs_write_unlock(s
);
2122 if ((errval
= reiserfs_lookup_privroot(s
)) ||
2123 (errval
= reiserfs_xattr_init(s
, s
->s_flags
))) {
2126 goto error_unlocked
;
2128 reiserfs_write_lock(s
);
2131 * look for files which were to be removed in previous session
2133 finish_unfinished(s
);
2135 if (old_format_only(s
) && !silent
) {
2136 reiserfs_info(s
, "using 3.5.x disk format\n");
2139 reiserfs_write_unlock(s
);
2140 if ((errval
= reiserfs_lookup_privroot(s
)) ||
2141 (errval
= reiserfs_xattr_init(s
, s
->s_flags
))) {
2144 goto error_unlocked
;
2146 reiserfs_write_lock(s
);
2149 * mark hash in super block: it could be unset. overwrite should be ok
2151 set_sb_hash_function_code(rs
, function2code(sbi
->s_hash_function
));
2155 reiserfs_proc_info_init(s
);
2157 init_waitqueue_head(&(sbi
->s_wait
));
2158 spin_lock_init(&sbi
->bitmap_lock
);
2160 reiserfs_write_unlock(s
);
2165 reiserfs_write_unlock(s
);
2168 /* kill the commit thread, free journal ram */
2170 reiserfs_write_lock(s
);
2171 journal_release_error(NULL
, s
);
2172 reiserfs_write_unlock(s
);
2176 destroy_workqueue(sbi
->commit_wq
);
2178 cancel_delayed_work_sync(&REISERFS_SB(s
)->old_work
);
2180 reiserfs_free_bitmap_cache(s
);
2181 if (SB_BUFFER_WITH_SB(s
))
2182 brelse(SB_BUFFER_WITH_SB(s
));
2186 for (j
= 0; j
< REISERFS_MAXQUOTAS
; j
++)
2192 s
->s_fs_info
= NULL
;
2196 static int reiserfs_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
2198 struct reiserfs_super_block
*rs
= SB_DISK_SUPER_BLOCK(dentry
->d_sb
);
2200 buf
->f_namelen
= (REISERFS_MAX_NAME(s
->s_blocksize
));
2201 buf
->f_bfree
= sb_free_blocks(rs
);
2202 buf
->f_bavail
= buf
->f_bfree
;
2203 buf
->f_blocks
= sb_block_count(rs
) - sb_bmap_nr(rs
) - 1;
2204 buf
->f_bsize
= dentry
->d_sb
->s_blocksize
;
2205 /* changed to accommodate gcc folks. */
2206 buf
->f_type
= REISERFS_SUPER_MAGIC
;
2207 buf
->f_fsid
.val
[0] = (u32
)crc32_le(0, rs
->s_uuid
, sizeof(rs
->s_uuid
)/2);
2208 buf
->f_fsid
.val
[1] = (u32
)crc32_le(0, rs
->s_uuid
+ sizeof(rs
->s_uuid
)/2,
2209 sizeof(rs
->s_uuid
)/2);
2215 static int reiserfs_write_dquot(struct dquot
*dquot
)
2217 struct reiserfs_transaction_handle th
;
2221 reiserfs_write_lock(dquot
->dq_sb
);
2223 journal_begin(&th
, dquot
->dq_sb
,
2224 REISERFS_QUOTA_TRANS_BLOCKS(dquot
->dq_sb
));
2227 depth
= reiserfs_write_unlock_nested(dquot
->dq_sb
);
2228 ret
= dquot_commit(dquot
);
2229 reiserfs_write_lock_nested(dquot
->dq_sb
, depth
);
2230 err
= journal_end(&th
);
2234 reiserfs_write_unlock(dquot
->dq_sb
);
2238 static int reiserfs_acquire_dquot(struct dquot
*dquot
)
2240 struct reiserfs_transaction_handle th
;
2244 reiserfs_write_lock(dquot
->dq_sb
);
2246 journal_begin(&th
, dquot
->dq_sb
,
2247 REISERFS_QUOTA_INIT_BLOCKS(dquot
->dq_sb
));
2250 depth
= reiserfs_write_unlock_nested(dquot
->dq_sb
);
2251 ret
= dquot_acquire(dquot
);
2252 reiserfs_write_lock_nested(dquot
->dq_sb
, depth
);
2253 err
= journal_end(&th
);
2257 reiserfs_write_unlock(dquot
->dq_sb
);
2261 static int reiserfs_release_dquot(struct dquot
*dquot
)
2263 struct reiserfs_transaction_handle th
;
2266 reiserfs_write_lock(dquot
->dq_sb
);
2268 journal_begin(&th
, dquot
->dq_sb
,
2269 REISERFS_QUOTA_DEL_BLOCKS(dquot
->dq_sb
));
2270 reiserfs_write_unlock(dquot
->dq_sb
);
2272 /* Release dquot anyway to avoid endless cycle in dqput() */
2273 dquot_release(dquot
);
2276 ret
= dquot_release(dquot
);
2277 reiserfs_write_lock(dquot
->dq_sb
);
2278 err
= journal_end(&th
);
2281 reiserfs_write_unlock(dquot
->dq_sb
);
2286 static int reiserfs_mark_dquot_dirty(struct dquot
*dquot
)
2288 /* Are we journaling quotas? */
2289 if (REISERFS_SB(dquot
->dq_sb
)->s_qf_names
[USRQUOTA
] ||
2290 REISERFS_SB(dquot
->dq_sb
)->s_qf_names
[GRPQUOTA
]) {
2291 dquot_mark_dquot_dirty(dquot
);
2292 return reiserfs_write_dquot(dquot
);
2294 return dquot_mark_dquot_dirty(dquot
);
2297 static int reiserfs_write_info(struct super_block
*sb
, int type
)
2299 struct reiserfs_transaction_handle th
;
2303 /* Data block + inode block */
2304 reiserfs_write_lock(sb
);
2305 ret
= journal_begin(&th
, sb
, 2);
2308 depth
= reiserfs_write_unlock_nested(sb
);
2309 ret
= dquot_commit_info(sb
, type
);
2310 reiserfs_write_lock_nested(sb
, depth
);
2311 err
= journal_end(&th
);
2315 reiserfs_write_unlock(sb
);
2320 * Turn on quotas during mount time - we need to find the quota file and such...
2322 static int reiserfs_quota_on_mount(struct super_block
*sb
, int type
)
2324 return dquot_quota_on_mount(sb
, REISERFS_SB(sb
)->s_qf_names
[type
],
2325 REISERFS_SB(sb
)->s_jquota_fmt
, type
);
2329 * Standard function to be called on quota_on
2331 static int reiserfs_quota_on(struct super_block
*sb
, int type
, int format_id
,
2335 struct inode
*inode
;
2336 struct reiserfs_transaction_handle th
;
2337 int opt
= type
== USRQUOTA
? REISERFS_USRQUOTA
: REISERFS_GRPQUOTA
;
2339 reiserfs_write_lock(sb
);
2340 if (!(REISERFS_SB(sb
)->s_mount_opt
& (1 << opt
))) {
2345 /* Quotafile not on the same filesystem? */
2346 if (path
->dentry
->d_sb
!= sb
) {
2350 inode
= d_inode(path
->dentry
);
2352 * We must not pack tails for quota files on reiserfs for quota
2355 if (!(REISERFS_I(inode
)->i_flags
& i_nopack_mask
)) {
2356 err
= reiserfs_unpack(inode
, NULL
);
2358 reiserfs_warning(sb
, "super-6520",
2359 "Unpacking tail of quota file failed"
2360 " (%d). Cannot turn on quotas.", err
);
2364 mark_inode_dirty(inode
);
2366 /* Journaling quota? */
2367 if (REISERFS_SB(sb
)->s_qf_names
[type
]) {
2368 /* Quotafile not of fs root? */
2369 if (path
->dentry
->d_parent
!= sb
->s_root
)
2370 reiserfs_warning(sb
, "super-6521",
2371 "Quota file not on filesystem root. "
2372 "Journalled quota will not work.");
2376 * When we journal data on quota file, we have to flush journal to see
2377 * all updates to the file when we bypass pagecache...
2379 if (reiserfs_file_data_log(inode
)) {
2380 /* Just start temporary transaction and finish it */
2381 err
= journal_begin(&th
, sb
, 1);
2384 err
= journal_end_sync(&th
);
2388 reiserfs_write_unlock(sb
);
2389 return dquot_quota_on(sb
, type
, format_id
, path
);
2391 reiserfs_write_unlock(sb
);
2396 * Read data from quotafile - avoid pagecache and such because we cannot afford
2397 * acquiring the locks... As quota files are never truncated and quota code
2398 * itself serializes the operations (and no one else should touch the files)
2399 * we don't have to be afraid of races
2401 static ssize_t
reiserfs_quota_read(struct super_block
*sb
, int type
, char *data
,
2402 size_t len
, loff_t off
)
2404 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
2405 unsigned long blk
= off
>> sb
->s_blocksize_bits
;
2406 int err
= 0, offset
= off
& (sb
->s_blocksize
- 1), tocopy
;
2408 struct buffer_head tmp_bh
, *bh
;
2409 loff_t i_size
= i_size_read(inode
);
2413 if (off
+ len
> i_size
)
2416 while (toread
> 0) {
2418 sb
->s_blocksize
- offset
<
2419 toread
? sb
->s_blocksize
- offset
: toread
;
2422 * Quota files are without tails so we can safely
2425 reiserfs_write_lock(sb
);
2426 err
= reiserfs_get_block(inode
, blk
, &tmp_bh
, 0);
2427 reiserfs_write_unlock(sb
);
2430 if (!buffer_mapped(&tmp_bh
)) /* A hole? */
2431 memset(data
, 0, tocopy
);
2433 bh
= sb_bread(sb
, tmp_bh
.b_blocknr
);
2436 memcpy(data
, bh
->b_data
+ offset
, tocopy
);
2448 * Write to quotafile (we know the transaction is already started and has
2451 static ssize_t
reiserfs_quota_write(struct super_block
*sb
, int type
,
2452 const char *data
, size_t len
, loff_t off
)
2454 struct inode
*inode
= sb_dqopt(sb
)->files
[type
];
2455 unsigned long blk
= off
>> sb
->s_blocksize_bits
;
2456 int err
= 0, offset
= off
& (sb
->s_blocksize
- 1), tocopy
;
2457 int journal_quota
= REISERFS_SB(sb
)->s_qf_names
[type
] != NULL
;
2458 size_t towrite
= len
;
2459 struct buffer_head tmp_bh
, *bh
;
2461 if (!current
->journal_info
) {
2462 printk(KERN_WARNING
"reiserfs: Quota write (off=%llu, len=%llu) cancelled because transaction is not started.\n",
2463 (unsigned long long)off
, (unsigned long long)len
);
2466 while (towrite
> 0) {
2467 tocopy
= sb
->s_blocksize
- offset
< towrite
?
2468 sb
->s_blocksize
- offset
: towrite
;
2470 reiserfs_write_lock(sb
);
2471 err
= reiserfs_get_block(inode
, blk
, &tmp_bh
, GET_BLOCK_CREATE
);
2472 reiserfs_write_unlock(sb
);
2475 if (offset
|| tocopy
!= sb
->s_blocksize
)
2476 bh
= sb_bread(sb
, tmp_bh
.b_blocknr
);
2478 bh
= sb_getblk(sb
, tmp_bh
.b_blocknr
);
2484 memcpy(bh
->b_data
+ offset
, data
, tocopy
);
2485 flush_dcache_page(bh
->b_page
);
2486 set_buffer_uptodate(bh
);
2488 reiserfs_write_lock(sb
);
2489 reiserfs_prepare_for_journal(sb
, bh
, 1);
2490 journal_mark_dirty(current
->journal_info
, bh
);
2492 reiserfs_add_ordered_list(inode
, bh
);
2493 reiserfs_write_unlock(sb
);
2503 if (inode
->i_size
< off
+ len
- towrite
)
2504 i_size_write(inode
, off
+ len
- towrite
);
2506 inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
2507 mark_inode_dirty(inode
);
2508 return len
- towrite
;
2513 static struct dentry
*get_super_block(struct file_system_type
*fs_type
,
2514 int flags
, const char *dev_name
,
2517 return mount_bdev(fs_type
, flags
, dev_name
, data
, reiserfs_fill_super
);
2520 static int __init
init_reiserfs_fs(void)
2524 ret
= init_inodecache();
2528 reiserfs_proc_info_global_init();
2530 ret
= register_filesystem(&reiserfs_fs_type
);
2536 reiserfs_proc_info_global_done();
2537 destroy_inodecache();
2542 static void __exit
exit_reiserfs_fs(void)
2544 reiserfs_proc_info_global_done();
2545 unregister_filesystem(&reiserfs_fs_type
);
2546 destroy_inodecache();
2549 struct file_system_type reiserfs_fs_type
= {
2550 .owner
= THIS_MODULE
,
2552 .mount
= get_super_block
,
2553 .kill_sb
= reiserfs_kill_sb
,
2554 .fs_flags
= FS_REQUIRES_DEV
,
2556 MODULE_ALIAS_FS("reiserfs");
2558 MODULE_DESCRIPTION("ReiserFS journaled filesystem");
2559 MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
2560 MODULE_LICENSE("GPL");
2562 module_init(init_reiserfs_fs
);
2563 module_exit(exit_reiserfs_fs
);