static void _pack_alloc(struct bb_alloc *bb_alloc, Buf buffer, uint16_t protocol_version) { if (protocol_version >= SLURM_16_05_PROTOCOL_VERSION) { packstr(bb_alloc->account, buffer); pack32(bb_alloc->array_job_id, buffer); pack32(bb_alloc->array_task_id, buffer); pack_time(bb_alloc->create_time, buffer); pack32(bb_alloc->job_id, buffer); packstr(bb_alloc->name, buffer); packstr(bb_alloc->partition, buffer); packstr(bb_alloc->pool, buffer); packstr(bb_alloc->qos, buffer); pack64(bb_alloc->size, buffer); pack16(bb_alloc->state, buffer); pack32(bb_alloc->user_id, buffer); } else { packstr(bb_alloc->account, buffer); pack32(bb_alloc->array_job_id, buffer); pack32(bb_alloc->array_task_id, buffer); pack_time(bb_alloc->create_time, buffer); pack32((uint32_t)0, buffer); pack32(bb_alloc->job_id, buffer); packstr(bb_alloc->name, buffer); packstr(bb_alloc->partition, buffer); packstr(bb_alloc->qos, buffer); pack64(bb_alloc->size, buffer); pack16(bb_alloc->state, buffer); pack32(bb_alloc->user_id, buffer); } }
extern void slurmdbd_pack_usage_msg(dbd_usage_msg_t *msg, uint16_t rpc_version, slurmdbd_msg_type_t type, Buf buffer) { void (*my_rec) (void *object, uint16_t rpc_version, Buf buffer); switch (type) { case DBD_GET_ASSOC_USAGE: case DBD_GOT_ASSOC_USAGE: my_rec = slurmdb_pack_assoc_rec; break; case DBD_GET_CLUSTER_USAGE: case DBD_GOT_CLUSTER_USAGE: my_rec = slurmdb_pack_cluster_rec; break; case DBD_GET_WCKEY_USAGE: case DBD_GOT_WCKEY_USAGE: my_rec = slurmdb_pack_wckey_rec; break; default: fatal("Unknown pack type"); return; } (*(my_rec))(msg->rec, rpc_version, buffer); pack_time(msg->start, buffer); pack_time(msg->end, buffer); }
extern void acct_gather_energy_pack(acct_gather_energy_t *energy, Buf buffer, uint16_t protocol_version) { if (protocol_version >= SLURM_2_6_PROTOCOL_VERSION) { if (!energy) { int i; for (i=0; i<5; i++) pack32(0, buffer); pack_time(0, buffer); return; } pack32(energy->base_consumed_energy, buffer); pack32(energy->base_watts, buffer); pack32(energy->consumed_energy, buffer); pack32(energy->current_watts, buffer); pack32(energy->previous_consumed_energy, buffer); pack_time(energy->poll_time, buffer); } else { if (!energy) { int i; for (i=0; i<4; i++) pack32(0, buffer); return; } pack32(energy->base_consumed_energy, buffer); pack32(energy->base_watts, buffer); pack32(energy->consumed_energy, buffer); pack32(energy->current_watts, buffer); } }
static void _pack_roll_usage_msg(dbd_roll_usage_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { pack16(msg->archive_data, buffer); pack_time(msg->end, buffer); pack_time(msg->start, buffer); } }
static void _pack_job_suspend_msg(dbd_job_suspend_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { pack32(msg->assoc_id, buffer); pack64(msg->db_index, buffer); pack32(msg->job_id, buffer); pack32(msg->job_state, buffer); pack_time(msg->submit_time, buffer); pack_time(msg->suspend_time, buffer); } }
/* * pack_all_front_end - dump all front_end node information for all nodes * in machine independent form (for network transmission) * OUT buffer_ptr - pointer to the stored data * OUT buffer_size - set to size of the buffer in bytes * IN protocol_version - slurm protocol version of client * NOTE: the caller must xfree the buffer at *buffer_ptr * NOTE: READ lock_slurmctld config before entry */ extern void pack_all_front_end(char **buffer_ptr, int *buffer_size, uid_t uid, uint16_t protocol_version) { time_t now = time(NULL); uint32_t nodes_packed = 0; Buf buffer; #ifdef HAVE_FRONT_END uint32_t tmp_offset; front_end_record_t *front_end_ptr; int i; buffer_ptr[0] = NULL; *buffer_size = 0; buffer = init_buf(BUF_SIZE * 2); nodes_packed = 0; if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) { /* write header: count and time */ pack32(nodes_packed, buffer); pack_time(now, buffer); /* write records */ for (i = 0, front_end_ptr = front_end_nodes; i < front_end_node_cnt; i++, front_end_ptr++) { xassert(front_end_ptr->magic == FRONT_END_MAGIC); _pack_front_end(front_end_ptr, buffer, protocol_version); nodes_packed++; } } else { error("pack_all_front_end: Unsupported slurm version %u", protocol_version); } tmp_offset = get_buf_offset (buffer); set_buf_offset(buffer, 0); pack32(nodes_packed, buffer); set_buf_offset(buffer, tmp_offset); *buffer_size = get_buf_offset(buffer); buffer_ptr[0] = xfer_buf_data(buffer); #else buffer_ptr[0] = NULL; *buffer_size = 0; buffer = init_buf(64); pack32(nodes_packed, buffer); pack_time(now, buffer); *buffer_size = get_buf_offset(buffer); buffer_ptr[0] = xfer_buf_data(buffer); #endif }
extern void ext_sensors_data_pack(ext_sensors_data_t *ext_sensors, Buf buffer, uint16_t protocol_version) { if (!ext_sensors) { pack32(0, buffer); pack32(0, buffer); pack_time((time_t)0, buffer); pack32(0, buffer); return; } pack32(ext_sensors->consumed_energy, buffer); pack32(ext_sensors->temperature, buffer); pack_time(ext_sensors->energy_update_time, buffer); pack32(ext_sensors->current_watts, buffer); }
extern int slurm_ckpt_pack_job(check_jobinfo_t jobinfo, Buf buffer, uint16_t protocol_version) { struct check_job_info *check_ptr = (struct check_job_info *)jobinfo; if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) { uint32_t x; uint32_t y; uint32_t z; uint32_t size; size = 0; pack16(CHECK_POE, buffer); x = get_buf_offset(buffer); pack32(size, buffer); y = get_buf_offset(buffer); pack16(check_ptr->disabled, buffer); pack16(check_ptr->node_cnt, buffer); pack16(check_ptr->reply_cnt, buffer); pack16(check_ptr->wait_time, buffer); pack32(check_ptr->error_code, buffer); packstr(check_ptr->error_msg, buffer); pack_time(check_ptr->time_stamp, buffer); z = get_buf_offset(buffer); set_buf_offset(buffer, x); pack32(z - y, buffer); set_buf_offset(buffer, z); } return SLURM_SUCCESS; }
/* * _pack_front_end - dump all configuration information about a specific * front_end node in machine independent form (for network transmission) * IN dump_front_end_ptr - pointer to front_end node for which information is * requested * IN/OUT buffer - buffer where data is placed, pointers automatically updated * IN protocol_version - slurm protocol version of client * NOTE: if you make any changes here be sure to make the corresponding * changes to load_front_end_config in api/node_info.c */ static void _pack_front_end(struct front_end_record *dump_front_end_ptr, Buf buffer, uint16_t protocol_version) { if (protocol_version >= SLURM_14_11_PROTOCOL_VERSION) { packstr(dump_front_end_ptr->allow_groups, buffer); packstr(dump_front_end_ptr->allow_users, buffer); pack_time(dump_front_end_ptr->boot_time, buffer); packstr(dump_front_end_ptr->deny_groups, buffer); packstr(dump_front_end_ptr->deny_users, buffer); packstr(dump_front_end_ptr->name, buffer); pack32(dump_front_end_ptr->node_state, buffer); packstr(dump_front_end_ptr->version, buffer); packstr(dump_front_end_ptr->reason, buffer); pack_time(dump_front_end_ptr->reason_time, buffer); pack32(dump_front_end_ptr->reason_uid, buffer); pack_time(dump_front_end_ptr->slurmd_start_time, buffer); } else if (protocol_version >= SLURM_14_03_PROTOCOL_VERSION) { packstr(dump_front_end_ptr->allow_groups, buffer); packstr(dump_front_end_ptr->allow_users, buffer); pack_time(dump_front_end_ptr->boot_time, buffer); packstr(dump_front_end_ptr->deny_groups, buffer); packstr(dump_front_end_ptr->deny_users, buffer); packstr(dump_front_end_ptr->name, buffer); pack16(dump_front_end_ptr->node_state, buffer); packstr(dump_front_end_ptr->version, buffer); packstr(dump_front_end_ptr->reason, buffer); pack_time(dump_front_end_ptr->reason_time, buffer); pack32(dump_front_end_ptr->reason_uid, buffer); pack_time(dump_front_end_ptr->slurmd_start_time, buffer); } else if (protocol_version >= SLURM_2_6_PROTOCOL_VERSION) { packstr(dump_front_end_ptr->allow_groups, buffer); packstr(dump_front_end_ptr->allow_users, buffer); pack_time(dump_front_end_ptr->boot_time, buffer); packstr(dump_front_end_ptr->deny_groups, buffer); packstr(dump_front_end_ptr->deny_users, buffer); packstr(dump_front_end_ptr->name, buffer); pack16(dump_front_end_ptr->node_state, buffer); packstr(dump_front_end_ptr->reason, buffer); pack_time(dump_front_end_ptr->reason_time, buffer); pack32(dump_front_end_ptr->reason_uid, buffer); pack_time(dump_front_end_ptr->slurmd_start_time, buffer); } else { error("_pack_front_end: Unsupported slurm version %u", protocol_version); } }
/* * _dump_front_end_state - dump state of a specific front_end node to a buffer * IN front_end_ptr - pointer to node for which information is requested * IN/OUT buffer - location to store data, pointers automatically advanced */ static void _dump_front_end_state(front_end_record_t *front_end_ptr, Buf buffer) { packstr (front_end_ptr->name, buffer); pack16 (front_end_ptr->node_state, buffer); packstr (front_end_ptr->reason, buffer); pack_time(front_end_ptr->reason_time, buffer); pack32 (front_end_ptr->reason_uid, buffer); }
static void _pack_cluster_tres_msg(dbd_cluster_tres_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { packstr(msg->cluster_nodes, buffer); pack_time(msg->event_time, buffer); packstr(msg->tres_str, buffer); } }
void cts_get_time_cfm(ble_service_t *svc, uint16_t conn_idx, att_error_t status, const cts_current_time_t *time) { ct_service_t *cts = (ct_service_t *) svc; uint8_t pdu[10]; pack_time(time, pdu); ble_gatts_read_cfm(conn_idx, cts->ct_val_h, ATT_ERROR_OK, sizeof(pdu), &pdu); }
static void _pack_step_complete_msg(dbd_step_comp_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { pack32(msg->assoc_id, buffer); pack64(msg->db_index, buffer); pack_time(msg->end_time, buffer); pack32(msg->exit_code, buffer); jobacctinfo_pack((struct jobacctinfo *)msg->jobacct, rpc_version, PROTOCOL_TYPE_DBD, buffer); pack32(msg->job_id, buffer); pack_time(msg->job_submit_time, buffer); packstr(msg->job_tres_alloc_str, buffer); pack32(msg->req_uid, buffer); pack_time(msg->start_time, buffer); pack16(msg->state, buffer); pack32(msg->step_id, buffer); pack32(msg->total_tasks, buffer); } }
static void _pack_job_complete_msg(dbd_job_comp_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { packstr(msg->admin_comment, buffer); pack32(msg->assoc_id, buffer); packstr(msg->comment, buffer); pack64(msg->db_index, buffer); pack32(msg->derived_ec, buffer); pack_time(msg->end_time, buffer); pack32(msg->exit_code, buffer); pack32(msg->job_id, buffer); pack32(msg->job_state, buffer); packstr(msg->nodes, buffer); pack32(msg->req_uid, buffer); pack_time(msg->start_time, buffer); pack_time(msg->submit_time, buffer); packstr(msg->system_comment, buffer); packstr(msg->tres_alloc_str, buffer); } }
static void _pack_node_state_msg(dbd_node_state_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { packstr(msg->hostlist, buffer); packstr(msg->reason, buffer); pack32(msg->reason_uid, buffer); pack16(msg->new_state, buffer); pack_time(msg->event_time, buffer); pack32(msg->state, buffer); packstr(msg->tres_str, buffer); } }
static void _pack_step_start_msg(dbd_step_start_msg_t *msg, uint16_t rpc_version, Buf buffer) { if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { pack32(msg->assoc_id, buffer); pack64(msg->db_index, buffer); pack32(msg->job_id, buffer); packstr(msg->name, buffer); packstr(msg->nodes, buffer); packstr(msg->node_inx, buffer); pack32(msg->node_cnt, buffer); pack_time(msg->start_time, buffer); pack_time(msg->job_submit_time, buffer); pack32(msg->req_cpufreq_min, buffer); pack32(msg->req_cpufreq_max, buffer); pack32(msg->req_cpufreq_gov, buffer); pack32(msg->step_id, buffer); pack32(msg->task_dist, buffer); pack32(msg->total_tasks, buffer); packstr(msg->tres_alloc_str, buffer); } }
extern int slurm_ckpt_pack_job(check_jobinfo_t jobinfo, Buf buffer, uint16_t protocol_version) { struct check_job_info *check_ptr = (struct check_job_info *)jobinfo; if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) { pack16(check_ptr->disabled, buffer); pack_time(check_ptr->time_stamp, buffer); pack32(check_ptr->error_code, buffer); packstr(check_ptr->error_msg, buffer); } return SLURM_SUCCESS; }
void cts_notify_time(ble_service_t *svc, uint16_t conn_idx, const cts_current_time_t *time) { ct_service_t *cts = (ct_service_t *) svc; uint16_t ccc = 0x0000; uint8_t pdu[10]; ble_storage_get_u16(conn_idx, cts->ct_ccc_h, &ccc); if (!(ccc & GATT_CCC_NOTIFICATIONS)) { return; } pack_time(time, pdu); ble_gatts_send_event(conn_idx, cts->ct_val_h, GATT_EVENT_NOTIFICATION, sizeof(pdu), pdu); }
/* * pack_all_part - dump all partition information for all partitions in * machine independent form (for network transmission) * OUT buffer_ptr - the pointer is set to the allocated buffer. * OUT buffer_size - set to size of the buffer in bytes * IN show_flags - partition filtering options * IN uid - uid of user making request (for partition filtering) * global: part_list - global list of partition records * NOTE: the buffer at *buffer_ptr must be xfreed by the caller * NOTE: change slurm_load_part() in api/part_info.c if data format changes */ extern void pack_all_part(char **buffer_ptr, int *buffer_size, uint16_t show_flags, uid_t uid, uint16_t protocol_version) { ListIterator part_iterator; struct part_record *part_ptr; uint32_t parts_packed; int tmp_offset; Buf buffer; time_t now = time(NULL); buffer_ptr[0] = NULL; *buffer_size = 0; buffer = init_buf(BUF_SIZE); /* write header: version and time */ parts_packed = 0; pack32(parts_packed, buffer); pack_time(now, buffer); /* write individual partition records */ part_iterator = list_iterator_create(part_list); while ((part_ptr = (struct part_record *) list_next(part_iterator))) { xassert (part_ptr->magic == PART_MAGIC); if (((show_flags & SHOW_ALL) == 0) && (uid != 0) && ((part_ptr->flags & PART_FLAG_HIDDEN) || (validate_group (part_ptr, uid) == 0))) continue; pack_part(part_ptr, buffer, protocol_version); parts_packed++; } list_iterator_destroy(part_iterator); /* put the real record count in the message body header */ tmp_offset = get_buf_offset(buffer); set_buf_offset(buffer, 0); pack32(parts_packed, buffer); set_buf_offset(buffer, tmp_offset); *buffer_size = get_buf_offset(buffer); buffer_ptr[0] = xfer_buf_data(buffer); }
/* dump_all_part_state - save the state of all partitions to file */ int dump_all_part_state(void) { /* Save high-water mark to avoid buffer growth with copies */ static int high_buffer_size = BUF_SIZE; ListIterator part_iterator; struct part_record *part_ptr; int error_code = 0, log_fd; char *old_file, *new_file, *reg_file; /* Locks: Read partition */ slurmctld_lock_t part_read_lock = { READ_LOCK, NO_LOCK, NO_LOCK, READ_LOCK }; Buf buffer = init_buf(high_buffer_size); DEF_TIMERS; START_TIMER; /* write header: time */ packstr(PART_STATE_VERSION, buffer); pack_time(time(NULL), buffer); /* write partition records to buffer */ lock_slurmctld(part_read_lock); part_iterator = list_iterator_create(part_list); while ((part_ptr = (struct part_record *) list_next(part_iterator))) { xassert (part_ptr->magic == PART_MAGIC); _dump_part_state(part_ptr, buffer); } list_iterator_destroy(part_iterator); old_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(old_file, "/part_state.old"); reg_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(reg_file, "/part_state"); new_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(new_file, "/part_state.new"); unlock_slurmctld(part_read_lock); /* write the buffer to file */ lock_state_files(); log_fd = creat(new_file, 0600); if (log_fd < 0) { error("Can't save state, error creating file %s, %m", new_file); error_code = errno; } else { int pos = 0, nwrite = get_buf_offset(buffer), amount, rc; char *data = (char *)get_buf_data(buffer); high_buffer_size = MAX(nwrite, high_buffer_size); while (nwrite > 0) { amount = write(log_fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); error_code = errno; break; } nwrite -= amount; pos += amount; } rc = fsync_and_close(log_fd, "partition"); if (rc && !error_code) error_code = rc; } if (error_code) (void) unlink(new_file); else { /* file shuffle */ (void) unlink(old_file); if (link(reg_file, old_file)) { debug4("unable to create link for %s -> %s: %m", reg_file, old_file); } (void) unlink(reg_file); if (link(new_file, reg_file)) { debug4("unable to create link for %s -> %s: %m", new_file, reg_file); } (void) unlink(new_file); } xfree(old_file); xfree(reg_file); xfree(new_file); unlock_state_files(); free_buf(buffer); END_TIMER2("dump_all_part_state"); return 0; }
static void _dump_sicp_state(void) { char *old_file, *new_file, *reg_file; ListIterator sicp_iterator; sicp_job_t *sicp_ptr; Buf buffer; time_t now = time(NULL); int error_code = SLURM_SUCCESS, len, log_fd; pthread_mutex_lock(&sicp_lock); len = list_count(sicp_job_list) * 4 + 128; buffer = init_buf(len); packstr("PROTOCOL_VERSION", buffer); pack16(SLURM_PROTOCOL_VERSION, buffer); pack_time(now, buffer); sicp_iterator = list_iterator_create(sicp_job_list); while ((sicp_ptr = (sicp_job_t *) list_next(sicp_iterator))) { pack32(sicp_ptr->job_id, buffer); pack16(sicp_ptr->job_state, buffer); } list_iterator_destroy(sicp_iterator); pthread_mutex_unlock(&sicp_lock); old_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(old_file, "/sicp_state.old"); reg_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(reg_file, "/sicp_state"); new_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(new_file, "/sicp_state.new"); lock_state_files(); log_fd = creat(new_file, 0600); if (log_fd < 0) { error("Can't save state, create file %s error %m", new_file); error_code = errno; } else { int pos = 0, nwrite, amount, rc; char *data; fd_set_close_on_exec(log_fd); nwrite = get_buf_offset(buffer); data = (char *)get_buf_data(buffer); while (nwrite > 0) { amount = write(log_fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); error_code = errno; break; } nwrite -= amount; pos += amount; } rc = fsync_and_close(log_fd, "sicp"); if (rc && !error_code) error_code = rc; } if (error_code) { (void) unlink(new_file); } else { /* file shuffle */ (void) unlink(old_file); if (link(reg_file, old_file)) debug4("unable to create link for %s -> %s: %m", reg_file, old_file); (void) unlink(reg_file); if (link(new_file, reg_file)) debug4("unable to create link for %s -> %s: %m", new_file, reg_file); (void) unlink(new_file); } xfree(old_file); xfree(reg_file); xfree(new_file); unlock_state_files(); free_buf(buffer); }
/* Pack all scheduling statistics */ extern void pack_all_stat(int resp, char **buffer_ptr, int *buffer_size, uint16_t protocol_version) { Buf buffer; int parts_packed; int agent_queue_size; time_t now = time(NULL); buffer_ptr[0] = NULL; *buffer_size = 0; buffer = init_buf(BUF_SIZE); if (protocol_version >= SLURM_2_5_PROTOCOL_VERSION) { parts_packed = resp; pack32(parts_packed, buffer); if (resp) { pack_time(now, buffer); debug3("pack_all_stat: time = %u", (uint32_t) last_proc_req_start); pack_time(last_proc_req_start, buffer); debug3("pack_all_stat: server_thread_count = %u", slurmctld_config.server_thread_count); pack32(slurmctld_config.server_thread_count, buffer); agent_queue_size = retry_list_size(); pack32(agent_queue_size, buffer); pack32(slurmctld_diag_stats.jobs_submitted, buffer); pack32(slurmctld_diag_stats.jobs_started, buffer); pack32(slurmctld_diag_stats.jobs_completed, buffer); pack32(slurmctld_diag_stats.jobs_canceled, buffer); pack32(slurmctld_diag_stats.jobs_failed, buffer); pack32(slurmctld_diag_stats.schedule_cycle_max, buffer); pack32(slurmctld_diag_stats.schedule_cycle_last, buffer); pack32(slurmctld_diag_stats.schedule_cycle_sum, buffer); pack32(slurmctld_diag_stats.schedule_cycle_counter, buffer); pack32(slurmctld_diag_stats.schedule_cycle_depth, buffer); pack32(slurmctld_diag_stats.schedule_queue_len, buffer); pack32(slurmctld_diag_stats.backfilled_jobs, buffer); pack32(slurmctld_diag_stats.last_backfilled_jobs, buffer); pack32(slurmctld_diag_stats.bf_cycle_counter, buffer); pack32(slurmctld_diag_stats.bf_cycle_sum, buffer); pack32(slurmctld_diag_stats.bf_cycle_last, buffer); pack32(slurmctld_diag_stats.bf_last_depth, buffer); pack32(slurmctld_diag_stats.bf_last_depth_try, buffer); pack32(slurmctld_diag_stats.bf_queue_len, buffer); pack32(slurmctld_diag_stats.bf_cycle_max, buffer); pack_time(slurmctld_diag_stats.bf_when_last_cycle, buffer); pack32(slurmctld_diag_stats.bf_depth_sum, buffer); pack32(slurmctld_diag_stats.bf_depth_try_sum, buffer); pack32(slurmctld_diag_stats.bf_queue_len_sum, buffer); pack32(slurmctld_diag_stats.bf_active, buffer); } } *buffer_size = get_buf_offset(buffer); buffer_ptr[0] = xfer_buf_data(buffer); }
/* dump_all_front_end_state - save the state of all front_end nodes to file */ extern int dump_all_front_end_state(void) { #ifdef HAVE_FRONT_END /* Save high-water mark to avoid buffer growth with copies */ static int high_buffer_size = (1024 * 1024); int error_code = 0, i, log_fd; char *old_file, *new_file, *reg_file; front_end_record_t *front_end_ptr; /* Locks: Read config and node */ slurmctld_lock_t node_read_lock = { READ_LOCK, NO_LOCK, READ_LOCK, NO_LOCK }; Buf buffer = init_buf(high_buffer_size); DEF_TIMERS; START_TIMER; /* write header: version, time */ packstr(FRONT_END_STATE_VERSION, buffer); pack_time(time(NULL), buffer); /* write node records to buffer */ lock_slurmctld (node_read_lock); for (i = 0, front_end_ptr = front_end_nodes; i < front_end_node_cnt; i++, front_end_ptr++) { xassert(front_end_ptr->magic == FRONT_END_MAGIC); _dump_front_end_state(front_end_ptr, buffer); } old_file = xstrdup (slurmctld_conf.state_save_location); xstrcat (old_file, "/front_end_state.old"); reg_file = xstrdup (slurmctld_conf.state_save_location); xstrcat (reg_file, "/front_end_state"); new_file = xstrdup (slurmctld_conf.state_save_location); xstrcat (new_file, "/front_end_state.new"); unlock_slurmctld (node_read_lock); /* write the buffer to file */ lock_state_files(); log_fd = creat (new_file, 0600); if (log_fd < 0) { error ("Can't save state, error creating file %s %m", new_file); error_code = errno; } else { int pos = 0, nwrite = get_buf_offset(buffer), amount, rc; char *data = (char *)get_buf_data(buffer); high_buffer_size = MAX(nwrite, high_buffer_size); while (nwrite > 0) { amount = write(log_fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); error_code = errno; break; } nwrite -= amount; pos += amount; } rc = fsync_and_close(log_fd, "front_end"); if (rc && !error_code) error_code = rc; } if (error_code) (void) unlink (new_file); else { /* file shuffle */ (void) unlink (old_file); if (link(reg_file, old_file)) debug4("unable to create link for %s -> %s: %m", reg_file, old_file); (void) unlink (reg_file); if (link(new_file, reg_file)) debug4("unable to create link for %s -> %s: %m", new_file, reg_file); (void) unlink (new_file); } xfree (old_file); xfree (reg_file); xfree (new_file); unlock_state_files (); free_buf (buffer); END_TIMER2("dump_all_front_end_state"); return error_code; #else return SLURM_SUCCESS; #endif }
static void _pack_job_start_msg(void *in, uint16_t rpc_version, Buf buffer) { dbd_job_start_msg_t *msg = (dbd_job_start_msg_t *)in; if (rpc_version >= SLURM_19_05_PROTOCOL_VERSION) { packstr(msg->account, buffer); pack32(msg->alloc_nodes, buffer); pack32(msg->array_job_id, buffer); pack32(msg->array_max_tasks, buffer); pack32(msg->array_task_id, buffer); packstr(msg->array_task_str, buffer); pack32(msg->array_task_pending, buffer); pack32(msg->assoc_id, buffer); packstr(msg->constraints, buffer); pack32(msg->db_flags, buffer); pack64(msg->db_index, buffer); pack_time(msg->eligible_time, buffer); pack32(msg->gid, buffer); packstr(msg->gres_alloc, buffer); packstr(msg->gres_req, buffer); packstr(msg->gres_used, buffer); pack32(msg->job_id, buffer); pack32(msg->job_state, buffer); pack32(msg->state_reason_prev, buffer); packstr(msg->mcs_label, buffer); packstr(msg->name, buffer); packstr(msg->nodes, buffer); packstr(msg->node_inx, buffer); pack32(msg->pack_job_id, buffer); pack32(msg->pack_job_offset, buffer); packstr(msg->partition, buffer); pack32(msg->priority, buffer); pack32(msg->qos_id, buffer); pack32(msg->req_cpus, buffer); pack64(msg->req_mem, buffer); pack32(msg->resv_id, buffer); pack_time(msg->start_time, buffer); pack_time(msg->submit_time, buffer); pack32(msg->timelimit, buffer); packstr(msg->tres_alloc_str, buffer); packstr(msg->tres_req_str, buffer); pack32(msg->uid, buffer); packstr(msg->wckey, buffer); packstr(msg->work_dir, buffer); } else if (rpc_version >= SLURM_MIN_PROTOCOL_VERSION) { packstr(msg->account, buffer); pack32(msg->alloc_nodes, buffer); pack32(msg->array_job_id, buffer); pack32(msg->array_max_tasks, buffer); pack32(msg->array_task_id, buffer); packstr(msg->array_task_str, buffer); pack32(msg->array_task_pending, buffer); pack32(msg->assoc_id, buffer); packnull(buffer); /* block_id */ pack64(msg->db_index, buffer); pack_time(msg->eligible_time, buffer); pack32(msg->gid, buffer); packstr(msg->gres_alloc, buffer); packstr(msg->gres_req, buffer); packstr(msg->gres_used, buffer); pack32(msg->job_id, buffer); pack32(msg->job_state, buffer); packstr(msg->mcs_label, buffer); packstr(msg->name, buffer); packstr(msg->nodes, buffer); packstr(msg->node_inx, buffer); pack32(msg->pack_job_id, buffer); pack32(msg->pack_job_offset, buffer); packstr(msg->partition, buffer); pack32(msg->priority, buffer); pack32(msg->qos_id, buffer); pack32(msg->req_cpus, buffer); pack64(msg->req_mem, buffer); pack32(msg->resv_id, buffer); pack_time(msg->start_time, buffer); pack_time(msg->submit_time, buffer); pack32(msg->timelimit, buffer); packstr(msg->tres_alloc_str, buffer); packstr(msg->tres_req_str, buffer); pack32(msg->uid, buffer); packstr(msg->wckey, buffer); packstr(msg->work_dir, buffer); } }
extern int fed_mgr_state_save(char *state_save_location) { int error_code = 0, log_fd; char *old_file = NULL, *new_file = NULL, *reg_file = NULL; slurmctld_lock_t fed_read_lock = { NO_LOCK, NO_LOCK, NO_LOCK, NO_LOCK, READ_LOCK }; Buf buffer = init_buf(0); DEF_TIMERS; START_TIMER; /* write header: version, time */ pack16(SLURM_PROTOCOL_VERSION, buffer); pack_time(time(NULL), buffer); lock_slurmctld(fed_read_lock); slurmdb_pack_federation_rec(fed_mgr_fed_rec, SLURM_PROTOCOL_VERSION, buffer); unlock_slurmctld(fed_read_lock); /* write the buffer to file */ reg_file = xstrdup_printf("%s/%s", state_save_location, FED_MGR_STATE_FILE); old_file = xstrdup_printf("%s.old", reg_file); new_file = xstrdup_printf("%s.new", reg_file); log_fd = creat(new_file, 0600); if (log_fd < 0) { error("Can't save state, create file %s error %m", new_file); error_code = errno; } else { int pos = 0, nwrite = get_buf_offset(buffer), amount; char *data = (char *)get_buf_data(buffer); while (nwrite > 0) { amount = write(log_fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); error_code = errno; break; } nwrite -= amount; pos += amount; } fsync(log_fd); close(log_fd); } if (error_code) (void) unlink(new_file); else { /* file shuffle */ (void) unlink(old_file); if (link(reg_file, old_file)) debug4("unable to create link for %s -> %s: %m", reg_file, old_file); (void) unlink(reg_file); if (link(new_file, reg_file)) debug4("unable to create link for %s -> %s: %m", new_file, reg_file); (void) unlink(new_file); } xfree(old_file); xfree(reg_file); xfree(new_file); free_buf(buffer); END_TIMER2("fed_mgr_state_save"); return error_code; }
static int _write_last_decay_ran(time_t last_ran, time_t last_reset) { /* Save high-water mark to avoid buffer growth with copies */ static int high_buffer_size = BUF_SIZE; int error_code = SLURM_SUCCESS; int state_fd; char *old_file, *new_file, *state_file; Buf buffer; if (!strcmp(slurmctld_conf.state_save_location, "/dev/null")) { error("Can not save priority state information, " "StateSaveLocation is /dev/null"); return error_code; } buffer = init_buf(high_buffer_size); pack_time(last_ran, buffer); pack_time(last_reset, buffer); /* read the file */ old_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(old_file, "/priority_last_decay_ran.old"); state_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(state_file, "/priority_last_decay_ran"); new_file = xstrdup(slurmctld_conf.state_save_location); xstrcat(new_file, "/priority_last_decay_ran.new"); lock_state_files(); state_fd = creat(new_file, 0600); if (state_fd < 0) { error("Can't save decay state, create file %s error %m", new_file); error_code = errno; } else { int pos = 0, nwrite = get_buf_offset(buffer), amount; char *data = (char *)get_buf_data(buffer); high_buffer_size = MAX(nwrite, high_buffer_size); while (nwrite > 0) { amount = write(state_fd, &data[pos], nwrite); if ((amount < 0) && (errno != EINTR)) { error("Error writing file %s, %m", new_file); error_code = errno; break; } nwrite -= amount; pos += amount; } fsync(state_fd); close(state_fd); } if (error_code != SLURM_SUCCESS) (void) unlink(new_file); else { /* file shuffle */ (void) unlink(old_file); if (link(state_file, old_file)) debug3("unable to create link for %s -> %s: %m", state_file, old_file); (void) unlink(state_file); if (link(new_file, state_file)) debug3("unable to create link for %s -> %s: %m", new_file, state_file); (void) unlink(new_file); } xfree(old_file); xfree(state_file); xfree(new_file); unlock_state_files(); debug4("done writing time %ld", (long)last_ran); free_buf(buffer); return error_code; }