|
|
dc149a |
From 560d88cb5a16636acb0e350d6997fe915cc4253e Mon Sep 17 00:00:00 2001
|
|
|
dc149a |
From: Kyle Walker <kwalker@redhat.com>
|
|
|
dc149a |
Date: Wed, 30 Jan 2019 07:50:55 -0500
|
|
|
dc149a |
Subject: [PATCH] sadc: Add a -f flag to force fdatasync() use
|
|
|
dc149a |
|
|
|
dc149a |
For quite some time, the sadc utility has not used fdatasync() when writing
|
|
|
dc149a |
stat information to disk. This resulted in instances where data files could
|
|
|
dc149a |
be corrupted or entries lost if a system encountered a sudden reset
|
|
|
dc149a |
condition. This change adds a "-f" flag which can be used to bring back the
|
|
|
dc149a |
previous behaviour if end users require it.
|
|
|
dc149a |
|
|
|
dc149a |
Note, the fdatasync() lowers the likelihood of lost data, but does so at
|
|
|
dc149a |
the expense of performance within the write operation.
|
|
|
dc149a |
---
|
|
|
dc149a |
man/sadc.in | 8 +++++++-
|
|
|
dc149a |
sa.h | 2 ++
|
|
|
dc149a |
sadc.c | 13 ++++++++++++-
|
|
|
dc149a |
3 files changed, 21 insertions(+), 2 deletions(-)
|
|
|
dc149a |
|
|
|
dc149a |
diff --git a/man/sadc.in b/man/sadc.in
|
|
|
dc149a |
index 2d754b71..ce8ee230 100644
|
|
|
dc149a |
--- a/man/sadc.in
|
|
|
dc149a |
+++ b/man/sadc.in
|
|
|
dc149a |
@@ -4,7 +4,7 @@ sadc \- System activity data collector.
|
|
|
dc149a |
.SH SYNOPSIS
|
|
|
dc149a |
.B @SA_LIB_DIR@/sadc [ -C
|
|
|
dc149a |
.I comment
|
|
|
dc149a |
-.B ] [ -D ] [ -F ] [ -L ] [ -V ] [ -S { DISK | INT | IPV6 | POWER | SNMP | XDISK | ALL | XALL [,...] } ] [
|
|
|
dc149a |
+.B ] [ -D ] [ -F ] [ -L ] [ -V ] [ -f ] [ -S { DISK | INT | IPV6 | POWER | SNMP | XDISK | ALL | XALL [,...] } ] [
|
|
|
dc149a |
.I interval
|
|
|
dc149a |
.B [
|
|
|
dc149a |
.I count
|
|
|
dc149a |
@@ -106,6 +106,12 @@ then it will be truncated. This may be useful for daily data files
|
|
|
dc149a |
created by an older version of
|
|
|
dc149a |
.B sadc
|
|
|
dc149a |
and whose format is no longer compatible with current one.
|
|
|
dc149a |
+.IP -f
|
|
|
dc149a |
+fdatasync() will be used to ensure data is written to disk. This differs
|
|
|
dc149a |
+from the normal operation in that a sudden system reset is less likely to
|
|
|
dc149a |
+result in the saDD datafiles being corrupted. However, this is at the
|
|
|
dc149a |
+expense of performance within the sadc process as forward progress will be
|
|
|
dc149a |
+blocked while data is written to underlying disk instead of just to cache.
|
|
|
dc149a |
.IP -L
|
|
|
dc149a |
.B sadc
|
|
|
dc149a |
will try to get an exclusive lock on the
|
|
|
dc149a |
diff --git a/sa.h b/sa.h
|
|
|
dc149a |
index 1cd0c3d9..d3236f7c 100644
|
|
|
dc149a |
--- a/sa.h
|
|
|
dc149a |
+++ b/sa.h
|
|
|
dc149a |
@@ -110,5 +110,6 @@
|
|
|
dc149a |
#define S_F_HUMAN_READ 0x01000000
|
|
|
dc149a |
#define S_F_ZERO_OMIT 0x02000000
|
|
|
dc149a |
+#define S_F_FDATASYNC 0x08000000
|
|
|
dc149a |
|
|
|
dc149a |
#define WANT_SINCE_BOOT(m) (((m) & S_F_SINCE_BOOT) == S_F_SINCE_BOOT)
|
|
|
dc149a |
#define WANT_SA_ROTAT(m) (((m) & S_F_SA_ROTAT) == S_F_SA_ROTAT)
|
|
|
dc149a |
@@ -138,5 +139,6 @@
|
|
|
dc149a |
#define PACK_VIEWS(m) (((m) & S_F_SVG_PACKED) == S_F_SVG_PACKED)
|
|
|
dc149a |
#define DISPLAY_HUMAN_READ(m) (((m) & S_F_HUMAN_READ) == S_F_HUMAN_READ)
|
|
|
dc149a |
+#define FDATASYNC(m) (((m) & S_F_FDATASYNC) == S_F_FDATASYNC)
|
|
|
dc149a |
|
|
|
dc149a |
#define AO_F_NULL 0x00000000
|
|
|
dc149a |
|
|
|
dc149a |
diff --git a/sadc.c b/sadc.c
|
|
|
dc149a |
index 826f4aed..139d490a 100644
|
|
|
dc149a |
--- a/sadc.c
|
|
|
dc149a |
+++ b/sadc.c
|
|
|
dc149a |
@@ -92,7 +92,7 @@ void usage(char *progname)
|
|
|
dc149a |
progname);
|
|
|
dc149a |
|
|
|
dc149a |
fprintf(stderr, _("Options are:\n"
|
|
|
dc149a |
- "[ -C <comment> ] [ -D ] [ -F ] [ -L ] [ -V ]\n"
|
|
|
dc149a |
+ "[ -C <comment> ] [ -D ] [ -F ] [ -L ] [ -V ] [ -f ]\n"
|
|
|
dc149a |
"[ -S { INT | DISK | IPV6 | POWER | SNMP | XDISK | ALL | XALL } ]\n"));
|
|
|
dc149a |
exit(1);
|
|
|
dc149a |
}
|
|
|
dc149a |
@@ -1109,6 +1109,13 @@ void rw_sa_stat_loop(long count, int stdfd, int ofd, char ofile[],
|
|
|
dc149a |
|
|
|
dc149a |
/* Flush data */
|
|
|
dc149a |
fflush(stdout);
|
|
|
dc149a |
+ if (FDATASYNC(flags)) {
|
|
|
dc149a |
+ /* If indicated, sync the data to media */
|
|
|
dc149a |
+ if (fdatasync(ofd) < 0) {
|
|
|
dc149a |
+ perror("fdatasync");
|
|
|
dc149a |
+ exit(4);
|
|
|
dc149a |
+ }
|
|
|
dc149a |
+ }
|
|
|
dc149a |
|
|
|
dc149a |
if (count > 0) {
|
|
|
dc149a |
count--;
|
|
|
dc149a |
@@ -1206,6 +1213,10 @@ int main(int argc, char **argv)
|
|
|
dc149a |
optz = 1;
|
|
|
dc149a |
}
|
|
|
dc149a |
|
|
|
dc149a |
+ else if (!strcmp(argv[opt], "-f")) {
|
|
|
dc149a |
+ flags |= S_F_FDATASYNC;
|
|
|
dc149a |
+ }
|
|
|
dc149a |
+
|
|
|
dc149a |
else if (!strcmp(argv[opt], "-C")) {
|
|
|
dc149a |
if (!argv[++opt]) {
|
|
|
dc149a |
usage(argv[0]);
|