1 | /* $Id: drmaa.c 351 2010-10-01 13:14:55Z mamonski $ */ |
---|
2 | /* |
---|
3 | * PSNC DRMAA for SLURM |
---|
4 | * Copyright (C) 2010 Poznan Supercomputing and Networking Center |
---|
5 | * |
---|
6 | * This program is free software: you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation, either version 3 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | |
---|
20 | #include <string.h> |
---|
21 | #include <sys/time.h> |
---|
22 | #include <sys/wait.h> |
---|
23 | |
---|
24 | #include <drmaa_utils/common.h> |
---|
25 | #include <drmaa_utils/compat.h> |
---|
26 | #include <drmaa_utils/drmaa.h> |
---|
27 | #include <drmaa_utils/drmaa_base.h> |
---|
28 | #include <drmaa_utils/iter.h> |
---|
29 | #include <drmaa_utils/drmaa_attrib.h> |
---|
30 | |
---|
31 | #include <slurm_drmaa/session.h> |
---|
32 | #include <slurm/slurm.h> |
---|
33 | |
---|
34 | static char slurmdrmaa_version[50] = ""; |
---|
35 | |
---|
36 | static fsd_drmaa_session_t * |
---|
37 | slurmdrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact ) |
---|
38 | { |
---|
39 | return slurmdrmaa_session_new( contact ); |
---|
40 | } |
---|
41 | |
---|
42 | static fsd_template_t * |
---|
43 | slurmdrmaa_new_job_template( fsd_drmaa_singletone_t *self ) |
---|
44 | { |
---|
45 | return drmaa_template_new(); |
---|
46 | } |
---|
47 | |
---|
48 | static const char * |
---|
49 | slurmdrmaa_get_contact( fsd_drmaa_singletone_t *self ) |
---|
50 | { |
---|
51 | return ""; |
---|
52 | } |
---|
53 | |
---|
54 | static void |
---|
55 | slurmdrmaa_get_version( fsd_drmaa_singletone_t *self, |
---|
56 | unsigned *major, unsigned *minor ) |
---|
57 | { |
---|
58 | *major = 1; *minor = 0; |
---|
59 | } |
---|
60 | |
---|
61 | static const char * |
---|
62 | slurmdrmaa_get_DRM_system( fsd_drmaa_singletone_t *self ) |
---|
63 | { |
---|
64 | if(slurmdrmaa_version[0] == '\0') /*no locks as drmaa_get_drm_system is usually called only once */ |
---|
65 | { |
---|
66 | slurm_ctl_conf_t * conf_info_msg_ptr = NULL; |
---|
67 | if ( slurm_load_ctl_conf ((time_t) NULL, &conf_info_msg_ptr ) == -1 ) |
---|
68 | { |
---|
69 | fsd_log_error(("slurm_load_ctl_conf error: %s",slurm_strerror(slurm_get_errno()))); |
---|
70 | fsd_snprintf(NULL, slurmdrmaa_version, sizeof(slurmdrmaa_version)-1,"SLURM"); |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | fsd_snprintf(NULL, slurmdrmaa_version, sizeof(slurmdrmaa_version)-1,"SLURM %s", conf_info_msg_ptr->version); |
---|
75 | slurm_free_ctl_conf (conf_info_msg_ptr); |
---|
76 | } |
---|
77 | } |
---|
78 | return slurmdrmaa_version; |
---|
79 | } |
---|
80 | |
---|
81 | static const char * |
---|
82 | slurmdrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self ) |
---|
83 | { |
---|
84 | return PACKAGE_STRING; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | fsd_iter_t * |
---|
89 | slurmdrmaa_get_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
90 | { |
---|
91 | static const char *attribute_names[] = { |
---|
92 | DRMAA_REMOTE_COMMAND, |
---|
93 | DRMAA_JS_STATE, |
---|
94 | DRMAA_WD, |
---|
95 | DRMAA_JOB_CATEGORY, |
---|
96 | DRMAA_NATIVE_SPECIFICATION, |
---|
97 | DRMAA_BLOCK_EMAIL, |
---|
98 | DRMAA_START_TIME, |
---|
99 | DRMAA_JOB_NAME, |
---|
100 | DRMAA_INPUT_PATH, |
---|
101 | DRMAA_OUTPUT_PATH, |
---|
102 | DRMAA_ERROR_PATH, |
---|
103 | DRMAA_JOIN_FILES, |
---|
104 | DRMAA_WCT_HLIMIT, |
---|
105 | NULL |
---|
106 | }; |
---|
107 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
108 | } |
---|
109 | |
---|
110 | fsd_iter_t * |
---|
111 | slurmdrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
112 | { |
---|
113 | static const char *attribute_names[] = { |
---|
114 | DRMAA_V_ARGV, |
---|
115 | DRMAA_V_ENV, |
---|
116 | DRMAA_V_EMAIL, |
---|
117 | NULL |
---|
118 | }; |
---|
119 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
120 | } |
---|
121 | |
---|
122 | static int |
---|
123 | slurmdrmaa_wifexited( |
---|
124 | int *exited, int stat, |
---|
125 | char *error_diagnosis, size_t error_diag_len |
---|
126 | ) |
---|
127 | { |
---|
128 | /*bool run; |
---|
129 | int exit_status; |
---|
130 | run = ((stat & 0xff) == 0); |
---|
131 | exit_status = ((stat & 0xff00) >> 8) & 0xff; |
---|
132 | *exited = run && (exit_status <= 128);*/ |
---|
133 | *exited = WIFEXITED(stat); |
---|
134 | return DRMAA_ERRNO_SUCCESS; |
---|
135 | } |
---|
136 | |
---|
137 | static int |
---|
138 | slurmdrmaa_wexitstatus( |
---|
139 | int *exit_status, int stat, |
---|
140 | char *error_diagnosis, size_t error_diag_len |
---|
141 | ) |
---|
142 | { |
---|
143 | /**exit_status = ((stat & 0xff00) >> 8) & 0xff;*/ |
---|
144 | *exit_status = WEXITSTATUS(stat); |
---|
145 | return DRMAA_ERRNO_SUCCESS; |
---|
146 | } |
---|
147 | |
---|
148 | static int |
---|
149 | slurmdrmaa_wifsignaled( |
---|
150 | int *signaled, int stat, |
---|
151 | char *error_diagnosis, size_t error_diag_len |
---|
152 | ) |
---|
153 | { |
---|
154 | *signaled = ((stat & 0xff00) >> 8) >= 128; |
---|
155 | /**signaled = WIFSIGNALED(stat);*/ |
---|
156 | return DRMAA_ERRNO_SUCCESS; |
---|
157 | } |
---|
158 | |
---|
159 | static int |
---|
160 | slurmdrmaa_wtermsig( |
---|
161 | char *signal, size_t signal_len, int stat, |
---|
162 | char *error_diagnosis, size_t error_diag_len |
---|
163 | ) |
---|
164 | { |
---|
165 | int sig = ((stat & 0xff00) >> 8) - 128; |
---|
166 | strlcpy( signal, fsd_strsignal(sig), signal_len ); |
---|
167 | /*int sig = WTERMSIG(stat); |
---|
168 | strlcpy( signal, fsd_strsignal(sig), signal_len );*/ |
---|
169 | return DRMAA_ERRNO_SUCCESS; |
---|
170 | } |
---|
171 | |
---|
172 | static int |
---|
173 | slurmdrmaa_wcoredump( |
---|
174 | int *core_dumped, int stat, |
---|
175 | char *error_diagnosis, size_t error_diag_len |
---|
176 | ) |
---|
177 | { |
---|
178 | /**core_dumped = 0;*/ |
---|
179 | *core_dumped = ((stat)&0200); |
---|
180 | return DRMAA_ERRNO_SUCCESS; |
---|
181 | } |
---|
182 | |
---|
183 | static int |
---|
184 | slurmdrmaa_wifaborted( |
---|
185 | int *aborted, int stat, |
---|
186 | char *error_diagnosis, size_t error_diag_len |
---|
187 | ) |
---|
188 | { |
---|
189 | *aborted = ((stat & 0x01) != 0); |
---|
190 | return DRMAA_ERRNO_SUCCESS; |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | fsd_drmaa_singletone_t _fsd_drmaa_singletone = { |
---|
195 | NULL, |
---|
196 | FSD_MUTEX_INITIALIZER, |
---|
197 | |
---|
198 | slurmdrmaa_new_session, |
---|
199 | slurmdrmaa_new_job_template, |
---|
200 | |
---|
201 | slurmdrmaa_get_contact, |
---|
202 | slurmdrmaa_get_version, |
---|
203 | slurmdrmaa_get_DRM_system, |
---|
204 | slurmdrmaa_get_DRMAA_implementation, |
---|
205 | |
---|
206 | slurmdrmaa_get_attribute_names, |
---|
207 | slurmdrmaa_get_vector_attribute_names, |
---|
208 | |
---|
209 | slurmdrmaa_wifexited, |
---|
210 | slurmdrmaa_wexitstatus, |
---|
211 | slurmdrmaa_wifsignaled, |
---|
212 | slurmdrmaa_wtermsig, |
---|
213 | slurmdrmaa_wcoredump, |
---|
214 | slurmdrmaa_wifaborted |
---|
215 | }; |
---|