PageRenderTime 66ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/src/sacctmgr/common.c

https://github.com/cfenoy/slurm
C | 1578 lines | 1323 code | 201 blank | 54 comment | 525 complexity | e8f2e4f9f3364d10826f0dafebd4091b MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * common.c - definitions for functions common to all modules in sacctmgr.
  3. *****************************************************************************
  4. * Copyright (C) 2008 Lawrence Livermore National Security.
  5. * Copyright (C) 2002-2007 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. #include "src/common/slurmdbd_defs.h"
  41. #include "src/common/slurm_auth.h"
  42. #include <unistd.h>
  43. #include <termios.h>
  44. #define FORMAT_STRING_SIZE 32
  45. static pthread_t lock_warning_thread;
  46. static void *_print_lock_warn(void *no_data)
  47. {
  48. sleep(5);
  49. printf(" Database is busy or waiting for lock from other user.\n");
  50. return NULL;
  51. }
  52. static void _nonblock(int state)
  53. {
  54. struct termios ttystate;
  55. //get the terminal state
  56. tcgetattr(STDIN_FILENO, &ttystate);
  57. switch(state) {
  58. case 1:
  59. //turn off canonical mode
  60. ttystate.c_lflag &= ~ICANON;
  61. //minimum of number input read.
  62. ttystate.c_cc[VMIN] = 1;
  63. break;
  64. default:
  65. //turn on canonical mode
  66. ttystate.c_lflag |= ICANON;
  67. }
  68. //set the terminal attributes.
  69. tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
  70. }
  71. extern int parse_option_end(char *option)
  72. {
  73. int end = 0;
  74. if (!option)
  75. return 0;
  76. while(option[end]) {
  77. if ((option[end] == '=')
  78. || (option[end] == '+' && option[end+1] == '=')
  79. || (option[end] == '-' && option[end+1] == '='))
  80. break;
  81. end++;
  82. }
  83. if (!option[end])
  84. return 0;
  85. end++;
  86. return end;
  87. }
  88. /* you need to xfree whatever is sent from here */
  89. extern char *strip_quotes(char *option, int *increased, bool make_lower)
  90. {
  91. int end = 0;
  92. int i=0, start=0;
  93. char *meat = NULL;
  94. char quote_c = '\0';
  95. int quote = 0;
  96. if (!option)
  97. return NULL;
  98. /* first strip off the ("|')'s */
  99. if (option[i] == '\"' || option[i] == '\'') {
  100. quote_c = option[i];
  101. quote = 1;
  102. i++;
  103. }
  104. start = i;
  105. while(option[i]) {
  106. if (quote && option[i] == quote_c) {
  107. end++;
  108. break;
  109. } else if (option[i] == '\"' || option[i] == '\'')
  110. option[i] = '`';
  111. else if (make_lower) {
  112. char lower = tolower(option[i]);
  113. if (lower != option[i])
  114. option[i] = lower;
  115. }
  116. i++;
  117. }
  118. end += i;
  119. meat = xmalloc((i-start)+1);
  120. memcpy(meat, option+start, (i-start));
  121. if (increased)
  122. (*increased) += end;
  123. return meat;
  124. }
  125. static print_field_t *_get_print_field(char *object)
  126. {
  127. /* This should be kept in alpha order to avoid picking the
  128. wrong field name.
  129. */
  130. print_field_t *field = xmalloc(sizeof(print_field_t));
  131. char *tmp_char = NULL;
  132. int command_len, field_len = 0;
  133. if((tmp_char = strstr(object, "\%"))) {
  134. field_len = atoi(tmp_char+1);
  135. tmp_char[0] = '\0';
  136. }
  137. command_len = strlen(object);
  138. if (!strncasecmp("Account", object, MAX(command_len, 3))
  139. || !strncasecmp("Acct", object, MAX(command_len, 4))) {
  140. field->type = PRINT_ACCT;
  141. field->name = xstrdup("Account");
  142. if (tree_display)
  143. field->len = -20;
  144. else
  145. field->len = 10;
  146. field->print_routine = print_fields_str;
  147. } else if (!strncasecmp("ActionRaw", object, MAX(command_len, 7))) {
  148. field->type = PRINT_ACTIONRAW;
  149. field->name = xstrdup("ActionRaw");
  150. field->len = 10;
  151. field->print_routine = print_fields_uint;
  152. } else if (!strncasecmp("Action", object, MAX(command_len, 4))) {
  153. field->type = PRINT_ACTION;
  154. field->name = xstrdup("Action");
  155. field->len = 20;
  156. field->print_routine = print_fields_str;
  157. } else if (!strncasecmp("Actor", object, MAX(command_len, 4))) {
  158. field->type = PRINT_ACTOR;
  159. field->name = xstrdup("Actor");
  160. field->len = 10;
  161. field->print_routine = print_fields_str;
  162. } else if (!strncasecmp("AdminLevel", object, MAX(command_len, 2))) {
  163. field->type = PRINT_ADMIN;
  164. field->name = xstrdup("Admin");
  165. field->len = 9;
  166. field->print_routine = print_fields_str;
  167. } else if (!strncasecmp("Classification", object,
  168. MAX(command_len, 3))) {
  169. field->type = PRINT_CPUS;
  170. field->name = xstrdup("Class");
  171. field->len = 9;
  172. field->print_routine = print_fields_str;
  173. } else if (!strncasecmp("ClusterNodes", object, MAX(command_len, 8))
  174. || !strncasecmp("NodeNames", object, MAX(command_len, 8))) {
  175. field->type = PRINT_CLUSTER_NODES;
  176. field->name = xstrdup("Cluster Nodes");
  177. field->len = 20;
  178. field->print_routine = print_fields_str;
  179. } else if (!strncasecmp("Cluster", object, MAX(command_len, 2))) {
  180. field->type = PRINT_CLUSTER;
  181. field->name = xstrdup("Cluster");
  182. field->len = 10;
  183. field->print_routine = print_fields_str;
  184. } else if (!strncasecmp("Coordinators", object, MAX(command_len, 2))) {
  185. field->type = PRINT_COORDS;
  186. field->name = xstrdup("Coord Accounts");
  187. field->len = 20;
  188. field->print_routine = sacctmgr_print_coord_list;
  189. } else if (!strncasecmp("ControlHost", object, MAX(command_len, 8))) {
  190. field->type = PRINT_CHOST;
  191. field->name = xstrdup("ControlHost");
  192. field->len = 15;
  193. field->print_routine = print_fields_str;
  194. } else if (!strncasecmp("ControlPort", object, MAX(command_len, 8))) {
  195. field->type = PRINT_CPORT;
  196. field->name = xstrdup("ControlPort");
  197. field->len = 12;
  198. field->print_routine = print_fields_uint;
  199. } else if (!strncasecmp("CPUCount", object, MAX(command_len, 2))) {
  200. field->type = PRINT_CPUS;
  201. field->name = xstrdup("CPUCount");
  202. field->len = 9;
  203. field->print_routine = print_fields_str;
  204. } else if (!strncasecmp("DefaultAccount", object,
  205. MAX(command_len, 8))) {
  206. field->type = PRINT_DACCT;
  207. field->name = xstrdup("Def Acct");
  208. field->len = 10;
  209. field->print_routine = print_fields_str;
  210. } else if (!strncasecmp("DefaultQOS", object, MAX(command_len, 8))) {
  211. field->type = PRINT_DQOS;
  212. field->name = xstrdup("Def QOS");
  213. field->len = 9;
  214. field->print_routine = print_fields_str;
  215. } else if (!strncasecmp("DefaultWCKey", object, MAX(command_len, 8))) {
  216. field->type = PRINT_DWCKEY;
  217. field->name = xstrdup("Def WCKey");
  218. field->len = 10;
  219. field->print_routine = print_fields_str;
  220. } else if (!strncasecmp("Description", object, MAX(command_len, 3))) {
  221. field->type = PRINT_DESC;
  222. field->name = xstrdup("Descr");
  223. field->len = 20;
  224. field->print_routine = print_fields_str;
  225. } else if(!strncasecmp("Duration", object, MAX(command_len, 2))) {
  226. field->type = PRINT_DURATION;
  227. field->name = xstrdup("Duration");
  228. field->len = 13;
  229. field->print_routine = print_fields_time_from_secs;
  230. } else if(!strncasecmp("End", object, MAX(command_len, 2))) {
  231. field->type = PRINT_END;
  232. field->name = xstrdup("End");
  233. field->len = 19;
  234. field->print_routine = print_fields_date;
  235. } else if(!strncasecmp("EventRaw", object, MAX(command_len, 6))) {
  236. field->type = PRINT_EVENTRAW;
  237. field->name = xstrdup("EventRaw");
  238. field->len = 8;
  239. field->print_routine = print_fields_uint;
  240. } else if(!strncasecmp("Event", object, MAX(command_len, 2))) {
  241. field->type = PRINT_EVENT;
  242. field->name = xstrdup("Event");
  243. field->len = 7;
  244. field->print_routine = print_fields_str;
  245. } else if (!strncasecmp("Flags", object, MAX(command_len, 2))) {
  246. field->type = PRINT_FLAGS;
  247. field->name = xstrdup("Flags");
  248. field->len = 20;
  249. field->print_routine = print_fields_str;
  250. } else if (!strncasecmp("GraceTime", object, MAX(command_len, 3))) {
  251. field->type = PRINT_GRACE;
  252. field->name = xstrdup("GraceTime");
  253. field->len = 10;
  254. field->print_routine = print_fields_time_from_secs;
  255. } else if (!strncasecmp("GrpCPUMins", object, MAX(command_len, 7))) {
  256. field->type = PRINT_GRPCM;
  257. field->name = xstrdup("GrpCPUMins");
  258. field->len = 11;
  259. field->print_routine = print_fields_uint64;
  260. } else if (!strncasecmp("GrpCPURunMins", object, MAX(command_len, 7))) {
  261. field->type = PRINT_GRPCRM;
  262. field->name = xstrdup("GrpCPURunMins");
  263. field->len = 13;
  264. field->print_routine = print_fields_uint64;
  265. } else if (!strncasecmp("GrpCPUs", object, MAX(command_len, 7))) {
  266. field->type = PRINT_GRPC;
  267. field->name = xstrdup("GrpCPUs");
  268. field->len = 8;
  269. field->print_routine = print_fields_uint;
  270. } else if (!strncasecmp("GrpJobs", object, MAX(command_len, 4))) {
  271. field->type = PRINT_GRPJ;
  272. field->name = xstrdup("GrpJobs");
  273. field->len = 7;
  274. field->print_routine = print_fields_uint;
  275. } else if (!strncasecmp("GrpMemory", object, MAX(command_len, 4))) {
  276. field->type = PRINT_GRPMEM;
  277. field->name = xstrdup("GrpMem");
  278. field->len = 7;
  279. field->print_routine = print_fields_uint;
  280. } else if (!strncasecmp("GrpNodes", object, MAX(command_len, 4))) {
  281. field->type = PRINT_GRPN;
  282. field->name = xstrdup("GrpNodes");
  283. field->len = 8;
  284. field->print_routine = print_fields_uint;
  285. } else if (!strncasecmp("GrpSubmitJobs", object, MAX(command_len, 4))) {
  286. field->type = PRINT_GRPS;
  287. field->name = xstrdup("GrpSubmit");
  288. field->len = 9;
  289. field->print_routine = print_fields_uint;
  290. } else if (!strncasecmp("GrpWall", object, MAX(command_len, 4))) {
  291. field->type = PRINT_GRPW;
  292. field->name = xstrdup("GrpWall");
  293. field->len = 11;
  294. field->print_routine = print_fields_time;
  295. } else if (!strncasecmp("ID", object, MAX(command_len, 2))) {
  296. field->type = PRINT_ID;
  297. field->name = xstrdup("ID");
  298. field->len = 6;
  299. field->print_routine = print_fields_uint;
  300. } else if (!strncasecmp("Info", object, MAX(command_len, 2))) {
  301. field->type = PRINT_INFO;
  302. field->name = xstrdup("Info");
  303. field->len = 20;
  304. field->print_routine = print_fields_str;
  305. } else if (!strncasecmp("LFT", object, MAX(command_len, 1))) {
  306. field->type = PRINT_LFT;
  307. field->name = xstrdup("LFT");
  308. field->len = 6;
  309. field->print_routine = print_fields_uint;
  310. } else if (!strncasecmp("MaxCPUMinsPerJob", object,
  311. MAX(command_len, 7))) {
  312. field->type = PRINT_MAXCM;
  313. field->name = xstrdup("MaxCPUMins");
  314. field->len = 11;
  315. field->print_routine = print_fields_uint64;
  316. } else if (!strncasecmp("MaxCPURunMinsPerUser",
  317. object, MAX(command_len, 7))) {
  318. field->type = PRINT_MAXCRM;
  319. field->name = xstrdup("MaxCPURunMinsPU");
  320. field->len = 15;
  321. field->print_routine = print_fields_uint64;
  322. } else if (!strncasecmp("MaxCPUsPerJob", object, MAX(command_len, 7))) {
  323. field->type = PRINT_MAXC;
  324. field->name = xstrdup("MaxCPUs");
  325. field->len = 8;
  326. field->print_routine = print_fields_uint;
  327. } else if (!strncasecmp("MaxCPUsPerUser", object,
  328. MAX(command_len, 11))) {
  329. field->type = PRINT_MAXCU;
  330. field->name = xstrdup("MaxCPUsPU");
  331. field->len = 9;
  332. field->print_routine = print_fields_uint;
  333. } else if (!strncasecmp("MaxJobs", object, MAX(command_len, 4))) {
  334. field->type = PRINT_MAXJ;
  335. field->name = xstrdup("MaxJobs");
  336. field->len = 7;
  337. field->print_routine = print_fields_uint;
  338. } else if (!strncasecmp("MaxJobsPerUser",
  339. object, MAX(command_len, 8))) {
  340. field->type = PRINT_MAXJ; /* used same as MaxJobs */
  341. field->name = xstrdup("MaxJobsPU");
  342. field->len = 9;
  343. field->print_routine = print_fields_uint;
  344. } else if (!strncasecmp("MaxNodesPerJob", object,
  345. MAX(command_len, 4))) {
  346. field->type = PRINT_MAXN;
  347. field->name = xstrdup("MaxNodes");
  348. field->len = 8;
  349. field->print_routine = print_fields_uint;
  350. } else if (!strncasecmp("MaxNodesPerUser", object,
  351. MAX(command_len, 12))) {
  352. field->type = PRINT_MAXNU;
  353. field->name = xstrdup("MaxNodesPU");
  354. field->len = 10;
  355. field->print_routine = print_fields_uint;
  356. } else if (!strncasecmp("MaxSubmitJobs", object, MAX(command_len, 4))) {
  357. field->type = PRINT_MAXS;
  358. field->name = xstrdup("MaxSubmit");
  359. field->len = 9;
  360. field->print_routine = print_fields_uint;
  361. } else if (!strncasecmp("MaxSubmitJobsPerUser",
  362. object, MAX(command_len, 10))) {
  363. field->type = PRINT_MAXS; /* used same as MaxSubmitJobs */
  364. field->name = xstrdup("MaxSubmitPU");
  365. field->len = 11;
  366. field->print_routine = print_fields_uint;
  367. } else if (!strncasecmp("MaxWallDurationPerJob", object,
  368. MAX(command_len, 4))) {
  369. field->type = PRINT_MAXW;
  370. field->name = xstrdup("MaxWall");
  371. field->len = 11;
  372. field->print_routine = print_fields_time;
  373. } else if (!strncasecmp("Name", object, MAX(command_len, 2))) {
  374. field->type = PRINT_NAME;
  375. field->name = xstrdup("Name");
  376. field->len = 10;
  377. field->print_routine = print_fields_str;
  378. } else if (!strncasecmp("NodeCount", object, MAX(command_len, 5))) {
  379. field->type = PRINT_NODECNT;
  380. field->name = xstrdup("NodeCount");
  381. field->len = 9;
  382. field->print_routine = print_fields_uint;
  383. } else if (!strncasecmp("NodeName", object, MAX(command_len, 5))) {
  384. field->type = PRINT_NODENAME;
  385. field->name = xstrdup("NodeName");
  386. field->len = 20;
  387. field->print_routine = print_fields_str;
  388. } else if (!strncasecmp("Organization", object, MAX(command_len, 1))) {
  389. field->type = PRINT_ORG;
  390. field->name = xstrdup("Org");
  391. field->len = 20;
  392. field->print_routine = print_fields_str;
  393. } else if (!strncasecmp("ParentID", object, MAX(command_len, 7))) {
  394. field->type = PRINT_PID;
  395. field->name = xstrdup("Par ID");
  396. field->len = 6;
  397. field->print_routine = print_fields_uint;
  398. } else if (!strncasecmp("ParentName", object, MAX(command_len, 7))) {
  399. field->type = PRINT_PNAME;
  400. field->name = xstrdup("Par Name");
  401. field->len = 10;
  402. field->print_routine = print_fields_str;
  403. } else if (!strncasecmp("Partition", object, MAX(command_len, 4))) {
  404. field->type = PRINT_PART;
  405. field->name = xstrdup("Partition");
  406. field->len = 10;
  407. field->print_routine = print_fields_str;
  408. } else if (!strncasecmp("PluginIDSelect", object,
  409. MAX(command_len, 2))) {
  410. field->type = PRINT_SELECT;
  411. field->name = xstrdup("PluginIDSelect");
  412. field->len = 14;
  413. field->print_routine = print_fields_uint;
  414. } else if (!strncasecmp("PreemptMode", object, MAX(command_len, 8))) {
  415. field->type = PRINT_PREEM;
  416. field->name = xstrdup("PreemptMode");
  417. field->len = 11;
  418. field->print_routine = print_fields_str;
  419. /* Preempt needs to follow PreemptMode */
  420. } else if (!strncasecmp("Preempt", object, MAX(command_len, 7))) {
  421. field->type = PRINT_PREE;
  422. field->name = xstrdup("Preempt");
  423. field->len = 10;
  424. field->print_routine = sacctmgr_print_qos_bitstr;
  425. } else if (!strncasecmp("Priority", object, MAX(command_len, 3))) {
  426. field->type = PRINT_PRIO;
  427. field->name = xstrdup("Priority");
  428. field->len = 10;
  429. field->print_routine = print_fields_uint;
  430. } else if (!strncasecmp("Problem", object, MAX(command_len, 1))) {
  431. field->type = PRINT_PROBLEM;
  432. field->name = xstrdup("Problem");
  433. field->len = 40;
  434. field->print_routine = print_fields_str;
  435. } else if (!strncasecmp("QOSLevel", object, MAX(command_len, 3))) {
  436. field->type = PRINT_QOS;
  437. field->name = xstrdup("QOS");
  438. field->len = 20;
  439. field->print_routine = sacctmgr_print_qos_list;
  440. } else if (!strncasecmp("QOSRAWLevel", object, MAX(command_len, 4))) {
  441. field->type = PRINT_QOS_RAW;
  442. field->name = xstrdup("QOS_RAW");
  443. field->len = 10;
  444. field->print_routine = print_fields_char_list;
  445. } else if (!strncasecmp("RGT", object, MAX(command_len, 1))) {
  446. field->type = PRINT_RGT;
  447. field->name = xstrdup("RGT");
  448. field->len = 6;
  449. field->print_routine = print_fields_uint;
  450. } else if (!strncasecmp("RPC", object, MAX(command_len, 1))) {
  451. field->type = PRINT_RPC_VERSION;
  452. field->name = xstrdup("RPC");
  453. field->len = 3;
  454. field->print_routine = print_fields_uint;
  455. } else if (!strncasecmp("Share", object, MAX(command_len, 1))
  456. || !strncasecmp("FairShare", object, MAX(command_len, 2))) {
  457. field->type = PRINT_FAIRSHARE;
  458. field->name = xstrdup("Share");
  459. field->len = 9;
  460. field->print_routine = print_fields_uint;
  461. } else if (!strncasecmp("TimeStamp", object, MAX(command_len, 1))) {
  462. field->type = PRINT_TS;
  463. field->name = xstrdup("Time");
  464. field->len = 19;
  465. field->print_routine = print_fields_date;
  466. } else if (!strncasecmp("UsageFactor", object, MAX(command_len, 6))) {
  467. field->type = PRINT_UF;
  468. field->name = xstrdup("UsageFactor");
  469. field->len = 11;
  470. field->print_routine = print_fields_double;
  471. } else if (!strncasecmp("UsageThreshold",
  472. object, MAX(command_len, 6))) {
  473. field->type = PRINT_UT;
  474. field->name = xstrdup("UsageThres");
  475. field->len = 10;
  476. field->print_routine = print_fields_double;
  477. } else if (!strncasecmp("User", object, MAX(command_len, 1))) {
  478. field->type = PRINT_USER;
  479. field->name = xstrdup("User");
  480. field->len = 10;
  481. field->print_routine = print_fields_str;
  482. } else if (!strncasecmp("WCKeys", object, MAX(command_len, 2))) {
  483. field->type = PRINT_WCKEYS;
  484. field->name = xstrdup("WCKeys");
  485. field->len = 20;
  486. field->print_routine = print_fields_char_list;
  487. } else if (!strncasecmp("Where", object, MAX(command_len, 2))) {
  488. field->type = PRINT_WHERE;
  489. field->name = xstrdup("Where");
  490. field->len = 20;
  491. field->print_routine = print_fields_str;
  492. } else {
  493. exit_code=1;
  494. fprintf(stderr, "Unknown field '%s'\n", object);
  495. exit(1);
  496. }
  497. if (field_len)
  498. field->len = field_len;
  499. return field;
  500. }
  501. extern int notice_thread_init()
  502. {
  503. pthread_attr_t attr;
  504. slurm_attr_init(&attr);
  505. if (pthread_create(&lock_warning_thread, &attr,
  506. &_print_lock_warn, NULL))
  507. error ("pthread_create error %m");
  508. slurm_attr_destroy(&attr);
  509. return SLURM_SUCCESS;
  510. }
  511. extern int notice_thread_fini()
  512. {
  513. return pthread_cancel(lock_warning_thread);
  514. }
  515. extern int commit_check(char *warning)
  516. {
  517. int ans = 0;
  518. char c = '\0';
  519. int fd = fileno(stdin);
  520. fd_set rfds;
  521. struct timeval tv;
  522. if (!rollback_flag)
  523. return 1;
  524. printf("%s (You have 30 seconds to decide)\n", warning);
  525. _nonblock(1);
  526. while(c != 'Y' && c != 'y'
  527. && c != 'N' && c != 'n'
  528. && c != '\n') {
  529. if (c) {
  530. printf("Y or N please\n");
  531. }
  532. printf("(N/y): ");
  533. fflush(stdout);
  534. FD_ZERO(&rfds);
  535. FD_SET(fd, &rfds);
  536. /* Wait up to 30 seconds. */
  537. tv.tv_sec = 30;
  538. tv.tv_usec = 0;
  539. if ((ans = select(fd+1, &rfds, NULL, NULL, &tv)) <= 0)
  540. break;
  541. c = getchar();
  542. printf("\n");
  543. }
  544. _nonblock(0);
  545. if (ans <= 0)
  546. printf("timeout\n");
  547. else if (c == 'Y' || c == 'y')
  548. return 1;
  549. return 0;
  550. }
  551. extern int sacctmgr_remove_assoc_usage(slurmdb_association_cond_t *assoc_cond)
  552. {
  553. List update_list = NULL;
  554. List local_assoc_list = NULL;
  555. List local_cluster_list = NULL;
  556. ListIterator itr = NULL;
  557. ListIterator itr2 = NULL;
  558. ListIterator itr3 = NULL;
  559. char *account = NULL;
  560. char *cluster = NULL;
  561. char *user = NULL;
  562. slurmdb_association_rec_t* rec = NULL;
  563. slurmdb_cluster_rec_t* cluster_rec = NULL;
  564. slurmdb_update_object_t* update_obj = NULL;
  565. slurmdb_cluster_cond_t cluster_cond;
  566. int rc = SLURM_SUCCESS;
  567. if (!assoc_cond->cluster_list)
  568. assoc_cond->cluster_list = list_create(slurm_destroy_char);
  569. if (!list_count(assoc_cond->cluster_list)) {
  570. char *temp = slurm_get_cluster_name();
  571. if (temp) {
  572. printf("No cluster specified, resetting "
  573. "on local cluster %s\n", temp);
  574. list_append(assoc_cond->cluster_list, temp);
  575. }
  576. if (!list_count(assoc_cond->cluster_list)) {
  577. error("A cluster name is required to remove usage");
  578. return SLURM_ERROR;
  579. }
  580. }
  581. if(!commit_check("Would you like to reset usage?")) {
  582. printf(" Changes Discarded\n");
  583. return rc;
  584. }
  585. local_assoc_list = acct_storage_g_get_associations(
  586. db_conn, my_uid, assoc_cond);
  587. slurmdb_init_cluster_cond(&cluster_cond, 0);
  588. cluster_cond.cluster_list = assoc_cond->cluster_list;
  589. local_cluster_list = acct_storage_g_get_clusters(
  590. db_conn, my_uid, &cluster_cond);
  591. itr = list_iterator_create(assoc_cond->cluster_list);
  592. itr2 = list_iterator_create(assoc_cond->acct_list);
  593. if (assoc_cond->user_list && list_count(assoc_cond->user_list))
  594. itr3 = list_iterator_create(assoc_cond->user_list);
  595. while((cluster = list_next(itr))) {
  596. cluster_rec = sacctmgr_find_cluster_from_list(
  597. local_cluster_list, cluster);
  598. if (!cluster_rec) {
  599. error("Failed to find cluster %s in database",
  600. cluster);
  601. rc = SLURM_ERROR;
  602. goto end_it;
  603. }
  604. update_list = list_create(slurmdb_destroy_update_object);
  605. update_obj = xmalloc(sizeof(slurmdb_update_object_t));
  606. update_obj->type = SLURMDB_REMOVE_ASSOC_USAGE;
  607. update_obj->objects = list_create(NULL);
  608. if (itr3) {
  609. while ((user = list_next(itr3))) {
  610. while ((account = list_next(itr2))) {
  611. rec = sacctmgr_find_association_from_list(
  612. local_assoc_list,
  613. user, account, cluster, "*");
  614. if (!rec) {
  615. error("Failed to find "
  616. "cluster %s "
  617. "account %s user "
  618. "%s association "
  619. "in database",
  620. cluster, account,
  621. user);
  622. rc = SLURM_ERROR;
  623. goto end_it;
  624. }
  625. list_append(update_obj->objects, rec);
  626. }
  627. list_iterator_reset(itr2);
  628. }
  629. list_iterator_reset(itr3);
  630. } else {
  631. while ((account = list_next(itr2))) {
  632. rec = sacctmgr_find_association_from_list(
  633. local_assoc_list,
  634. NULL, account, cluster, "*");
  635. if (!rec) {
  636. error("Failed to find cluster %s "
  637. "account %s association in "
  638. "database",
  639. cluster, account);
  640. rc = SLURM_ERROR;
  641. goto end_it;
  642. }
  643. list_append(update_obj->objects, rec);
  644. }
  645. list_iterator_reset(itr2);
  646. }
  647. if (list_count(update_obj->objects)) {
  648. list_append(update_list, update_obj);
  649. rc = slurmdb_send_accounting_update(
  650. update_list, cluster,
  651. cluster_rec->control_host,
  652. cluster_rec->control_port,
  653. cluster_rec->rpc_version);
  654. }
  655. list_destroy(update_list);
  656. }
  657. end_it:
  658. list_iterator_destroy(itr);
  659. list_iterator_destroy(itr2);
  660. if (itr3)
  661. list_iterator_destroy(itr3);
  662. list_destroy(local_assoc_list);
  663. list_destroy(local_cluster_list);
  664. return rc;
  665. }
  666. extern slurmdb_association_rec_t *sacctmgr_find_account_base_assoc(
  667. char *account, char *cluster)
  668. {
  669. slurmdb_association_rec_t *assoc = NULL;
  670. char *temp = "root";
  671. slurmdb_association_cond_t assoc_cond;
  672. List assoc_list = NULL;
  673. if (!cluster)
  674. return NULL;
  675. if (account)
  676. temp = account;
  677. memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));
  678. assoc_cond.acct_list = list_create(NULL);
  679. list_append(assoc_cond.cluster_list, temp);
  680. assoc_cond.cluster_list = list_create(NULL);
  681. list_append(assoc_cond.cluster_list, cluster);
  682. assoc_cond.user_list = list_create(NULL);
  683. list_append(assoc_cond.user_list, "");
  684. assoc_list = acct_storage_g_get_associations(db_conn, my_uid,
  685. &assoc_cond);
  686. list_destroy(assoc_cond.acct_list);
  687. list_destroy(assoc_cond.cluster_list);
  688. list_destroy(assoc_cond.user_list);
  689. if (assoc_list)
  690. assoc = list_pop(assoc_list);
  691. list_destroy(assoc_list);
  692. return assoc;
  693. }
  694. extern slurmdb_association_rec_t *sacctmgr_find_root_assoc(char *cluster)
  695. {
  696. return sacctmgr_find_account_base_assoc(NULL, cluster);
  697. }
  698. extern slurmdb_user_rec_t *sacctmgr_find_user(char *name)
  699. {
  700. slurmdb_user_rec_t *user = NULL;
  701. slurmdb_user_cond_t user_cond;
  702. slurmdb_association_cond_t assoc_cond;
  703. List user_list = NULL;
  704. if (!name)
  705. return NULL;
  706. memset(&user_cond, 0, sizeof(slurmdb_user_cond_t));
  707. memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));
  708. assoc_cond.user_list = list_create(NULL);
  709. list_append(assoc_cond.user_list, name);
  710. user_cond.assoc_cond = &assoc_cond;
  711. user_list = acct_storage_g_get_users(db_conn, my_uid,
  712. &user_cond);
  713. list_destroy(assoc_cond.user_list);
  714. if (user_list)
  715. user = list_pop(user_list);
  716. list_destroy(user_list);
  717. return user;
  718. }
  719. extern slurmdb_account_rec_t *sacctmgr_find_account(char *name)
  720. {
  721. slurmdb_account_rec_t *account = NULL;
  722. slurmdb_account_cond_t account_cond;
  723. slurmdb_association_cond_t assoc_cond;
  724. List account_list = NULL;
  725. if (!name)
  726. return NULL;
  727. memset(&account_cond, 0, sizeof(slurmdb_account_cond_t));
  728. memset(&assoc_cond, 0, sizeof(slurmdb_association_cond_t));
  729. assoc_cond.acct_list = list_create(NULL);
  730. list_append(assoc_cond.acct_list, name);
  731. account_cond.assoc_cond = &assoc_cond;
  732. account_list = acct_storage_g_get_accounts(db_conn, my_uid,
  733. &account_cond);
  734. list_destroy(assoc_cond.acct_list);
  735. if (account_list)
  736. account = list_pop(account_list);
  737. list_destroy(account_list);
  738. return account;
  739. }
  740. extern slurmdb_cluster_rec_t *sacctmgr_find_cluster(char *name)
  741. {
  742. slurmdb_cluster_rec_t *cluster = NULL;
  743. slurmdb_cluster_cond_t cluster_cond;
  744. List cluster_list = NULL;
  745. if (!name)
  746. return NULL;
  747. slurmdb_init_cluster_cond(&cluster_cond, 0);
  748. cluster_cond.cluster_list = list_create(NULL);
  749. list_append(cluster_cond.cluster_list, name);
  750. cluster_list = acct_storage_g_get_clusters(db_conn, my_uid,
  751. &cluster_cond);
  752. list_destroy(cluster_cond.cluster_list);
  753. if (cluster_list)
  754. cluster = list_pop(cluster_list);
  755. list_destroy(cluster_list);
  756. return cluster;
  757. }
  758. extern slurmdb_association_rec_t *sacctmgr_find_association_from_list(
  759. List assoc_list, char *user, char *account,
  760. char *cluster, char *partition)
  761. {
  762. ListIterator itr = NULL;
  763. slurmdb_association_rec_t * assoc = NULL;
  764. if (!assoc_list)
  765. return NULL;
  766. itr = list_iterator_create(assoc_list);
  767. while((assoc = list_next(itr))) {
  768. if (((!user && assoc->user)
  769. || (user && (!assoc->user
  770. || strcasecmp(user, assoc->user))))
  771. || (account && (!assoc->acct
  772. || strcasecmp(account, assoc->acct)))
  773. || ((!cluster && assoc->cluster)
  774. || (cluster && (!assoc->cluster
  775. || strcasecmp(cluster,
  776. assoc->cluster)))))
  777. continue;
  778. else if (partition) {
  779. if (partition[0] != '*'
  780. && (!assoc->partition
  781. || strcasecmp(partition, assoc->partition)))
  782. continue;
  783. } else if (assoc->partition)
  784. continue;
  785. break;
  786. }
  787. list_iterator_destroy(itr);
  788. return assoc;
  789. }
  790. extern slurmdb_association_rec_t *sacctmgr_find_account_base_assoc_from_list(
  791. List assoc_list, char *account, char *cluster)
  792. {
  793. ListIterator itr = NULL;
  794. slurmdb_association_rec_t *assoc = NULL;
  795. char *temp = "root";
  796. if (!cluster || !assoc_list)
  797. return NULL;
  798. if (account)
  799. temp = account;
  800. /* info("looking for %s %s in %d", account, cluster, */
  801. /* list_count(assoc_list)); */
  802. itr = list_iterator_create(assoc_list);
  803. while((assoc = list_next(itr))) {
  804. /* info("is it %s %s %s", assoc->user, assoc->acct, assoc->cluster); */
  805. if (assoc->user
  806. || strcasecmp(temp, assoc->acct)
  807. || strcasecmp(cluster, assoc->cluster))
  808. continue;
  809. /* info("found it"); */
  810. break;
  811. }
  812. list_iterator_destroy(itr);
  813. return assoc;
  814. }
  815. extern slurmdb_qos_rec_t *sacctmgr_find_qos_from_list(
  816. List qos_list, char *name)
  817. {
  818. ListIterator itr = NULL;
  819. slurmdb_qos_rec_t *qos = NULL;
  820. char *working_name = NULL;
  821. if (!name || !qos_list)
  822. return NULL;
  823. if (name[0] == '+' || name[0] == '-')
  824. working_name = name+1;
  825. else
  826. working_name = name;
  827. itr = list_iterator_create(qos_list);
  828. while((qos = list_next(itr))) {
  829. if (!strcasecmp(working_name, qos->name))
  830. break;
  831. }
  832. list_iterator_destroy(itr);
  833. return qos;
  834. }
  835. extern slurmdb_user_rec_t *sacctmgr_find_user_from_list(
  836. List user_list, char *name)
  837. {
  838. ListIterator itr = NULL;
  839. slurmdb_user_rec_t *user = NULL;
  840. if (!name || !user_list)
  841. return NULL;
  842. itr = list_iterator_create(user_list);
  843. while((user = list_next(itr))) {
  844. if (!strcasecmp(name, user->name))
  845. break;
  846. }
  847. list_iterator_destroy(itr);
  848. return user;
  849. }
  850. extern slurmdb_account_rec_t *sacctmgr_find_account_from_list(
  851. List acct_list, char *name)
  852. {
  853. ListIterator itr = NULL;
  854. slurmdb_account_rec_t *account = NULL;
  855. if (!name || !acct_list)
  856. return NULL;
  857. itr = list_iterator_create(acct_list);
  858. while((account = list_next(itr))) {
  859. if (!strcasecmp(name, account->name))
  860. break;
  861. }
  862. list_iterator_destroy(itr);
  863. return account;
  864. }
  865. extern slurmdb_cluster_rec_t *sacctmgr_find_cluster_from_list(
  866. List cluster_list, char *name)
  867. {
  868. ListIterator itr = NULL;
  869. slurmdb_cluster_rec_t *cluster = NULL;
  870. if (!name || !cluster_list)
  871. return NULL;
  872. itr = list_iterator_create(cluster_list);
  873. while((cluster = list_next(itr))) {
  874. if (!strcasecmp(name, cluster->name))
  875. break;
  876. }
  877. list_iterator_destroy(itr);
  878. return cluster;
  879. }
  880. extern slurmdb_wckey_rec_t *sacctmgr_find_wckey_from_list(
  881. List wckey_list, char *user, char *name, char *cluster)
  882. {
  883. ListIterator itr = NULL;
  884. slurmdb_wckey_rec_t * wckey = NULL;
  885. if (!wckey_list)
  886. return NULL;
  887. itr = list_iterator_create(wckey_list);
  888. while((wckey = list_next(itr))) {
  889. if (((!user && wckey->user)
  890. || (user && (!wckey->user
  891. || strcasecmp(user, wckey->user))))
  892. || (name && (!wckey->name
  893. || strcasecmp(name, wckey->name)))
  894. || ((!cluster && wckey->cluster)
  895. || (cluster && (!wckey->cluster
  896. || strcasecmp(cluster,
  897. wckey->cluster)))))
  898. continue;
  899. break;
  900. }
  901. list_iterator_destroy(itr);
  902. return wckey;
  903. }
  904. extern int get_uint(char *in_value, uint32_t *out_value, char *type)
  905. {
  906. char *ptr = NULL, *meat = NULL;
  907. long num;
  908. if (!(meat = strip_quotes(in_value, NULL, 1))) {
  909. error("Problem with strip_quotes");
  910. return SLURM_ERROR;
  911. }
  912. num = strtol(meat, &ptr, 10);
  913. if ((num == 0) && ptr && ptr[0]) {
  914. error("Invalid value for %s (%s)", type, meat);
  915. xfree(meat);
  916. return SLURM_ERROR;
  917. }
  918. xfree(meat);
  919. if (num < 0)
  920. *out_value = INFINITE; /* flag to clear */
  921. else
  922. *out_value = (uint32_t) num;
  923. return SLURM_SUCCESS;
  924. }
  925. extern int get_uint16(char *in_value, uint16_t *out_value, char *type)
  926. {
  927. char *ptr = NULL, *meat = NULL;
  928. long num;
  929. if (!(meat = strip_quotes(in_value, NULL, 1))) {
  930. error("Problem with strip_quotes");
  931. return SLURM_ERROR;
  932. }
  933. num = strtol(meat, &ptr, 10);
  934. if ((num == 0) && ptr && ptr[0]) {
  935. error("Invalid value for %s (%s)", type, meat);
  936. xfree(meat);
  937. return SLURM_ERROR;
  938. }
  939. xfree(meat);
  940. if (num < 0)
  941. *out_value = (uint16_t) INFINITE; /* flag to clear */
  942. else
  943. *out_value = (uint16_t) num;
  944. return SLURM_SUCCESS;
  945. }
  946. extern int get_uint64(char *in_value, uint64_t *out_value, char *type)
  947. {
  948. char *ptr = NULL, *meat = NULL;
  949. long long num;
  950. if (!(meat = strip_quotes(in_value, NULL, 1))) {
  951. error("Problem with strip_quotes");
  952. return SLURM_ERROR;
  953. }
  954. num = strtoll(meat, &ptr, 10);
  955. if ((num == 0) && ptr && ptr[0]) {
  956. error("Invalid value for %s (%s)", type, meat);
  957. xfree(meat);
  958. return SLURM_ERROR;
  959. }
  960. xfree(meat);
  961. if (num < 0)
  962. *out_value = INFINITE; /* flag to clear */
  963. else
  964. *out_value = (uint64_t) num;
  965. return SLURM_SUCCESS;
  966. }
  967. extern int get_double(char *in_value, double *out_value, char *type)
  968. {
  969. char *ptr = NULL, *meat = NULL;
  970. double num;
  971. if (!(meat = strip_quotes(in_value, NULL, 1))) {
  972. error("Problem with strip_quotes");
  973. return SLURM_ERROR;
  974. }
  975. num = strtod(meat, &ptr);
  976. if ((num == 0) && ptr && ptr[0]) {
  977. error("Invalid value for %s (%s)", type, meat);
  978. xfree(meat);
  979. return SLURM_ERROR;
  980. }
  981. xfree(meat);
  982. if (num < 0)
  983. *out_value = (double) INFINITE; /* flag to clear */
  984. else
  985. *out_value = (double) num;
  986. return SLURM_SUCCESS;
  987. }
  988. extern int addto_action_char_list(List char_list, char *names)
  989. {
  990. int i=0, start=0;
  991. char *name = NULL, *tmp_char = NULL;
  992. ListIterator itr = NULL;
  993. char quote_c = '\0';
  994. int quote = 0;
  995. uint32_t id=0;
  996. int count = 0;
  997. if (!char_list) {
  998. error("No list was given to fill in");
  999. return 0;
  1000. }
  1001. itr = list_iterator_create(char_list);
  1002. if (names) {
  1003. if (names[i] == '\"' || names[i] == '\'') {
  1004. quote_c = names[i];
  1005. quote = 1;
  1006. i++;
  1007. }
  1008. start = i;
  1009. while(names[i]) {
  1010. if (quote && names[i] == quote_c)
  1011. break;
  1012. else if (names[i] == '\"' || names[i] == '\'')
  1013. names[i] = '`';
  1014. else if (names[i] == ',') {
  1015. if ((i-start) > 0) {
  1016. name = xmalloc((i-start+1));
  1017. memcpy(name, names+start, (i-start));
  1018. id = str_2_slurmdbd_msg_type(name);
  1019. if (id == NO_VAL) {
  1020. error("You gave a bad action "
  1021. "'%s'.", name);
  1022. xfree(name);
  1023. break;
  1024. }
  1025. xfree(name);
  1026. name = xstrdup_printf("%u", id);
  1027. while((tmp_char = list_next(itr))) {
  1028. if (!strcasecmp(tmp_char, name))
  1029. break;
  1030. }
  1031. list_iterator_reset(itr);
  1032. if (!tmp_char) {
  1033. list_append(char_list, name);
  1034. count++;
  1035. } else
  1036. xfree(name);
  1037. }
  1038. i++;
  1039. start = i;
  1040. if (!names[i]) {
  1041. error("There is a problem with "
  1042. "your request. It appears you "
  1043. "have spaces inside your list.");
  1044. break;
  1045. }
  1046. }
  1047. i++;
  1048. }
  1049. if ((i-start) > 0) {
  1050. name = xmalloc((i-start)+1);
  1051. memcpy(name, names+start, (i-start));
  1052. id = str_2_slurmdbd_msg_type(name);
  1053. if (id == NO_VAL) {
  1054. error("You gave a bad action '%s'.",
  1055. name);
  1056. xfree(name);
  1057. goto end_it;
  1058. }
  1059. xfree(name);
  1060. name = xstrdup_printf("%u", id);
  1061. while((tmp_char = list_next(itr))) {
  1062. if (!strcasecmp(tmp_char, name))
  1063. break;
  1064. }
  1065. if (!tmp_char) {
  1066. list_append(char_list, name);
  1067. count++;
  1068. } else
  1069. xfree(name);
  1070. }
  1071. }
  1072. end_it:
  1073. list_iterator_destroy(itr);
  1074. return count;
  1075. }
  1076. extern List copy_char_list(List char_list)
  1077. {
  1078. List ret_list = NULL;
  1079. char *tmp_char = NULL;
  1080. ListIterator itr = NULL;
  1081. if (!char_list || !list_count(char_list))
  1082. return NULL;
  1083. itr = list_iterator_create(char_list);
  1084. ret_list = list_create(slurm_destroy_char);
  1085. while((tmp_char = list_next(itr)))
  1086. list_append(ret_list, xstrdup(tmp_char));
  1087. list_iterator_destroy(itr);
  1088. return ret_list;
  1089. }
  1090. extern void sacctmgr_print_coord_list(
  1091. print_field_t *field, List value, int last)
  1092. {
  1093. int abs_len = abs(field->len);
  1094. ListIterator itr = NULL;
  1095. char *print_this = NULL;
  1096. slurmdb_coord_rec_t *object = NULL;
  1097. if (!value || !list_count(value)) {
  1098. if (print_fields_parsable_print)
  1099. print_this = xstrdup("");
  1100. else
  1101. print_this = xstrdup(" ");
  1102. } else {
  1103. list_sort(value, (ListCmpF)sort_coord_list);
  1104. itr = list_iterator_create(value);
  1105. while((object = list_next(itr))) {
  1106. if (print_this)
  1107. xstrfmtcat(print_this, ",%s",
  1108. object->name);
  1109. else
  1110. print_this = xstrdup(object->name);
  1111. }
  1112. list_iterator_destroy(itr);
  1113. }
  1114. if (print_fields_parsable_print == PRINT_FIELDS_PARSABLE_NO_ENDING
  1115. && last)
  1116. printf("%s", print_this);
  1117. else if (print_fields_parsable_print)
  1118. printf("%s|", print_this);
  1119. else {
  1120. if (strlen(print_this) > abs_len)
  1121. print_this[abs_len-1] = '+';
  1122. if (field->len == abs_len)
  1123. printf("%*.*s ", abs_len, abs_len, print_this);
  1124. else
  1125. printf("%-*.*s ", abs_len, abs_len, print_this);
  1126. }
  1127. xfree(print_this);
  1128. }
  1129. extern void sacctmgr_print_qos_list(print_field_t *field, List qos_list,
  1130. List value, int last)
  1131. {
  1132. int abs_len = abs(field->len);
  1133. char *print_this = NULL;
  1134. print_this = get_qos_complete_str(qos_list, value);
  1135. if (print_fields_parsable_print == PRINT_FIELDS_PARSABLE_NO_ENDING
  1136. && last)
  1137. printf("%s", print_this);
  1138. else if (print_fields_parsable_print)
  1139. printf("%s|", print_this);
  1140. else {
  1141. if (strlen(print_this) > abs_len)
  1142. print_this[abs_len-1] = '+';
  1143. if (field->len == abs_len)
  1144. printf("%*.*s ", abs_len, abs_len, print_this);
  1145. else
  1146. printf("%-*.*s ", abs_len, abs_len, print_this);
  1147. }
  1148. xfree(print_this);
  1149. }
  1150. extern void sacctmgr_print_qos_bitstr(print_field_t *field, List qos_list,
  1151. bitstr_t *value, int last)
  1152. {
  1153. int abs_len = abs(field->len);
  1154. char *print_this = NULL;
  1155. print_this = get_qos_complete_str_bitstr(qos_list, value);
  1156. if (print_fields_parsable_print == PRINT_FIELDS_PARSABLE_NO_ENDING
  1157. && last)
  1158. printf("%s", print_this);
  1159. else if (print_fields_parsable_print)
  1160. printf("%s|", print_this);
  1161. else {
  1162. if (strlen(print_this) > abs_len)
  1163. print_this[abs_len-1] = '+';
  1164. if (field->len == abs_len)
  1165. printf("%*.*s ", abs_len, abs_len, print_this);
  1166. else
  1167. printf("%-*.*s ", abs_len, abs_len, print_this);
  1168. }
  1169. xfree(print_this);
  1170. }
  1171. extern void sacctmgr_print_assoc_limits(slurmdb_association_rec_t *assoc)
  1172. {
  1173. if (!assoc)
  1174. return;
  1175. if (assoc->shares_raw == INFINITE)
  1176. printf(" Fairshare = NONE\n");
  1177. else if (assoc->shares_raw != NO_VAL)
  1178. printf(" Fairshare = %u\n", assoc->shares_raw);
  1179. if (assoc->grp_cpu_mins == INFINITE)
  1180. printf(" GrpCPUMins = NONE\n");
  1181. else if (assoc->grp_cpu_mins != NO_VAL)
  1182. printf(" GrpCPUMins = %"PRIu64"\n",
  1183. assoc->grp_cpu_mins);
  1184. if (assoc->grp_cpus == INFINITE)
  1185. printf(" GrpCPUs = NONE\n");
  1186. else if (assoc->grp_cpus != NO_VAL)
  1187. printf(" GrpCPUs = %u\n", assoc->grp_cpus);
  1188. if (assoc->grp_jobs == INFINITE)
  1189. printf(" GrpJobs = NONE\n");
  1190. else if (assoc->grp_jobs != NO_VAL)
  1191. printf(" GrpJobs = %u\n", assoc->grp_jobs);
  1192. if (assoc->grp_mem == INFINITE)
  1193. printf(" GrpMemory = NONE\n");
  1194. else if (assoc->grp_mem != NO_VAL)
  1195. printf(" GrpMemory = %u\n", assoc->grp_mem);
  1196. if (assoc->grp_nodes == INFINITE)
  1197. printf(" GrpNodes = NONE\n");
  1198. else if (assoc->grp_nodes != NO_VAL)
  1199. printf(" GrpNodes = %u\n", assoc->grp_nodes);
  1200. if (assoc->grp_submit_jobs == INFINITE)
  1201. printf(" GrpSubmitJobs = NONE\n");
  1202. else if (assoc->grp_submit_jobs != NO_VAL)
  1203. printf(" GrpSubmitJobs = %u\n",
  1204. assoc->grp_submit_jobs);
  1205. if (assoc->grp_wall == INFINITE)
  1206. printf(" GrpWall = NONE\n");
  1207. else if (assoc->grp_wall != NO_VAL) {
  1208. char time_buf[32];
  1209. mins2time_str((time_t) assoc->grp_wall,
  1210. time_buf, sizeof(time_buf));
  1211. printf(" GrpWall = %s\n", time_buf);
  1212. }
  1213. if (assoc->max_cpu_mins_pj == (uint64_t)INFINITE)
  1214. printf(" MaxCPUMins = NONE\n");
  1215. else if (assoc->max_cpu_mins_pj != (uint64_t)NO_VAL)
  1216. printf(" MaxCPUMins = %"PRIu64"\n",
  1217. assoc->max_cpu_mins_pj);
  1218. if (assoc->max_cpus_pj == INFINITE)
  1219. printf(" MaxCPUs = NONE\n");
  1220. else if (assoc->max_cpus_pj != NO_VAL)
  1221. printf(" MaxCPUs = %u\n", assoc->max_cpus_pj);
  1222. if (assoc->max_jobs == INFINITE)
  1223. printf(" MaxJobs = NONE\n");
  1224. else if (assoc->max_jobs != NO_VAL)
  1225. printf(" MaxJobs = %u\n", assoc->max_jobs);
  1226. if (assoc->max_nodes_pj == INFINITE)
  1227. printf(" MaxNodes = NONE\n");
  1228. else if (assoc->max_nodes_pj != NO_VAL)
  1229. printf(" MaxNodes = %u\n", assoc->max_nodes_pj);
  1230. if (assoc->max_submit_jobs == INFINITE)
  1231. printf(" MaxSubmitJobs = NONE\n");
  1232. else if (assoc->max_submit_jobs != NO_VAL)
  1233. printf(" MaxSubmitJobs = %u\n",
  1234. assoc->max_submit_jobs);
  1235. if (assoc->max_wall_pj == INFINITE)
  1236. printf(" MaxWall = NONE\n");
  1237. else if (assoc->max_wall_pj != NO_VAL) {
  1238. char time_buf[32];
  1239. mins2time_str((time_t) assoc->max_wall_pj,
  1240. time_buf, sizeof(time_buf));
  1241. printf(" MaxWall = %s\n", time_buf);
  1242. }
  1243. if (assoc->qos_list) {
  1244. if (!g_qos_list)
  1245. g_qos_list =
  1246. acct_storage_g_get_qos(db_conn, my_uid, NULL);
  1247. char *temp_char = get_qos_complete_str(g_qos_list,
  1248. assoc->qos_list);
  1249. if (temp_char) {
  1250. printf(" QOS = %s\n", temp_char);
  1251. xfree(temp_char);
  1252. }
  1253. }
  1254. }
  1255. extern void sacctmgr_print_qos_limits(slurmdb_qos_rec_t *qos)
  1256. {
  1257. if (!qos)
  1258. return;
  1259. if (qos->preempt_list && !g_qos_list)
  1260. g_qos_list = acct_storage_g_get_qos(db_conn, my_uid, NULL);
  1261. if (qos->grace_time != NO_VAL)
  1262. printf(" GraceTime = %d\n", qos->grace_time);
  1263. else
  1264. printf(" GraceTime = NONE\n");
  1265. if (qos->grp_cpu_mins == INFINITE)
  1266. printf(" GrpCPUMins = NONE\n");
  1267. else if (qos->grp_cpu_mins != NO_VAL)
  1268. printf(" GrpCPUMins = %"PRIu64"\n",
  1269. qos->grp_cpu_mins);
  1270. if (qos->grp_cpus == INFINITE)
  1271. printf(" GrpCPUs = NONE\n");
  1272. else if (qos->grp_cpus != NO_VAL)
  1273. printf(" GrpCPUs = %u\n", qos->grp_cpus);
  1274. if (qos->grp_jobs == INFINITE)
  1275. printf(" GrpJobs = NONE\n");
  1276. else if (qos->grp_jobs != NO_VAL)
  1277. printf(" GrpJobs = %u\n", qos->grp_jobs);
  1278. if (qos->grp_mem == INFINITE)
  1279. printf(" GrpMemory = NONE\n");
  1280. else if (qos->grp_mem != NO_VAL)
  1281. printf(" GrpMemory = %u\n", qos->grp_mem);
  1282. if (qos->grp_nodes == INFINITE)
  1283. printf(" GrpNodes = NONE\n");
  1284. else if (qos->grp_nodes != NO_VAL)
  1285. printf(" GrpNodes = %u\n", qos->grp_nodes);
  1286. if (qos->grp_submit_jobs == INFINITE)
  1287. printf(" GrpSubmitJobs = NONE\n");
  1288. else if (qos->grp_submit_jobs != NO_VAL)
  1289. printf(" GrpSubmitJobs = %u\n",
  1290. qos->grp_submit_jobs);
  1291. if (qos->grp_wall == INFINITE)
  1292. printf(" GrpWall = NONE\n");
  1293. else if (qos->grp_wall != NO_VAL) {
  1294. char time_buf[32];
  1295. mins2time_str((time_t) qos->grp_wall,
  1296. time_buf, sizeof(time_buf));
  1297. printf(" GrpWall = %s\n", time_buf);
  1298. }
  1299. if (qos->max_cpu_mins_pj == (uint64_t)INFINITE)
  1300. printf(" MaxCPUMins = NONE\n");
  1301. else if (qos->max_cpu_mins_pj != (uint64_t)NO_VAL)
  1302. printf(" MaxCPUMins = %"PRIu64"\n",
  1303. qos->max_cpu_mins_pj);
  1304. if (qos->max_cpus_pj == INFINITE)
  1305. printf(" MaxCPUs = NONE\n");
  1306. else if (qos->max_cpus_pj != NO_VAL)
  1307. printf(" MaxCPUs = %u\n", qos->max_cpus_pj);
  1308. if (qos->max_cpus_pu == INFINITE)
  1309. printf(" MaxCPUsPerUser = NONE\n");
  1310. else if (qos->max_cpus_pu != NO_VAL)
  1311. printf(" MaxCPUsPerUser = %u\n", qos->max_cpus_pu);
  1312. if (qos->max_jobs_pu == INFINITE)
  1313. printf(" MaxJobs = NONE\n");
  1314. else if (qos->max_jobs_pu != NO_VAL)
  1315. printf(" MaxJobs = %u\n", qos->max_jobs_pu);
  1316. if (qos->max_nodes_pj == INFINITE)
  1317. printf(" MaxNodes = NONE\n");
  1318. else if (qos->max_nodes_pj != NO_VAL)
  1319. printf(" MaxNodes = %u\n", qos->max_nodes_pj);
  1320. if (qos->max_nodes_pu == INFINITE)
  1321. printf(" MaxNodesPerUser = NONE\n");
  1322. else if (qos->max_nodes_pu != NO_VAL)
  1323. printf(" MaxNodesPerUser = %u\n", qos->max_nodes_pu);
  1324. if (qos->max_submit_jobs_pu == INFINITE)
  1325. printf(" MaxSubmitJobs = NONE\n");
  1326. else if (qos->max_submit_jobs_pu != NO_VAL)
  1327. printf(" MaxSubmitJobs = %u\n",
  1328. qos->max_submit_jobs_pu);
  1329. if (qos->max_wall_pj == INFINITE)
  1330. printf(" MaxWall = NONE\n");
  1331. else if (qos->max_wall_pj != NO_VAL) {
  1332. char time_buf[32];
  1333. mins2time_str((time_t) qos->max_wall_pj,
  1334. time_buf, sizeof(time_buf));
  1335. printf(" MaxWall = %s\n", time_buf);
  1336. }
  1337. if (qos->preempt_list) {
  1338. char *temp_char = get_qos_complete_str(g_qos_list,
  1339. qos->preempt_list);
  1340. if (temp_char) {
  1341. printf(" Preempt = %s\n", temp_char);
  1342. xfree(temp_char);
  1343. }
  1344. }
  1345. if (qos->preempt_mode) {
  1346. printf(" PreemptMode = %s\n",
  1347. preempt_mode_string(qos->preempt_mode));
  1348. }
  1349. if (qos->priority == INFINITE)
  1350. printf(" Priority = NONE\n");
  1351. else if (qos->priority != NO_VAL)
  1352. printf(" Priority = %d\n", qos->priority);
  1353. }
  1354. extern int sort_coord_list(slurmdb_coord_rec_t *coord_a,
  1355. slurmdb_coord_rec_t *coord_b)
  1356. {
  1357. int diff = strcmp(coord_a->name, coord_b->name);
  1358. if (diff < 0)
  1359. return -1;
  1360. else if (diff > 0)
  1361. return 1;
  1362. return 0;
  1363. }
  1364. extern List sacctmgr_process_format_list(List format_list)
  1365. {
  1366. List print_fields_list = list_create(destroy_print_field);
  1367. ListIterator itr = list_iterator_create(format_list);
  1368. print_field_t *field = NULL;
  1369. char *object = NULL;
  1370. while((object = list_next(itr))) {
  1371. if(!(field = _get_print_field(object)))
  1372. exit(1);
  1373. list_append(print_fields_list, field);
  1374. }
  1375. list_iterator_destroy(itr);
  1376. return print_fields_list;
  1377. }