From 3f947d455643d0aebc2c7210df463379495b09d2 Mon Sep 17 00:00:00 2001 From: Nate Rini <nate@schedmd.com> Date: Fri, 31 May 2019 13:24:38 -0600 Subject: [PATCH] Move fsync_and_close() to common/fd.[ch]. No functional changes to fsync_and_close(), but tag the file_type as const and clean up some minor style issues while moving this. Add include for fd.h header where needed as well. Bug 7146. --- src/common/fd.c | 36 +++++++++++++++++++++++++ src/common/fd.h | 7 +++++ src/plugins/slurmctld/nonstop/do_work.c | 1 + src/slurmctld/node_mgr.c | 1 + src/slurmctld/partition_mgr.c | 1 + src/slurmctld/reservation.c | 1 + src/slurmctld/state_save.c | 31 --------------------- src/slurmctld/state_save.h | 5 ---- src/slurmctld/trigger_mgr.c | 1 + 9 files changed, 48 insertions(+), 36 deletions(-) diff --git a/src/common/fd.c b/src/common/fd.c index 8354caa66e0..89a5459afa9 100644 --- a/src/common/fd.c +++ b/src/common/fd.c @@ -189,3 +189,39 @@ extern int wait_fd_readable(int fd, int time_limit) } } } + +/* + * fsync() then close() a file. + * Execute fsync() and close() multiple times if necessary and log failures + * RET 0 on success or -1 on error + */ +extern int fsync_and_close(int fd, const char *file_type) +{ + int rc = 0, retval, pos; + + /* + * Slurm state save files are commonly stored on shared filesystems, + * so lets give fsync() three tries to sync the data to disk. + */ + for (retval = 1, pos = 1; retval && pos < 4; pos++) { + retval = fsync(fd); + if (retval && (errno != EINTR)) { + error("fsync() error writing %s state save file: %m", + file_type); + } + } + if (retval) + rc = retval; + + for (retval = 1, pos = 1; retval && pos < 4; pos++) { + retval = close(fd); + if (retval && (errno != EINTR)) { + error("close () error on %s state save file: %m", + file_type); + } + } + if (retval) + rc = retval; + + return rc; +} diff --git a/src/common/fd.h b/src/common/fd.h index 4d9fe1b3096..1d6706e1a86 100644 --- a/src/common/fd.h +++ b/src/common/fd.h @@ -112,4 +112,11 @@ extern int wait_fd_readable(int fd, int time_limit); /* Wait for a file descriptor to be readable (up to time_limit seconds). * Return 0 when readable or -1 on error */ +/* + * fsync() then close() a file. + * Execute fsync() and close() multiple times if necessary and log failures + * RET 0 on success or -1 on error + */ +extern int fsync_and_close(int fd, const char *file_type); + #endif /* !_FD_H */ diff --git a/src/plugins/slurmctld/nonstop/do_work.c b/src/plugins/slurmctld/nonstop/do_work.c index 0255130cddc..ca846495e49 100644 --- a/src/plugins/slurmctld/nonstop/do_work.c +++ b/src/plugins/slurmctld/nonstop/do_work.c @@ -49,6 +49,7 @@ #include "src/common/slurm_xlator.h" /* Must be first */ #include "src/common/bitstring.h" +#include "src/common/fd.h" #include "src/common/job_resources.h" #include "src/common/list.h" #include "src/common/node_conf.h" diff --git a/src/slurmctld/node_mgr.c b/src/slurmctld/node_mgr.c index ea1112b62e0..710b15fdb72 100644 --- a/src/slurmctld/node_mgr.c +++ b/src/slurmctld/node_mgr.c @@ -53,6 +53,7 @@ #include <time.h> #include "src/common/bitstring.h" +#include "src/common/fd.h" #include "src/common/gres.h" #include "src/common/hostlist.h" #include "src/common/macros.h" diff --git a/src/slurmctld/partition_mgr.c b/src/slurmctld/partition_mgr.c index 34a5702553f..2f63867ccd8 100644 --- a/src/slurmctld/partition_mgr.c +++ b/src/slurmctld/partition_mgr.c @@ -53,6 +53,7 @@ #include <unistd.h> #include "src/common/assoc_mgr.h" +#include "src/common/fd.h" #include "src/common/hostlist.h" #include "src/common/list.h" #include "src/common/node_select.h" diff --git a/src/slurmctld/reservation.c b/src/slurmctld/reservation.c index 4ca1aeb841c..df2c831bb36 100644 --- a/src/slurmctld/reservation.c +++ b/src/slurmctld/reservation.c @@ -54,6 +54,7 @@ #include "src/common/assoc_mgr.h" #include "src/common/bitstring.h" +#include "src/common/fd.h" #include "src/common/hostlist.h" #include "src/common/list.h" #include "src/common/log.h" diff --git a/src/slurmctld/state_save.c b/src/slurmctld/state_save.c index abf1afccd00..a66938d549b 100644 --- a/src/slurmctld/state_save.c +++ b/src/slurmctld/state_save.c @@ -62,37 +62,6 @@ static int save_jobs = 0, save_nodes = 0, save_parts = 0; static int save_front_end = 0, save_triggers = 0, save_resv = 0; static bool run_save_thread = true; -/* fsync() and close() a file, - * Execute fsync() and close() multiple times if necessary and log failures - * RET 0 on success or -1 on error */ -extern int fsync_and_close(int fd, char *file_type) -{ - int rc = 0, retval, pos; - - /* Slurm state save files are typically stored on shared filesystems, - * so lets give fysync() three tries to sync the data to disk. */ - for (retval = 1, pos = 1; retval && pos < 4; pos++) { - retval = fsync(fd); - if (retval && (errno != EINTR)) { - error("fsync() error writing %s state save file: %m", - file_type); - } - } - if (retval) - rc = retval; - - for (retval = 1, pos = 1; retval && pos < 4; pos++) { - retval = close(fd); - if (retval && (errno != EINTR)) { - error("close () error on %s state save file: %m", - file_type); - } - } - if (retval) - rc = retval; - - return rc; -} /* Queue saving of front_end state information */ extern void schedule_front_end_save(void) diff --git a/src/slurmctld/state_save.h b/src/slurmctld/state_save.h index 9c372100424..eebb509138b 100644 --- a/src/slurmctld/state_save.h +++ b/src/slurmctld/state_save.h @@ -40,11 +40,6 @@ #ifndef _SLURMCTLD_STATE_SAVE_H #define _SLURMCTLD_STATE_SAVE_H -/* fsync() and close() a file, - * Execute fsync() and close() multiple times if necessary and log failures - * RET 0 on success or -1 on error */ -extern int fsync_and_close(int fd, char *file_type); - /* Queue saving of front_end state information */ extern void schedule_front_end_save(void); diff --git a/src/slurmctld/trigger_mgr.c b/src/slurmctld/trigger_mgr.c index e480214108e..1693421b3e8 100644 --- a/src/slurmctld/trigger_mgr.c +++ b/src/slurmctld/trigger_mgr.c @@ -51,6 +51,7 @@ #include <sys/types.h> #include "src/common/bitstring.h" +#include "src/common/fd.h" #include "src/common/list.h" #include "src/common/slurmdbd_defs.h" #include "src/common/slurm_protocol_defs.h" -- GitLab