PageRenderTime 68ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/src/slurmdbd/proc_req.c

https://github.com/cfenoy/slurm
C | 3599 lines | 3113 code | 392 blank | 94 comment | 659 complexity | b9798d7e544059e4133a50c710d197b1 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0
  1. /*****************************************************************************\
  2. * proc_req.c - functions for processing incoming RPCs.
  3. *****************************************************************************
  4. * Copyright (C) 2008-2010 Lawrence Livermore National Security.
  5. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
  6. * Written by Morris Jette <jette1@llnl.gov>, Danny Auble <da@llnl.gov>
  7. * CODE-OCEC-09-009. All rights reserved.
  8. *
  9. * This file is part of SLURM, a resource management program.
  10. * For details, see <http://www.schedmd.com/slurmdocs/>.
  11. * Please also read the included file: DISCLAIMER.
  12. *
  13. * SLURM is free software; you can redistribute it and/or modify it under
  14. * the terms of the GNU General Public License as published by the Free
  15. * Software Foundation; either version 2 of the License, or (at your option)
  16. * any later version.
  17. *
  18. * In addition, as a special exception, the copyright holders give permission
  19. * to link the code of portions of this program with the OpenSSL library under
  20. * certain conditions as described in each individual source file, and
  21. * distribute linked combinations including the two. You must obey the GNU
  22. * General Public License in all respects for all of the code used other than
  23. * OpenSSL. If you modify file(s) with this exception, you may extend this
  24. * exception to your version of the file(s), but you are not obligated to do
  25. * so. If you do not wish to do so, delete this exception statement from your
  26. * version. If you delete this exception statement from all source files in
  27. * the program, then also delete it here.
  28. *
  29. * SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
  30. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  31. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  32. * details.
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with SLURM; if not, write to the Free Software Foundation, Inc.,
  36. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  37. \*****************************************************************************/
  38. #include "src/common/gres.h"
  39. #include "src/common/macros.h"
  40. #include "src/common/pack.h"
  41. #include "src/common/slurmdbd_defs.h"
  42. #include "src/common/slurm_accounting_storage.h"
  43. #include "src/common/slurm_jobacct_gather.h"
  44. #include "src/common/slurm_protocol_api.h"
  45. #include "src/common/slurm_protocol_defs.h"
  46. #include "src/common/uid.h"
  47. #include "src/common/xstring.h"
  48. #include "src/slurmdbd/read_config.h"
  49. #include "src/slurmdbd/rpc_mgr.h"
  50. #include "src/slurmdbd/proc_req.h"
  51. #include "src/slurmctld/slurmctld.h"
  52. /* Local functions */
  53. static int _add_accounts(slurmdbd_conn_t *slurmdbd_conn,
  54. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  55. static int _add_account_coords(slurmdbd_conn_t *slurmdbd_conn,
  56. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  57. static int _add_assocs(slurmdbd_conn_t *slurmdbd_conn,
  58. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  59. static int _add_clusters(slurmdbd_conn_t *slurmdbd_conn,
  60. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  61. static int _add_qos(slurmdbd_conn_t *slurmdbd_conn,
  62. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  63. static int _add_users(slurmdbd_conn_t *slurmdbd_conn,
  64. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  65. static int _add_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  66. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  67. static int _add_reservation(slurmdbd_conn_t *slurmdbd_conn,
  68. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  69. static int _archive_dump(slurmdbd_conn_t *slurmdbd_conn,
  70. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  71. static int _archive_load(slurmdbd_conn_t *slurmdbd_conn,
  72. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  73. static int _cluster_cpus(slurmdbd_conn_t *slurmdbd_conn,
  74. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  75. static int _get_accounts(slurmdbd_conn_t *slurmdbd_conn,
  76. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  77. static int _get_assocs(slurmdbd_conn_t *slurmdbd_conn,
  78. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  79. static int _get_clusters(slurmdbd_conn_t *slurmdbd_conn,
  80. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  81. static int _get_config(slurmdbd_conn_t *slurmdbd_conn,
  82. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  83. static int _get_events(slurmdbd_conn_t *slurmdbd_conn,
  84. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  85. static int _get_jobs_cond(slurmdbd_conn_t *slurmdbd_conn,
  86. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  87. static int _get_probs(slurmdbd_conn_t *slurmdbd_conn,
  88. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  89. static int _get_qos(slurmdbd_conn_t *slurmdbd_conn,
  90. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  91. static int _get_txn(slurmdbd_conn_t *slurmdbd_conn,
  92. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  93. static int _get_usage(uint16_t type, slurmdbd_conn_t *slurmdbd_conn,
  94. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  95. static int _get_users(slurmdbd_conn_t *slurmdbd_conn,
  96. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  97. static int _get_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  98. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  99. static int _get_reservations(slurmdbd_conn_t *slurmdbd_conn,
  100. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  101. static int _flush_jobs(slurmdbd_conn_t *slurmdbd_conn,
  102. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  103. static int _init_conn(slurmdbd_conn_t *slurmdbd_conn,
  104. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  105. static int _fini_conn(slurmdbd_conn_t *slurmdbd_conn, Buf in_buffer,
  106. Buf *out_buffer);
  107. static int _job_complete(slurmdbd_conn_t *slurmdbd_conn,
  108. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  109. static int _job_start(slurmdbd_conn_t *slurmdbd_conn,
  110. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  111. static int _job_suspend(slurmdbd_conn_t *slurmdbd_conn,
  112. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  113. static int _modify_accounts(slurmdbd_conn_t *slurmdbd_conn,
  114. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  115. static int _modify_assocs(slurmdbd_conn_t *slurmdbd_conn,
  116. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  117. static int _modify_clusters(slurmdbd_conn_t *slurmdbd_conn,
  118. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  119. static int _modify_job(slurmdbd_conn_t *slurmdbd_conn,
  120. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  121. static int _modify_qos(slurmdbd_conn_t *slurmdbd_conn,
  122. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  123. static int _modify_users(slurmdbd_conn_t *slurmdbd_conn,
  124. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  125. static int _modify_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  126. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  127. static int _modify_reservation(slurmdbd_conn_t *slurmdbd_conn,
  128. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  129. static int _node_state(slurmdbd_conn_t *slurmdbd_conn,
  130. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  131. static char *_node_state_string(uint16_t node_state);
  132. static void _process_job_start(slurmdbd_conn_t *slurmdbd_conn,
  133. dbd_job_start_msg_t *job_start_msg,
  134. dbd_id_rc_msg_t *id_rc_msg);
  135. static int _register_ctld(slurmdbd_conn_t *slurmdbd_conn,
  136. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  137. static int _remove_accounts(slurmdbd_conn_t *slurmdbd_conn,
  138. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  139. static int _remove_account_coords(slurmdbd_conn_t *slurmdbd_conn,
  140. Buf in_buffer, Buf *out_buffer,
  141. uint32_t *uid);
  142. static int _remove_assocs(slurmdbd_conn_t *slurmdbd_conn,
  143. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  144. static int _remove_clusters(slurmdbd_conn_t *slurmdbd_conn,
  145. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  146. static int _remove_qos(slurmdbd_conn_t *slurmdbd_conn,
  147. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  148. static int _remove_users(slurmdbd_conn_t *slurmdbd_conn,
  149. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  150. static int _remove_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  151. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  152. static int _remove_reservation(slurmdbd_conn_t *slurmdbd_conn,
  153. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  154. static int _roll_usage(slurmdbd_conn_t *slurmdbd_conn,
  155. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  156. static int _send_mult_job_start(slurmdbd_conn_t *slurmdbd_conn,
  157. Buf in_buffer, Buf *out_buffer,
  158. uint32_t *uid);
  159. static int _send_mult_msg(slurmdbd_conn_t *slurmdbd_conn,
  160. Buf in_buffer, Buf *out_buffer,
  161. uint32_t *uid);
  162. static int _step_complete(slurmdbd_conn_t *slurmdbd_conn,
  163. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  164. static int _step_start(slurmdbd_conn_t *slurmdbd_conn,
  165. Buf in_buffer, Buf *out_buffer, uint32_t *uid);
  166. /* Process an incoming RPC
  167. * slurmdbd_conn IN/OUT - in will that the newsockfd set before
  168. * calling and db_conn and rpc_version will be filled in with the init.
  169. * msg IN - incoming message
  170. * msg_size IN - size of msg in bytes
  171. * first IN - set if first message received on the socket
  172. * buffer OUT - outgoing response, must be freed by caller
  173. * uid IN/OUT - user ID who initiated the RPC
  174. * RET SLURM_SUCCESS or error code */
  175. extern int
  176. proc_req(slurmdbd_conn_t *slurmdbd_conn,
  177. char *msg, uint32_t msg_size,
  178. bool first, Buf *out_buffer, uint32_t *uid)
  179. {
  180. int rc = SLURM_SUCCESS;
  181. uint16_t msg_type;
  182. Buf in_buffer;
  183. char *comment = NULL;
  184. in_buffer = create_buf(msg, msg_size); /* puts msg into buffer struct */
  185. safe_unpack16(&msg_type, in_buffer);
  186. errno = 0; /* clear errno */
  187. if (first && (msg_type != DBD_INIT)) {
  188. comment = "Initial RPC not DBD_INIT";
  189. error("CONN:%u %s type (%d)",
  190. slurmdbd_conn->newsockfd, comment, msg_type);
  191. rc = EINVAL;
  192. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  193. rc, comment, DBD_INIT);
  194. } else {
  195. switch (msg_type) {
  196. case DBD_ADD_ACCOUNTS:
  197. rc = _add_accounts(slurmdbd_conn,
  198. in_buffer, out_buffer, uid);
  199. break;
  200. case DBD_ADD_ACCOUNT_COORDS:
  201. rc = _add_account_coords(slurmdbd_conn,
  202. in_buffer, out_buffer, uid);
  203. break;
  204. case DBD_ADD_ASSOCS:
  205. rc = _add_assocs(slurmdbd_conn,
  206. in_buffer, out_buffer, uid);
  207. break;
  208. case DBD_ADD_CLUSTERS:
  209. rc = _add_clusters(slurmdbd_conn,
  210. in_buffer, out_buffer, uid);
  211. break;
  212. case DBD_ADD_QOS:
  213. rc = _add_qos(slurmdbd_conn,
  214. in_buffer, out_buffer, uid);
  215. break;
  216. case DBD_ADD_USERS:
  217. rc = _add_users(slurmdbd_conn,
  218. in_buffer, out_buffer, uid);
  219. break;
  220. case DBD_ADD_WCKEYS:
  221. rc = _add_wckeys(slurmdbd_conn,
  222. in_buffer, out_buffer, uid);
  223. break;
  224. case DBD_ADD_RESV:
  225. rc = _add_reservation(slurmdbd_conn,
  226. in_buffer, out_buffer, uid);
  227. break;
  228. case DBD_ARCHIVE_DUMP:
  229. rc = _archive_dump(slurmdbd_conn,
  230. in_buffer, out_buffer, uid);
  231. break;
  232. case DBD_ARCHIVE_LOAD:
  233. rc = _archive_load(slurmdbd_conn,
  234. in_buffer, out_buffer, uid);
  235. break;
  236. case DBD_CLUSTER_CPUS:
  237. rc = _cluster_cpus(slurmdbd_conn,
  238. in_buffer, out_buffer, uid);
  239. break;
  240. case DBD_GET_ACCOUNTS:
  241. rc = _get_accounts(slurmdbd_conn,
  242. in_buffer, out_buffer, uid);
  243. break;
  244. case DBD_GET_ASSOCS:
  245. rc = _get_assocs(slurmdbd_conn,
  246. in_buffer, out_buffer, uid);
  247. break;
  248. case DBD_GET_ASSOC_USAGE:
  249. case DBD_GET_CLUSTER_USAGE:
  250. rc = _get_usage(msg_type, slurmdbd_conn,
  251. in_buffer, out_buffer, uid);
  252. break;
  253. case DBD_GET_CLUSTERS:
  254. rc = _get_clusters(slurmdbd_conn,
  255. in_buffer, out_buffer, uid);
  256. break;
  257. case DBD_GET_CONFIG:
  258. rc = _get_config(slurmdbd_conn,
  259. in_buffer, out_buffer, uid);
  260. break;
  261. case DBD_GET_EVENTS:
  262. rc = _get_events(slurmdbd_conn,
  263. in_buffer, out_buffer, uid);
  264. break;
  265. case DBD_GET_JOBS_COND:
  266. rc = _get_jobs_cond(slurmdbd_conn,
  267. in_buffer, out_buffer, uid);
  268. break;
  269. case DBD_GET_PROBS:
  270. rc = _get_probs(slurmdbd_conn,
  271. in_buffer, out_buffer, uid);
  272. break;
  273. case DBD_GET_QOS:
  274. rc = _get_qos(slurmdbd_conn,
  275. in_buffer, out_buffer, uid);
  276. break;
  277. case DBD_GET_TXN:
  278. rc = _get_txn(slurmdbd_conn,
  279. in_buffer, out_buffer, uid);
  280. break;
  281. case DBD_GET_WCKEYS:
  282. rc = _get_wckeys(slurmdbd_conn,
  283. in_buffer, out_buffer, uid);
  284. break;
  285. case DBD_GET_RESVS:
  286. rc = _get_reservations(slurmdbd_conn,
  287. in_buffer, out_buffer, uid);
  288. break;
  289. case DBD_GET_USERS:
  290. rc = _get_users(slurmdbd_conn,
  291. in_buffer, out_buffer, uid);
  292. break;
  293. case DBD_FLUSH_JOBS:
  294. rc = _flush_jobs(slurmdbd_conn,
  295. in_buffer, out_buffer, uid);
  296. break;
  297. case DBD_INIT:
  298. if (first)
  299. rc = _init_conn(slurmdbd_conn,
  300. in_buffer, out_buffer, uid);
  301. else {
  302. comment = "DBD_INIT sent after connection established";
  303. error("CONN:%u %s",
  304. slurmdbd_conn->newsockfd, comment);
  305. rc = EINVAL;
  306. *out_buffer = make_dbd_rc_msg(
  307. slurmdbd_conn->rpc_version, rc, comment,
  308. DBD_INIT);
  309. }
  310. break;
  311. case DBD_FINI:
  312. rc = _fini_conn(slurmdbd_conn, in_buffer, out_buffer);
  313. break;
  314. case DBD_JOB_COMPLETE:
  315. rc = _job_complete(slurmdbd_conn,
  316. in_buffer, out_buffer, uid);
  317. break;
  318. case DBD_JOB_START:
  319. rc = _job_start(slurmdbd_conn,
  320. in_buffer, out_buffer, uid);
  321. break;
  322. case DBD_JOB_SUSPEND:
  323. rc = _job_suspend(slurmdbd_conn,
  324. in_buffer, out_buffer, uid);
  325. break;
  326. case DBD_MODIFY_ACCOUNTS:
  327. rc = _modify_accounts(slurmdbd_conn,
  328. in_buffer, out_buffer, uid);
  329. break;
  330. case DBD_MODIFY_ASSOCS:
  331. rc = _modify_assocs(slurmdbd_conn,
  332. in_buffer, out_buffer, uid);
  333. break;
  334. case DBD_MODIFY_CLUSTERS:
  335. rc = _modify_clusters(slurmdbd_conn,
  336. in_buffer, out_buffer, uid);
  337. break;
  338. case DBD_MODIFY_JOB:
  339. rc = _modify_job(slurmdbd_conn,
  340. in_buffer, out_buffer, uid);
  341. break;
  342. case DBD_MODIFY_QOS:
  343. rc = _modify_qos(slurmdbd_conn,
  344. in_buffer, out_buffer, uid);
  345. break;
  346. case DBD_MODIFY_USERS:
  347. rc = _modify_users(slurmdbd_conn,
  348. in_buffer, out_buffer, uid);
  349. break;
  350. case DBD_MODIFY_WCKEYS:
  351. rc = _modify_wckeys(slurmdbd_conn,
  352. in_buffer, out_buffer, uid);
  353. break;
  354. case DBD_MODIFY_RESV:
  355. rc = _modify_reservation(slurmdbd_conn,
  356. in_buffer, out_buffer, uid);
  357. break;
  358. case DBD_NODE_STATE:
  359. rc = _node_state(slurmdbd_conn,
  360. in_buffer, out_buffer, uid);
  361. break;
  362. case DBD_REGISTER_CTLD:
  363. rc = _register_ctld(slurmdbd_conn, in_buffer,
  364. out_buffer, uid);
  365. break;
  366. case DBD_REMOVE_ACCOUNTS:
  367. rc = _remove_accounts(slurmdbd_conn,
  368. in_buffer, out_buffer, uid);
  369. break;
  370. case DBD_REMOVE_ACCOUNT_COORDS:
  371. rc = _remove_account_coords(slurmdbd_conn,
  372. in_buffer, out_buffer, uid);
  373. break;
  374. case DBD_REMOVE_ASSOCS:
  375. rc = _remove_assocs(slurmdbd_conn,
  376. in_buffer, out_buffer, uid);
  377. break;
  378. case DBD_REMOVE_CLUSTERS:
  379. rc = _remove_clusters(slurmdbd_conn,
  380. in_buffer, out_buffer, uid);
  381. break;
  382. case DBD_REMOVE_QOS:
  383. rc = _remove_qos(slurmdbd_conn,
  384. in_buffer, out_buffer, uid);
  385. break;
  386. case DBD_REMOVE_USERS:
  387. rc = _remove_users(slurmdbd_conn,
  388. in_buffer, out_buffer, uid);
  389. break;
  390. case DBD_REMOVE_WCKEYS:
  391. rc = _remove_wckeys(slurmdbd_conn,
  392. in_buffer, out_buffer, uid);
  393. break;
  394. case DBD_REMOVE_RESV:
  395. rc = _remove_reservation(slurmdbd_conn,
  396. in_buffer, out_buffer, uid);
  397. break;
  398. case DBD_ROLL_USAGE:
  399. rc = _roll_usage(slurmdbd_conn,
  400. in_buffer, out_buffer, uid);
  401. break;
  402. case DBD_SEND_MULT_JOB_START:
  403. rc = _send_mult_job_start(slurmdbd_conn,
  404. in_buffer, out_buffer, uid);
  405. break;
  406. case DBD_SEND_MULT_MSG:
  407. rc = _send_mult_msg(slurmdbd_conn,
  408. in_buffer, out_buffer, uid);
  409. break;
  410. case DBD_STEP_COMPLETE:
  411. rc = _step_complete(slurmdbd_conn,
  412. in_buffer, out_buffer, uid);
  413. break;
  414. case DBD_STEP_START:
  415. rc = _step_start(slurmdbd_conn,
  416. in_buffer, out_buffer, uid);
  417. break;
  418. case DBD_GET_JOBS:
  419. /* Defunct RPC */
  420. default:
  421. comment = "Invalid RPC";
  422. error("CONN:%u %s msg_type=%d",
  423. slurmdbd_conn->newsockfd, comment, msg_type);
  424. rc = EINVAL;
  425. *out_buffer = make_dbd_rc_msg(
  426. slurmdbd_conn->rpc_version, rc, comment, 0);
  427. break;
  428. }
  429. if (rc == ESLURM_ACCESS_DENIED)
  430. error("CONN:%u Security violation, %s",
  431. slurmdbd_conn->newsockfd,
  432. slurmdbd_msg_type_2_str(msg_type, 1));
  433. }
  434. xfer_buf_data(in_buffer); /* delete in_buffer struct without
  435. * xfree of msg */
  436. return rc;
  437. unpack_error:
  438. free_buf(in_buffer);
  439. return SLURM_ERROR;
  440. }
  441. /* replace \" with \` return is the same as what is given */
  442. static char * _replace_double_quotes(char *option)
  443. {
  444. int i=0;
  445. if (!option)
  446. return NULL;
  447. while (option[i]) {
  448. if (option[i] == '\"')
  449. option[i] = '`';
  450. i++;
  451. }
  452. return option;
  453. }
  454. static int _add_accounts(slurmdbd_conn_t *slurmdbd_conn,
  455. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  456. {
  457. int rc = SLURM_SUCCESS;
  458. dbd_list_msg_t *get_msg = NULL;
  459. char *comment = NULL;
  460. debug2("DBD_ADD_ACCOUNTS: called");
  461. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  462. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  463. < SLURMDB_ADMIN_OPERATOR) {
  464. slurmdb_user_rec_t user;
  465. memset(&user, 0, sizeof(slurmdb_user_rec_t));
  466. user.uid = *uid;
  467. if (assoc_mgr_fill_in_user(
  468. slurmdbd_conn->db_conn, &user, 1, NULL)
  469. != SLURM_SUCCESS) {
  470. comment = "Your user has not been added to the accounting system yet.";
  471. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  472. rc = SLURM_ERROR;
  473. goto end_it;
  474. }
  475. if (!user.coord_accts || !list_count(user.coord_accts)) {
  476. comment = "Your user doesn't have privilege to preform this action";
  477. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  478. rc = ESLURM_ACCESS_DENIED;
  479. goto end_it;
  480. }
  481. /* If the user is a coord of any acct they can add
  482. * accounts they are only able to make associations to
  483. * these accounts if they are coordinators of the
  484. * parent they are trying to add to
  485. */
  486. }
  487. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  488. DBD_ADD_ACCOUNTS, in_buffer) !=
  489. SLURM_SUCCESS) {
  490. comment = "Failed to unpack DBD_ADD_ACCOUNTS message";
  491. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  492. rc = SLURM_ERROR;
  493. goto end_it;
  494. }
  495. rc = acct_storage_g_add_accounts(slurmdbd_conn->db_conn, *uid,
  496. get_msg->my_list);
  497. end_it:
  498. slurmdbd_free_list_msg(get_msg);
  499. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  500. rc, comment, DBD_ADD_ACCOUNTS);
  501. return rc;
  502. }
  503. static int _add_account_coords(slurmdbd_conn_t *slurmdbd_conn,
  504. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  505. {
  506. int rc = SLURM_SUCCESS;
  507. dbd_acct_coord_msg_t *get_msg = NULL;
  508. char *comment = NULL;
  509. if (slurmdbd_unpack_acct_coord_msg(
  510. &get_msg, slurmdbd_conn->rpc_version, in_buffer)
  511. != SLURM_SUCCESS) {
  512. comment = "Failed to unpack DBD_ADD_ACCOUNT_COORDS message";
  513. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  514. rc = SLURM_ERROR;
  515. goto end_it;
  516. }
  517. debug2("DBD_ADD_ACCOUNT_COORDS: called");
  518. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  519. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  520. < SLURMDB_ADMIN_OPERATOR) {
  521. ListIterator itr = NULL;
  522. ListIterator itr2 = NULL;
  523. slurmdb_user_rec_t user;
  524. slurmdb_coord_rec_t *coord = NULL;
  525. char *acct = NULL;
  526. int bad = 0;
  527. memset(&user, 0, sizeof(slurmdb_user_rec_t));
  528. user.uid = *uid;
  529. if (assoc_mgr_fill_in_user(
  530. slurmdbd_conn->db_conn, &user, 1, NULL)
  531. != SLURM_SUCCESS) {
  532. comment = "Your user has not been added to the accounting system yet.";
  533. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  534. rc = SLURM_ERROR;
  535. goto end_it;
  536. }
  537. if (!user.coord_accts || !list_count(user.coord_accts)) {
  538. comment = "Your user doesn't have privilege to preform this action";
  539. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  540. rc = ESLURM_ACCESS_DENIED;
  541. goto end_it;
  542. }
  543. itr = list_iterator_create(get_msg->acct_list);
  544. itr2 = list_iterator_create(user.coord_accts);
  545. while ((acct = list_next(itr))) {
  546. while ((coord = list_next(itr2))) {
  547. if (!strcasecmp(coord->name, acct))
  548. break;
  549. }
  550. if (!coord) {
  551. bad = 1;
  552. break;
  553. }
  554. list_iterator_reset(itr2);
  555. }
  556. list_iterator_destroy(itr2);
  557. list_iterator_destroy(itr);
  558. if (bad) {
  559. comment = "Your user doesn't have privilege to preform this action";
  560. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  561. rc = ESLURM_ACCESS_DENIED;
  562. goto end_it;
  563. }
  564. }
  565. rc = acct_storage_g_add_coord(slurmdbd_conn->db_conn, *uid,
  566. get_msg->acct_list, get_msg->cond);
  567. end_it:
  568. slurmdbd_free_acct_coord_msg(get_msg);
  569. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  570. rc, comment, DBD_ADD_ACCOUNT_COORDS);
  571. return rc;
  572. }
  573. static int _add_assocs(slurmdbd_conn_t *slurmdbd_conn,
  574. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  575. {
  576. int rc = SLURM_SUCCESS;
  577. dbd_list_msg_t *get_msg = NULL;
  578. char *comment = NULL;
  579. debug2("DBD_ADD_ASSOCS: called");
  580. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  581. DBD_ADD_ASSOCS, in_buffer) !=
  582. SLURM_SUCCESS) {
  583. comment = "Failed to unpack DBD_ADD_ASSOCS message";
  584. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  585. rc = SLURM_ERROR;
  586. goto end_it;
  587. }
  588. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  589. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  590. < SLURMDB_ADMIN_OPERATOR) {
  591. ListIterator itr = NULL;
  592. ListIterator itr2 = NULL;
  593. slurmdb_user_rec_t user;
  594. slurmdb_coord_rec_t *coord = NULL;
  595. slurmdb_association_rec_t *object = NULL;
  596. memset(&user, 0, sizeof(slurmdb_user_rec_t));
  597. user.uid = *uid;
  598. if (assoc_mgr_fill_in_user(
  599. slurmdbd_conn->db_conn, &user, 1, NULL)
  600. != SLURM_SUCCESS) {
  601. comment = "Your user has not been added to the accounting system yet.";
  602. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  603. rc = SLURM_ERROR;
  604. goto end_it;
  605. }
  606. if (!user.coord_accts || !list_count(user.coord_accts)) {
  607. comment = "Your user doesn't have privilege to preform this action";
  608. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  609. rc = ESLURM_ACCESS_DENIED;
  610. goto end_it;
  611. }
  612. itr = list_iterator_create(get_msg->my_list);
  613. itr2 = list_iterator_create(user.coord_accts);
  614. while ((object = list_next(itr))) {
  615. char *account = "root";
  616. if (object->user)
  617. account = object->acct;
  618. else if (object->parent_acct)
  619. account = object->parent_acct;
  620. list_iterator_reset(itr2);
  621. while ((coord = list_next(itr2))) {
  622. if (!strcasecmp(coord->name, account))
  623. break;
  624. }
  625. if (!coord)
  626. break;
  627. }
  628. list_iterator_destroy(itr2);
  629. list_iterator_destroy(itr);
  630. if (!coord) {
  631. comment = "Your user doesn't have privilege to preform this action";
  632. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  633. rc = ESLURM_ACCESS_DENIED;
  634. goto end_it;
  635. }
  636. }
  637. rc = acct_storage_g_add_associations(slurmdbd_conn->db_conn, *uid,
  638. get_msg->my_list);
  639. end_it:
  640. slurmdbd_free_list_msg(get_msg);
  641. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  642. rc, comment, DBD_ADD_ASSOCS);
  643. return rc;
  644. }
  645. static int _add_clusters(slurmdbd_conn_t *slurmdbd_conn,
  646. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  647. {
  648. int rc = SLURM_SUCCESS;
  649. dbd_list_msg_t *get_msg = NULL;
  650. char *comment = NULL;
  651. debug2("DBD_ADD_CLUSTERS: called");
  652. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  653. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  654. < SLURMDB_ADMIN_SUPER_USER) {
  655. comment = "Your user doesn't have privilege to preform this action";
  656. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  657. rc = ESLURM_ACCESS_DENIED;
  658. goto end_it;
  659. }
  660. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  661. DBD_ADD_CLUSTERS, in_buffer) !=
  662. SLURM_SUCCESS) {
  663. comment = "Failed to unpack DBD_ADD_CLUSTERS message";
  664. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  665. rc = SLURM_ERROR;
  666. goto end_it;
  667. }
  668. rc = acct_storage_g_add_clusters(slurmdbd_conn->db_conn, *uid,
  669. get_msg->my_list);
  670. if (rc != SLURM_SUCCESS)
  671. comment = "Failed to add cluster.";
  672. end_it:
  673. slurmdbd_free_list_msg(get_msg);
  674. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  675. rc, comment, DBD_ADD_CLUSTERS);
  676. return rc;
  677. }
  678. static int _add_qos(slurmdbd_conn_t *slurmdbd_conn,
  679. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  680. {
  681. int rc = SLURM_SUCCESS;
  682. dbd_list_msg_t *get_msg = NULL;
  683. char *comment = NULL;
  684. debug2("DBD_ADD_QOS: called");
  685. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  686. && (assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  687. < SLURMDB_ADMIN_SUPER_USER)) {
  688. comment = "Your user doesn't have privilege to preform this action";
  689. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  690. rc = ESLURM_ACCESS_DENIED;
  691. goto end_it;
  692. }
  693. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  694. DBD_ADD_QOS, in_buffer) !=
  695. SLURM_SUCCESS) {
  696. comment = "Failed to unpack DBD_ADD_QOS message";
  697. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  698. rc = SLURM_ERROR;
  699. goto end_it;
  700. }
  701. rc = acct_storage_g_add_qos(slurmdbd_conn->db_conn, *uid,
  702. get_msg->my_list);
  703. if (rc != SLURM_SUCCESS)
  704. comment = "Failed to add qos.";
  705. end_it:
  706. slurmdbd_free_list_msg(get_msg);
  707. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  708. rc, comment, DBD_ADD_QOS);
  709. return rc;
  710. }
  711. static int _add_users(slurmdbd_conn_t *slurmdbd_conn,
  712. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  713. {
  714. int rc = SLURM_SUCCESS;
  715. dbd_list_msg_t *get_msg = NULL;
  716. char *comment = NULL;
  717. debug2("DBD_ADD_USERS: called");
  718. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  719. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  720. < SLURMDB_ADMIN_OPERATOR) {
  721. slurmdb_user_rec_t user;
  722. memset(&user, 0, sizeof(slurmdb_user_rec_t));
  723. user.uid = *uid;
  724. if (assoc_mgr_fill_in_user(
  725. slurmdbd_conn->db_conn, &user, 1, NULL)
  726. != SLURM_SUCCESS) {
  727. comment = "Your user has not been added to the accounting system yet.";
  728. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  729. rc = SLURM_ERROR;
  730. goto end_it;
  731. }
  732. if (!user.coord_accts || !list_count(user.coord_accts)) {
  733. comment = "Your user doesn't have privilege to preform this action";
  734. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  735. rc = ESLURM_ACCESS_DENIED;
  736. goto end_it;
  737. }
  738. /* If the user is a coord of any acct they can add
  739. * users they are only able to make associations to
  740. * these users if they are coordinators of the
  741. * account they are trying to add to
  742. */
  743. }
  744. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  745. DBD_ADD_USERS, in_buffer) !=
  746. SLURM_SUCCESS) {
  747. comment = "Failed to unpack DBD_ADD_USERS message";
  748. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  749. rc = SLURM_ERROR;
  750. goto end_it;
  751. }
  752. rc = acct_storage_g_add_users(slurmdbd_conn->db_conn, *uid,
  753. get_msg->my_list);
  754. end_it:
  755. slurmdbd_free_list_msg(get_msg);
  756. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  757. rc, comment, DBD_ADD_USERS);
  758. return rc;
  759. }
  760. static int _add_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  761. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  762. {
  763. int rc = SLURM_SUCCESS;
  764. dbd_list_msg_t *get_msg = NULL;
  765. char *comment = NULL;
  766. debug2("DBD_ADD_WCKEYS: called");
  767. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  768. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  769. < SLURMDB_ADMIN_SUPER_USER) {
  770. comment = "Your user doesn't have privilege to preform this action";
  771. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  772. rc = ESLURM_ACCESS_DENIED;
  773. goto end_it;
  774. }
  775. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  776. DBD_ADD_WCKEYS, in_buffer) !=
  777. SLURM_SUCCESS) {
  778. comment = "Failed to unpack DBD_ADD_WCKEYS message";
  779. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  780. rc = SLURM_ERROR;
  781. goto end_it;
  782. }
  783. rc = acct_storage_g_add_wckeys(slurmdbd_conn->db_conn, *uid,
  784. get_msg->my_list);
  785. end_it:
  786. slurmdbd_free_list_msg(get_msg);
  787. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  788. rc, comment, DBD_ADD_WCKEYS);
  789. return rc;
  790. }
  791. static int _add_reservation(slurmdbd_conn_t *slurmdbd_conn,
  792. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  793. {
  794. int rc = SLURM_SUCCESS;
  795. dbd_rec_msg_t *rec_msg = NULL;
  796. char *comment = NULL;
  797. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)) {
  798. comment = "DBD_ADD_RESV message from invalid uid";
  799. error("DBD_ADD_RESV message from invalid uid %u", *uid);
  800. rc = ESLURM_ACCESS_DENIED;
  801. goto end_it;
  802. }
  803. if (slurmdbd_unpack_rec_msg(&rec_msg, slurmdbd_conn->rpc_version,
  804. DBD_ADD_RESV, in_buffer) != SLURM_SUCCESS) {
  805. comment = "Failed to unpack DBD_ADD_RESV message";
  806. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  807. rc = SLURM_ERROR;
  808. goto end_it;
  809. }
  810. debug2("DBD_ADD_RESV: called");
  811. rc = acct_storage_g_add_reservation(slurmdbd_conn->db_conn,
  812. rec_msg->rec);
  813. end_it:
  814. slurmdbd_free_rec_msg(rec_msg, DBD_ADD_RESV);
  815. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  816. rc, comment, DBD_ADD_RESV);
  817. return rc;
  818. }
  819. static int _archive_dump(slurmdbd_conn_t *slurmdbd_conn,
  820. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  821. {
  822. int rc = SLURM_SUCCESS;
  823. dbd_cond_msg_t *get_msg = NULL;
  824. char *comment = "SUCCESS";
  825. slurmdb_archive_cond_t *arch_cond = NULL;
  826. debug2("DBD_ARCHIVE_DUMP: called");
  827. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  828. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  829. < SLURMDB_ADMIN_SUPER_USER) {
  830. comment = "Your user doesn't have privilege to preform this action";
  831. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  832. rc = ESLURM_ACCESS_DENIED;
  833. goto end_it;
  834. }
  835. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  836. DBD_ARCHIVE_DUMP, in_buffer) !=
  837. SLURM_SUCCESS) {
  838. comment = "Failed to unpack DBD_ARCHIVE_DUMP message";
  839. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  840. rc = SLURM_ERROR;
  841. goto end_it;
  842. }
  843. arch_cond = (slurmdb_archive_cond_t *)get_msg->cond;
  844. /* set up some defaults */
  845. if (!arch_cond->archive_dir)
  846. arch_cond->archive_dir = xstrdup(slurmdbd_conf->archive_dir);
  847. if (!arch_cond->archive_script)
  848. arch_cond->archive_script =
  849. xstrdup(slurmdbd_conf->archive_script);
  850. if (arch_cond->purge_event == NO_VAL)
  851. arch_cond->purge_event = slurmdbd_conf->purge_event;
  852. if (arch_cond->purge_job == NO_VAL)
  853. arch_cond->purge_job = slurmdbd_conf->purge_job;
  854. if (arch_cond->purge_step == NO_VAL)
  855. arch_cond->purge_step = slurmdbd_conf->purge_step;
  856. if (arch_cond->purge_suspend == NO_VAL)
  857. arch_cond->purge_suspend = slurmdbd_conf->purge_suspend;
  858. rc = jobacct_storage_g_archive(slurmdbd_conn->db_conn, arch_cond);
  859. if (rc != SLURM_SUCCESS) {
  860. if (errno == EACCES)
  861. comment = "Problem accessing file.";
  862. else
  863. comment = "Error with request.";
  864. }
  865. end_it:
  866. slurmdbd_free_cond_msg(get_msg, DBD_ARCHIVE_DUMP);
  867. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  868. rc, comment, DBD_ARCHIVE_DUMP);
  869. return rc;
  870. }
  871. static int _archive_load(slurmdbd_conn_t *slurmdbd_conn,
  872. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  873. {
  874. int rc = SLURM_SUCCESS;
  875. slurmdb_archive_rec_t *arch_rec = NULL;
  876. char *comment = "SUCCESS";
  877. debug2("DBD_ARCHIVE_LOAD: called");
  878. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  879. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  880. < SLURMDB_ADMIN_SUPER_USER) {
  881. comment = "Your user doesn't have privilege to preform this action";
  882. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  883. rc = ESLURM_ACCESS_DENIED;
  884. goto end_it;
  885. }
  886. if (slurmdb_unpack_archive_rec((void *)&arch_rec,
  887. slurmdbd_conn->rpc_version,
  888. in_buffer) != SLURM_SUCCESS) {
  889. comment = "Failed to unpack DBD_ARCHIVE_LOAD message";
  890. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  891. rc = SLURM_ERROR;
  892. goto end_it;
  893. }
  894. rc = jobacct_storage_g_archive_load(slurmdbd_conn->db_conn, arch_rec);
  895. if (rc == ENOENT)
  896. comment = "No archive file given to recover.";
  897. else if (rc != SLURM_SUCCESS)
  898. comment = "Error with request.";
  899. end_it:
  900. slurmdb_destroy_archive_rec(arch_rec);
  901. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  902. rc, comment, DBD_ARCHIVE_LOAD);
  903. return rc;
  904. }
  905. static int _cluster_cpus(slurmdbd_conn_t *slurmdbd_conn,
  906. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  907. {
  908. dbd_cluster_cpus_msg_t *cluster_cpus_msg = NULL;
  909. int rc = SLURM_SUCCESS;
  910. char *comment = NULL;
  911. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)) {
  912. comment = "DBD_CLUSTER_CPUS message from invalid uid";
  913. error("DBD_CLUSTER_CPUS message from invalid uid %u", *uid);
  914. rc = ESLURM_ACCESS_DENIED;
  915. goto end_it;
  916. }
  917. if (slurmdbd_unpack_cluster_cpus_msg(&cluster_cpus_msg,
  918. slurmdbd_conn->rpc_version,
  919. in_buffer) !=
  920. SLURM_SUCCESS) {
  921. comment = "Failed to unpack DBD_CLUSTER_CPUS message";
  922. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  923. rc = SLURM_ERROR;
  924. goto end_it;
  925. }
  926. debug2("DBD_CLUSTER_CPUS: called for %s(%u)",
  927. slurmdbd_conn->cluster_name,
  928. cluster_cpus_msg->cpu_count);
  929. rc = clusteracct_storage_g_cluster_cpus(
  930. slurmdbd_conn->db_conn,
  931. cluster_cpus_msg->cluster_nodes,
  932. cluster_cpus_msg->cpu_count,
  933. cluster_cpus_msg->event_time);
  934. if (rc == ESLURM_ACCESS_DENIED) {
  935. comment = "This cluster hasn't been added to accounting yet";
  936. rc = SLURM_ERROR;
  937. }
  938. end_it:
  939. if (rc == SLURM_SUCCESS)
  940. slurmdbd_conn->cluster_cpus = cluster_cpus_msg->cpu_count;
  941. if (!slurmdbd_conn->ctld_port) {
  942. info("DBD_CLUSTER_CPUS: cluster not registered");
  943. slurmdbd_conn->ctld_port =
  944. clusteracct_storage_g_register_disconn_ctld(
  945. slurmdbd_conn->db_conn, slurmdbd_conn->ip);
  946. }
  947. slurmdbd_free_cluster_cpus_msg(cluster_cpus_msg);
  948. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  949. rc, comment, DBD_CLUSTER_CPUS);
  950. return rc;
  951. }
  952. static int _get_accounts(slurmdbd_conn_t *slurmdbd_conn,
  953. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  954. {
  955. dbd_cond_msg_t *get_msg = NULL;
  956. dbd_list_msg_t list_msg;
  957. char *comment = NULL;
  958. int rc = SLURM_SUCCESS;
  959. debug2("DBD_GET_ACCOUNTS: called");
  960. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  961. DBD_GET_ACCOUNTS, in_buffer) !=
  962. SLURM_SUCCESS) {
  963. comment = "Failed to unpack DBD_GET_ACCOUNTS message";
  964. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  965. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  966. SLURM_ERROR, comment,
  967. DBD_GET_ACCOUNTS);
  968. return SLURM_ERROR;
  969. }
  970. list_msg.my_list = acct_storage_g_get_accounts(slurmdbd_conn->db_conn,
  971. *uid, get_msg->cond);
  972. if (!errno) {
  973. if (!list_msg.my_list)
  974. list_msg.my_list = list_create(NULL);
  975. *out_buffer = init_buf(1024);
  976. pack16((uint16_t) DBD_GOT_ACCOUNTS, *out_buffer);
  977. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  978. DBD_GOT_ACCOUNTS,
  979. *out_buffer);
  980. } else {
  981. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  982. errno, slurm_strerror(errno),
  983. DBD_GET_ACCOUNTS);
  984. rc = SLURM_ERROR;
  985. }
  986. slurmdbd_free_cond_msg(get_msg, DBD_GET_ACCOUNTS);
  987. if (list_msg.my_list)
  988. list_destroy(list_msg.my_list);
  989. return rc;
  990. }
  991. static int _get_assocs(slurmdbd_conn_t *slurmdbd_conn,
  992. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  993. {
  994. dbd_cond_msg_t *get_msg = NULL;
  995. dbd_list_msg_t list_msg;
  996. char *comment = NULL;
  997. int rc = SLURM_SUCCESS;
  998. debug2("DBD_GET_ASSOCS: called");
  999. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1000. DBD_GET_ASSOCS, in_buffer) !=
  1001. SLURM_SUCCESS) {
  1002. comment = "Failed to unpack DBD_GET_ASSOCS message";
  1003. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1004. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1005. SLURM_ERROR, comment,
  1006. DBD_GET_ASSOCS);
  1007. return SLURM_ERROR;
  1008. }
  1009. list_msg.my_list = acct_storage_g_get_associations(
  1010. slurmdbd_conn->db_conn, *uid, get_msg->cond);
  1011. if (!errno) {
  1012. if (!list_msg.my_list)
  1013. list_msg.my_list = list_create(NULL);
  1014. *out_buffer = init_buf(1024);
  1015. pack16((uint16_t) DBD_GOT_ASSOCS, *out_buffer);
  1016. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1017. DBD_GOT_ASSOCS, *out_buffer);
  1018. } else {
  1019. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1020. errno, slurm_strerror(errno),
  1021. DBD_GET_ASSOCS);
  1022. rc = SLURM_ERROR;
  1023. }
  1024. slurmdbd_free_cond_msg(get_msg, DBD_GET_ASSOCS);
  1025. if (list_msg.my_list)
  1026. list_destroy(list_msg.my_list);
  1027. return rc;
  1028. }
  1029. static int _get_clusters(slurmdbd_conn_t *slurmdbd_conn,
  1030. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1031. {
  1032. dbd_cond_msg_t *get_msg = NULL;
  1033. dbd_list_msg_t list_msg;
  1034. char *comment = NULL;
  1035. int rc = SLURM_SUCCESS;
  1036. debug2("DBD_GET_CLUSTERS: called");
  1037. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1038. DBD_GET_CLUSTERS, in_buffer) !=
  1039. SLURM_SUCCESS) {
  1040. comment = "Failed to unpack DBD_GET_CLUSTERS message";
  1041. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1042. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1043. SLURM_ERROR, comment,
  1044. DBD_GET_CLUSTERS);
  1045. return SLURM_ERROR;
  1046. }
  1047. list_msg.my_list = acct_storage_g_get_clusters(
  1048. slurmdbd_conn->db_conn, *uid, get_msg->cond);
  1049. if (!errno) {
  1050. if (!list_msg.my_list)
  1051. list_msg.my_list = list_create(NULL);
  1052. *out_buffer = init_buf(1024);
  1053. pack16((uint16_t) DBD_GOT_CLUSTERS, *out_buffer);
  1054. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1055. DBD_GOT_CLUSTERS,
  1056. *out_buffer);
  1057. } else {
  1058. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1059. errno, slurm_strerror(errno),
  1060. DBD_GET_CLUSTERS);
  1061. rc = SLURM_ERROR;
  1062. }
  1063. slurmdbd_free_cond_msg(get_msg, DBD_GET_CLUSTERS);
  1064. if (list_msg.my_list)
  1065. list_destroy(list_msg.my_list);
  1066. return rc;
  1067. }
  1068. static int _unpack_config_name(char **object, Buf buffer)
  1069. {
  1070. char *config_name;
  1071. uint32_t uint32_tmp;
  1072. safe_unpackstr_xmalloc(&config_name, &uint32_tmp, buffer);
  1073. *object = config_name;
  1074. return SLURM_SUCCESS;
  1075. unpack_error:
  1076. *object = NULL;
  1077. return SLURM_ERROR;
  1078. }
  1079. static int _get_config(slurmdbd_conn_t *slurmdbd_conn,
  1080. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1081. {
  1082. char *config_name = NULL;
  1083. dbd_list_msg_t list_msg = { NULL };
  1084. debug2("DBD_GET_CONFIG: called");
  1085. if (slurmdbd_conn->rpc_version >= 10 &&
  1086. _unpack_config_name(&config_name, in_buffer) != SLURM_SUCCESS) {
  1087. char *comment = "Failed to unpack DBD_GET_CONFIG message";
  1088. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1089. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1090. SLURM_ERROR, comment,
  1091. DBD_GET_CONFIG);
  1092. return SLURM_ERROR;
  1093. }
  1094. if (config_name == NULL ||
  1095. strcmp(config_name, "slurmdbd.conf") == 0)
  1096. list_msg.my_list = dump_config();
  1097. else if ((list_msg.my_list = acct_storage_g_get_config(
  1098. slurmdbd_conn->db_conn, config_name)) == NULL) {
  1099. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1100. errno, slurm_strerror(errno),
  1101. DBD_GET_CONFIG);
  1102. xfree(config_name);
  1103. return SLURM_ERROR;
  1104. }
  1105. *out_buffer = init_buf(1024);
  1106. pack16((uint16_t) DBD_GOT_CONFIG, *out_buffer);
  1107. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1108. DBD_GOT_CONFIG, *out_buffer);
  1109. if (list_msg.my_list)
  1110. list_destroy(list_msg.my_list);
  1111. xfree(config_name);
  1112. return SLURM_SUCCESS;
  1113. }
  1114. static int _get_events(slurmdbd_conn_t *slurmdbd_conn,
  1115. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1116. {
  1117. dbd_cond_msg_t *get_msg = NULL;
  1118. dbd_list_msg_t list_msg;
  1119. char *comment = NULL;
  1120. int rc = SLURM_SUCCESS;
  1121. debug2("DBD_GET_EVENTS: called");
  1122. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1123. DBD_GET_EVENTS, in_buffer) !=
  1124. SLURM_SUCCESS) {
  1125. comment = "Failed to unpack DBD_GET_EVENTS message";
  1126. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1127. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1128. SLURM_ERROR, comment,
  1129. DBD_GET_EVENTS);
  1130. return SLURM_ERROR;
  1131. }
  1132. list_msg.my_list = acct_storage_g_get_events(
  1133. slurmdbd_conn->db_conn, *uid, get_msg->cond);
  1134. if (!errno) {
  1135. if (!list_msg.my_list)
  1136. list_msg.my_list = list_create(NULL);
  1137. *out_buffer = init_buf(1024);
  1138. pack16((uint16_t) DBD_GOT_EVENTS, *out_buffer);
  1139. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1140. DBD_GOT_EVENTS,
  1141. *out_buffer);
  1142. } else {
  1143. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1144. errno, slurm_strerror(errno),
  1145. DBD_GET_EVENTS);
  1146. rc = SLURM_ERROR;
  1147. }
  1148. slurmdbd_free_cond_msg(get_msg, DBD_GET_EVENTS);
  1149. if (list_msg.my_list)
  1150. list_destroy(list_msg.my_list);
  1151. return rc;
  1152. }
  1153. static int _get_jobs_cond(slurmdbd_conn_t *slurmdbd_conn,
  1154. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1155. {
  1156. dbd_cond_msg_t *cond_msg = NULL;
  1157. dbd_list_msg_t list_msg;
  1158. char *comment = NULL;
  1159. int rc = SLURM_SUCCESS;
  1160. debug2("DBD_GET_JOBS_COND: called");
  1161. if (slurmdbd_unpack_cond_msg(&cond_msg, slurmdbd_conn->rpc_version,
  1162. DBD_GET_JOBS_COND, in_buffer) !=
  1163. SLURM_SUCCESS) {
  1164. comment = "Failed to unpack DBD_GET_JOBS_COND message";
  1165. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1166. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1167. SLURM_ERROR, comment,
  1168. DBD_GET_JOBS_COND);
  1169. return SLURM_ERROR;
  1170. }
  1171. list_msg.my_list = jobacct_storage_g_get_jobs_cond(
  1172. slurmdbd_conn->db_conn, *uid, cond_msg->cond);
  1173. if (!errno) {
  1174. if (!list_msg.my_list)
  1175. list_msg.my_list = list_create(NULL);
  1176. *out_buffer = init_buf(1024);
  1177. pack16((uint16_t) DBD_GOT_JOBS, *out_buffer);
  1178. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1179. DBD_GOT_JOBS, *out_buffer);
  1180. } else {
  1181. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1182. errno, slurm_strerror(errno),
  1183. DBD_GET_JOBS_COND);
  1184. rc = SLURM_ERROR;
  1185. }
  1186. slurmdbd_free_cond_msg(cond_msg, DBD_GET_JOBS_COND);
  1187. if (list_msg.my_list)
  1188. list_destroy(list_msg.my_list);
  1189. return rc;
  1190. }
  1191. static int _get_probs(slurmdbd_conn_t *slurmdbd_conn,
  1192. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1193. {
  1194. dbd_cond_msg_t *get_msg = NULL;
  1195. dbd_list_msg_t list_msg;
  1196. char *comment = NULL;
  1197. int rc = SLURM_SUCCESS;
  1198. debug2("DBD_GET_PROBS: called");
  1199. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  1200. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  1201. < SLURMDB_ADMIN_OPERATOR) {
  1202. comment = "Your user doesn't have privilege to preform this action";
  1203. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1204. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1205. ESLURM_ACCESS_DENIED,
  1206. comment, DBD_GET_PROBS);
  1207. return ESLURM_ACCESS_DENIED;
  1208. }
  1209. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1210. DBD_GET_PROBS, in_buffer) !=
  1211. SLURM_SUCCESS) {
  1212. comment = "Failed to unpack DBD_GET_PROBS message";
  1213. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1214. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1215. SLURM_ERROR, comment,
  1216. DBD_GET_PROBS);
  1217. return SLURM_ERROR;
  1218. }
  1219. list_msg.my_list = acct_storage_g_get_problems(
  1220. slurmdbd_conn->db_conn, *uid, get_msg->cond);
  1221. if (!errno) {
  1222. if (!list_msg.my_list)
  1223. list_msg.my_list = list_create(NULL);
  1224. *out_buffer = init_buf(1024);
  1225. pack16((uint16_t) DBD_GOT_PROBS, *out_buffer);
  1226. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1227. DBD_GOT_PROBS, *out_buffer);
  1228. } else {
  1229. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1230. errno, slurm_strerror(errno),
  1231. DBD_GET_PROBS);
  1232. rc = SLURM_ERROR;
  1233. }
  1234. slurmdbd_free_cond_msg(get_msg, DBD_GET_PROBS);
  1235. if (list_msg.my_list)
  1236. list_destroy(list_msg.my_list);
  1237. return rc;
  1238. }
  1239. static int _get_qos(slurmdbd_conn_t *slurmdbd_conn,
  1240. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1241. {
  1242. dbd_cond_msg_t *cond_msg = NULL;
  1243. dbd_list_msg_t list_msg;
  1244. char *comment = NULL;
  1245. int rc = SLURM_SUCCESS;
  1246. debug2("DBD_GET_QOS: called");
  1247. if (slurmdbd_unpack_cond_msg(&cond_msg, slurmdbd_conn->rpc_version,
  1248. DBD_GET_QOS, in_buffer) !=
  1249. SLURM_SUCCESS) {
  1250. comment = "Failed to unpack DBD_GET_QOS message";
  1251. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1252. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1253. SLURM_ERROR, comment,
  1254. DBD_GET_QOS);
  1255. return SLURM_ERROR;
  1256. }
  1257. list_msg.my_list = acct_storage_g_get_qos(slurmdbd_conn->db_conn, *uid,
  1258. cond_msg->cond);
  1259. if (errno == ESLURM_ACCESS_DENIED && !list_msg.my_list)
  1260. list_msg.my_list = list_create(NULL);
  1261. if (!errno) {
  1262. if (!list_msg.my_list)
  1263. list_msg.my_list = list_create(NULL);
  1264. *out_buffer = init_buf(1024);
  1265. pack16((uint16_t) DBD_GOT_QOS, *out_buffer);
  1266. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1267. DBD_GOT_QOS, *out_buffer);
  1268. } else {
  1269. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1270. errno, slurm_strerror(errno),
  1271. DBD_GET_QOS);
  1272. rc = SLURM_ERROR;
  1273. }
  1274. slurmdbd_free_cond_msg(cond_msg, DBD_GET_QOS);
  1275. if (list_msg.my_list)
  1276. list_destroy(list_msg.my_list);
  1277. return rc;
  1278. }
  1279. static int _get_txn(slurmdbd_conn_t *slurmdbd_conn,
  1280. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1281. {
  1282. dbd_cond_msg_t *cond_msg = NULL;
  1283. dbd_list_msg_t list_msg;
  1284. char *comment = NULL;
  1285. int rc = SLURM_SUCCESS;
  1286. debug2("DBD_GET_TXN: called");
  1287. if (slurmdbd_unpack_cond_msg(&cond_msg, slurmdbd_conn->rpc_version,
  1288. DBD_GET_TXN, in_buffer) !=
  1289. SLURM_SUCCESS) {
  1290. comment = "Failed to unpack DBD_GET_TXN message";
  1291. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1292. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1293. SLURM_ERROR, comment,
  1294. DBD_GET_TXN);
  1295. return SLURM_ERROR;
  1296. }
  1297. list_msg.my_list = acct_storage_g_get_txn(slurmdbd_conn->db_conn, *uid,
  1298. cond_msg->cond);
  1299. if (!errno) {
  1300. if (!list_msg.my_list)
  1301. list_msg.my_list = list_create(NULL);
  1302. *out_buffer = init_buf(1024);
  1303. pack16((uint16_t) DBD_GOT_TXN, *out_buffer);
  1304. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1305. DBD_GOT_TXN, *out_buffer);
  1306. } else {
  1307. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1308. errno, slurm_strerror(errno),
  1309. DBD_GET_TXN);
  1310. rc = SLURM_ERROR;
  1311. }
  1312. slurmdbd_free_cond_msg(cond_msg, DBD_GET_TXN);
  1313. if (list_msg.my_list)
  1314. list_destroy(list_msg.my_list);
  1315. return rc;
  1316. }
  1317. static int _get_usage(uint16_t type, slurmdbd_conn_t *slurmdbd_conn,
  1318. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1319. {
  1320. dbd_usage_msg_t *get_msg = NULL;
  1321. dbd_usage_msg_t got_msg;
  1322. uint16_t ret_type = 0;
  1323. int rc = SLURM_SUCCESS;
  1324. char *comment = NULL;
  1325. info("DBD_GET_USAGE: called type is %s",
  1326. slurmdbd_msg_type_2_str(type, 1));
  1327. if (slurmdbd_unpack_usage_msg(&get_msg, slurmdbd_conn->rpc_version,
  1328. type, in_buffer) !=
  1329. SLURM_SUCCESS) {
  1330. comment = "Failed to unpack DBD_GET_USAGE message";
  1331. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1332. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1333. SLURM_ERROR, comment, type);
  1334. return SLURM_ERROR;
  1335. }
  1336. switch(type) {
  1337. case DBD_GET_ASSOC_USAGE:
  1338. ret_type = DBD_GOT_ASSOC_USAGE;
  1339. break;
  1340. case DBD_GET_WCKEY_USAGE:
  1341. ret_type = DBD_GOT_WCKEY_USAGE;
  1342. break;
  1343. case DBD_GET_CLUSTER_USAGE:
  1344. ret_type = DBD_GOT_CLUSTER_USAGE;
  1345. break;
  1346. default:
  1347. comment = "Unknown type of usage to get";
  1348. error("%s %u", comment, type);
  1349. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1350. SLURM_ERROR, comment, type);
  1351. return SLURM_ERROR;
  1352. }
  1353. rc = acct_storage_g_get_usage(slurmdbd_conn->db_conn,
  1354. *uid, get_msg->rec, type,
  1355. get_msg->start, get_msg->end);
  1356. slurmdbd_free_usage_msg(get_msg, type);
  1357. if (rc != SLURM_SUCCESS) {
  1358. comment = "Problem getting usage info";
  1359. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1360. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1361. rc, comment, type);
  1362. return rc;
  1363. }
  1364. memset(&got_msg, 0, sizeof(dbd_usage_msg_t));
  1365. got_msg.rec = get_msg->rec;
  1366. get_msg->rec = NULL;
  1367. *out_buffer = init_buf(1024);
  1368. pack16((uint16_t) ret_type, *out_buffer);
  1369. slurmdbd_pack_usage_msg(&got_msg, slurmdbd_conn->rpc_version,
  1370. ret_type, *out_buffer);
  1371. return SLURM_SUCCESS;
  1372. }
  1373. static int _get_users(slurmdbd_conn_t *slurmdbd_conn,
  1374. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1375. {
  1376. dbd_cond_msg_t *get_msg = NULL;
  1377. dbd_list_msg_t list_msg;
  1378. char *comment = NULL;
  1379. int rc = SLURM_SUCCESS;
  1380. slurmdb_user_cond_t * user_cond = NULL;
  1381. debug2("DBD_GET_USERS: called");
  1382. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1383. DBD_GET_USERS, in_buffer) !=
  1384. SLURM_SUCCESS) {
  1385. comment = "Failed to unpack DBD_GET_USERS message";
  1386. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1387. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1388. SLURM_ERROR, comment,
  1389. DBD_GET_USERS);
  1390. return SLURM_ERROR;
  1391. }
  1392. user_cond = get_msg->cond;
  1393. if ((!user_cond->with_assocs && !user_cond->with_wckeys)
  1394. && ((slurmdbd_conn->rpc_version < 8)
  1395. || (user_cond->assoc_cond->only_defs))) {
  1396. List cluster_list = user_cond->assoc_cond->cluster_list;
  1397. /* load up with just this cluster to query against
  1398. * since befor 2.2 we had only 1 default account so
  1399. * send the default for this cluster. */
  1400. if (!cluster_list) {
  1401. cluster_list = list_create(NULL);
  1402. list_append(cluster_list, slurmdbd_conn->cluster_name);
  1403. user_cond->assoc_cond->cluster_list = cluster_list;
  1404. }
  1405. }
  1406. list_msg.my_list = acct_storage_g_get_users(slurmdbd_conn->db_conn,
  1407. *uid, user_cond);
  1408. if (!errno) {
  1409. if (!list_msg.my_list)
  1410. list_msg.my_list = list_create(NULL);
  1411. *out_buffer = init_buf(1024);
  1412. pack16((uint16_t) DBD_GOT_USERS, *out_buffer);
  1413. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1414. DBD_GOT_USERS, *out_buffer);
  1415. } else {
  1416. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1417. errno, slurm_strerror(errno),
  1418. DBD_GET_USERS);
  1419. rc = SLURM_ERROR;
  1420. }
  1421. slurmdbd_free_cond_msg(get_msg, DBD_GET_USERS);
  1422. if (list_msg.my_list)
  1423. list_destroy(list_msg.my_list);
  1424. return rc;
  1425. }
  1426. static int _get_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  1427. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1428. {
  1429. dbd_cond_msg_t *get_msg = NULL;
  1430. dbd_list_msg_t list_msg;
  1431. char *comment = NULL;
  1432. int rc = SLURM_SUCCESS;
  1433. debug2("DBD_GET_WCKEYS: called");
  1434. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  1435. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  1436. < SLURMDB_ADMIN_OPERATOR) {
  1437. comment = "Your user doesn't have privilege to preform this action";
  1438. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1439. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1440. ESLURM_ACCESS_DENIED, comment,
  1441. DBD_GET_WCKEYS);
  1442. return ESLURM_ACCESS_DENIED;
  1443. }
  1444. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1445. DBD_GET_WCKEYS, in_buffer) !=
  1446. SLURM_SUCCESS) {
  1447. comment = "Failed to unpack DBD_GET_WCKEYS message";
  1448. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1449. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1450. SLURM_ERROR, comment,
  1451. DBD_GET_WCKEYS);
  1452. return SLURM_ERROR;
  1453. }
  1454. list_msg.my_list = acct_storage_g_get_wckeys(slurmdbd_conn->db_conn,
  1455. *uid, get_msg->cond);
  1456. if (!errno) {
  1457. if (!list_msg.my_list)
  1458. list_msg.my_list = list_create(NULL);
  1459. *out_buffer = init_buf(1024);
  1460. pack16((uint16_t) DBD_GOT_WCKEYS, *out_buffer);
  1461. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1462. DBD_GOT_WCKEYS, *out_buffer);
  1463. } else {
  1464. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1465. errno, slurm_strerror(errno),
  1466. DBD_GET_WCKEYS);
  1467. rc = SLURM_ERROR;
  1468. }
  1469. slurmdbd_free_cond_msg(get_msg, DBD_GET_WCKEYS);
  1470. if (list_msg.my_list)
  1471. list_destroy(list_msg.my_list);
  1472. return rc;
  1473. }
  1474. static int _get_reservations(slurmdbd_conn_t *slurmdbd_conn,
  1475. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1476. {
  1477. dbd_cond_msg_t *get_msg = NULL;
  1478. dbd_list_msg_t list_msg;
  1479. char *comment = NULL;
  1480. int rc = SLURM_SUCCESS;
  1481. debug2("DBD_GET_RESVS: called");
  1482. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  1483. DBD_GET_RESVS, in_buffer) !=
  1484. SLURM_SUCCESS) {
  1485. comment = "Failed to unpack DBD_GET_RESVS message";
  1486. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1487. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1488. SLURM_ERROR, comment,
  1489. DBD_GET_RESVS);
  1490. return SLURM_ERROR;
  1491. }
  1492. list_msg.my_list = acct_storage_g_get_reservations(
  1493. slurmdbd_conn->db_conn, *uid, get_msg->cond);
  1494. if (!errno) {
  1495. if (!list_msg.my_list)
  1496. list_msg.my_list = list_create(NULL);
  1497. *out_buffer = init_buf(1024);
  1498. pack16((uint16_t) DBD_GOT_RESVS, *out_buffer);
  1499. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1500. DBD_GOT_RESVS, *out_buffer);
  1501. } else {
  1502. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1503. errno, slurm_strerror(errno),
  1504. DBD_GET_RESVS);
  1505. rc = SLURM_ERROR;
  1506. }
  1507. slurmdbd_free_cond_msg(get_msg, DBD_GET_RESVS);
  1508. if (list_msg.my_list)
  1509. list_destroy(list_msg.my_list);
  1510. return rc;
  1511. }
  1512. static int _flush_jobs(slurmdbd_conn_t *slurmdbd_conn,
  1513. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1514. {
  1515. dbd_cluster_cpus_msg_t *cluster_cpus_msg = NULL;
  1516. int rc = SLURM_SUCCESS;
  1517. char *comment = NULL;
  1518. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)) {
  1519. comment = "DBD_FLUSH_JOBS message from invalid uid";
  1520. error("DBD_FLUSH_JOBS message from invalid uid %u", *uid);
  1521. rc = ESLURM_ACCESS_DENIED;
  1522. goto end_it;
  1523. }
  1524. if (slurmdbd_unpack_cluster_cpus_msg(
  1525. &cluster_cpus_msg, slurmdbd_conn->rpc_version, in_buffer)
  1526. != SLURM_SUCCESS) {
  1527. comment = "Failed to unpack DBD_FLUSH_JOBS message";
  1528. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1529. rc = SLURM_ERROR;
  1530. goto end_it;
  1531. }
  1532. debug2("DBD_FLUSH_JOBS: called for %s",
  1533. slurmdbd_conn->cluster_name);
  1534. rc = acct_storage_g_flush_jobs_on_cluster(
  1535. slurmdbd_conn->db_conn,
  1536. cluster_cpus_msg->event_time);
  1537. end_it:
  1538. slurmdbd_free_cluster_cpus_msg(cluster_cpus_msg);
  1539. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1540. rc, comment, DBD_FLUSH_JOBS);
  1541. return rc;
  1542. }
  1543. static int _init_conn(slurmdbd_conn_t *slurmdbd_conn,
  1544. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1545. {
  1546. dbd_init_msg_t *init_msg = NULL;
  1547. char *comment = NULL;
  1548. int rc = SLURM_SUCCESS;
  1549. if ((rc = slurmdbd_unpack_init_msg(&init_msg, in_buffer,
  1550. slurmdbd_conf->auth_info))
  1551. != SLURM_SUCCESS) {
  1552. comment = "Failed to unpack DBD_INIT message";
  1553. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1554. goto end_it;
  1555. }
  1556. if ((init_msg->version < SLURMDBD_VERSION_MIN) ||
  1557. (init_msg->version > SLURMDBD_VERSION)) {
  1558. comment = "Incompatible RPC version";
  1559. error("Incompatible RPC version received "
  1560. "(%u not between %d and %d)",
  1561. init_msg->version,
  1562. SLURMDBD_VERSION_MIN, SLURMDBD_VERSION);
  1563. rc = SLURM_PROTOCOL_VERSION_ERROR;
  1564. goto end_it;
  1565. }
  1566. *uid = init_msg->uid;
  1567. debug("DBD_INIT: CLUSTER:%s VERSION:%u UID:%u IP:%s CONN:%u",
  1568. init_msg->cluster_name, init_msg->version, init_msg->uid,
  1569. slurmdbd_conn->ip, slurmdbd_conn->newsockfd);
  1570. slurmdbd_conn->cluster_name = xstrdup(init_msg->cluster_name);
  1571. slurmdbd_conn->db_conn = acct_storage_g_get_connection(
  1572. false, slurmdbd_conn->newsockfd, init_msg->rollback,
  1573. slurmdbd_conn->cluster_name);
  1574. slurmdbd_conn->rpc_version = init_msg->version;
  1575. if (errno) {
  1576. rc = errno;
  1577. comment = slurm_strerror(rc);
  1578. }
  1579. end_it:
  1580. slurmdbd_free_init_msg(init_msg);
  1581. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1582. rc, comment, DBD_INIT);
  1583. return rc;
  1584. }
  1585. static int _fini_conn(slurmdbd_conn_t *slurmdbd_conn, Buf in_buffer,
  1586. Buf *out_buffer)
  1587. {
  1588. dbd_fini_msg_t *fini_msg = NULL;
  1589. char *comment = NULL;
  1590. int rc = SLURM_SUCCESS;
  1591. if (slurmdbd_unpack_fini_msg(
  1592. &fini_msg, slurmdbd_conn->rpc_version, in_buffer)
  1593. != SLURM_SUCCESS) {
  1594. comment = "Failed to unpack DBD_FINI message";
  1595. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1596. rc = SLURM_ERROR;
  1597. goto end_it;
  1598. }
  1599. debug2("DBD_FINI: CLOSE:%u COMMIT:%u",
  1600. fini_msg->close_conn, fini_msg->commit);
  1601. if (fini_msg->close_conn == 1)
  1602. rc = acct_storage_g_close_connection(&slurmdbd_conn->db_conn);
  1603. else
  1604. rc = acct_storage_g_commit(slurmdbd_conn->db_conn,
  1605. fini_msg->commit);
  1606. end_it:
  1607. slurmdbd_free_fini_msg(fini_msg);
  1608. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1609. rc, comment, DBD_FINI);
  1610. return rc;
  1611. }
  1612. static int _job_complete(slurmdbd_conn_t *slurmdbd_conn,
  1613. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1614. {
  1615. dbd_job_comp_msg_t *job_comp_msg = NULL;
  1616. struct job_record job;
  1617. struct job_details details;
  1618. int rc = SLURM_SUCCESS;
  1619. char *comment = NULL;
  1620. if (*uid != slurmdbd_conf->slurm_user_id) {
  1621. comment = "DBD_JOB_COMPLETE message from invalid uid";
  1622. error("CONN:%u %s %u",
  1623. slurmdbd_conn->newsockfd, comment, *uid);
  1624. rc = ESLURM_ACCESS_DENIED;
  1625. goto end_it;
  1626. }
  1627. if (slurmdbd_unpack_job_complete_msg(
  1628. &job_comp_msg, slurmdbd_conn->rpc_version, in_buffer)
  1629. != SLURM_SUCCESS) {
  1630. comment = "Failed to unpack DBD_JOB_COMPLETE message";
  1631. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1632. rc = SLURM_ERROR;
  1633. goto end_it;
  1634. }
  1635. memset(&job, 0, sizeof(struct job_record));
  1636. memset(&details, 0, sizeof(struct job_details));
  1637. job.assoc_id = job_comp_msg->assoc_id;
  1638. job.comment = job_comp_msg->comment;
  1639. if (job_comp_msg->db_index != NO_VAL)
  1640. job.db_index = job_comp_msg->db_index;
  1641. job.derived_ec = job_comp_msg->derived_ec;
  1642. job.end_time = job_comp_msg->end_time;
  1643. job.exit_code = job_comp_msg->exit_code;
  1644. job.job_id = job_comp_msg->job_id;
  1645. job.job_state = job_comp_msg->job_state;
  1646. job.requid = job_comp_msg->req_uid;
  1647. job.nodes = job_comp_msg->nodes;
  1648. job.start_time = job_comp_msg->start_time;
  1649. details.submit_time = job_comp_msg->submit_time;
  1650. job.details = &details;
  1651. if (job.job_state & JOB_RESIZING) {
  1652. job.resize_time = job_comp_msg->end_time;
  1653. debug2("DBD_JOB_COMPLETE: RESIZE ID:%u", job_comp_msg->job_id);
  1654. } else
  1655. debug2("DBD_JOB_COMPLETE: ID:%u", job_comp_msg->job_id);
  1656. rc = jobacct_storage_g_job_complete(slurmdbd_conn->db_conn, &job);
  1657. if (rc && errno == 740) /* meaning data is already there */
  1658. rc = SLURM_SUCCESS;
  1659. /* just incase this gets set we need to clear it */
  1660. xfree(job.wckey);
  1661. if (!slurmdbd_conn->ctld_port) {
  1662. info("DBD_JOB_COMPLETE: cluster not registered");
  1663. slurmdbd_conn->ctld_port =
  1664. clusteracct_storage_g_register_disconn_ctld(
  1665. slurmdbd_conn->db_conn, slurmdbd_conn->ip);
  1666. }
  1667. end_it:
  1668. slurmdbd_free_job_complete_msg(job_comp_msg);
  1669. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1670. rc, comment, DBD_JOB_COMPLETE);
  1671. return SLURM_SUCCESS;
  1672. }
  1673. static int _job_start(slurmdbd_conn_t *slurmdbd_conn,
  1674. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1675. {
  1676. dbd_job_start_msg_t *job_start_msg = NULL;
  1677. dbd_id_rc_msg_t id_rc_msg;
  1678. char *comment = NULL;
  1679. if (*uid != slurmdbd_conf->slurm_user_id) {
  1680. comment = "DBD_JOB_START message from invalid uid";
  1681. error("CONN:%u %s %u",
  1682. slurmdbd_conn->newsockfd, comment, *uid);
  1683. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1684. ESLURM_ACCESS_DENIED, comment,
  1685. DBD_JOB_START);
  1686. return SLURM_ERROR;
  1687. }
  1688. if (slurmdbd_unpack_job_start_msg((void **)&job_start_msg,
  1689. slurmdbd_conn->rpc_version,
  1690. in_buffer) !=
  1691. SLURM_SUCCESS) {
  1692. comment = "Failed to unpack DBD_JOB_START message";
  1693. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1694. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1695. SLURM_ERROR, comment,
  1696. DBD_JOB_START);
  1697. return SLURM_ERROR;
  1698. }
  1699. _process_job_start(slurmdbd_conn, job_start_msg, &id_rc_msg);
  1700. slurmdbd_free_job_start_msg(job_start_msg);
  1701. *out_buffer = init_buf(1024);
  1702. pack16((uint16_t) DBD_ID_RC, *out_buffer);
  1703. slurmdbd_pack_id_rc_msg(&id_rc_msg,
  1704. slurmdbd_conn->rpc_version, *out_buffer);
  1705. return SLURM_SUCCESS;
  1706. }
  1707. static int _job_suspend(slurmdbd_conn_t *slurmdbd_conn,
  1708. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1709. {
  1710. dbd_job_suspend_msg_t *job_suspend_msg = NULL;
  1711. struct job_record job;
  1712. struct job_details details;
  1713. int rc = SLURM_SUCCESS;
  1714. char *comment = NULL;
  1715. if (*uid != slurmdbd_conf->slurm_user_id) {
  1716. comment = "DBD_JOB_SUSPEND message from invalid uid";
  1717. error("CONN:%u %s %u",
  1718. slurmdbd_conn->newsockfd, comment, *uid);
  1719. rc = ESLURM_ACCESS_DENIED;
  1720. goto end_it;
  1721. }
  1722. if (slurmdbd_unpack_job_suspend_msg(&job_suspend_msg,
  1723. slurmdbd_conn->rpc_version,
  1724. in_buffer) != SLURM_SUCCESS) {
  1725. comment = "Failed to unpack DBD_JOB_SUSPEND message";
  1726. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1727. rc = SLURM_ERROR;
  1728. goto end_it;
  1729. }
  1730. debug2("DBD_JOB_SUSPEND: ID:%u STATE:%s",
  1731. job_suspend_msg->job_id,
  1732. job_state_string((enum job_states) job_suspend_msg->job_state));
  1733. memset(&job, 0, sizeof(struct job_record));
  1734. memset(&details, 0, sizeof(struct job_details));
  1735. job.assoc_id = job_suspend_msg->assoc_id;
  1736. if (job_suspend_msg->db_index != NO_VAL)
  1737. job.db_index = job_suspend_msg->db_index;
  1738. job.job_id = job_suspend_msg->job_id;
  1739. job.job_state = job_suspend_msg->job_state;
  1740. details.submit_time = job_suspend_msg->submit_time;
  1741. job.suspend_time = job_suspend_msg->suspend_time;
  1742. job.details = &details;
  1743. rc = jobacct_storage_g_job_suspend(slurmdbd_conn->db_conn, &job);
  1744. if (rc && errno == 740) /* meaning data is already there */
  1745. rc = SLURM_SUCCESS;
  1746. /* just incase this gets set we need to clear it */
  1747. xfree(job.wckey);
  1748. end_it:
  1749. slurmdbd_free_job_suspend_msg(job_suspend_msg);
  1750. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1751. rc, comment, DBD_JOB_SUSPEND);
  1752. return SLURM_SUCCESS;
  1753. }
  1754. static int _modify_accounts(slurmdbd_conn_t *slurmdbd_conn,
  1755. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1756. {
  1757. dbd_list_msg_t list_msg;
  1758. int rc = SLURM_SUCCESS;
  1759. dbd_modify_msg_t *get_msg = NULL;
  1760. char *comment = NULL;
  1761. debug2("DBD_MODIFY_ACCOUNTS: called");
  1762. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  1763. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  1764. < SLURMDB_ADMIN_OPERATOR) {
  1765. comment = "Your user doesn't have privilege to preform this action";
  1766. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1767. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1768. ESLURM_ACCESS_DENIED,
  1769. comment, DBD_MODIFY_ACCOUNTS);
  1770. return ESLURM_ACCESS_DENIED;
  1771. }
  1772. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  1773. DBD_MODIFY_ACCOUNTS,
  1774. in_buffer) != SLURM_SUCCESS) {
  1775. comment = "Failed to unpack DBD_MODIFY_ACCOUNTS message";
  1776. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1777. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1778. SLURM_ERROR,
  1779. comment, DBD_MODIFY_ACCOUNTS);
  1780. return SLURM_ERROR;
  1781. }
  1782. if (!(list_msg.my_list = acct_storage_g_modify_accounts(
  1783. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  1784. get_msg->rec))) {
  1785. if (errno == ESLURM_ACCESS_DENIED) {
  1786. comment = "Your user doesn't have privilege to preform this action";
  1787. rc = ESLURM_ACCESS_DENIED;
  1788. } else if (errno == SLURM_ERROR) {
  1789. comment = "Something was wrong with your query";
  1790. rc = SLURM_ERROR;
  1791. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  1792. comment = "Request didn't affect anything";
  1793. rc = SLURM_SUCCESS;
  1794. } else if (errno == ESLURM_DB_CONNECTION) {
  1795. comment = slurm_strerror(errno);
  1796. rc = errno;
  1797. } else {
  1798. rc = errno;
  1799. if (!(comment = slurm_strerror(errno)))
  1800. comment = "Unknown issue";
  1801. }
  1802. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1803. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_ACCOUNTS);
  1804. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1805. rc, comment, DBD_MODIFY_ACCOUNTS);
  1806. return rc;
  1807. }
  1808. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_ACCOUNTS);
  1809. *out_buffer = init_buf(1024);
  1810. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  1811. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1812. DBD_GOT_LIST, *out_buffer);
  1813. if (list_msg.my_list)
  1814. list_destroy(list_msg.my_list);
  1815. return rc;
  1816. }
  1817. static int _modify_assocs(slurmdbd_conn_t *slurmdbd_conn,
  1818. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1819. {
  1820. dbd_list_msg_t list_msg;
  1821. int rc = SLURM_SUCCESS;
  1822. dbd_modify_msg_t *get_msg = NULL;
  1823. char *comment = NULL;
  1824. debug2("DBD_MODIFY_ASSOCS: called");
  1825. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  1826. DBD_MODIFY_ASSOCS,
  1827. in_buffer) != SLURM_SUCCESS) {
  1828. comment = "Failed to unpack DBD_MODIFY_ASSOCS message";
  1829. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1830. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1831. SLURM_ERROR,
  1832. comment, DBD_MODIFY_ASSOCS);
  1833. return SLURM_ERROR;
  1834. }
  1835. /* All authentication needs to be done inside the plugin since we are
  1836. * unable to know what accounts this request is talking about
  1837. * until we process it through the database.
  1838. */
  1839. if (!(list_msg.my_list = acct_storage_g_modify_associations(
  1840. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  1841. get_msg->rec))) {
  1842. if (errno == ESLURM_ACCESS_DENIED) {
  1843. comment = "Your user doesn't have privilege to preform this action";
  1844. rc = ESLURM_ACCESS_DENIED;
  1845. } else if (errno == SLURM_ERROR) {
  1846. comment = "Something was wrong with your query";
  1847. rc = SLURM_ERROR;
  1848. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  1849. comment = "Request didn't affect anything";
  1850. rc = SLURM_SUCCESS;
  1851. } else if (errno == ESLURM_DB_CONNECTION) {
  1852. comment = slurm_strerror(errno);
  1853. rc = errno;
  1854. } else {
  1855. rc = errno;
  1856. if (!(comment = slurm_strerror(errno)))
  1857. comment = "Unknown issue";
  1858. }
  1859. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1860. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_ASSOCS);
  1861. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1862. rc, comment, DBD_MODIFY_ASSOCS);
  1863. return rc;
  1864. }
  1865. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_ASSOCS);
  1866. *out_buffer = init_buf(1024);
  1867. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  1868. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1869. DBD_GOT_LIST, *out_buffer);
  1870. if (list_msg.my_list)
  1871. list_destroy(list_msg.my_list);
  1872. return rc;
  1873. }
  1874. static int _modify_clusters(slurmdbd_conn_t *slurmdbd_conn,
  1875. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1876. {
  1877. dbd_list_msg_t list_msg;
  1878. int rc = SLURM_SUCCESS;
  1879. dbd_modify_msg_t *get_msg = NULL;
  1880. char *comment = NULL;
  1881. debug2("DBD_MODIFY_CLUSTERS: called");
  1882. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  1883. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  1884. < SLURMDB_ADMIN_SUPER_USER) {
  1885. comment = "Your user doesn't have privilege to preform this action";
  1886. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1887. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1888. ESLURM_ACCESS_DENIED,
  1889. comment, DBD_MODIFY_CLUSTERS);
  1890. return ESLURM_ACCESS_DENIED;
  1891. }
  1892. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  1893. DBD_MODIFY_CLUSTERS,
  1894. in_buffer) != SLURM_SUCCESS) {
  1895. comment = "Failed to unpack DBD_MODIFY_CLUSTERS message";
  1896. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1897. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1898. SLURM_ERROR,
  1899. comment, DBD_MODIFY_CLUSTERS);
  1900. return SLURM_ERROR;
  1901. }
  1902. if (!(list_msg.my_list = acct_storage_g_modify_clusters(
  1903. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  1904. get_msg->rec))) {
  1905. if (errno == ESLURM_ACCESS_DENIED) {
  1906. comment = "Your user doesn't have privilege to preform this action";
  1907. rc = ESLURM_ACCESS_DENIED;
  1908. } else if (errno == SLURM_ERROR) {
  1909. comment = "Something was wrong with your query";
  1910. rc = SLURM_ERROR;
  1911. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  1912. comment = "Request didn't affect anything";
  1913. rc = SLURM_SUCCESS;
  1914. } else if (errno == ESLURM_DB_CONNECTION) {
  1915. comment = slurm_strerror(errno);
  1916. rc = errno;
  1917. } else {
  1918. rc = errno;
  1919. if (!(comment = slurm_strerror(errno)))
  1920. comment = "Unknown issue";
  1921. }
  1922. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1923. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_CLUSTERS);
  1924. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1925. rc, comment, DBD_MODIFY_CLUSTERS);
  1926. return rc;
  1927. }
  1928. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_CLUSTERS);
  1929. *out_buffer = init_buf(1024);
  1930. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  1931. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1932. DBD_GOT_LIST, *out_buffer);
  1933. if (list_msg.my_list)
  1934. list_destroy(list_msg.my_list);
  1935. return rc;
  1936. }
  1937. static int _modify_job(slurmdbd_conn_t *slurmdbd_conn,
  1938. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  1939. {
  1940. dbd_list_msg_t list_msg;
  1941. int rc = SLURM_SUCCESS;
  1942. dbd_modify_msg_t *get_msg = NULL;
  1943. char *comment = NULL;
  1944. debug2("DBD_MODIFY_JOB: called");
  1945. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  1946. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  1947. < SLURMDB_ADMIN_SUPER_USER) {
  1948. comment = "Your user doesn't have privilege to preform this action";
  1949. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1950. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1951. ESLURM_ACCESS_DENIED,
  1952. comment, DBD_MODIFY_JOB);
  1953. return ESLURM_ACCESS_DENIED;
  1954. }
  1955. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  1956. DBD_MODIFY_JOB,
  1957. in_buffer) != SLURM_SUCCESS) {
  1958. comment = "Failed to unpack DBD_MODIFY_JOB message";
  1959. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1960. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1961. SLURM_ERROR,
  1962. comment, DBD_MODIFY_JOB);
  1963. return SLURM_ERROR;
  1964. }
  1965. if (!(list_msg.my_list = acct_storage_g_modify_job(
  1966. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  1967. get_msg->rec))) {
  1968. if (errno == ESLURM_ACCESS_DENIED) {
  1969. comment = "Your user doesn't have privilege to preform this action";
  1970. rc = ESLURM_ACCESS_DENIED;
  1971. } else if (errno == SLURM_ERROR) {
  1972. comment = "Something was wrong with your query";
  1973. rc = SLURM_ERROR;
  1974. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  1975. comment = "Request didn't affect anything";
  1976. rc = SLURM_SUCCESS;
  1977. } else if (errno == ESLURM_DB_CONNECTION) {
  1978. comment = slurm_strerror(errno);
  1979. rc = errno;
  1980. } else {
  1981. rc = errno;
  1982. if (!(comment = slurm_strerror(errno)))
  1983. comment = "Unknown issue";
  1984. }
  1985. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  1986. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_JOB);
  1987. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  1988. rc, comment, DBD_MODIFY_JOB);
  1989. return rc;
  1990. }
  1991. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_JOB);
  1992. *out_buffer = init_buf(1024);
  1993. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  1994. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  1995. DBD_GOT_LIST, *out_buffer);
  1996. if (list_msg.my_list)
  1997. list_destroy(list_msg.my_list);
  1998. return rc;
  1999. }
  2000. static int _modify_qos(slurmdbd_conn_t *slurmdbd_conn,
  2001. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2002. {
  2003. dbd_list_msg_t list_msg;
  2004. int rc = SLURM_SUCCESS;
  2005. dbd_modify_msg_t *get_msg = NULL;
  2006. char *comment = NULL;
  2007. debug2("DBD_MODIFY_QOS: called");
  2008. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2009. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2010. < SLURMDB_ADMIN_SUPER_USER) {
  2011. comment = "Your user doesn't have privilege to preform this action";
  2012. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2013. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2014. ESLURM_ACCESS_DENIED,
  2015. comment, DBD_MODIFY_QOS);
  2016. return ESLURM_ACCESS_DENIED;
  2017. }
  2018. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  2019. DBD_MODIFY_QOS,
  2020. in_buffer) != SLURM_SUCCESS) {
  2021. comment = "Failed to unpack DBD_MODIFY_QOS message";
  2022. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2023. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2024. SLURM_ERROR,
  2025. comment, DBD_MODIFY_QOS);
  2026. return SLURM_ERROR;
  2027. }
  2028. if (!(list_msg.my_list = acct_storage_g_modify_qos(
  2029. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  2030. get_msg->rec))) {
  2031. if (errno == ESLURM_ACCESS_DENIED) {
  2032. comment = "Your user doesn't have privilege to preform this action";
  2033. rc = ESLURM_ACCESS_DENIED;
  2034. } else if (errno == SLURM_ERROR) {
  2035. comment = "Something was wrong with your query";
  2036. rc = SLURM_ERROR;
  2037. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2038. comment = "Request didn't affect anything";
  2039. rc = SLURM_SUCCESS;
  2040. } else if (errno == ESLURM_QOS_PREEMPTION_LOOP) {
  2041. comment = "QOS Preemption loop detected";
  2042. rc = ESLURM_QOS_PREEMPTION_LOOP;
  2043. } else if (errno == ESLURM_DB_CONNECTION) {
  2044. comment = slurm_strerror(errno);
  2045. rc = errno;
  2046. } else {
  2047. rc = errno;
  2048. if (!(comment = slurm_strerror(errno)))
  2049. comment = "Unknown issue";
  2050. }
  2051. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2052. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_QOS);
  2053. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2054. rc, comment, DBD_MODIFY_QOS);
  2055. return rc;
  2056. }
  2057. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_QOS);
  2058. *out_buffer = init_buf(1024);
  2059. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2060. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2061. DBD_GOT_LIST, *out_buffer);
  2062. if (list_msg.my_list)
  2063. list_destroy(list_msg.my_list);
  2064. return rc;
  2065. }
  2066. static int _modify_users(slurmdbd_conn_t *slurmdbd_conn,
  2067. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2068. {
  2069. dbd_list_msg_t list_msg;
  2070. int rc = SLURM_SUCCESS;
  2071. dbd_modify_msg_t *get_msg = NULL;
  2072. char *comment = NULL;
  2073. int same_user = 0;
  2074. int admin_level = assoc_mgr_get_admin_level(slurmdbd_conn->db_conn,
  2075. *uid);
  2076. slurmdb_user_cond_t *user_cond = NULL;
  2077. slurmdb_user_rec_t *user_rec = NULL;
  2078. debug2("DBD_MODIFY_USERS: called");
  2079. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  2080. DBD_MODIFY_USERS,
  2081. in_buffer) != SLURM_SUCCESS) {
  2082. comment = "Failed to unpack DBD_MODIFY_USERS message";
  2083. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2084. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2085. SLURM_ERROR,
  2086. comment, DBD_MODIFY_USERS);
  2087. return SLURM_ERROR;
  2088. }
  2089. user_cond = (slurmdb_user_cond_t *)get_msg->cond;
  2090. user_rec = (slurmdb_user_rec_t *)get_msg->rec;
  2091. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2092. && admin_level < SLURMDB_ADMIN_OPERATOR) {
  2093. if (user_cond && user_cond->assoc_cond
  2094. && user_cond->assoc_cond->user_list
  2095. && (list_count(user_cond->assoc_cond->user_list) == 1)) {
  2096. uid_t pw_uid;
  2097. char *name;
  2098. name = list_peek (user_cond->assoc_cond->user_list);
  2099. if ((uid_from_string (name, &pw_uid) >= 0)
  2100. && pw_uid == *uid) {
  2101. same_user = 1;
  2102. goto is_same_user;
  2103. }
  2104. }
  2105. comment = "Your user doesn't have privilege to preform this action";
  2106. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2107. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2108. ESLURM_ACCESS_DENIED,
  2109. comment, DBD_MODIFY_USERS);
  2110. return ESLURM_ACCESS_DENIED;
  2111. }
  2112. is_same_user:
  2113. /* same_user can only alter the default account, default wckey
  2114. * nothing else */
  2115. if (same_user) {
  2116. /* If we add anything else here for the user we will
  2117. * need to document it
  2118. */
  2119. if ((user_rec->admin_level != SLURMDB_ADMIN_NOTSET)) {
  2120. comment = "You can only change your own default account, default wckey nothing else";
  2121. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2122. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->
  2123. rpc_version,
  2124. ESLURM_ACCESS_DENIED,
  2125. comment,
  2126. DBD_MODIFY_USERS);
  2127. return ESLURM_ACCESS_DENIED;
  2128. }
  2129. }
  2130. if ((user_rec->admin_level != SLURMDB_ADMIN_NOTSET)
  2131. && (*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2132. && (admin_level < user_rec->admin_level)) {
  2133. comment = "You have to be the same or higher admin level to change another persons";
  2134. user_rec->admin_level = SLURMDB_ADMIN_NOTSET;
  2135. }
  2136. if (!(list_msg.my_list = acct_storage_g_modify_users(
  2137. slurmdbd_conn->db_conn, *uid, user_cond, user_rec))) {
  2138. if (errno == ESLURM_ACCESS_DENIED) {
  2139. comment = "Your user doesn't have privilege to preform this action";
  2140. rc = ESLURM_ACCESS_DENIED;
  2141. } else if (errno == SLURM_ERROR) {
  2142. comment = "Something was wrong with your query";
  2143. rc = SLURM_ERROR;
  2144. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2145. comment = "Request didn't affect anything";
  2146. rc = SLURM_SUCCESS;
  2147. } else if (errno == ESLURM_DB_CONNECTION) {
  2148. comment = slurm_strerror(errno);
  2149. rc = errno;
  2150. } else {
  2151. rc = errno;
  2152. if (!(comment = slurm_strerror(errno)))
  2153. comment = "Unknown issue";
  2154. }
  2155. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2156. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_USERS);
  2157. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2158. rc, comment, DBD_MODIFY_USERS);
  2159. return rc;
  2160. }
  2161. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_USERS);
  2162. *out_buffer = init_buf(1024);
  2163. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2164. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2165. DBD_GOT_LIST, *out_buffer);
  2166. if (list_msg.my_list)
  2167. list_destroy(list_msg.my_list);
  2168. return rc;
  2169. }
  2170. static int _modify_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  2171. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2172. {
  2173. dbd_list_msg_t list_msg;
  2174. int rc = SLURM_SUCCESS;
  2175. dbd_modify_msg_t *get_msg = NULL;
  2176. char *comment = NULL;
  2177. debug2("DBD_MODIFY_WCKEYS: called");
  2178. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2179. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2180. < SLURMDB_ADMIN_SUPER_USER) {
  2181. comment = "Your user doesn't have privilege to preform this action";
  2182. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2183. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2184. ESLURM_ACCESS_DENIED,
  2185. comment, DBD_MODIFY_WCKEYS);
  2186. return ESLURM_ACCESS_DENIED;
  2187. }
  2188. if (slurmdbd_unpack_modify_msg(&get_msg, slurmdbd_conn->rpc_version,
  2189. DBD_MODIFY_WCKEYS,
  2190. in_buffer) != SLURM_SUCCESS) {
  2191. comment = "Failed to unpack DBD_MODIFY_WCKEYS message";
  2192. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2193. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2194. SLURM_ERROR,
  2195. comment, DBD_MODIFY_WCKEYS);
  2196. return SLURM_ERROR;
  2197. }
  2198. if (!(list_msg.my_list = acct_storage_g_modify_wckeys(
  2199. slurmdbd_conn->db_conn, *uid, get_msg->cond,
  2200. get_msg->rec))) {
  2201. if (errno == ESLURM_ACCESS_DENIED) {
  2202. comment = "Your user doesn't have privilege to preform this action";
  2203. rc = ESLURM_ACCESS_DENIED;
  2204. } else if (errno == SLURM_ERROR) {
  2205. comment = "Something was wrong with your query";
  2206. rc = SLURM_ERROR;
  2207. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2208. comment = "Request didn't affect anything";
  2209. rc = SLURM_SUCCESS;
  2210. } else if (errno == ESLURM_DB_CONNECTION) {
  2211. comment = slurm_strerror(errno);
  2212. rc = errno;
  2213. } else {
  2214. rc = errno;
  2215. if (!(comment = slurm_strerror(errno)))
  2216. comment = "Unknown issue";
  2217. }
  2218. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2219. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_WCKEYS);
  2220. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2221. rc, comment, DBD_MODIFY_WCKEYS);
  2222. return rc;
  2223. }
  2224. slurmdbd_free_modify_msg(get_msg, DBD_MODIFY_WCKEYS);
  2225. *out_buffer = init_buf(1024);
  2226. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2227. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2228. DBD_GOT_LIST, *out_buffer);
  2229. if (list_msg.my_list)
  2230. list_destroy(list_msg.my_list);
  2231. return rc;
  2232. }
  2233. static int _modify_reservation(slurmdbd_conn_t *slurmdbd_conn,
  2234. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2235. {
  2236. int rc = SLURM_SUCCESS;
  2237. dbd_rec_msg_t *rec_msg = NULL;
  2238. char *comment = NULL;
  2239. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)) {
  2240. comment = "DBD_MODIFY_RESV message from invalid uid";
  2241. error("CONN:%u %s %u",
  2242. slurmdbd_conn->newsockfd, comment, *uid);
  2243. rc = ESLURM_ACCESS_DENIED;
  2244. goto end_it;
  2245. }
  2246. if (slurmdbd_unpack_rec_msg(&rec_msg, slurmdbd_conn->rpc_version,
  2247. DBD_MODIFY_RESV, in_buffer)
  2248. != SLURM_SUCCESS) {
  2249. comment = "Failed to unpack DBD_MODIFY_RESV message";
  2250. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2251. rc = SLURM_ERROR;
  2252. goto end_it;
  2253. }
  2254. debug2("DBD_MODIFY_RESV: called");
  2255. rc = acct_storage_g_modify_reservation(slurmdbd_conn->db_conn,
  2256. rec_msg->rec);
  2257. end_it:
  2258. slurmdbd_free_rec_msg(rec_msg, DBD_MODIFY_RESV);
  2259. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2260. rc, comment, DBD_MODIFY_RESV);
  2261. return rc;
  2262. }
  2263. static int _node_state(slurmdbd_conn_t *slurmdbd_conn,
  2264. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2265. {
  2266. dbd_node_state_msg_t *node_state_msg = NULL;
  2267. struct node_record node_ptr;
  2268. int rc = SLURM_SUCCESS;
  2269. char *comment = NULL;
  2270. if (*uid != slurmdbd_conf->slurm_user_id) {
  2271. comment = "DBD_NODE_STATE message from invalid uid";
  2272. error("CONN:%u %s %u",
  2273. slurmdbd_conn->newsockfd, comment, *uid);
  2274. rc = ESLURM_ACCESS_DENIED;
  2275. goto end_it;
  2276. }
  2277. if (slurmdbd_unpack_node_state_msg(&node_state_msg,
  2278. slurmdbd_conn->rpc_version,
  2279. in_buffer) !=
  2280. SLURM_SUCCESS) {
  2281. comment = "Failed to unpack DBD_NODE_STATE message";
  2282. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2283. rc = SLURM_ERROR;
  2284. goto end_it;
  2285. }
  2286. memset(&node_ptr, 0, sizeof(struct node_record));
  2287. node_ptr.name = node_state_msg->hostlist;
  2288. node_ptr.cpus = node_state_msg->cpu_count;
  2289. node_ptr.node_state = node_state_msg->state;
  2290. node_ptr.reason = node_state_msg->reason;
  2291. node_ptr.reason_time = node_state_msg->event_time;
  2292. node_ptr.reason_uid = node_state_msg->reason_uid;
  2293. slurmctld_conf.fast_schedule = 0;
  2294. if (!node_ptr.cpus)
  2295. node_state_msg->new_state = DBD_NODE_STATE_UP;
  2296. if (node_state_msg->new_state == DBD_NODE_STATE_UP) {
  2297. debug3("DBD_NODE_STATE: NODE:%s STATE:%s REASON:%s TIME:%ld",
  2298. node_state_msg->hostlist,
  2299. _node_state_string(node_state_msg->new_state),
  2300. node_state_msg->reason,
  2301. (long)node_state_msg->event_time);
  2302. rc = clusteracct_storage_g_node_up(
  2303. slurmdbd_conn->db_conn,
  2304. &node_ptr,
  2305. node_state_msg->event_time);
  2306. } else {
  2307. debug2("DBD_NODE_STATE: NODE:%s STATE:%s "
  2308. "REASON:%s UID:%u TIME:%ld",
  2309. node_state_msg->hostlist,
  2310. _node_state_string(node_state_msg->new_state),
  2311. node_state_msg->reason,
  2312. node_ptr.reason_uid,
  2313. (long)node_state_msg->event_time);
  2314. rc = clusteracct_storage_g_node_down(
  2315. slurmdbd_conn->db_conn,
  2316. &node_ptr,
  2317. node_state_msg->event_time,
  2318. node_state_msg->reason, node_ptr.reason_uid);
  2319. }
  2320. end_it:
  2321. slurmdbd_free_node_state_msg(node_state_msg);
  2322. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2323. rc, comment, DBD_NODE_STATE);
  2324. return SLURM_SUCCESS;
  2325. }
  2326. static char *_node_state_string(uint16_t node_state)
  2327. {
  2328. switch(node_state) {
  2329. case DBD_NODE_STATE_DOWN:
  2330. return "DOWN";
  2331. case DBD_NODE_STATE_UP:
  2332. return "UP";
  2333. }
  2334. return "UNKNOWN";
  2335. }
  2336. static void _process_job_start(slurmdbd_conn_t *slurmdbd_conn,
  2337. dbd_job_start_msg_t *job_start_msg,
  2338. dbd_id_rc_msg_t *id_rc_msg)
  2339. {
  2340. struct job_record job, *job_ptr;
  2341. struct job_details details;
  2342. memset(&job, 0, sizeof(struct job_record));
  2343. memset(&details, 0, sizeof(struct job_details));
  2344. memset(id_rc_msg, 0, sizeof(dbd_id_rc_msg_t));
  2345. job.total_cpus = job_start_msg->alloc_cpus;
  2346. job.total_nodes = job_start_msg->alloc_nodes;
  2347. job.account = _replace_double_quotes(job_start_msg->account);
  2348. job.assoc_id = job_start_msg->assoc_id;
  2349. job.comment = job_start_msg->block_id;
  2350. if (job_start_msg->db_index != NO_VAL)
  2351. job.db_index = job_start_msg->db_index;
  2352. details.begin_time = job_start_msg->eligible_time;
  2353. job.user_id = job_start_msg->uid;
  2354. job.group_id = job_start_msg->gid;
  2355. job.job_id = job_start_msg->job_id;
  2356. job.job_state = job_start_msg->job_state;
  2357. job.name = _replace_double_quotes(job_start_msg->name);
  2358. job.nodes = job_start_msg->nodes;
  2359. job.network = job_start_msg->node_inx;
  2360. job.partition = job_start_msg->partition;
  2361. details.min_cpus = job_start_msg->req_cpus;
  2362. job.qos_id = job_start_msg->qos_id;
  2363. job.resv_id = job_start_msg->resv_id;
  2364. job.priority = job_start_msg->priority;
  2365. job.start_time = job_start_msg->start_time;
  2366. job.time_limit = job_start_msg->timelimit;
  2367. job.gres_alloc = job_start_msg->gres_alloc;
  2368. job.gres_req = job_start_msg->gres_req;
  2369. job.gres_used = job_start_msg->gres_used;
  2370. job.wckey = _replace_double_quotes(job_start_msg->wckey);
  2371. details.submit_time = job_start_msg->submit_time;
  2372. job.details = &details;
  2373. job_ptr = &job;
  2374. if (job.job_state & JOB_RESIZING) {
  2375. job.resize_time = job_start_msg->eligible_time;
  2376. debug2("DBD_JOB_START: RESIZE CALL ID:%u NAME:%s INX:%u",
  2377. job_start_msg->job_id, job_start_msg->name,
  2378. job.db_index);
  2379. } else if (job.start_time && !IS_JOB_PENDING(job_ptr)) {
  2380. debug2("DBD_JOB_START: START CALL ID:%u NAME:%s INX:%u",
  2381. job_start_msg->job_id, job_start_msg->name,
  2382. job.db_index);
  2383. } else {
  2384. debug2("DBD_JOB_START: ELIGIBLE CALL ID:%u NAME:%s",
  2385. job_start_msg->job_id, job_start_msg->name);
  2386. }
  2387. id_rc_msg->return_code = jobacct_storage_g_job_start(
  2388. slurmdbd_conn->db_conn, &job);
  2389. id_rc_msg->job_id = job.job_id;
  2390. id_rc_msg->id = job.db_index;
  2391. /* just incase job.wckey was set because we didn't send one */
  2392. if (!job_start_msg->wckey)
  2393. xfree(job.wckey);
  2394. if (!slurmdbd_conn->ctld_port) {
  2395. info("DBD_JOB_START: cluster not registered");
  2396. slurmdbd_conn->ctld_port =
  2397. clusteracct_storage_g_register_disconn_ctld(
  2398. slurmdbd_conn->db_conn, slurmdbd_conn->ip);
  2399. }
  2400. }
  2401. static int _register_ctld(slurmdbd_conn_t *slurmdbd_conn,
  2402. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2403. {
  2404. dbd_register_ctld_msg_t *register_ctld_msg = NULL;
  2405. int rc = SLURM_SUCCESS;
  2406. char *comment = NULL;
  2407. slurmdb_cluster_cond_t cluster_q;
  2408. slurmdb_cluster_rec_t cluster;
  2409. dbd_list_msg_t list_msg;
  2410. if (*uid != slurmdbd_conf->slurm_user_id) {
  2411. comment = "DBD_REGISTER_CTLD message from invalid uid";
  2412. error("CONN:%u %s %u",
  2413. slurmdbd_conn->newsockfd, comment, *uid);
  2414. rc = ESLURM_ACCESS_DENIED;
  2415. goto end_it;
  2416. }
  2417. if (slurmdbd_unpack_register_ctld_msg(&register_ctld_msg,
  2418. slurmdbd_conn->rpc_version,
  2419. in_buffer) !=
  2420. SLURM_SUCCESS) {
  2421. comment = "Failed to unpack DBD_REGISTER_CTLD message";
  2422. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2423. rc = SLURM_ERROR;
  2424. goto end_it;
  2425. }
  2426. debug2("DBD_REGISTER_CTLD: called for %s(%u)",
  2427. slurmdbd_conn->cluster_name, register_ctld_msg->port);
  2428. debug2("slurmctld at ip:%s, port:%d",
  2429. slurmdbd_conn->ip, register_ctld_msg->port);
  2430. slurmdb_init_cluster_cond(&cluster_q, 0);
  2431. slurmdb_init_cluster_rec(&cluster, 0);
  2432. cluster_q.cluster_list = list_create(NULL);
  2433. list_append(cluster_q.cluster_list, slurmdbd_conn->cluster_name);
  2434. cluster.control_host = slurmdbd_conn->ip;
  2435. cluster.control_port = register_ctld_msg->port;
  2436. cluster.dimensions = register_ctld_msg->dimensions;
  2437. cluster.flags = register_ctld_msg->flags;
  2438. cluster.plugin_id_select = register_ctld_msg->plugin_id_select;
  2439. cluster.rpc_version = slurmdbd_conn->rpc_version;
  2440. list_msg.my_list = acct_storage_g_modify_clusters(
  2441. slurmdbd_conn->db_conn, *uid, &cluster_q, &cluster);
  2442. if (errno == EFAULT) {
  2443. comment = "Request to register was incomplete";
  2444. rc = SLURM_ERROR;
  2445. } else if (errno == ESLURM_ACCESS_DENIED) {
  2446. comment = "Your user doesn't have privilege to preform this action";
  2447. rc = ESLURM_ACCESS_DENIED;
  2448. } else if (errno == ESLURM_DB_CONNECTION) {
  2449. comment = slurm_strerror(errno);
  2450. rc = errno;
  2451. } else if (!list_msg.my_list || !list_count(list_msg.my_list)) {
  2452. comment = "This cluster hasn't been added to accounting yet";
  2453. rc = SLURM_ERROR;
  2454. }
  2455. if (list_msg.my_list)
  2456. list_destroy(list_msg.my_list);
  2457. list_destroy(cluster_q.cluster_list);
  2458. /*
  2459. * Outgoing message header must have flag set:
  2460. * out_msg.flags = SLURM_GLOBAL_AUTH_KEY;
  2461. */
  2462. #if 0
  2463. {
  2464. /* Code to validate communications back to slurmctld */
  2465. slurm_fd_t fd;
  2466. slurm_set_addr_char(&ctld_address, register_ctld_msg->port, ip);
  2467. fd = slurm_open_msg_conn(&ctld_address);
  2468. if (fd < 0) {
  2469. error("CONN: can not open socket back to slurmctld",
  2470. slurmdbd_conn->newsockfd);
  2471. } else {
  2472. slurm_msg_t out_msg;
  2473. slurm_msg_t_init(&out_msg);
  2474. out_msg.msg_type = REQUEST_PING;
  2475. out_msg.flags = SLURM_GLOBAL_AUTH_KEY;
  2476. slurm_send_node_msg(slurmdbd_conn->rpc_version,
  2477. fd, &out_msg);
  2478. /* We probably need to add matching recv_msg function
  2479. * for an arbitray fd or should these be fire
  2480. * and forget? */
  2481. slurm_close_stream(fd);
  2482. }
  2483. }
  2484. #endif
  2485. end_it:
  2486. if (rc == SLURM_SUCCESS)
  2487. slurmdbd_conn->ctld_port = register_ctld_msg->port;
  2488. slurmdbd_free_register_ctld_msg(register_ctld_msg);
  2489. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2490. rc, comment, DBD_REGISTER_CTLD);
  2491. return rc;
  2492. }
  2493. static int _remove_accounts(slurmdbd_conn_t *slurmdbd_conn,
  2494. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2495. {
  2496. int rc = SLURM_SUCCESS;
  2497. dbd_cond_msg_t *get_msg = NULL;
  2498. dbd_list_msg_t list_msg;
  2499. char *comment = NULL;
  2500. debug2("DBD_REMOVE_ACCOUNTS: called");
  2501. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2502. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2503. < SLURMDB_ADMIN_OPERATOR) {
  2504. comment = "Your user doesn't have privilege to preform this action";
  2505. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2506. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2507. ESLURM_ACCESS_DENIED,
  2508. comment, DBD_REMOVE_ACCOUNTS);
  2509. return ESLURM_ACCESS_DENIED;
  2510. }
  2511. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2512. DBD_REMOVE_ACCOUNTS,
  2513. in_buffer) != SLURM_SUCCESS) {
  2514. comment = "Failed to unpack DBD_REMOVE_ACCOUNTS message";
  2515. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2516. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2517. SLURM_ERROR,
  2518. comment, DBD_REMOVE_ACCOUNTS);
  2519. return SLURM_ERROR;
  2520. }
  2521. if (!(list_msg.my_list = acct_storage_g_remove_accounts(
  2522. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2523. if (errno == ESLURM_ACCESS_DENIED) {
  2524. comment = "Your user doesn't have privilege to preform this action";
  2525. rc = ESLURM_ACCESS_DENIED;
  2526. } else if (errno == SLURM_ERROR) {
  2527. comment = "Something was wrong with your query";
  2528. rc = SLURM_ERROR;
  2529. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2530. comment = "Request didn't affect anything";
  2531. rc = SLURM_SUCCESS;
  2532. } else if (errno == ESLURM_DB_CONNECTION) {
  2533. comment = slurm_strerror(errno);
  2534. rc = errno;
  2535. } else {
  2536. rc = errno;
  2537. if (!(comment = slurm_strerror(errno)))
  2538. comment = "Unknown issue";
  2539. }
  2540. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2541. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_ACCOUNTS);
  2542. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2543. rc, comment, DBD_REMOVE_ACCOUNTS);
  2544. return rc;
  2545. }
  2546. list_msg.return_code = errno;
  2547. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_ACCOUNTS);
  2548. *out_buffer = init_buf(1024);
  2549. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2550. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2551. DBD_GOT_LIST, *out_buffer);
  2552. if (list_msg.my_list)
  2553. list_destroy(list_msg.my_list);
  2554. return rc;
  2555. }
  2556. static int _remove_account_coords(slurmdbd_conn_t *slurmdbd_conn,
  2557. Buf in_buffer, Buf *out_buffer,
  2558. uint32_t *uid)
  2559. {
  2560. int rc = SLURM_SUCCESS;
  2561. dbd_acct_coord_msg_t *get_msg = NULL;
  2562. dbd_list_msg_t list_msg;
  2563. char *comment = NULL;
  2564. debug2("DBD_REMOVE_ACCOUNT_COORDS: called");
  2565. if (slurmdbd_unpack_acct_coord_msg(
  2566. &get_msg, slurmdbd_conn->rpc_version, in_buffer)
  2567. != SLURM_SUCCESS) {
  2568. comment = "Failed to unpack DBD_REMOVE_ACCOUNT_COORDS message";
  2569. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2570. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2571. SLURM_ERROR, comment,
  2572. DBD_ADD_ACCOUNT_COORDS);
  2573. return SLURM_ERROR;
  2574. }
  2575. /* All authentication needs to be done inside the plugin since we are
  2576. * unable to know what accounts this request is talking about
  2577. * until we process it through the database.
  2578. */
  2579. if (!(list_msg.my_list = acct_storage_g_remove_coord(
  2580. slurmdbd_conn->db_conn, *uid, get_msg->acct_list,
  2581. get_msg->cond))) {
  2582. if (errno == ESLURM_ACCESS_DENIED) {
  2583. comment = "Your user doesn't have privilege to preform this action";
  2584. rc = ESLURM_ACCESS_DENIED;
  2585. } else if (errno == SLURM_ERROR) {
  2586. comment = "Something was wrong with your query";
  2587. rc = SLURM_ERROR;
  2588. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2589. comment = "Request didn't affect anything";
  2590. rc = SLURM_SUCCESS;
  2591. } else if (errno == ESLURM_DB_CONNECTION) {
  2592. comment = slurm_strerror(errno);
  2593. rc = errno;
  2594. } else {
  2595. rc = errno;
  2596. if (!(comment = slurm_strerror(errno)))
  2597. comment = "Unknown issue";
  2598. }
  2599. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2600. slurmdbd_free_acct_coord_msg(get_msg);
  2601. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2602. rc, comment,
  2603. DBD_REMOVE_ACCOUNT_COORDS);
  2604. return rc;
  2605. }
  2606. list_msg.return_code = SLURM_SUCCESS;
  2607. slurmdbd_free_acct_coord_msg(get_msg);
  2608. *out_buffer = init_buf(1024);
  2609. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2610. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2611. DBD_GOT_LIST, *out_buffer);
  2612. if (list_msg.my_list)
  2613. list_destroy(list_msg.my_list);
  2614. return rc;
  2615. }
  2616. static int _remove_assocs(slurmdbd_conn_t *slurmdbd_conn,
  2617. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2618. {
  2619. int rc = SLURM_SUCCESS;
  2620. dbd_cond_msg_t *get_msg = NULL;
  2621. dbd_list_msg_t list_msg;
  2622. char *comment = NULL;
  2623. debug2("DBD_REMOVE_ASSOCS: called");
  2624. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2625. DBD_REMOVE_ASSOCS, in_buffer) !=
  2626. SLURM_SUCCESS) {
  2627. comment = "Failed to unpack DBD_REMOVE_ASSOCS message";
  2628. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2629. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2630. SLURM_ERROR,
  2631. comment, DBD_REMOVE_ASSOCS);
  2632. return SLURM_ERROR;
  2633. }
  2634. /* All authentication needs to be done inside the plugin since we are
  2635. * unable to know what accounts this request is talking about
  2636. * until we process it through the database.
  2637. */
  2638. if (!(list_msg.my_list = acct_storage_g_remove_associations(
  2639. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2640. if (errno == ESLURM_ACCESS_DENIED) {
  2641. comment = "Your user doesn't have privilege to preform this action";
  2642. rc = ESLURM_ACCESS_DENIED;
  2643. } else if (errno == SLURM_ERROR) {
  2644. comment = "Something was wrong with your query";
  2645. rc = SLURM_ERROR;
  2646. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2647. comment = "Request didn't affect anything";
  2648. rc = SLURM_SUCCESS;
  2649. } else if (errno == ESLURM_DB_CONNECTION) {
  2650. comment = slurm_strerror(errno);
  2651. rc = errno;
  2652. } else {
  2653. rc = errno;
  2654. if (!(comment = slurm_strerror(errno)))
  2655. comment = "Unknown issue";
  2656. }
  2657. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2658. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_ASSOCS);
  2659. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2660. rc, comment, DBD_REMOVE_ASSOCS);
  2661. return rc;
  2662. }
  2663. list_msg.return_code = errno;
  2664. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_ASSOCS);
  2665. *out_buffer = init_buf(1024);
  2666. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2667. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2668. DBD_GOT_LIST, *out_buffer);
  2669. if (list_msg.my_list)
  2670. list_destroy(list_msg.my_list);
  2671. return rc;
  2672. }
  2673. static int _remove_clusters(slurmdbd_conn_t *slurmdbd_conn,
  2674. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2675. {
  2676. int rc = SLURM_SUCCESS;
  2677. dbd_cond_msg_t *get_msg = NULL;
  2678. dbd_list_msg_t list_msg;
  2679. char *comment = NULL;
  2680. debug2("DBD_REMOVE_CLUSTERS: called");
  2681. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2682. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2683. < SLURMDB_ADMIN_SUPER_USER) {
  2684. comment = "Your user doesn't have privilege to preform this action";
  2685. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2686. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2687. ESLURM_ACCESS_DENIED,
  2688. comment, DBD_REMOVE_CLUSTERS);
  2689. return ESLURM_ACCESS_DENIED;
  2690. }
  2691. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2692. DBD_REMOVE_CLUSTERS,
  2693. in_buffer) != SLURM_SUCCESS) {
  2694. comment = "Failed to unpack DBD_REMOVE_CLUSTERS message";
  2695. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2696. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2697. SLURM_ERROR,
  2698. comment, DBD_REMOVE_CLUSTERS);
  2699. return SLURM_ERROR;
  2700. }
  2701. if (!(list_msg.my_list = acct_storage_g_remove_clusters(
  2702. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2703. if (errno == ESLURM_ACCESS_DENIED) {
  2704. comment = "Your user doesn't have privilege to preform this action";
  2705. rc = ESLURM_ACCESS_DENIED;
  2706. } else if (errno == SLURM_ERROR) {
  2707. comment = "Something was wrong with your query";
  2708. rc = SLURM_ERROR;
  2709. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2710. comment = "Request didn't affect anything";
  2711. rc = SLURM_SUCCESS;
  2712. } else if (errno == ESLURM_DB_CONNECTION) {
  2713. comment = slurm_strerror(errno);
  2714. rc = errno;
  2715. } else {
  2716. rc = errno;
  2717. if (!(comment = slurm_strerror(errno)))
  2718. comment = "Unknown issue";
  2719. }
  2720. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2721. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_CLUSTERS);
  2722. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2723. rc, comment, DBD_REMOVE_CLUSTERS);
  2724. return rc;
  2725. }
  2726. list_msg.return_code = errno;
  2727. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_CLUSTERS);
  2728. *out_buffer = init_buf(1024);
  2729. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2730. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2731. DBD_GOT_LIST, *out_buffer);
  2732. if (list_msg.my_list)
  2733. list_destroy(list_msg.my_list);
  2734. return rc;
  2735. }
  2736. static int _remove_qos(slurmdbd_conn_t *slurmdbd_conn,
  2737. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2738. {
  2739. int rc = SLURM_SUCCESS;
  2740. dbd_cond_msg_t *get_msg = NULL;
  2741. dbd_list_msg_t list_msg;
  2742. char *comment = NULL;
  2743. debug2("DBD_REMOVE_QOS: called");
  2744. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2745. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2746. < SLURMDB_ADMIN_SUPER_USER) {
  2747. comment = "Your user doesn't have privilege to preform this action";
  2748. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2749. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2750. ESLURM_ACCESS_DENIED,
  2751. comment, DBD_REMOVE_QOS);
  2752. return ESLURM_ACCESS_DENIED;
  2753. }
  2754. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2755. DBD_REMOVE_QOS,
  2756. in_buffer) != SLURM_SUCCESS) {
  2757. comment = "Failed to unpack DBD_REMOVE_QOS message";
  2758. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2759. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2760. SLURM_ERROR,
  2761. comment, DBD_REMOVE_QOS);
  2762. return SLURM_ERROR;
  2763. }
  2764. if (!(list_msg.my_list = acct_storage_g_remove_qos(
  2765. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2766. if (errno == ESLURM_ACCESS_DENIED) {
  2767. comment = "Your user doesn't have privilege to preform this action";
  2768. rc = ESLURM_ACCESS_DENIED;
  2769. } else if (errno == SLURM_ERROR) {
  2770. comment = "Something was wrong with your query";
  2771. rc = SLURM_ERROR;
  2772. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2773. comment = "Request didn't affect anything";
  2774. rc = SLURM_SUCCESS;
  2775. } else if (errno == ESLURM_DB_CONNECTION) {
  2776. comment = slurm_strerror(errno);
  2777. rc = errno;
  2778. } else {
  2779. rc = errno;
  2780. if (!(comment = slurm_strerror(errno)))
  2781. comment = "Unknown issue";
  2782. }
  2783. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2784. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_QOS);
  2785. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2786. rc, comment, DBD_REMOVE_QOS);
  2787. return rc;
  2788. }
  2789. list_msg.return_code = SLURM_SUCCESS;
  2790. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_QOS);
  2791. *out_buffer = init_buf(1024);
  2792. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2793. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2794. DBD_GOT_LIST, *out_buffer);
  2795. if (list_msg.my_list)
  2796. list_destroy(list_msg.my_list);
  2797. return rc;
  2798. }
  2799. static int _remove_users(slurmdbd_conn_t *slurmdbd_conn,
  2800. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2801. {
  2802. int rc = SLURM_SUCCESS;
  2803. dbd_cond_msg_t *get_msg = NULL;
  2804. dbd_list_msg_t list_msg;
  2805. char *comment = NULL;
  2806. debug2("DBD_REMOVE_USERS: called");
  2807. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2808. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2809. < SLURMDB_ADMIN_OPERATOR) {
  2810. comment = "Your user doesn't have privilege to preform this action";
  2811. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2812. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2813. ESLURM_ACCESS_DENIED,
  2814. comment, DBD_REMOVE_USERS);
  2815. return ESLURM_ACCESS_DENIED;
  2816. }
  2817. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2818. DBD_REMOVE_USERS, in_buffer) !=
  2819. SLURM_SUCCESS) {
  2820. comment = "Failed to unpack DBD_REMOVE_USERS message";
  2821. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2822. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2823. SLURM_ERROR,
  2824. comment, DBD_REMOVE_USERS);
  2825. return SLURM_ERROR;
  2826. }
  2827. if (!(list_msg.my_list = acct_storage_g_remove_users(
  2828. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2829. if (errno == ESLURM_ACCESS_DENIED) {
  2830. comment = "Your user doesn't have privilege to preform this action";
  2831. rc = ESLURM_ACCESS_DENIED;
  2832. } else if (errno == SLURM_ERROR) {
  2833. comment = "Something was wrong with your query";
  2834. rc = SLURM_ERROR;
  2835. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2836. comment = "Request didn't affect anything";
  2837. rc = SLURM_SUCCESS;
  2838. } else if (errno == ESLURM_DB_CONNECTION) {
  2839. comment = slurm_strerror(errno);
  2840. rc = errno;
  2841. } else {
  2842. rc = errno;
  2843. if (!(comment = slurm_strerror(errno)))
  2844. comment = "Unknown issue";
  2845. }
  2846. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2847. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_USERS);
  2848. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2849. rc, comment, DBD_REMOVE_USERS);
  2850. return rc;
  2851. }
  2852. list_msg.return_code = errno;
  2853. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_USERS);
  2854. *out_buffer = init_buf(1024);
  2855. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2856. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2857. DBD_GOT_LIST, *out_buffer);
  2858. if (list_msg.my_list)
  2859. list_destroy(list_msg.my_list);
  2860. return rc;
  2861. }
  2862. static int _remove_wckeys(slurmdbd_conn_t *slurmdbd_conn,
  2863. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2864. {
  2865. int rc = SLURM_SUCCESS;
  2866. dbd_cond_msg_t *get_msg = NULL;
  2867. dbd_list_msg_t list_msg;
  2868. char *comment = NULL;
  2869. debug2("DBD_REMOVE_WCKEYS: called");
  2870. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2871. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2872. < SLURMDB_ADMIN_SUPER_USER) {
  2873. comment = "Your user doesn't have privilege to preform this action";
  2874. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2875. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2876. ESLURM_ACCESS_DENIED,
  2877. comment, DBD_REMOVE_WCKEYS);
  2878. return ESLURM_ACCESS_DENIED;
  2879. }
  2880. if (slurmdbd_unpack_cond_msg(&get_msg, slurmdbd_conn->rpc_version,
  2881. DBD_REMOVE_WCKEYS,
  2882. in_buffer) != SLURM_SUCCESS) {
  2883. comment = "Failed to unpack DBD_REMOVE_WCKEYS message";
  2884. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2885. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2886. SLURM_ERROR,
  2887. comment, DBD_REMOVE_WCKEYS);
  2888. return SLURM_ERROR;
  2889. }
  2890. if (!(list_msg.my_list = acct_storage_g_remove_wckeys(
  2891. slurmdbd_conn->db_conn, *uid, get_msg->cond))) {
  2892. if (errno == ESLURM_ACCESS_DENIED) {
  2893. comment = "Your user doesn't have privilege to preform this action";
  2894. rc = ESLURM_ACCESS_DENIED;
  2895. } else if (errno == SLURM_ERROR) {
  2896. comment = "Something was wrong with your query";
  2897. rc = SLURM_ERROR;
  2898. } else if (errno == SLURM_NO_CHANGE_IN_DATA) {
  2899. comment = "Request didn't affect anything";
  2900. rc = SLURM_SUCCESS;
  2901. } else if (errno == ESLURM_DB_CONNECTION) {
  2902. comment = slurm_strerror(errno);
  2903. rc = errno;
  2904. } else {
  2905. rc = errno;
  2906. if (!(comment = slurm_strerror(errno)))
  2907. comment = "Unknown issue";
  2908. }
  2909. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2910. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_WCKEYS);
  2911. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2912. rc, comment, DBD_REMOVE_WCKEYS);
  2913. return rc;
  2914. }
  2915. list_msg.return_code = SLURM_SUCCESS;
  2916. slurmdbd_free_cond_msg(get_msg, DBD_REMOVE_WCKEYS);
  2917. *out_buffer = init_buf(1024);
  2918. pack16((uint16_t) DBD_GOT_LIST, *out_buffer);
  2919. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  2920. DBD_GOT_LIST, *out_buffer);
  2921. if (list_msg.my_list)
  2922. list_destroy(list_msg.my_list);
  2923. return rc;
  2924. }
  2925. static int _remove_reservation(slurmdbd_conn_t *slurmdbd_conn,
  2926. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2927. {
  2928. int rc = SLURM_SUCCESS;
  2929. dbd_rec_msg_t *rec_msg = NULL;
  2930. char *comment = NULL;
  2931. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)) {
  2932. comment = "DBD_REMOVE_RESV message from invalid uid";
  2933. error("DBD_REMOVE_RESV message from invalid uid %u", *uid);
  2934. rc = ESLURM_ACCESS_DENIED;
  2935. goto end_it;
  2936. }
  2937. if (slurmdbd_unpack_rec_msg(&rec_msg, slurmdbd_conn->rpc_version,
  2938. DBD_REMOVE_RESV,
  2939. in_buffer) != SLURM_SUCCESS) {
  2940. comment = "Failed to unpack DBD_REMOVE_RESV message";
  2941. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2942. rc = SLURM_ERROR;
  2943. goto end_it;
  2944. }
  2945. debug2("DBD_REMOVE_RESV: called");
  2946. rc = acct_storage_g_remove_reservation(slurmdbd_conn->db_conn,
  2947. rec_msg->rec);
  2948. end_it:
  2949. slurmdbd_free_rec_msg(rec_msg, DBD_REMOVE_RESV);
  2950. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2951. rc, comment, DBD_REMOVE_RESV);
  2952. return rc;
  2953. }
  2954. static int _roll_usage(slurmdbd_conn_t *slurmdbd_conn,
  2955. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  2956. {
  2957. dbd_roll_usage_msg_t *get_msg = NULL;
  2958. int rc = SLURM_SUCCESS;
  2959. char *comment = NULL;
  2960. info("DBD_ROLL_USAGE: called");
  2961. if ((*uid != slurmdbd_conf->slurm_user_id && *uid != 0)
  2962. && assoc_mgr_get_admin_level(slurmdbd_conn->db_conn, *uid)
  2963. < SLURMDB_ADMIN_OPERATOR) {
  2964. comment = "Your user doesn't have privilege to preform this action";
  2965. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2966. rc = ESLURM_ACCESS_DENIED;
  2967. goto end_it;
  2968. }
  2969. if (slurmdbd_unpack_roll_usage_msg(
  2970. &get_msg, slurmdbd_conn->rpc_version, in_buffer)
  2971. != SLURM_SUCCESS) {
  2972. comment = "Failed to unpack DBD_ROLL_USAGE message";
  2973. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  2974. rc = SLURM_ERROR;
  2975. goto end_it;
  2976. }
  2977. rc = acct_storage_g_roll_usage(slurmdbd_conn->db_conn,
  2978. get_msg->start, get_msg->end,
  2979. get_msg->archive_data);
  2980. end_it:
  2981. slurmdbd_free_roll_usage_msg(get_msg);
  2982. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  2983. rc, comment, DBD_ROLL_USAGE);
  2984. return rc;
  2985. }
  2986. static int _send_mult_job_start(slurmdbd_conn_t *slurmdbd_conn,
  2987. Buf in_buffer, Buf *out_buffer,
  2988. uint32_t *uid)
  2989. {
  2990. dbd_list_msg_t *get_msg = NULL;
  2991. dbd_list_msg_t list_msg;
  2992. char *comment = NULL;
  2993. ListIterator itr = NULL;
  2994. dbd_job_start_msg_t *job_start_msg;
  2995. dbd_id_rc_msg_t *id_rc_msg;
  2996. if (*uid != slurmdbd_conf->slurm_user_id) {
  2997. comment = "DBD_SEND_MULT_JOB_START message from invalid uid";
  2998. error("%s %u", comment, *uid);
  2999. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3000. ESLURM_ACCESS_DENIED, comment,
  3001. DBD_SEND_MULT_JOB_START);
  3002. return SLURM_ERROR;
  3003. }
  3004. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  3005. DBD_SEND_MULT_JOB_START,
  3006. in_buffer) != SLURM_SUCCESS) {
  3007. comment = "Failed to unpack DBD_SEND_MULT_JOB_START message";
  3008. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  3009. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3010. SLURM_ERROR, comment,
  3011. DBD_SEND_MULT_JOB_START);
  3012. return SLURM_ERROR;
  3013. }
  3014. list_msg.my_list = list_create(slurmdbd_free_id_rc_msg);
  3015. itr = list_iterator_create(get_msg->my_list);
  3016. while ((job_start_msg = list_next(itr))) {
  3017. id_rc_msg = xmalloc(sizeof(dbd_id_rc_msg_t));
  3018. list_append(list_msg.my_list, id_rc_msg);
  3019. _process_job_start(slurmdbd_conn, job_start_msg, id_rc_msg);
  3020. }
  3021. list_iterator_destroy(itr);
  3022. slurmdbd_free_list_msg(get_msg);
  3023. *out_buffer = init_buf(1024);
  3024. pack16((uint16_t) DBD_GOT_MULT_JOB_START, *out_buffer);
  3025. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  3026. DBD_GOT_MULT_JOB_START, *out_buffer);
  3027. if (list_msg.my_list)
  3028. list_destroy(list_msg.my_list);
  3029. return SLURM_SUCCESS;
  3030. }
  3031. static int _send_mult_msg(slurmdbd_conn_t *slurmdbd_conn,
  3032. Buf in_buffer, Buf *out_buffer,
  3033. uint32_t *uid)
  3034. {
  3035. dbd_list_msg_t *get_msg = NULL;
  3036. dbd_list_msg_t list_msg;
  3037. char *comment = NULL;
  3038. ListIterator itr = NULL;
  3039. Buf req_buf = NULL, ret_buf = NULL;
  3040. int rc = SLURM_SUCCESS;
  3041. if (*uid != slurmdbd_conf->slurm_user_id) {
  3042. comment = "DBD_SEND_MULT_MSG message from invalid uid";
  3043. error("%s %u", comment, *uid);
  3044. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3045. ESLURM_ACCESS_DENIED, comment,
  3046. DBD_SEND_MULT_MSG);
  3047. return SLURM_ERROR;
  3048. }
  3049. if (slurmdbd_unpack_list_msg(&get_msg, slurmdbd_conn->rpc_version,
  3050. DBD_SEND_MULT_MSG,
  3051. in_buffer) != SLURM_SUCCESS) {
  3052. comment = "Failed to unpack DBD_SEND_MULT_MSG message";
  3053. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  3054. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3055. SLURM_ERROR, comment,
  3056. DBD_SEND_MULT_MSG);
  3057. return SLURM_ERROR;
  3058. }
  3059. list_msg.my_list = list_create(slurmdbd_free_buffer);
  3060. itr = list_iterator_create(get_msg->my_list);
  3061. while ((req_buf = list_next(itr))) {
  3062. ret_buf = NULL;
  3063. rc = proc_req(slurmdbd_conn, get_buf_data(req_buf),
  3064. size_buf(req_buf), 0, &ret_buf, uid);
  3065. if (ret_buf)
  3066. list_append(list_msg.my_list, ret_buf);
  3067. if (rc != SLURM_SUCCESS)
  3068. break;
  3069. }
  3070. list_iterator_destroy(itr);
  3071. slurmdbd_free_list_msg(get_msg);
  3072. *out_buffer = init_buf(1024);
  3073. pack16((uint16_t) DBD_GOT_MULT_MSG, *out_buffer);
  3074. slurmdbd_pack_list_msg(&list_msg, slurmdbd_conn->rpc_version,
  3075. DBD_GOT_MULT_MSG, *out_buffer);
  3076. if (list_msg.my_list)
  3077. list_destroy(list_msg.my_list);
  3078. return SLURM_SUCCESS;
  3079. }
  3080. static int _step_complete(slurmdbd_conn_t *slurmdbd_conn,
  3081. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  3082. {
  3083. dbd_step_comp_msg_t *step_comp_msg = NULL;
  3084. struct step_record step;
  3085. struct job_record job;
  3086. struct job_details details;
  3087. int rc = SLURM_SUCCESS;
  3088. char *comment = NULL;
  3089. if (*uid != slurmdbd_conf->slurm_user_id) {
  3090. comment = "DBD_STEP_COMPLETE message from invalid uid";
  3091. error("%s %u", comment, *uid);
  3092. rc = ESLURM_ACCESS_DENIED;
  3093. goto end_it;
  3094. }
  3095. if (slurmdbd_unpack_step_complete_msg(&step_comp_msg,
  3096. slurmdbd_conn->rpc_version,
  3097. in_buffer) !=
  3098. SLURM_SUCCESS) {
  3099. comment = "Failed to unpack DBD_STEP_COMPLETE message";
  3100. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  3101. rc = SLURM_ERROR;
  3102. goto end_it;
  3103. }
  3104. debug2("DBD_STEP_COMPLETE: ID:%u.%u SUBMIT:%lu",
  3105. step_comp_msg->job_id, step_comp_msg->step_id,
  3106. (unsigned long) step_comp_msg->job_submit_time);
  3107. memset(&step, 0, sizeof(struct step_record));
  3108. memset(&job, 0, sizeof(struct job_record));
  3109. memset(&details, 0, sizeof(struct job_details));
  3110. job.assoc_id = step_comp_msg->assoc_id;
  3111. if (step_comp_msg->db_index != NO_VAL)
  3112. job.db_index = step_comp_msg->db_index;
  3113. job.end_time = step_comp_msg->end_time;
  3114. step.exit_code = step_comp_msg->exit_code;
  3115. step.jobacct = step_comp_msg->jobacct;
  3116. job.job_id = step_comp_msg->job_id;
  3117. step.requid = step_comp_msg->req_uid;
  3118. job.start_time = step_comp_msg->start_time;
  3119. details.submit_time = step_comp_msg->job_submit_time;
  3120. step.step_id = step_comp_msg->step_id;
  3121. step.cpu_count = step_comp_msg->total_cpus;
  3122. details.num_tasks = step_comp_msg->total_tasks;
  3123. job.details = &details;
  3124. step.job_ptr = &job;
  3125. rc = jobacct_storage_g_step_complete(slurmdbd_conn->db_conn, &step);
  3126. if (rc && errno == 740) /* meaning data is already there */
  3127. rc = SLURM_SUCCESS;
  3128. /* just incase this gets set we need to clear it */
  3129. xfree(job.wckey);
  3130. if (!slurmdbd_conn->ctld_port) {
  3131. info("DBD_STEP_COMPLETE: cluster not registered");
  3132. slurmdbd_conn->ctld_port =
  3133. clusteracct_storage_g_register_disconn_ctld(
  3134. slurmdbd_conn->db_conn, slurmdbd_conn->ip);
  3135. }
  3136. end_it:
  3137. slurmdbd_free_step_complete_msg(step_comp_msg);
  3138. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3139. rc, comment, DBD_STEP_COMPLETE);
  3140. return rc;
  3141. }
  3142. static int _step_start(slurmdbd_conn_t *slurmdbd_conn,
  3143. Buf in_buffer, Buf *out_buffer, uint32_t *uid)
  3144. {
  3145. dbd_step_start_msg_t *step_start_msg = NULL;
  3146. struct step_record step;
  3147. struct job_record job;
  3148. struct job_details details;
  3149. slurm_step_layout_t layout;
  3150. int rc = SLURM_SUCCESS;
  3151. char *comment = NULL;
  3152. if (*uid != slurmdbd_conf->slurm_user_id) {
  3153. comment = "DBD_STEP_START message from invalid uid";
  3154. error("%s %u", comment, *uid);
  3155. rc = ESLURM_ACCESS_DENIED;
  3156. goto end_it;
  3157. }
  3158. if (slurmdbd_unpack_step_start_msg(&step_start_msg,
  3159. slurmdbd_conn->rpc_version,
  3160. in_buffer) != SLURM_SUCCESS) {
  3161. comment = "Failed to unpack DBD_STEP_START message";
  3162. error("CONN:%u %s", slurmdbd_conn->newsockfd, comment);
  3163. rc = SLURM_ERROR;
  3164. goto end_it;
  3165. }
  3166. debug2("DBD_STEP_START: ID:%u.%u NAME:%s SUBMIT:%lu",
  3167. step_start_msg->job_id, step_start_msg->step_id,
  3168. step_start_msg->name,
  3169. (unsigned long) step_start_msg->job_submit_time);
  3170. memset(&step, 0, sizeof(struct step_record));
  3171. memset(&job, 0, sizeof(struct job_record));
  3172. memset(&details, 0, sizeof(struct job_details));
  3173. memset(&layout, 0, sizeof(slurm_step_layout_t));
  3174. job.assoc_id = step_start_msg->assoc_id;
  3175. if (step_start_msg->db_index != NO_VAL)
  3176. job.db_index = step_start_msg->db_index;
  3177. job.job_id = step_start_msg->job_id;
  3178. step.name = step_start_msg->name;
  3179. job.nodes = step_start_msg->nodes;
  3180. step.network = step_start_msg->node_inx;
  3181. step.start_time = step_start_msg->start_time;
  3182. details.submit_time = step_start_msg->job_submit_time;
  3183. step.step_id = step_start_msg->step_id;
  3184. step.cpu_count = step_start_msg->total_cpus;
  3185. details.num_tasks = step_start_msg->total_tasks;
  3186. layout.node_cnt = step_start_msg->node_cnt;
  3187. layout.task_dist = step_start_msg->task_dist;
  3188. job.details = &details;
  3189. step.job_ptr = &job;
  3190. step.step_layout = &layout;
  3191. rc = jobacct_storage_g_step_start(slurmdbd_conn->db_conn, &step);
  3192. if (rc && errno == 740) /* meaning data is already there */
  3193. rc = SLURM_SUCCESS;
  3194. /* just incase this gets set we need to clear it */
  3195. xfree(job.wckey);
  3196. if (!slurmdbd_conn->ctld_port) {
  3197. info("DBD_STEP_START: cluster not registered");
  3198. slurmdbd_conn->ctld_port =
  3199. clusteracct_storage_g_register_disconn_ctld(
  3200. slurmdbd_conn->db_conn, slurmdbd_conn->ip);
  3201. }
  3202. end_it:
  3203. slurmdbd_free_step_start_msg(step_start_msg);
  3204. *out_buffer = make_dbd_rc_msg(slurmdbd_conn->rpc_version,
  3205. rc, comment, DBD_STEP_START);
  3206. return rc;
  3207. }