⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 journal.c

📁 ocfs1.2.7 源码
💻 C
📖 第 1 页 / 共 3 页
字号:
		status = -EACCES;		mlog_errno(status);		goto done;	}	if (is_bad_inode(inode)) {		status = -EACCES;		iput(inode);		inode = NULL;		mlog_errno(status);		goto done;	}	SET_INODE_JOURNAL(inode);	status = ocfs2_meta_lock_full(inode, NULL, &bh, 1,				      OCFS2_META_LOCK_RECOVERY, NULL, 0);	if (status < 0) {		mlog(0, "status returned from ocfs2_meta_lock=%d\n", status);		if (status != -ERESTARTSYS)			mlog(ML_ERROR, "Could not lock journal!\n");		goto done;	}	got_lock = 1;	fe = (struct ocfs2_dinode *) bh->b_data;	flags = le32_to_cpu(fe->id1.journal1.ij_flags);	if (!(flags & OCFS2_JOURNAL_DIRTY_FL)) {		mlog(0, "No recovery required for node %d\n", node_num);		goto done;	}	mlog(ML_NOTICE, "Recovering node %d from slot %d on device (%u,%u)\n",	     node_num, slot_num,	     MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));	OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);	status = ocfs2_force_read_journal(inode);	if (status < 0) {		mlog_errno(status);		goto done;	}	mlog(0, "calling journal_init_inode\n");	journal = journal_init_inode(inode);	if (journal == NULL) {		mlog(ML_ERROR, "Linux journal layer error\n");		status = -EIO;		goto done;	}	status = journal_load(journal);	if (status < 0) {		mlog_errno(status);		if (!igrab(inode))			BUG();		journal_destroy(journal);		goto done;	}	ocfs2_clear_journal_error(osb->sb, journal, slot_num);	/* wipe the journal */	mlog(0, "flushing the journal.\n");	journal_lock_updates(journal);	status = journal_flush(journal);	journal_unlock_updates(journal);	if (status < 0)		mlog_errno(status);	/* This will mark the node clean */	flags = le32_to_cpu(fe->id1.journal1.ij_flags);	flags &= ~OCFS2_JOURNAL_DIRTY_FL;	fe->id1.journal1.ij_flags = cpu_to_le32(flags);	status = ocfs2_write_block(osb, bh, inode);	if (status < 0)		mlog_errno(status);	if (!igrab(inode))		BUG();	journal_destroy(journal);done:	/* drop the lock on this nodes journal */	if (got_lock)		ocfs2_meta_unlock(inode, 1);	if (inode)		iput(inode);	if (bh)		brelse(bh);	mlog_exit(status);	return status;}/* * Do the most important parts of node recovery: *  - Replay it's journal *  - Stamp a clean local allocator file *  - Stamp a clean truncate log *  - Mark the node clean * * If this function completes without error, a node in OCFS2 can be * said to have been safely recovered. As a result, failure during the * second part of a nodes recovery process (local alloc recovery) is * far less concerning. */static int ocfs2_recover_node(struct ocfs2_super *osb,			      int node_num){	int status = 0;	int slot_num;	struct ocfs2_slot_info *si = osb->slot_info;	struct ocfs2_dinode *la_copy = NULL;	struct ocfs2_dinode *tl_copy = NULL;	mlog_entry("(node_num=%d, osb->node_num = %d)\n",		   node_num, osb->node_num);	mlog(0, "checking node %d\n", node_num);	/* Should not ever be called to recover ourselves -- in that	 * case we should've called ocfs2_journal_load instead. */	if (osb->node_num == node_num)		BUG();	slot_num = ocfs2_node_num_to_slot(si, node_num);	if (slot_num == OCFS2_INVALID_SLOT) {		status = 0;		mlog(0, "no slot for this node, so no recovery required.\n");		goto done;	}	mlog(0, "node %d was using slot %d\n", node_num, slot_num);	status = ocfs2_replay_journal(osb, node_num, slot_num);	if (status < 0) {		mlog_errno(status);		goto done;	}	/* Stamp a clean local alloc file AFTER recovering the journal... */	status = ocfs2_begin_local_alloc_recovery(osb, slot_num, &la_copy);	if (status < 0) {		mlog_errno(status);		goto done;	}	/* An error from begin_truncate_log_recovery is not	 * serious enough to warrant halting the rest of	 * recovery. */	status = ocfs2_begin_truncate_log_recovery(osb, slot_num, &tl_copy);	if (status < 0)		mlog_errno(status);	/* Likewise, this would be a strange but ultimately not so	 * harmful place to get an error... */	ocfs2_clear_slot(si, slot_num);	status = ocfs2_update_disk_slots(osb, si);	if (status < 0)		mlog_errno(status);	/* This will kfree the memory pointed to by la_copy and tl_copy */	ocfs2_queue_recovery_completion(osb->journal, slot_num, la_copy,					tl_copy, node_num);	status = 0;done:	mlog_exit(status);	return status;}/* Test node liveness by trylocking his journal. If we get the lock, * we drop it here. Return 0 if we got the lock, -EAGAIN if node is * still alive (we couldn't get the lock) and < 0 on error. */static int ocfs2_trylock_journal(struct ocfs2_super *osb,				 int slot_num){	int status, flags;	struct inode *inode = NULL;	inode = ocfs2_get_system_file_inode(osb, JOURNAL_SYSTEM_INODE,					    slot_num);	if (inode == NULL) {		mlog(ML_ERROR, "access error\n");		status = -EACCES;		goto bail;	}	if (is_bad_inode(inode)) {		mlog(ML_ERROR, "access error (bad inode)\n");		iput(inode);		inode = NULL;		status = -EACCES;		goto bail;	}	SET_INODE_JOURNAL(inode);	flags = OCFS2_META_LOCK_RECOVERY | OCFS2_META_LOCK_NOQUEUE;	status = ocfs2_meta_lock_full(inode, NULL, NULL, 1, flags, NULL, 0);	if (status < 0) {		if (status != -EAGAIN)			mlog_errno(status);		goto bail;	}	ocfs2_meta_unlock(inode, 1);bail:	if (inode)		iput(inode);	return status;}/* Call this underneath ocfs2_super_lock. It also assumes that the * slot info struct has been updated from disk. */int ocfs2_mark_dead_nodes(struct ocfs2_super *osb){	int status, i, node_num;	struct ocfs2_slot_info *si = osb->slot_info;	/* This is called with the super block cluster lock, so we	 * know that the slot map can't change underneath us. */	spin_lock(&si->si_lock);	for(i = 0; i < si->si_num_slots; i++) {		if (i == osb->slot_num)			continue;		if (ocfs2_is_empty_slot(si, i))			continue;		node_num = si->si_global_node_nums[i];		if (ocfs2_node_map_test_bit(osb, &osb->recovery_map, node_num))			continue;		spin_unlock(&si->si_lock);		/* Ok, we have a slot occupied by another node which		 * is not in the recovery map. We trylock his journal		 * file here to test if he's alive. */		status = ocfs2_trylock_journal(osb, i);		if (!status) {			/* Since we're called from mount, we know that			 * the recovery thread can't race us on			 * setting / checking the recovery bits. */			ocfs2_recovery_thread(osb, node_num);		} else if ((status < 0) && (status != -EAGAIN)) {			mlog_errno(status);			goto bail;		}		spin_lock(&si->si_lock);	}	spin_unlock(&si->si_lock);	status = 0;bail:	mlog_exit(status);	return status;}static int ocfs2_queue_orphans(struct ocfs2_super *osb,			       int slot,			       int node_num,			       struct inode **head){	int status;	struct inode *orphan_dir_inode = NULL;	struct inode *iter;	unsigned long offset, blk, local;	struct buffer_head *bh = NULL;	struct ocfs2_dir_entry *de;	struct super_block *sb = osb->sb;	struct ocfs2_inode_info *oi;	orphan_dir_inode = ocfs2_get_system_file_inode(osb,						       ORPHAN_DIR_SYSTEM_INODE,						       slot);	if  (!orphan_dir_inode) {		status = -ENOENT;		mlog_errno(status);		return status;	}		mutex_lock(&orphan_dir_inode->i_mutex);	status = ocfs2_meta_lock(orphan_dir_inode, NULL, NULL, 0);	if (status < 0) {		mlog_errno(status);		goto out;	}	offset = 0;	iter = NULL;	while(offset < i_size_read(orphan_dir_inode)) {		blk = offset >> sb->s_blocksize_bits;		bh = ocfs2_bread(orphan_dir_inode, blk, &status, 0);		if (!bh)			status = -EINVAL;		if (status < 0) {			if (bh)				brelse(bh);			mlog_errno(status);			goto out_unlock;		}		local = 0;		while(offset < i_size_read(orphan_dir_inode)		      && local < sb->s_blocksize) {			de = (struct ocfs2_dir_entry *) (bh->b_data + local);			if (!ocfs2_check_dir_entry(orphan_dir_inode,						  de, bh, local)) {				status = -EINVAL;				mlog_errno(status);				brelse(bh);				goto out_unlock;			}			local += le16_to_cpu(de->rec_len);			offset += le16_to_cpu(de->rec_len);			/* I guess we silently fail on no inode? */			if (!le64_to_cpu(de->inode))				continue;			if (de->file_type > OCFS2_FT_MAX) {				mlog(ML_ERROR,				     "block %llu contains invalid de: "				     "inode = %"MLFu64", rec_len = %u, "				     "name_len = %u, file_type = %u, "				     "name='%.*s'\n",				     (unsigned long long)bh->b_blocknr,				     le64_to_cpu(de->inode),				     le16_to_cpu(de->rec_len),				     de->name_len,				     de->file_type,				     de->name_len,				     de->name);				continue;			}			if (de->name_len == 1 && !strncmp(".", de->name, 1))				continue;			if (de->name_len == 2 && !strncmp("..", de->name, 2))				continue;			iter = ocfs2_iget(osb, le64_to_cpu(de->inode));			if (IS_ERR(iter))				continue;			mlog(0, "queue orphan %"MLFu64"\n",			     OCFS2_I(iter)->ip_blkno);			oi = OCFS2_I(iter);			spin_lock(&oi->ip_lock);			/* Delete voting may have set these on the assumption			 * that the other node would wipe them successfully.			 * If they are still in the node's orphan dir, we need			 * to reset that state. */			if (oi->ip_deleting_node == node_num)				oi->ip_flags &= 				~(OCFS2_INODE_DELETED|OCFS2_INODE_SKIP_DELETE);			/* Set the proper information to get us going into			 * ocfs2_delete_inode. */			oi->ip_flags |= OCFS2_INODE_MAYBE_ORPHANED;			oi->ip_orphaned_slot = slot;			spin_unlock(&oi->ip_lock);			/* No locking is required for the next_orphan			 * queue as there is only ever a single			 * process doing orphan recovery. */			OCFS2_I(iter)->ip_next_orphan = *head;			*head = iter;		}		brelse(bh);	}out_unlock:	ocfs2_meta_unlock(orphan_dir_inode, 0);out:	mutex_unlock(&orphan_dir_inode->i_mutex);	iput(orphan_dir_inode);	return status;}static int ocfs2_orphan_recovery_can_continue(struct ocfs2_super *osb,					      int slot){	int ret;	spin_lock(&osb->osb_lock);	ret = !osb->osb_orphan_wipes[slot];	spin_unlock(&osb->osb_lock);	return ret;}static void ocfs2_mark_recovering_orphan_dir(struct ocfs2_super *osb,					     int slot){	spin_lock(&osb->osb_lock);	/* Mark ourselves such that new processes in delete_inode()	 * know to quit early. */	ocfs2_node_map_set_bit(osb, &osb->osb_recovering_orphan_dirs, slot);	while (osb->osb_orphan_wipes[slot]) {		mlog(0, "%u threads in iput from orphan dir %d, will wait\n",		     osb->osb_orphan_wipes[slot], slot);		/* If any processes are already in the middle of an		 * orphan wipe on this dir, then we need to wait for		 * them. */		spin_unlock(&osb->osb_lock);		wait_event_interruptible(osb->osb_wipe_event,					 ocfs2_orphan_recovery_can_continue(osb, slot));		spin_lock(&osb->osb_lock);	}	spin_unlock(&osb->osb_lock);}static void ocfs2_clear_recovering_orphan_dir(struct ocfs2_super *osb,					      int slot){	ocfs2_node_map_clear_bit(osb, &osb->osb_recovering_orphan_dirs, slot);}/* * Orphan recovery. Each mounted node has its own orphan dir which we * must run during recovery. Our strategy here is to build a list of * the inodes in the orphan dir and iget/iput them. The VFS does * (most) of the rest of the work. * * Orphan recovery can happen at any time, not just mount so we have a * couple of extra considerations. * * - We grab as many inodes as we can under the orphan dir lock - *   doing iget() outside the orphan dir risks getting a reference on *   an invalid inode. * - We must be sure not to deadlock with other processes on the *   system wanting to run delete_inode(). This can happen when they go *   to lock the orphan dir and the orphan recovery process attempts to *   iget() inside the orphan dir lock. This can be avoided by *   advertising our state to ocfs2_delete_inode(). */static int ocfs2_recover_orphans(struct ocfs2_super *osb,				 int slot, int node_num){	int ret = 0;	struct inode *inode = NULL;	struct inode *iter;	struct ocfs2_inode_info *oi;	mlog(0, "Recover inodes from orphan dir in slot %d\n", slot);	ocfs2_mark_recovering_orphan_dir(osb, slot);	ret = ocfs2_queue_orphans(osb, slot, node_num, &inode);	ocfs2_clear_recovering_orphan_dir(osb, slot);	/* Error here should be noted, but we want to continue with as	 * many queued inodes as we've got. */	if (ret)		mlog_errno(ret);	while (inode) {		oi = OCFS2_I(inode);		mlog(0, "iput orphan %"MLFu64"\n", oi->ip_blkno);		iter = oi->ip_next_orphan;		iput(inode);		inode = iter;	}	return ret;}static int ocfs2_wait_on_mount(struct ocfs2_super *osb){	/* This check is good because ocfs2 will wait on our recovery	 * thread before changing it to something other than MOUNTED	 * or DISABLED. */	wait_event(osb->osb_mount_event,		   atomic_read(&osb->vol_state) == VOLUME_MOUNTED ||		   atomic_read(&osb->vol_state) == VOLUME_DISABLED);	/* If there's an error on mount, then we may never get to the	 * MOUNTED flag, but this is set right before	 * dismount_volume() so we can trust it. */	if (atomic_read(&osb->vol_state) == VOLUME_DISABLED) {		mlog(0, "mount error, exiting!\n");		return -EBUSY;	}	return 0;}static int ocfs2_commit_thread(void *arg){	int status;	struct ocfs2_super *osb = arg;	struct ocfs2_journal *journal = osb->journal;	/* we can trust j_num_trans here because _should_stop() is only set in	 * shutdown and nobody other than ourselves should be able to start	 * transactions.  committing on shutdown might take a few iterations	 * as final transactions put deleted inodes on the list */	while (!(kthread_should_stop() &&		 atomic_read(&journal->j_num_trans) == 0)) {		wait_event_interruptible(osb->checkpoint_event,					 atomic_read(&journal->j_num_trans)					 || kthread_should_stop());		status = ocfs2_commit_cache(osb);		if (status < 0)			mlog_errno(status);		if (kthread_should_stop() && atomic_read(&journal->j_num_trans)){			mlog(ML_KTHREAD,			     "commit_thread: %u transactions pending on "			     "shutdown\n",			     atomic_read(&journal->j_num_trans));		}	}	return 0;}/* Look for a dirty journal without taking any cluster locks. Used for * hard readonly access to determine whether the file system journals * require recovery. */int ocfs2_check_journals_nolocks(struct ocfs2_super *osb){	int ret = 0;	unsigned int slot;	struct buffer_head *di_bh;	struct ocfs2_dinode *di;	struct inode *journal = NULL;	for(slot = 0; slot < osb->max_slots; slot++) {		journal = ocfs2_get_system_file_inode(osb,						      JOURNAL_SYSTEM_INODE,						      slot);		if (!journal || is_bad_inode(journal)) {			ret = -EACCES;			mlog_errno(ret);			goto out;		}		di_bh = NULL;		ret = ocfs2_read_block(osb, OCFS2_I(journal)->ip_blkno, &di_bh,				       0, journal);		if (ret < 0) {			mlog_errno(ret);			goto out;		}		di = (struct ocfs2_dinode *) di_bh->b_data;		if (le32_to_cpu(di->id1.journal1.ij_flags) &		    OCFS2_JOURNAL_DIRTY_FL)			ret = -EROFS;		brelse(di_bh);		if (ret)			break;	}out:	if (journal)		iput(journal);	return ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -