1 /* Copyright by Hans Reiser, 2003 */
5 #include "plugin/plugin_set.h"
7 #include <linux/swap.h>
10 * init_fs_info - allocate reiser4 specific super block
11 * @super: super block of filesystem
13 * Allocates and initialize reiser4_super_info_data, attaches it to
14 * super->s_fs_info, initializes structures maintaining d_cursor-s.
16 int reiser4_init_fs_info(struct super_block
*super
)
18 reiser4_super_info_data
*sbinfo
;
20 sbinfo
= kzalloc(sizeof(reiser4_super_info_data
),
21 reiser4_ctx_gfp_mask_get());
23 return RETERR(-ENOMEM
);
25 super
->s_fs_info
= sbinfo
;
28 ON_DEBUG(INIT_LIST_HEAD(&sbinfo
->all_jnodes
));
29 ON_DEBUG(spin_lock_init(&sbinfo
->all_guard
));
31 mutex_init(&sbinfo
->delete_mutex
);
32 spin_lock_init(&(sbinfo
->guard
));
34 /* initialize per-super-block d_cursor resources */
35 reiser4_init_super_d_info(super
);
41 * reiser4_done_fs_info - free reiser4 specific super block
42 * @super: super block of filesystem
44 * Performs some sanity checks, releases structures maintaining d_cursor-s,
45 * frees reiser4_super_info_data.
47 void reiser4_done_fs_info(struct super_block
*super
)
49 assert("zam-990", super
->s_fs_info
!= NULL
);
51 /* release per-super-block d_cursor resources */
52 reiser4_done_super_d_info(super
);
54 /* make sure that there are not jnodes already */
55 assert("", list_empty(&get_super_private(super
)->all_jnodes
));
56 assert("", get_current_context()->trans
->atom
== NULL
);
57 reiser4_check_block_counters(super
);
58 kfree(super
->s_fs_info
);
59 super
->s_fs_info
= NULL
;
62 /* type of option parseable by parse_option() */
64 /* value of option is arbitrary string */
68 * option specifies bit in a bitmask. When option is set - bit in
69 * sbinfo->fs_flags is set. Examples are bsdgroups, 32bittimes, mtflush,
70 * dont_load_bitmap, atomic_write.
75 * value of option should conform to sprintf() format. Examples are
76 * tmgr.atom_max_size=N, tmgr.atom_max_age=N
81 * option can take one of predefined values. Example is onerror=panic or
88 struct opt_bitmask_bit
{
94 /* description of option parseable by parse_option() */
98 parsed portion of string has a form "name=value".
104 /* where to store value of string option (type == OPT_STRING) */
106 /* description of bits for bit option (type == OPT_BIT) */
111 /* description of format and targets for format option (type
123 const char *list
[10];
128 /* struct opt_bitmask_bit *bits; */
134 * parse_option - parse one option
135 * @opt_strin: starting point of parsing
136 * @opt: option description
140 * | | +-- replaced to '\0'
143 * Figures out option type and handles option correspondingly.
145 static int parse_option(char *opt_string
, struct opt_desc
*opt
)
151 /* NOTE-NIKITA think about using lib/cmdline.c functions here. */
153 val_start
= strchr(opt_string
, '=');
154 if (val_start
!= NULL
) {
163 if (val_start
== NULL
) {
164 err_msg
= "String arg missing";
165 result
= RETERR(-EINVAL
);
167 *opt
->u
.string
= val_start
;
170 if (val_start
!= NULL
)
171 err_msg
= "Value ignored";
173 set_bit(opt
->u
.bit
.nr
, opt
->u
.bit
.addr
);
176 if (val_start
== NULL
) {
177 err_msg
= "Formatted arg missing";
178 result
= RETERR(-EINVAL
);
181 if (sscanf(val_start
, opt
->u
.f
.format
,
182 opt
->u
.f
.arg1
, opt
->u
.f
.arg2
, opt
->u
.f
.arg3
,
183 opt
->u
.f
.arg4
) != opt
->u
.f
.nr_args
) {
184 err_msg
= "Wrong conversion";
185 result
= RETERR(-EINVAL
);
192 if (val_start
== NULL
) {
193 err_msg
= "Value is missing";
194 result
= RETERR(-EINVAL
);
197 err_msg
= "Wrong option value";
198 result
= RETERR(-EINVAL
);
199 while (opt
->u
.oneof
.list
[i
]) {
200 if (!strcmp(opt
->u
.oneof
.list
[i
], val_start
)) {
203 *opt
->u
.oneof
.result
= i
;
211 wrong_return_value("nikita-2100", "opt -> type");
214 if (err_msg
!= NULL
) {
215 warning("nikita-2496", "%s when parsing option \"%s%s%s\"",
216 err_msg
, opt
->name
, val_start
? "=" : "",
223 * parse_options - parse reiser4 mount options
224 * @opt_string: starting point
225 * @opts: array of option description
226 * @nr_opts: number of elements in @opts
228 * Parses comma separated list of reiser4 mount options.
230 static int parse_options(char *opt_string
, struct opt_desc
*opts
, int nr_opts
)
235 while ((result
== 0) && opt_string
&& *opt_string
) {
239 next
= strchr(opt_string
, ',');
244 for (j
= 0; j
< nr_opts
; ++j
) {
245 if (!strncmp(opt_string
, opts
[j
].name
,
246 strlen(opts
[j
].name
))) {
247 result
= parse_option(opt_string
, &opts
[j
]);
252 warning("nikita-2307", "Unrecognized option: \"%s\"",
254 /* traditionally, -EINVAL is returned on wrong mount
256 result
= RETERR(-EINVAL
);
263 #define NUM_OPT(label, fmt, addr) \
266 .type = OPT_FORMAT, \
279 #define SB_FIELD_OPT(field, fmt) NUM_OPT(#field, fmt, &sbinfo->field)
281 #define BIT_OPT(label, bitnr) \
288 .addr = &sbinfo->fs_flags \
293 #define MAX_NR_OPTIONS (30)
296 # define OPT_ARRAY_CHECK(opt, array) \
297 if ((opt) > (array) + MAX_NR_OPTIONS) { \
298 warning("zam-1046", "opt array is overloaded"); break; \
301 # define OPT_ARRAY_CHECK(opt, array) noop
304 #define PUSH_OPT(opt, array, ...) \
306 struct opt_desc o = __VA_ARGS__; \
307 OPT_ARRAY_CHECK(opt, array); \
311 static noinline
void push_sb_field_opts(struct opt_desc
**p
,
312 struct opt_desc
*opts
,
313 reiser4_super_info_data
*sbinfo
)
315 #define PUSH_SB_FIELD_OPT(field, format) \
316 PUSH_OPT(*p, opts, SB_FIELD_OPT(field, format))
318 * tmgr.atom_max_size=N
319 * Atoms containing more than N blocks will be forced to commit. N is
322 PUSH_SB_FIELD_OPT(tmgr
.atom_max_size
, "%u");
324 * tmgr.atom_max_age=N
325 * Atoms older than N seconds will be forced to commit. N is decimal.
327 PUSH_SB_FIELD_OPT(tmgr
.atom_max_age
, "%u");
329 * tmgr.atom_min_size=N
330 * In committing an atom to free dirty pages, force the atom less than
331 * N in size to fuse with another one.
333 PUSH_SB_FIELD_OPT(tmgr
.atom_min_size
, "%u");
335 * tmgr.atom_max_flushers=N
336 * limit of concurrent flushers for one atom. 0 means no limit.
338 PUSH_SB_FIELD_OPT(tmgr
.atom_max_flushers
, "%u");
340 * tree.cbk_cache_slots=N
341 * Number of slots in the cbk cache.
343 PUSH_SB_FIELD_OPT(tree
.cbk_cache
.nr_slots
, "%u");
345 * If flush finds more than FLUSH_RELOCATE_THRESHOLD adjacent dirty
346 * leaf-level blocks it will force them to be relocated.
348 PUSH_SB_FIELD_OPT(flush
.relocate_threshold
, "%u");
350 * If flush finds can find a block allocation closer than at most
351 * FLUSH_RELOCATE_DISTANCE from the preceder it will relocate to that
354 PUSH_SB_FIELD_OPT(flush
.relocate_distance
, "%u");
356 * If we have written this much or more blocks before encountering busy
357 * jnode in flush list - abort flushing hoping that next time we get
358 * called this jnode will be clean already, and we will save some
361 PUSH_SB_FIELD_OPT(flush
.written_threshold
, "%u");
362 /* The maximum number of nodes to scan left on a level during flush. */
363 PUSH_SB_FIELD_OPT(flush
.scan_maxnodes
, "%u");
364 /* preferred IO size */
365 PUSH_SB_FIELD_OPT(optimal_io_size
, "%u");
366 /* carry flags used for insertion of new nodes */
367 PUSH_SB_FIELD_OPT(tree
.carry
.new_node_flags
, "%u");
368 /* carry flags used for insertion of new extents */
369 PUSH_SB_FIELD_OPT(tree
.carry
.new_extent_flags
, "%u");
370 /* carry flags used for paste operations */
371 PUSH_SB_FIELD_OPT(tree
.carry
.paste_flags
, "%u");
372 /* carry flags used for insert operations */
373 PUSH_SB_FIELD_OPT(tree
.carry
.insert_flags
, "%u");
375 #ifdef CONFIG_REISER4_BADBLOCKS
377 * Alternative master superblock location in case if it's original
378 * location is not writeable/accessable. This is offset in BYTES.
380 PUSH_SB_FIELD_OPT(altsuper
, "%lu");
385 * reiser4_init_super_data - initialize reiser4 private super block
386 * @super: super block to initialize
387 * @opt_string: list of reiser4 mount options
389 * Sets various reiser4 parameters to default values. Parses mount options and
390 * overwrites default settings.
392 int reiser4_init_super_data(struct super_block
*super
, char *opt_string
)
395 struct opt_desc
*opts
, *p
;
396 reiser4_super_info_data
*sbinfo
= get_super_private(super
);
398 /* initialize super, export, dentry operations */
399 sbinfo
->ops
.super
= reiser4_super_operations
;
400 sbinfo
->ops
.export
= reiser4_export_operations
;
401 sbinfo
->ops
.dentry
= reiser4_dentry_operations
;
402 super
->s_op
= &sbinfo
->ops
.super
;
403 super
->s_export_op
= &sbinfo
->ops
.export
;
405 /* initialize transaction manager parameters to default values */
406 sbinfo
->tmgr
.atom_max_size
= totalram_pages
/ 4;
407 sbinfo
->tmgr
.atom_max_age
= REISER4_ATOM_MAX_AGE
/ HZ
;
408 sbinfo
->tmgr
.atom_min_size
= 256;
409 sbinfo
->tmgr
.atom_max_flushers
= ATOM_MAX_FLUSHERS
;
411 /* initialize cbk cache parameter */
412 sbinfo
->tree
.cbk_cache
.nr_slots
= CBK_CACHE_SLOTS
;
414 /* initialize flush parameters */
415 sbinfo
->flush
.relocate_threshold
= FLUSH_RELOCATE_THRESHOLD
;
416 sbinfo
->flush
.relocate_distance
= FLUSH_RELOCATE_DISTANCE
;
417 sbinfo
->flush
.written_threshold
= FLUSH_WRITTEN_THRESHOLD
;
418 sbinfo
->flush
.scan_maxnodes
= FLUSH_SCAN_MAXNODES
;
420 sbinfo
->optimal_io_size
= REISER4_OPTIMAL_IO_SIZE
;
422 /* preliminary tree initializations */
423 sbinfo
->tree
.super
= super
;
424 sbinfo
->tree
.carry
.new_node_flags
= REISER4_NEW_NODE_FLAGS
;
425 sbinfo
->tree
.carry
.new_extent_flags
= REISER4_NEW_EXTENT_FLAGS
;
426 sbinfo
->tree
.carry
.paste_flags
= REISER4_PASTE_FLAGS
;
427 sbinfo
->tree
.carry
.insert_flags
= REISER4_INSERT_FLAGS
;
428 rwlock_init(&(sbinfo
->tree
.tree_lock
));
429 spin_lock_init(&(sbinfo
->tree
.epoch_lock
));
431 /* initialize default readahead params */
432 sbinfo
->ra_params
.max
= num_physpages
/ 4;
433 sbinfo
->ra_params
.flags
= 0;
435 /* allocate memory for structure describing reiser4 mount options */
436 opts
= kmalloc(sizeof(struct opt_desc
) * MAX_NR_OPTIONS
,
437 reiser4_ctx_gfp_mask_get());
439 return RETERR(-ENOMEM
);
441 /* initialize structure describing reiser4 mount options */
444 push_sb_field_opts(&p
, opts
, sbinfo
);
445 /* turn on BSD-style gid assignment */
447 #define PUSH_BIT_OPT(name, bit) \
448 PUSH_OPT(p, opts, BIT_OPT(name, bit))
450 PUSH_BIT_OPT("bsdgroups", REISER4_BSD_GID
);
451 /* turn on 32 bit times */
452 PUSH_BIT_OPT("32bittimes", REISER4_32_BIT_TIMES
);
454 * Don't load all bitmap blocks at mount time, it is useful for
455 * machines with tiny RAM and large disks.
457 PUSH_BIT_OPT("dont_load_bitmap", REISER4_DONT_LOAD_BITMAP
);
458 /* disable transaction commits during write() */
459 PUSH_BIT_OPT("atomic_write", REISER4_ATOMIC_WRITE
);
460 /* disable use of write barriers in the reiser4 log writer. */
461 PUSH_BIT_OPT("no_write_barrier", REISER4_NO_WRITE_BARRIER
);
466 * tree traversal readahead parameters:
467 * -o readahead:MAXNUM:FLAGS
468 * MAXNUM - max number fo nodes to request readahead for: -1UL
469 * will set it to max_sane_readahead()
470 * FLAGS - combination of bits: RA_ADJCENT_ONLY, RA_ALL_LEVELS,
471 * CONTINUE_ON_PRESENT
479 .arg1
= &sbinfo
->ra_params
.max
,
480 .arg2
= &sbinfo
->ra_params
.flags
,
488 /* What to do in case of fs error */
495 .result
= &sbinfo
->onerror
,
497 "panic", "remount-ro", NULL
504 /* modify default settings to values set by mount options */
505 result
= parse_options(opt_string
, opts
, p
- opts
);
510 /* correct settings to sanity values */
511 sbinfo
->tmgr
.atom_max_age
*= HZ
;
512 if (sbinfo
->tmgr
.atom_max_age
<= 0)
514 sbinfo
->tmgr
.atom_max_age
= REISER4_ATOM_MAX_AGE
;
516 /* round optimal io size up to 512 bytes */
517 sbinfo
->optimal_io_size
>>= VFS_BLKSIZE_BITS
;
518 sbinfo
->optimal_io_size
<<= VFS_BLKSIZE_BITS
;
519 if (sbinfo
->optimal_io_size
== 0) {
520 warning("nikita-2497", "optimal_io_size is too small");
521 return RETERR(-EINVAL
);
527 * reiser4_init_read_super - read reiser4 master super block
528 * @super: super block to fill
529 * @silent: if 0 - print warnings
531 * Reads reiser4 master super block either from predefined location or from
532 * location specified by altsuper mount option, initializes disk format plugin.
534 int reiser4_init_read_super(struct super_block
*super
, int silent
)
536 struct buffer_head
*super_bh
;
537 struct reiser4_master_sb
*master_sb
;
538 reiser4_super_info_data
*sbinfo
= get_super_private(super
);
539 unsigned long blocksize
;
542 #ifdef CONFIG_REISER4_BADBLOCKS
543 if (sbinfo
->altsuper
)
545 * read reiser4 master super block at position specified by
548 super_bh
= sb_bread(super
,
549 (sector_t
)(sbinfo
->altsuper
/ super
->s_blocksize
));
552 /* read reiser4 master super block at 16-th 4096 block */
553 super_bh
= sb_bread(super
,
554 (sector_t
)(REISER4_MAGIC_OFFSET
/ super
->s_blocksize
));
558 master_sb
= (struct reiser4_master_sb
*)super_bh
->b_data
;
559 /* check reiser4 magic string */
560 if (!strncmp(master_sb
->magic
, REISER4_SUPER_MAGIC_STRING
,
561 sizeof(REISER4_SUPER_MAGIC_STRING
))) {
562 /* reiser4 master super block contains filesystem blocksize */
563 blocksize
= le16_to_cpu(get_unaligned(&master_sb
->blocksize
));
565 if (blocksize
!= PAGE_CACHE_SIZE
) {
567 * currenly reiser4's blocksize must be equal to
571 warning("nikita-2609",
572 "%s: wrong block size %ld\n", super
->s_id
,
575 return RETERR(-EINVAL
);
577 if (blocksize
!= super
->s_blocksize
) {
579 * filesystem uses different blocksize. Reread master
580 * super block with correct blocksize
583 if (!sb_set_blocksize(super
, (int)blocksize
))
584 return RETERR(-EINVAL
);
585 goto read_super_block
;
589 disk_format_plugin_by_id(
590 le16_to_cpu(get_unaligned(&master_sb
->disk_plugin_id
)));
591 if (sbinfo
->df_plug
== NULL
) {
593 warning("nikita-26091",
594 "%s: unknown disk format plugin %d\n",
596 le16_to_cpu(get_unaligned(&master_sb
->disk_plugin_id
)));
598 return RETERR(-EINVAL
);
600 sbinfo
->diskmap_block
= le64_to_cpu(get_unaligned(&master_sb
->diskmap
));
605 /* there is no reiser4 on the device */
607 warning("nikita-2608",
608 "%s: wrong master super block magic", super
->s_id
);
610 return RETERR(-EINVAL
);
614 reiser4_plugin_type type
;
615 reiser4_plugin_id id
;
616 } default_plugins
[PSET_LAST
] = {
618 .type
= REISER4_FILE_PLUGIN_TYPE
,
619 .id
= UNIX_FILE_PLUGIN_ID
622 .type
= REISER4_DIR_PLUGIN_TYPE
,
623 .id
= HASHED_DIR_PLUGIN_ID
626 .type
= REISER4_HASH_PLUGIN_TYPE
,
630 .type
= REISER4_FIBRATION_PLUGIN_TYPE
,
631 .id
= FIBRATION_DOT_O
634 .type
= REISER4_PERM_PLUGIN_TYPE
,
637 [PSET_FORMATTING
] = {
638 .type
= REISER4_FORMATTING_PLUGIN_TYPE
,
639 .id
= SMALL_FILE_FORMATTING_ID
642 .type
= REISER4_ITEM_PLUGIN_TYPE
,
643 .id
= STATIC_STAT_DATA_ID
646 .type
= REISER4_ITEM_PLUGIN_TYPE
,
647 .id
= COMPOUND_DIR_ID
650 .type
= REISER4_CIPHER_PLUGIN_TYPE
,
654 .type
= REISER4_DIGEST_PLUGIN_TYPE
,
655 .id
= SHA256_32_DIGEST_ID
657 [PSET_COMPRESSION
] = {
658 .type
= REISER4_COMPRESSION_PLUGIN_TYPE
,
659 .id
= LZO1_COMPRESSION_ID
661 [PSET_COMPRESSION_MODE
] = {
662 .type
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
663 .id
= CONVX_COMPRESSION_MODE_ID
666 .type
= REISER4_CLUSTER_PLUGIN_TYPE
,
670 .type
= REISER4_FILE_PLUGIN_TYPE
,
671 .id
= UNIX_FILE_PLUGIN_ID
675 /* access to default plugin table */
676 reiser4_plugin
*get_default_plugin(pset_member memb
)
678 return plugin_by_id(default_plugins
[memb
].type
,
679 default_plugins
[memb
].id
);
683 * reiser4_init_root_inode - obtain inode of root directory
684 * @super: super block of filesystem
686 * Obtains inode of root directory (reading it from disk), initializes plugin
687 * set it was not initialized.
689 int reiser4_init_root_inode(struct super_block
*super
)
691 reiser4_super_info_data
*sbinfo
= get_super_private(super
);
695 inode
= reiser4_iget(super
, sbinfo
->df_plug
->root_dir_key(super
), 0);
697 return RETERR(PTR_ERR(inode
));
699 super
->s_root
= d_alloc_root(inode
);
700 if (!super
->s_root
) {
702 return RETERR(-ENOMEM
);
705 super
->s_root
->d_op
= &sbinfo
->ops
.dentry
;
707 if (!is_inode_loaded(inode
)) {
711 pset
= reiser4_inode_data(inode
)->pset
;
712 for (memb
= 0; memb
< PSET_LAST
; ++memb
) {
714 if (aset_get(pset
, memb
) != NULL
)
717 result
= grab_plugin_pset(inode
, NULL
, memb
);
721 reiser4_inode_clr_flag(inode
, REISER4_SDLEN_KNOWN
);
726 for (memb
= 0; memb
< PSET_LAST
; ++memb
)
727 assert("nikita-3500",
728 aset_get(pset
, memb
) != NULL
);
731 warning("nikita-3448", "Cannot set plugins of root: %i",
733 reiser4_iget_complete(inode
);
735 /* As the default pset kept in the root dir may has been changed
736 (length is unknown), call update_sd. */
737 if (!reiser4_inode_get_flag(inode
, REISER4_SDLEN_KNOWN
)) {
738 result
= reiser4_grab_space(
739 inode_file_plugin(inode
)->estimate
.update(inode
),
743 result
= reiser4_update_sd(inode
);
749 super
->s_maxbytes
= MAX_LFS_FILESIZE
;
755 * c-indentation-style: "K&R"