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

📄 xfs_rename.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	 * into our tree when the project IDs are the same; else the	 * tree quota mechanism would be circumvented.	 */	if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&		     (target_dp->i_d.di_projid != src_ip->i_d.di_projid))) {		error = XFS_ERROR(EXDEV);		xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);		goto rele_return;	}	new_parent = (src_dp != target_dp);	src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);	/*	 * Drop the locks on our inodes so that we can start the transaction.	 */	xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);	XFS_BMAP_INIT(&free_list, &first_block);	tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);	cancel_flags = XFS_TRANS_RELEASE_LOG_RES;	spaceres = XFS_RENAME_SPACE_RES(mp, target_namelen);	error = xfs_trans_reserve(tp, spaceres, XFS_RENAME_LOG_RES(mp), 0,			XFS_TRANS_PERM_LOG_RES, XFS_RENAME_LOG_COUNT);	if (error == ENOSPC) {		spaceres = 0;		error = xfs_trans_reserve(tp, 0, XFS_RENAME_LOG_RES(mp), 0,				XFS_TRANS_PERM_LOG_RES, XFS_RENAME_LOG_COUNT);	}	if (error) {		xfs_trans_cancel(tp, 0);		goto rele_return;	}	/*	 * Attach the dquots to the inodes	 */	if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) {		xfs_trans_cancel(tp, cancel_flags);		goto rele_return;	}	/*	 * Reacquire the inode locks we dropped above.	 */	xfs_lock_inodes(inodes, num_inodes, 0, XFS_ILOCK_EXCL);	/*	 * Join all the inodes to the transaction. From this point on,	 * we can rely on either trans_commit or trans_cancel to unlock	 * them.  Note that we need to add a vnode reference to the	 * directories since trans_commit & trans_cancel will decrement	 * them when they unlock the inodes.  Also, we need to be careful	 * not to add an inode to the transaction more than once.	 */	VN_HOLD(src_dir_vp);	xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);	if (new_parent) {		VN_HOLD(target_dir_vp);		xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);	}	if ((src_ip != src_dp) && (src_ip != target_dp)) {		xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);	}	if ((target_ip != NULL) &&	    (target_ip != src_ip) &&	    (target_ip != src_dp) &&	    (target_ip != target_dp)) {		xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);	}	/*	 * Set up the target.	 */	if (target_ip == NULL) {		/*		 * If there's no space reservation, check the entry will		 * fit before actually inserting it.		 */		if (spaceres == 0 &&		    (error = xfs_dir_canenter(tp, target_dp, target_name,						target_namelen)))			goto error_return;		/*		 * If target does not exist and the rename crosses		 * directories, adjust the target directory link count		 * to account for the ".." reference from the new entry.		 */		error = xfs_dir_createname(tp, target_dp, target_name,					   target_namelen, src_ip->i_ino,					   &first_block, &free_list, spaceres);		if (error == ENOSPC)			goto error_return;		if (error)			goto abort_return;		xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);		if (new_parent && src_is_directory) {			error = xfs_bumplink(tp, target_dp);			if (error)				goto abort_return;		}	} else { /* target_ip != NULL */		/*		 * If target exists and it's a directory, check that both		 * target and source are directories and that target can be		 * destroyed, or that neither is a directory.		 */		if ((target_ip->i_d.di_mode & S_IFMT) == S_IFDIR) {			/*			 * Make sure target dir is empty.			 */			if (!(xfs_dir_isempty(target_ip)) ||			    (target_ip->i_d.di_nlink > 2)) {				error = XFS_ERROR(EEXIST);				goto error_return;			}		}		/*		 * Link the source inode under the target name.		 * If the source inode is a directory and we are moving		 * it across directories, its ".." entry will be		 * inconsistent until we replace that down below.		 *		 * In case there is already an entry with the same		 * name at the destination directory, remove it first.		 */		error = xfs_dir_replace(tp, target_dp, target_name,					target_namelen, src_ip->i_ino,					&first_block, &free_list, spaceres);		if (error)			goto abort_return;		xfs_ichgtime(target_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);		/*		 * Decrement the link count on the target since the target		 * dir no longer points to it.		 */		error = xfs_droplink(tp, target_ip);		if (error)			goto abort_return;		target_ip_dropped = 1;		if (src_is_directory) {			/*			 * Drop the link from the old "." entry.			 */			error = xfs_droplink(tp, target_ip);			if (error)				goto abort_return;		}		/* Do this test while we still hold the locks */		target_link_zero = (target_ip)->i_d.di_nlink==0;	} /* target_ip != NULL */	/*	 * Remove the source.	 */	if (new_parent && src_is_directory) {		/*		 * Rewrite the ".." entry to point to the new		 * directory.		 */		error = xfs_dir_replace(tp, src_ip, "..", 2, target_dp->i_ino,					&first_block, &free_list, spaceres);		ASSERT(error != EEXIST);		if (error)			goto abort_return;		xfs_ichgtime(src_ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);	} else {		/*		 * We always want to hit the ctime on the source inode.		 * We do it in the if clause above for the 'new_parent &&		 * src_is_directory' case, and here we get all the other		 * cases.  This isn't strictly required by the standards		 * since the source inode isn't really being changed,		 * but old unix file systems did it and some incremental		 * backup programs won't work without it.		 */		xfs_ichgtime(src_ip, XFS_ICHGTIME_CHG);	}	/*	 * Adjust the link count on src_dp.  This is necessary when	 * renaming a directory, either within one parent when	 * the target existed, or across two parent directories.	 */	if (src_is_directory && (new_parent || target_ip != NULL)) {		/*		 * Decrement link count on src_directory since the		 * entry that's moved no longer points to it.		 */		error = xfs_droplink(tp, src_dp);		if (error)			goto abort_return;	}	error = xfs_dir_removename(tp, src_dp, src_name, src_namelen,			src_ip->i_ino, &first_block, &free_list, spaceres);	if (error)		goto abort_return;	xfs_ichgtime(src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);	/*	 * Update the generation counts on all the directory inodes	 * that we're modifying.	 */	src_dp->i_gen++;	xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);	if (new_parent) {		target_dp->i_gen++;		xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);	}	/*	 * If there was a target inode, take an extra reference on	 * it here so that it doesn't go to xfs_inactive() from	 * within the commit.	 */	if (target_ip != NULL) {		IHOLD(target_ip);	}	/*	 * If this is a synchronous mount, make sure that the	 * rename transaction goes to disk before returning to	 * the user.	 */	if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC)) {		xfs_trans_set_sync(tp);	}	/*	 * Take refs. for vop_link_removed calls below.  No need to worry	 * about directory refs. because the caller holds them.	 *	 * Do holds before the xfs_bmap_finish since it might rele them down	 * to zero.	 */	if (target_ip_dropped)		IHOLD(target_ip);	IHOLD(src_ip);	error = xfs_bmap_finish(&tp, &free_list, &committed);	if (error) {		xfs_bmap_cancel(&free_list);		xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |				 XFS_TRANS_ABORT));		if (target_ip != NULL) {			IRELE(target_ip);		}		if (target_ip_dropped) {			IRELE(target_ip);		}		IRELE(src_ip);		goto std_return;	}	/*	 * trans_commit will unlock src_ip, target_ip & decrement	 * the vnode references.	 */	error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);	if (target_ip != NULL) {		xfs_refcache_purge_ip(target_ip);		IRELE(target_ip);	}	/*	 * Let interposed file systems know about removed links.	 */	if (target_ip_dropped)		IRELE(target_ip);	IRELE(src_ip);	/* Fall through to std_return with error = 0 or errno from	 * xfs_trans_commit	 */std_return:	if (DM_EVENT_ENABLED(src_dp, DM_EVENT_POSTRENAME) ||	    DM_EVENT_ENABLED(target_dp, DM_EVENT_POSTRENAME)) {		(void) XFS_SEND_NAMESP (mp, DM_EVENT_POSTRENAME,					src_dir_vp, DM_RIGHT_NULL,					target_dir_vp, DM_RIGHT_NULL,					src_name, target_name,					0, error, 0);	}	return error; abort_return:	cancel_flags |= XFS_TRANS_ABORT;	/* FALLTHROUGH */ error_return:	xfs_bmap_cancel(&free_list);	xfs_trans_cancel(tp, cancel_flags);	goto std_return; rele_return:	IRELE(src_ip);	if (target_ip != NULL) {		IRELE(target_ip);	}	goto std_return;}

⌨️ 快捷键说明

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