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