linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock"
@ 2019-07-02 21:29 Theodore Ts'o
  2019-07-02 21:29 ` [PATCH 2/3] ext4: refactor initialize_dirent_tail() Theodore Ts'o
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Theodore Ts'o @ 2019-07-02 21:29 UTC (permalink / raw)
  To: Ext4 Developers List; +Cc: Theodore Ts'o

Functions such as ext4_dirent_csum_verify() and ext4_dirent_csum_set()
don't actually operate on a directory entry, but a directory block.
And while they take a struct ext4_dir_entry *dirent as an argument, it
had better be the first directory at the beginning of the direct
block, or things will go very wrong.

Rename the following functions so that things make more sense, and
remove a lot of confusing casts along the way:

   ext4_dirent_csum_verify	 -> ext4_dirblock_csum_verify
   ext4_dirent_csum_set		 -> ext4_dirblock_csum_set
   ext4_dirent_csum		 -> ext4_dirblock_csum
   ext4_handle_dirty_dirent_node -> ext4_handle_dirty_dirblock

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/dir.c    |  3 +--
 fs/ext4/ext4.h   |  9 ++++---
 fs/ext4/inline.c |  2 +-
 fs/ext4/namei.c  | 62 ++++++++++++++++++++++--------------------------
 4 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 3a77b7affd09..86054f31fe4d 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -194,8 +194,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
 
 		/* Check the checksum */
 		if (!buffer_verified(bh) &&
-		    !ext4_dirent_csum_verify(inode,
-				(struct ext4_dir_entry *)bh->b_data)) {
+		    !ext4_dirblock_csum_verify(inode, bh)) {
 			EXT4_ERROR_FILE(file, 0, "directory fails checksum "
 					"at offset %llu",
 					(unsigned long long)ctx->pos);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 7215a2a2a0de..5b86df7ec326 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2602,8 +2602,8 @@ extern int ext4_ext_migrate(struct inode *);
 extern int ext4_ind_migrate(struct inode *inode);
 
 /* namei.c */
-extern int ext4_dirent_csum_verify(struct inode *inode,
-				   struct ext4_dir_entry *dirent);
+extern int ext4_dirblock_csum_verify(struct inode *inode,
+				     struct buffer_head *bh);
 extern int ext4_orphan_add(handle_t *, struct inode *);
 extern int ext4_orphan_del(handle_t *, struct inode *);
 extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
@@ -3149,9 +3149,8 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
 				 unsigned int parent_ino, int dotdot_real_len);
 extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
 				   unsigned int blocksize);
-extern int ext4_handle_dirty_dirent_node(handle_t *handle,
-					 struct inode *inode,
-					 struct buffer_head *bh);
+extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
+				      struct buffer_head *bh);
 extern int ext4_ci_compare(const struct inode *parent,
 			   const struct qstr *fname,
 			   const struct qstr *entry, bool quick);
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index f73bc3925282..f19dd5a08d0d 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1164,7 +1164,7 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
 		initialize_dirent_tail(t, inode->i_sb->s_blocksize);
 	}
 	set_buffer_uptodate(dir_block);
-	err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
+	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
 	if (err)
 		return err;
 	set_buffer_verified(dir_block);
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 0cda080f3fd5..4f0bcbbcfe96 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -163,7 +163,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
 		}
 	}
 	if (!is_dx_block) {
-		if (ext4_dirent_csum_verify(inode, dirent))
+		if (ext4_dirblock_csum_verify(inode, bh))
 			set_buffer_verified(bh);
 		else {
 			ext4_error_inode(inode, func, line, block,
@@ -304,17 +304,17 @@ void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
 
 /* Walk through a dirent block to find a checksum "dirent" at the tail */
 static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
-						   struct ext4_dir_entry *de)
+						   struct buffer_head *bh)
 {
 	struct ext4_dir_entry_tail *t;
 
 #ifdef PARANOID
 	struct ext4_dir_entry *d, *top;
 
-	d = de;
-	top = (struct ext4_dir_entry *)(((void *)de) +
+	d = (struct ext4_dir_entry *)bh->b_data;
+	top = (struct ext4_dir_entry *)(bh->b_data +
 		(EXT4_BLOCK_SIZE(inode->i_sb) -
-		sizeof(struct ext4_dir_entry_tail)));
+		 sizeof(struct ext4_dir_entry_tail)));
 	while (d < top && d->rec_len)
 		d = (struct ext4_dir_entry *)(((void *)d) +
 		    le16_to_cpu(d->rec_len));
@@ -324,7 +324,7 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
 
 	t = (struct ext4_dir_entry_tail *)d;
 #else
-	t = EXT4_DIRENT_TAIL(de, EXT4_BLOCK_SIZE(inode->i_sb));
+	t = EXT4_DIRENT_TAIL(bh->b_data, EXT4_BLOCK_SIZE(inode->i_sb));
 #endif
 
 	if (t->det_reserved_zero1 ||
@@ -336,8 +336,7 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
 	return t;
 }
 
-static __le32 ext4_dirent_csum(struct inode *inode,
-			       struct ext4_dir_entry *dirent, int size)
+static __le32 ext4_dirblock_csum(struct inode *inode, void *dirent, int size)
 {
 	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
 	struct ext4_inode_info *ei = EXT4_I(inode);
@@ -357,49 +356,49 @@ static void __warn_no_space_for_csum(struct inode *inode, const char *func,
 		"No space for directory leaf checksum. Please run e2fsck -D.");
 }
 
-int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent)
+int ext4_dirblock_csum_verify(struct inode *inode, struct buffer_head *bh)
 {
 	struct ext4_dir_entry_tail *t;
 
 	if (!ext4_has_metadata_csum(inode->i_sb))
 		return 1;
 
-	t = get_dirent_tail(inode, dirent);
+	t = get_dirent_tail(inode, bh);
 	if (!t) {
 		warn_no_space_for_csum(inode);
 		return 0;
 	}
 
-	if (t->det_checksum != ext4_dirent_csum(inode, dirent,
-						(void *)t - (void *)dirent))
+	if (t->det_checksum != ext4_dirblock_csum(inode, bh->b_data,
+						(char *)t - bh->b_data))
 		return 0;
 
 	return 1;
 }
 
-static void ext4_dirent_csum_set(struct inode *inode,
-				 struct ext4_dir_entry *dirent)
+static void ext4_dirblock_csum_set(struct inode *inode,
+				 struct buffer_head *bh)
 {
 	struct ext4_dir_entry_tail *t;
 
 	if (!ext4_has_metadata_csum(inode->i_sb))
 		return;
 
-	t = get_dirent_tail(inode, dirent);
+	t = get_dirent_tail(inode, bh);
 	if (!t) {
 		warn_no_space_for_csum(inode);
 		return;
 	}
 
-	t->det_checksum = ext4_dirent_csum(inode, dirent,
-					   (void *)t - (void *)dirent);
+	t->det_checksum = ext4_dirblock_csum(inode, bh->b_data,
+					   (char *)t - bh->b_data);
 }
 
-int ext4_handle_dirty_dirent_node(handle_t *handle,
-				  struct inode *inode,
-				  struct buffer_head *bh)
+int ext4_handle_dirty_dirblock(handle_t *handle,
+			       struct inode *inode,
+			       struct buffer_head *bh)
 {
-	ext4_dirent_csum_set(inode, (struct ext4_dir_entry *)bh->b_data);
+	ext4_dirblock_csum_set(inode, bh);
 	return ext4_handle_dirty_metadata(handle, inode, bh);
 }
 
@@ -1530,8 +1529,7 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
 		if (!buffer_verified(bh) &&
 		    !is_dx_internal_node(dir, block,
 					 (struct ext4_dir_entry *)bh->b_data) &&
-		    !ext4_dirent_csum_verify(dir,
-				(struct ext4_dir_entry *)bh->b_data)) {
+		    !ext4_dirblock_csum_verify(dir, bh)) {
 			EXT4_ERROR_INODE(dir, "checksumming directory "
 					 "block %lu", (unsigned long)block);
 			brelse(bh);
@@ -1894,7 +1892,7 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
 		de = de2;
 	}
 	dx_insert_block(frame, hash2 + continued, newblock);
-	err = ext4_handle_dirty_dirent_node(handle, dir, bh2);
+	err = ext4_handle_dirty_dirblock(handle, dir, bh2);
 	if (err)
 		goto journal_error;
 	err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
@@ -2022,7 +2020,7 @@ static int add_dirent_to_buf(handle_t *handle, struct ext4_filename *fname,
 	inode_inc_iversion(dir);
 	ext4_mark_inode_dirty(handle, dir);
 	BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
-	err = ext4_handle_dirty_dirent_node(handle, dir, bh);
+	err = ext4_handle_dirty_dirblock(handle, dir, bh);
 	if (err)
 		ext4_std_error(dir->i_sb, err);
 	return 0;
@@ -2126,7 +2124,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 	retval = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
 	if (retval)
 		goto out_frames;	
-	retval = ext4_handle_dirty_dirent_node(handle, dir, bh2);
+	retval = ext4_handle_dirty_dirblock(handle, dir, bh2);
 	if (retval)
 		goto out_frames;	
 
@@ -2512,7 +2510,7 @@ static int ext4_delete_entry(handle_t *handle,
 		goto out;
 
 	BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
-	err = ext4_handle_dirty_dirent_node(handle, dir, bh);
+	err = ext4_handle_dirty_dirblock(handle, dir, bh);
 	if (unlikely(err))
 		goto out;
 
@@ -2744,7 +2742,7 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
 	}
 
 	BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
-	err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
+	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
 	if (err)
 		goto out;
 	set_buffer_verified(dir_block);
@@ -3492,9 +3490,8 @@ static int ext4_rename_dir_finish(handle_t *handle, struct ext4_renament *ent,
 							   ent->inode,
 							   ent->dir_bh);
 		} else {
-			retval = ext4_handle_dirty_dirent_node(handle,
-							       ent->inode,
-							       ent->dir_bh);
+			retval = ext4_handle_dirty_dirblock(handle, ent->inode,
+							    ent->dir_bh);
 		}
 	} else {
 		retval = ext4_mark_inode_dirty(handle, ent->inode);
@@ -3524,8 +3521,7 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent,
 	ext4_mark_inode_dirty(handle, ent->dir);
 	BUFFER_TRACE(ent->bh, "call ext4_handle_dirty_metadata");
 	if (!ent->inlined) {
-		retval = ext4_handle_dirty_dirent_node(handle,
-						       ent->dir, ent->bh);
+		retval = ext4_handle_dirty_dirblock(handle, ent->dir, ent->bh);
 		if (unlikely(retval)) {
 			ext4_std_error(ent->dir->i_sb, retval);
 			return retval;
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] ext4: refactor initialize_dirent_tail()
  2019-07-02 21:29 [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Theodore Ts'o
@ 2019-07-02 21:29 ` Theodore Ts'o
  2019-07-03  3:50   ` Darrick J. Wong
  2019-07-02 21:29 ` [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree() Theodore Ts'o
  2019-07-03  3:50 ` [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Darrick J. Wong
  2 siblings, 1 reply; 6+ messages in thread
From: Theodore Ts'o @ 2019-07-02 21:29 UTC (permalink / raw)
  To: Ext4 Developers List; +Cc: Theodore Ts'o

Move the calculation of the location of the dirent tail into
initialize_dirent_tail().  Also prefix the function with ext4_ to fix
kernel namepsace polution.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/ext4.h   |  4 ++--
 fs/ext4/inline.c |  9 +++-----
 fs/ext4/namei.c  | 54 +++++++++++++++++++-----------------------------
 3 files changed, 26 insertions(+), 41 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 5b86df7ec326..83128bdd7abb 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3147,8 +3147,8 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
 				 struct ext4_dir_entry_2 *de,
 				 int blocksize, int csum_size,
 				 unsigned int parent_ino, int dotdot_real_len);
-extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
-				   unsigned int blocksize);
+extern void ext4_initialize_dirent_tail(struct buffer_head *bh,
+					unsigned int blocksize);
 extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
 				      struct buffer_head *bh);
 extern int ext4_ci_compare(const struct inode *parent,
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index f19dd5a08d0d..796137bb7dfa 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1132,7 +1132,6 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
 {
 	int err, csum_size = 0, header_size = 0;
 	struct ext4_dir_entry_2 *de;
-	struct ext4_dir_entry_tail *t;
 	void *target = dir_block->b_data;
 
 	/*
@@ -1158,11 +1157,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
 			inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size,
 			inode->i_sb->s_blocksize - csum_size);
 
-	if (csum_size) {
-		t = EXT4_DIRENT_TAIL(dir_block->b_data,
-				     inode->i_sb->s_blocksize);
-		initialize_dirent_tail(t, inode->i_sb->s_blocksize);
-	}
+	if (csum_size)
+		ext4_initialize_dirent_tail(dir_block,
+					    inode->i_sb->s_blocksize);
 	set_buffer_uptodate(dir_block);
 	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
 	if (err)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 4f0bcbbcfe96..183ad614ae3d 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -293,9 +293,11 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 			     struct inode *dir, struct inode *inode);
 
 /* checksumming functions */
-void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
-			    unsigned int blocksize)
+void ext4_initialize_dirent_tail(struct buffer_head *bh,
+				 unsigned int blocksize)
 {
+	struct ext4_dir_entry_tail *t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
+
 	memset(t, 0, sizeof(struct ext4_dir_entry_tail));
 	t->det_rec_len = ext4_rec_len_to_disk(
 			sizeof(struct ext4_dir_entry_tail), blocksize);
@@ -370,7 +372,7 @@ int ext4_dirblock_csum_verify(struct inode *inode, struct buffer_head *bh)
 	}
 
 	if (t->det_checksum != ext4_dirblock_csum(inode, bh->b_data,
-						(char *)t - bh->b_data))
+						  (char *)t - bh->b_data))
 		return 0;
 
 	return 1;
@@ -391,7 +393,7 @@ static void ext4_dirblock_csum_set(struct inode *inode,
 	}
 
 	t->det_checksum = ext4_dirblock_csum(inode, bh->b_data,
-					   (char *)t - bh->b_data);
+					     (char *)t - bh->b_data);
 }
 
 int ext4_handle_dirty_dirblock(handle_t *handle,
@@ -1813,7 +1815,6 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
 	char *data1 = (*bh)->b_data, *data2;
 	unsigned split, move, size;
 	struct ext4_dir_entry_2 *de = NULL, *de2;
-	struct ext4_dir_entry_tail *t;
 	int	csum_size = 0;
 	int	err = 0, i;
 
@@ -1874,11 +1875,8 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
 					    (char *) de2,
 					    blocksize);
 	if (csum_size) {
-		t = EXT4_DIRENT_TAIL(data2, blocksize);
-		initialize_dirent_tail(t, blocksize);
-
-		t = EXT4_DIRENT_TAIL(data1, blocksize);
-		initialize_dirent_tail(t, blocksize);
+		ext4_initialize_dirent_tail(*bh, blocksize);
+		ext4_initialize_dirent_tail(bh2, blocksize);
 	}
 
 	dxtrace(dx_show_leaf(dir, hinfo, (struct ext4_dir_entry_2 *) data1,
@@ -2039,8 +2037,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 	struct dx_frame	frames[EXT4_HTREE_LEVEL], *frame;
 	struct dx_entry *entries;
 	struct ext4_dir_entry_2	*de, *de2;
-	struct ext4_dir_entry_tail *t;
-	char		*data1, *top;
+	char		*data2, *top;
 	unsigned	len;
 	int		retval;
 	unsigned	blocksize;
@@ -2080,21 +2077,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
 		return PTR_ERR(bh2);
 	}
 	ext4_set_inode_flag(dir, EXT4_INODE_INDEX);
-	data1 = bh2->b_data;
+	data2 = bh2->b_data;
 
-	memcpy (data1, de, len);
-	de = (struct ext4_dir_entry_2 *) data1;
-	top = data1 + len;
+	memcpy(data2, de, len);
+	de = (struct ext4_dir_entry_2 *) data2;
+	top = data2 + len;
 	while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top)
 		de = de2;
-	de->rec_len = ext4_rec_len_to_disk(data1 + (blocksize - csum_size) -
-					   (char *) de,
-					   blocksize);
+	de->rec_len = ext4_rec_len_to_disk(data2 + (blocksize - csum_size) -
+					   (char *) de, blocksize);
 
-	if (csum_size) {
-		t = EXT4_DIRENT_TAIL(data1, blocksize);
-		initialize_dirent_tail(t, blocksize);
-	}
+	if (csum_size)
+		ext4_initialize_dirent_tail(bh2, blocksize);
 
 	/* Initialize the root; the dot dirents already exist */
 	de = (struct ext4_dir_entry_2 *) (&root->dotdot);
@@ -2164,7 +2158,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
 	struct inode *dir = d_inode(dentry->d_parent);
 	struct buffer_head *bh = NULL;
 	struct ext4_dir_entry_2 *de;
-	struct ext4_dir_entry_tail *t;
 	struct super_block *sb;
 	struct ext4_sb_info *sbi;
 	struct ext4_filename fname;
@@ -2249,10 +2242,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
 	de->inode = 0;
 	de->rec_len = ext4_rec_len_to_disk(blocksize - csum_size, blocksize);
 
-	if (csum_size) {
-		t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
-		initialize_dirent_tail(t, blocksize);
-	}
+	if (csum_size)
+		ext4_initialize_dirent_tail(bh, blocksize);
 
 	retval = add_dirent_to_buf(handle, &fname, dir, inode, de, bh);
 out:
@@ -2712,7 +2703,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
 {
 	struct buffer_head *dir_block = NULL;
 	struct ext4_dir_entry_2 *de;
-	struct ext4_dir_entry_tail *t;
 	ext4_lblk_t block = 0;
 	unsigned int blocksize = dir->i_sb->s_blocksize;
 	int csum_size = 0;
@@ -2736,10 +2726,8 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
 	de = (struct ext4_dir_entry_2 *)dir_block->b_data;
 	ext4_init_dot_dotdot(inode, de, blocksize, csum_size, dir->i_ino, 0);
 	set_nlink(inode, 2);
-	if (csum_size) {
-		t = EXT4_DIRENT_TAIL(dir_block->b_data, blocksize);
-		initialize_dirent_tail(t, blocksize);
-	}
+	if (csum_size)
+		ext4_initialize_dirent_tail(dir_block, blocksize);
 
 	BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
 	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree()
  2019-07-02 21:29 [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Theodore Ts'o
  2019-07-02 21:29 ` [PATCH 2/3] ext4: refactor initialize_dirent_tail() Theodore Ts'o
@ 2019-07-02 21:29 ` Theodore Ts'o
  2019-07-03  3:50   ` Darrick J. Wong
  2019-07-03  3:50 ` [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Darrick J. Wong
  2 siblings, 1 reply; 6+ messages in thread
From: Theodore Ts'o @ 2019-07-02 21:29 UTC (permalink / raw)
  To: Ext4 Developers List; +Cc: Theodore Ts'o

Clean up namespace pollution by the inline_data code.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 fs/ext4/ext4.h   | 10 +++++-----
 fs/ext4/inline.c | 10 +++++-----
 fs/ext4/namei.c  |  8 ++++----
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 83128bdd7abb..bf660aa7a9e0 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -3104,11 +3104,11 @@ extern int ext4_try_create_inline_dir(handle_t *handle,
 extern int ext4_read_inline_dir(struct file *filp,
 				struct dir_context *ctx,
 				int *has_inline_data);
-extern int htree_inlinedir_to_tree(struct file *dir_file,
-				   struct inode *dir, ext4_lblk_t block,
-				   struct dx_hash_info *hinfo,
-				   __u32 start_hash, __u32 start_minor_hash,
-				   int *has_inline_data);
+extern int ext4_inlinedir_to_tree(struct file *dir_file,
+				  struct inode *dir, ext4_lblk_t block,
+				  struct dx_hash_info *hinfo,
+				  __u32 start_hash, __u32 start_minor_hash,
+				  int *has_inline_data);
 extern struct buffer_head *ext4_find_inline_entry(struct inode *dir,
 					struct ext4_filename *fname,
 					struct ext4_dir_entry_2 **res_dir,
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 796137bb7dfa..88cdf3c90bd1 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1324,11 +1324,11 @@ int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
  * inlined dir.  It returns the number directory entries loaded
  * into the tree.  If there is an error it is returned in err.
  */
-int htree_inlinedir_to_tree(struct file *dir_file,
-			    struct inode *dir, ext4_lblk_t block,
-			    struct dx_hash_info *hinfo,
-			    __u32 start_hash, __u32 start_minor_hash,
-			    int *has_inline_data)
+int ext4_inlinedir_to_tree(struct file *dir_file,
+			   struct inode *dir, ext4_lblk_t block,
+			   struct dx_hash_info *hinfo,
+			   __u32 start_hash, __u32 start_minor_hash,
+			   int *has_inline_data)
 {
 	int err = 0, count = 0;
 	unsigned int parent_ino;
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 183ad614ae3d..c9568fee9e11 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1104,10 +1104,10 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
 		hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
 		if (ext4_has_inline_data(dir)) {
 			int has_inline_data = 1;
-			count = htree_inlinedir_to_tree(dir_file, dir, 0,
-							&hinfo, start_hash,
-							start_minor_hash,
-							&has_inline_data);
+			count = ext4_inlinedir_to_tree(dir_file, dir, 0,
+						       &hinfo, start_hash,
+						       start_minor_hash,
+						       &has_inline_data);
 			if (has_inline_data) {
 				*next_hash = ~0;
 				return count;
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock"
  2019-07-02 21:29 [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Theodore Ts'o
  2019-07-02 21:29 ` [PATCH 2/3] ext4: refactor initialize_dirent_tail() Theodore Ts'o
  2019-07-02 21:29 ` [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree() Theodore Ts'o
@ 2019-07-03  3:50 ` Darrick J. Wong
  2 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2019-07-03  3:50 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Ext4 Developers List

On Tue, Jul 02, 2019 at 05:29:23PM -0400, Theodore Ts'o wrote:
> Functions such as ext4_dirent_csum_verify() and ext4_dirent_csum_set()
> don't actually operate on a directory entry, but a directory block.
> And while they take a struct ext4_dir_entry *dirent as an argument, it
> had better be the first directory at the beginning of the direct
> block, or things will go very wrong.
> 
> Rename the following functions so that things make more sense, and
> remove a lot of confusing casts along the way:
> 
>    ext4_dirent_csum_verify	 -> ext4_dirblock_csum_verify
>    ext4_dirent_csum_set		 -> ext4_dirblock_csum_set
>    ext4_dirent_csum		 -> ext4_dirblock_csum
>    ext4_handle_dirty_dirent_node -> ext4_handle_dirty_dirblock
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/ext4/dir.c    |  3 +--
>  fs/ext4/ext4.h   |  9 ++++---
>  fs/ext4/inline.c |  2 +-
>  fs/ext4/namei.c  | 62 ++++++++++++++++++++++--------------------------
>  4 files changed, 35 insertions(+), 41 deletions(-)
> 
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index 3a77b7affd09..86054f31fe4d 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -194,8 +194,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
>  
>  		/* Check the checksum */
>  		if (!buffer_verified(bh) &&
> -		    !ext4_dirent_csum_verify(inode,
> -				(struct ext4_dir_entry *)bh->b_data)) {
> +		    !ext4_dirblock_csum_verify(inode, bh)) {
>  			EXT4_ERROR_FILE(file, 0, "directory fails checksum "
>  					"at offset %llu",
>  					(unsigned long long)ctx->pos);
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 7215a2a2a0de..5b86df7ec326 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -2602,8 +2602,8 @@ extern int ext4_ext_migrate(struct inode *);
>  extern int ext4_ind_migrate(struct inode *inode);
>  
>  /* namei.c */
> -extern int ext4_dirent_csum_verify(struct inode *inode,
> -				   struct ext4_dir_entry *dirent);
> +extern int ext4_dirblock_csum_verify(struct inode *inode,
> +				     struct buffer_head *bh);
>  extern int ext4_orphan_add(handle_t *, struct inode *);
>  extern int ext4_orphan_del(handle_t *, struct inode *);
>  extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
> @@ -3149,9 +3149,8 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
>  				 unsigned int parent_ino, int dotdot_real_len);
>  extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
>  				   unsigned int blocksize);
> -extern int ext4_handle_dirty_dirent_node(handle_t *handle,
> -					 struct inode *inode,
> -					 struct buffer_head *bh);
> +extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
> +				      struct buffer_head *bh);
>  extern int ext4_ci_compare(const struct inode *parent,
>  			   const struct qstr *fname,
>  			   const struct qstr *entry, bool quick);
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index f73bc3925282..f19dd5a08d0d 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
> @@ -1164,7 +1164,7 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
>  		initialize_dirent_tail(t, inode->i_sb->s_blocksize);
>  	}
>  	set_buffer_uptodate(dir_block);
> -	err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
> +	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
>  	if (err)
>  		return err;
>  	set_buffer_verified(dir_block);
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 0cda080f3fd5..4f0bcbbcfe96 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -163,7 +163,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
>  		}
>  	}
>  	if (!is_dx_block) {
> -		if (ext4_dirent_csum_verify(inode, dirent))
> +		if (ext4_dirblock_csum_verify(inode, bh))
>  			set_buffer_verified(bh);
>  		else {
>  			ext4_error_inode(inode, func, line, block,
> @@ -304,17 +304,17 @@ void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
>  
>  /* Walk through a dirent block to find a checksum "dirent" at the tail */
>  static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
> -						   struct ext4_dir_entry *de)
> +						   struct buffer_head *bh)
>  {
>  	struct ext4_dir_entry_tail *t;
>  
>  #ifdef PARANOID
>  	struct ext4_dir_entry *d, *top;
>  
> -	d = de;
> -	top = (struct ext4_dir_entry *)(((void *)de) +
> +	d = (struct ext4_dir_entry *)bh->b_data;
> +	top = (struct ext4_dir_entry *)(bh->b_data +
>  		(EXT4_BLOCK_SIZE(inode->i_sb) -
> -		sizeof(struct ext4_dir_entry_tail)));
> +		 sizeof(struct ext4_dir_entry_tail)));
>  	while (d < top && d->rec_len)
>  		d = (struct ext4_dir_entry *)(((void *)d) +
>  		    le16_to_cpu(d->rec_len));
> @@ -324,7 +324,7 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
>  
>  	t = (struct ext4_dir_entry_tail *)d;
>  #else
> -	t = EXT4_DIRENT_TAIL(de, EXT4_BLOCK_SIZE(inode->i_sb));
> +	t = EXT4_DIRENT_TAIL(bh->b_data, EXT4_BLOCK_SIZE(inode->i_sb));
>  #endif
>  
>  	if (t->det_reserved_zero1 ||
> @@ -336,8 +336,7 @@ static struct ext4_dir_entry_tail *get_dirent_tail(struct inode *inode,
>  	return t;
>  }
>  
> -static __le32 ext4_dirent_csum(struct inode *inode,
> -			       struct ext4_dir_entry *dirent, int size)
> +static __le32 ext4_dirblock_csum(struct inode *inode, void *dirent, int size)
>  {
>  	struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
>  	struct ext4_inode_info *ei = EXT4_I(inode);
> @@ -357,49 +356,49 @@ static void __warn_no_space_for_csum(struct inode *inode, const char *func,
>  		"No space for directory leaf checksum. Please run e2fsck -D.");
>  }
>  
> -int ext4_dirent_csum_verify(struct inode *inode, struct ext4_dir_entry *dirent)
> +int ext4_dirblock_csum_verify(struct inode *inode, struct buffer_head *bh)
>  {
>  	struct ext4_dir_entry_tail *t;
>  
>  	if (!ext4_has_metadata_csum(inode->i_sb))
>  		return 1;
>  
> -	t = get_dirent_tail(inode, dirent);
> +	t = get_dirent_tail(inode, bh);
>  	if (!t) {
>  		warn_no_space_for_csum(inode);
>  		return 0;
>  	}
>  
> -	if (t->det_checksum != ext4_dirent_csum(inode, dirent,
> -						(void *)t - (void *)dirent))
> +	if (t->det_checksum != ext4_dirblock_csum(inode, bh->b_data,
> +						(char *)t - bh->b_data))
>  		return 0;
>  
>  	return 1;
>  }
>  
> -static void ext4_dirent_csum_set(struct inode *inode,
> -				 struct ext4_dir_entry *dirent)
> +static void ext4_dirblock_csum_set(struct inode *inode,
> +				 struct buffer_head *bh)
>  {
>  	struct ext4_dir_entry_tail *t;
>  
>  	if (!ext4_has_metadata_csum(inode->i_sb))
>  		return;
>  
> -	t = get_dirent_tail(inode, dirent);
> +	t = get_dirent_tail(inode, bh);
>  	if (!t) {
>  		warn_no_space_for_csum(inode);
>  		return;
>  	}
>  
> -	t->det_checksum = ext4_dirent_csum(inode, dirent,
> -					   (void *)t - (void *)dirent);
> +	t->det_checksum = ext4_dirblock_csum(inode, bh->b_data,
> +					   (char *)t - bh->b_data);
>  }
>  
> -int ext4_handle_dirty_dirent_node(handle_t *handle,
> -				  struct inode *inode,
> -				  struct buffer_head *bh)
> +int ext4_handle_dirty_dirblock(handle_t *handle,
> +			       struct inode *inode,
> +			       struct buffer_head *bh)
>  {
> -	ext4_dirent_csum_set(inode, (struct ext4_dir_entry *)bh->b_data);
> +	ext4_dirblock_csum_set(inode, bh);
>  	return ext4_handle_dirty_metadata(handle, inode, bh);
>  }
>  
> @@ -1530,8 +1529,7 @@ static struct buffer_head *__ext4_find_entry(struct inode *dir,
>  		if (!buffer_verified(bh) &&
>  		    !is_dx_internal_node(dir, block,
>  					 (struct ext4_dir_entry *)bh->b_data) &&
> -		    !ext4_dirent_csum_verify(dir,
> -				(struct ext4_dir_entry *)bh->b_data)) {
> +		    !ext4_dirblock_csum_verify(dir, bh)) {
>  			EXT4_ERROR_INODE(dir, "checksumming directory "
>  					 "block %lu", (unsigned long)block);
>  			brelse(bh);
> @@ -1894,7 +1892,7 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
>  		de = de2;
>  	}
>  	dx_insert_block(frame, hash2 + continued, newblock);
> -	err = ext4_handle_dirty_dirent_node(handle, dir, bh2);
> +	err = ext4_handle_dirty_dirblock(handle, dir, bh2);
>  	if (err)
>  		goto journal_error;
>  	err = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
> @@ -2022,7 +2020,7 @@ static int add_dirent_to_buf(handle_t *handle, struct ext4_filename *fname,
>  	inode_inc_iversion(dir);
>  	ext4_mark_inode_dirty(handle, dir);
>  	BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
> -	err = ext4_handle_dirty_dirent_node(handle, dir, bh);
> +	err = ext4_handle_dirty_dirblock(handle, dir, bh);
>  	if (err)
>  		ext4_std_error(dir->i_sb, err);
>  	return 0;
> @@ -2126,7 +2124,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
>  	retval = ext4_handle_dirty_dx_node(handle, dir, frame->bh);
>  	if (retval)
>  		goto out_frames;	
> -	retval = ext4_handle_dirty_dirent_node(handle, dir, bh2);
> +	retval = ext4_handle_dirty_dirblock(handle, dir, bh2);
>  	if (retval)
>  		goto out_frames;	
>  
> @@ -2512,7 +2510,7 @@ static int ext4_delete_entry(handle_t *handle,
>  		goto out;
>  
>  	BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
> -	err = ext4_handle_dirty_dirent_node(handle, dir, bh);
> +	err = ext4_handle_dirty_dirblock(handle, dir, bh);
>  	if (unlikely(err))
>  		goto out;
>  
> @@ -2744,7 +2742,7 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
>  	}
>  
>  	BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
> -	err = ext4_handle_dirty_dirent_node(handle, inode, dir_block);
> +	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
>  	if (err)
>  		goto out;
>  	set_buffer_verified(dir_block);
> @@ -3492,9 +3490,8 @@ static int ext4_rename_dir_finish(handle_t *handle, struct ext4_renament *ent,
>  							   ent->inode,
>  							   ent->dir_bh);
>  		} else {
> -			retval = ext4_handle_dirty_dirent_node(handle,
> -							       ent->inode,
> -							       ent->dir_bh);
> +			retval = ext4_handle_dirty_dirblock(handle, ent->inode,
> +							    ent->dir_bh);
>  		}
>  	} else {
>  		retval = ext4_mark_inode_dirty(handle, ent->inode);
> @@ -3524,8 +3521,7 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent,
>  	ext4_mark_inode_dirty(handle, ent->dir);
>  	BUFFER_TRACE(ent->bh, "call ext4_handle_dirty_metadata");
>  	if (!ent->inlined) {
> -		retval = ext4_handle_dirty_dirent_node(handle,
> -						       ent->dir, ent->bh);
> +		retval = ext4_handle_dirty_dirblock(handle, ent->dir, ent->bh);
>  		if (unlikely(retval)) {
>  			ext4_std_error(ent->dir->i_sb, retval);
>  			return retval;
> -- 
> 2.22.0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] ext4: refactor initialize_dirent_tail()
  2019-07-02 21:29 ` [PATCH 2/3] ext4: refactor initialize_dirent_tail() Theodore Ts'o
@ 2019-07-03  3:50   ` Darrick J. Wong
  0 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2019-07-03  3:50 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Ext4 Developers List

On Tue, Jul 02, 2019 at 05:29:24PM -0400, Theodore Ts'o wrote:
> Move the calculation of the location of the dirent tail into
> initialize_dirent_tail().  Also prefix the function with ext4_ to fix
> kernel namepsace polution.
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/ext4/ext4.h   |  4 ++--
>  fs/ext4/inline.c |  9 +++-----
>  fs/ext4/namei.c  | 54 +++++++++++++++++++-----------------------------
>  3 files changed, 26 insertions(+), 41 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 5b86df7ec326..83128bdd7abb 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -3147,8 +3147,8 @@ extern struct ext4_dir_entry_2 *ext4_init_dot_dotdot(struct inode *inode,
>  				 struct ext4_dir_entry_2 *de,
>  				 int blocksize, int csum_size,
>  				 unsigned int parent_ino, int dotdot_real_len);
> -extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
> -				   unsigned int blocksize);
> +extern void ext4_initialize_dirent_tail(struct buffer_head *bh,
> +					unsigned int blocksize);
>  extern int ext4_handle_dirty_dirblock(handle_t *handle, struct inode *inode,
>  				      struct buffer_head *bh);
>  extern int ext4_ci_compare(const struct inode *parent,
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index f19dd5a08d0d..796137bb7dfa 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
> @@ -1132,7 +1132,6 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
>  {
>  	int err, csum_size = 0, header_size = 0;
>  	struct ext4_dir_entry_2 *de;
> -	struct ext4_dir_entry_tail *t;
>  	void *target = dir_block->b_data;
>  
>  	/*
> @@ -1158,11 +1157,9 @@ static int ext4_finish_convert_inline_dir(handle_t *handle,
>  			inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size,
>  			inode->i_sb->s_blocksize - csum_size);
>  
> -	if (csum_size) {
> -		t = EXT4_DIRENT_TAIL(dir_block->b_data,
> -				     inode->i_sb->s_blocksize);
> -		initialize_dirent_tail(t, inode->i_sb->s_blocksize);
> -	}
> +	if (csum_size)
> +		ext4_initialize_dirent_tail(dir_block,
> +					    inode->i_sb->s_blocksize);
>  	set_buffer_uptodate(dir_block);
>  	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
>  	if (err)
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 4f0bcbbcfe96..183ad614ae3d 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -293,9 +293,11 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			     struct inode *dir, struct inode *inode);
>  
>  /* checksumming functions */
> -void initialize_dirent_tail(struct ext4_dir_entry_tail *t,
> -			    unsigned int blocksize)
> +void ext4_initialize_dirent_tail(struct buffer_head *bh,
> +				 unsigned int blocksize)
>  {
> +	struct ext4_dir_entry_tail *t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
> +
>  	memset(t, 0, sizeof(struct ext4_dir_entry_tail));
>  	t->det_rec_len = ext4_rec_len_to_disk(
>  			sizeof(struct ext4_dir_entry_tail), blocksize);
> @@ -370,7 +372,7 @@ int ext4_dirblock_csum_verify(struct inode *inode, struct buffer_head *bh)
>  	}
>  
>  	if (t->det_checksum != ext4_dirblock_csum(inode, bh->b_data,
> -						(char *)t - bh->b_data))
> +						  (char *)t - bh->b_data))
>  		return 0;
>  
>  	return 1;
> @@ -391,7 +393,7 @@ static void ext4_dirblock_csum_set(struct inode *inode,
>  	}
>  
>  	t->det_checksum = ext4_dirblock_csum(inode, bh->b_data,
> -					   (char *)t - bh->b_data);
> +					     (char *)t - bh->b_data);
>  }
>  
>  int ext4_handle_dirty_dirblock(handle_t *handle,
> @@ -1813,7 +1815,6 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
>  	char *data1 = (*bh)->b_data, *data2;
>  	unsigned split, move, size;
>  	struct ext4_dir_entry_2 *de = NULL, *de2;
> -	struct ext4_dir_entry_tail *t;
>  	int	csum_size = 0;
>  	int	err = 0, i;
>  
> @@ -1874,11 +1875,8 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
>  					    (char *) de2,
>  					    blocksize);
>  	if (csum_size) {
> -		t = EXT4_DIRENT_TAIL(data2, blocksize);
> -		initialize_dirent_tail(t, blocksize);
> -
> -		t = EXT4_DIRENT_TAIL(data1, blocksize);
> -		initialize_dirent_tail(t, blocksize);
> +		ext4_initialize_dirent_tail(*bh, blocksize);
> +		ext4_initialize_dirent_tail(bh2, blocksize);
>  	}
>  
>  	dxtrace(dx_show_leaf(dir, hinfo, (struct ext4_dir_entry_2 *) data1,
> @@ -2039,8 +2037,7 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
>  	struct dx_frame	frames[EXT4_HTREE_LEVEL], *frame;
>  	struct dx_entry *entries;
>  	struct ext4_dir_entry_2	*de, *de2;
> -	struct ext4_dir_entry_tail *t;
> -	char		*data1, *top;
> +	char		*data2, *top;
>  	unsigned	len;
>  	int		retval;
>  	unsigned	blocksize;
> @@ -2080,21 +2077,18 @@ static int make_indexed_dir(handle_t *handle, struct ext4_filename *fname,
>  		return PTR_ERR(bh2);
>  	}
>  	ext4_set_inode_flag(dir, EXT4_INODE_INDEX);
> -	data1 = bh2->b_data;
> +	data2 = bh2->b_data;
>  
> -	memcpy (data1, de, len);
> -	de = (struct ext4_dir_entry_2 *) data1;
> -	top = data1 + len;
> +	memcpy(data2, de, len);
> +	de = (struct ext4_dir_entry_2 *) data2;
> +	top = data2 + len;
>  	while ((char *)(de2 = ext4_next_entry(de, blocksize)) < top)
>  		de = de2;
> -	de->rec_len = ext4_rec_len_to_disk(data1 + (blocksize - csum_size) -
> -					   (char *) de,
> -					   blocksize);
> +	de->rec_len = ext4_rec_len_to_disk(data2 + (blocksize - csum_size) -
> +					   (char *) de, blocksize);
>  
> -	if (csum_size) {
> -		t = EXT4_DIRENT_TAIL(data1, blocksize);
> -		initialize_dirent_tail(t, blocksize);
> -	}
> +	if (csum_size)
> +		ext4_initialize_dirent_tail(bh2, blocksize);
>  
>  	/* Initialize the root; the dot dirents already exist */
>  	de = (struct ext4_dir_entry_2 *) (&root->dotdot);
> @@ -2164,7 +2158,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
>  	struct inode *dir = d_inode(dentry->d_parent);
>  	struct buffer_head *bh = NULL;
>  	struct ext4_dir_entry_2 *de;
> -	struct ext4_dir_entry_tail *t;
>  	struct super_block *sb;
>  	struct ext4_sb_info *sbi;
>  	struct ext4_filename fname;
> @@ -2249,10 +2242,8 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
>  	de->inode = 0;
>  	de->rec_len = ext4_rec_len_to_disk(blocksize - csum_size, blocksize);
>  
> -	if (csum_size) {
> -		t = EXT4_DIRENT_TAIL(bh->b_data, blocksize);
> -		initialize_dirent_tail(t, blocksize);
> -	}
> +	if (csum_size)
> +		ext4_initialize_dirent_tail(bh, blocksize);
>  
>  	retval = add_dirent_to_buf(handle, &fname, dir, inode, de, bh);
>  out:
> @@ -2712,7 +2703,6 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
>  {
>  	struct buffer_head *dir_block = NULL;
>  	struct ext4_dir_entry_2 *de;
> -	struct ext4_dir_entry_tail *t;
>  	ext4_lblk_t block = 0;
>  	unsigned int blocksize = dir->i_sb->s_blocksize;
>  	int csum_size = 0;
> @@ -2736,10 +2726,8 @@ static int ext4_init_new_dir(handle_t *handle, struct inode *dir,
>  	de = (struct ext4_dir_entry_2 *)dir_block->b_data;
>  	ext4_init_dot_dotdot(inode, de, blocksize, csum_size, dir->i_ino, 0);
>  	set_nlink(inode, 2);
> -	if (csum_size) {
> -		t = EXT4_DIRENT_TAIL(dir_block->b_data, blocksize);
> -		initialize_dirent_tail(t, blocksize);
> -	}
> +	if (csum_size)
> +		ext4_initialize_dirent_tail(dir_block, blocksize);
>  
>  	BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
>  	err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
> -- 
> 2.22.0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree()
  2019-07-02 21:29 ` [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree() Theodore Ts'o
@ 2019-07-03  3:50   ` Darrick J. Wong
  0 siblings, 0 replies; 6+ messages in thread
From: Darrick J. Wong @ 2019-07-03  3:50 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: Ext4 Developers List

On Tue, Jul 02, 2019 at 05:29:25PM -0400, Theodore Ts'o wrote:
> Clean up namespace pollution by the inline_data code.
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/ext4/ext4.h   | 10 +++++-----
>  fs/ext4/inline.c | 10 +++++-----
>  fs/ext4/namei.c  |  8 ++++----
>  3 files changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 83128bdd7abb..bf660aa7a9e0 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -3104,11 +3104,11 @@ extern int ext4_try_create_inline_dir(handle_t *handle,
>  extern int ext4_read_inline_dir(struct file *filp,
>  				struct dir_context *ctx,
>  				int *has_inline_data);
> -extern int htree_inlinedir_to_tree(struct file *dir_file,
> -				   struct inode *dir, ext4_lblk_t block,
> -				   struct dx_hash_info *hinfo,
> -				   __u32 start_hash, __u32 start_minor_hash,
> -				   int *has_inline_data);
> +extern int ext4_inlinedir_to_tree(struct file *dir_file,
> +				  struct inode *dir, ext4_lblk_t block,
> +				  struct dx_hash_info *hinfo,
> +				  __u32 start_hash, __u32 start_minor_hash,
> +				  int *has_inline_data);
>  extern struct buffer_head *ext4_find_inline_entry(struct inode *dir,
>  					struct ext4_filename *fname,
>  					struct ext4_dir_entry_2 **res_dir,
> diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
> index 796137bb7dfa..88cdf3c90bd1 100644
> --- a/fs/ext4/inline.c
> +++ b/fs/ext4/inline.c
> @@ -1324,11 +1324,11 @@ int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
>   * inlined dir.  It returns the number directory entries loaded
>   * into the tree.  If there is an error it is returned in err.
>   */
> -int htree_inlinedir_to_tree(struct file *dir_file,
> -			    struct inode *dir, ext4_lblk_t block,
> -			    struct dx_hash_info *hinfo,
> -			    __u32 start_hash, __u32 start_minor_hash,
> -			    int *has_inline_data)
> +int ext4_inlinedir_to_tree(struct file *dir_file,
> +			   struct inode *dir, ext4_lblk_t block,
> +			   struct dx_hash_info *hinfo,
> +			   __u32 start_hash, __u32 start_minor_hash,
> +			   int *has_inline_data)
>  {
>  	int err = 0, count = 0;
>  	unsigned int parent_ino;
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 183ad614ae3d..c9568fee9e11 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -1104,10 +1104,10 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
>  		hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
>  		if (ext4_has_inline_data(dir)) {
>  			int has_inline_data = 1;
> -			count = htree_inlinedir_to_tree(dir_file, dir, 0,
> -							&hinfo, start_hash,
> -							start_minor_hash,
> -							&has_inline_data);
> +			count = ext4_inlinedir_to_tree(dir_file, dir, 0,
> +						       &hinfo, start_hash,
> +						       start_minor_hash,
> +						       &has_inline_data);
>  			if (has_inline_data) {
>  				*next_hash = ~0;
>  				return count;
> -- 
> 2.22.0
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-03  3:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02 21:29 [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Theodore Ts'o
2019-07-02 21:29 ` [PATCH 2/3] ext4: refactor initialize_dirent_tail() Theodore Ts'o
2019-07-03  3:50   ` Darrick J. Wong
2019-07-02 21:29 ` [PATCH 3/3] ext4: rename htree_inline_dir_to_tree() to ext4_inlinedir_to_tree() Theodore Ts'o
2019-07-03  3:50   ` Darrick J. Wong
2019-07-03  3:50 ` [PATCH 1/3] ext4: rename "dirent_csum" functions to use "dirblock" Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).