From 3dd66d0c5ab80375806a35d9ecab21fb919d7d22 Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Fri, 30 Jan 2004 18:23:28 +0000 Subject: [PATCH] Add support for sinfo to sort partitions in the same order as configured in addition to the formerly supported alphabetical order. Reporting partitions in configuration order is the new default behavior. --- NEWS | 1 + doc/man/man1/sinfo.1 | 17 +++++++++++------ src/sinfo/sinfo.c | 37 +++++++++++++++++++++++++++++-------- src/sinfo/sinfo.h | 1 + src/sinfo/sort.c | 26 ++++++++++++++++++-------- 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index 7daa7ee4c70..698db5c209a 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ documents those changes that are of interest to users and admins. * Changes in SLURM 0.3.0.0-pre7 (not tagged yet) =============================== -- Add support for getting node's real memory size on AIX + -- Sinfo sort partitions in slurm.conf order, new sort option ("#P") * Changes in SLURM 0.3.0.0-pre6 =============================== diff --git a/doc/man/man1/sinfo.1 b/doc/man/man1/sinfo.1 index 61418e34e06..bbb0d54e21a 100644 --- a/doc/man/man1/sinfo.1 +++ b/doc/man/man1/sinfo.1 @@ -1,4 +1,4 @@ -.TH SINFO "1" "November 2003" "sinfo 0.3" "Slurm components" +.TH SINFO "1" "January 2004" "sinfo 0.3" "Slurm components" .SH "NAME" sinfo \- Used to view information about Slurm nodes and partitions. @@ -119,12 +119,15 @@ This uses the same field specifciation as the <output_format>. Multiple sorts may be performed by listing multiple sort fields separated by commas. The field specifications may be preceeded by "+" or "-" for -assending (default) and desending order respectively. -For example, a sort value of "P,-m" requests that records be +assending (default) and desending order respectively. +The partition field specification, "P", may be preceeded by +a "#" to report partitions in the same order that they +appear in SLURM's configuration file, \fBslurm.conf\fR. +For example, a sort value of "+P,-m" requests that records be printed in order of increasing partition name and within a partition by decreasing memory size. -The default value of sort is "P,-t" (increasing partition name -then decreasing node state). +The default value of sort is "#P,-t" (partitions ordered as +configured then decreasing node state). If the "--Node" option is selected, the default sort value is "N" (increasing node name). .TP @@ -327,4 +330,6 @@ details. \fBslurm_load_ctl_conf\fR(3), \fBslurm_load_jobs\fR(3), \fBslurm_load_node\fR(3), \fBslurm_load_partitions\fR(3), \fBslurm_reconfigure\fR(3), \fBslurm_shutdown\fR(3), -\fBslurm_update_job\fR(3), \fBslurm_update_node\fR(3), \fBslurm_update_partition\fR(3) +\fBslurm_update_job\fR(3), \fBslurm_update_node\fR(3), +\fBslurm_update_partition\fR(3), +\fBslurm.conf\fR(5) diff --git a/src/sinfo/sinfo.c b/src/sinfo/sinfo.c index e60cf298cbd..58238027e8a 100644 --- a/src/sinfo/sinfo.c +++ b/src/sinfo/sinfo.c @@ -41,11 +41,11 @@ static int _build_sinfo_data(List sinfo_list, partition_info_msg_t *partition_msg, node_info_msg_t *node_msg); static void _create_sinfo(List sinfo_list, partition_info_t* part_ptr, - node_info_t *node_ptr); + uint16_t part_inx, node_info_t *node_ptr); static bool _filter_out(node_info_t *node_ptr); static void _sinfo_list_delete(void *data); static partition_info_t *_find_part(char *part_name, - partition_info_msg_t *partition_msg); + partition_info_msg_t *partition_msg, uint16_t *part_inx); static bool _match_node_data(sinfo_data_t *sinfo_ptr, node_info_t *node_ptr); static bool _match_part_data(sinfo_data_t *sinfo_ptr, @@ -162,6 +162,7 @@ static int _build_sinfo_data(List sinfo_list, partition_info_t* part_ptr; ListIterator i; int j; + uint16_t part_inx; /* by default every partition is shown, even if no nodes */ if ((!params.node_flag) && params.match_flags.partition_flag) { @@ -169,7 +170,8 @@ static int _build_sinfo_data(List sinfo_list, for (j=0; j<partition_msg->record_count; j++, part_ptr++) { if ((!params.partition) || (_strcmp(params.partition, part_ptr->name) == 0)) - _create_sinfo(sinfo_list, part_ptr, NULL); + _create_sinfo(sinfo_list, part_ptr, + (uint16_t) j, NULL); } } @@ -181,7 +183,8 @@ static int _build_sinfo_data(List sinfo_list, if (params.filtering && _filter_out(node_ptr)) continue; - part_ptr = _find_part(node_ptr->partition, partition_msg); + part_ptr = _find_part(node_ptr->partition, partition_msg, + &part_inx); if ( ! part_ptr ) continue; i = list_iterator_create(sinfo_list); @@ -201,7 +204,7 @@ static int _build_sinfo_data(List sinfo_list, /* no match, create new sinfo_data entry */ if (sinfo_ptr == NULL) - _create_sinfo(sinfo_list, part_ptr, node_ptr); + _create_sinfo(sinfo_list, part_ptr, part_inx, node_ptr); list_iterator_destroy(i); } @@ -393,8 +396,15 @@ static void _update_sinfo(sinfo_data_t *sinfo_ptr, partition_info_t* part_ptr, hostlist_push(sinfo_ptr->nodes, node_ptr->name); } +/* + * _create_sinfo - create an sinfo record for the given node and partition + * sinfo_list IN/OUT - table of accumulated sinfo records + * part_ptr IN - pointer to partition record to add + * part_inx IN - index of partition record (0-origin) + * node_ptr IN - pointer to node record to add + */ static void _create_sinfo(List sinfo_list, partition_info_t* part_ptr, - node_info_t *node_ptr) + uint16_t part_inx, node_info_t *node_ptr) { sinfo_data_t *sinfo_ptr; @@ -430,6 +440,8 @@ static void _create_sinfo(List sinfo_list, partition_info_t* part_ptr, sinfo_ptr->reason = node_ptr->reason; sinfo_ptr->nodes = hostlist_create(node_ptr->name); + + sinfo_ptr->part_inx = part_inx; } else { sinfo_ptr->nodes = hostlist_create(""); } @@ -437,17 +449,26 @@ static void _create_sinfo(List sinfo_list, partition_info_t* part_ptr, list_append(sinfo_list, sinfo_ptr); } -/* Return a pointer to the given partition name or NULL on error */ +/* + * _find_part - find a partition by name + * part_name IN - name of partition to locate + * partition_msg IN - partition information message from API + * part_inx OUT - index of the partition within the table (0-origin) + */ static partition_info_t *_find_part(char *part_name, - partition_info_msg_t *partition_msg) + partition_info_msg_t *partition_msg, + uint16_t *part_inx) { int i; for (i=0; i<partition_msg->record_count; i++) { if (_strcmp(part_name, partition_msg->partition_array[i].name)) continue; + *part_inx = i; return &(partition_msg->partition_array[i]); } + + *part_inx = 0; /* not correct, but better than random data */ return NULL; } diff --git a/src/sinfo/sinfo.h b/src/sinfo/sinfo.h index 1f055d2de16..61e58138893 100644 --- a/src/sinfo/sinfo.h +++ b/src/sinfo/sinfo.h @@ -80,6 +80,7 @@ typedef struct { /* part_info contains partition, avail, max_time, job_size, * root, share, groups */ partition_info_t* part_info; + uint16_t part_inx; } sinfo_data_t; /* Identify what fields must match for a node's information to be diff --git a/src/sinfo/sort.c b/src/sinfo/sort.c index 72ed335128a..530781c610e 100644 --- a/src/sinfo/sort.c +++ b/src/sinfo/sort.c @@ -34,6 +34,7 @@ #define PURE_ALPHA_SORT 0 static bool reverse_order; +static bool part_order; /* order same as in part table */ static int _sort_by_avail(void *void1, void *void2); static int _sort_by_cpus(void *void1, void *void2); @@ -64,16 +65,21 @@ void sort_sinfo_list(List sinfo_list) if (params.node_flag) params.sort = xstrdup("N"); else - params.sort = xstrdup("P,-t"); + params.sort = xstrdup("#P,-t"); } for (i=(strlen(params.sort)-1); i >= 0; i--) { reverse_order = false; - if ((params.sort[i] == ',') || - (params.sort[i] == '+') || params.sort[i] == '-') + part_order = false; + + if ((params.sort[i] == ',') || (params.sort[i] == '#') || + (params.sort[i] == '+') || (params.sort[i] == '-')) continue; if ((i > 0) && (params.sort[i-1] == '-')) reverse_order = true; + if ((i > 0) && (params.sort[i-1] == '#')) + part_order = true; + if (params.sort[i] == 'a') list_sort(sinfo_list, _sort_by_avail); else if (params.sort[i] == 'A') @@ -341,11 +347,15 @@ static int _sort_by_partition(void *void1, void *void2) sinfo_data_t *sinfo2 = (sinfo_data_t *) void2; char *val1 = "", *val2 = ""; - if (sinfo1->part_info && sinfo1->part_info->name) - val1 = sinfo1->part_info->name; - if (sinfo2->part_info && sinfo2->part_info->name) - val2 = sinfo2->part_info->name; - diff = strcmp(val1, val2); + if (part_order) { + diff = sinfo1->part_inx - sinfo2->part_inx; + } else { + if (sinfo1->part_info && sinfo1->part_info->name) + val1 = sinfo1->part_info->name; + if (sinfo2->part_info && sinfo2->part_info->name) + val2 = sinfo2->part_info->name; + diff = strcmp(val1, val2); + } if (reverse_order) diff = -diff; -- GitLab