1 /*****************************************************************************\
2  *  print.c - sinfo print job functions
3  *****************************************************************************
4  *  Copyright (C) 2002-2007 The Regents of the University of California.
5  *  Copyright (C) 2008-2010 Lawrence Livermore National Security.
6  *  Portions Copyright (C) 2010-2017 SchedMD <https://www.schedmd.com>.
7  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
8  *  Written by Joey Ekstrom <ekstrom1@llnl.gov> and
9  *  Morris Jette <jette1@llnl.gov>
10  *  CODE-OCEC-09-009. All rights reserved.
11  *
12  *  This file is part of Slurm, a resource management program.
13  *  For details, see <https://slurm.schedmd.com/>.
14  *  Please also read the included file: DISCLAIMER.
15  *
16  *  Slurm is free software; you can redistribute it and/or modify it under
17  *  the terms of the GNU General Public License as published by the Free
18  *  Software Foundation; either version 2 of the License, or (at your option)
19  *  any later version.
20  *
21  *  In addition, as a special exception, the copyright holders give permission
22  *  to link the code of portions of this program with the OpenSSL library under
23  *  certain conditions as described in each individual source file, and
24  *  distribute linked combinations including the two. You must obey the GNU
25  *  General Public License in all respects for all of the code used other than
26  *  OpenSSL. If you modify file(s) with this exception, you may extend this
27  *  exception to your version of the file(s), but you are not obligated to do
28  *  so. If you do not wish to do so, delete this exception statement from your
29  *  version.  If you delete this exception statement from all source files in
30  *  the program, then also delete it here.
31  *
32  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
33  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
35  *  details.
36  *
37  *  You should have received a copy of the GNU General Public License along
38  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
39  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
40 \*****************************************************************************/
41 
42 #include <ctype.h>
43 #include <time.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <pwd.h>
47 #include <sys/types.h>
48 
49 #include "src/common/hostlist.h"
50 #include "src/common/list.h"
51 #include "src/common/parse_time.h"
52 #include "src/common/xmalloc.h"
53 #include "src/common/xstring.h"
54 
55 #include "src/sinfo/print.h"
56 #include "src/sinfo/sinfo.h"
57 
58 #define MIN_NODE_FIELD_SIZE 9
59 #define MIN_PART_FIELD_SIZE 9
60 
61 static int   _build_min_max_16_string(char *buffer, int buf_size,
62 				uint16_t min, uint16_t max, bool range);
63 static int   _build_min_max_32_string(char *buffer, int buf_size,
64 				uint32_t min, uint32_t max,
65 				bool range, bool use_suffix);
66 static int   _build_cpu_load_min_max_32(char *buffer, int buf_size,
67 					uint32_t min, uint32_t max,
68 					bool range);
69 static int   _build_free_mem_min_max_64(char *buffer, int buf_size,
70 					uint64_t min, uint64_t max,
71 					bool range);
72 static void  _print_reservation(reserve_info_t *resv_ptr, int width);
73 static int   _print_secs(long time, int width, bool right, bool cut_output);
74 static int   _print_str(const char *str, int width, bool right, bool cut_output);
75 static int   _resv_name_width(reserve_info_t *resv_ptr);
76 static void  _set_node_field_size(List sinfo_list);
77 static void  _set_part_field_size(List sinfo_list);
78 static char *_str_tolower(char *upper_str);
79 
80 /*****************************************************************************
81  * Global Print Functions
82  *****************************************************************************/
print_sinfo_list(List sinfo_list)83 int print_sinfo_list(List sinfo_list)
84 {
85 	ListIterator i = list_iterator_create(sinfo_list);
86 	sinfo_data_t *current;
87 
88 	if (params.node_field_flag)
89 		_set_node_field_size(sinfo_list);
90 	if (params.part_field_flag)
91 		_set_part_field_size(sinfo_list);
92 
93 	if (!params.no_header)
94 		print_sinfo_entry(NULL);
95 
96 	while ((current = list_next(i)))
97 		 print_sinfo_entry(current);
98 
99 	list_iterator_destroy(i);
100 	return SLURM_SUCCESS;
101 }
102 
print_sinfo_entry(sinfo_data_t * sinfo_data)103 int print_sinfo_entry(sinfo_data_t *sinfo_data)
104 {
105 	ListIterator i = list_iterator_create(params.format_list);
106 	sinfo_format_t *current;
107 
108 	while ((current = list_next(i))) {
109 		if (current->function(sinfo_data, current->width,
110 				      current->right_justify, current->suffix)
111 		    != SLURM_SUCCESS)
112 			return SLURM_ERROR;
113 	}
114 	list_iterator_destroy(i);
115 
116 	printf("\n");
117 	return SLURM_SUCCESS;
118 }
119 
print_sinfo_reservation(reserve_info_msg_t * resv_ptr)120 void print_sinfo_reservation(reserve_info_msg_t *resv_ptr)
121 {
122 	reserve_info_t *reserve_ptr = NULL;
123 	char format[64];
124 	int i, width = 9;
125 
126 	reserve_ptr = resv_ptr->reservation_array;
127 	if (!params.no_header) {
128 		for (i = 0; i < resv_ptr->record_count; i++)
129 			width = MAX(width, _resv_name_width(&reserve_ptr[i]));
130 		snprintf(format, sizeof(format),
131 			 "%%-%ds  %%8s  %%19s  %%19s  %%11s  %%s\n", width);
132 		printf(format,
133 		       "RESV_NAME", "STATE", "START_TIME", "END_TIME",
134 		       "DURATION", "NODELIST");
135 	}
136 	for (i = 0; i < resv_ptr->record_count; i++)
137 		_print_reservation(&reserve_ptr[i], width);
138 }
139 
140 /*****************************************************************************
141  * Local Print Functions
142  *****************************************************************************/
_resv_name_width(reserve_info_t * resv_ptr)143 static int _resv_name_width(reserve_info_t *resv_ptr)
144 {
145 	if (!resv_ptr->name)
146 		return 0;
147 	return strlen(resv_ptr->name);
148 }
149 
_print_reservation(reserve_info_t * resv_ptr,int width)150 static void _print_reservation(reserve_info_t *resv_ptr, int width)
151 {
152 	char format[64], tmp1[32], tmp2[32], tmp3[32];
153 	char *state = "INACTIVE";
154 	uint32_t duration;
155 	time_t now = time(NULL);
156 
157 	slurm_make_time_str(&resv_ptr->start_time, tmp1, sizeof(tmp1));
158 	slurm_make_time_str(&resv_ptr->end_time,   tmp2, sizeof(tmp2));
159 	duration = difftime(resv_ptr->end_time, resv_ptr->start_time);
160 	secs2time_str(duration, tmp3, sizeof(tmp3));
161 
162 	if ((resv_ptr->start_time <= now) && (resv_ptr->end_time >= now))
163 		state = "ACTIVE";
164 	snprintf(format, sizeof(format),
165 		 "%%-%ds  %%8s  %%19s  %%19s  %%11s  %%s\n", width);
166 	printf(format,
167 	       resv_ptr->name, state, tmp1, tmp2, tmp3, resv_ptr->node_list);
168 
169 	return;
170 }
171 
_print_str(const char * str,int width,bool right,bool cut_output)172 static int _print_str(const char *str, int width, bool right, bool cut_output)
173 {
174 	char format[64];
175 	int printed = 0;
176 
177 	if (right == true && width != 0)
178 		snprintf(format, 64, "%%%ds", width);
179 	else if (width != 0)
180 		snprintf(format, 64, "%%.%ds", width);
181 	else {
182 		format[0] = '%';
183 		format[1] = 's';
184 		format[2] = '\0';
185 	}
186 
187 	if ((width == 0) || (cut_output == false)) {
188 		if ((printed = printf(format, str)) < 0)
189 			return printed;
190 	} else {
191 		char temp[width + 1];
192 		snprintf(temp, width + 1, format, str);
193 		if ((printed = printf("%s",temp)) < 0)
194 			return printed;
195 	}
196 
197 	while (printed++ < width)
198 		printf(" ");
199 
200 	return printed;
201 }
202 
_print_secs(long time,int width,bool right,bool cut_output)203 static int _print_secs(long time, int width, bool right, bool cut_output)
204 {
205 	char str[FORMAT_STRING_SIZE];
206 	long days, hours, minutes, seconds;
207 
208 	seconds =  time % 60;
209 	minutes = (time / 60)   % 60;
210 	hours   = (time / 3600) % 24;
211 	days    =  time / 86400;
212 
213 	if (days)
214 		snprintf(str, FORMAT_STRING_SIZE,
215 			 "%ld-%2.2ld:%2.2ld:%2.2ld",
216 			 days, hours, minutes, seconds);
217 	else if (hours)
218 		snprintf(str, FORMAT_STRING_SIZE,
219 			 "%ld:%2.2ld:%2.2ld",
220 			 hours, minutes, seconds);
221 	else
222 		snprintf(str, FORMAT_STRING_SIZE,
223 			 "%ld:%2.2ld",
224 			 minutes, seconds);
225 
226 	_print_str(str, width, right, cut_output);
227 	return SLURM_SUCCESS;
228 }
229 
230 static int
_build_min_max_16_string(char * buffer,int buf_size,uint16_t min,uint16_t max,bool range)231 _build_min_max_16_string(char *buffer, int buf_size, uint16_t min, uint16_t max,
232 			 bool range)
233 {
234 	char tmp_min[8];
235 	char tmp_max[8];
236 	convert_num_unit((float)min, tmp_min, sizeof(tmp_min), UNIT_NONE,
237 			 NO_VAL, params.convert_flags);
238 	convert_num_unit((float)max, tmp_max, sizeof(tmp_max), UNIT_NONE,
239 			 NO_VAL, params.convert_flags);
240 
241 	if (max == min)
242 		return snprintf(buffer, buf_size, "%s", tmp_max);
243 	else if (range) {
244 		if (max == INFINITE16)
245 			return snprintf(buffer, buf_size, "%s-infinite",
246 					tmp_min);
247 		else
248 			return snprintf(buffer, buf_size, "%s-%s",
249 					tmp_min, tmp_max);
250 	} else
251 		return snprintf(buffer, buf_size, "%s+", tmp_min);
252 }
253 
254 static int
_build_min_max_32_string(char * buffer,int buf_size,uint32_t min,uint32_t max,bool range,bool use_suffix)255 _build_min_max_32_string(char *buffer, int buf_size,
256 			 uint32_t min, uint32_t max,
257 			 bool range, bool use_suffix)
258 {
259 	char tmp_min[8];
260 	char tmp_max[8];
261 
262 	if (use_suffix) {
263 		convert_num_unit((float)min, tmp_min, sizeof(tmp_min),
264 				 UNIT_NONE, NO_VAL, params.convert_flags);
265 		convert_num_unit((float)max, tmp_max, sizeof(tmp_max),
266 				 UNIT_NONE, NO_VAL, params.convert_flags);
267 	} else {
268 		snprintf(tmp_min, sizeof(tmp_min), "%u", min);
269 		snprintf(tmp_max, sizeof(tmp_max), "%u", max);
270 	}
271 
272 	if (max == min)
273 		return snprintf(buffer, buf_size, "%s", tmp_max);
274 	else if (range) {
275 		if (max == INFINITE)
276 			return snprintf(buffer, buf_size, "%s-infinite",
277 					tmp_min);
278 		else
279 			return snprintf(buffer, buf_size, "%s-%s",
280 					tmp_min, tmp_max);
281 	} else
282 		return snprintf(buffer, buf_size, "%s+", tmp_min);
283 
284 
285 }
286 
287 static int
_build_cpu_load_min_max_32(char * buffer,int buf_size,uint32_t min,uint32_t max,bool range)288 _build_cpu_load_min_max_32(char *buffer, int buf_size,
289 			    uint32_t min, uint32_t max,
290 			    bool range)
291 {
292 
293 	char tmp_min[8];
294 	char tmp_max[8];
295 
296 	if (min == NO_VAL) {
297 		strcpy(tmp_min, "N/A");
298 	} else {
299 		snprintf(tmp_min, sizeof(tmp_min), "%.2f", (min/100.0));
300 	}
301 
302 	if (max == NO_VAL) {
303 		strcpy(tmp_max, "N/A");
304 	} else {
305 		snprintf(tmp_max, sizeof(tmp_max), "%.2f", (max/100.0));
306 	}
307 
308 	if (max == min)
309 		return snprintf(buffer, buf_size, "%s", tmp_max);
310 	else if (range)
311 		return snprintf(buffer, buf_size, "%s-%s", tmp_min, tmp_max);
312 	else
313 		return snprintf(buffer, buf_size, "%s+", tmp_min);
314 }
315 
316 static int
_build_free_mem_min_max_64(char * buffer,int buf_size,uint64_t min,uint64_t max,bool range)317 _build_free_mem_min_max_64(char *buffer, int buf_size,
318 			    uint64_t min, uint64_t max,
319 			    bool range)
320 {
321 
322 	char tmp_min[16];
323 	char tmp_max[16];
324 
325 	if (min == NO_VAL64) {
326 		strcpy(tmp_min, "N/A");
327 	} else {
328 		snprintf(tmp_min, sizeof(tmp_min), "%"PRIu64"", min);
329 	}
330 
331 	if (max == NO_VAL64) {
332 		strcpy(tmp_max, "N/A");
333 	} else {
334 		snprintf(tmp_max, sizeof(tmp_max), "%"PRIu64"", max);
335 	}
336 
337 	if (max == min)
338 		return snprintf(buffer, buf_size, "%s", tmp_max);
339 	else if (range)
340 		return snprintf(buffer, buf_size, "%s-%s", tmp_min, tmp_max);
341 	else
342 		return snprintf(buffer, buf_size, "%s+", tmp_min);
343 }
344 
345 int
format_add_function(List list,int width,bool right,char * suffix,int (* function)(sinfo_data_t *,int,bool,char *))346 format_add_function(List list, int width, bool right, char *suffix,
347 			int (*function) (sinfo_data_t *, int, bool, char*))
348 {
349 	sinfo_format_t *tmp =
350 		(sinfo_format_t *) xmalloc(sizeof(sinfo_format_t));
351 	tmp->function = function;
352 	tmp->width = width;
353 	tmp->right_justify = right;
354 	tmp->suffix = suffix;
355 	list_append(list, tmp);
356 
357 	return SLURM_SUCCESS;
358 }
359 
360 int
format_prepend_function(List list,int width,bool right,char * suffix,int (* function)(sinfo_data_t *,int,bool,char *))361 format_prepend_function(List list, int width, bool right, char *suffix,
362 			int (*function) (sinfo_data_t *, int, bool, char*))
363 {
364 	sinfo_format_t *tmp =
365 		(sinfo_format_t *) xmalloc(sizeof(sinfo_format_t));
366 	tmp->function = function;
367 	tmp->width = width;
368 	tmp->right_justify = right;
369 	tmp->suffix = suffix;
370 	list_prepend(list, tmp);
371 
372 	return SLURM_SUCCESS;
373 }
374 
_set_node_field_size(List sinfo_list)375 static void _set_node_field_size(List sinfo_list)
376 {
377 	char *tmp = NULL;
378 	ListIterator i = list_iterator_create(sinfo_list);
379 	sinfo_data_t *current;
380 	int max_width = MIN_NODE_FIELD_SIZE, this_width = 0;
381 
382 	while ((current = list_next(i))) {
383 		tmp = hostlist_ranged_string_xmalloc(current->nodes);
384 		this_width = strlen(tmp);
385 		xfree(tmp);
386 		max_width = MAX(max_width, this_width);
387 	}
388 	list_iterator_destroy(i);
389 	params.node_field_size = max_width;
390 }
391 
_set_part_field_size(List sinfo_list)392 static void _set_part_field_size(List sinfo_list)
393 {
394 	ListIterator i = list_iterator_create(sinfo_list);
395 	sinfo_data_t *current;
396 	int max_width = MIN_PART_FIELD_SIZE, this_width = 0;
397 
398 	while ((current = list_next(i))) {
399 		if (!current->part_info || !current->part_info->name)
400 			continue;
401 		this_width = strlen(current->part_info->name);
402 		if (current->part_info->flags & PART_FLAG_DEFAULT)
403 			this_width++;
404 		max_width = MAX(max_width, this_width);
405 	}
406 	list_iterator_destroy(i);
407 	params.part_field_size = max_width;
408 }
409 
410 /*
411  * _str_tolower - convert string to all lower case
412  * upper_str IN - upper case input string
413  * RET - lower case version of upper_str, caller must be xfree
414  */
_str_tolower(char * upper_str)415 static char *_str_tolower(char *upper_str)
416 {
417 	int i = strlen(upper_str) + 1;
418 	char *lower_str = xmalloc(i);
419 
420 	for (i=0; upper_str[i]; i++)
421 		lower_str[i] = tolower((int) upper_str[i]);
422 
423 	return lower_str;
424 }
425 
426 /*****************************************************************************
427  * Sinfo Print Functions
428  *****************************************************************************/
429 
_print_avail(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)430 int _print_avail(sinfo_data_t * sinfo_data, int width,
431 			bool right_justify, char *suffix)
432 {
433 	if (sinfo_data) {
434 		if (sinfo_data->part_info == NULL)
435 			_print_str("n/a", width, right_justify, true);
436 		else if (sinfo_data->part_info->state_up == PARTITION_UP)
437 			_print_str("up", width, right_justify, true);
438 		else if (sinfo_data->part_info->state_up == PARTITION_DOWN)
439 			_print_str("down", width, right_justify, true);
440 		else if (sinfo_data->part_info->state_up == PARTITION_DRAIN)
441 			_print_str("drain", width, right_justify, true);
442 		else if (sinfo_data->part_info->state_up == PARTITION_INACTIVE)
443 			_print_str("inactive", width, right_justify, true);
444 		else
445 			_print_str("unknown", width, right_justify, true);
446 	} else
447 		_print_str("AVAIL", width, right_justify, true);
448 
449 	if (suffix)
450 		printf("%s", suffix);
451 	return SLURM_SUCCESS;
452 }
453 
_print_cpus(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)454 int _print_cpus(sinfo_data_t * sinfo_data, int width,
455 			bool right_justify, char *suffix)
456 {
457 	char id[FORMAT_STRING_SIZE];
458 	if (sinfo_data) {
459 		_build_min_max_32_string(id, FORMAT_STRING_SIZE,
460 				      sinfo_data->min_cpus,
461 				      sinfo_data->max_cpus,
462 				      false, true);
463 		_print_str(id, width, right_justify, true);
464 	} else
465 		_print_str("CPUS", width, right_justify, true);
466 
467 	if (suffix)
468 		printf("%s", suffix);
469 	return SLURM_SUCCESS;
470 }
471 
472 /* Cpus, allocated/idle/other/total */
_print_cpus_aiot(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)473 int _print_cpus_aiot(sinfo_data_t * sinfo_data, int width,
474 		     bool right_justify, char *suffix)
475 {
476 	char id[FORMAT_STRING_SIZE];
477 	if (sinfo_data) {
478 		snprintf(id, FORMAT_STRING_SIZE, "%u/%u/%u/%u",
479 			 sinfo_data->cpus_alloc, sinfo_data->cpus_idle,
480 			 sinfo_data->cpus_other, sinfo_data->cpus_total);
481 		_print_str(id, width, right_justify, true);
482 	} else
483 		_print_str("CPUS(A/I/O/T)", width, right_justify, true);
484 	if (suffix)
485 		printf("%s", suffix);
486 	return SLURM_SUCCESS;
487 }
488 
_print_sct(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)489 int _print_sct(sinfo_data_t * sinfo_data, int width,
490 			bool right_justify, char *suffix)
491 {
492 	char sockets[FORMAT_STRING_SIZE];
493 	char cores[FORMAT_STRING_SIZE];
494 	char threads[FORMAT_STRING_SIZE];
495 	char sct[(FORMAT_STRING_SIZE+1)*3];
496 	if (sinfo_data) {
497 		_build_min_max_16_string(sockets, FORMAT_STRING_SIZE,
498 				      sinfo_data->min_sockets,
499 				      sinfo_data->max_sockets, false);
500 		_build_min_max_16_string(cores, FORMAT_STRING_SIZE,
501 				      sinfo_data->min_cores,
502 				      sinfo_data->max_cores, false);
503 		_build_min_max_16_string(threads, FORMAT_STRING_SIZE,
504 				      sinfo_data->min_threads,
505 				      sinfo_data->max_threads, false);
506 		sct[0] = '\0';
507 		strcat(sct, sockets);
508 		strcat(sct, ":");
509 		strcat(sct, cores);
510 		strcat(sct, ":");
511 		strcat(sct, threads);
512 		_print_str(sct, width, right_justify, true);
513 	} else {
514 		_print_str("S:C:T", width, right_justify, true);
515 	}
516 
517 	if (suffix)
518 		printf("%s", suffix);
519 	return SLURM_SUCCESS;
520 }
521 
_print_sockets(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)522 int _print_sockets(sinfo_data_t * sinfo_data, int width,
523 			bool right_justify, char *suffix)
524 {
525 	char id[FORMAT_STRING_SIZE];
526 	if (sinfo_data) {
527 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
528 				      sinfo_data->min_sockets,
529 				      sinfo_data->max_sockets, false);
530 		_print_str(id, width, right_justify, true);
531 	} else {
532 		_print_str("SOCKETS", width, right_justify, true);
533 	}
534 
535 	if (suffix)
536 		printf("%s", suffix);
537 	return SLURM_SUCCESS;
538 }
539 
_print_cores(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)540 int _print_cores(sinfo_data_t * sinfo_data, int width,
541 			bool right_justify, char *suffix)
542 {
543 	char id[FORMAT_STRING_SIZE];
544 	if (sinfo_data) {
545 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
546 				      sinfo_data->min_cores,
547 				      sinfo_data->max_cores, false);
548 		_print_str(id, width, right_justify, true);
549 	} else {
550 		_print_str("CORES", width, right_justify, true);
551 	}
552 
553 	if (suffix)
554 		printf("%s", suffix);
555 	return SLURM_SUCCESS;
556 }
557 
_print_threads(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)558 int _print_threads(sinfo_data_t * sinfo_data, int width,
559 			bool right_justify, char *suffix)
560 {
561 	char id[FORMAT_STRING_SIZE];
562 	if (sinfo_data) {
563 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
564 				      sinfo_data->min_threads,
565 				      sinfo_data->max_threads, false);
566 		_print_str(id, width, right_justify, true);
567 	} else {
568 		_print_str("THREADS", width, right_justify, true);
569 	}
570 
571 	if (suffix)
572 		printf("%s", suffix);
573 	return SLURM_SUCCESS;
574 }
575 
_print_disk(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)576 int _print_disk(sinfo_data_t * sinfo_data, int width,
577 			bool right_justify, char *suffix)
578 {
579 	char id[FORMAT_STRING_SIZE];
580 	if (sinfo_data) {
581 		_build_min_max_32_string(id, FORMAT_STRING_SIZE,
582 				      sinfo_data->min_disk,
583 				      sinfo_data->max_disk,
584 				      false, false);
585 		_print_str(id, width, right_justify, true);
586 	} else
587 		_print_str("TMP_DISK", width, right_justify, true);
588 
589 	if (suffix)
590 		printf("%s", suffix);
591 	return SLURM_SUCCESS;
592 }
593 
_print_features(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)594 int _print_features(sinfo_data_t * sinfo_data, int width,
595 			bool right_justify, char *suffix)
596 {
597 	if (sinfo_data)
598 		_print_str(sinfo_data->features, width, right_justify, true);
599 	else
600 		_print_str("AVAIL_FEATURES", width, right_justify, true);
601 
602 	if (suffix)
603 		printf("%s", suffix);
604 	return SLURM_SUCCESS;
605 }
606 
_print_features_act(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)607 int _print_features_act(sinfo_data_t * sinfo_data, int width,
608 			bool right_justify, char *suffix)
609 {
610 	if (sinfo_data)
611 		_print_str(sinfo_data->features_act, width, right_justify, true);
612 	else
613 		_print_str("ACTIVE_FEATURES", width, right_justify, true);
614 
615 	if (suffix)
616 		printf("%s", suffix);
617 	return SLURM_SUCCESS;
618 }
619 
_print_gres(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)620 int _print_gres(sinfo_data_t * sinfo_data, int width,
621 			bool right_justify, char *suffix)
622 {
623 	if (sinfo_data)
624 		_print_str(sinfo_data->gres, width, right_justify, true);
625 	else
626 		_print_str("GRES", width, right_justify, true);
627 
628 	if (suffix)
629 		printf("%s", suffix);
630 	return SLURM_SUCCESS;
631 }
632 
_print_gres_used(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)633 int _print_gres_used(sinfo_data_t * sinfo_data, int width,
634 		     bool right_justify, char *suffix)
635 {
636 	if (sinfo_data)
637 		_print_str(sinfo_data->gres_used, width, right_justify, true);
638 	else
639 		_print_str("GRES_USED", width, right_justify, true);
640 
641 	if (suffix)
642 		printf("%s", suffix);
643 	return SLURM_SUCCESS;
644 }
645 
_print_groups(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)646 int _print_groups(sinfo_data_t * sinfo_data, int width,
647 			bool right_justify, char *suffix)
648 {
649 	if (sinfo_data) {
650 		if (sinfo_data->part_info == NULL)
651 			_print_str("n/a", width, right_justify, true);
652 		else if (sinfo_data->part_info->allow_groups)
653 			_print_str(sinfo_data->part_info->allow_groups,
654 					width, right_justify, true);
655 		else
656 			_print_str("all", width, right_justify, true);
657 	} else
658 		_print_str("GROUPS", width, right_justify, true);
659 
660 	if (suffix)
661 		printf("%s", suffix);
662 	return SLURM_SUCCESS;
663 }
664 
_print_alloc_nodes(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)665 int _print_alloc_nodes(sinfo_data_t * sinfo_data, int width,
666 		       bool right_justify, char *suffix)
667 {
668 	if (sinfo_data) {
669 		if (sinfo_data->part_info == NULL)
670 			_print_str("n/a", width, right_justify, true);
671 		else if (sinfo_data->part_info->allow_alloc_nodes)
672 			_print_str(sinfo_data->part_info->allow_alloc_nodes,
673 				   width, right_justify, true);
674 		else
675 			_print_str("all", width, right_justify, true);
676 	} else
677 		_print_str("ALLOCNODES", width, right_justify, true);
678 
679 	if (suffix)
680 		printf("%s", suffix);
681 	return SLURM_SUCCESS;
682 }
683 
_print_memory(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)684 int _print_memory(sinfo_data_t * sinfo_data, int width,
685 			bool right_justify, char *suffix)
686 {
687 	char id[FORMAT_STRING_SIZE];
688 	if (sinfo_data) {
689 		_build_min_max_32_string(id, FORMAT_STRING_SIZE,
690 				      sinfo_data->min_mem,
691 				      sinfo_data->max_mem,
692 				      false, false);
693 		_print_str(id, width, right_justify, true);
694 	} else
695 		_print_str("MEMORY", width, right_justify, true);
696 
697 	if (suffix)
698 		printf("%s", suffix);
699 	return SLURM_SUCCESS;
700 }
701 
_print_node_address(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)702 int _print_node_address(sinfo_data_t * sinfo_data, int width,
703 			bool right_justify, char *suffix)
704 {
705 	if (sinfo_data) {
706 		char *tmp = NULL;
707 		tmp = hostlist_ranged_string_xmalloc(
708 				sinfo_data->node_addr);
709 		_print_str(tmp, width, right_justify, true);
710 		xfree(tmp);
711 	} else {
712 		char *title = "NODE_ADDR";
713 		_print_str(title, width, right_justify, false);
714 	}
715 
716 	if (suffix)
717 		printf("%s", suffix);
718 	return SLURM_SUCCESS;
719 }
720 
_print_node_list(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)721 int _print_node_list(sinfo_data_t * sinfo_data, int width,
722 			bool right_justify, char *suffix)
723 {
724 	if (params.node_field_flag)
725 		width = params.node_field_size;
726 
727 	if (sinfo_data) {
728 		char *tmp = NULL;
729 		tmp = hostlist_ranged_string_xmalloc(
730 				sinfo_data->nodes);
731 		_print_str(tmp, width, right_justify, true);
732 		xfree(tmp);
733 	} else {
734 		char *title = "NODELIST";
735 		_print_str(title, width, right_justify, false);
736 	}
737 
738 	if (suffix)
739 		printf("%s", suffix);
740 	return SLURM_SUCCESS;
741 }
742 
_print_node_hostnames(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)743 int _print_node_hostnames(sinfo_data_t * sinfo_data, int width,
744 			  bool right_justify, char *suffix)
745 {
746 	if (params.node_field_flag)
747 		width = params.node_field_size;
748 
749 	if (sinfo_data) {
750 		char *tmp = NULL;
751 		tmp = hostlist_ranged_string_xmalloc(
752 				sinfo_data->hostnames);
753 		_print_str(tmp, width, right_justify, true);
754 		xfree(tmp);
755 	} else {
756 		char *title = "HOSTNAMES";
757 		_print_str(title, width, right_justify, false);
758 	}
759 
760 	if (suffix)
761 		printf("%s", suffix);
762 	return SLURM_SUCCESS;
763 }
764 
_print_nodes_t(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)765 int _print_nodes_t(sinfo_data_t * sinfo_data, int width,
766 		   bool right_justify, char *suffix)
767 {
768 	char id[FORMAT_STRING_SIZE];
769 	if (sinfo_data) {
770 		snprintf(id, FORMAT_STRING_SIZE, "%d",
771 			 sinfo_data->nodes_total);
772 		_print_str(id, width, right_justify, true);
773 	} else
774 		_print_str("NODES", width, right_justify, true);
775 
776 	if (suffix)
777 		printf("%s", suffix);
778 	return SLURM_SUCCESS;
779 }
780 
_print_nodes_ai(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)781 int _print_nodes_ai(sinfo_data_t * sinfo_data, int width,
782 		    bool right_justify, char *suffix)
783 {
784 	char id[FORMAT_STRING_SIZE];
785 	if (sinfo_data) {
786 		snprintf(id, FORMAT_STRING_SIZE, "%d/%d",
787 			 sinfo_data->nodes_alloc, sinfo_data->nodes_idle);
788 		_print_str(id, width, right_justify, true);
789 	} else
790 		_print_str("NODES(A/I)", width, right_justify, true);
791 
792 	if (suffix)
793 		printf("%s", suffix);
794 	return SLURM_SUCCESS;
795 }
796 
_print_nodes_aiot(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)797 int _print_nodes_aiot(sinfo_data_t * sinfo_data, int width,
798 			bool right_justify, char *suffix)
799 {
800 	char id[FORMAT_STRING_SIZE];
801 	if (sinfo_data) {
802 		snprintf(id, FORMAT_STRING_SIZE, "%u/%u/%u/%u",
803 			 sinfo_data->nodes_alloc, sinfo_data->nodes_idle,
804 			 sinfo_data->nodes_other, sinfo_data->nodes_total);
805 		_print_str(id, width, right_justify, true);
806 	} else
807 		_print_str("NODES(A/I/O/T)", width, right_justify, true);
808 
809 	if (suffix)
810 		printf("%s", suffix);
811 	return SLURM_SUCCESS;
812 }
813 
_print_partition(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)814 int _print_partition(sinfo_data_t * sinfo_data, int width,
815 			bool right_justify, char *suffix)
816 {
817 	if (params.part_field_flag)
818 		width = params.part_field_size;
819 	if (sinfo_data) {
820 		if (sinfo_data->part_info == NULL)
821 			_print_str("n/a", width, right_justify, true);
822 		else {
823 			char *tmp;
824 			tmp = xstrdup(sinfo_data->part_info->name);
825 			if (sinfo_data->part_info->flags & PART_FLAG_DEFAULT) {
826 				if ( (strlen(tmp) < width) || (width == 0) )
827 					xstrcat(tmp, "*");
828 				else if (width > 0)
829 					tmp[width-1] = '*';
830 			}
831 			_print_str(tmp, width, right_justify, true);
832 			xfree(tmp);
833 		}
834 	} else
835 		_print_str("PARTITION", width, right_justify, true);
836 
837 	if (suffix)
838 		printf("%s", suffix);
839 	return SLURM_SUCCESS;
840 }
841 
_print_partition_name(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)842 int _print_partition_name(sinfo_data_t * sinfo_data, int width,
843 			  bool right_justify, char *suffix)
844 {
845 	if (params.part_field_flag)
846 		width = params.part_field_size;
847 	if (sinfo_data) {
848 		if (sinfo_data->part_info == NULL)
849 			_print_str("n/a", width, right_justify, true);
850 		else {
851 			_print_str(sinfo_data->part_info->name, width,
852 				   right_justify, true);
853 		}
854 	} else
855 		_print_str("PARTITION", width, right_justify, true);
856 
857 	if (suffix)
858 		printf("%s", suffix);
859 	return SLURM_SUCCESS;
860 }
861 
_print_port(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)862 int _print_port(sinfo_data_t * sinfo_data, int width,
863 			bool right_justify, char *suffix)
864 {
865 	char id[FORMAT_STRING_SIZE];
866 	if (sinfo_data) {
867 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
868 				      sinfo_data->port,
869 				      sinfo_data->port, false);
870 		_print_str(id, width, right_justify, true);
871 	} else {
872 		_print_str("PORT", width, right_justify, true);
873 	}
874 
875 	if (suffix)
876 		printf("%s", suffix);
877 	return SLURM_SUCCESS;
878 }
879 
_print_prefix(sinfo_data_t * job,int width,bool right_justify,char * suffix)880 int _print_prefix(sinfo_data_t * job, int width, bool right_justify,
881 		char* suffix)
882 {
883 	if (suffix)
884 		printf("%s", suffix);
885 	return SLURM_SUCCESS;
886 }
887 
_print_preempt_mode(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)888 int _print_preempt_mode(sinfo_data_t * sinfo_data, int width,
889 			bool right_justify, char *suffix)
890 {
891 	if (sinfo_data) {
892 		uint16_t preempt_mode = sinfo_data->part_info->preempt_mode;
893 		if (preempt_mode == NO_VAL16)
894 			preempt_mode =  slurm_get_preempt_mode();
895 		_print_str(preempt_mode_string(preempt_mode),
896 			   width, right_justify, true);
897 	} else
898 		_print_str("PREEMPT_MODE", width, right_justify, true);
899 
900 	if (suffix)
901 		printf("%s", suffix);
902 	return SLURM_SUCCESS;
903 }
904 
_print_priority_job_factor(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)905 int _print_priority_job_factor(sinfo_data_t * sinfo_data, int width,
906 			       bool right_justify, char *suffix)
907 {
908 	char id[FORMAT_STRING_SIZE];
909 
910 	if (sinfo_data) {
911 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
912 				sinfo_data->part_info->priority_job_factor,
913 				sinfo_data->part_info->priority_job_factor,
914 				true);
915 		_print_str(id, width, right_justify, true);
916 	} else
917 		_print_str("PRIO_JOB_FACTOR", width, right_justify, true);
918 
919 	if (suffix)
920 		printf("%s", suffix);
921 	return SLURM_SUCCESS;
922 }
923 
_print_priority_tier(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)924 int _print_priority_tier(sinfo_data_t * sinfo_data, int width,
925 			 bool right_justify, char *suffix)
926 {
927 	char id[FORMAT_STRING_SIZE];
928 
929 	if (sinfo_data) {
930 		_build_min_max_16_string(id, FORMAT_STRING_SIZE,
931 				sinfo_data->part_info->priority_tier,
932 				sinfo_data->part_info->priority_tier,
933 				true);
934 		_print_str(id, width, right_justify, true);
935 	} else
936 		_print_str("PRIO_TIER", width, right_justify, true);
937 
938 	if (suffix)
939 		printf("%s", suffix);
940 	return SLURM_SUCCESS;
941 }
942 
_print_reason(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)943 int _print_reason(sinfo_data_t * sinfo_data, int width,
944 			bool right_justify, char *suffix)
945 {
946 	if (sinfo_data) {
947 		char * reason = sinfo_data->reason ? sinfo_data->reason:"none";
948 		if (xstrncmp(reason, "(null)", 6) == 0)
949 			reason = "none";
950 		_print_str(reason, width, right_justify, true);
951 	} else
952 		_print_str("REASON", width, right_justify, true);
953 
954 	if (suffix)
955 		printf("%s", suffix);
956 	return SLURM_SUCCESS;
957 }
958 
_print_root(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)959 int _print_root(sinfo_data_t * sinfo_data, int width,
960 			bool right_justify, char *suffix)
961 {
962 	if (sinfo_data) {
963 		if (sinfo_data->part_info == NULL)
964 			_print_str("n/a", width, right_justify, true);
965 		else if (sinfo_data->part_info->flags & PART_FLAG_ROOT_ONLY)
966 			_print_str("yes", width, right_justify, true);
967 		else
968 			_print_str("no", width, right_justify, true);
969 	} else
970 		_print_str("ROOT", width, right_justify, true);
971 
972 	if (suffix)
973 		printf("%s", suffix);
974 	return SLURM_SUCCESS;
975 }
976 
_print_oversubscribe(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)977 int _print_oversubscribe(sinfo_data_t * sinfo_data, int width,
978 			 bool right_justify, char *suffix)
979 {
980 	char id[FORMAT_STRING_SIZE];
981 
982 	if (sinfo_data) {
983 		bool force = sinfo_data->part_info->max_share & SHARED_FORCE;
984 		uint16_t val = sinfo_data->part_info->max_share & (~SHARED_FORCE);
985 		if (val == 0)
986 			snprintf(id, sizeof(id), "EXCLUSIVE");
987 		else if (force)
988 			snprintf(id, sizeof(id), "FORCE:%u", val);
989 		else if (val == 1)
990 			snprintf(id, sizeof(id), "NO");
991 		else
992 			snprintf(id, sizeof(id), "YES:%u", val);
993 		_print_str(id, width, right_justify, true);
994 	} else
995 		_print_str("OVERSUBSCRIBE", width, right_justify, true);
996 
997 	if (suffix)
998 		printf("%s", suffix);
999 	return SLURM_SUCCESS;
1000 }
1001 
_print_size(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1002 int _print_size(sinfo_data_t * sinfo_data, int width,
1003 			bool right_justify, char *suffix)
1004 {
1005 	char id[FORMAT_STRING_SIZE];
1006 	if (sinfo_data) {
1007 		if (sinfo_data->part_info == NULL)
1008 			_print_str("n/a", width, right_justify, true);
1009 		else {
1010 			if ((sinfo_data->part_info->min_nodes < 1) &&
1011 			    (sinfo_data->part_info->max_nodes > 0))
1012 				sinfo_data->part_info->min_nodes = 1;
1013 			_build_min_max_32_string(id, FORMAT_STRING_SIZE,
1014 					      sinfo_data->part_info->min_nodes,
1015 					      sinfo_data->part_info->max_nodes,
1016 					      true, true);
1017 			_print_str(id, width, right_justify, true);
1018 		}
1019 	} else
1020 		_print_str("JOB_SIZE", width, right_justify, true);
1021 
1022 	if (suffix)
1023 		printf("%s", suffix);
1024 	return SLURM_SUCCESS;
1025 }
1026 
_print_state_compact(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1027 int _print_state_compact(sinfo_data_t * sinfo_data, int width,
1028 			bool right_justify, char *suffix)
1029 {
1030 	char *upper_state, *lower_state;
1031 	uint32_t my_state;
1032 
1033 	if (sinfo_data && sinfo_data->nodes_total) {
1034 		my_state = sinfo_data->node_state;
1035 		upper_state = node_state_string_compact(my_state);
1036 		lower_state = _str_tolower(upper_state);
1037 		_print_str(lower_state, width, right_justify, true);
1038 		xfree(lower_state);
1039 	} else if (sinfo_data)
1040 		_print_str("n/a", width, right_justify, true);
1041 	else
1042 		_print_str("STATE", width, right_justify, true);
1043 
1044 	if (suffix)
1045 		printf("%s", suffix);
1046 	return SLURM_SUCCESS;
1047 }
1048 
_print_state_long(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1049 int _print_state_long(sinfo_data_t * sinfo_data, int width,
1050 			bool right_justify, char *suffix)
1051 {
1052 	char *upper_state, *lower_state;
1053 	uint32_t my_state;
1054 
1055 	if (sinfo_data && sinfo_data->nodes_total) {
1056 		my_state = sinfo_data->node_state;
1057 		upper_state = node_state_string(my_state);
1058 		lower_state = _str_tolower(upper_state);
1059 		_print_str(lower_state, width, right_justify, true);
1060 		xfree(lower_state);
1061 	} else if (sinfo_data)
1062 		_print_str("n/a", width, right_justify, true);
1063 	else
1064 		_print_str("STATE", width, right_justify, true);
1065 
1066 	if (suffix)
1067 		printf("%s", suffix);
1068 	return SLURM_SUCCESS;
1069 }
1070 
1071 
_print_time(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1072 int _print_time(sinfo_data_t * sinfo_data, int width,
1073 			bool right_justify, char *suffix)
1074 {
1075 	if (sinfo_data) {
1076 		if (sinfo_data->part_info == NULL)
1077 			_print_str("n/a", width, right_justify, true);
1078 		else if (sinfo_data->part_info->max_time == INFINITE)
1079 			_print_str("infinite", width, right_justify, true);
1080 		else
1081 			_print_secs((sinfo_data->part_info->max_time * 60L),
1082 					width, right_justify, true);
1083 	} else
1084 		_print_str("TIMELIMIT", width, right_justify, true);
1085 
1086 	if (suffix)
1087 		printf("%s", suffix);
1088 	return SLURM_SUCCESS;
1089 }
1090 
_print_timestamp(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1091 int _print_timestamp(sinfo_data_t * sinfo_data, int width,
1092 			bool right_justify, char *suffix)
1093 {
1094 	if (sinfo_data && sinfo_data->reason_time) {
1095 		char time_str[32];
1096 		slurm_make_time_str(&sinfo_data->reason_time,
1097 				    time_str, sizeof(time_str));
1098 		_print_str(time_str, width, right_justify, true);
1099 	} else if (sinfo_data)
1100 		_print_str("Unknown", width, right_justify, true);
1101 	else
1102 		_print_str("TIMESTAMP", width, right_justify, true);
1103 
1104 	if (suffix)
1105 		printf("%s", suffix);
1106 	return SLURM_SUCCESS;
1107 }
1108 
_print_user(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1109 int _print_user(sinfo_data_t * sinfo_data, int width,
1110 			bool right_justify, char *suffix)
1111 {
1112 	if (sinfo_data && (sinfo_data->reason_uid != NO_VAL)) {
1113 		char user[FORMAT_STRING_SIZE];
1114 		struct passwd *pw = NULL;
1115 
1116 		if ((pw=getpwuid(sinfo_data->reason_uid)))
1117 			snprintf(user, sizeof(user), "%s", pw->pw_name);
1118 		else
1119 			snprintf(user, sizeof(user), "Unk(%u)",
1120 				 sinfo_data->reason_uid);
1121 		_print_str(user, width, right_justify, true);
1122 	} else if (sinfo_data)
1123 		_print_str("Unknown", width, right_justify, true);
1124 	else
1125 		_print_str("USER", width, right_justify, true);
1126 
1127 	if (suffix)
1128 		printf("%s", suffix);
1129 	return SLURM_SUCCESS;
1130 }
1131 
_print_user_long(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1132 int _print_user_long(sinfo_data_t * sinfo_data, int width,
1133 			bool right_justify, char *suffix)
1134 {
1135 	if (sinfo_data && (sinfo_data->reason_uid != NO_VAL)) {
1136 		char user[FORMAT_STRING_SIZE];
1137 		struct passwd *pw = NULL;
1138 
1139 		if ((pw=getpwuid(sinfo_data->reason_uid)))
1140 			snprintf(user, sizeof(user), "%s(%u)", pw->pw_name,
1141 				 sinfo_data->reason_uid);
1142 		else
1143 			snprintf(user, sizeof(user), "Unk(%u)",
1144 				 sinfo_data->reason_uid);
1145 		_print_str(user, width, right_justify, true);
1146 	} else if (sinfo_data)
1147 		_print_str("Unknown", width, right_justify, true);
1148 	else
1149 		_print_str("USER", width, right_justify, true);
1150 
1151 	if (suffix)
1152 		printf("%s", suffix);
1153 	return SLURM_SUCCESS;
1154 }
1155 
_print_default_time(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1156 int _print_default_time(sinfo_data_t * sinfo_data, int width,
1157 				bool right_justify, char *suffix)
1158 {
1159 	if (sinfo_data) {
1160 		if ((sinfo_data->part_info == NULL) ||
1161 		    (sinfo_data->part_info->default_time == NO_VAL))
1162 			_print_str("n/a", width, right_justify, true);
1163 		else if (sinfo_data->part_info->default_time == INFINITE)
1164 			_print_str("infinite", width, right_justify, true);
1165 		else
1166 			_print_secs((sinfo_data->part_info->default_time * 60L),
1167 				    width, right_justify, true);
1168 	} else
1169 		_print_str("DEFAULTTIME", width, right_justify, true);
1170 
1171 	if (suffix)
1172 		printf("%s", suffix);
1173 	return SLURM_SUCCESS;
1174 }
1175 
_print_weight(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1176 int _print_weight(sinfo_data_t * sinfo_data, int width,
1177 		  bool right_justify, char *suffix)
1178 {
1179 	char id[FORMAT_STRING_SIZE];
1180 	if (sinfo_data) {
1181 		_build_min_max_32_string(id, FORMAT_STRING_SIZE,
1182 					 sinfo_data->min_weight,
1183 					 sinfo_data->max_weight,
1184 					 false, false);
1185 		_print_str(id, width, right_justify, true);
1186 	} else
1187 		_print_str("WEIGHT", width, right_justify, true);
1188 
1189 	if (suffix)
1190 		printf("%s", suffix);
1191 	return SLURM_SUCCESS;
1192 }
1193 
_print_com_invalid(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1194 int _print_com_invalid(sinfo_data_t * sinfo_data, int width,
1195 		       bool right_justify, char *suffix)
1196 {
1197 	if (suffix)
1198 		printf("%s", suffix);
1199 	return SLURM_SUCCESS;
1200 }
1201 
_print_cpu_load(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1202 int _print_cpu_load(sinfo_data_t * sinfo_data, int width,
1203 		    bool right_justify, char *suffix)
1204 {
1205 	char id[FORMAT_STRING_SIZE];
1206 
1207 	if (sinfo_data) {
1208 		_build_cpu_load_min_max_32(id, FORMAT_STRING_SIZE,
1209 					 sinfo_data->min_cpu_load,
1210 					 sinfo_data->max_cpu_load,
1211 					 true);
1212 		_print_str(id, width, right_justify, true);
1213 	} else {
1214 		_print_str("CPU_LOAD", width, right_justify, true);
1215 	}
1216 
1217 	if (suffix)
1218 		printf("%s", suffix);
1219 	return SLURM_SUCCESS;
1220 }
1221 
_print_free_mem(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1222 int _print_free_mem(sinfo_data_t * sinfo_data, int width,
1223 		    bool right_justify, char *suffix)
1224 {
1225 	char id[FORMAT_STRING_SIZE];
1226 
1227 	if (sinfo_data) {
1228 		_build_free_mem_min_max_64(id, FORMAT_STRING_SIZE,
1229 					   sinfo_data->min_free_mem,
1230 					   sinfo_data->max_free_mem,
1231 					   true);
1232 		_print_str(id, width, right_justify, true);
1233 	} else {
1234 		_print_str("FREE_MEM", width, right_justify, true);
1235 	}
1236 
1237 	if (suffix)
1238 		printf("%s", suffix);
1239 	return SLURM_SUCCESS;
1240 }
1241 
_print_max_cpus_per_node(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1242 int _print_max_cpus_per_node(sinfo_data_t * sinfo_data, int width,
1243 			     bool right_justify, char *suffix)
1244 {
1245 	char tmp_line[32];
1246 	if (sinfo_data) {
1247 		if (sinfo_data->part_info->max_cpus_per_node == INFINITE)
1248 			sprintf(tmp_line, "UNLIMITED");
1249 		else
1250 			sprintf(tmp_line, "%u", sinfo_data->max_cpus_per_node);
1251 		_print_str(tmp_line, width, right_justify, true);
1252 
1253 	} else {
1254 		_print_str("MAX_CPUS_PER_NODE", width, right_justify, true);
1255 	}
1256 	if (suffix)
1257 		printf("%s", suffix);
1258 	return SLURM_SUCCESS;
1259 }
1260 
_print_version(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1261 int _print_version(sinfo_data_t * sinfo_data, int width,
1262 		   bool right_justify, char *suffix)
1263 {
1264 	if (sinfo_data) {
1265 		if (sinfo_data->version == NULL) {
1266 			_print_str("N/A", width, right_justify, true);
1267 		} else {
1268 			_print_str(sinfo_data->version, width,
1269 				   right_justify, true);
1270 		}
1271 	} else {
1272 		_print_str("VERSION", width, right_justify, true);
1273 	}
1274 	if (suffix) {
1275 		printf ("%s", suffix);
1276 	}
1277 	return SLURM_SUCCESS;
1278 
1279 }
1280 
_print_alloc_mem(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1281 int _print_alloc_mem(sinfo_data_t * sinfo_data, int width,
1282 		     bool right_justify, char *suffix)
1283 {
1284 	char tmp_line[32];
1285 	if (sinfo_data) {
1286 		sprintf(tmp_line, "%"PRIu64"", sinfo_data->alloc_memory);
1287 		_print_str(tmp_line, width, right_justify, true);
1288 	} else {
1289 		_print_str("ALLOCMEM", width, right_justify, true);
1290 	}
1291 	if (suffix) {
1292 		printf ("%s", suffix);
1293 	}
1294 	return SLURM_SUCCESS;
1295 }
1296 
1297 
_print_cluster_name(sinfo_data_t * sinfo_data,int width,bool right_justify,char * suffix)1298 int _print_cluster_name(sinfo_data_t *sinfo_data, int width,
1299 			bool right_justify, char *suffix)
1300 {
1301 	if (sinfo_data) {
1302 		if (sinfo_data->cluster_name == NULL) {
1303 			_print_str("N/A", width, right_justify, true);
1304 		} else {
1305 			_print_str(sinfo_data->cluster_name, width,
1306 				   right_justify, true);
1307 		}
1308 	} else {
1309 		_print_str("CLUSTER", width, right_justify, true);
1310 	}
1311 	if (suffix) {
1312 		printf ("%s", suffix);
1313 	}
1314 	return SLURM_SUCCESS;
1315 
1316 }
1317