コード例 #1
0
ファイル: spank_direct_io.c プロジェクト: SchedMD/slurm
/*
 *  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);
}
コード例 #2
0
ファイル: singularity.c プロジェクト: DrDaveD/singularity
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;
}
コード例 #3
0
ファイル: bindtmp.c プロジェクト: cinek810/slurm_plugins
/* 
 * Called from both srun and slurmd.
 */
int slurm_spank_init (spank_t sp, int ac, char **av)
{
    uint32_t jobid;
    struct passwd *pw;
    uid_t uid;
    char buf [1024];
    int n;

    if (ac!=1) {
        slurm_error ("bindtmp: Error module need argument ' lls_mountpoint_prefix ' ");
        return (-1);
    }
    if (!spank_remote (sp))
        return (0);

    slurm_verbose("bindtmp: av[0] == %s ",av[0] );
    lls_mountpoint_prefix=av[0];

    spank_get_item (sp, S_JOB_UID, &uid);
    pw = getpwuid (uid);
    if (!pw) {
        slurm_error ("bindtmp: Error looking up uid in /etc/passwd");
        return (-1);
    }

    if (unshare (CLONE_NEWNS) < 0) {
        slurm_error ("bindtmp: Error unshare CLONE_NEWNS: %m");
        return (-1);
    }

    if ( spank_get_item (sp, S_JOB_ID, &jobid) != ESPANK_SUCCESS ) {
        slurm_error ("bindtmp: Error unable to get jobid");
        return (-1);
    }
    n = snprintf (buf, sizeof (buf), "%s%u",lls_mountpoint_prefix,  jobid);
    if ((n < 0) || (n > sizeof (buf) - 1)) {
        slurm_error ("bindtmp: Error sprintf ");
        return (-1);
    }
    if (mount(buf, "/tmp", NULL, MS_BIND , NULL)!= 0) {
        slurm_error ("bindtmp: Could not bind %s to /tmp",buf);
        return (-1);
    }

    return (0);
}
コード例 #4
0
/*
 * in remote mode, remove DISPLAY file in order to stop
 * ssh -X process initialized by the client
 */
int slurm_spank_exit (spank_t sp, int ac, char **av)
{
	uint32_t jobid;
	uint32_t stepid;

	FILE* f;
	char* expc_pattern= X11_LIBEXEC_PROG " -i %u.%u -r 2>/dev/null";
	char* expc_cmd;
	size_t expc_length;
	
	/* noting to do in local mode */
	if (!spank_remote (sp))
		return 0;

	/* get job id */
	if ( spank_get_item (sp, S_JOB_ID, &jobid) != ESPANK_SUCCESS )
		return -1;

	/* get job step id */
	if ( spank_get_item (sp, S_JOB_STEPID, &stepid) != ESPANK_SUCCESS )
		return -1;
	
	/* remove DISPLAY reference */
	expc_length = strlen(expc_pattern) + 128 ;
	expc_cmd = (char*) malloc(expc_length*sizeof(char));
	if ( expc_cmd != NULL && 
	     ( snprintf(expc_cmd,expc_length,expc_pattern,jobid,stepid)
	       >= expc_length )	) {
		ERROR("x11: error while creating remove reference cmd");
	}
	else {
		f = popen(expc_cmd,"r");
		if ( f == NULL ) {
			ERROR("x11: unable to exec remove"
				    " cmd '%s'",expc_cmd);
		}
		else
			pclose(f);		
	}
	if ( expc_cmd != NULL )
		free(expc_cmd);
	
	return 0;
}
コード例 #5
0
int
_spank_x11_get_mode(spank_t sp, int ac, char *av[])
{
	int i;
	char* elt;
	char* p;
        int fstatus;
	char spank_x11_env[6];

	char* envval=NULL;

	/* get configuration line parameters, replacing '|' with ' ' */
        for (i = 0; i < ac; i++) {
                elt = av[i];
                if ( strncmp(elt,"ssh_cmd=",8) == 0 ) {
                        ssh_cmd=strdup(elt+8);
			p = ssh_cmd;
			while ( p != NULL && *p != '\0' ) {
				if ( *p == '|' )
					*p= ' ';
				p++;
			}
                }
                else if ( strncmp(elt,"ssh_args=",9) == 0 ) {
                        ssh_args=strdup(elt+9);
			p = ssh_args;
			while ( p != NULL && *p != '\0' ) {
				if ( *p == '|' )
					*p= ' ';
				p++;
			}
                }
                else if ( strncmp(elt,"helpertask_args=",16) == 0 ) {
                        helpertask_args=strdup(elt+16);
			p = helpertask_args;
			while ( p != NULL && *p != '\0' ) {
				if ( *p == '|' )
					*p= ' ';
				p++;
			}
                }
        }

	/* read env configuration variable */
	if (spank_remote (sp)) {
		fstatus = spank_getenv(sp,SPANK_X11_ENVVAR,
				       spank_x11_env,6);
		if ( fstatus == 0 ) {
			spank_x11_env[5]='\0';
			envval=spank_x11_env;
		}
	}
	else {
		envval = getenv(SPANK_X11_ENVVAR);
	}
	/* if env variable is set, use it */
	if ( envval != NULL ) {
		/* check env var value (can be yes|no|done)*/
		if ( strncmp(envval,"first",5) == 0 ) {
			return X11_MODE_FIRST ;
		}
		else if ( strncmp(envval,"last",4) == 0 ) {
			return X11_MODE_LAST ;
		}
		else if ( strncmp(envval,"all",3) == 0 ) {
			return X11_MODE_ALL ;
		}
		else if ( strncmp(envval,"batch",5) == 0 ) {
			return X11_MODE_BATCH ;
		}
		else
			return X11_MODE_NONE ;
	}
	else {
                /* no env variable defined, return command line */
                /* or configuration file auks flag */
                return x11_mode ;
        }

}