Ejemplo n.º 1
0
/*
 *  Called from both srun and slurmd.
 */
int slurm_spank_init_post_opt (spank_t sp, int ac, char **av)
{
	int rc = ESPANK_SUCCESS;

	if (spank_remote (sp))
		return (0);

	if (io_style == CACHE_IO) {
		slurm_debug("cache_io option");
		rc = spank_set_job_env("O_DIRECT", "0", 1);
	} else if (io_style == DIRECT_IO) {
		slurm_debug("direct_io option");
		rc = spank_set_job_env("O_DIRECT", "1", 1);
	} else if (getenv("SLURM_CACHE_IO")) {
		slurm_debug("cache_io env var");
		rc = spank_set_job_env("O_DIRECT", "0", 1);
	} else if (getenv("SLURM_DIRECT_IO")) {
		slurm_debug("direct_io env var");
		rc = spank_set_job_env("O_DIRECT", "1", 1);
	}
	if (rc != ESPANK_SUCCESS)
		slurm_error("spank_setjob_env: %s", spank_strerror(rc));

	return (0);
}
Ejemplo n.º 2
0
static int l_spank_log_msg (lua_State *L)
{
    int level = luaL_checknumber (L, 1);
    const char *msg;

    msg = l_string_sanitized (L);
    if (!msg)
        return (0);

    if (level == -1) {
        slurm_error (msg);
        lua_pushnumber (L, -1);
        return (1);
    }

    if (level == 0)
        slurm_info (msg);
    else if (level == 1)
        slurm_verbose (msg);
    else if (level == 2)
        slurm_debug (msg);
    return (0);
}
Ejemplo n.º 3
0
static int lua_spank_option_callback (int val, const char *optarg, int remote)
{
    lua_State *L;
    struct lua_script_option *o;

    o = list_find_first (
            script_option_list,
            (ListFindF) s_opt_find,
            &val);

    if (o == NULL)
        return (-1);

    if (o->l_function == NULL)
        return (0);

    L = o->script->L;

    lua_getglobal (L, o->l_function);
    lua_pushnumber (L, o->l_val);
    lua_pushstring (L, optarg);
    lua_pushboolean (L, remote);

    slurm_debug ("spank/lua: %s: callback %s for option %s optarg=%s",
            o->script->path, o->l_function, o->s_opt.name,
            optarg ? optarg : "nil");

    if (lua_pcall (L, 3, 1, 0) != 0) {
        slurm_error ("Failed to call lua callback function %s: %s",
                    o->l_function, lua_tostring (L, -1));
        lua_pop (L, 1);
        return (-1);
    }

    return lua_script_rc (L);
}
Ejemplo n.º 4
0
int spank_lua_init (spank_t sp, int ac, char *av[])
{
    struct spank_lua_options opt;
    ListIterator i;
    struct lua_script *script;
    int rc = 0;

    if (ac == 0) {
        slurm_error ("spank/lua: Requires at least 1 arg");
        return (-1);
    }
    /*
     *  Check for spank/lua options in argv
     */
    spank_lua_process_args (&ac, &av, &opt);

    /*
     *  dlopen liblua to ensure that symbols from that lib are
     *   available globally (so lua doesn't fail to dlopen its
     *   DSOs
     */
    if (!dlopen ("liblua.so", RTLD_NOW | RTLD_GLOBAL)) {
        slurm_error ("spank/lua: Failed to open liblua.so");
        return (-1);
    }

    global_L = luaL_newstate ();
    luaL_openlibs (global_L);

    /*
     *  Create the global SPANK table
     */
    SPANK_table_create (global_L);

    lua_script_list = lua_script_list_create (global_L, av[0]);
    if (lua_script_list == NULL) {
        slurm_verbose ("spank/lua: No files found in %s", av[0]);
        return (0);
    }

    /*
     *  Set up handler for lua_atpanic() so lua doesn't exit() on us.
     *   This handles errors from outside of protected mode --
     *   for example when this plugin is processing the global
     *   spank_options table. The spank_atpanic() function will
     *   return to the setjmp() point below (thus avoiding Lua's
     *   call to exit() from its own panic handler). This is basically
     *   here so that we can use luaL_error() everwhere without
     *   worrying about the context of the call.
     */
    lua_atpanic (global_L, spank_atpanic);
    if (setjmp (panicbuf)) {
        slurm_error ("spank/lua: PANIC: %s: %s",
                av[0], lua_tostring (global_L, -1));
        return (-1);
    }

    i = list_iterator_create (lua_script_list);
    while ((script = list_next (i))) {
        script->fail_on_error = opt.fail_on_error;

        /*
         *  Load script (luaL_loadfile) and compile it (lua_pcall).
         */
        if (luaL_loadfile (script->L, script->path) ||
            lua_pcall (script->L, 0, 0, 0)) {
            print_lua_script_error (script);
            if (opt.fail_on_error)
                return (-1);
            list_remove(i);
            lua_script_destroy (script);
            continue;
        }

        /*
         *  Don't keep script loaded if the script doesn't have any
         *   callbacks in the current context.
         */
        if (!lua_script_valid_in_context (sp, script)) {
                slurm_debug ("%s: no callbacks in this context",
                             basename (script->path));
                list_remove (i);
                lua_script_destroy (script);
        }
    }
    list_iterator_destroy (i);
    slurm_verbose ("spank/lua: Loaded %d plugins in this context",
                    list_count (lua_script_list));
    return rc;
}