diff --git a/src/plugins/priority/multifactor/priority_multifactor.c b/src/plugins/priority/multifactor/priority_multifactor.c index d4ef775def2cc18455da232349f340130fdd5eae..97dc7a94ecd421f5035d08bbe0a22dede406bfe5 100644 --- a/src/plugins/priority/multifactor/priority_multifactor.c +++ b/src/plugins/priority/multifactor/priority_multifactor.c @@ -260,10 +260,7 @@ static int _reset_usage(void) static void _read_last_decay_ran(time_t *last_ran, time_t *last_reset) { - int data_allocated, data_read = 0; - uint32_t data_size = 0; - int state_fd; - char *data = NULL, *state_file; + char *state_file; Buf buffer; xassert(last_ran); @@ -276,37 +273,16 @@ static void _read_last_decay_ran(time_t *last_ran, time_t *last_reset) state_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(state_file, "/priority_last_decay_ran"); lock_state_files(); - state_fd = open(state_file, O_RDONLY); - if (state_fd < 0) { + + if (!(buffer = create_mmap_buf(state_file))) { info("No last decay (%s) to recover", state_file); + xfree(state_file); unlock_state_files(); return; - } else { - data_allocated = BUF_SIZE; - data = xmalloc(data_allocated); - while (1) { - data_read = read(state_fd, &data[data_size], - BUF_SIZE); - if (data_read < 0) { - if (errno == EINTR) - continue; - else { - error("Read error on %s: %m", - state_file); - break; - } - } else if (data_read == 0) /* eof */ - break; - data_size += data_read; - data_allocated += data_read; - xrealloc(data, data_allocated); - } - close(state_fd); } xfree(state_file); unlock_state_files(); - buffer = create_buf(data, data_size); safe_unpack_time(last_ran, buffer); safe_unpack_time(last_reset, buffer); free_buf(buffer); diff --git a/src/plugins/select/cray/select_cray.c b/src/plugins/select/cray/select_cray.c index 4c4ea6b445b8820513db6a8dbb5d82d1514e358b..6b9e0033f67aa862d8087f32f80a98255eda113d 100644 --- a/src/plugins/select/cray/select_cray.c +++ b/src/plugins/select/cray/select_cray.c @@ -1399,12 +1399,9 @@ extern int select_p_state_save(char *dir_name) extern int select_p_state_restore(char *dir_name) { static time_t last_config_update = (time_t) 0; - int state_fd, i; + int i; char *state_file = NULL; Buf buffer = NULL; - char *data = NULL; - int data_size = 0; - int data_allocated, data_read = 0; uint16_t protocol_version = NO_VAL16; uint32_t record_count; @@ -1421,36 +1418,13 @@ extern int select_p_state_restore(char *dir_name) state_file = xstrdup(dir_name); xstrcat(state_file, "/blade_state"); - state_fd = open(state_file, O_RDONLY); - if (state_fd < 0) { + if (!(buffer = create_mmap_buf(state_file))) { error("No blade state file (%s) to recover", state_file); xfree(state_file); return SLURM_SUCCESS; - } else { - data_allocated = BUF_SIZE; - data = xmalloc(data_allocated); - while (1) { - data_read = read(state_fd, &data[data_size], - BUF_SIZE); - if (data_read < 0) { - if (errno == EINTR) - continue; - else { - error("Read error on %s: %m", - state_file); - break; - } - } else if (data_read == 0) /* eof */ - break; - data_size += data_read; - data_allocated += data_read; - xrealloc(data, data_allocated); - } - close(state_fd); } xfree(state_file); - buffer = create_buf(data, data_size); safe_unpack16(&protocol_version, buffer); debug3("Version in blade_state header is %u", protocol_version); diff --git a/src/plugins/slurmctld/nonstop/do_work.c b/src/plugins/slurmctld/nonstop/do_work.c index cb7a8b6592b574f8f29c9bf55eda7d37c80e6bd1..0255130cddc99c39b612f23a32408197a77fab02 100644 --- a/src/plugins/slurmctld/nonstop/do_work.c +++ b/src/plugins/slurmctld/nonstop/do_work.c @@ -369,12 +369,10 @@ extern int save_nonstop_state(void) extern int restore_nonstop_state(void) { char *dir_path, *state_file; - uint32_t data_allocated, data_size = 0; uint32_t job_cnt = 0; - char *data; uint16_t protocol_version = NO_VAL16; Buf buffer; - int error_code = SLURM_SUCCESS, i, state_fd, data_read; + int error_code = SLURM_SUCCESS, i; time_t buf_time; job_failures_t *job_fail_ptr = NULL; @@ -383,37 +381,14 @@ extern int restore_nonstop_state(void) xstrcat(state_file, "/nonstop_state"); xfree(dir_path); - state_fd = open(state_file, O_RDONLY); - if (state_fd < 0) { + if (!(buffer = create_mmap_buf(state_file))) { error("No nonstop state file (%s) to recover", state_file); xfree(state_file); return error_code; - } else { - data_allocated = BUF_SIZE; - data = xmalloc(data_allocated); - while (1) { - data_read = read(state_fd, &data[data_size], - BUF_SIZE); - if (data_read < 0) { - if (errno == EINTR) - continue; - else { - error("Read error on %s: %m", - state_file); - break; - } - } else if (data_read == 0) /* eof */ - break; - data_size += data_read; - data_allocated += data_read; - xrealloc(data, data_allocated); - } - close(state_fd); } xfree(state_file); /* Validate state version */ - buffer = create_buf(data, data_size); safe_unpack16(&protocol_version, buffer); debug3("Version in slurmctld/nonstop header is %u", protocol_version);