Blame SOURCES/0001-sadc-Add-a-f-flag-to-force-fdatasync-use.patch

9a8d55
From f44275403f866cd0a7e0e40714c249ec5903d356 Mon Sep 17 00:00:00 2001
9a8d55
From: Kyle Walker <kwalker@redhat.com>
9a8d55
Date: Wed, 30 Jan 2019 07:50:55 -0500
9a8d55
Subject: [PATCH] sadc: Add a -f flag to force fdatasync() use
9a8d55
9a8d55
For quite some time, the sadc utility has not used fdatasync() when writing
9a8d55
stat information to disk. This resulted in instances where data files could
9a8d55
be corrupted or entries lost if a system encountered a sudden reset
9a8d55
condition. This change adds a "-f" flag which can be used to bring back the
9a8d55
previous behaviour if end users require it.
9a8d55
9a8d55
Note, the fdatasync() lowers the likelihood of lost data, but does so at
9a8d55
the expense of performance within the write operation.
9a8d55
9a8d55
(cherry picked from commit 560d88cb5a16636acb0e350d6997fe915cc4253e)
9a8d55
---
9a8d55
 man/sadc.in |  8 +++++++-
9a8d55
 sa.h        |  2 ++
9a8d55
 sadc.c      | 13 ++++++++++++-
9a8d55
 3 files changed, 21 insertions(+), 2 deletions(-)
9a8d55
9a8d55
diff --git a/man/sadc.in b/man/sadc.in
9a8d55
index 9b75754..d3574c1 100644
9a8d55
--- a/man/sadc.in
9a8d55
+++ b/man/sadc.in
9a8d55
@@ -4,7 +4,7 @@ sadc \- System activity data collector.
9a8d55
 .SH SYNOPSIS
9a8d55
 .B @SA_LIB_DIR@/sadc [ -C
9a8d55
 .I comment
9a8d55
-.B ] [ -F ] [ -L ] [ -V ] [ -S { INT | DISK | SNMP | IPV6 | POWER | XDISK | ALL | XALL } ] [
9a8d55
+.B ] [ -F ] [ -L ] [ -V ] [ -f ] [ -S { INT | DISK | SNMP | IPV6 | POWER | XDISK | ALL | XALL } ] [
9a8d55
 .I interval
9a8d55
 .B [
9a8d55
 .I count
9a8d55
@@ -85,6 +85,12 @@ then it will be truncated. This may be useful for daily data files
9a8d55
 created by an older version of
9a8d55
 .B sadc
9a8d55
 and whose format is no longer compatible with current one.
9a8d55
+.IP -f
9a8d55
+fdatasync() will be used to ensure data is written to disk. This differs
9a8d55
+from the normal operation in that a sudden system reset is less likely to
9a8d55
+result in the saDD datafiles being corrupted. However, this is at the
9a8d55
+expense of performance within the sadc process as forward progress will be
9a8d55
+blocked while data is written to underlying disk instead of just to cache.
9a8d55
 .IP -L
9a8d55
 .B sadc
9a8d55
 will try to get an exclusive lock on the
9a8d55
diff --git a/sa.h b/sa.h
9a8d55
index 54e7a4e..0c3b24c 100644
9a8d55
--- a/sa.h
9a8d55
+++ b/sa.h
9a8d55
@@ -88,6 +88,7 @@
9a8d55
 #define S_F_COMMENT		0x00001000
9a8d55
 #define S_F_PERSIST_NAME	0x00002000
9a8d55
 #define S_F_LOCAL_TIME		0x00004000
9a8d55
+#define S_F_FDATASYNC       0x00008000
9a8d55
 
9a8d55
 #define WANT_SINCE_BOOT(m)		(((m) & S_F_SINCE_BOOT)   == S_F_SINCE_BOOT)
9a8d55
 #define WANT_SA_ROTAT(m)		(((m) & S_F_SA_ROTAT)     == S_F_SA_ROTAT)
9a8d55
@@ -104,6 +105,7 @@
9a8d55
 #define DISPLAY_COMMENT(m)		(((m) & S_F_COMMENT)      == S_F_COMMENT)
9a8d55
 #define DISPLAY_PERSIST_NAME_S(m)	(((m) & S_F_PERSIST_NAME) == S_F_PERSIST_NAME)
9a8d55
 #define PRINT_LOCAL_TIME(m)		(((m) & S_F_LOCAL_TIME)   == S_F_LOCAL_TIME)
9a8d55
+#define FDATASYNC(m)            (((m) & S_F_FDATASYNC)    == S_F_FDATASYNC)
9a8d55
 
9a8d55
 #define AO_F_NULL		0x00000000
9a8d55
 
9a8d55
diff --git a/sadc.c b/sadc.c
9a8d55
index fb3254d..bac28d4 100644
9a8d55
--- a/sadc.c
9a8d55
+++ b/sadc.c
9a8d55
@@ -85,7 +85,7 @@ void usage(char *progname)
9a8d55
 		progname);
9a8d55
 
9a8d55
 	fprintf(stderr, _("Options are:\n"
9a8d55
-			  "[ -C <comment> ] [ -F ] [ -L ] [ -V ]\n"
9a8d55
+			  "[ -C <comment> ] [ -F ] [ -L ] [ -V ] [ -f ]\n"
9a8d55
 			  "[ -S { INT | DISK | IPV6 | POWER | SNMP | XDISK | ALL | XALL } ]\n"));
9a8d55
 	exit(1);
9a8d55
 }
9a8d55
@@ -991,6 +991,13 @@ void rw_sa_stat_loop(long count, struct tm *rectime, int stdfd, int ofd,
9a8d55
 
9a8d55
 		/* Flush data */
9a8d55
 		fflush(stdout);
9a8d55
+		if (FDATASYNC(flags)) {
9a8d55
+			/* Flush previous file */
9a8d55
+			if (fdatasync(ofd) < 0) {
9a8d55
+				perror("fdatasync");
9a8d55
+				exit(4);
9a8d55
+			}
9a8d55
+		}
9a8d55
 
9a8d55
 		if (count > 0) {
9a8d55
 			count--;
9a8d55
@@ -1079,6 +1086,10 @@ int main(int argc, char **argv)
9a8d55
 			optz = 1;
9a8d55
 		}
9a8d55
 
9a8d55
+		else if (!strcmp(argv[opt], "-f")) {
9a8d55
+			flags |= S_F_FDATASYNC;
9a8d55
+		}
9a8d55
+
9a8d55
 		else if (!strcmp(argv[opt], "-C")) {
9a8d55
 			if (argv[++opt]) {
9a8d55
 				strncpy(comment, argv[opt], MAX_COMMENT_LEN);
9a8d55
-- 
9a8d55
2.17.1
9a8d55