Beispiel #1
0
static int lua_script_valid_in_context (spank_t sp, struct lua_script *script)
{
    int valid = 1;

#if HAVE_S_CTX_SLURMD
    if (spank_context() == S_CTX_SLURMD) {
        lua_getglobal (script->L, "slurm_spank_slurmd_init");
        lua_getglobal (script->L, "slurm_spank_slurmd_exit");
        if (lua_isnil (script->L, -1) && lua_isnil (script->L, -2))
            valid = 0;
        lua_pop (script->L, 2);
    }
#endif
#if HAVE_S_CTX_JOB_SCRIPT
    if (spank_context() == S_CTX_JOB_SCRIPT) {
        lua_getglobal (script->L, "slurm_spank_job_prolog");
        lua_getglobal (script->L, "slurm_spank_job_epilog");
        if (lua_isnil (script->L, -1) && lua_isnil (script->L, -2))
            valid = 0;
        lua_pop (script->L, 2);
    }
#endif

    return (valid);
}
Beispiel #2
0
static int l_spank_context (lua_State *L)
{
    switch (spank_context ()) {
    case S_CTX_LOCAL:
        lua_pushstring (L, "local");
        break;
    case S_CTX_REMOTE:
        lua_pushstring (L, "remote");
        break;
    case S_CTX_ALLOCATOR:
        lua_pushstring (L, "allocator");
        break;
#if HAVE_S_CTX_SLURMD
    case S_CTX_SLURMD:
        lua_pushstring (L, "slurmd");
        break;
#endif
#if HAVE_S_CTX_JOB_SCRIPT
    case S_CTX_JOB_SCRIPT:
        lua_pushstring (L, "job_script");
        break;
#endif
    case S_CTX_ERROR:
    default:
        lua_pushstring (L, "error");
        break;
    }

    return (1);
}
Beispiel #3
0
int slurm_spank_init(spank_t spank, int ac, char **av)
{
    int i;
    struct spank_option image_opt,
                        bind_opt;

    memset(&image_opt, '\0', sizeof(image_opt));
    image_opt.name = "singularity-image";
    image_opt.arginfo = "[path]";
    image_opt.usage = "Specify a path to a Singularity image, directory tree, "
                      "or Docker image";
    image_opt.has_arg = 1;
    image_opt.val = 0;
    image_opt.cb = determine_image;
    if (ESPANK_SUCCESS != spank_option_register(spank, &image_opt)) {
        slurm_error("spank/%s: Unable to register a new option.",
                    plugin_name);
        return -1;
    }

    memset(&bind_opt, '\0', sizeof(bind_opt));
    bind_opt.name = "singularity-bind";
    bind_opt.arginfo = "[path || src:dest],...";
    bind_opt.usage = "Specify a user-bind path specification.  Can either be "
                     "a path or a src:dest pair, specifying the bind mount to "
                     "perform";
    bind_opt.has_arg = 1;
    bind_opt.val = 0;
    bind_opt.cb = determine_bind;
    if (ESPANK_SUCCESS != spank_option_register(spank, &bind_opt)) {
        slurm_error("spank/%s: Unable to register a new option.",
                    plugin_name);
        return -1;
    }

    // Make this a no-op except when starting the task.
    if (spank_context() == S_CTX_ALLOCATOR || (spank_remote(spank) != 1)) {
        return 0;
    }

    for (i = 0; i < ac; i++) {
        if (strncmp ("default_image=", av[i], 14) == 0) {
            const char *optarg = av[i] + 14;
            job_image = strdup(optarg);
        } else {
            slurm_error ("spank/%s: Invalid option: %s", av[i], plugin_name);
        }
    }

    return 0;
}
Beispiel #4
0
/* Display a message through Slurm SPANK system. */
int _display_msg(spank_t sp, char const *caller, char const *msg) {
    uid_t uid = getuid();
    gid_t gid = getgid();
    char hostname[1024];

    int ctx = spank_context();
    char *ctx_str[] = {"ERROR", "LOCAL", "REMOTE", "ALLOCATOR", "SLURMD", "JOB_SCRIPT"};

    hostname[1023] = '\0';
    gethostname(hostname, 1023);

    if (msg && msg[0]) {
        slurm_info("%s: %s, %s, %s (uid=%d, gid=%d): %s", myname, ctx_str[ctx], hostname, caller, uid, gid, msg);
    }
    else {
        slurm_info("%s: %s, %s, %s (uid=%d, gid=%d)", myname, ctx_str[ctx], hostname, caller, uid, gid);
    }

    return 0;
}