1 /*****************************************************************************\
2  **  spawn.c - PMI job spawn handling
3  *****************************************************************************
4  *  Copyright (C) 2011-2012 National University of Defense Technology.
5  *  Written by Hongjia Cao <hjcao@nudt.edu.cn>.
6  *  All rights reserved.
7  *
8  *  This file is part of Slurm, a resource management program.
9  *  For details, see <https://slurm.schedmd.com/>.
10  *  Please also read the included file: DISCLAIMER.
11  *
12  *  Slurm is free software; you can redistribute it and/or modify it under
13  *  the terms of the GNU General Public License as published by the Free
14  *  Software Foundation; either version 2 of the License, or (at your option)
15  *  any later version.
16  *
17  *  In addition, as a special exception, the copyright holders give permission
18  *  to link the code of portions of this program with the OpenSSL library under
19  *  certain conditions as described in each individual source file, and
20  *  distribute linked combinations including the two. You must obey the GNU
21  *  General Public License in all respects for all of the code used other than
22  *  OpenSSL. If you modify file(s) with this exception, you may extend this
23  *  exception to your version of the file(s), but you are not obligated to do
24  *  so. If you do not wish to do so, delete this exception statement from your
25  *  version.  If you delete this exception statement from all source files in
26  *  the program, then also delete it here.
27  *
28  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
29  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
30  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
31  *  details.
32  *
33  *  You should have received a copy of the GNU General Public License along
34  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
35  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
36 \*****************************************************************************/
37 
38 #ifndef _SPAWN_H
39 #define _SPAWN_H
40 
41 #include <inttypes.h>
42 
43 #include "src/common/pack.h"
44 
45 typedef struct spawn_subcmd {
46 	char *cmd;
47 	uint32_t max_procs;
48 	uint32_t argc;
49 	char **argv;
50 	uint32_t info_cnt;
51 	char **info_keys;
52 	char **info_vals;
53 } spawn_subcmd_t;
54 
55 typedef struct spawn_req {
56 	uint32_t seq;
57 	char *from_node;
58 	uint32_t subcmd_cnt;
59 	uint32_t preput_cnt;
60 	char **pp_keys;
61 	char **pp_vals;
62 	spawn_subcmd_t **subcmds;
63 	/* TODO: Slurm specific job control info */
64 } spawn_req_t;
65 
66 typedef struct spawn_resp {
67 	uint32_t seq;
68 	int rc;
69 	char *jobid;
70 	uint16_t pmi_port;
71 	uint32_t error_cnt;
72 	int *error_codes;
73 } spawn_resp_t;
74 
75 extern spawn_subcmd_t *spawn_subcmd_new(void);
76 extern void spawn_subcmd_free(spawn_subcmd_t *subcmd);
77 extern spawn_req_t *spawn_req_new(void);
78 extern void spawn_req_free(spawn_req_t *req);
79 extern void spawn_req_pack(spawn_req_t *req, Buf buf);
80 extern int  spawn_req_unpack(spawn_req_t **req_ptr, Buf buf);
81 extern int  spawn_req_send_to_srun(spawn_req_t *req, spawn_resp_t **resp_ptr);
82 
83 extern spawn_resp_t *spawn_resp_new(void);
84 extern void spawn_resp_free(spawn_resp_t *resp);
85 extern void spawn_resp_pack(spawn_resp_t *resp, Buf buf);
86 extern int  spawn_resp_unpack(spawn_resp_t **resp_ptr, Buf buf);
87 extern int  spawn_resp_send_to_stepd(spawn_resp_t *resp, char **node);
88 extern int  spawn_resp_send_to_fd(spawn_resp_t *resp, int fd);
89 extern int  spawn_resp_send_to_srun(spawn_resp_t *resp);
90 
91 extern int  spawn_psr_enqueue(uint32_t seq, int fd, int lrank,
92 			      char *from_node);
93 extern int  spawn_psr_dequeue(uint32_t seq, int *fd, int *lrank,
94 			      char **from_node);
95 
96 extern uint32_t spawn_seq_next(void);
97 
98 extern int  spawn_job_do_spawn(spawn_req_t *req);
99 extern void spawn_job_wait(void);
100 
101 
102 #endif	/* _SPAWN_H */
103