[20] | 1 | /* $Id$ */ |
---|
[1] | 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/time.h> |
---|
| 20 | #include <sys/wait.h> |
---|
| 21 | #include <drmaa_utils/common.h> |
---|
| 22 | #include <drmaa_utils/drmaa.h> |
---|
| 23 | #include <drmaa_utils/drmaa_base.h> |
---|
| 24 | #include <drmaa_utils/iter.h> |
---|
| 25 | #include <drmaa_utils/drmaa_attrib.h> |
---|
| 26 | |
---|
| 27 | #include <ll_drmaa/session.h> |
---|
| 28 | |
---|
| 29 | #include <llapi.h> |
---|
| 30 | |
---|
| 31 | static char lldrmaa_version[50] = ""; |
---|
| 32 | |
---|
| 33 | static fsd_drmaa_session_t * |
---|
| 34 | lldrmaa_new_session( fsd_drmaa_singletone_t *self, const char *contact ) |
---|
| 35 | { |
---|
| 36 | return lldrmaa_session_new( contact ); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | static fsd_template_t * |
---|
| 40 | lldrmaa_new_job_template( fsd_drmaa_singletone_t *self ) |
---|
| 41 | { |
---|
| 42 | return drmaa_template_new(); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | static const char * |
---|
| 46 | lldrmaa_get_contact( fsd_drmaa_singletone_t *self ) |
---|
| 47 | { |
---|
| 48 | return ""; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | static void |
---|
| 52 | lldrmaa_get_version( fsd_drmaa_singletone_t *self, |
---|
| 53 | unsigned *major, unsigned *minor ) |
---|
| 54 | { |
---|
| 55 | *major = 1; *minor = 0; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | static const char * |
---|
| 59 | lldrmaa_get_DRM_system( fsd_drmaa_singletone_t *self ) |
---|
| 60 | { |
---|
| 61 | if(lldrmaa_version[0] == '\0') /*no locks as drmaa_get_drm_system is usually called only once */ |
---|
| 62 | { |
---|
| 63 | fsd_snprintf(NULL, lldrmaa_version, sizeof(lldrmaa_version) - 1,"LoadLeveler %s", ll_version()); |
---|
| 64 | } |
---|
| 65 | return lldrmaa_version; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | static const char * |
---|
| 69 | lldrmaa_get_DRMAA_implementation( fsd_drmaa_singletone_t *self ) |
---|
| 70 | { |
---|
| 71 | return PACKAGE_STRING; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | fsd_iter_t * |
---|
| 75 | lldrmaa_get_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 76 | { |
---|
| 77 | static const char *attribute_names[] = { |
---|
| 78 | DRMAA_REMOTE_COMMAND, |
---|
| 79 | DRMAA_JS_STATE, |
---|
| 80 | DRMAA_WD, |
---|
| 81 | DRMAA_JOB_CATEGORY, |
---|
| 82 | DRMAA_NATIVE_SPECIFICATION, |
---|
| 83 | DRMAA_BLOCK_EMAIL, |
---|
| 84 | DRMAA_START_TIME, |
---|
| 85 | DRMAA_JOB_NAME, |
---|
| 86 | DRMAA_INPUT_PATH, |
---|
| 87 | DRMAA_OUTPUT_PATH, |
---|
| 88 | DRMAA_ERROR_PATH, |
---|
| 89 | DRMAA_JOIN_FILES, |
---|
| 90 | DRMAA_WCT_HLIMIT, |
---|
| 91 | DRMAA_WCT_SLIMIT, |
---|
| 92 | NULL |
---|
| 93 | }; |
---|
| 94 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | fsd_iter_t * |
---|
| 98 | lldrmaa_get_vector_attribute_names( fsd_drmaa_singletone_t *self ) |
---|
| 99 | { |
---|
| 100 | static const char *attribute_names[] = { |
---|
| 101 | DRMAA_V_ARGV, |
---|
| 102 | DRMAA_V_ENV, |
---|
| 103 | DRMAA_V_EMAIL, |
---|
| 104 | NULL |
---|
| 105 | }; |
---|
| 106 | return fsd_iter_new_const( attribute_names, -1 ); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | static int |
---|
| 110 | lldrmaa_wifexited( |
---|
| 111 | int *exited, int stat, |
---|
| 112 | char *error_diagnosis, size_t error_diag_len |
---|
| 113 | ) |
---|
| 114 | { |
---|
| 115 | *exited = WIFEXITED(stat); |
---|
| 116 | return DRMAA_ERRNO_SUCCESS; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | static int |
---|
| 120 | lldrmaa_wexitstatus( |
---|
| 121 | int *exit_status, int stat, |
---|
| 122 | char *error_diagnosis, size_t error_diag_len |
---|
| 123 | ) |
---|
| 124 | { |
---|
| 125 | *exit_status = WEXITSTATUS(stat); |
---|
| 126 | return DRMAA_ERRNO_SUCCESS; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | static int |
---|
| 130 | lldrmaa_wifsignaled( |
---|
| 131 | int *signaled, int stat, |
---|
| 132 | char *error_diagnosis, size_t error_diag_len |
---|
| 133 | ) |
---|
| 134 | { |
---|
| 135 | *signaled = WIFSIGNALED(stat); |
---|
| 136 | return DRMAA_ERRNO_SUCCESS; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | static int |
---|
| 140 | lldrmaa_wtermsig( |
---|
| 141 | char *signal, size_t signal_len, int stat, |
---|
| 142 | char *error_diagnosis, size_t error_diag_len |
---|
| 143 | ) |
---|
| 144 | { |
---|
| 145 | int sig = WTERMSIG(stat); |
---|
| 146 | strlcpy( signal, fsd_strsignal(sig), signal_len ); |
---|
| 147 | return DRMAA_ERRNO_SUCCESS; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | static int |
---|
| 151 | lldrmaa_wcoredump( |
---|
| 152 | int *core_dumped, int stat, |
---|
| 153 | char *error_diagnosis, size_t error_diag_len |
---|
| 154 | ) |
---|
| 155 | { |
---|
| 156 | *core_dumped = ((stat)&0200); |
---|
| 157 | return DRMAA_ERRNO_SUCCESS; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | static int |
---|
| 161 | lldrmaa_wifaborted( |
---|
| 162 | int *aborted, int stat, |
---|
| 163 | char *error_diagnosis, size_t error_diag_len |
---|
| 164 | ) |
---|
| 165 | { |
---|
| 166 | *aborted = (stat == -1); |
---|
| 167 | return DRMAA_ERRNO_SUCCESS; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | fsd_drmaa_singletone_t _fsd_drmaa_singletone = { |
---|
| 172 | NULL, |
---|
| 173 | FSD_MUTEX_INITIALIZER, |
---|
| 174 | |
---|
| 175 | lldrmaa_new_session, |
---|
| 176 | lldrmaa_new_job_template, |
---|
| 177 | |
---|
| 178 | lldrmaa_get_contact, |
---|
| 179 | lldrmaa_get_version, |
---|
| 180 | lldrmaa_get_DRM_system, |
---|
| 181 | lldrmaa_get_DRMAA_implementation, |
---|
| 182 | |
---|
| 183 | lldrmaa_get_attribute_names, |
---|
| 184 | lldrmaa_get_vector_attribute_names, |
---|
| 185 | |
---|
| 186 | lldrmaa_wifexited, |
---|
| 187 | lldrmaa_wexitstatus, |
---|
| 188 | lldrmaa_wifsignaled, |
---|
| 189 | lldrmaa_wtermsig, |
---|
| 190 | lldrmaa_wcoredump, |
---|
| 191 | lldrmaa_wifaborted |
---|
| 192 | }; |
---|
| 193 | |
---|