Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38760e24 authored by Mark Fasheh's avatar Mark Fasheh
Browse files

ocfs2: Rename cleanups



ocfs2_rename() does direct manipulation of the dirent it's gotten back from
a directory search. Wrap this manipulation inside of a function so that we
can transparently change directory update behavior in the future. As an
added bonus, this gets rid of an ugly macro.

Signed-off-by: default avatarMark Fasheh <mark.fasheh@oracle.com>
Reviewed-by: default avatarJoel Becker <joel.becker@oracle.com>
parent be94d117
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -271,6 +271,28 @@ struct buffer_head *ocfs2_find_entry(const char *name, int namelen,
	return ret;
}

int ocfs2_update_entry(struct inode *dir, handle_t *handle,
		       struct buffer_head *de_bh, struct ocfs2_dir_entry *de,
		       struct inode *new_entry_inode)
{
	int ret;

	ret = ocfs2_journal_access(handle, dir, de_bh,
				   OCFS2_JOURNAL_ACCESS_WRITE);
	if (ret) {
		mlog_errno(ret);
		goto out;
	}

	de->inode = cpu_to_le64(OCFS2_I(new_entry_inode)->ip_blkno);
	ocfs2_set_de_type(de, new_entry_inode->i_mode);

	ocfs2_journal_dirty(handle, de_bh);

out:
	return ret;
}

/*
 * ocfs2_delete_entry deletes a directory entry by merging it with the
 * previous entry
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ static inline int ocfs2_add_entry(handle_t *handle,
				 dentry->d_name.name, dentry->d_name.len,
				 inode, blkno, parent_fe_bh, insert_bh);
}
int ocfs2_update_entry(struct inode *dir, handle_t *handle,
		       struct buffer_head *de_bh, struct ocfs2_dir_entry *de,
		       struct inode *new_entry_inode);

int ocfs2_check_dir_for_entry(struct inode *dir,
			      const char *name,
+22 −31
Original line number Diff line number Diff line
@@ -933,11 +933,6 @@ static void ocfs2_double_unlock(struct inode *inode1, struct inode *inode2)
		ocfs2_meta_unlock(inode2, 1);
}

#define PARENT_INO(buffer) \
	((struct ocfs2_dir_entry *) \
	 ((char *)buffer + \
	  le16_to_cpu(((struct ocfs2_dir_entry *)buffer)->rec_len)))->inode

static int ocfs2_rename(struct inode *old_dir,
			struct dentry *old_dentry,
			struct inode *new_dir,
@@ -959,8 +954,8 @@ static int ocfs2_rename(struct inode *old_dir,
	handle_t *handle = NULL;
	struct buffer_head *old_dir_bh = NULL;
	struct buffer_head *new_dir_bh = NULL;
	struct ocfs2_dir_entry *old_de = NULL, *new_de = NULL; // dirent for old_dentry
							       // and new_dentry
	struct ocfs2_dir_entry *old_inode_dot_dot_de = NULL, *old_de = NULL,
		*new_de = NULL;
	struct buffer_head *new_de_bh = NULL, *old_de_bh = NULL; // bhs for above
	struct buffer_head *old_inode_de_bh = NULL; // if old_dentry is a dir,
						    // this is the 1st dirent bh
@@ -1044,20 +1039,27 @@ static int ocfs2_rename(struct inode *old_dir,
	}

	if (S_ISDIR(old_inode->i_mode)) {
		u64 old_inode_parent;

		status = ocfs2_find_files_on_disk("..", 2, &old_inode_parent,
						  old_inode, &old_inode_de_bh,
						  &old_inode_dot_dot_de);
		if (status) {
			status = -EIO;
		old_inode_de_bh = ocfs2_bread(old_inode, 0, &status, 0);
		if (!old_inode_de_bh)
			goto bail;
		}

		if (old_inode_parent != OCFS2_I(old_dir)->ip_blkno) {
			status = -EIO;
		if (le64_to_cpu(PARENT_INO(old_inode_de_bh->b_data)) !=
		    OCFS2_I(old_dir)->ip_blkno)
			goto bail;
		status = -EMLINK;
		}

		if (!new_inode && new_dir != old_dir &&
		    new_dir->i_nlink >= OCFS2_LINK_MAX)
		    new_dir->i_nlink >= OCFS2_LINK_MAX) {
			status = -EMLINK;
			goto bail;
		}
	}

	status = -ENOENT;
	old_de_bh = ocfs2_find_entry(old_dentry->d_name.name,
@@ -1206,20 +1208,13 @@ static int ocfs2_rename(struct inode *old_dir,
		}

		/* change the dirent to point to the correct inode */
		status = ocfs2_journal_access(handle, new_dir, new_de_bh,
					      OCFS2_JOURNAL_ACCESS_WRITE);
		status = ocfs2_update_entry(new_dir, handle, new_de_bh,
					    new_de, old_inode);
		if (status < 0) {
			mlog_errno(status);
			goto bail;
		}
		new_de->inode = cpu_to_le64(OCFS2_I(old_inode)->ip_blkno);
		new_de->file_type = old_de->file_type;
		new_dir->i_version++;
		status = ocfs2_journal_dirty(handle, new_de_bh);
		if (status < 0) {
			mlog_errno(status);
			goto bail;
		}

		if (S_ISDIR(new_inode->i_mode))
			newfe->i_links_count = 0;
@@ -1268,12 +1263,8 @@ static int ocfs2_rename(struct inode *old_dir,
	}
	old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
	if (old_inode_de_bh) {
		status = ocfs2_journal_access(handle, old_inode,
					     old_inode_de_bh,
					     OCFS2_JOURNAL_ACCESS_WRITE);
		PARENT_INO(old_inode_de_bh->b_data) =
			cpu_to_le64(OCFS2_I(new_dir)->ip_blkno);
		status = ocfs2_journal_dirty(handle, old_inode_de_bh);
		status = ocfs2_update_entry(old_inode, handle, old_inode_de_bh,
					    old_inode_dot_dot_de, new_dir);
		old_dir->i_nlink--;
		if (new_inode) {
			new_inode->i_nlink--;