[1] | 1 | /* $Id: drmaa.c 220 2010-05-24 17:42:49Z mmatloka $ */ |
---|
| 2 | /* |
---|
| 3 | * PSNC DRMAA for LL |
---|
| 4 | * Copyright (C) 2010 Poznan Supercomputing and Networking Center |
---|
| 5 | * |
---|
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
| 7 | * you may not use this file except in compliance with the License. |
---|
| 8 | * You may obtain a copy of the License at |
---|
| 9 | * |
---|
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 11 | * |
---|
| 12 | * Unless required by applicable law or agreed to in writing, software |
---|
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 15 | * See the License for the specific language governing permissions and |
---|
| 16 | * limitations under the License. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include <sys/timers.h> |
---|
| 20 | #include <sys/time.h> |
---|
| 21 | #include <sys/wait.h> |
---|
| 22 | #include <drmaa_utils/common.h> |
---|
| 23 | #include <drmaa_utils/drmaa.h> |
---|
| 24 | #include <drmaa_utils/drmaa_base.h> |
---|
| 25 | #include <drmaa_utils/iter.h> |
---|
| 26 | #include <drmaa_utils/drmaa_attrib.h> |
---|
| 27 | |
---|
| 28 | #include <ll_drmaa/session.h> |
---|
| 29 | |
---|
| 30 | #include <llapi.h> |
---|
| 31 | |
---|
| 32 | static char lldrmaa_version[50] = ""; |
---|
| 33 | |
---|
| 34 | static fsd_drmaa_session_t * |
---|
| 35 | lldrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact ) |
---|
| 36 | { |
---|
| 37 | return lldrmaa_session_new( contact ); |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | static fsd_template_t * |
---|
| 41 | lldrmaa_new_job_template( fsd_drmaa_singletone_t *self ) |
---|
| 42 | { |
---|
| 43 | return drmaa_template_new(); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | static const char * |
---|
| 47 | lldrmaa_get_contact( fsd_drmaa_singletone_t *self ) |
---|
| 48 | { |
---|
| 49 | return ""; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | static void |
---|
| 53 | lldrmaa_get_version( fsd_drmaa_singletone_t *self, |
---|
| 54 | unsigned *major, unsigned *minor ) |
---|
| 55 | { |
---|
| 56 | *major = 1; *minor = 0; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | static const char * |
---|
| 60 | lldrmaa_get_DRM_system( fsd_drmaa_singletone_t *self ) |
---|
| 61 | { |
---|
| 62 | if(lldrmaa_version[0] == '\0') /*no locks as drmaa_get_drm_system is usually called only once */ |
---|
| 63 | { |
---|
| 64 | fsd_snprintf(NULL, lldrmaa_version, sizeof(lldrmaa_version) - 1,"LoadLeveler %s", ll_version()); |
---|
| 65 | } |
---|
| 66 | return lldrmaa_version; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | static const char * |
---|
| 70 | lldrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self ) |
---|
| 71 | { |
---|
| 72 | return PACKAGE_STRING; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | fsd_iter_t * |
---|
| 76 | lldrmaa_get_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 77 | { |
---|
| 78 | static const char *attribute_names[] = { |
---|
| 79 | DRMAA_REMOTE_COMMAND, |
---|
| 80 | DRMAA_JS_STATE, |
---|
| 81 | DRMAA_WD, |
---|
| 82 | DRMAA_JOB_CATEGORY, |
---|
| 83 | DRMAA_NATIVE_SPECIFICATION, |
---|
| 84 | DRMAA_BLOCK_EMAIL, |
---|
| 85 | DRMAA_START_TIME, |
---|
| 86 | DRMAA_JOB_NAME, |
---|
| 87 | DRMAA_INPUT_PATH, |
---|
| 88 | DRMAA_OUTPUT_PATH, |
---|
| 89 | DRMAA_ERROR_PATH, |
---|
| 90 | DRMAA_JOIN_FILES, |
---|
| 91 | DRMAA_WCT_HLIMIT, |
---|
| 92 | DRMAA_WCT_SLIMIT, |
---|
| 93 | NULL |
---|
| 94 | }; |
---|
| 95 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | fsd_iter_t * |
---|
| 99 | lldrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 100 | { |
---|
| 101 | static const char *attribute_names[] = { |
---|
| 102 | DRMAA_V_ARGV, |
---|
| 103 | DRMAA_V_ENV, |
---|
| 104 | DRMAA_V_EMAIL, |
---|
| 105 | NULL |
---|
| 106 | }; |
---|
| 107 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | static int |
---|
| 111 | lldrmaa_wifexited( |
---|
| 112 | int *exited, int stat, |
---|
| 113 | char *error_diagnosis, size_t error_diag_len |
---|
| 114 | ) |
---|
| 115 | { |
---|
| 116 | *exited = WIFEXITED(stat); |
---|
| 117 | return DRMAA_ERRNO_SUCCESS; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static int |
---|
| 121 | lldrmaa_wexitstatus( |
---|
| 122 | int *exit_status, int stat, |
---|
| 123 | char *error_diagnosis, size_t error_diag_len |
---|
| 124 | ) |
---|
| 125 | { |
---|
| 126 | *exit_status = WEXITSTATUS(stat); |
---|
| 127 | return DRMAA_ERRNO_SUCCESS; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | static int |
---|
| 131 | lldrmaa_wifsignaled( |
---|
| 132 | int *signaled, int stat, |
---|
| 133 | char *error_diagnosis, size_t error_diag_len |
---|
| 134 | ) |
---|
| 135 | { |
---|
| 136 | *signaled = WIFSIGNALED(stat); |
---|
| 137 | return DRMAA_ERRNO_SUCCESS; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | static int |
---|
| 141 | lldrmaa_wtermsig( |
---|
| 142 | char *signal, size_t signal_len, int stat, |
---|
| 143 | char *error_diagnosis, size_t error_diag_len |
---|
| 144 | ) |
---|
| 145 | { |
---|
| 146 | int sig = WTERMSIG(stat); |
---|
| 147 | strlcpy( signal, fsd_strsignal(sig), signal_len ); |
---|
| 148 | return DRMAA_ERRNO_SUCCESS; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | static int |
---|
| 152 | lldrmaa_wcoredump( |
---|
| 153 | int *core_dumped, int stat, |
---|
| 154 | char *error_diagnosis, size_t error_diag_len |
---|
| 155 | ) |
---|
| 156 | { |
---|
| 157 | *core_dumped = ((stat)&0200); |
---|
| 158 | return DRMAA_ERRNO_SUCCESS; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | static int |
---|
| 162 | lldrmaa_wifaborted( |
---|
| 163 | int *aborted, int stat, |
---|
| 164 | char *error_diagnosis, size_t error_diag_len |
---|
| 165 | ) |
---|
| 166 | { |
---|
| 167 | *aborted = (stat == -1); |
---|
| 168 | return DRMAA_ERRNO_SUCCESS; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | fsd_drmaa_singletone_t _fsd_drmaa_singletone = { |
---|
| 173 | NULL, |
---|
| 174 | FSD_MUTEX_INITIALIZER, |
---|
| 175 | |
---|
| 176 | lldrmaa_new_session, |
---|
| 177 | lldrmaa_new_job_template, |
---|
| 178 | |
---|
| 179 | lldrmaa_get_contact, |
---|
| 180 | lldrmaa_get_version, |
---|
| 181 | lldrmaa_get_DRM_system, |
---|
| 182 | lldrmaa_get_DRMAA_implementation, |
---|
| 183 | |
---|
| 184 | lldrmaa_get_attribute_names, |
---|
| 185 | lldrmaa_get_vector_attribute_names, |
---|
| 186 | |
---|
| 187 | lldrmaa_wifexited, |
---|
| 188 | lldrmaa_wexitstatus, |
---|
| 189 | lldrmaa_wifsignaled, |
---|
| 190 | lldrmaa_wtermsig, |
---|
| 191 | lldrmaa_wcoredump, |
---|
| 192 | lldrmaa_wifaborted |
---|
| 193 | }; |
---|
| 194 | |
---|