Back to home page

OSCL-LXR

 
 

    


0001 /* -*- linux-c -*- */
0002 
0003 /* fs/reiserfs/procfs.c */
0004 
0005 /*
0006  * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
0007  */
0008 
0009 /* proc info support a la one created by Sizif@Botik.RU for PGC */
0010 
0011 #include <linux/module.h>
0012 #include <linux/time.h>
0013 #include <linux/seq_file.h>
0014 #include <linux/uaccess.h>
0015 #include "reiserfs.h"
0016 #include <linux/init.h>
0017 #include <linux/proc_fs.h>
0018 #include <linux/blkdev.h>
0019 
0020 /*
0021  * LOCKING:
0022  *
0023  * These guys are evicted from procfs as the very first step in ->kill_sb().
0024  *
0025  */
0026 
0027 static int show_version(struct seq_file *m, void *unused)
0028 {
0029     struct super_block *sb = m->private;
0030     char *format;
0031 
0032     if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
0033         format = "3.6";
0034     } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
0035         format = "3.5";
0036     } else {
0037         format = "unknown";
0038     }
0039 
0040     seq_printf(m, "%s format\twith checks %s\n", format,
0041 #if defined( CONFIG_REISERFS_CHECK )
0042            "on"
0043 #else
0044            "off"
0045 #endif
0046         );
0047     return 0;
0048 }
0049 
0050 #define SF( x ) ( r -> x )
0051 #define SFP( x ) SF( s_proc_info_data.x )
0052 #define SFPL( x ) SFP( x[ level ] )
0053 #define SFPF( x ) SFP( scan_bitmap.x )
0054 #define SFPJ( x ) SFP( journal.x )
0055 
0056 #define D2C( x ) le16_to_cpu( x )
0057 #define D4C( x ) le32_to_cpu( x )
0058 #define DF( x ) D2C( rs -> s_v1.x )
0059 #define DFL( x ) D4C( rs -> s_v1.x )
0060 
0061 #define objectid_map( s, rs ) (old_format_only (s) ?                \
0062                          (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
0063              (__le32 *)(rs + 1))
0064 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
0065 
0066 #define DJF( x ) le32_to_cpu( rs -> x )
0067 #define DJP( x ) le32_to_cpu( jp -> x )
0068 #define JF( x ) ( r -> s_journal -> x )
0069 
0070 static int show_super(struct seq_file *m, void *unused)
0071 {
0072     struct super_block *sb = m->private;
0073     struct reiserfs_sb_info *r = REISERFS_SB(sb);
0074 
0075     seq_printf(m, "state: \t%s\n"
0076            "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
0077            "gen. counter: \t%i\n"
0078            "s_disk_reads: \t%i\n"
0079            "s_disk_writes: \t%i\n"
0080            "s_fix_nodes: \t%i\n"
0081            "s_do_balance: \t%i\n"
0082            "s_unneeded_left_neighbor: \t%i\n"
0083            "s_good_search_by_key_reada: \t%i\n"
0084            "s_bmaps: \t%i\n"
0085            "s_bmaps_without_search: \t%i\n"
0086            "s_direct2indirect: \t%i\n"
0087            "s_indirect2direct: \t%i\n"
0088            "\n"
0089            "max_hash_collisions: \t%i\n"
0090            "breads: \t%lu\n"
0091            "bread_misses: \t%lu\n"
0092            "search_by_key: \t%lu\n"
0093            "search_by_key_fs_changed: \t%lu\n"
0094            "search_by_key_restarted: \t%lu\n"
0095            "insert_item_restarted: \t%lu\n"
0096            "paste_into_item_restarted: \t%lu\n"
0097            "cut_from_item_restarted: \t%lu\n"
0098            "delete_solid_item_restarted: \t%lu\n"
0099            "delete_item_restarted: \t%lu\n"
0100            "leaked_oid: \t%lu\n"
0101            "leaves_removable: \t%lu\n",
0102            SF(s_mount_state) == REISERFS_VALID_FS ?
0103            "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
0104            reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
0105            reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
0106            reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
0107            reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
0108            reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
0109            reiserfs_no_unhashed_relocation(sb) ?
0110            "NO_UNHASHED_RELOCATION " : "",
0111            reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
0112            reiserfs_test4(sb) ? "TEST4 " : "",
0113            have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
0114            "SMALL_TAILS " : "NO_TAILS ",
0115            replay_only(sb) ? "REPLAY_ONLY " : "",
0116            convert_reiserfs(sb) ? "CONV " : "",
0117            atomic_read(&r->s_generation_counter),
0118            SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
0119            SF(s_do_balance), SF(s_unneeded_left_neighbor),
0120            SF(s_good_search_by_key_reada), SF(s_bmaps),
0121            SF(s_bmaps_without_search), SF(s_direct2indirect),
0122            SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
0123            SFP(bread_miss), SFP(search_by_key),
0124            SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
0125            SFP(insert_item_restarted), SFP(paste_into_item_restarted),
0126            SFP(cut_from_item_restarted),
0127            SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
0128            SFP(leaked_oid), SFP(leaves_removable));
0129 
0130     return 0;
0131 }
0132 
0133 static int show_per_level(struct seq_file *m, void *unused)
0134 {
0135     struct super_block *sb = m->private;
0136     struct reiserfs_sb_info *r = REISERFS_SB(sb);
0137     int level;
0138 
0139     seq_printf(m, "level\t"
0140            "     balances"
0141            " [sbk:  reads"
0142            "   fs_changed"
0143            "   restarted]"
0144            "   free space"
0145            "        items"
0146            "   can_remove"
0147            "         lnum"
0148            "         rnum"
0149            "       lbytes"
0150            "       rbytes"
0151            "     get_neig"
0152            " get_neig_res" "  need_l_neig" "  need_r_neig" "\n");
0153 
0154     for (level = 0; level < MAX_HEIGHT; ++level) {
0155         seq_printf(m, "%i\t"
0156                " %12lu"
0157                " %12lu"
0158                " %12lu"
0159                " %12lu"
0160                " %12lu"
0161                " %12lu"
0162                " %12lu"
0163                " %12li"
0164                " %12li"
0165                " %12li"
0166                " %12li"
0167                " %12lu"
0168                " %12lu"
0169                " %12lu"
0170                " %12lu"
0171                "\n",
0172                level,
0173                SFPL(balance_at),
0174                SFPL(sbk_read_at),
0175                SFPL(sbk_fs_changed),
0176                SFPL(sbk_restarted),
0177                SFPL(free_at),
0178                SFPL(items_at),
0179                SFPL(can_node_be_removed),
0180                SFPL(lnum),
0181                SFPL(rnum),
0182                SFPL(lbytes),
0183                SFPL(rbytes),
0184                SFPL(get_neighbors),
0185                SFPL(get_neighbors_restart),
0186                SFPL(need_l_neighbor), SFPL(need_r_neighbor)
0187             );
0188     }
0189     return 0;
0190 }
0191 
0192 static int show_bitmap(struct seq_file *m, void *unused)
0193 {
0194     struct super_block *sb = m->private;
0195     struct reiserfs_sb_info *r = REISERFS_SB(sb);
0196 
0197     seq_printf(m, "free_block: %lu\n"
0198            "  scan_bitmap:"
0199            "          wait"
0200            "          bmap"
0201            "         retry"
0202            "        stolen"
0203            "  journal_hint"
0204            "journal_nohint"
0205            "\n"
0206            " %14lu"
0207            " %14lu"
0208            " %14lu"
0209            " %14lu"
0210            " %14lu"
0211            " %14lu"
0212            " %14lu"
0213            "\n",
0214            SFP(free_block),
0215            SFPF(call),
0216            SFPF(wait),
0217            SFPF(bmap),
0218            SFPF(retry),
0219            SFPF(stolen),
0220            SFPF(in_journal_hint), SFPF(in_journal_nohint));
0221 
0222     return 0;
0223 }
0224 
0225 static int show_on_disk_super(struct seq_file *m, void *unused)
0226 {
0227     struct super_block *sb = m->private;
0228     struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
0229     struct reiserfs_super_block *rs = sb_info->s_rs;
0230     int hash_code = DFL(s_hash_function_code);
0231     __u32 flags = DJF(s_flags);
0232 
0233     seq_printf(m, "block_count: \t%i\n"
0234            "free_blocks: \t%i\n"
0235            "root_block: \t%i\n"
0236            "blocksize: \t%i\n"
0237            "oid_maxsize: \t%i\n"
0238            "oid_cursize: \t%i\n"
0239            "umount_state: \t%i\n"
0240            "magic: \t%10.10s\n"
0241            "fs_state: \t%i\n"
0242            "hash: \t%s\n"
0243            "tree_height: \t%i\n"
0244            "bmap_nr: \t%i\n"
0245            "version: \t%i\n"
0246            "flags: \t%x[%s]\n"
0247            "reserved_for_journal: \t%i\n",
0248            DFL(s_block_count),
0249            DFL(s_free_blocks),
0250            DFL(s_root_block),
0251            DF(s_blocksize),
0252            DF(s_oid_maxsize),
0253            DF(s_oid_cursize),
0254            DF(s_umount_state),
0255            rs->s_v1.s_magic,
0256            DF(s_fs_state),
0257            hash_code == TEA_HASH ? "tea" :
0258            (hash_code == YURA_HASH) ? "rupasov" :
0259            (hash_code == R5_HASH) ? "r5" :
0260            (hash_code == UNSET_HASH) ? "unset" : "unknown",
0261            DF(s_tree_height),
0262            DF(s_bmap_nr),
0263            DF(s_version), flags, (flags & reiserfs_attrs_cleared)
0264            ? "attrs_cleared" : "", DF(s_reserved_for_journal));
0265 
0266     return 0;
0267 }
0268 
0269 static int show_oidmap(struct seq_file *m, void *unused)
0270 {
0271     struct super_block *sb = m->private;
0272     struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
0273     struct reiserfs_super_block *rs = sb_info->s_rs;
0274     unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
0275     unsigned long total_used = 0;
0276     int i;
0277 
0278     for (i = 0; i < mapsize; ++i) {
0279         __u32 right;
0280 
0281         right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
0282         seq_printf(m, "%s: [ %x .. %x )\n",
0283                (i & 1) ? "free" : "used", MAP(i), right);
0284         if (!(i & 1)) {
0285             total_used += right - MAP(i);
0286         }
0287     }
0288 #if defined( REISERFS_USE_OIDMAPF )
0289     if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
0290         loff_t size = file_inode(sb_info->oidmap.mapf)->i_size;
0291         total_used += size / sizeof(reiserfs_oidinterval_d_t);
0292     }
0293 #endif
0294     seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
0295            mapsize,
0296            mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
0297     return 0;
0298 }
0299 
0300 static time64_t ktime_mono_to_real_seconds(time64_t mono)
0301 {
0302     ktime_t kt = ktime_set(mono, NSEC_PER_SEC/2);
0303 
0304     return ktime_divns(ktime_mono_to_real(kt), NSEC_PER_SEC);
0305 }
0306 
0307 static int show_journal(struct seq_file *m, void *unused)
0308 {
0309     struct super_block *sb = m->private;
0310     struct reiserfs_sb_info *r = REISERFS_SB(sb);
0311     struct reiserfs_super_block *rs = r->s_rs;
0312     struct journal_params *jp = &rs->s_v1.s_journal;
0313 
0314     seq_printf(m,       /* on-disk fields */
0315            "jp_journal_1st_block: \t%i\n"
0316            "jp_journal_dev: \t%pg[%x]\n"
0317            "jp_journal_size: \t%i\n"
0318            "jp_journal_trans_max: \t%i\n"
0319            "jp_journal_magic: \t%i\n"
0320            "jp_journal_max_batch: \t%i\n"
0321            "jp_journal_max_commit_age: \t%i\n"
0322            "jp_journal_max_trans_age: \t%i\n"
0323            /* incore fields */
0324            "j_1st_reserved_block: \t%i\n"
0325            "j_state: \t%li\n"
0326            "j_trans_id: \t%u\n"
0327            "j_mount_id: \t%lu\n"
0328            "j_start: \t%lu\n"
0329            "j_len: \t%lu\n"
0330            "j_len_alloc: \t%lu\n"
0331            "j_wcount: \t%i\n"
0332            "j_bcount: \t%lu\n"
0333            "j_first_unflushed_offset: \t%lu\n"
0334            "j_last_flush_trans_id: \t%u\n"
0335            "j_trans_start_time: \t%lli\n"
0336            "j_list_bitmap_index: \t%i\n"
0337            "j_must_wait: \t%i\n"
0338            "j_next_full_flush: \t%i\n"
0339            "j_next_async_flush: \t%i\n"
0340            "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
0341            /* reiserfs_proc_info_data_t.journal fields */
0342            "in_journal: \t%12lu\n"
0343            "in_journal_bitmap: \t%12lu\n"
0344            "in_journal_reusable: \t%12lu\n"
0345            "lock_journal: \t%12lu\n"
0346            "lock_journal_wait: \t%12lu\n"
0347            "journal_begin: \t%12lu\n"
0348            "journal_relock_writers: \t%12lu\n"
0349            "journal_relock_wcount: \t%12lu\n"
0350            "mark_dirty: \t%12lu\n"
0351            "mark_dirty_already: \t%12lu\n"
0352            "mark_dirty_notjournal: \t%12lu\n"
0353            "restore_prepared: \t%12lu\n"
0354            "prepare: \t%12lu\n"
0355            "prepare_retry: \t%12lu\n",
0356            DJP(jp_journal_1st_block),
0357            SB_JOURNAL(sb)->j_dev_bd,
0358            DJP(jp_journal_dev),
0359            DJP(jp_journal_size),
0360            DJP(jp_journal_trans_max),
0361            DJP(jp_journal_magic),
0362            DJP(jp_journal_max_batch),
0363            SB_JOURNAL(sb)->j_max_commit_age,
0364            DJP(jp_journal_max_trans_age),
0365            JF(j_1st_reserved_block),
0366            JF(j_state),
0367            JF(j_trans_id),
0368            JF(j_mount_id),
0369            JF(j_start),
0370            JF(j_len),
0371            JF(j_len_alloc),
0372            atomic_read(&r->s_journal->j_wcount),
0373            JF(j_bcount),
0374            JF(j_first_unflushed_offset),
0375            JF(j_last_flush_trans_id),
0376            ktime_mono_to_real_seconds(JF(j_trans_start_time)),
0377            JF(j_list_bitmap_index),
0378            JF(j_must_wait),
0379            JF(j_next_full_flush),
0380            JF(j_next_async_flush),
0381            JF(j_cnode_used),
0382            JF(j_cnode_free),
0383            SFPJ(in_journal),
0384            SFPJ(in_journal_bitmap),
0385            SFPJ(in_journal_reusable),
0386            SFPJ(lock_journal),
0387            SFPJ(lock_journal_wait),
0388            SFPJ(journal_being),
0389            SFPJ(journal_relock_writers),
0390            SFPJ(journal_relock_wcount),
0391            SFPJ(mark_dirty),
0392            SFPJ(mark_dirty_already),
0393            SFPJ(mark_dirty_notjournal),
0394            SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
0395         );
0396     return 0;
0397 }
0398 
0399 static struct proc_dir_entry *proc_info_root = NULL;
0400 static const char proc_info_root_name[] = "fs/reiserfs";
0401 
0402 static void add_file(struct super_block *sb, char *name,
0403              int (*func) (struct seq_file *, void *))
0404 {
0405     proc_create_single_data(name, 0, REISERFS_SB(sb)->procdir, func, sb);
0406 }
0407 
0408 int reiserfs_proc_info_init(struct super_block *sb)
0409 {
0410     char b[BDEVNAME_SIZE];
0411     char *s;
0412 
0413     /* Some block devices use /'s */
0414     strlcpy(b, sb->s_id, BDEVNAME_SIZE);
0415     s = strchr(b, '/');
0416     if (s)
0417         *s = '!';
0418 
0419     spin_lock_init(&__PINFO(sb).lock);
0420     REISERFS_SB(sb)->procdir = proc_mkdir_data(b, 0, proc_info_root, sb);
0421     if (REISERFS_SB(sb)->procdir) {
0422         add_file(sb, "version", show_version);
0423         add_file(sb, "super", show_super);
0424         add_file(sb, "per-level", show_per_level);
0425         add_file(sb, "bitmap", show_bitmap);
0426         add_file(sb, "on-disk-super", show_on_disk_super);
0427         add_file(sb, "oidmap", show_oidmap);
0428         add_file(sb, "journal", show_journal);
0429         return 0;
0430     }
0431     reiserfs_warning(sb, "cannot create /proc/%s/%s",
0432              proc_info_root_name, b);
0433     return 1;
0434 }
0435 
0436 int reiserfs_proc_info_done(struct super_block *sb)
0437 {
0438     struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
0439     if (de) {
0440         char b[BDEVNAME_SIZE];
0441         char *s;
0442 
0443         /* Some block devices use /'s */
0444         strlcpy(b, sb->s_id, BDEVNAME_SIZE);
0445         s = strchr(b, '/');
0446         if (s)
0447             *s = '!';
0448 
0449         remove_proc_subtree(b, proc_info_root);
0450         REISERFS_SB(sb)->procdir = NULL;
0451     }
0452     return 0;
0453 }
0454 
0455 int reiserfs_proc_info_global_init(void)
0456 {
0457     if (proc_info_root == NULL) {
0458         proc_info_root = proc_mkdir(proc_info_root_name, NULL);
0459         if (!proc_info_root) {
0460             reiserfs_warning(NULL, "cannot create /proc/%s",
0461                      proc_info_root_name);
0462             return 1;
0463         }
0464     }
0465     return 0;
0466 }
0467 
0468 int reiserfs_proc_info_global_done(void)
0469 {
0470     if (proc_info_root != NULL) {
0471         proc_info_root = NULL;
0472         remove_proc_entry(proc_info_root_name, NULL);
0473     }
0474     return 0;
0475 }
0476 /*
0477  * Revision 1.1.8.2  2001/07/15 17:08:42  god
0478  *  . use get_super() in procfs.c
0479  *  . remove remove_save_link() from reiserfs_do_truncate()
0480  *
0481  * I accept terms and conditions stated in the Legal Agreement
0482  * (available at http://www.namesys.com/legalese.html)
0483  *
0484  * Revision 1.1.8.1  2001/07/11 16:48:50  god
0485  * proc info support
0486  *
0487  * I accept terms and conditions stated in the Legal Agreement
0488  * (available at http://www.namesys.com/legalese.html)
0489  *
0490  */