PageRenderTime 43ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/src/sacctmgr/qos_functions.c

https://github.com/cfenoy/slurm
C | 1126 lines | 981 code | 93 blank | 52 comment | 306 complexity | 59cf7277ad9fb2cfe1d8b6952163d41d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * qos_functions.c - functions dealing with qoss in the
  3. * accounting system.
  4. *****************************************************************************
  5. * Copyright (C) 2002-2008 The Regents of the University of California.
  6. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  7. * Written by Danny Auble <da@llnl.gov>
  8. * CODE-OCEC-09-009. All rights reserved.
  9. *
  10. * This file is part of SLURM, a resource management program.
  11. * For details, see <http://www.schedmd.com/slurmdocs/>.
  12. * Please also read the included file: DISCLAIMER.
  13. *
  14. * SLURM is free software; you can redistribute it and/or modify it under
  15. * the terms of the GNU General Public License as published by the Free
  16. * Software Foundation; either version 2 of the License, or (at your option)
  17. * any later version.
  18. *
  19. * In addition, as a special exception, the copyright holders give permission
  20. * to link the code of portions of this program with the OpenSSL library under
  21. * certain conditions as described in each individual source file, and
  22. * distribute linked combinations including the two. You must obey the GNU
  23. * General Public License in all respects for all of the code used other than
  24. * OpenSSL. If you modify file(s) with this exception, you may extend this
  25. * exception to your version of the file(s), but you are not obligated to do
  26. * so. If you do not wish to do so, delete this exception statement from your
  27. * version. If you delete this exception statement from all source files in
  28. * the program, then also delete it here.
  29. *
  30. * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
  31. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  32. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  33. * details.
  34. *
  35. * You should have received a copy of the GNU General Public License along
  36. * with SLURM; if not, write to the Free Software Foundation, Inc.,
  37. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  38. \*****************************************************************************/
  39. #include "src/sacctmgr/sacctmgr.h"
  40. static uint16_t _parse_preempt_modes(char *names)
  41. {
  42. int i=0, start=0;
  43. char *name = NULL;
  44. char quote_c = '\0';
  45. int quote = 0;
  46. int count = 0;
  47. uint16_t preempt_mode = 0;
  48. uint16_t ret_mode = 0;
  49. if(names) {
  50. if (names[i] == '\"' || names[i] == '\'') {
  51. quote_c = names[i];
  52. quote = 1;
  53. i++;
  54. }
  55. start = i;
  56. while(names[i]) {
  57. //info("got %d - %d = %d", i, start, i-start);
  58. if(quote && names[i] == quote_c)
  59. break;
  60. else if (names[i] == '\"' || names[i] == '\'')
  61. names[i] = '`';
  62. else if(names[i] == ',') {
  63. name = xmalloc((i-start+1));
  64. memcpy(name, names+start, (i-start));
  65. //info("got %s %d", name, i-start);
  66. ret_mode = preempt_mode_num(name);
  67. if(ret_mode == (uint16_t)NO_VAL) {
  68. error("Unknown preempt_mode given '%s'",
  69. name);
  70. xfree(name);
  71. preempt_mode = (uint16_t)NO_VAL;
  72. break;
  73. }
  74. preempt_mode |= ret_mode;
  75. count++;
  76. xfree(name);
  77. i++;
  78. start = i;
  79. if(!names[i]) {
  80. info("There is a problem with "
  81. "your request. It appears you "
  82. "have spaces inside your list.");
  83. break;
  84. }
  85. }
  86. i++;
  87. }
  88. name = xmalloc((i-start+1));
  89. memcpy(name, names+start, (i-start));
  90. //info("got %s %d", name, i-start);
  91. ret_mode = preempt_mode_num(name);
  92. if(ret_mode == (uint16_t)NO_VAL) {
  93. error("Unknown preempt_mode given '%s'",
  94. name);
  95. xfree(name);
  96. preempt_mode = (uint16_t)NO_VAL;
  97. return preempt_mode;
  98. }
  99. preempt_mode |= ret_mode;
  100. count++;
  101. xfree(name);
  102. }
  103. return preempt_mode;
  104. }
  105. static int _set_cond(int *start, int argc, char *argv[],
  106. slurmdb_qos_cond_t *qos_cond,
  107. List format_list)
  108. {
  109. int i;
  110. int set = 0;
  111. int end = 0;
  112. int command_len = 0;
  113. if(!qos_cond) {
  114. error("No qos_cond given");
  115. return -1;
  116. }
  117. for (i=(*start); i<argc; i++) {
  118. end = parse_option_end(argv[i]);
  119. if(!end)
  120. command_len=strlen(argv[i]);
  121. else {
  122. command_len=end-1;
  123. if (argv[i][end] == '=') {
  124. end++;
  125. }
  126. }
  127. if (!strncasecmp (argv[i], "Set", MAX(command_len, 3))) {
  128. i--;
  129. break;
  130. } else if (!end && !strncasecmp (argv[i], "WithDeleted",
  131. MAX(command_len, 5))) {
  132. qos_cond->with_deleted = 1;
  133. } else if(!end && !strncasecmp(argv[i], "where",
  134. MAX(command_len, 5))) {
  135. continue;
  136. } else if(!end
  137. || !strncasecmp (argv[i], "Names",
  138. MAX(command_len, 1))
  139. || !strncasecmp (argv[i], "QOSLevel",
  140. MAX(command_len, 1))) {
  141. if(!qos_cond->name_list) {
  142. qos_cond->name_list =
  143. list_create(slurm_destroy_char);
  144. }
  145. if(slurm_addto_char_list(qos_cond->name_list,
  146. argv[i]+end))
  147. set = 1;
  148. } else if(!strncasecmp (argv[i], "Descriptions",
  149. MAX(command_len, 1))) {
  150. if(!qos_cond->description_list) {
  151. qos_cond->description_list =
  152. list_create(slurm_destroy_char);
  153. }
  154. if(slurm_addto_char_list(qos_cond->description_list,
  155. argv[i]+end))
  156. set = 1;
  157. } else if (!strncasecmp (argv[i], "Format",
  158. MAX(command_len, 1))) {
  159. if(format_list)
  160. slurm_addto_char_list(format_list, argv[i]+end);
  161. } else if(!strncasecmp (argv[i], "Ids", MAX(command_len, 1))) {
  162. ListIterator itr = NULL;
  163. char *temp = NULL;
  164. uint32_t id = 0;
  165. if(!qos_cond->id_list) {
  166. qos_cond->id_list =
  167. list_create(slurm_destroy_char);
  168. }
  169. if(slurm_addto_char_list(qos_cond->id_list,
  170. argv[i]+end))
  171. set = 1;
  172. /* check to make sure user gave ints here */
  173. itr = list_iterator_create(qos_cond->id_list);
  174. while ((temp = list_next(itr))) {
  175. if (get_uint(temp, &id, "QOS ID")
  176. != SLURM_SUCCESS) {
  177. exit_code = 1;
  178. list_delete_item(itr);
  179. }
  180. }
  181. list_iterator_destroy(itr);
  182. } else if (!strncasecmp (argv[i], "PreemptMode",
  183. MAX(command_len, 8))) {
  184. if(!qos_cond)
  185. continue;
  186. qos_cond->preempt_mode |=
  187. _parse_preempt_modes(argv[i]+end);
  188. if(qos_cond->preempt_mode == (uint16_t)NO_VAL) {
  189. fprintf(stderr,
  190. " Bad Preempt Mode given: %s\n",
  191. argv[i]);
  192. exit_code = 1;
  193. } else if (qos_cond->preempt_mode ==
  194. PREEMPT_MODE_SUSPEND) {
  195. printf("PreemptType and PreemptMode "
  196. "values incompatible\n");
  197. exit_code = 1;
  198. } else
  199. set = 1;
  200. } else {
  201. exit_code=1;
  202. fprintf(stderr, " Unknown condition: %s\n"
  203. " Use keyword 'set' to modify "
  204. "SLURM_PRINT_VALUE\n", argv[i]);
  205. }
  206. }
  207. (*start) = i;
  208. return set;
  209. }
  210. static int _set_rec(int *start, int argc, char *argv[],
  211. List name_list,
  212. slurmdb_qos_rec_t *qos)
  213. {
  214. int i, mins;
  215. int set = 0;
  216. int end = 0;
  217. int command_len = 0;
  218. int option = 0;
  219. for (i=(*start); i<argc; i++) {
  220. end = parse_option_end(argv[i]);
  221. if(!end)
  222. command_len=strlen(argv[i]);
  223. else {
  224. command_len=end-1;
  225. if(argv[i][end] == '=') {
  226. option = (int)argv[i][end-1];
  227. end++;
  228. }
  229. }
  230. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))) {
  231. i--;
  232. break;
  233. } else if(!end && !strncasecmp(argv[i], "set",
  234. MAX(command_len, 3))) {
  235. continue;
  236. } else if(!end
  237. || !strncasecmp (argv[i], "Name",
  238. MAX(command_len, 1))) {
  239. if(name_list)
  240. slurm_addto_char_list(name_list, argv[i]+end);
  241. } else if (!strncasecmp (argv[i], "Description",
  242. MAX(command_len, 1))) {
  243. if(!qos->description)
  244. qos->description =
  245. strip_quotes(argv[i]+end, NULL, 1);
  246. set = 1;
  247. } else if (!strncasecmp (argv[i], "Flags",
  248. MAX(command_len, 2))) {
  249. if(!qos)
  250. continue;
  251. qos->flags = str_2_qos_flags(argv[i]+end, option);
  252. if (qos->flags == QOS_FLAG_NOTSET) {
  253. char *tmp_char = NULL;
  254. qos->flags = INFINITE;
  255. qos->flags &= (~QOS_FLAG_NOTSET &
  256. ~QOS_FLAG_ADD &
  257. ~QOS_FLAG_REMOVE);
  258. tmp_char = slurmdb_qos_flags_str(qos->flags);
  259. printf(" Unknown QOS flag used in:\n '%s'\n"
  260. " Valid QOS flags are\n '%s'\n",
  261. argv[i]+end, tmp_char);
  262. xfree(tmp_char);
  263. exit_code = 1;
  264. } else
  265. set = 1;
  266. } else if (!strncasecmp (argv[i], "GraceTime",
  267. MAX(command_len, 3))) {
  268. if (!qos)
  269. continue;
  270. if (get_uint(argv[i]+end, &qos->grace_time,
  271. "GraceTime") == SLURM_SUCCESS) {
  272. set = 1;
  273. }
  274. } else if (!strncasecmp (argv[i], "GrpCPUMins",
  275. MAX(command_len, 7))) {
  276. if(!qos)
  277. continue;
  278. if (get_uint64(argv[i]+end,
  279. &qos->grp_cpu_mins,
  280. "GrpCPUMins") == SLURM_SUCCESS)
  281. set = 1;
  282. } else if (!strncasecmp (argv[i], "GrpCPURunMins",
  283. MAX(command_len, 7))) {
  284. if(!qos)
  285. continue;
  286. if (get_uint64(argv[i]+end, &qos->grp_cpu_run_mins,
  287. "GrpCPURunMins") == SLURM_SUCCESS)
  288. set = 1;
  289. } else if (!strncasecmp (argv[i], "GrpCPUs",
  290. MAX(command_len, 7))) {
  291. if(!qos)
  292. continue;
  293. if (get_uint(argv[i]+end, &qos->grp_cpus,
  294. "GrpCPUs") == SLURM_SUCCESS)
  295. set = 1;
  296. } else if (!strncasecmp (argv[i], "GrpJobs",
  297. MAX(command_len, 4))) {
  298. if(!qos)
  299. continue;
  300. if (get_uint(argv[i]+end, &qos->grp_jobs,
  301. "GrpJobs") == SLURM_SUCCESS)
  302. set = 1;
  303. } else if (!strncasecmp (argv[i], "GrpMemory",
  304. MAX(command_len, 4))) {
  305. if(!qos)
  306. continue;
  307. if (get_uint(argv[i]+end, &qos->grp_mem,
  308. "GrpMemory") == SLURM_SUCCESS)
  309. set = 1;
  310. } else if (!strncasecmp (argv[i], "GrpNodes",
  311. MAX(command_len, 4))) {
  312. if(!qos)
  313. continue;
  314. if (get_uint(argv[i]+end, &qos->grp_nodes,
  315. "GrpNodes") == SLURM_SUCCESS)
  316. set = 1;
  317. } else if (!strncasecmp (argv[i], "GrpSubmitJobs",
  318. MAX(command_len, 4))) {
  319. if(!qos)
  320. continue;
  321. if (get_uint(argv[i]+end, &qos->grp_submit_jobs,
  322. "GrpSubmitJobs") == SLURM_SUCCESS)
  323. set = 1;
  324. } else if (!strncasecmp (argv[i], "GrpWall",
  325. MAX(command_len, 4))) {
  326. if(!qos)
  327. continue;
  328. mins = time_str2mins(argv[i]+end);
  329. if (mins != NO_VAL) {
  330. qos->grp_wall = (uint32_t) mins;
  331. set = 1;
  332. } else {
  333. exit_code=1;
  334. fprintf(stderr,
  335. " Bad GrpWall time format: %s\n",
  336. argv[i]);
  337. }
  338. } else if (!strncasecmp (argv[i], "MaxCPUMinsPerJob",
  339. MAX(command_len, 7))) {
  340. if(!qos)
  341. continue;
  342. if (get_uint64(argv[i]+end,
  343. &qos->max_cpu_mins_pj,
  344. "MaxCPUMins") == SLURM_SUCCESS)
  345. set = 1;
  346. } else if (!strncasecmp (argv[i], "MaxCPUsPerJob",
  347. MAX(command_len, 7))) {
  348. if(!qos)
  349. continue;
  350. if (get_uint(argv[i]+end, &qos->max_cpus_pj,
  351. "MaxCPUs") == SLURM_SUCCESS)
  352. set = 1;
  353. } else if (!strncasecmp (argv[i], "MaxCPUsPerUser",
  354. MAX(command_len, 11))) {
  355. if(!qos)
  356. continue;
  357. if (get_uint(argv[i]+end, &qos->max_cpus_pu,
  358. "MaxCPUsPerUser") == SLURM_SUCCESS)
  359. set = 1;
  360. } else if (!strncasecmp (argv[i], "MaxJobsPerUser",
  361. MAX(command_len, 4))) {
  362. if(!qos)
  363. continue;
  364. if (get_uint(argv[i]+end, &qos->max_jobs_pu,
  365. "MaxJobs") == SLURM_SUCCESS)
  366. set = 1;
  367. } else if (!strncasecmp (argv[i], "MaxNodesPerJob",
  368. MAX(command_len, 4))) {
  369. if(!qos)
  370. continue;
  371. if (get_uint(argv[i]+end,
  372. &qos->max_nodes_pj,
  373. "MaxNodes") == SLURM_SUCCESS)
  374. set = 1;
  375. } else if (!strncasecmp (argv[i], "MaxNodesPerUser",
  376. MAX(command_len, 8))) {
  377. if(!qos)
  378. continue;
  379. if (get_uint(argv[i]+end,
  380. &qos->max_nodes_pu,
  381. "MaxNodesPerUser") == SLURM_SUCCESS)
  382. set = 1;
  383. } else if (!strncasecmp (argv[i], "MaxSubmitJobsPerUser",
  384. MAX(command_len, 4))) {
  385. if(!qos)
  386. continue;
  387. if (get_uint(argv[i]+end, &qos->max_submit_jobs_pu,
  388. "MaxSubmitJobs") == SLURM_SUCCESS)
  389. set = 1;
  390. } else if (!strncasecmp (argv[i], "MaxWallDurationPerJob",
  391. MAX(command_len, 4))) {
  392. if(!qos)
  393. continue;
  394. mins = time_str2mins(argv[i]+end);
  395. if (mins != NO_VAL) {
  396. qos->max_wall_pj = (uint32_t) mins;
  397. set = 1;
  398. } else {
  399. exit_code=1;
  400. fprintf(stderr,
  401. " Bad MaxWall time format: %s\n",
  402. argv[i]);
  403. }
  404. } else if (!strncasecmp (argv[i], "PreemptMode",
  405. MAX(command_len, 8))) {
  406. if(!qos)
  407. continue;
  408. qos->preempt_mode = preempt_mode_num(argv[i]+end);
  409. if(qos->preempt_mode == (uint16_t)NO_VAL) {
  410. fprintf(stderr,
  411. " Bad Preempt Mode given: %s\n",
  412. argv[i]);
  413. exit_code = 1;
  414. } else if (qos->preempt_mode == PREEMPT_MODE_SUSPEND) {
  415. printf("PreemptType and PreemptMode "
  416. "values incompatible\n");
  417. exit_code = 1;
  418. } else
  419. set = 1;
  420. /* Preempt needs to follow PreemptMode */
  421. } else if (!strncasecmp (argv[i], "Preempt",
  422. MAX(command_len, 7))) {
  423. if(!qos)
  424. continue;
  425. if(!qos->preempt_list)
  426. qos->preempt_list =
  427. list_create(slurm_destroy_char);
  428. if(!g_qos_list)
  429. g_qos_list = acct_storage_g_get_qos(
  430. db_conn, my_uid, NULL);
  431. if(slurmdb_addto_qos_char_list(qos->preempt_list,
  432. g_qos_list, argv[i]+end,
  433. option))
  434. set = 1;
  435. else
  436. exit_code = 1;
  437. } else if (!strncasecmp (argv[i], "Priority",
  438. MAX(command_len, 3))) {
  439. if(!qos)
  440. continue;
  441. if (get_uint(argv[i]+end, &qos->priority,
  442. "Priority") == SLURM_SUCCESS)
  443. set = 1;
  444. } else if (!strncasecmp (argv[i], "UsageFactor",
  445. MAX(command_len, 6))) {
  446. if(!qos)
  447. continue;
  448. if (get_double(argv[i]+end, &qos->usage_factor,
  449. "UsageFactor") == SLURM_SUCCESS)
  450. set = 1;
  451. } else if (!strncasecmp (argv[i], "UsageThreshold",
  452. MAX(command_len, 6))) {
  453. if(!qos)
  454. continue;
  455. if (get_double(argv[i]+end, &qos->usage_thres,
  456. "UsageThreshold") == SLURM_SUCCESS)
  457. set = 1;
  458. } else {
  459. exit_code = 1;
  460. printf(" Unknown option: %s\n"
  461. " Use keyword 'where' to modify condition\n",
  462. argv[i]);
  463. }
  464. }
  465. (*start) = i;
  466. return set;
  467. }
  468. static bool _isdefault(List qos_list)
  469. {
  470. int rc = 0;
  471. slurmdb_association_cond_t assoc_cond;
  472. slurmdb_association_rec_t *assoc = NULL;
  473. ListIterator itr;
  474. List ret_list = NULL;
  475. char *name = NULL;
  476. if(!qos_list || !list_count(qos_list))
  477. return rc;
  478. /* this needs to happen before any removing takes place so we
  479. can figure out things correctly */
  480. xassert(g_qos_list);
  481. memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));
  482. assoc_cond.without_parent_info = 1;
  483. assoc_cond.def_qos_id_list = list_create(slurm_destroy_char);
  484. itr = list_iterator_create(qos_list);
  485. while ((name = list_next(itr))) {
  486. uint32_t id = str_2_slurmdb_qos(g_qos_list, name);
  487. if(id == NO_VAL)
  488. continue;
  489. list_append(assoc_cond.def_qos_id_list,
  490. xstrdup_printf("%u", id));
  491. }
  492. list_iterator_destroy(itr);
  493. ret_list = acct_storage_g_get_associations(
  494. db_conn, my_uid, &assoc_cond);
  495. list_destroy(assoc_cond.def_qos_id_list);
  496. if(!ret_list || !list_count(ret_list))
  497. goto end_it;
  498. fprintf(stderr," Associations listed below have these "
  499. "as their Default QOS.\n");
  500. itr = list_iterator_create(ret_list);
  501. while((assoc = list_next(itr))) {
  502. name = slurmdb_qos_str(g_qos_list, assoc->def_qos_id);
  503. if (!assoc->user) {
  504. // see if this isn't a user
  505. fprintf(stderr,
  506. " DefQOS = %-10s C = %-10s A = %-20s\n",
  507. name, assoc->cluster, assoc->acct);
  508. } else if (assoc->partition) {
  509. // see if there is a partition name
  510. fprintf(stderr,
  511. " DefQOS = %-10s C = %-10s A = %-20s "
  512. "U = %-9s P = %s\n",
  513. name, assoc->cluster, assoc->acct,
  514. assoc->user, assoc->partition);
  515. } else {
  516. fprintf(stderr,
  517. " DefQOS = %-10s C = %-10s A = %-20s "
  518. "U = %-9s\n",
  519. name, assoc->cluster, assoc->acct, assoc->user);
  520. }
  521. }
  522. list_iterator_destroy(itr);
  523. rc = 1;
  524. end_it:
  525. if(ret_list)
  526. list_destroy(ret_list);
  527. return rc;
  528. }
  529. extern int sacctmgr_add_qos(int argc, char *argv[])
  530. {
  531. int rc = SLURM_SUCCESS;
  532. int i=0, limit_set=0;
  533. ListIterator itr = NULL;
  534. slurmdb_qos_rec_t *qos = NULL;
  535. slurmdb_qos_rec_t *start_qos = xmalloc(sizeof(slurmdb_qos_rec_t));
  536. List name_list = list_create(slurm_destroy_char);
  537. char *description = NULL;
  538. char *name = NULL;
  539. List qos_list = NULL;
  540. char *qos_str = NULL;
  541. slurmdb_init_qos_rec(start_qos, 0);
  542. for (i=0; i<argc; i++) {
  543. int command_len = strlen(argv[i]);
  544. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
  545. || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
  546. i++;
  547. limit_set += _set_rec(&i, argc, argv, name_list, start_qos);
  548. }
  549. if(exit_code) {
  550. list_destroy(name_list);
  551. xfree(description);
  552. return SLURM_ERROR;
  553. } else if(!list_count(name_list)) {
  554. list_destroy(name_list);
  555. slurmdb_destroy_qos_rec(start_qos);
  556. exit_code=1;
  557. fprintf(stderr, " Need name of qos to add.\n");
  558. return SLURM_SUCCESS;
  559. }
  560. if(!g_qos_list) {
  561. g_qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
  562. if(!g_qos_list) {
  563. exit_code=1;
  564. fprintf(stderr, " Problem getting qos's "
  565. "from database. "
  566. "Contact your admin.\n");
  567. list_destroy(name_list);
  568. xfree(description);
  569. return SLURM_ERROR;
  570. }
  571. }
  572. qos_list = list_create(slurmdb_destroy_qos_rec);
  573. itr = list_iterator_create(name_list);
  574. while((name = list_next(itr))) {
  575. qos = NULL;
  576. if(!sacctmgr_find_qos_from_list(g_qos_list, name)) {
  577. qos = xmalloc(sizeof(slurmdb_qos_rec_t));
  578. slurmdb_init_qos_rec(qos, 0);
  579. qos->name = xstrdup(name);
  580. if(start_qos->description)
  581. qos->description =
  582. xstrdup(start_qos->description);
  583. else
  584. qos->description = xstrdup(name);
  585. qos->grace_time = start_qos->grace_time;
  586. qos->grp_cpu_mins = start_qos->grp_cpu_mins;
  587. qos->grp_cpus = start_qos->grp_cpus;
  588. qos->grp_jobs = start_qos->grp_jobs;
  589. qos->grp_mem = start_qos->grp_mem;
  590. qos->grp_nodes = start_qos->grp_nodes;
  591. qos->grp_submit_jobs = start_qos->grp_submit_jobs;
  592. qos->grp_wall = start_qos->grp_wall;
  593. qos->max_cpu_mins_pj = start_qos->max_cpu_mins_pj;
  594. qos->max_cpu_run_mins_pu =
  595. start_qos->max_cpu_run_mins_pu;
  596. qos->max_cpus_pj = start_qos->max_cpus_pj;
  597. qos->max_cpus_pu = start_qos->max_cpus_pu;
  598. qos->max_jobs_pu = start_qos->max_jobs_pu;
  599. qos->max_nodes_pj = start_qos->max_nodes_pj;
  600. qos->max_nodes_pu = start_qos->max_nodes_pu;
  601. qos->max_submit_jobs_pu = start_qos->max_submit_jobs_pu;
  602. qos->max_wall_pj = start_qos->max_wall_pj;
  603. qos->preempt_list =
  604. copy_char_list(start_qos->preempt_list);
  605. qos->preempt_mode = start_qos->preempt_mode;
  606. qos->priority = start_qos->priority;
  607. qos->usage_factor = start_qos->usage_factor;
  608. qos->usage_thres = start_qos->usage_thres;
  609. xstrfmtcat(qos_str, " %s\n", name);
  610. list_append(qos_list, qos);
  611. }
  612. }
  613. list_iterator_destroy(itr);
  614. list_destroy(name_list);
  615. if(!list_count(qos_list)) {
  616. printf(" Nothing new added.\n");
  617. goto end_it;
  618. }
  619. if(qos_str) {
  620. printf(" Adding QOS(s)\n%s", qos_str);
  621. printf(" Settings\n");
  622. if(description)
  623. printf(" Description = %s\n", description);
  624. else
  625. printf(" Description = %s\n", "QOS Name");
  626. sacctmgr_print_qos_limits(start_qos);
  627. xfree(qos_str);
  628. }
  629. notice_thread_init();
  630. if(list_count(qos_list))
  631. rc = acct_storage_g_add_qos(db_conn, my_uid, qos_list);
  632. else
  633. goto end_it;
  634. notice_thread_fini();
  635. if(rc == SLURM_SUCCESS) {
  636. if(commit_check("Would you like to commit changes?")) {
  637. acct_storage_g_commit(db_conn, 1);
  638. } else {
  639. printf(" Changes Discarded\n");
  640. acct_storage_g_commit(db_conn, 0);
  641. }
  642. } else {
  643. exit_code=1;
  644. fprintf(stderr, " Problem adding QOS: %s\n",
  645. slurm_strerror(rc));
  646. rc = SLURM_ERROR;
  647. }
  648. end_it:
  649. list_destroy(qos_list);
  650. xfree(description);
  651. return rc;
  652. }
  653. extern int sacctmgr_list_qos(int argc, char *argv[])
  654. {
  655. int rc = SLURM_SUCCESS;
  656. slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t));
  657. int i=0;
  658. ListIterator itr = NULL;
  659. ListIterator itr2 = NULL;
  660. slurmdb_qos_rec_t *qos = NULL;
  661. List qos_list = NULL;
  662. int field_count = 0;
  663. print_field_t *field = NULL;
  664. List format_list = list_create(slurm_destroy_char);
  665. List print_fields_list; /* types are of print_field_t */
  666. for (i=0; i<argc; i++) {
  667. int command_len = strlen(argv[i]);
  668. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
  669. || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
  670. i++;
  671. _set_cond(&i, argc, argv, qos_cond, format_list);
  672. }
  673. if(exit_code) {
  674. slurmdb_destroy_qos_cond(qos_cond);
  675. list_destroy(format_list);
  676. return SLURM_ERROR;
  677. } else if(!list_count(format_list)) {
  678. slurm_addto_char_list(format_list,
  679. "Name,Prio,GraceT,Preempt,PreemptM,"
  680. "Flags%40,UsageThres,UsageFactor,"
  681. "GrpCPUs,GrpCPUMins,GrpCPURunMins,"
  682. "GrpJ,GrpMEM,GrpN,GrpS,GrpW,"
  683. "MaxCPUs,MaxCPUMins,MaxN,MaxW,"
  684. "MaxCPUsPerUser,"
  685. "MaxJobsPerUser,MaxNodesPerUser,"
  686. "MaxSubmitJobsPerUser");
  687. }
  688. print_fields_list = sacctmgr_process_format_list(format_list);
  689. list_destroy(format_list);
  690. if(exit_code) {
  691. list_destroy(print_fields_list);
  692. return SLURM_ERROR;
  693. }
  694. qos_list = acct_storage_g_get_qos(db_conn, my_uid, qos_cond);
  695. slurmdb_destroy_qos_cond(qos_cond);
  696. if(!qos_list) {
  697. exit_code=1;
  698. fprintf(stderr, " Problem with query.\n");
  699. list_destroy(print_fields_list);
  700. return SLURM_ERROR;
  701. }
  702. itr = list_iterator_create(qos_list);
  703. itr2 = list_iterator_create(print_fields_list);
  704. print_fields_header(print_fields_list);
  705. field_count = list_count(print_fields_list);
  706. while((qos = list_next(itr))) {
  707. int curr_inx = 1;
  708. while((field = list_next(itr2))) {
  709. switch(field->type) {
  710. case PRINT_DESC:
  711. field->print_routine(
  712. field, qos->description,
  713. (curr_inx == field_count));
  714. break;
  715. case PRINT_FLAGS:
  716. {
  717. char *tmp_char = slurmdb_qos_flags_str(
  718. qos->flags);
  719. field->print_routine(
  720. field,
  721. tmp_char,
  722. (curr_inx == field_count));
  723. xfree(tmp_char);
  724. break;
  725. }
  726. case PRINT_UT:
  727. field->print_routine(
  728. field, qos->usage_thres,
  729. (curr_inx == field_count));
  730. break;
  731. case PRINT_GRACE:
  732. field->print_routine(
  733. field, (uint64_t)qos->grace_time,
  734. (curr_inx == field_count));
  735. break;
  736. case PRINT_GRPCM:
  737. field->print_routine(
  738. field,
  739. qos->grp_cpu_mins,
  740. (curr_inx == field_count));
  741. break;
  742. case PRINT_GRPCRM:
  743. field->print_routine(
  744. field,
  745. qos->grp_cpu_run_mins,
  746. (curr_inx == field_count));
  747. break;
  748. case PRINT_GRPC:
  749. field->print_routine(field,
  750. qos->grp_cpus,
  751. (curr_inx == field_count));
  752. break;
  753. case PRINT_GRPJ:
  754. field->print_routine(field,
  755. qos->grp_jobs,
  756. (curr_inx == field_count));
  757. break;
  758. case PRINT_GRPMEM:
  759. field->print_routine(field,
  760. qos->grp_mem,
  761. (curr_inx == field_count));
  762. break;
  763. case PRINT_GRPN:
  764. field->print_routine(field,
  765. qos->grp_nodes,
  766. (curr_inx == field_count));
  767. break;
  768. case PRINT_GRPS:
  769. field->print_routine(field,
  770. qos->grp_submit_jobs,
  771. (curr_inx == field_count));
  772. break;
  773. case PRINT_GRPW:
  774. field->print_routine(
  775. field,
  776. qos->grp_wall,
  777. (curr_inx == field_count));
  778. break;
  779. case PRINT_ID:
  780. field->print_routine(
  781. field, qos->id,
  782. (curr_inx == field_count));
  783. break;
  784. case PRINT_MAXCM:
  785. field->print_routine(
  786. field,
  787. qos->max_cpu_mins_pj,
  788. (curr_inx == field_count));
  789. break;
  790. case PRINT_MAXCRM:
  791. field->print_routine(
  792. field,
  793. qos->max_cpu_run_mins_pu,
  794. (curr_inx == field_count));
  795. break;
  796. case PRINT_MAXC:
  797. field->print_routine(field,
  798. qos->max_cpus_pj,
  799. (curr_inx == field_count));
  800. break;
  801. case PRINT_MAXCU:
  802. field->print_routine(field,
  803. qos->max_cpus_pu,
  804. (curr_inx == field_count));
  805. break;
  806. case PRINT_MAXJ:
  807. field->print_routine(field,
  808. qos->max_jobs_pu,
  809. (curr_inx == field_count));
  810. break;
  811. case PRINT_MAXN:
  812. field->print_routine(field,
  813. qos->max_nodes_pj,
  814. (curr_inx == field_count));
  815. break;
  816. case PRINT_MAXNU:
  817. field->print_routine(field,
  818. qos->max_nodes_pu,
  819. (curr_inx == field_count));
  820. break;
  821. case PRINT_MAXS:
  822. field->print_routine(field,
  823. qos->max_submit_jobs_pu,
  824. (curr_inx == field_count));
  825. break;
  826. case PRINT_MAXW:
  827. field->print_routine(
  828. field,
  829. qos->max_wall_pj,
  830. (curr_inx == field_count));
  831. break;
  832. case PRINT_NAME:
  833. field->print_routine(
  834. field, qos->name,
  835. (curr_inx == field_count));
  836. break;
  837. case PRINT_PREE:
  838. if(!g_qos_list)
  839. g_qos_list = acct_storage_g_get_qos(
  840. db_conn, my_uid, NULL);
  841. field->print_routine(
  842. field, g_qos_list, qos->preempt_bitstr,
  843. (curr_inx == field_count));
  844. break;
  845. case PRINT_PREEM:
  846. {
  847. char *tmp_char = "cluster";
  848. if(qos->preempt_mode)
  849. tmp_char = xstrtolower(
  850. preempt_mode_string(
  851. qos->preempt_mode));
  852. field->print_routine(
  853. field,
  854. tmp_char,
  855. (curr_inx == field_count));
  856. break;
  857. }
  858. case PRINT_PRIO:
  859. field->print_routine(
  860. field, qos->priority,
  861. (curr_inx == field_count));
  862. break;
  863. case PRINT_UF:
  864. field->print_routine(
  865. field, qos->usage_factor,
  866. (curr_inx == field_count));
  867. break;
  868. default:
  869. field->print_routine(
  870. field, NULL,
  871. (curr_inx == field_count));
  872. break;
  873. }
  874. curr_inx++;
  875. }
  876. list_iterator_reset(itr2);
  877. printf("\n");
  878. }
  879. list_iterator_destroy(itr2);
  880. list_iterator_destroy(itr);
  881. list_destroy(qos_list);
  882. list_destroy(print_fields_list);
  883. return rc;
  884. }
  885. extern int sacctmgr_modify_qos(int argc, char *argv[])
  886. {
  887. int rc = SLURM_SUCCESS;
  888. slurmdb_qos_cond_t *qos_cond = xmalloc(sizeof(slurmdb_qos_cond_t));
  889. slurmdb_qos_rec_t *qos = xmalloc(sizeof(slurmdb_qos_rec_t));
  890. int i=0;
  891. int cond_set = 0, rec_set = 0, set = 0;
  892. List ret_list = NULL;
  893. slurmdb_init_qos_rec(qos, 0);
  894. for (i=0; i<argc; i++) {
  895. int command_len = strlen(argv[i]);
  896. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))) {
  897. i++;
  898. cond_set += _set_cond(&i, argc, argv, qos_cond, NULL);
  899. } else if (!strncasecmp (argv[i], "Set", MAX(command_len, 3))) {
  900. i++;
  901. rec_set += _set_rec(&i, argc, argv, NULL, qos);
  902. } else {
  903. cond_set += _set_cond(&i, argc, argv, qos_cond, NULL);
  904. }
  905. }
  906. if(exit_code) {
  907. slurmdb_destroy_qos_cond(qos_cond);
  908. slurmdb_destroy_qos_rec(qos);
  909. return SLURM_ERROR;
  910. } else if(!rec_set) {
  911. exit_code=1;
  912. fprintf(stderr, " You didn't give me anything to set\n");
  913. slurmdb_destroy_qos_cond(qos_cond);
  914. slurmdb_destroy_qos_rec(qos);
  915. return SLURM_ERROR;
  916. } else if(!cond_set) {
  917. if(!commit_check("You didn't set any conditions with 'WHERE'.\n"
  918. "Are you sure you want to continue?")) {
  919. printf("Aborted\n");
  920. slurmdb_destroy_qos_cond(qos_cond);
  921. slurmdb_destroy_qos_rec(qos);
  922. return SLURM_SUCCESS;
  923. }
  924. }
  925. notice_thread_init();
  926. ret_list = acct_storage_g_modify_qos(db_conn, my_uid, qos_cond, qos);
  927. if(ret_list && list_count(ret_list)) {
  928. char *object = NULL;
  929. ListIterator itr = list_iterator_create(ret_list);
  930. printf(" Modified qos...\n");
  931. while((object = list_next(itr))) {
  932. printf(" %s\n", object);
  933. }
  934. list_iterator_destroy(itr);
  935. set = 1;
  936. } else if(ret_list) {
  937. printf(" Nothing modified\n");
  938. } else {
  939. exit_code=1;
  940. fprintf(stderr, " Error with request: %s\n",
  941. slurm_strerror(errno));
  942. rc = SLURM_ERROR;
  943. }
  944. if(ret_list)
  945. list_destroy(ret_list);
  946. notice_thread_fini();
  947. if(set) {
  948. if(commit_check("Would you like to commit changes?"))
  949. acct_storage_g_commit(db_conn, 1);
  950. else {
  951. printf(" Changes Discarded\n");
  952. acct_storage_g_commit(db_conn, 0);
  953. }
  954. }
  955. slurmdb_destroy_qos_cond(qos_cond);
  956. slurmdb_destroy_qos_rec(qos);
  957. return rc;
  958. }
  959. extern int sacctmgr_delete_qos(int argc, char *argv[])
  960. {
  961. int rc = SLURM_SUCCESS;
  962. slurmdb_qos_cond_t *qos_cond =
  963. xmalloc(sizeof(slurmdb_qos_cond_t));
  964. int i=0;
  965. List ret_list = NULL;
  966. int set = 0;
  967. for (i=0; i<argc; i++) {
  968. int command_len = strlen(argv[i]);
  969. if (!strncasecmp (argv[i], "Where", MAX(command_len, 5))
  970. || !strncasecmp (argv[i], "Set", MAX(command_len, 3)))
  971. i++;
  972. set += _set_cond(&i, argc, argv, qos_cond, NULL);
  973. }
  974. if(!set) {
  975. exit_code=1;
  976. fprintf(stderr,
  977. " No conditions given to remove, not executing.\n");
  978. slurmdb_destroy_qos_cond(qos_cond);
  979. return SLURM_ERROR;
  980. } else if(set == -1) {
  981. slurmdb_destroy_qos_cond(qos_cond);
  982. return SLURM_ERROR;
  983. }
  984. if (!g_qos_list)
  985. g_qos_list = acct_storage_g_get_qos(
  986. db_conn, my_uid, NULL);
  987. notice_thread_init();
  988. ret_list = acct_storage_g_remove_qos(db_conn, my_uid, qos_cond);
  989. notice_thread_fini();
  990. slurmdb_destroy_qos_cond(qos_cond);
  991. if(ret_list && list_count(ret_list)) {
  992. char *object = NULL;
  993. ListIterator itr = NULL;
  994. /* Check to see if person is trying to remove a default
  995. * qos of an association. _isdefault only works with the
  996. * output from acct_storage_g_remove_qos, and
  997. * with a previously got g_qos_list.
  998. */
  999. if (_isdefault(ret_list)) {
  1000. exit_code=1;
  1001. fprintf(stderr, " Please either remove the qos' listed "
  1002. "above from list and resubmit,\n"
  1003. " or change the default qos to "
  1004. "remove the qos.\n"
  1005. " Changes Discarded\n");
  1006. acct_storage_g_commit(db_conn, 0);
  1007. goto end_it;
  1008. }
  1009. itr = list_iterator_create(ret_list);
  1010. printf(" Deleting QOS(s)...\n");
  1011. while((object = list_next(itr))) {
  1012. printf(" %s\n", object);
  1013. }
  1014. list_iterator_destroy(itr);
  1015. if(commit_check("Would you like to commit changes?")) {
  1016. acct_storage_g_commit(db_conn, 1);
  1017. } else {
  1018. printf(" Changes Discarded\n");
  1019. acct_storage_g_commit(db_conn, 0);
  1020. }
  1021. } else if(ret_list) {
  1022. printf(" Nothing deleted\n");
  1023. } else {
  1024. exit_code=1;
  1025. fprintf(stderr, " Error with request: %s\n",
  1026. slurm_strerror(errno));
  1027. rc = SLURM_ERROR;
  1028. }
  1029. end_it:
  1030. if(ret_list)
  1031. list_destroy(ret_list);
  1032. return rc;
  1033. }