1
/*****************************************************************************\
2
* reseration_info.c - get/print the reservation state information of slurm
3
*****************************************************************************
4
* Copyright (C) 2009 Lawrence Livermore National Security.
5
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6
* Written by Morris Jette <jette1@llnl.gov> et. al.
7
* CODE-OCEC-09-009. All rights reserved.
9
* This file is part of SLURM, a resource management program.
10
* For details, see <https://computing.llnl.gov/linux/slurm/>.
11
* Please also read the included file: DISCLAIMER.
13
* SLURM is free software; you can redistribute it and/or modify it under
14
* the terms of the GNU General Public License as published by the Free
15
* Software Foundation; either version 2 of the License, or (at your option)
18
* In addition, as a special exception, the copyright holders give permission
19
* to link the code of portions of this program with the OpenSSL library under
20
* certain conditions as described in each individual source file, and
21
* distribute linked combinations including the two. You must obey the GNU
22
* General Public License in all respects for all of the code used other than
23
* OpenSSL. If you modify file(s) with this exception, you may extend this
24
* exception to your version of the file(s), but you are not obligated to do
25
* so. If you do not wish to do so, delete this exception statement from your
26
* version. If you delete this exception statement from all source files in
27
* the program, then also delete it here.
29
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
30
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
34
* You should have received a copy of the GNU General Public License along
35
* with SLURM; if not, write to the Free Software Foundation, Inc.,
36
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37
\*****************************************************************************/
47
#include <slurm/slurm.h>
49
#include "src/api/job_info.h"
50
#include "src/common/parse_time.h"
51
#include "src/common/slurm_protocol_api.h"
52
#include "src/common/xmalloc.h"
53
#include "src/common/xstring.h"
56
* slurm_print_reservation_info_msg - output information about all Slurm
57
* reservations based upon message as loaded using slurm_load_reservation
58
* IN out - file to write to
59
* IN resv_info_ptr - reservation information message pointer
60
* IN one_liner - print as a single line if true
62
void slurm_print_reservation_info_msg ( FILE* out,
63
reserve_info_msg_t * resv_info_ptr, int one_liner )
66
reserve_info_t * resv_ptr = resv_info_ptr->reservation_array ;
69
slurm_make_time_str( (time_t *)&resv_info_ptr->last_update, time_str,
71
fprintf( out, "Reservation data as of %s, record count %d\n",
72
time_str, resv_info_ptr->record_count);
74
for (i = 0; i < resv_info_ptr->record_count; i++) {
75
slurm_print_reservation_info ( out, & resv_ptr[i], one_liner );
81
* slurm_print_reservation_info - output information about a specific Slurm
82
* reservation based upon message as loaded using slurm_load_reservation
83
* IN out - file to write to
84
* IN resv_ptr - an individual reservation information record pointer
85
* IN one_liner - print as a single line if true
87
void slurm_print_reservation_info ( FILE* out, reserve_info_t * resv_ptr,
90
char *print_this = slurm_sprint_reservation_info(resv_ptr, one_liner);
91
fprintf ( out, "%s", print_this);
97
* slurm_sprint_reservation_info - output information about a specific Slurm
98
* reservation based upon message as loaded using slurm_load_reservations
99
* IN resv_ptr - an individual reservation information record pointer
100
* IN one_liner - print as a single line if true
101
* RET out - char * containing formatted output (must be freed after call)
102
* NULL is returned on failure.
104
char *slurm_sprint_reservation_info ( reserve_info_t * resv_ptr,
107
char tmp1[32], tmp2[32], *flag_str = NULL;
108
char tmp_line[MAXHOSTRANGELEN];
111
/****** Line 1 ******/
112
slurm_make_time_str(&resv_ptr->start_time, tmp1, sizeof(tmp1));
113
slurm_make_time_str(&resv_ptr->end_time, tmp2, sizeof(tmp2));
114
snprintf(tmp_line, sizeof(tmp_line),
115
"ReservationName=%s StartTime=%s EndTime=%s Duration=%u",
116
resv_ptr->name, tmp1, tmp2,
117
(uint32_t) (difftime(resv_ptr->end_time,
118
resv_ptr->start_time) / 60));
119
xstrcat(out, tmp_line);
126
/****** Line 2 ******/
127
flag_str = reservation_flags_string(resv_ptr->flags);
129
snprintf(tmp_line, sizeof(tmp_line),
130
"Nodes=%s NodeCnt=%u Features=%s PartitionName=%s Flags=%s",
131
resv_ptr->node_list, resv_ptr->node_cnt,
132
resv_ptr->features, resv_ptr->partition, flag_str);
134
xstrcat(out, tmp_line);
140
/****** Line 3 ******/
141
snprintf(tmp_line, sizeof(tmp_line),
142
"Users=%s Accounts=%s",
143
resv_ptr->users, resv_ptr->accounts);
144
xstrcat(out, tmp_line);
148
xstrcat(out, "\n\n");
156
* slurm_load_reservations - issue RPC to get all slurm reservation
157
* configuration information if changed since update_time
158
* IN update_time - time of current configuration data
159
* IN reserve_info_msg_pptr - place to store a reservation configuration
161
* RET 0 or a slurm error code
162
* NOTE: free the response using slurm_free_reservation_info_msg
164
extern int slurm_load_reservations (time_t update_time,
165
reserve_info_msg_t **resp)
169
slurm_msg_t resp_msg;
170
resv_info_request_msg_t req;
172
slurm_msg_t_init(&req_msg);
173
slurm_msg_t_init(&resp_msg);
175
req.last_update = update_time;
176
req_msg.msg_type = REQUEST_RESERVATION_INFO;
179
if (slurm_send_recv_controller_msg(&req_msg, &resp_msg) < 0)
182
switch (resp_msg.msg_type) {
183
case RESPONSE_RESERVATION_INFO:
184
*resp = (reserve_info_msg_t *) resp_msg.data;
186
case RESPONSE_SLURM_RC:
187
rc = ((return_code_msg_t *) resp_msg.data)->return_code;
188
slurm_free_return_code_msg(resp_msg.data);
190
slurm_seterrno_ret(rc);
194
slurm_seterrno_ret(SLURM_UNEXPECTED_MSG_ERROR);
198
return SLURM_PROTOCOL_SUCCESS;