Blame SOURCES/bz1942434-2-gfs2_jadd_Don_t_fsync_after_each_block_written.patch

957bb1
commit 11070364f04a111212efcc2604840eee71f32c8f
957bb1
Author: Andrew Price <anprice@redhat.com>
957bb1
Date:   Thu Mar 18 17:50:16 2021 +0000
957bb1
957bb1
    gfs2_jadd: Don't fsync after each block written
957bb1
    
957bb1
    gfs2_jadd has always called fsync() after writing each block of the
957bb1
    journal. There doesn't seem to be any need for that so take the fsync()
957bb1
    call out of the loop.
957bb1
    
957bb1
    Add an additional fsync() after preallocation to make sure we're in good
957bb1
    shape before writing the log headers.
957bb1
    
957bb1
    In my tests this reduces the time to add one journal from 5 minutes to
957bb1
    9 seconds.
957bb1
    
957bb1
    Resolves: rhbz#1942434
957bb1
    
957bb1
    Signed-off-by: Andrew Price <anprice@redhat.com>
957bb1
957bb1
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
957bb1
index b0cffbac..6aff97c3 100644
957bb1
--- a/gfs2/mkfs/main_jadd.c
957bb1
+++ b/gfs2/mkfs/main_jadd.c
957bb1
@@ -531,6 +531,11 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
957bb1
 	if (error != 0)
957bb1
 		goto close_fd;
957bb1
 
957bb1
+	error = fsync(fd);
957bb1
+	if (error != 0) {
957bb1
+		perror("Failed to sync journal metadata");
957bb1
+		goto close_fd;
957bb1
+	}
957bb1
 	if ((error = lseek(fd, 0, SEEK_SET)) < 0) {
957bb1
 		perror("add_j lseek");
957bb1
 		goto close_fd;
957bb1
@@ -574,12 +579,12 @@ static int add_j(struct gfs2_sbd *sdp, struct jadd_opts *opts)
957bb1
 			seq = 0;
957bb1
 		off += sdp->bsize;
957bb1
 
957bb1
-		if ((error = fsync(fd))) {
957bb1
-			perror("add_j fsync");
957bb1
-			goto close_fd;
957bb1
-		}
957bb1
 	}
957bb1
-
957bb1
+	error = fsync(fd);
957bb1
+	if (error != 0) {
957bb1
+		perror("Failed to sync journal metadata");
957bb1
+		goto close_fd;
957bb1
+	}
957bb1
 	sprintf(new_name, "journal%u", opts->journals);
957bb1
 	error = rename2system(opts, opts->jindex, new_name);
957bb1
 	if (error < 0 && errno != EEXIST){