Blame SOURCES/bz1154786-fsck_gfs2_Improve_reporting_of_pass_timings.patch

7ddfb4
commit 34ab6e375e654b5b8b4c4c3c01e12c9f9749a928
7ddfb4
Author: Andrew Price <anprice@redhat.com>
7ddfb4
Date:   Thu Nov 13 07:43:01 2014 -0500
7ddfb4
7ddfb4
    fsck.gfs2: Improve reporting of pass timings
7ddfb4
    
7ddfb4
    The days value is not currently reported in the pass timings but the
7ddfb4
    hours value is still reported modulo 24.  Drop the use of gmtime(3) as
7ddfb4
    it's more appropriate for calendar time operations than elapsed time,
7ddfb4
    and add a simple duration reporting function which matches the existing
7ddfb4
    output format.
7ddfb4
    
7ddfb4
    Resolves: rhbz#1154786
7ddfb4
    
7ddfb4
    Signed-off-by: Andrew Price <anprice@redhat.com>
7ddfb4
7ddfb4
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
7ddfb4
index b25d802..a4af25d 100644
7ddfb4
--- a/gfs2/fsck/main.c
7ddfb4
+++ b/gfs2/fsck/main.c
7ddfb4
@@ -246,18 +246,46 @@ static const struct fsck_pass passes[] = {
7ddfb4
 	{ .name = NULL, }
7ddfb4
 };
7ddfb4
 
7ddfb4
+static void print_pass_duration(const char *name, struct timeval *start)
7ddfb4
+{
7ddfb4
+	char duration[17] = ""; /* strlen("XXdXXhXXmXX.XXXs") + 1 */
7ddfb4
+	struct timeval end, diff;
7ddfb4
+	unsigned d, h, m, s;
7ddfb4
+	char *p = duration;
7ddfb4
+
7ddfb4
+	gettimeofday(&end, NULL);
7ddfb4
+	timersub(&end, start, &diff);
7ddfb4
+
7ddfb4
+	s = diff.tv_sec % 60;
7ddfb4
+	diff.tv_sec /= 60;
7ddfb4
+	m = diff.tv_sec % 60;
7ddfb4
+	diff.tv_sec /= 60;
7ddfb4
+	h = diff.tv_sec % 24;
7ddfb4
+	d = diff.tv_sec / 24;
7ddfb4
+
7ddfb4
+	if (d)
7ddfb4
+		p += snprintf(p, 4, "%ud", d > 99 ? 99U : d);
7ddfb4
+	if (h)
7ddfb4
+		p += snprintf(p, 4, "%uh", h);
7ddfb4
+	if (m)
7ddfb4
+		p += snprintf(p, 4, "%um", m);
7ddfb4
+
7ddfb4
+	snprintf(p, 8, "%u.%03lus", s, diff.tv_usec / 1000);
7ddfb4
+	log_notice(_("%s completed in %s\n"), name, duration);
7ddfb4
+}
7ddfb4
+
7ddfb4
 static int fsck_pass(const struct fsck_pass *p, struct gfs2_sbd *sdp)
7ddfb4
 {
7ddfb4
 	int ret;
7ddfb4
-	struct	timeval	before, after, diff;
7ddfb4
-	time_t runtime;
7ddfb4
-	struct tm *run_tm;
7ddfb4
+	struct timeval timer;
7ddfb4
 
7ddfb4
 	if (fsck_abort)
7ddfb4
 		return FSCK_CANCELED;
7ddfb4
 	pass = p->name;
7ddfb4
+
7ddfb4
 	log_notice( _("Starting %s\n"), p->name);
7ddfb4
-	gettimeofday(&before, 0);
7ddfb4
+	gettimeofday(&timer, NULL);
7ddfb4
+
7ddfb4
 	ret = p->f(sdp);
7ddfb4
 	if (ret)
7ddfb4
 		exit(ret);
7ddfb4
@@ -266,16 +294,8 @@ static int fsck_pass(const struct fsck_pass *p, struct gfs2_sbd *sdp)
7ddfb4
 		log_notice( _("%s interrupted   \n"), p->name);
7ddfb4
 		return FSCK_CANCELED;
7ddfb4
 	}
7ddfb4
-	gettimeofday(&after, 0);
7ddfb4
-	timersub(&after, &before, &diff);
7ddfb4
-	runtime = (time_t)diff.tv_sec;
7ddfb4
-	run_tm = gmtime(&runtime);
7ddfb4
-	log_notice( _("%s completed in "), p->name);
7ddfb4
-	if (run_tm->tm_hour)
7ddfb4
-		log_notice("%dh", run_tm->tm_hour);
7ddfb4
-	if (run_tm->tm_min)
7ddfb4
-		log_notice("%dm", run_tm->tm_min);
7ddfb4
-	log_notice("%d.%03lds      \n", run_tm->tm_sec, diff.tv_usec / 1000);
7ddfb4
+
7ddfb4
+	print_pass_duration(p->name, &timer;;
7ddfb4
 	return 0;
7ddfb4
 }
7ddfb4