procfs.c 18.6 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* -*- linux-c -*- */

/* fs/reiserfs/procfs.c */

/*
 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
 */

/* proc info support a la one created by Sizif@Botik.RU for PGC */

/* $Id: procfs.c,v 1.1.8.2 2001/07/15 17:08:42 god Exp $ */

#include <linux/config.h>
#include <linux/module.h>
15
#include <linux/time.h>
Linus Torvalds's avatar
Linus Torvalds committed
16 17
#include <asm/uaccess.h>
#include <linux/reiserfs_fs.h>
Linus Torvalds's avatar
Linus Torvalds committed
18
#include <linux/reiserfs_fs_sb.h>
Linus Torvalds's avatar
Linus Torvalds committed
19 20 21 22 23 24 25 26 27 28 29 30 31
#include <linux/smp_lock.h>
#include <linux/init.h>
#include <linux/proc_fs.h>

#if defined( REISERFS_PROC_INFO )

/*
 * LOCKING:
 *
 * We rely on new Alexander Viro's super-block locking.
 *
 */

Alexander Viro's avatar
Alexander Viro committed
32
static struct super_block *procinfo_prologue(dev_t dev)
Linus Torvalds's avatar
Linus Torvalds committed
33 34 35 36
{
	struct super_block *result;

	/* get super-block by device */
Alexander Viro's avatar
Alexander Viro committed
37
	result = user_get_super(dev);
Linus Torvalds's avatar
Linus Torvalds committed
38
	if( result != NULL ) {
39
		if( !is_reiserfs_super( result ) ) {
Linus Torvalds's avatar
Linus Torvalds committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
			printk( KERN_DEBUG "reiserfs: procfs-52: "
				"non-reiserfs super found\n" );
			drop_super( result );
			result = NULL;
		}
	} else
		printk( KERN_DEBUG "reiserfs: procfs-74: "
			"race between procinfo and umount\n" );
	return result;
}

int procinfo_epilogue( struct super_block *super )
{
	drop_super( super );
	return 0;
}

int reiserfs_proc_tail( int len, char *buffer, char **start, 
			off_t offset, int count, int *eof )
{
	/* this is black procfs magic */
	if( offset >= len ) {
		*start = buffer;
		*eof = 1;
		return 0;
	}
	*start = buffer + offset;
	if( ( len -= offset ) > count ) {
		return count;
	}
	*eof = 1;
	return len;
}

int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
			      int count, int *eof, void *data )
{
	int len = 0;
	struct super_block *sb;
Linus Torvalds's avatar
Linus Torvalds committed
79
	char *format;
Linus Torvalds's avatar
Linus Torvalds committed
80
    
81
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
82 83
	if( sb == NULL )
		return -ENOENT;
84
	if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6) ) {
Linus Torvalds's avatar
Linus Torvalds committed
85
		format = "3.6";
86
	} else if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5) ) {
Linus Torvalds's avatar
Linus Torvalds committed
87 88 89 90 91
		format = "3.5";
	} else {
		format = "unknown";
	}

Linus Torvalds's avatar
Linus Torvalds committed
92
	len += sprintf( &buffer[ len ], "%s format\twith checks %s\n",
Linus Torvalds's avatar
Linus Torvalds committed
93
			format,
Linus Torvalds's avatar
Linus Torvalds committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#if defined( CONFIG_REISERFS_CHECK )
			"on"
#else
			"off"
#endif
		);
	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset,
				     int count, int *eof, void *data )
{
	int len = 0;
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

#define SF( x ) ( r -> x )
#define SFP( x ) SF( s_proc_info_data.x )
#define SFPL( x ) SFP( x[ level ] )
114
#define SFPF( x ) SFP( scan_bitmap.x )
Linus Torvalds's avatar
Linus Torvalds committed
115 116 117 118
#define SFPJ( x ) SFP( journal.x )

#define D2C( x ) le16_to_cpu( x )
#define D4C( x ) le32_to_cpu( x )
Linus Torvalds's avatar
Linus Torvalds committed
119 120
#define DF( x ) D2C( rs -> s_v1.x )
#define DFL( x ) D4C( rs -> s_v1.x )
Linus Torvalds's avatar
Linus Torvalds committed
121 122 123 124 125 126 127

#define objectid_map( s, rs ) (old_format_only (s) ?				\
                         (__u32 *)((struct reiserfs_super_block_v1 *)rs + 1) :	\
			 (__u32 *)(rs + 1))
#define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )

#define DJF( x ) le32_to_cpu( rs -> x )
Linus Torvalds's avatar
Linus Torvalds committed
128 129
#define DJV( x ) le32_to_cpu( s_v1 -> x )
#define DJP( x ) le32_to_cpu( jp -> x ) 
Linus Torvalds's avatar
Linus Torvalds committed
130 131 132 133 134 135 136 137 138
#define JF( x ) ( r -> s_journal -> x )

int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
			    int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *r;
	int len = 0;
    
139
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
140 141
	if( sb == NULL )
		return -ENOENT;
142
	r = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	len += sprintf( &buffer[ len ], 
			"state: \t%s\n"
			"mount options: \t%s%s%s%s%s%s%s%s%s%s%s%s\n"
			"gen. counter: \t%i\n"
			"s_kmallocs: \t%i\n"
			"s_disk_reads: \t%i\n"
			"s_disk_writes: \t%i\n"
			"s_fix_nodes: \t%i\n"
			"s_do_balance: \t%i\n"
			"s_unneeded_left_neighbor: \t%i\n"
			"s_good_search_by_key_reada: \t%i\n"
			"s_bmaps: \t%i\n"
			"s_bmaps_without_search: \t%i\n"
			"s_direct2indirect: \t%i\n"
			"s_indirect2direct: \t%i\n"
			"\n"
			"max_hash_collisions: \t%i\n"

			"breads: \t%lu\n"
			"bread_misses: \t%lu\n"

			"search_by_key: \t%lu\n"
			"search_by_key_fs_changed: \t%lu\n"
			"search_by_key_restarted: \t%lu\n"
			
168 169 170 171 172 173
			"insert_item_restarted: \t%lu\n"
			"paste_into_item_restarted: \t%lu\n"
			"cut_from_item_restarted: \t%lu\n"
			"delete_solid_item_restarted: \t%lu\n"
			"delete_item_restarted: \t%lu\n"

Linus Torvalds's avatar
Linus Torvalds committed
174 175 176 177 178 179 180 181 182 183 184 185 186
			"leaked_oid: \t%lu\n"
			"leaves_removable: \t%lu\n",

			SF( s_mount_state ) == REISERFS_VALID_FS ?
			"REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
			reiserfs_r5_hash( sb ) ? "FORCE_R5 " : "",
			reiserfs_rupasov_hash( sb ) ? "FORCE_RUPASOV " : "",
			reiserfs_tea_hash( sb ) ? "FORCE_TEA " : "",
			reiserfs_hash_detect( sb ) ? "DETECT_HASH " : "",
			reiserfs_no_border( sb ) ? "NO_BORDER " : "BORDER ",
			reiserfs_no_unhashed_relocation( sb ) ? "NO_UNHASHED_RELOCATION " : "",
			reiserfs_hashed_relocation( sb ) ? "UNHASHED_RELOCATION " : "",
			reiserfs_test4( sb ) ? "TEST4 " : "",
187
			have_large_tails( sb ) ? "TAILS " : have_small_tails(sb)?"SMALL_TAILS ":"NO_TAILS ",
Linus Torvalds's avatar
Linus Torvalds committed
188 189
			replay_only( sb ) ? "REPLAY_ONLY " : "",
			reiserfs_dont_log( sb ) ? "DONT_LOG " : "LOG ",
Linus Torvalds's avatar
Linus Torvalds committed
190
			convert_reiserfs( sb ) ? "CONV " : "",
Linus Torvalds's avatar
Linus Torvalds committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209

			atomic_read( &r -> s_generation_counter ),
			SF( s_kmallocs ),
			SF( s_disk_reads ),
			SF( s_disk_writes ),
			SF( s_fix_nodes ),
			SF( s_do_balance ),
			SF( s_unneeded_left_neighbor ),
			SF( s_good_search_by_key_reada ),
			SF( s_bmaps ),
			SF( s_bmaps_without_search ),
			SF( s_direct2indirect ),
			SF( s_indirect2direct ),
			SFP( max_hash_collisions ),
			SFP( breads ),
			SFP( bread_miss ),
			SFP( search_by_key ),
			SFP( search_by_key_fs_changed ),
			SFP( search_by_key_restarted ),
210 211 212 213 214 215 216

			SFP( insert_item_restarted ),
			SFP( paste_into_item_restarted ),
			SFP( cut_from_item_restarted ),
			SFP( delete_solid_item_restarted ),
			SFP( delete_item_restarted ),

Linus Torvalds's avatar
Linus Torvalds committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
			SFP( leaked_oid ),
			SFP( leaves_removable ) );

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
				int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *r;
	int len = 0;
	int level;
	
232
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
233 234
	if( sb == NULL )
		return -ENOENT;
235
	r = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

	len += sprintf( &buffer[ len ],
			"level\t"
			"     balances"
			" [sbk:  reads"
			"   fs_changed"
			"   restarted]"
			"   free space"
			"        items"
			"   can_remove"
			"         lnum"
			"         rnum"
			"       lbytes"
			"       rbytes"
			"     get_neig"
			" get_neig_res"
			"  need_l_neig"
			"  need_r_neig"
			"\n"
			
		);

	for( level = 0 ; level < MAX_HEIGHT ; ++ level ) {
		if( len > PAGE_SIZE - 240 ) {
			len += sprintf( &buffer[ len ], "... and more\n" );
			break;
		}
		len += sprintf( &buffer[ len ], 
				"%i\t"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12li"
				" %12li"
				" %12li"
				" %12li"
				" %12lu"
				" %12lu"
				" %12lu"
				" %12lu"
				"\n",
				level, 
				SFPL( balance_at ),
				SFPL( sbk_read_at ),
				SFPL( sbk_fs_changed ),
				SFPL( sbk_restarted ),
				SFPL( free_at ),
				SFPL( items_at ),
				SFPL( can_node_be_removed ),
				SFPL( lnum ),
				SFPL( rnum ),
				SFPL( lbytes ),
				SFPL( rbytes ),
				SFPL( get_neighbors ),
				SFPL( get_neighbors_restart ),
				SFPL( need_l_neighbor ),
				SFPL( need_r_neighbor )
			);
	}

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
			     int count, int *eof, void *data )
{
	struct super_block *sb;
308
	struct reiserfs_sb_info *r;
Linus Torvalds's avatar
Linus Torvalds committed
309 310
	int len = 0;
    
311
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
312 313
	if( sb == NULL )
		return -ENOENT;
314
	r = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
315 316

	len += sprintf( &buffer[ len ], "free_block: %lu\n"
317 318 319 320 321 322 323
			"  scan_bitmap:"
			"          wait"
			"          bmap"
			"         retry"
			"        stolen"
			"  journal_hint"
			"journal_nohint"
Linus Torvalds's avatar
Linus Torvalds committed
324
			"\n"
325 326 327 328 329 330 331
			" %14lu"
			" %14lu"
			" %14lu"
			" %14lu"
			" %14lu"
			" %14lu"
			" %14lu"
Linus Torvalds's avatar
Linus Torvalds committed
332 333 334 335 336 337
			"\n",
			SFP( free_block ),
			SFPF( call ), 
			SFPF( wait ), 
			SFPF( bmap ),
			SFPF( retry ),
338
			SFPF( stolen ),
Linus Torvalds's avatar
Linus Torvalds committed
339
			SFPF( in_journal_hint ),
340
			SFPF( in_journal_nohint ) );
Linus Torvalds's avatar
Linus Torvalds committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
				    int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *sb_info;
	struct reiserfs_super_block *rs;
	int hash_code;
	int len = 0;
    
355
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
356 357
	if( sb == NULL )
		return -ENOENT;
358
	sb_info = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
359 360 361 362 363 364 365 366 367 368
	rs = sb_info -> s_rs;
	hash_code = DFL( s_hash_function_code );

	len += sprintf( &buffer[ len ], 
			"block_count: \t%i\n"
			"free_blocks: \t%i\n"
			"root_block: \t%i\n"
			"blocksize: \t%i\n"
			"oid_maxsize: \t%i\n"
			"oid_cursize: \t%i\n"
Linus Torvalds's avatar
Linus Torvalds committed
369 370 371
			"umount_state: \t%i\n"
			"magic: \t%10.10s\n"
			"fs_state: \t%i\n"
Linus Torvalds's avatar
Linus Torvalds committed
372 373 374
			"hash: \t%s\n"
			"tree_height: \t%i\n"
			"bmap_nr: \t%i\n"
Linus Torvalds's avatar
Linus Torvalds committed
375 376
			"version: \t%i\n"
			"reserved_for_journal: \t%i\n",
Linus Torvalds's avatar
Linus Torvalds committed
377 378 379 380 381 382 383

			DFL( s_block_count ),
			DFL( s_free_blocks ),
			DFL( s_root_block ),
			DF( s_blocksize ),
			DF( s_oid_maxsize ),
			DF( s_oid_cursize ),
Linus Torvalds's avatar
Linus Torvalds committed
384 385 386
			DF( s_umount_state ),
			rs -> s_v1.s_magic,
			DF( s_fs_state ),
Linus Torvalds's avatar
Linus Torvalds committed
387 388 389 390 391 392
			hash_code == TEA_HASH ? "tea" :
			( hash_code == YURA_HASH ) ? "rupasov" :
			( hash_code == R5_HASH ) ? "r5" :
			( hash_code == UNSET_HASH ) ? "unset" : "unknown",
			DF( s_tree_height ),
			DF( s_bmap_nr ),
Linus Torvalds's avatar
Linus Torvalds committed
393 394
			DF( s_version ),
			DF (s_reserved_for_journal));
Linus Torvalds's avatar
Linus Torvalds committed
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
			     int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *sb_info;
	struct reiserfs_super_block *rs;
	int i;
	unsigned int mapsize;
	unsigned long total_used;
	int len = 0;
	int exact;
    
412
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
413 414
	if( sb == NULL )
		return -ENOENT;
415
	sb_info = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
416
	rs = sb_info -> s_rs;
Linus Torvalds's avatar
Linus Torvalds committed
417
	mapsize = le16_to_cpu( rs -> s_v1.s_oid_cursize );
Linus Torvalds's avatar
Linus Torvalds committed
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
	total_used = 0;

	for( i = 0 ; i < mapsize ; ++i ) {
		__u32 right;

		right = ( i == mapsize - 1 ) ? MAX_KEY_OBJECTID : MAP( i + 1 );
		len += sprintf( &buffer[ len ], "%s: [ %x .. %x )\n",
				( i & 1 ) ? "free" : "used", MAP( i ), right );
		if( ! ( i & 1 ) ) {
			total_used += right - MAP( i );
		}
		if( len > PAGE_SIZE - 100 ) {
			len += sprintf( &buffer[ len ], "... and more\n" );
			break;
		}
	}
#if defined( REISERFS_USE_OIDMAPF )
	if( sb_info -> oidmap.use_file && ( sb_info -> oidmap.mapf != NULL ) ) {
		loff_t size;

		size = sb_info -> oidmap.mapf -> f_dentry -> d_inode -> i_size;
		total_used += size / sizeof( reiserfs_oidinterval_d_t );
		exact = 1;
	} else
#endif
	{
		exact = ( i == mapsize );
	}
	len += sprintf( &buffer[ len ], "total: \t%i [%i/%i] used: %lu [%s]\n", 
			i, 
Linus Torvalds's avatar
Linus Torvalds committed
448
			mapsize, le16_to_cpu( rs -> s_v1.s_oid_maxsize ),
Linus Torvalds's avatar
Linus Torvalds committed
449 450 451 452 453 454 455 456 457 458 459 460
			total_used, exact ? "exact" : "estimation" );

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}

int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
			      int count, int *eof, void *data )
{
	struct super_block *sb;
	struct reiserfs_sb_info *r;
	struct reiserfs_super_block *rs;
Linus Torvalds's avatar
Linus Torvalds committed
461
	struct journal_params *jp;	
Linus Torvalds's avatar
Linus Torvalds committed
462 463
	int len = 0;
    
464
	sb = procinfo_prologue((int)data);
Linus Torvalds's avatar
Linus Torvalds committed
465 466
	if( sb == NULL )
		return -ENOENT;
467
	r = REISERFS_SB(sb);
Linus Torvalds's avatar
Linus Torvalds committed
468
	rs = r -> s_rs;
Linus Torvalds's avatar
Linus Torvalds committed
469
	jp = &rs->s_v1.s_journal;
Linus Torvalds's avatar
Linus Torvalds committed
470 471 472

	len += sprintf( &buffer[ len ], 
			/* on-disk fields */
Linus Torvalds's avatar
Linus Torvalds committed
473 474 475 476 477 478 479 480
 			"jp_journal_1st_block: \t%i\n"
 			"jp_journal_dev: \t%s[%x]\n"
 			"jp_journal_size: \t%i\n"
 			"jp_journal_trans_max: \t%i\n"
 			"jp_journal_magic: \t%i\n"
 			"jp_journal_max_batch: \t%i\n"
 			"jp_journal_max_commit_age: \t%i\n"
 			"jp_journal_max_trans_age: \t%i\n"
Linus Torvalds's avatar
Linus Torvalds committed
481
			/* incore fields */
Linus Torvalds's avatar
Linus Torvalds committed
482
			"j_1st_reserved_block: \t%i\n"	  
483
			"j_state: \t%li\n"			
Linus Torvalds's avatar
Linus Torvalds committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
			"j_trans_id: \t%lu\n"
			"j_mount_id: \t%lu\n"
			"j_start: \t%lu\n"
			"j_len: \t%lu\n"
			"j_len_alloc: \t%lu\n"
			"j_wcount: \t%i\n"
			"j_bcount: \t%lu\n"
			"j_first_unflushed_offset: \t%lu\n"
			"j_last_flush_trans_id: \t%lu\n"
			"j_trans_start_time: \t%li\n"
			"j_journal_list_index: \t%i\n"
			"j_list_bitmap_index: \t%i\n"
			"j_must_wait: \t%i\n"
			"j_next_full_flush: \t%i\n"
			"j_next_async_flush: \t%i\n"
			"j_cnode_used: \t%i\n"
			"j_cnode_free: \t%i\n"
			"\n"
			/* reiserfs_proc_info_data_t.journal fields */
			"in_journal: \t%12lu\n"
			"in_journal_bitmap: \t%12lu\n"
			"in_journal_reusable: \t%12lu\n"
			"lock_journal: \t%12lu\n"
			"lock_journal_wait: \t%12lu\n"
			"journal_begin: \t%12lu\n"
			"journal_relock_writers: \t%12lu\n"
			"journal_relock_wcount: \t%12lu\n"
			"mark_dirty: \t%12lu\n"
			"mark_dirty_already: \t%12lu\n"
			"mark_dirty_notjournal: \t%12lu\n"
			"restore_prepared: \t%12lu\n"
			"prepare: \t%12lu\n"
			"prepare_retry: \t%12lu\n",

Linus Torvalds's avatar
Linus Torvalds committed
518
                        DJP( jp_journal_1st_block ),
Oleg Drokin's avatar
Oleg Drokin committed
519
                        bdevname(SB_JOURNAL(sb)->j_dev_bd),
Linus Torvalds's avatar
Linus Torvalds committed
520 521 522 523 524 525 526 527 528
                        DJP( jp_journal_dev ),
                        DJP( jp_journal_size ),
                        DJP( jp_journal_trans_max ),
                        DJP( jp_journal_magic ),
                        DJP( jp_journal_max_batch ),
                        DJP( jp_journal_max_commit_age ),
                        DJP( jp_journal_max_trans_age ),

			JF( j_1st_reserved_block ),			
Linus Torvalds's avatar
Linus Torvalds committed
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
			JF( j_state ),			
			JF( j_trans_id ),
			JF( j_mount_id ),
			JF( j_start ),
			JF( j_len ),
			JF( j_len_alloc ),
			atomic_read( & r -> s_journal -> j_wcount ),
			JF( j_bcount ),
			JF( j_first_unflushed_offset ),
			JF( j_last_flush_trans_id ),
			JF( j_trans_start_time ),
			JF( j_journal_list_index ),
			JF( j_list_bitmap_index ),
			JF( j_must_wait ),
			JF( j_next_full_flush ),
			JF( j_next_async_flush ),
			JF( j_cnode_used ),
			JF( j_cnode_free ),

			SFPJ( in_journal ),
			SFPJ( in_journal_bitmap ),
			SFPJ( in_journal_reusable ),
			SFPJ( lock_journal ),
			SFPJ( lock_journal_wait ),
			SFPJ( journal_being ),
			SFPJ( journal_relock_writers ),
			SFPJ( journal_relock_wcount ),
			SFPJ( mark_dirty ),
			SFPJ( mark_dirty_already ),
			SFPJ( mark_dirty_notjournal ),
			SFPJ( restore_prepared ),
			SFPJ( prepare ),
			SFPJ( prepare_retry )
		);

	procinfo_epilogue( sb );
	return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
}


static struct proc_dir_entry *proc_info_root = NULL;
static const char *proc_info_root_name = "fs/reiserfs";

int reiserfs_proc_info_init( struct super_block *sb )
{
	spin_lock_init( & __PINFO( sb ).lock );
Oleg Drokin's avatar
Oleg Drokin committed
575
	REISERFS_SB(sb)->procdir = proc_mkdir(reiserfs_bdevname (sb), proc_info_root);
576 577
	if( REISERFS_SB(sb)->procdir ) {
		REISERFS_SB(sb)->procdir -> owner = THIS_MODULE;
Linus Torvalds's avatar
Linus Torvalds committed
578 579 580
		return 0;
	}
	reiserfs_warning( "reiserfs: cannot create /proc/%s/%s\n",
Oleg Drokin's avatar
Oleg Drokin committed
581
			  proc_info_root_name, reiserfs_bdevname (sb) );
Linus Torvalds's avatar
Linus Torvalds committed
582 583 584 585 586 587 588 589 590 591
	return 1;
}


int reiserfs_proc_info_done( struct super_block *sb )
{
	spin_lock( & __PINFO( sb ).lock );
	__PINFO( sb ).exiting = 1;
	spin_unlock( & __PINFO( sb ).lock );
	if ( proc_info_root ) {
Oleg Drokin's avatar
Oleg Drokin committed
592
		remove_proc_entry( reiserfs_bdevname (sb), proc_info_root );
593
		REISERFS_SB(sb)->procdir = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
594 595 596 597 598 599 600 601 602 603 604
	}
	return 0;
}

/* Create /proc/fs/reiserfs/DEV/name and attach read procedure @func
   to it.  Other parts of reiserfs use this function to make their
   per-device statistics available via /proc */

struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb, 
					       char *name, read_proc_t *func )
{
605 606
	return ( REISERFS_SB(sb)->procdir ) ? create_proc_read_entry
		( name, 0, REISERFS_SB(sb)->procdir, func, 
607
		  ( void * )(int) sb->s_bdev->bd_dev) : NULL;
Linus Torvalds's avatar
Linus Torvalds committed
608 609 610 611
}

void reiserfs_proc_unregister( struct super_block *sb, const char *name )
{
612
	remove_proc_entry( name, REISERFS_SB(sb)->procdir );
Linus Torvalds's avatar
Linus Torvalds committed
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
}

struct proc_dir_entry *reiserfs_proc_register_global( char *name, 
						      read_proc_t *func )
{
	return ( proc_info_root ) ? create_proc_read_entry( name, 0, 
							    proc_info_root, 
							    func, NULL ) : NULL;
}

void reiserfs_proc_unregister_global( const char *name )
{
	remove_proc_entry( name, proc_info_root );
}

int reiserfs_proc_info_global_init( void )
{
	if( proc_info_root == NULL ) {
		proc_info_root = proc_mkdir( proc_info_root_name, 0 );
		if( proc_info_root ) {
			proc_info_root -> owner = THIS_MODULE;
		} else {
			reiserfs_warning( "reiserfs: cannot create /proc/%s\n",
					  proc_info_root_name );
			return 1;
		}
	}
	return 0;
}

int reiserfs_proc_info_global_done( void )
{
	if ( proc_info_root != NULL ) {
		proc_info_root = NULL;
		remove_proc_entry( proc_info_root_name, 0 );
	}
	return 0;
}

/* REISERFS_PROC_INFO */
#else

int reiserfs_proc_info_init( struct super_block *sb ) { return 0; }
int reiserfs_proc_info_done( struct super_block *sb ) { return 0; }

struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb, 
					       char *name, 
					       read_proc_t *func ) 
{ return NULL; }

void reiserfs_proc_unregister( struct super_block *sb, const char *name ) 
{;}

struct proc_dir_entry *reiserfs_proc_register_global( char *name, 
						      read_proc_t *func )
{ return NULL; }

void reiserfs_proc_unregister_global( const char *name ) {;}

int reiserfs_proc_info_global_init( void ) { return 0; }
int reiserfs_proc_info_global_done( void ) { return 0; }

int reiserfs_global_version_in_proc( char *buffer, char **start, 
				     off_t offset,
				     int count, int *eof, void *data )
{ return 0; }

int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
			      int count, int *eof, void *data )
{ return 0; }

int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
			    int count, int *eof, void *data )
{ return 0; }

int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
				int count, int *eof, void *data )
{ return 0; }

int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
			     int count, int *eof, void *data )
{ return 0; }

int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
				    int count, int *eof, void *data )
{ return 0; }

int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
			     int count, int *eof, void *data )
{ return 0; }

int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
			      int count, int *eof, void *data )
{ return 0; }

/* REISERFS_PROC_INFO */
#endif

/*
 * $Log: procfs.c,v $
 * Revision 1.1.8.2  2001/07/15 17:08:42  god
 *  . use get_super() in procfs.c
 *  . remove remove_save_link() from reiserfs_do_truncate()
 *
 * I accept terms and conditions stated in the Legal Agreement
 * (available at http://www.namesys.com/legalese.html)
 *
 * Revision 1.1.8.1  2001/07/11 16:48:50  god
 * proc info support
 *
 * I accept terms and conditions stated in the Legal Agreement
 * (available at http://www.namesys.com/legalese.html)
 *
 */

/* 
 * Make Linus happy.
 * Local variables:
 * c-indentation-style: "K&R"
 * mode-name: "LC"
 * c-basic-offset: 8
 * tab-width: 8
 * End:
 */