if (journal->j_cnode_free == 0) { reiserfs_warning(p_s_sb, "journal-2004: Journal cnode memory " "allocation failed (%ld bytes). Journal is " "too large for available memory. Usually " "this is due to a journal that is too large.", sizeof (struct reiserfs_journal_cnode) * num_cnodes); goto free_and_return; }  
int journal_init(struct super_block *p_s_sb, const char *j_dev_name,		 int old_format, unsigned int commit_max_age){	int num_cnodes = SB_ONDISK_JOURNAL_SIZE(p_s_sb) * 2;	struct buffer_head *bhjh;	struct reiserfs_super_block *rs;	struct reiserfs_journal_header *jh;	struct reiserfs_journal *journal;	struct reiserfs_journal_list *jl;	char b[BDEVNAME_SIZE];	journal = SB_JOURNAL(p_s_sb) = vmalloc(sizeof(struct reiserfs_journal));	if (!journal) {		reiserfs_warning(p_s_sb,				 "journal-1256: unable to get memory for journal structure");		return 1;	}	memset(journal, 0, sizeof(struct reiserfs_journal));	INIT_LIST_HEAD(&journal->j_bitmap_nodes);	INIT_LIST_HEAD(&journal->j_prealloc_list);	INIT_LIST_HEAD(&journal->j_working_list);	INIT_LIST_HEAD(&journal->j_journal_list);	journal->j_persistent_trans = 0;	if (reiserfs_allocate_list_bitmaps(p_s_sb,					   journal->j_list_bitmap,					   SB_BMAP_NR(p_s_sb)))		goto free_and_return;	allocate_bitmap_nodes(p_s_sb);	/* reserved for journal area support */	SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?						 REISERFS_OLD_DISK_OFFSET_IN_BYTES						 / p_s_sb->s_blocksize +						 SB_BMAP_NR(p_s_sb) +						 1 :						 REISERFS_DISK_OFFSET_IN_BYTES /						 p_s_sb->s_blocksize + 2);	/* Sanity check to see is the standard journal fitting withing first bitmap	   (actual for small blocksizes) */	if (!SB_ONDISK_JOURNAL_DEVICE(p_s_sb) &&	    (SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) +	     SB_ONDISK_JOURNAL_SIZE(p_s_sb) > p_s_sb->s_blocksize * 8)) {		reiserfs_warning(p_s_sb,				 "journal-1393: journal does not fit for area "				 "addressed by first of bitmap blocks. It starts at "				 "%u and its size is %u. Block size %ld",				 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb),				 SB_ONDISK_JOURNAL_SIZE(p_s_sb),				 p_s_sb->s_blocksize);		goto free_and_return;	}	if (journal_init_dev(p_s_sb, journal, j_dev_name) != 0) {		reiserfs_warning(p_s_sb,				 "sh-462: unable to initialize jornal device");		goto free_and_return;	}	rs = SB_DISK_SUPER_BLOCK(p_s_sb);	/* read journal header */	bhjh = journal_bread(p_s_sb,			     SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +			     SB_ONDISK_JOURNAL_SIZE(p_s_sb));	if (!bhjh) {		reiserfs_warning(p_s_sb,				 "sh-459: unable to read journal header");		goto free_and_return;	}	jh = (struct reiserfs_journal_header *)(bhjh->b_data);	/* make sure that journal matches to the super block */	if (is_reiserfs_jr(rs)	    && (le32_to_cpu(jh->jh_journal.jp_journal_magic) !=		sb_jp_journal_magic(rs))) {		reiserfs_warning(p_s_sb,				 "sh-460: journal header magic %x "				 "(device %s) does not match to magic found in super "				 "block %x", jh->jh_journal.jp_journal_magic,				 bdevname(journal->j_dev_bd, b),				 sb_jp_journal_magic(rs));		brelse(bhjh);		goto free_and_return;	}	journal->j_trans_max = le32_to_cpu(jh->jh_journal.jp_journal_trans_max);	journal->j_max_batch = le32_to_cpu(jh->jh_journal.jp_journal_max_batch);	journal->j_max_commit_age =	    le32_to_cpu(jh->jh_journal.jp_journal_max_commit_age);	journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;	if (journal->j_trans_max) {		/* make sure these parameters are available, assign it if they are not */		__u32 initial = journal->j_trans_max;		__u32 ratio = 1;		if (p_s_sb->s_blocksize < 4096)			ratio = 4096 / p_s_sb->s_blocksize;		if (SB_ONDISK_JOURNAL_SIZE(p_s_sb) / journal->j_trans_max <		    JOURNAL_MIN_RATIO)			journal->j_trans_max =			    SB_ONDISK_JOURNAL_SIZE(p_s_sb) / JOURNAL_MIN_RATIO;		if (journal->j_trans_max > JOURNAL_TRANS_MAX_DEFAULT / ratio)			journal->j_trans_max =			    JOURNAL_TRANS_MAX_DEFAULT / ratio;		if (journal->j_trans_max < JOURNAL_TRANS_MIN_DEFAULT / ratio)			journal->j_trans_max =			    JOURNAL_TRANS_MIN_DEFAULT / ratio;		if (journal->j_trans_max != initial)			reiserfs_warning(p_s_sb,					 "sh-461: journal_init: wrong transaction max size (%u). Changed to %u",					 initial, journal->j_trans_max);		journal->j_max_batch = journal->j_trans_max *		    JOURNAL_MAX_BATCH_DEFAULT / JOURNAL_TRANS_MAX_DEFAULT;	}	if (!journal->j_trans_max) {		/*we have the file system was created by old version of mkreiserfs 		   so this field contains zero value */		journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT;		journal->j_max_batch = JOURNAL_MAX_BATCH_DEFAULT;		journal->j_max_commit_age = JOURNAL_MAX_COMMIT_AGE;		/* for blocksize >= 4096 - max transaction size is 1024. For block size < 4096		   trans max size is decreased proportionally */		if (p_s_sb->s_blocksize < 4096) {			journal->j_trans_max /= (4096 / p_s_sb->s_blocksize);			journal->j_max_batch = (journal->j_trans_max) * 9 / 10;		}	}	journal->j_default_max_commit_age = journal->j_max_commit_age;	if (commit_max_age != 0) {		journal->j_max_commit_age = commit_max_age;		journal->j_max_trans_age = commit_max_age;	}	reiserfs_info(p_s_sb, "journal params: device %s, size %u, "		      "journal first block %u, max trans len %u, max batch %u, "		      "max commit age %u, max trans age %u\n",		      bdevname(journal->j_dev_bd, b),		      SB_ONDISK_JOURNAL_SIZE(p_s_sb),		      SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),		      journal->j_trans_max,		      journal->j_max_batch,		      journal->j_max_commit_age, journal->j_max_trans_age);	brelse(bhjh);	journal->j_list_bitmap_index = 0;	journal_list_init(p_s_sb);	memset(journal->j_list_hash_table, 0,	       JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *));	INIT_LIST_HEAD(&journal->j_dirty_buffers);	spin_lock_init(&journal->j_dirty_buffers_lock);	journal->j_start = 0;	journal->j_len = 0;	journal->j_len_alloc = 0;	atomic_set(&(journal->j_wcount), 0);	atomic_set(&(journal->j_async_throttle), 0);	journal->j_bcount = 0;	journal->j_trans_start_time = 0;	journal->j_last = NULL;	journal->j_first = NULL;	init_waitqueue_head(&(journal->j_join_wait));	sema_init(&journal->j_lock, 1);	sema_init(&journal->j_flush_sem, 1);	journal->j_trans_id = 10;	journal->j_mount_id = 10;	journal->j_state = 0;	atomic_set(&(journal->j_jlock), 0);	journal->j_cnode_free_list = allocate_cnodes(num_cnodes);	journal->j_cnode_free_orig = journal->j_cnode_free_list;	journal->j_cnode_free = journal->j_cnode_free_list ? num_cnodes : 0;	journal->j_cnode_used = 0;	journal->j_must_wait = 0;	init_journal_hash(p_s_sb);	jl = journal->j_current_jl;	jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl);	if (!jl->j_list_bitmap) {		reiserfs_warning(p_s_sb,				 "journal-2005, get_list_bitmap failed for journal list 0");		goto free_and_return;	}	if (journal_read(p_s_sb) < 0) {		reiserfs_warning(p_s_sb, "Replay Failure, unable to mount");		goto free_and_return;	}	reiserfs_mounted_fs_count++;	if (reiserfs_mounted_fs_count <= 1)		commit_wq = create_workqueue("reiserfs");	INIT_WORK(&journal->j_work, flush_async_commits, p_s_sb);	return 0;      free_and_return:	free_journal_ram(p_s_sb);	return 1;}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/576f6d79564d0d2c1f43088e6805674d2e122935/journal.c/clean/fs/reiserfs/journal.c