PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/smap/configure_functions.c

https://github.com/cfenoy/slurm
C | 1556 lines | 1336 code | 158 blank | 62 comment | 373 complexity | 02d5763237d1b065d538d6cb6f6b7541 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * configure_functions.c - Functions related to configure mode of smap.
  3. *****************************************************************************
  4. * Copyright (C) 2002-2007 The Regents of the University of California.
  5. * Copyright (C) 2008-2011 Lawrence Livermore National Security.
  6. * Copyright (C) 2011 SchedMD LLC.
  7. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  8. * Written by Danny Auble <da@schedmd.com>
  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/uid.h"
  43. #include "src/common/xstring.h"
  44. #include "src/common/proc_args.h"
  45. ///////////////////////////////////////////////////////////////////////
  46. typedef struct {
  47. int color;
  48. int color_count;
  49. char letter;
  50. List nodes;
  51. select_ba_request_t *request;
  52. } allocated_block_t;
  53. static int _add_bg_record(select_ba_request_t *blockreq,
  54. List allocated_blocks);
  55. static int _change_state_all_bps(char *com, int state);
  56. static int _change_state_bps(char *com, int state);
  57. static int _copy_allocation(char *com, List allocated_blocks);
  58. static int _create_allocation(char *com, List allocated_blocks);
  59. static int _load_configuration(char *com, List allocated_blocks);
  60. static allocated_block_t *_make_request(select_ba_request_t *request);
  61. static void _print_header_command(void);
  62. static void _print_text_command(allocated_block_t *allocated_block);
  63. static int _remove_allocation(char *com, List allocated_blocks);
  64. static int _resolve(char *com);
  65. static int _save_allocation(char *com, List allocated_blocks);
  66. static int _set_layout(char *com);
  67. static int _set_base_part_cnt(char *com);
  68. static int _set_nodecard_cnt(char *com);
  69. int color_count = 0;
  70. char error_string[255];
  71. int base_part_node_cnt = 512;
  72. int nodecard_node_cnt = 32;
  73. char *layout_mode = "STATIC";
  74. static void _set_nodes(List nodes, int color, char letter)
  75. {
  76. ListIterator itr;
  77. smap_node_t *smap_node;
  78. ba_mp_t *ba_mp;
  79. if (!nodes || !smap_system_ptr)
  80. return;
  81. itr = list_iterator_create(nodes);
  82. while ((ba_mp = list_next(itr))) {
  83. if (!ba_mp->used)
  84. continue;
  85. smap_node = smap_system_ptr->grid[ba_mp->index];
  86. smap_node->color = color;
  87. smap_node->letter = letter;
  88. }
  89. list_iterator_destroy(itr);
  90. return;
  91. }
  92. static void _destroy_allocated_block(void *object)
  93. {
  94. allocated_block_t *allocated_block = (allocated_block_t *)object;
  95. if (allocated_block) {
  96. bool is_small = (allocated_block->request->conn_type[0] >=
  97. SELECT_SMALL);
  98. if (allocated_block->nodes) {
  99. _set_nodes(allocated_block->nodes, 0, '.');
  100. bg_configure_remove_block(
  101. allocated_block->nodes, is_small);
  102. list_destroy(allocated_block->nodes);
  103. }
  104. destroy_select_ba_request(allocated_block->request);
  105. xfree(allocated_block);
  106. }
  107. }
  108. static allocated_block_t *_make_request(select_ba_request_t *request)
  109. {
  110. List results = list_create(NULL);
  111. allocated_block_t *allocated_block = NULL;
  112. #ifdef HAVE_BGQ
  113. results = list_create(bg_configure_destroy_ba_mp);
  114. #else
  115. results = list_create(NULL);
  116. #endif
  117. if (bg_configure_allocate_block(request, results)) {
  118. char *pass = bg_configure_ba_passthroughs_string(
  119. request->deny_pass);
  120. if (pass) {
  121. sprintf(error_string,"THERE ARE PASSTHROUGHS IN "
  122. "THIS ALLOCATION DIM %s!!!!!!!", pass);
  123. xfree(pass);
  124. }
  125. allocated_block = xmalloc(sizeof(allocated_block_t));
  126. allocated_block->request = request;
  127. allocated_block->nodes = results;
  128. allocated_block->letter = letters[color_count%62];
  129. allocated_block->color = colors[color_count%6];
  130. allocated_block->color_count = color_count++;
  131. _set_nodes(allocated_block->nodes,
  132. allocated_block->color,
  133. allocated_block->letter);
  134. results = NULL;
  135. }
  136. if (results)
  137. list_destroy(results);
  138. return allocated_block;
  139. }
  140. static int _full_request(select_ba_request_t *request,
  141. bitstr_t *usable_mp_bitmap,
  142. List allocated_blocks)
  143. {
  144. char *tmp_char = NULL, *tmp_char2 = NULL;
  145. allocated_block_t *allocated_block;
  146. int rc = 1;
  147. if (!strcasecmp(layout_mode,"OVERLAP"))
  148. bg_configure_reset_ba_system(true);
  149. if (usable_mp_bitmap)
  150. bg_configure_ba_set_removable_mps(usable_mp_bitmap, 1);
  151. /*
  152. * Here is where we do the allocating of the partition.
  153. * It will send a request back which we will throw into
  154. * a list just incase we change something later.
  155. */
  156. if (!bg_configure_new_ba_request(request)) {
  157. memset(error_string, 0, 255);
  158. if (request->size != -1) {
  159. sprintf(error_string,
  160. "Problems with request for %d\n"
  161. "Either you put in something "
  162. "that doesn't work,\n"
  163. "or we are unable to process "
  164. "your request.",
  165. request->size);
  166. rc = 0;
  167. } else {
  168. tmp_char = bg_configure_give_geo(request->geometry,
  169. params.cluster_dims,
  170. 1);
  171. sprintf(error_string,
  172. "Problems with request of size %s\n"
  173. "Either you put in something "
  174. "that doesn't work,\n"
  175. "or we are unable to process "
  176. "your request.",
  177. tmp_char);
  178. xfree(tmp_char);
  179. rc = 0;
  180. }
  181. } else {
  182. if ((allocated_block = _make_request(request)) != NULL)
  183. list_append(allocated_blocks, allocated_block);
  184. else {
  185. if (request->geometry[0] != (uint16_t)NO_VAL)
  186. tmp_char = bg_configure_give_geo(
  187. request->geometry,
  188. params.cluster_dims, 1);
  189. tmp_char2 = bg_configure_give_geo(request->start,
  190. params.cluster_dims,
  191. 1);
  192. memset(error_string, 0, 255);
  193. sprintf(error_string,
  194. "allocate failure\nSize requested "
  195. "was %d MidPlanes\n",
  196. request->size);
  197. if (tmp_char) {
  198. sprintf(error_string + strlen(error_string),
  199. "Geo requested was %s\n", tmp_char);
  200. xfree(tmp_char);
  201. } else {
  202. sprintf(error_string + strlen(error_string),
  203. "No geometry could be laid out "
  204. "for that size\n");
  205. }
  206. sprintf(error_string + strlen(error_string),
  207. "Start position was %s", tmp_char2);
  208. xfree(tmp_char2);
  209. rc = 0;
  210. }
  211. }
  212. if (usable_mp_bitmap)
  213. bg_configure_ba_reset_all_removed_mps();
  214. return rc;
  215. }
  216. static int _set_layout(char *com)
  217. {
  218. int i;
  219. for (i = 0; com[i]; i++) {
  220. if (!strncasecmp(com+i, "dynamic", 7)) {
  221. layout_mode = "DYNAMIC";
  222. break;
  223. } else if (!strncasecmp(com+i, "static", 6)) {
  224. layout_mode = "STATIC";
  225. break;
  226. } else if (!strncasecmp(com+i, "overlap", 7)) {
  227. layout_mode = "OVERLAP";
  228. break;
  229. }
  230. }
  231. if (com[i] == '\0') {
  232. sprintf(error_string,
  233. "You didn't put in a mode that I recognized. \n"
  234. "Please use STATIC, OVERLAP, or DYNAMIC\n");
  235. return 0;
  236. }
  237. sprintf(error_string,
  238. "LayoutMode set to %s\n", layout_mode);
  239. return 1;
  240. }
  241. static int _set_base_part_cnt(char *com)
  242. {
  243. int i;
  244. for (i = 0; com[i]; i++) {
  245. if ((com[i] >= '0') && (com[i] <= '9'))
  246. break;
  247. }
  248. if (com[i] == '\0') {
  249. sprintf(error_string,
  250. "I didn't notice the number you typed in\n");
  251. return 0;
  252. }
  253. base_part_node_cnt = atoi(&com[i]);
  254. memset(error_string, 0, 255);
  255. sprintf(error_string,
  256. "BasePartitionNodeCnt set to %d\n", base_part_node_cnt);
  257. return 1;
  258. }
  259. static int _set_nodecard_cnt(char *com)
  260. {
  261. int i;
  262. for (i = 0; com[i]; i++) {
  263. if ((com[i] >= '0') && (com[i] <= '9'))
  264. break;
  265. }
  266. if (com[i] == '\0') {
  267. sprintf(error_string,
  268. "I didn't notice the number you typed in\n");
  269. return 0;
  270. }
  271. nodecard_node_cnt = atoi(&com[i]);
  272. memset(error_string, 0, 255);
  273. sprintf(error_string,
  274. "NodeCardNodeCnt set to %d\n", nodecard_node_cnt);
  275. return 1;
  276. }
  277. static int _xlate_coord(char *str, int len)
  278. {
  279. if (len > 1)
  280. return xstrntol(str, NULL, len, 10);
  281. else
  282. return xstrntol(str, NULL, len, params.cluster_base);
  283. }
  284. static int _create_allocation(char *com, List allocated_blocks)
  285. {
  286. int i=6, j, geoi=-1, starti=-1, i2=0, small32=-1, small128=-1;
  287. int len = strlen(com);
  288. select_ba_request_t *request;
  289. char fini_char;
  290. int diff=0;
  291. #ifndef HAVE_BGL
  292. #ifdef HAVE_BGP
  293. int small16=-1;
  294. #endif
  295. int small64=-1, small256=-1;
  296. #endif
  297. request = (select_ba_request_t*) xmalloc(sizeof(select_ba_request_t));
  298. request->rotate = false;
  299. request->elongate = false;
  300. request->start_req = 0;
  301. request->size = 0;
  302. request->small32 = 0;
  303. request->small128 = 0;
  304. request->deny_pass = 0;
  305. request->avail_mp_bitmap = NULL;
  306. for (j = 0; j < params.cluster_dims; j++) {
  307. request->geometry[j] = (uint16_t) NO_VAL;
  308. request->conn_type[j] = SELECT_TORUS;
  309. }
  310. while (i < len) {
  311. if (!strncasecmp(com+i, "mesh", 4)
  312. || !strncasecmp(com+i, "small", 5)
  313. || !strncasecmp(com+i, "torus", 5)) {
  314. char conn_type[200];
  315. j = i;
  316. while (j < len) {
  317. if (com[j] == ' ')
  318. break;
  319. conn_type[j-i] = com[j];
  320. j++;
  321. if (j >= 200)
  322. break;
  323. }
  324. conn_type[(j-i)+1] = '\0';
  325. verify_conn_type(conn_type, request->conn_type);
  326. i += j;
  327. } else if (!strncasecmp(com+i, "deny", 4)) {
  328. i += 4;
  329. if (strstr(com+i, "A"))
  330. request->deny_pass |= PASS_DENY_A;
  331. if (strstr(com+i, "X"))
  332. request->deny_pass |= PASS_DENY_X;
  333. if (strstr(com+i, "Y"))
  334. request->deny_pass |= PASS_DENY_Y;
  335. if (strstr(com+i, "Z"))
  336. request->deny_pass |= PASS_DENY_Z;
  337. if (!strcasecmp(com+i, "ALL"))
  338. request->deny_pass |= PASS_DENY_ALL;
  339. } else if (!strncasecmp(com+i, "nodecard", 8)) {
  340. small32 = 0;
  341. i += 8;
  342. } else if (!strncasecmp(com+i, "quarter", 7)) {
  343. small128 = 0;
  344. i += 7;
  345. } else if (!strncasecmp(com+i, "32CN", 4)) {
  346. small32 = 0;
  347. i += 4;
  348. } else if (!strncasecmp(com+i, "128CN", 5)) {
  349. small128 = 0;
  350. i += 5;
  351. } else if (!strncasecmp(com+i, "rotate", 6)) {
  352. request->rotate = true;
  353. i += 6;
  354. } else if (!strncasecmp(com+i, "elongate", 8)) {
  355. request->elongate = true;
  356. i += 8;
  357. } else if (!strncasecmp(com+i, "start", 5)) {
  358. request->start_req = 1;
  359. i += 5;
  360. } else if (request->start_req && (starti < 0) &&
  361. (((com[i] >= '0') && (com[i] <= '9')) ||
  362. ((com[i] >= 'A') && (com[i] <= 'Z')))) {
  363. starti = i;
  364. i++;
  365. } else if (small32 == 0 && (com[i] >= '0' && com[i] <= '9')) {
  366. small32 = i;
  367. i++;
  368. } else if (small128 == 0 && (com[i] >= '0' && com[i] <= '9')) {
  369. small128 = i;
  370. i++;
  371. }
  372. #ifdef HAVE_BGP
  373. else if (!strncasecmp(com+i, "16CN", 4)) {
  374. small16 = 0;
  375. i += 4;
  376. } else if (small16 == 0 && (com[i] >= '0' && com[i] <= '9')) {
  377. small16 = i;
  378. i++;
  379. }
  380. #endif
  381. #ifndef HAVE_BGL
  382. else if (!strncasecmp(com+i, "64CN", 4)) {
  383. small64 = 0;
  384. i += 4;
  385. } else if (!strncasecmp(com+i, "256CN", 5)) {
  386. small256 = 0;
  387. i += 5;
  388. } else if (small64 == 0 && (com[i] >= '0' && com[i] <= '9')) {
  389. small64 = i;
  390. i++;
  391. } else if (small256 == 0 && (com[i] >= '0' && com[i] <= '9')) {
  392. small256 = i;
  393. i++;
  394. }
  395. #endif
  396. else if ((geoi < 0) &&
  397. (((com[i] >= '0') && (com[i] <= '9')) ||
  398. ((com[i] >= 'A') && (com[i] <= 'Z')))) {
  399. geoi = i;
  400. i++;
  401. } else {
  402. i++;
  403. }
  404. }
  405. if (request->conn_type[0] >= SELECT_SMALL) {
  406. int total = 512;
  407. #ifdef HAVE_BGP
  408. if (small16 > 0) {
  409. request->small16 = atoi(&com[small16]);
  410. total -= request->small16 * 16;
  411. }
  412. #endif
  413. #ifndef HAVE_BGL
  414. if (small64 > 0) {
  415. request->small64 = atoi(&com[small64]);
  416. total -= request->small64 * 64;
  417. }
  418. if (small256 > 0) {
  419. request->small256 = atoi(&com[small256]);
  420. total -= request->small256 * 256;
  421. }
  422. #endif
  423. if (small32 > 0) {
  424. request->small32 = atoi(&com[small32]);
  425. total -= request->small32 * 32;
  426. }
  427. if (small128 > 0) {
  428. request->small128 = atoi(&com[small128]);
  429. total -= request->small128 * 128;
  430. }
  431. if (total < 0) {
  432. sprintf(error_string,
  433. "You asked for %d more nodes than "
  434. "are in a Midplane\n", total * 2);
  435. geoi = -1;
  436. }
  437. #ifndef HAVE_BGL
  438. while (total > 0) {
  439. if (total >= 256) {
  440. request->small256++;
  441. total -= 256;
  442. } else if (total >= 128) {
  443. request->small128++;
  444. total -= 128;
  445. } else if (total >= 64) {
  446. request->small64++;
  447. total -= 64;
  448. } else if (total >= 32) {
  449. request->small32++;
  450. total -= 32;
  451. }
  452. #ifdef HAVE_BGP
  453. else if (total >= 16) {
  454. request->small16++;
  455. total -= 16;
  456. }
  457. #endif
  458. else
  459. break;
  460. }
  461. #else
  462. while (total > 0) {
  463. if (total >= 128) {
  464. request->small128++;
  465. total -= 128;
  466. } else if (total >= 32) {
  467. request->small32++;
  468. total -= 32;
  469. } else
  470. break;
  471. }
  472. #endif
  473. request->size = 1;
  474. /* sprintf(error_string, */
  475. /* "got %d %d %d %d %d %d", */
  476. /* total, request->small16, request->small32, */
  477. /* request->small64, request->small128, */
  478. /* request->small256); */
  479. }
  480. if ((geoi < 0) && !request->size) {
  481. memset(error_string, 0, 255);
  482. sprintf(error_string,
  483. "No size or dimension specified, please re-enter");
  484. } else {
  485. i2 = geoi;
  486. while (i2 < len) {
  487. if (request->size)
  488. break;
  489. if ((com[i2] == ' ') || (i2 == (len-1))) {
  490. char *p;
  491. /* for size */
  492. request->size = strtol(&com[geoi], &p, 10);
  493. if (*p == 'k' || *p == 'K') {
  494. request->size *= 2; /* (1024 / 512) */
  495. p++;
  496. }
  497. break;
  498. }
  499. if (com[i2]=='x') {
  500. request->size = -1;
  501. diff = i2 - geoi;
  502. /* for geometery */
  503. request->geometry[0] = _xlate_coord(&com[geoi],
  504. diff);
  505. for (j = 1; j < params.cluster_dims; j++) {
  506. geoi += diff;
  507. diff = geoi;
  508. while ((com[geoi-1]!='x') && com[geoi])
  509. geoi++;
  510. if (com[geoi] == '\0')
  511. goto geo_error_message;
  512. diff = geoi - diff;
  513. request->geometry[j] =
  514. _xlate_coord(&com[geoi], diff);
  515. }
  516. break;
  517. }
  518. i2++;
  519. }
  520. if (request->start_req) {
  521. i2 = starti;
  522. while (com[i2]!='x' && i2<len)
  523. i2++;
  524. diff = i2-starti;
  525. request->start[0] = _xlate_coord(&com[starti], diff);
  526. for (j = 1; j < params.cluster_dims; j++) {
  527. starti += diff;
  528. if (starti == len)
  529. goto start_request;
  530. starti++;
  531. i2 = starti;
  532. if (j == (params.cluster_dims - 1))
  533. fini_char = ' ';
  534. else
  535. fini_char = 'x';
  536. while ((com[i2] != fini_char) && com[i2])
  537. i2++;
  538. diff = i2 - starti;
  539. request->start[j] = _xlate_coord(&com[starti],
  540. diff);
  541. }
  542. }
  543. start_request:
  544. if(!_full_request(request, NULL, allocated_blocks))
  545. destroy_select_ba_request(request);
  546. }
  547. return 1;
  548. geo_error_message:
  549. destroy_select_ba_request(request);
  550. memset(error_string, 0, 255);
  551. sprintf(error_string,
  552. "Error in geo dimension specified, please re-enter");
  553. return 0;
  554. }
  555. static int _resolve(char *com)
  556. {
  557. int i=0;
  558. char *ret_str;
  559. while (com[i] != '\0') {
  560. if ((i>0) && (com[i-1] != ' '))
  561. break;
  562. i++;
  563. }
  564. if (com[i] == 'r')
  565. com[i] = 'R';
  566. ret_str = resolve_mp(com+i, NULL);
  567. if (ret_str) {
  568. snprintf(error_string, sizeof(error_string), "%s", ret_str);
  569. xfree(ret_str);
  570. }
  571. if (params.commandline)
  572. printf("%s", error_string);
  573. else {
  574. wnoutrefresh(text_win);
  575. doupdate();
  576. }
  577. return 1;
  578. }
  579. static int _change_state_all_bps(char *com, int state)
  580. {
  581. char start_loc[32], end_loc[32];
  582. char allnodes[50];
  583. int i;
  584. xassert(params.cluster_dims < 31);
  585. for (i = 0; i < params.cluster_dims; i++) {
  586. start_loc[i] = '0';
  587. end_loc[i] = alpha_num[dim_size[i] - 1];
  588. }
  589. start_loc[i] = '\0';
  590. end_loc[i] = '\0';
  591. memset(allnodes, 0, 50);
  592. sprintf(allnodes, "%sx%s", start_loc, end_loc);
  593. return _change_state_bps(allnodes, state);
  594. }
  595. static int _change_state_bps(char *com, int state)
  596. {
  597. char *host;
  598. int i = 0;
  599. uint16_t pos[params.cluster_dims];
  600. char letter = '.';
  601. bool used = false;
  602. char *c_state = "up";
  603. hostlist_t hl = NULL;
  604. int rc = 1;
  605. if (state == NODE_STATE_DOWN) {
  606. letter = '#';
  607. used = true;
  608. c_state = "down";
  609. }
  610. while (com[i] && (com[i] != '[') &&
  611. ((com[i] < '0') || (com[i] > '9')) &&
  612. ((com[i] < 'A') || (com[i] > 'Z')))
  613. i++;
  614. if (com[i] == '\0') {
  615. memset(error_string, 0, 255);
  616. sprintf(error_string,
  617. "You didn't specify any nodes to make %s. "
  618. "in statement '%s'",
  619. c_state, com);
  620. return 0;
  621. }
  622. if (!(hl = hostlist_create(com+i))) {
  623. memset(error_string, 0, 255);
  624. sprintf(error_string, "Bad hostlist given '%s'", com+i);
  625. return 0;
  626. }
  627. while ((host = hostlist_shift(hl))) {
  628. ba_mp_t *ba_mp;
  629. smap_node_t *smap_node;
  630. for (i = 0; i < params.cluster_dims; i++)
  631. pos[i] = select_char2coord(host[i]);
  632. if (!(ba_mp = bg_configure_coord2ba_mp(pos))) {
  633. memset(error_string, 0, 255);
  634. sprintf(error_string, "Bad host given '%s'", host);
  635. rc = 0;
  636. break;
  637. }
  638. bg_configure_ba_update_mp_state(ba_mp, state);
  639. smap_node = smap_system_ptr->grid[ba_mp->index];
  640. smap_node->color = 0;
  641. smap_node->letter = letter;
  642. smap_node->used = used;
  643. free(host);
  644. }
  645. hostlist_destroy(hl);
  646. return rc;
  647. }
  648. static int _remove_allocation(char *com, List allocated_blocks)
  649. {
  650. ListIterator results_i;
  651. allocated_block_t *allocated_block = NULL;
  652. int i=1, found=0;
  653. int len = strlen(com);
  654. char letter;
  655. while (com[i-1]!=' ' && i<len) {
  656. i++;
  657. }
  658. if (i>(len-1)) {
  659. memset(error_string, 0, 255);
  660. sprintf(error_string,
  661. "You need to specify which letter to delete.");
  662. return 0;
  663. } else {
  664. letter = com[i];
  665. results_i = list_iterator_create(allocated_blocks);
  666. while ((allocated_block = list_next(results_i)) != NULL) {
  667. if (found) {
  668. allocated_block->letter =
  669. letters[color_count%62];
  670. allocated_block->color =
  671. colors[color_count%6];
  672. allocated_block->color_count = color_count++;
  673. _set_nodes(allocated_block->nodes,
  674. allocated_block->color,
  675. allocated_block->letter);
  676. } else if (allocated_block->letter == letter) {
  677. found = 1;
  678. color_count = allocated_block->color_count;
  679. list_delete_item(results_i);
  680. }
  681. }
  682. list_iterator_destroy(results_i);
  683. }
  684. return 1;
  685. }
  686. static int _copy_allocation(char *com, List allocated_blocks)
  687. {
  688. ListIterator results_i;
  689. allocated_block_t *allocated_block = NULL;
  690. allocated_block_t *temp_block = NULL;
  691. select_ba_request_t *request = NULL;
  692. int i = 1, j;
  693. int len = strlen(com);
  694. char letter = '\0';
  695. int count = 1;
  696. int *geo = NULL, *geo_ptr = NULL;
  697. /* look for the space after copy */
  698. while ((com[i-1] != ' ') && (i < len))
  699. i++;
  700. if (i <= len) {
  701. /* Here we are looking for a real number for the count
  702. * instead of the params.cluster_base so atoi is ok */
  703. if ((com[i] >= '0') && (com[i] <= '9'))
  704. count = atoi(com+i);
  705. else {
  706. letter = com[i];
  707. i++;
  708. if (com[i] != '\n') {
  709. while ((com[i-1] != ' ') && (i < len))
  710. i++;
  711. if ((com[i] >= '0') && (com[i] <= '9'))
  712. count = atoi(com+i);
  713. }
  714. }
  715. }
  716. results_i = list_iterator_create(allocated_blocks);
  717. while ((allocated_block = list_next(results_i)) != NULL) {
  718. temp_block = allocated_block;
  719. if (allocated_block->letter != letter)
  720. continue;
  721. break;
  722. }
  723. list_iterator_destroy(results_i);
  724. if (!letter)
  725. allocated_block = temp_block;
  726. if (!allocated_block) {
  727. memset(error_string, 0, 255);
  728. sprintf(error_string,
  729. "Could not find requested record to copy");
  730. return 0;
  731. }
  732. for (i = 0; i < count; i++) {
  733. request = (select_ba_request_t*)
  734. xmalloc(sizeof(select_ba_request_t));
  735. for (j = 0; j < params.cluster_dims; j++) {
  736. request->geometry[j] = allocated_block->request->
  737. geometry[j];
  738. request->conn_type[j] = allocated_block->request->
  739. conn_type[j];
  740. }
  741. request->size = allocated_block->request->size;
  742. request->rotate =allocated_block->request->rotate;
  743. request->elongate = allocated_block->request->elongate;
  744. request->deny_pass = allocated_block->request->deny_pass;
  745. #ifndef HAVE_BGL
  746. request->small16 = allocated_block->request->small16;
  747. request->small64 = allocated_block->request->small64;
  748. request->small256 = allocated_block->request->small256;
  749. #endif
  750. request->small32 = allocated_block->request->small32;
  751. request->small128 = allocated_block->request->small128;
  752. request->rotate_count= 0;
  753. request->elongate_count = 0;
  754. request->elongate_geos = list_create(NULL);
  755. request->avail_mp_bitmap = NULL;
  756. results_i = list_iterator_create(request->elongate_geos);
  757. while ((geo_ptr = list_next(results_i)) != NULL) {
  758. geo = xmalloc(sizeof(int) * params.cluster_dims);
  759. for (j = 0; j < params.cluster_dims; j++)
  760. geo[j] = geo_ptr[j];
  761. list_append(request->elongate_geos, geo);
  762. }
  763. list_iterator_destroy(results_i);
  764. if ((allocated_block = _make_request(request)) == NULL) {
  765. memset(error_string, 0, 255);
  766. sprintf(error_string,
  767. "Problem with the copy\n"
  768. "Are you sure there is enough room for it?");
  769. xfree(request);
  770. return 0;
  771. }
  772. list_append(allocated_blocks, allocated_block);
  773. }
  774. return 1;
  775. }
  776. static int _save_allocation(char *com, List allocated_blocks)
  777. {
  778. int len = strlen(com);
  779. int i=5, j=0;
  780. allocated_block_t *allocated_block = NULL;
  781. char filename[50];
  782. char *save_string = NULL;
  783. FILE *file_ptr = NULL;
  784. char *extra = NULL;
  785. ListIterator results_i;
  786. memset(filename, 0, 50);
  787. if (len > 5)
  788. while (i<len) {
  789. while (com[i-1]!=' ' && i<len) {
  790. i++;
  791. }
  792. while (i<len && com[i]!=' ') {
  793. filename[j] = com[i];
  794. i++;
  795. j++;
  796. }
  797. }
  798. if (filename[0]=='\0') {
  799. time_t now_time = time(NULL);
  800. sprintf(filename,"bluegene.conf.%ld",
  801. (long int) now_time);
  802. }
  803. file_ptr = fopen(filename,"w");
  804. if (file_ptr!=NULL) {
  805. char *image_dir = NULL;
  806. xstrcat(save_string,
  807. "#\n# bluegene.conf file generated by smap\n");
  808. xstrcat(save_string,
  809. "# See the bluegene.conf man page for "
  810. "more information\n");
  811. xstrcat(save_string, "#\n");
  812. #ifdef HAVE_BGL
  813. image_dir = "/bgl/BlueLight/ppcfloor/bglsys/bin";
  814. xstrfmtcat(save_string, "BlrtsImage=%s/rts_hw.rts\n",
  815. image_dir);
  816. xstrfmtcat(save_string, "LinuxImage=%s/zImage.elf\n",
  817. image_dir);
  818. xstrfmtcat(save_string,
  819. "MloaderImage=%s/mmcs-mloader.rts\n",
  820. image_dir);
  821. xstrfmtcat(save_string,
  822. "RamDiskImage=%s/ramdisk.elf\n",
  823. image_dir);
  824. xstrcat(save_string, "IONodesPerMP=8 # io poor\n");
  825. xstrcat(save_string, "# IONodesPerMP=64 # io rich\n");
  826. #elif defined HAVE_BGP
  827. image_dir = "/bgsys/drivers/ppcfloor/boot";
  828. xstrfmtcat(save_string, "CnloadImage=%s/cns,%s/cnk\n",
  829. image_dir, image_dir);
  830. xstrfmtcat(save_string, "MloaderImage=%s/uloader\n",
  831. image_dir);
  832. xstrfmtcat(save_string,
  833. "IoloadImage=%s/cns,%s/linux,%s/ramdisk\n",
  834. image_dir, image_dir, image_dir);
  835. xstrcat(save_string, "IONodesPerMP=4 # io poor\n");
  836. xstrcat(save_string, "# IONodesPerMP=32 # io rich\n");
  837. #else
  838. image_dir = "/bgsys/drivers/ppcfloor/boot";
  839. xstrfmtcat(save_string, "MloaderImage=%s/firmware\n",
  840. image_dir);
  841. xstrcat(save_string, "IONodesPerMP=4 # io semi-poor\n");
  842. xstrcat(save_string, "# IONodesPerMP=16 # io rich\n");
  843. #endif
  844. xstrcat(save_string, "BridgeAPILogFile="
  845. "/var/log/slurm/bridgeapi.log\n");
  846. xstrcat(save_string, "BridgeAPIVerbose=2\n");
  847. xstrfmtcat(save_string, "BasePartitionNodeCnt=%d\n",
  848. base_part_node_cnt);
  849. xstrfmtcat(save_string, "NodeCardNodeCnt=%d\n",
  850. nodecard_node_cnt);
  851. if (!list_count(allocated_blocks))
  852. xstrcat(save_string, "LayoutMode=DYNAMIC\n");
  853. else {
  854. xstrfmtcat(save_string, "LayoutMode=%s\n", layout_mode);
  855. xstrfmtcat(save_string, "#\n# Block Layout\n#\n");
  856. }
  857. results_i = list_iterator_create(allocated_blocks);
  858. while ((allocated_block = list_next(results_i)) != NULL) {
  859. select_ba_request_t *request = allocated_block->request;
  860. if (request->small16 || request->small32
  861. || request->small64 || request->small128
  862. || request->small256) {
  863. #ifdef HAVE_BGL
  864. xstrfmtcat(extra,
  865. " 32CNBlocks=%d "
  866. "128CNBlocks=%d",
  867. request->small32,
  868. request->small128);
  869. #elif defined HAVE_BGP
  870. xstrfmtcat(extra,
  871. " 16CNBlocks=%d "
  872. "32CNBlocks=%d "
  873. "64CNBlocks=%d "
  874. "128CNBlocks=%d "
  875. "256CNBlocks=%d",
  876. request->small16,
  877. request->small32,
  878. request->small64,
  879. request->small128,
  880. request->small256);
  881. #else
  882. xstrfmtcat(extra,
  883. " 32CNBlocks=%d "
  884. "64CNBlocks=%d "
  885. "128CNBlocks=%d "
  886. "256CNBlocks=%d",
  887. request->small32,
  888. request->small64,
  889. request->small128,
  890. request->small256);
  891. #endif
  892. }
  893. xstrfmtcat(save_string, "MPs=%s", request->save_name);
  894. for (i=0; i<SYSTEM_DIMENSIONS; i++) {
  895. if (request->conn_type[i] == (uint16_t)NO_VAL)
  896. break;
  897. if (i)
  898. xstrcat(save_string, ",");
  899. else
  900. xstrcat(save_string, " Type=");
  901. xstrfmtcat(save_string, "%s", conn_type_string(
  902. request->conn_type[i]));
  903. #ifdef HAVE_BG_L_P
  904. break;
  905. #endif
  906. }
  907. if (extra) {
  908. xstrfmtcat(save_string, "%s\n", extra);
  909. xfree(extra);
  910. } else
  911. xstrcat(save_string, "\n");
  912. }
  913. list_iterator_destroy(results_i);
  914. fputs(save_string, file_ptr);
  915. xfree(save_string);
  916. fclose (file_ptr);
  917. }
  918. return 1;
  919. }
  920. static int _add_bg_record(select_ba_request_t *blockreq, List allocated_blocks)
  921. {
  922. int rc = 1;
  923. #ifdef HAVE_BG
  924. char *nodes = NULL, *host;
  925. int diff = 0;
  926. int largest_diff = -1;
  927. uint16_t start[params.cluster_dims];
  928. uint16_t end[params.cluster_dims];
  929. uint16_t best_start[params.cluster_dims];
  930. int i, j = 0;
  931. hostlist_t hl = NULL;
  932. bitstr_t *mark_bitmap = NULL;
  933. char tmp_char[params.cluster_dims+1],
  934. tmp_char2[params.cluster_dims+1];
  935. memset(tmp_char, 0, sizeof(tmp_char));
  936. memset(tmp_char2, 0, sizeof(tmp_char2));
  937. for (i = 0; i < params.cluster_dims; i++) {
  938. best_start[0] = 0;
  939. blockreq->geometry[i] = 0;
  940. end[i] = (int16_t)-1;
  941. }
  942. nodes = blockreq->save_name;
  943. if (!nodes)
  944. return SLURM_SUCCESS;
  945. while (nodes[j] && (nodes[j] != '[') &&
  946. ((nodes[j] < '0') || (nodes[j] > '9')) &&
  947. ((nodes[j] < 'A') || (nodes[j] > 'Z')))
  948. j++;
  949. if (nodes[j] == '\0') {
  950. snprintf(error_string, sizeof(error_string),
  951. "This block '%s' for some reason didn't contain "
  952. "any midplanes.",
  953. nodes);
  954. rc = 0;
  955. goto fini;
  956. }
  957. if (!(hl = hostlist_create(nodes+j))) {
  958. snprintf(error_string, sizeof(error_string),
  959. "Bad hostlist given '%s'", nodes+j);
  960. rc = 0;
  961. goto fini;
  962. }
  963. /* figure out the geo and the size */
  964. mark_bitmap = bit_alloc(smap_system_ptr->node_cnt);
  965. while ((host = hostlist_shift(hl))) {
  966. ba_mp_t *ba_mp;
  967. uint16_t pos[params.cluster_dims];
  968. for (i = 0; i < params.cluster_dims; i++)
  969. pos[i] = select_char2coord(host[i]);
  970. free(host);
  971. if (!(ba_mp = bg_configure_coord2ba_mp(pos))) {
  972. memset(error_string, 0, 255);
  973. sprintf(error_string, "Bad host given '%s'", host);
  974. rc = 0;
  975. break;
  976. }
  977. bit_set(mark_bitmap, ba_mp->index);
  978. for (i = 0; i < params.cluster_dims; i++) {
  979. if (ba_mp->coord[i] > (int16_t)end[i]) {
  980. blockreq->geometry[i]++;
  981. end[i] = ba_mp->coord[i];
  982. }
  983. }
  984. }
  985. hostlist_destroy(hl);
  986. if (!rc)
  987. goto fini;
  988. /* figure out the start pos */
  989. while (nodes[j] != '\0') {
  990. int mid = j + params.cluster_dims + 1;
  991. int fin = mid + params.cluster_dims + 1;
  992. if (((nodes[j] == '[') || (nodes[j] == ',')) &&
  993. ((nodes[mid] == 'x') || (nodes[mid] == '-')) &&
  994. ((nodes[fin] == ']') || (nodes[fin] == ','))) {
  995. j++; /* Skip leading '[' or ',' */
  996. for (i = 0; i < params.cluster_dims; i++, j++)
  997. start[i] = select_char2coord(nodes[j]);
  998. j++; /* Skip middle 'x' or '-' */
  999. for (i = 0; i < params.cluster_dims; i++, j++)
  1000. end[i] = select_char2coord(nodes[j]);
  1001. diff = end[0] - start[0];
  1002. } else if (((nodes[j] >= '0') && (nodes[j] <= '9')) ||
  1003. ((nodes[j] >= 'A') && (nodes[j] <= 'Z'))) {
  1004. for (i = 0; i < params.cluster_dims; i++, j++)
  1005. start[i] = select_char2coord(nodes[j]);
  1006. diff = 0;
  1007. } else {
  1008. j++;
  1009. continue;
  1010. }
  1011. if (diff > largest_diff) {
  1012. largest_diff = diff;
  1013. memcpy(best_start, start, sizeof(best_start));
  1014. }
  1015. if (nodes[j] != ',')
  1016. break;
  1017. }
  1018. if (largest_diff == -1) {
  1019. snprintf(error_string, sizeof(error_string),
  1020. "No hostnames given here");
  1021. goto fini;
  1022. }
  1023. memcpy(blockreq->start, best_start, sizeof(blockreq->start));
  1024. if(!_full_request(blockreq, mark_bitmap, allocated_blocks))
  1025. destroy_select_ba_request(blockreq);
  1026. fini:
  1027. FREE_NULL_BITMAP(mark_bitmap);
  1028. #endif
  1029. return rc;
  1030. }
  1031. static int _load_configuration(char *com, List allocated_blocks)
  1032. {
  1033. int len = strlen(com);
  1034. int i=5, j=0;
  1035. char filename[100];
  1036. s_p_hashtbl_t *tbl = NULL;
  1037. char *layout = NULL;
  1038. select_ba_request_t **blockreq_array = NULL;
  1039. int count = 0;
  1040. if (allocated_blocks)
  1041. list_flush(allocated_blocks);
  1042. else
  1043. allocated_blocks = list_create(_destroy_allocated_block);
  1044. memset(filename, 0, 100);
  1045. if (len>5)
  1046. while (i<len) {
  1047. while (com[i-1]!=' ' && i<len) {
  1048. i++;
  1049. }
  1050. while (i<len && com[i]!=' ') {
  1051. filename[j] = com[i];
  1052. i++;
  1053. j++;
  1054. if (j>100) {
  1055. memset(error_string, 0, 255);
  1056. sprintf(error_string,
  1057. "filename is too long needs "
  1058. "to be under 100 chars");
  1059. return 0;
  1060. }
  1061. }
  1062. }
  1063. if (filename[0]=='\0') {
  1064. sprintf(filename,"bluegene.conf");
  1065. }
  1066. if (!(tbl = bg_configure_config_make_tbl(filename))) {
  1067. memset(error_string,0,255);
  1068. sprintf(error_string, "ERROR: couldn't open/read %s",
  1069. filename);
  1070. return 0;
  1071. }
  1072. if (!s_p_get_string(&layout, "LayoutMode", tbl)) {
  1073. memset(error_string,0,255);
  1074. sprintf(error_string,
  1075. "Warning: LayoutMode was not specified in "
  1076. "bluegene.conf defaulting to STATIC partitioning");
  1077. } else {
  1078. _set_layout(layout);
  1079. xfree(layout);
  1080. }
  1081. if (strcasecmp(layout_mode, "DYNAMIC")) {
  1082. if (!s_p_get_array((void ***)&blockreq_array,
  1083. &count, "MPs", tbl)) {
  1084. if (!s_p_get_array((void ***)&blockreq_array,
  1085. &count, "BPs", tbl)) {
  1086. memset(error_string, 0, 255);
  1087. sprintf(error_string,
  1088. "WARNING: no blocks defined in "
  1089. "bluegene.conf");
  1090. }
  1091. }
  1092. for (i = 0; i < count; i++) {
  1093. _add_bg_record(blockreq_array[i], allocated_blocks);
  1094. /* The freeing of this will happen when
  1095. allocated_blocks gets freed.
  1096. */
  1097. blockreq_array[i] = NULL;
  1098. }
  1099. }
  1100. s_p_hashtbl_destroy(tbl);
  1101. return 1;
  1102. }
  1103. static void _print_header_command(void)
  1104. {
  1105. main_ycord=2;
  1106. mvwprintw(text_win, main_ycord,
  1107. main_xcord, "ID");
  1108. main_xcord += 4;
  1109. mvwprintw(text_win, main_ycord,
  1110. main_xcord, "TYPE");
  1111. main_xcord += 8;
  1112. mvwprintw(text_win, main_ycord,
  1113. main_xcord, "ROTATE");
  1114. main_xcord += 7;
  1115. mvwprintw(text_win, main_ycord,
  1116. main_xcord, "ELONG");
  1117. main_xcord += 7;
  1118. #ifdef HAVE_BG
  1119. mvwprintw(text_win, main_ycord,
  1120. main_xcord, "MIDPLANES");
  1121. #else
  1122. mvwprintw(text_win, main_ycord,
  1123. main_xcord, "NODES");
  1124. #endif
  1125. main_xcord += 10;
  1126. #ifdef HAVE_BGP
  1127. mvwprintw(text_win, main_ycord,
  1128. main_xcord, "16CN");
  1129. main_xcord += 5;
  1130. #endif
  1131. mvwprintw(text_win, main_ycord,
  1132. main_xcord, "32CN");
  1133. main_xcord += 5;
  1134. #ifndef HAVE_BGL
  1135. mvwprintw(text_win, main_ycord,
  1136. main_xcord, "64CN");
  1137. main_xcord += 5;
  1138. #endif
  1139. mvwprintw(text_win, main_ycord,
  1140. main_xcord, "128CN");
  1141. main_xcord += 6;
  1142. #ifndef HAVE_BGL
  1143. mvwprintw(text_win, main_ycord,
  1144. main_xcord, "256CN");
  1145. main_xcord += 6;
  1146. #endif
  1147. #ifdef HAVE_BG
  1148. mvwprintw(text_win, main_ycord,
  1149. main_xcord, "MIDPLANELIST");
  1150. #else
  1151. mvwprintw(text_win, main_ycord,
  1152. main_xcord, "NODELIST");
  1153. #endif
  1154. main_xcord = 1;
  1155. main_ycord++;
  1156. }
  1157. static void _print_text_command(allocated_block_t *allocated_block)
  1158. {
  1159. char *tmp_char = NULL;
  1160. wattron(text_win,
  1161. COLOR_PAIR(allocated_block->color));
  1162. mvwprintw(text_win, main_ycord,
  1163. main_xcord, "%c", allocated_block->letter);
  1164. main_xcord += 4;
  1165. tmp_char = conn_type_string_full(allocated_block->request->conn_type);
  1166. mvwprintw(text_win, main_ycord, main_xcord, tmp_char);
  1167. xfree(tmp_char);
  1168. main_xcord += 8;
  1169. if (allocated_block->request->rotate)
  1170. mvwprintw(text_win, main_ycord,
  1171. main_xcord, "Y");
  1172. else
  1173. mvwprintw(text_win, main_ycord,
  1174. main_xcord, "N");
  1175. main_xcord += 7;
  1176. if (allocated_block->request->elongate)
  1177. mvwprintw(text_win, main_ycord,
  1178. main_xcord, "Y");
  1179. else
  1180. mvwprintw(text_win, main_ycord,
  1181. main_xcord, "N");
  1182. main_xcord += 7;
  1183. mvwprintw(text_win, main_ycord,
  1184. main_xcord, "%d", allocated_block->request->size);
  1185. main_xcord += 10;
  1186. if (allocated_block->request->conn_type[0] >= SELECT_SMALL) {
  1187. #ifdef HAVE_BGP
  1188. mvwprintw(text_win, main_ycord,
  1189. main_xcord, "%d",
  1190. allocated_block->request->small16);
  1191. main_xcord += 5;
  1192. #endif
  1193. mvwprintw(text_win, main_ycord,
  1194. main_xcord, "%d",
  1195. allocated_block->request->small32);
  1196. main_xcord += 5;
  1197. #ifndef HAVE_BGL
  1198. mvwprintw(text_win, main_ycord,
  1199. main_xcord, "%d",
  1200. allocated_block->request->small64);
  1201. main_xcord += 5;
  1202. #endif
  1203. mvwprintw(text_win, main_ycord,
  1204. main_xcord, "%d",
  1205. allocated_block->request->small128);
  1206. main_xcord += 6;
  1207. #ifndef HAVE_BGL
  1208. mvwprintw(text_win, main_ycord,
  1209. main_xcord, "%d",
  1210. allocated_block->request->small256);
  1211. main_xcord += 6;
  1212. #endif
  1213. } else {
  1214. #ifdef HAVE_BGL
  1215. main_xcord += 11;
  1216. #elif defined HAVE_BGP
  1217. main_xcord += 27;
  1218. #else
  1219. main_xcord += 22;
  1220. #endif
  1221. }
  1222. mvwprintw(text_win, main_ycord,
  1223. main_xcord, "%s",
  1224. allocated_block->request->save_name);
  1225. main_xcord = 1;
  1226. main_ycord++;
  1227. wattroff(text_win,
  1228. COLOR_PAIR(allocated_block->color));
  1229. return;
  1230. }
  1231. void get_command(void)
  1232. {
  1233. char com[255];
  1234. int text_width, text_startx;
  1235. allocated_block_t *allocated_block = NULL;
  1236. int i = 0;
  1237. int count = 0;
  1238. WINDOW *command_win = NULL;
  1239. List allocated_blocks = NULL;
  1240. ListIterator results_i;
  1241. if (params.commandline && !params.command) {
  1242. printf("Configure won't work with commandline mode.\n");
  1243. printf("Please remove the -c from the commandline.\n");
  1244. bg_configure_ba_fini();
  1245. exit(0);
  1246. }
  1247. if (working_cluster_rec) {
  1248. char *cluster_name = slurm_get_cluster_name();
  1249. if (strcmp(working_cluster_rec->name, cluster_name)) {
  1250. xfree(cluster_name);
  1251. endwin();
  1252. printf("To use the configure option you must be on the "
  1253. "cluster the configure is for.\nCross cluster "
  1254. "support doesn't exist today.\nSorry for the "
  1255. "inconvenince.\n");
  1256. bg_configure_ba_fini();
  1257. exit(0);
  1258. }
  1259. xfree(cluster_name);
  1260. }
  1261. /* make sure we don't get any noisy debug */
  1262. ba_configure_set_ba_debug_flags(0);
  1263. bg_configure_ba_setup_wires();
  1264. color_count = 0;
  1265. allocated_blocks = list_create(_destroy_allocated_block);
  1266. if (params.commandline) {
  1267. snprintf(com, sizeof(com), "%s", params.command);
  1268. goto run_command;
  1269. } else {
  1270. text_width = text_win->_maxx;
  1271. text_startx = text_win->_begx;
  1272. command_win = newwin(3, text_width - 1, LINES - 4,
  1273. text_startx + 1);
  1274. curs_set(1);
  1275. echo();
  1276. }
  1277. while (strcmp(com, "quit")) {
  1278. clear_window(grid_win);
  1279. print_grid();
  1280. clear_window(text_win);
  1281. box(text_win, 0, 0);
  1282. box(grid_win, 0, 0);
  1283. if (!params.no_header)
  1284. _print_header_command();
  1285. if (error_string != NULL) {
  1286. i = 0;
  1287. while (error_string[i] != '\0') {
  1288. if (error_string[i] == '\n') {
  1289. main_ycord++;
  1290. main_xcord=1;
  1291. i++;
  1292. }
  1293. mvwprintw(text_win,
  1294. main_ycord,
  1295. main_xcord,
  1296. "%c",
  1297. error_string[i++]);
  1298. main_xcord++;
  1299. }
  1300. main_ycord++;
  1301. main_xcord = 1;
  1302. memset(error_string, 0, 255);
  1303. }
  1304. results_i = list_iterator_create(allocated_blocks);
  1305. count = list_count(allocated_blocks)
  1306. - (LINES-(main_ycord+5));
  1307. if (count<0)
  1308. count=0;
  1309. i=0;
  1310. while ((allocated_block = list_next(results_i)) != NULL) {
  1311. if (i >= count)
  1312. _print_text_command(allocated_block);
  1313. i++;
  1314. }
  1315. list_iterator_destroy(results_i);
  1316. wnoutrefresh(text_win);
  1317. wnoutrefresh(grid_win);
  1318. doupdate();
  1319. clear_window(command_win);
  1320. box(command_win, 0, 0);
  1321. mvwprintw(command_win, 0, 3,
  1322. "Input Command: (type quit to change view, "
  1323. "exit to exit)");
  1324. wmove(command_win, 1, 1);
  1325. wgetstr(command_win, com);
  1326. if (!strcmp(com, "exit")) {
  1327. endwin();
  1328. if (allocated_blocks)
  1329. list_destroy(allocated_blocks);
  1330. bg_configure_ba_fini();
  1331. exit(0);
  1332. }
  1333. run_command:
  1334. if (!strcmp(com, "quit") || !strcmp(com, "\\q")) {
  1335. break;
  1336. } else if (!strncasecmp(com, "layout", 6)) {
  1337. _set_layout(com);
  1338. } else if (!strncasecmp(com, "basepartition", 13)) {
  1339. _set_base_part_cnt(com);
  1340. } else if (!strncasecmp(com, "nodecard", 8)) {
  1341. _set_nodecard_cnt(com);
  1342. } else if (!strncasecmp(com, "resolve", 7) ||
  1343. !strncasecmp(com, "r ", 2)) {
  1344. _resolve(com);
  1345. } else if (!strncasecmp(com, "resume", 6)) {
  1346. mvwprintw(text_win,
  1347. main_ycord,
  1348. main_xcord, "%s", com);
  1349. } else if (!strncasecmp(com, "drain", 5)) {
  1350. mvwprintw(text_win,
  1351. main_ycord,
  1352. main_xcord, "%s", com);
  1353. } else if (!strncasecmp(com, "alldown", 7)) {
  1354. _change_state_all_bps(com, NODE_STATE_DOWN);
  1355. } else if (!strncasecmp(com, "down", 4)) {
  1356. _change_state_bps(com, NODE_STATE_DOWN);
  1357. } else if (!strncasecmp(com, "allup", 5)) {
  1358. _change_state_all_bps(com, NODE_STATE_IDLE);
  1359. } else if (!strncasecmp(com, "up", 2)) {
  1360. _change_state_bps(com, NODE_STATE_IDLE);
  1361. } else if (!strncasecmp(com, "remove", 6)
  1362. || !strncasecmp(com, "delete", 6)
  1363. || !strncasecmp(com, "drop", 4)) {
  1364. _remove_allocation(com, allocated_blocks);
  1365. } else if (!strncasecmp(com, "create", 6)) {
  1366. _create_allocation(com, allocated_blocks);
  1367. } else if (!strncasecmp(com, "copy", 4)
  1368. || !strncasecmp(com, "c ", 2)
  1369. || !strncasecmp(com, "c\0", 2)) {
  1370. _copy_allocation(com, allocated_blocks);
  1371. } else if (!strncasecmp(com, "save", 4)) {
  1372. _save_allocation(com, allocated_blocks);
  1373. } else if (!strncasecmp(com, "load", 4)) {
  1374. _load_configuration(com, allocated_blocks);
  1375. } else if (!strncasecmp(com, "clear all", 9)
  1376. || !strncasecmp(com, "clear", 5)) {
  1377. list_flush(allocated_blocks);
  1378. } else {
  1379. memset(error_string, 0, 255);
  1380. sprintf(error_string, "Unknown command '%s'",com);
  1381. }
  1382. if (params.commandline) {
  1383. bg_configure_ba_fini();
  1384. exit(1);
  1385. }
  1386. }
  1387. if (allocated_blocks)
  1388. list_destroy(allocated_blocks);
  1389. params.display = 0;
  1390. noecho();
  1391. clear_window(text_win);
  1392. main_xcord = 1;
  1393. main_ycord = 1;
  1394. curs_set(0);
  1395. print_date();
  1396. get_job();
  1397. return;
  1398. }