[Ocfs2-tools-devel] [PATCH] mkfs: code cleanup in mkfs_swap_dir()

Coly Li i at coly.li
Thu Sep 27 21:04:18 PDT 2012


When swap directory entries, if trailer is not supported, we don't have
to get trailer object by calling ocfs2_dir_trailer_from_block(). While
if directory trailer is not supported, meta_ecc will not supported, we
don't have to call ocfs2_compute_meta_ecc() neither.

This patch tries to clean up the code, we only swap trailer and do
meta_ecc when directory trailer existing (a.k.a end != s->blocksize
in the code).

Signed-off-by: Coly Li <i at coly.li>
Cc: Joel Becker <jlbec at evilplan.org>
---
 mkfs.ocfs2/mkfs.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index 7abea73..9c97e41 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -2674,12 +2674,15 @@ static void mkfs_swap_dir(State *s, DirData *dir,
 			end = ocfs2_dir_trailer_blk_off(&fake_fs);
 
 	while (offset < dir->record->file_size) {
-		trailer = ocfs2_dir_trailer_from_block(&fake_fs, p);
 		swap_entry_func(p, end);
-		if (end != s->blocksize)
+		/* we have trailer to handle */
+		if (end != s->blocksize) {
+			trailer = ocfs2_dir_trailer_from_block(&fake_fs, p);
 			ocfs2_swap_dir_trailer(trailer);
-		/* Remember, this does nothing if the feature isn't set */
-		ocfs2_compute_meta_ecc(&fake_fs, p, &trailer->db_check);
+			/* Remember, this does nothing if
+			 * the feature isn't set */
+			ocfs2_compute_meta_ecc(&fake_fs, p, &trailer->db_check);
+		}
 		offset += s->blocksize;
 		p += s->blocksize;
 	}



More information about the Ocfs2-tools-devel mailing list