PageRenderTime 59ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/smap/partition_functions.c

https://github.com/cfenoy/slurm
C | 988 lines | 845 code | 100 blank | 43 comment | 258 complexity | bd18e585dbe0cc8bb7dc41c480819a22 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * partition_functions.c - Functions related to partition display
  3. * mode of smap.
  4. *****************************************************************************
  5. * Copyright (C) 2004-2007 The Regents of the University of California.
  6. * Copyright (C) 2008-2011 Lawrence Livermore National Security.
  7. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  8. * Written by Danny Auble <da@llnl.gov>
  9. *
  10. * CODE-OCEC-09-009. All rights reserved.
  11. *
  12. * This file is part of SLURM, a resource management program.
  13. * For details, see <http://www.schedmd.com/slurmdocs/>.
  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. #include "src/smap/smap.h"
  42. #include "src/common/node_select.h"
  43. #include "src/common/parse_time.h"
  44. #define _DEBUG 0
  45. typedef struct {
  46. char *bg_block_name;
  47. uint16_t bg_conn_type[HIGHEST_DIMENSIONS];
  48. uint16_t bg_node_use;
  49. char *ionode_str;
  50. List job_list;
  51. int letter_num;
  52. List nodelist;
  53. char *mp_str;
  54. int cnode_cnt;
  55. bool printed;
  56. int size;
  57. char *slurm_part_name;
  58. uint16_t state;
  59. } db2_block_info_t;
  60. static List block_list = NULL;
  61. static void _block_list_del(void *object);
  62. static int _in_slurm_partition(List slurm_nodes, List bg_nodes);
  63. static int _make_nodelist(char *nodes, List nodelist);
  64. static void _marknodes(db2_block_info_t *block_ptr, int count);
  65. static void _nodelist_del(void *object);
  66. static void _print_header_part(void);
  67. static int _print_rest(db2_block_info_t *block_ptr);
  68. static int _print_text_part(partition_info_t *part_ptr,
  69. db2_block_info_t *db2_info_ptr);
  70. extern void get_slurm_part(void)
  71. {
  72. int error_code, i, j, recs, count = 0;
  73. static partition_info_msg_t *part_info_ptr = NULL;
  74. static partition_info_msg_t *new_part_ptr = NULL;
  75. partition_info_t part;
  76. uint16_t show_flags = 0;
  77. bitstr_t *nodes_req = NULL;
  78. static uint16_t last_flags = 0;
  79. if (params.all_flag)
  80. show_flags |= SHOW_ALL;
  81. if (part_info_ptr) {
  82. if (show_flags != last_flags)
  83. part_info_ptr->last_update = 0;
  84. error_code = slurm_load_partitions(part_info_ptr->last_update,
  85. &new_part_ptr, show_flags);
  86. if (error_code == SLURM_SUCCESS)
  87. slurm_free_partition_info_msg(part_info_ptr);
  88. else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
  89. error_code = SLURM_SUCCESS;
  90. new_part_ptr = part_info_ptr;
  91. }
  92. } else {
  93. error_code = slurm_load_partitions((time_t) NULL,
  94. &new_part_ptr, show_flags);
  95. }
  96. last_flags = show_flags;
  97. if (error_code) {
  98. if (quiet_flag != 1) {
  99. if (!params.commandline) {
  100. mvwprintw(text_win,
  101. main_ycord, 1,
  102. "slurm_load_partitions: %s",
  103. slurm_strerror(slurm_get_errno()));
  104. main_ycord++;
  105. } else {
  106. printf("slurm_load_partitions: %s\n",
  107. slurm_strerror(slurm_get_errno()));
  108. }
  109. }
  110. return;
  111. }
  112. if (!params.no_header)
  113. _print_header_part();
  114. if (new_part_ptr)
  115. recs = new_part_ptr->record_count;
  116. else
  117. recs = 0;
  118. if (!params.commandline)
  119. if ((recs - text_line_cnt) < (getmaxy(text_win) - 4))
  120. text_line_cnt--;
  121. if (params.hl)
  122. nodes_req = get_requested_node_bitmap();
  123. for (i = 0; i < recs; i++) {
  124. part = new_part_ptr->partition_array[i];
  125. if (nodes_req) {
  126. int overlap = 0;
  127. bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req));
  128. inx2bitstr(loc_bitmap, part.node_inx);
  129. overlap = bit_overlap(loc_bitmap, nodes_req);
  130. FREE_NULL_BITMAP(loc_bitmap);
  131. if (!overlap)
  132. continue;
  133. }
  134. j = 0;
  135. while (part.node_inx[j] >= 0) {
  136. set_grid_inx(part.node_inx[j],
  137. part.node_inx[j + 1], count);
  138. j += 2;
  139. }
  140. if (!params.commandline) {
  141. if (i >= text_line_cnt) {
  142. part.flags = (int) letters[count%62];
  143. wattron(text_win,
  144. COLOR_PAIR(colors[count%6]));
  145. _print_text_part(&part, NULL);
  146. wattroff(text_win,
  147. COLOR_PAIR(colors[count%6]));
  148. }
  149. } else {
  150. part.flags = (int) letters[count%62];
  151. _print_text_part(&part, NULL);
  152. }
  153. count++;
  154. }
  155. if (count == 128)
  156. count = 0;
  157. if (params.commandline && params.iterate)
  158. printf("\n");
  159. part_info_ptr = new_part_ptr;
  160. return;
  161. }
  162. extern void get_bg_part(void)
  163. {
  164. int error_code, i, recs=0, count = 0, last_count = -1;
  165. static partition_info_msg_t *part_info_ptr = NULL;
  166. static partition_info_msg_t *new_part_ptr = NULL;
  167. static block_info_msg_t *bg_info_ptr = NULL;
  168. static block_info_msg_t *new_bg_ptr = NULL;
  169. uint16_t show_flags = 0;
  170. partition_info_t part;
  171. db2_block_info_t *block_ptr = NULL;
  172. db2_block_info_t *found_block = NULL;
  173. ListIterator itr;
  174. List nodelist = NULL;
  175. bitstr_t *nodes_req = NULL;
  176. if (!(params.cluster_flags & CLUSTER_FLAG_BG))
  177. return;
  178. if (params.all_flag)
  179. show_flags |= SHOW_ALL;
  180. if (part_info_ptr) {
  181. error_code = slurm_load_partitions(part_info_ptr->last_update,
  182. &new_part_ptr, show_flags);
  183. if (error_code == SLURM_SUCCESS)
  184. slurm_free_partition_info_msg(part_info_ptr);
  185. else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
  186. error_code = SLURM_SUCCESS;
  187. new_part_ptr = part_info_ptr;
  188. }
  189. } else {
  190. error_code = slurm_load_partitions((time_t) NULL,
  191. &new_part_ptr, show_flags);
  192. }
  193. if (error_code) {
  194. if (quiet_flag != 1) {
  195. if (!params.commandline) {
  196. mvwprintw(text_win,
  197. main_ycord, 1,
  198. "slurm_load_partitions: %s",
  199. slurm_strerror(slurm_get_errno()));
  200. main_ycord++;
  201. } else {
  202. printf("slurm_load_partitions: %s\n",
  203. slurm_strerror(slurm_get_errno()));
  204. }
  205. }
  206. return;
  207. }
  208. if (bg_info_ptr) {
  209. error_code = slurm_load_block_info(bg_info_ptr->last_update,
  210. &new_bg_ptr, show_flags);
  211. if (error_code == SLURM_SUCCESS)
  212. slurm_free_block_info_msg(bg_info_ptr);
  213. else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
  214. error_code = SLURM_SUCCESS;
  215. new_bg_ptr = bg_info_ptr;
  216. }
  217. } else {
  218. error_code = slurm_load_block_info((time_t) NULL,
  219. &new_bg_ptr, show_flags);
  220. }
  221. if (error_code) {
  222. if (quiet_flag != 1) {
  223. if (!params.commandline) {
  224. mvwprintw(text_win,
  225. main_ycord, 1,
  226. "slurm_load_block: %s",
  227. slurm_strerror(slurm_get_errno()));
  228. main_ycord++;
  229. } else {
  230. printf("slurm_load_block: %s\n",
  231. slurm_strerror(slurm_get_errno()));
  232. }
  233. }
  234. return;
  235. }
  236. if (block_list) {
  237. /* clear the old list */
  238. list_flush(block_list);
  239. } else {
  240. block_list = list_create(_block_list_del);
  241. if (!block_list) {
  242. fprintf(stderr, "malloc error\n");
  243. return;
  244. }
  245. }
  246. if (!params.commandline)
  247. if ((new_bg_ptr->record_count - text_line_cnt)
  248. < (getmaxy(text_win) - 4))
  249. text_line_cnt--;
  250. if (params.hl)
  251. nodes_req = get_requested_node_bitmap();
  252. for (i = 0; i < new_bg_ptr->record_count; i++) {
  253. if (nodes_req) {
  254. int overlap = 0;
  255. bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req));
  256. inx2bitstr(loc_bitmap,
  257. new_bg_ptr->block_array[i].mp_inx);
  258. overlap = bit_overlap(loc_bitmap, nodes_req);
  259. FREE_NULL_BITMAP(loc_bitmap);
  260. if (!overlap)
  261. continue;
  262. }
  263. if (params.io_bit && new_bg_ptr->block_array[i].ionode_str) {
  264. int overlap = 0;
  265. bitstr_t *loc_bitmap =
  266. bit_alloc(bit_size(params.io_bit));
  267. inx2bitstr(loc_bitmap,
  268. new_bg_ptr->block_array[i].ionode_inx);
  269. overlap = bit_overlap(loc_bitmap, params.io_bit);
  270. FREE_NULL_BITMAP(loc_bitmap);
  271. if (!overlap)
  272. continue;
  273. }
  274. block_ptr = xmalloc(sizeof(db2_block_info_t));
  275. block_ptr->bg_block_name
  276. = xstrdup(new_bg_ptr->block_array[i].bg_block_id);
  277. block_ptr->mp_str = xstrdup(new_bg_ptr->block_array[i].mp_str);
  278. block_ptr->nodelist = list_create(_nodelist_del);
  279. _make_nodelist(block_ptr->mp_str, block_ptr->nodelist);
  280. block_ptr->state = new_bg_ptr->block_array[i].state;
  281. memcpy(block_ptr->bg_conn_type,
  282. new_bg_ptr->block_array[i].conn_type,
  283. sizeof(block_ptr->bg_conn_type));
  284. if (params.cluster_flags & CLUSTER_FLAG_BGL)
  285. block_ptr->bg_node_use =
  286. new_bg_ptr->block_array[i].node_use;
  287. block_ptr->ionode_str
  288. = xstrdup(new_bg_ptr->block_array[i].ionode_str);
  289. block_ptr->cnode_cnt = new_bg_ptr->block_array[i].cnode_cnt;
  290. itr = list_iterator_create(block_list);
  291. while ((found_block = (db2_block_info_t*)list_next(itr))) {
  292. if (!strcmp(block_ptr->mp_str, found_block->mp_str)) {
  293. block_ptr->letter_num =
  294. found_block->letter_num;
  295. break;
  296. }
  297. }
  298. list_iterator_destroy(itr);
  299. if (!found_block) {
  300. last_count++;
  301. _marknodes(block_ptr, last_count);
  302. }
  303. block_ptr->job_list = list_create(slurm_free_block_job_info);
  304. if (new_bg_ptr->block_array[i].job_list) {
  305. block_job_info_t *found_job;
  306. ListIterator itr = list_iterator_create(
  307. new_bg_ptr->block_array[i].job_list);
  308. while ((found_job = list_next(itr))) {
  309. block_job_info_t *block_job =
  310. xmalloc(sizeof(block_job_info_t));
  311. block_job->job_id = found_job->job_id;
  312. list_append(block_ptr->job_list, block_job);
  313. }
  314. list_iterator_destroy(itr);
  315. }
  316. if (block_ptr->bg_conn_type[0] >= SELECT_SMALL)
  317. block_ptr->size = 0;
  318. list_append(block_list, block_ptr);
  319. }
  320. if (!params.no_header)
  321. _print_header_part();
  322. if (new_part_ptr)
  323. recs = new_part_ptr->record_count;
  324. else
  325. recs = 0;
  326. for (i = 0; i < recs; i++) {
  327. part = new_part_ptr->partition_array[i];
  328. if (!part.nodes || (part.nodes[0] == '\0'))
  329. continue; /* empty partition */
  330. nodelist = list_create(_nodelist_del);
  331. _make_nodelist(part.nodes, nodelist);
  332. if (block_list) {
  333. itr = list_iterator_create(block_list);
  334. while ((block_ptr = (db2_block_info_t*)
  335. list_next(itr)) != NULL) {
  336. if (_in_slurm_partition(nodelist,
  337. block_ptr->nodelist)) {
  338. block_ptr->slurm_part_name
  339. = xstrdup(part.name);
  340. }
  341. }
  342. list_iterator_destroy(itr);
  343. }
  344. list_destroy(nodelist);
  345. }
  346. /* Report the BG Blocks */
  347. if (block_list) {
  348. itr = list_iterator_create(block_list);
  349. while ((block_ptr = (db2_block_info_t*)
  350. list_next(itr)) != NULL) {
  351. if (params.commandline)
  352. block_ptr->printed = 1;
  353. else {
  354. if (count>=text_line_cnt)
  355. block_ptr->printed = 1;
  356. }
  357. _print_rest(block_ptr);
  358. count++;
  359. }
  360. list_iterator_destroy(itr);
  361. }
  362. if (params.commandline && params.iterate)
  363. printf("\n");
  364. part_info_ptr = new_part_ptr;
  365. bg_info_ptr = new_bg_ptr;
  366. return;
  367. }
  368. static char *_set_running_job_str(List job_list, bool compact)
  369. {
  370. int cnt = list_count(job_list);
  371. block_job_info_t *block_job;
  372. if (!cnt) {
  373. return xstrdup("-");
  374. } else if (cnt == 1) {
  375. block_job = list_peek(job_list);
  376. return xstrdup_printf("%u", block_job->job_id);
  377. } else if (compact)
  378. return xstrdup("multiple");
  379. else {
  380. char *tmp_char = NULL;
  381. ListIterator itr = list_iterator_create(job_list);
  382. while ((block_job = list_next(itr))) {
  383. if (tmp_char)
  384. xstrcat(tmp_char, " ");
  385. xstrfmtcat(tmp_char, "%u", block_job->job_id);
  386. }
  387. return tmp_char;
  388. }
  389. return NULL;
  390. }
  391. static void _marknodes(db2_block_info_t *block_ptr, int count)
  392. {
  393. int i, j = 0;
  394. int start[params.cluster_dims];
  395. int end[params.cluster_dims];
  396. char *nodes = block_ptr->mp_str;
  397. block_ptr->letter_num = count;
  398. while (nodes[j] != '\0') {
  399. int mid = j + params.cluster_dims + 1;
  400. int fin = mid + params.cluster_dims + 1;
  401. if (((nodes[j] == '[') || (nodes[j] == ',')) &&
  402. ((nodes[mid] == 'x') || (nodes[mid] == '-')) &&
  403. ((nodes[fin] == ']') || (nodes[fin] == ','))) {
  404. j++; /* Skip leading '[' or ',' */
  405. for (i = 0; i < params.cluster_dims; i++, j++)
  406. start[i] = select_char2coord(nodes[j]);
  407. j++; /* Skip middle 'x' or '-' */
  408. for (i = 0; i < params.cluster_dims; i++, j++)
  409. end[i] = select_char2coord(nodes[j]);
  410. if (block_ptr->state != BG_BLOCK_FREE) {
  411. block_ptr->size += set_grid_bg(
  412. start, end, count, 1);
  413. } else {
  414. block_ptr->size += set_grid_bg(
  415. start, end, count, 0);
  416. }
  417. if (nodes[j] != ',')
  418. break;
  419. } else if (((nodes[j] >= '0') && (nodes[j] <= '9')) ||
  420. ((nodes[j] >= 'A') && (nodes[j] <= 'Z'))) {
  421. for (i = 0; i < params.cluster_dims; i++, j++)
  422. start[i] = select_char2coord(nodes[j]);
  423. block_ptr->size += set_grid_bg(start, start, count, 1);
  424. if (nodes[j] != ',')
  425. break;
  426. } else
  427. j++;
  428. }
  429. }
  430. static void _print_header_part(void)
  431. {
  432. if (!params.commandline) {
  433. mvwprintw(text_win, main_ycord,
  434. main_xcord, "ID");
  435. main_xcord += 4;
  436. mvwprintw(text_win, main_ycord,
  437. main_xcord, "PARTITION");
  438. main_xcord += 10;
  439. if (params.display != BGPART) {
  440. mvwprintw(text_win,
  441. main_ycord,
  442. main_xcord, "AVAIL");
  443. main_xcord += 7;
  444. mvwprintw(text_win,
  445. main_ycord,
  446. main_xcord, "TIMELIMIT");
  447. main_xcord += 11;
  448. } else {
  449. mvwprintw(text_win,
  450. main_ycord,
  451. main_xcord, "BG_BLOCK");
  452. main_xcord += 18;
  453. mvwprintw(text_win,
  454. main_ycord,
  455. main_xcord, "STATE");
  456. main_xcord += 8;
  457. mvwprintw(text_win,
  458. main_ycord,
  459. main_xcord, "JOBID");
  460. main_xcord += 8;
  461. mvwprintw(text_win,
  462. main_ycord,
  463. main_xcord, "CONN");
  464. main_xcord += 8;
  465. if (params.cluster_flags & CLUSTER_FLAG_BGL) {
  466. mvwprintw(text_win,
  467. main_ycord,
  468. main_xcord, "NODE_USE");
  469. main_xcord += 10;
  470. }
  471. }
  472. mvwprintw(text_win, main_ycord,
  473. main_xcord, "NODES");
  474. main_xcord += 7;
  475. if (params.cluster_flags & CLUSTER_FLAG_BG)
  476. mvwprintw(text_win, main_ycord,
  477. main_xcord, "MIDPLANELIST");
  478. else
  479. mvwprintw(text_win, main_ycord,
  480. main_xcord, "NODELIST");
  481. main_xcord = 1;
  482. main_ycord++;
  483. } else {
  484. printf("PARTITION ");
  485. if (params.display != BGPART) {
  486. printf("AVAIL ");
  487. printf("TIMELIMIT ");
  488. } else {
  489. printf(" BG_BLOCK ");
  490. printf("STATE ");
  491. printf(" JOBID ");
  492. printf(" CONN ");
  493. if (params.cluster_flags & CLUSTER_FLAG_BGL)
  494. printf(" NODE_USE ");
  495. }
  496. printf("NODES ");
  497. if (params.cluster_flags & CLUSTER_FLAG_BG)
  498. printf("MIDPLANELIST\n");
  499. else
  500. printf("NODELIST\n");
  501. }
  502. }
  503. static int _print_text_part(partition_info_t *part_ptr,
  504. db2_block_info_t *db2_info_ptr)
  505. {
  506. int printed = 0;
  507. int tempxcord;
  508. int prefixlen;
  509. int i = 0;
  510. int width = 0;
  511. char *nodes = NULL, time_buf[20], *conn_str = NULL;
  512. char tmp_cnt[8];
  513. char tmp_char[8];
  514. if (params.cluster_flags & CLUSTER_FLAG_BG)
  515. convert_num_unit((float)part_ptr->total_nodes, tmp_cnt,
  516. sizeof(tmp_cnt), UNIT_NONE);
  517. else
  518. snprintf(tmp_cnt, sizeof(tmp_cnt), "%u", part_ptr->total_nodes);
  519. if (!params.commandline) {
  520. mvwprintw(text_win,
  521. main_ycord,
  522. main_xcord, "%c",
  523. part_ptr->flags);
  524. main_xcord += 4;
  525. if (part_ptr->name) {
  526. mvwprintw(text_win,
  527. main_ycord,
  528. main_xcord, "%.9s",
  529. part_ptr->name);
  530. main_xcord += 10;
  531. if (params.display != BGPART) {
  532. char *tmp_state;
  533. if (part_ptr->state_up == PARTITION_INACTIVE)
  534. tmp_state = "inact";
  535. else if (part_ptr->state_up == PARTITION_UP)
  536. tmp_state = "up";
  537. else if (part_ptr->state_up == PARTITION_DOWN)
  538. tmp_state = "down";
  539. else if (part_ptr->state_up == PARTITION_DRAIN)
  540. tmp_state = "drain";
  541. else
  542. tmp_state = "unk";
  543. mvwprintw(text_win, main_ycord, main_xcord,
  544. tmp_state);
  545. main_xcord += 7;
  546. if (part_ptr->max_time == INFINITE)
  547. snprintf(time_buf, sizeof(time_buf),
  548. "infinite");
  549. else {
  550. secs2time_str((part_ptr->max_time
  551. * 60),
  552. time_buf,
  553. sizeof(time_buf));
  554. }
  555. width = strlen(time_buf);
  556. mvwprintw(text_win,
  557. main_ycord,
  558. main_xcord + (9 - width),
  559. "%s",
  560. time_buf);
  561. main_xcord += 11;
  562. }
  563. } else
  564. main_xcord += 10;
  565. if (params.display == BGPART) {
  566. if (db2_info_ptr) {
  567. char *job_running = _set_running_job_str(
  568. db2_info_ptr->job_list, 1);
  569. mvwprintw(text_win,
  570. main_ycord,
  571. main_xcord, "%.16s",
  572. db2_info_ptr->bg_block_name);
  573. main_xcord += 18;
  574. mvwprintw(text_win,
  575. main_ycord,
  576. main_xcord, "%.7s",
  577. bg_block_state_string(
  578. db2_info_ptr->state));
  579. main_xcord += 8;
  580. snprintf(tmp_char, sizeof(tmp_char),
  581. "%s", job_running);
  582. xfree(job_running);
  583. mvwprintw(text_win,
  584. main_ycord,
  585. main_xcord,
  586. "%.8s", tmp_char);
  587. main_xcord += 8;
  588. conn_str = conn_type_string_full(
  589. db2_info_ptr->bg_conn_type);
  590. mvwprintw(text_win,
  591. main_ycord,
  592. main_xcord, "%.7s",
  593. conn_str);
  594. xfree(conn_str);
  595. main_xcord += 8;
  596. if (params.cluster_flags & CLUSTER_FLAG_BGL) {
  597. mvwprintw(text_win,
  598. main_ycord,
  599. main_xcord, "%.9s",
  600. node_use_string(
  601. db2_info_ptr->
  602. bg_node_use));
  603. main_xcord += 10;
  604. }
  605. } else {
  606. mvwprintw(text_win,
  607. main_ycord,
  608. main_xcord, "?");
  609. main_xcord += 18;
  610. mvwprintw(text_win,
  611. main_ycord,
  612. main_xcord, "?");
  613. main_xcord += 8;
  614. mvwprintw(text_win,
  615. main_ycord,
  616. main_xcord, "?");
  617. main_xcord += 8;
  618. mvwprintw(text_win,
  619. main_ycord,
  620. main_xcord, "?");
  621. main_xcord += 9;
  622. mvwprintw(text_win,
  623. main_ycord,
  624. main_xcord, "?");
  625. main_xcord += 7;
  626. mvwprintw(text_win,
  627. main_ycord,
  628. main_xcord, "?");
  629. main_xcord += 10;
  630. }
  631. }
  632. mvwprintw(text_win,
  633. main_ycord,
  634. main_xcord, "%5s", tmp_cnt);
  635. main_xcord += 7;
  636. tempxcord = main_xcord;
  637. if (params.display == BGPART)
  638. nodes = part_ptr->allow_groups;
  639. else
  640. nodes = part_ptr->nodes;
  641. i = 0;
  642. prefixlen = i;
  643. while (nodes && nodes[i]) {
  644. width = getmaxx(text_win) - 1 - main_xcord;
  645. if (!prefixlen && (nodes[i] == '[') &&
  646. (nodes[i - 1] == ','))
  647. prefixlen = i + 1;
  648. if (nodes[i - 1] == ',' && (width - 12) <= 0) {
  649. main_ycord++;
  650. main_xcord = tempxcord + prefixlen;
  651. } else if (main_xcord >= getmaxx(text_win)) {
  652. main_ycord++;
  653. main_xcord = tempxcord + prefixlen;
  654. }
  655. if ((printed = mvwaddch(text_win,
  656. main_ycord,
  657. main_xcord,
  658. nodes[i])) < 0)
  659. return printed;
  660. main_xcord++;
  661. i++;
  662. }
  663. if ((params.display == BGPART) && db2_info_ptr &&
  664. (db2_info_ptr->ionode_str)) {
  665. mvwprintw(text_win,
  666. main_ycord,
  667. main_xcord, "[%s]",
  668. db2_info_ptr->ionode_str);
  669. }
  670. main_xcord = 1;
  671. main_ycord++;
  672. } else {
  673. if (part_ptr->name) {
  674. printf("%9.9s ", part_ptr->name);
  675. if (params.display != BGPART) {
  676. if (part_ptr->state_up == PARTITION_INACTIVE)
  677. printf(" inact ");
  678. else if (part_ptr->state_up == PARTITION_UP)
  679. printf(" up ");
  680. else if (part_ptr->state_up == PARTITION_DOWN)
  681. printf(" down ");
  682. else if (part_ptr->state_up == PARTITION_DRAIN)
  683. printf(" drain ");
  684. else
  685. printf(" unk ");
  686. if (part_ptr->max_time == INFINITE)
  687. snprintf(time_buf, sizeof(time_buf),
  688. "infinite");
  689. else {
  690. secs2time_str((part_ptr->max_time
  691. * 60),
  692. time_buf,
  693. sizeof(time_buf));
  694. }
  695. width = strlen(time_buf);
  696. printf("%9.9s ", time_buf);
  697. }
  698. }
  699. if (params.display == BGPART) {
  700. if (db2_info_ptr) {
  701. char *job_running = _set_running_job_str(
  702. db2_info_ptr->job_list, 1);
  703. printf("%16.16s ",
  704. db2_info_ptr->bg_block_name);
  705. printf("%-7.7s ",
  706. bg_block_state_string(
  707. db2_info_ptr->state));
  708. printf("%8.8s ", job_running);
  709. xfree(job_running);
  710. conn_str = conn_type_string_full(
  711. db2_info_ptr->bg_conn_type);
  712. printf("%8.8s ", conn_str);
  713. xfree(conn_str);
  714. if (params.cluster_flags & CLUSTER_FLAG_BGL)
  715. printf("%9.9s ", node_use_string(
  716. db2_info_ptr->
  717. bg_node_use));
  718. }
  719. }
  720. printf("%5s ", tmp_cnt);
  721. if (params.display == BGPART)
  722. nodes = part_ptr->allow_groups;
  723. else
  724. nodes = part_ptr->nodes;
  725. if ((params.display == BGPART) && db2_info_ptr &&
  726. (db2_info_ptr->ionode_str)) {
  727. printf("%s[%s]\n", nodes, db2_info_ptr->ionode_str);
  728. } else
  729. printf("%s\n",nodes);
  730. }
  731. return printed;
  732. }
  733. static void _block_list_del(void *object)
  734. {
  735. db2_block_info_t *block_ptr = (db2_block_info_t *)object;
  736. if (block_ptr) {
  737. xfree(block_ptr->bg_block_name);
  738. xfree(block_ptr->slurm_part_name);
  739. xfree(block_ptr->mp_str);
  740. xfree(block_ptr->ionode_str);
  741. if (block_ptr->nodelist)
  742. list_destroy(block_ptr->nodelist);
  743. if (block_ptr->job_list) {
  744. list_destroy(block_ptr->job_list);
  745. block_ptr->job_list = NULL;
  746. }
  747. xfree(block_ptr);
  748. }
  749. }
  750. static void _nodelist_del(void *object)
  751. {
  752. int *coord = (int *)object;
  753. xfree(coord);
  754. return;
  755. }
  756. static int _in_slurm_partition(List slurm_nodes, List bg_nodes)
  757. {
  758. ListIterator slurm_itr;
  759. ListIterator bg_itr;
  760. int *coord = NULL;
  761. int *slurm_coord = NULL;
  762. int found = 0, i;
  763. bg_itr = list_iterator_create(bg_nodes);
  764. slurm_itr = list_iterator_create(slurm_nodes);
  765. while ((coord = list_next(bg_itr)) != NULL) {
  766. list_iterator_reset(slurm_itr);
  767. found = 0;
  768. while ((slurm_coord = list_next(slurm_itr)) != NULL) {
  769. for (i = 0; i < params.cluster_dims; i++) {
  770. if (coord[i] != slurm_coord[i])
  771. break;
  772. }
  773. if (i >= params.cluster_dims) {
  774. found = 1;
  775. break;
  776. }
  777. }
  778. if (!found)
  779. break;
  780. }
  781. list_iterator_destroy(slurm_itr);
  782. list_iterator_destroy(bg_itr);
  783. if (found)
  784. return 1;
  785. else
  786. return 0;
  787. }
  788. static int _print_rest(db2_block_info_t *block_ptr)
  789. {
  790. partition_info_t part;
  791. if (block_ptr->cnode_cnt == 0)
  792. block_ptr->cnode_cnt = block_ptr->size;
  793. part.total_nodes = block_ptr->cnode_cnt;
  794. if (block_ptr->slurm_part_name)
  795. part.name = block_ptr->slurm_part_name;
  796. else
  797. part.name = "no part";
  798. if (!block_ptr->printed)
  799. return SLURM_SUCCESS;
  800. part.allow_groups = block_ptr->mp_str;
  801. part.flags = (int) letters[block_ptr->letter_num%62];
  802. if (!params.commandline) {
  803. wattron(text_win,
  804. COLOR_PAIR(colors[block_ptr->letter_num%6]));
  805. _print_text_part(&part, block_ptr);
  806. wattroff(text_win,
  807. COLOR_PAIR(colors[block_ptr->letter_num%6]));
  808. } else {
  809. _print_text_part(&part, block_ptr);
  810. }
  811. return SLURM_SUCCESS;
  812. }
  813. static int *_build_coord(int *current)
  814. {
  815. int i;
  816. int *coord = NULL;
  817. coord = xmalloc(sizeof(int) * params.cluster_dims);
  818. for (i = 0; i < params.cluster_dims; i++)
  819. coord[i] = current[i];
  820. return coord;
  821. }
  822. /* increment an array, return false if can't be incremented (reached limts) */
  823. static bool _incr_coord(int *start, int *end, int *current)
  824. {
  825. int i;
  826. for (i = 0; i < params.cluster_dims; i++) {
  827. current[i]++;
  828. if (current[i] <= end[i])
  829. return true;
  830. current[i] = start[i];
  831. }
  832. return false;
  833. }
  834. static void _addto_nodelist(List nodelist, int *start, int *end)
  835. {
  836. int *coord = NULL;
  837. int i;
  838. coord = xmalloc(sizeof(int) * params.cluster_dims);
  839. for (i = 0; i < params.cluster_dims; i++) {
  840. xassert(start[i] >= 0);
  841. coord[i] = start[i];
  842. if (end[i] < dim_size[i])
  843. continue;
  844. fatal("It appears the slurm.conf file has changed since "
  845. "the last restart.\nThings are in an incompatible "
  846. "state, please restart the slurmctld.");
  847. }
  848. do {
  849. list_append(nodelist, _build_coord(coord));
  850. } while (_incr_coord(start, end, coord));
  851. xfree(coord);
  852. }
  853. static int _make_nodelist(char *nodes, List nodelist)
  854. {
  855. int i, j = 0;
  856. int start[params.cluster_dims];
  857. int end[params.cluster_dims];
  858. if (!nodelist)
  859. nodelist = list_create(_nodelist_del);
  860. while (nodes[j] != '\0') {
  861. int mid = j + params.cluster_dims + 1;
  862. int fin = mid + params.cluster_dims + 1;
  863. if (((nodes[j] == '[') || (nodes[j] == ',')) &&
  864. ((nodes[mid] == 'x') || (nodes[mid] == '-')) &&
  865. ((nodes[fin] == ']') || (nodes[fin] == ','))) {
  866. j++; /* Skip leading '[' or ',' */
  867. for (i = 0; i < params.cluster_dims; i++, j++)
  868. start[i] = select_char2coord(nodes[j]);
  869. j++; /* Skip middle 'x' or '-' */
  870. for (i = 0; i < params.cluster_dims; i++, j++)
  871. end[i] = select_char2coord(nodes[j]);
  872. _addto_nodelist(nodelist, start, end);
  873. if (nodes[j] != ',')
  874. break;
  875. j--;
  876. } else if (((nodes[j] >= '0') && (nodes[j] <= '9')) ||
  877. ((nodes[j] >= 'A') && (nodes[j] <= 'Z'))) {
  878. for (i = 0; i < params.cluster_dims; i++, j++)
  879. start[i] = select_char2coord(nodes[j]);
  880. _addto_nodelist(nodelist, start, start);
  881. if (nodes[j] != ',')
  882. break;
  883. j--;
  884. }
  885. j++;
  886. }
  887. return 1;
  888. }