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

📄 namei.c

📁 ocfs1.4.1 oracle分布式文件系统
💻 C
📖 第 1 页 / 共 4 页
字号:
		status = ocfs2_create_new_inode_locks(inode);		if (status < 0)			mlog_errno(status);	}	status = 0; /* error in ocfs2_create_new_inode_locks is not		     * critical */	*ret_inode = inode;leave:	if (status < 0) {		if (*new_fe_bh) {			brelse(*new_fe_bh);			*new_fe_bh = NULL;		}		if (inode)			iput(inode);	}	mlog_exit(status);	return status;}static int ocfs2_mkdir(struct inode *dir,		       struct dentry *dentry,		       int mode){	int ret;	mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,		   dentry->d_name.len, dentry->d_name.name);	ret = ocfs2_mknod(dir, dentry, mode | S_IFDIR, 0);	mlog_exit(ret);	return ret;}static int ocfs2_create(struct inode *dir,			struct dentry *dentry,			int mode,			struct nameidata *nd){	int ret;	mlog_entry("(0x%p, 0x%p, %d, '%.*s')\n", dir, dentry, mode,		   dentry->d_name.len, dentry->d_name.name);	ret = ocfs2_mknod(dir, dentry, mode | S_IFREG, 0);	mlog_exit(ret);	return ret;}static int ocfs2_link(struct dentry *old_dentry,		      struct inode *dir,		      struct dentry *dentry){	handle_t *handle;	struct inode *inode = old_dentry->d_inode;	int err;	struct buffer_head *fe_bh = NULL;	struct buffer_head *parent_fe_bh = NULL;	struct buffer_head *de_bh = NULL;	struct ocfs2_dinode *fe = NULL;	struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);	mlog_entry("(inode=%lu, old='%.*s' new='%.*s')\n", inode->i_ino,		   old_dentry->d_name.len, old_dentry->d_name.name,		   dentry->d_name.len, dentry->d_name.name);	if (S_ISDIR(inode->i_mode))		return -EPERM;	err = ocfs2_inode_lock(dir, &parent_fe_bh, 1);	if (err < 0) {		if (err != -ENOENT)			mlog_errno(err);		return err;	}	if (!dir->i_nlink) {		err = -ENOENT;		goto out;	}	err = ocfs2_check_dir_for_entry(dir, dentry->d_name.name,					dentry->d_name.len);	if (err)		goto out;	err = ocfs2_prepare_dir_for_insert(osb, dir, parent_fe_bh,					   dentry->d_name.name,					   dentry->d_name.len, &de_bh);	if (err < 0) {		mlog_errno(err);		goto out;	}	err = ocfs2_inode_lock(inode, &fe_bh, 1);	if (err < 0) {		if (err != -ENOENT)			mlog_errno(err);		goto out;	}	fe = (struct ocfs2_dinode *) fe_bh->b_data;	if (le16_to_cpu(fe->i_links_count) >= OCFS2_LINK_MAX) {		err = -EMLINK;		goto out_unlock_inode;	}	handle = ocfs2_start_trans(osb, OCFS2_LINK_CREDITS);	if (IS_ERR(handle)) {		err = PTR_ERR(handle);		handle = NULL;		mlog_errno(err);		goto out_unlock_inode;	}	err = ocfs2_journal_access(handle, inode, fe_bh,				   OCFS2_JOURNAL_ACCESS_WRITE);	if (err < 0) {		mlog_errno(err);		goto out_commit;	}	inc_nlink(inode);	inode->i_ctime = CURRENT_TIME;	fe->i_links_count = cpu_to_le16(inode->i_nlink);	fe->i_ctime = cpu_to_le64(inode->i_ctime.tv_sec);	fe->i_ctime_nsec = cpu_to_le32(inode->i_ctime.tv_nsec);	err = ocfs2_journal_dirty(handle, fe_bh);	if (err < 0) {		le16_add_cpu(&fe->i_links_count, -1);		drop_nlink(inode);		mlog_errno(err);		goto out_commit;	}	err = ocfs2_add_entry(handle, dentry, inode,			      OCFS2_I(inode)->ip_blkno,			      parent_fe_bh, de_bh);	if (err) {		le16_add_cpu(&fe->i_links_count, -1);		drop_nlink(inode);		mlog_errno(err);		goto out_commit;	}	err = ocfs2_dentry_attach_lock(dentry, inode, OCFS2_I(dir)->ip_blkno);	if (err) {		mlog_errno(err);		goto out_commit;	}	atomic_inc(&inode->i_count);	dentry->d_op = &ocfs2_dentry_ops;	d_instantiate(dentry, inode);out_commit:	ocfs2_commit_trans(osb, handle);out_unlock_inode:	ocfs2_inode_unlock(inode, 1);out:	ocfs2_inode_unlock(dir, 1);	if (de_bh)		brelse(de_bh);	if (fe_bh)		brelse(fe_bh);	if (parent_fe_bh)		brelse(parent_fe_bh);	mlog_exit(err);	return err;}/* * Takes and drops an exclusive lock on the given dentry. This will * force other nodes to drop it. */static int ocfs2_remote_dentry_delete(struct dentry *dentry){	int ret;	ret = ocfs2_dentry_lock(dentry, 1);	if (ret)		mlog_errno(ret);	else		ocfs2_dentry_unlock(dentry, 1);	return ret;}static inline int inode_is_unlinkable(struct inode *inode){	if (S_ISDIR(inode->i_mode)) {		if (inode->i_nlink == 2)			return 1;		return 0;	}	if (inode->i_nlink == 1)		return 1;	return 0;}static int ocfs2_unlink(struct inode *dir,			struct dentry *dentry){	int status;	int child_locked = 0;	struct inode *inode = dentry->d_inode;	struct inode *orphan_dir = NULL;	struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);	u64 blkno;	struct ocfs2_dinode *fe = NULL;	struct buffer_head *fe_bh = NULL;	struct buffer_head *parent_node_bh = NULL;	handle_t *handle = NULL;	struct ocfs2_dir_entry *dirent = NULL;	struct buffer_head *dirent_bh = NULL;	char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];	struct buffer_head *orphan_entry_bh = NULL;	mlog_entry("(0x%p, 0x%p, '%.*s')\n", dir, dentry,		   dentry->d_name.len, dentry->d_name.name);	BUG_ON(dentry->d_parent->d_inode != dir);	mlog(0, "ino = %llu\n", (unsigned long long)OCFS2_I(inode)->ip_blkno);	if (inode == osb->root_inode) {		mlog(0, "Cannot delete the root directory\n");		return -EPERM;	}	status = ocfs2_inode_lock(dir, &parent_node_bh, 1);	if (status < 0) {		if (status != -ENOENT)			mlog_errno(status);		return status;	}	status = ocfs2_find_files_on_disk(dentry->d_name.name,					  dentry->d_name.len, &blkno,					  dir, &dirent_bh, &dirent);	if (status < 0) {		if (status != -ENOENT)			mlog_errno(status);		goto leave;	}	if (OCFS2_I(inode)->ip_blkno != blkno) {		status = -ENOENT;		mlog(0, "ip_blkno %llu != dirent blkno %llu ip_flags = %x\n",		     (unsigned long long)OCFS2_I(inode)->ip_blkno,		     (unsigned long long)blkno, OCFS2_I(inode)->ip_flags);		goto leave;	}	status = ocfs2_inode_lock(inode, &fe_bh, 1);	if (status < 0) {		if (status != -ENOENT)			mlog_errno(status);		goto leave;	}	child_locked = 1;	if (S_ISDIR(inode->i_mode)) {	       	if (!ocfs2_empty_dir(inode)) {			status = -ENOTEMPTY;			goto leave;		} else if (inode->i_nlink != 2) {			status = -ENOTEMPTY;			goto leave;		}	}	status = ocfs2_remote_dentry_delete(dentry);	if (status < 0) {		/* This remote delete should succeed under all normal		 * circumstances. */		mlog_errno(status);		goto leave;	}	if (inode_is_unlinkable(inode)) {		status = ocfs2_prepare_orphan_dir(osb, &orphan_dir, inode,						  orphan_name,						  &orphan_entry_bh);		if (status < 0) {			mlog_errno(status);			goto leave;		}	}	handle = ocfs2_start_trans(osb, OCFS2_UNLINK_CREDITS);	if (IS_ERR(handle)) {		status = PTR_ERR(handle);		handle = NULL;		mlog_errno(status);		goto leave;	}	status = ocfs2_journal_access(handle, inode, fe_bh,				      OCFS2_JOURNAL_ACCESS_WRITE);	if (status < 0) {		mlog_errno(status);		goto leave;	}	fe = (struct ocfs2_dinode *) fe_bh->b_data;	if (inode_is_unlinkable(inode)) {		status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name,					  orphan_entry_bh, orphan_dir);		if (status < 0) {			mlog_errno(status);			goto leave;		}	}	/* delete the name from the parent dir */	status = ocfs2_delete_entry(handle, dir, dirent, dirent_bh);	if (status < 0) {		mlog_errno(status);		goto leave;	}	if (S_ISDIR(inode->i_mode))		drop_nlink(inode);	drop_nlink(inode);	fe->i_links_count = cpu_to_le16(inode->i_nlink);	status = ocfs2_journal_dirty(handle, fe_bh);	if (status < 0) {		mlog_errno(status);		goto leave;	}	dir->i_ctime = dir->i_mtime = CURRENT_TIME;	if (S_ISDIR(inode->i_mode))		drop_nlink(dir);	status = ocfs2_mark_inode_dirty(handle, dir, parent_node_bh);	if (status < 0) {		mlog_errno(status);		if (S_ISDIR(inode->i_mode))			inc_nlink(dir);	}leave:	if (handle)		ocfs2_commit_trans(osb, handle);	if (child_locked)		ocfs2_inode_unlock(inode, 1);	ocfs2_inode_unlock(dir, 1);	if (orphan_dir) {		/* This was locked for us in ocfs2_prepare_orphan_dir() */		ocfs2_inode_unlock(orphan_dir, 1);		mutex_unlock(&orphan_dir->i_mutex);		iput(orphan_dir);	}	if (fe_bh)		brelse(fe_bh);	if (dirent_bh)		brelse(dirent_bh);	if (parent_node_bh)		brelse(parent_node_bh);	if (orphan_entry_bh)		brelse(orphan_entry_bh);	mlog_exit(status);	return status;}/* * The only place this should be used is rename! * if they have the same id, then the 1st one is the only one locked. */static int ocfs2_double_lock(struct ocfs2_super *osb,			     struct buffer_head **bh1,			     struct inode *inode1,			     struct buffer_head **bh2,			     struct inode *inode2){	int status;	struct ocfs2_inode_info *oi1 = OCFS2_I(inode1);	struct ocfs2_inode_info *oi2 = OCFS2_I(inode2);	struct buffer_head **tmpbh;	struct inode *tmpinode;	mlog_entry("(inode1 = %llu, inode2 = %llu)\n",		   (unsigned long long)oi1->ip_blkno,		   (unsigned long long)oi2->ip_blkno);	if (*bh1)		*bh1 = NULL;	if (*bh2)		*bh2 = NULL;	/* we always want to lock the one with the lower lockid first. */	if (oi1->ip_blkno != oi2->ip_blkno) {		if (oi1->ip_blkno < oi2->ip_blkno) {			/* switch id1 and id2 around */			mlog(0, "switching them around...\n");			tmpbh = bh2;			bh2 = bh1;			bh1 = tmpbh;			tmpinode = inode2;			inode2 = inode1;			inode1 = tmpinode;		}		/* lock id2 */		status = ocfs2_inode_lock(inode2, bh2, 1);		if (status < 0) {			if (status != -ENOENT)				mlog_errno(status);			goto bail;		}	}	/* lock id1 */	status = ocfs2_inode_lock(inode1, bh1, 1);	if (status < 0) {		/*		 * An error return must mean that no cluster locks		 * were held on function exit.		 */		if (oi1->ip_blkno != oi2->ip_blkno)			ocfs2_inode_unlock(inode2, 1);		if (status != -ENOENT)			mlog_errno(status);	}bail:	mlog_exit(status);	return status;}static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2){	ocfs2_inode_unlock(inode1, 1);	if (inode1 != inode2)		ocfs2_inode_unlock(inode2, 1);}static int ocfs2_rename(struct inode *old_dir,			struct dentry *old_dentry,			struct inode *new_dir,			struct dentry *new_dentry){	int status = 0, rename_lock = 0, parents_locked = 0;	int old_child_locked = 0, new_child_locked = 0;	struct inode *old_inode = old_dentry->d_inode;	struct inode *new_inode = new_dentry->d_inode;	struct inode *orphan_dir = NULL;	struct ocfs2_dinode *newfe = NULL;	char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];	struct buffer_head *orphan_entry_bh = NULL;	struct buffer_head *newfe_bh = NULL;	struct buffer_head *old_inode_bh = NULL;	struct buffer_head *insert_entry_bh = NULL;	struct ocfs2_super *osb = NULL;	u64 newfe_blkno, old_de_ino;	handle_t *handle = NULL;	struct buffer_head *old_dir_bh = NULL;

⌨️ 快捷键说明

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