Ejemplo n.º 1
0
/*
 * Replace first "%h" in path string with actual hostname.
 * Replace first "%n" in path string with NodeName.
 */
static void
_massage_pathname(char **path)
{
	if (path && *path) {
		if (conf->hostname)
			xstrsubstitute(*path, "%h", conf->hostname);
		if (conf->node_name)
			xstrsubstitute(*path, "%n", conf->node_name);
	}
}
Ejemplo n.º 2
0
extern char* jobacct_cgroup_create_slurm_cg(xcgroup_ns_t* ns)
 {
	/* we do it here as we do not have access to the conf structure */
	/* in libslurm (src/common/xcgroup.c) */
	xcgroup_t slurm_cg;
	char* pre = (char*) xstrdup(slurm_cgroup_conf.cgroup_prepend);
#ifdef MULTIPLE_SLURMD
	if (conf->node_name != NULL)
		xstrsubstitute(pre,"%n", conf->node_name);
	else {
		xfree(pre);
		pre = (char*) xstrdup("/slurm");
	}
#endif

	/* create slurm cgroup in the ns (it could already exist) */
	if (xcgroup_create(ns,&slurm_cg,pre,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		return pre;
	}

	if (xcgroup_instanciate(&slurm_cg) != XCGROUP_SUCCESS) {
		error("unable to build slurm cgroup for ns %s: %m",
		      ns->subsystems);
		xcgroup_destroy(&slurm_cg);
		return pre;
	} else {
		debug3("slurm cgroup %s successfully created for ns %s: %m",
		       pre,ns->subsystems);
		xcgroup_destroy(&slurm_cg);
	}

	return pre;
}
Ejemplo n.º 3
0
static char* _system_cgroup_create_slurm_cg (xcgroup_ns_t* ns)
{
	/* we do it here as we do not have access to the conf structure */
	/* in libslurm (src/common/xcgroup.c) */
	xcgroup_t slurm_cg;
	char* pre = (char*) xstrdup(slurm_cgroup_conf.cgroup_prepend);

#ifdef MULTIPLE_SLURMD
	if ( conf->node_name != NULL )
		xstrsubstitute(pre, "%n", conf->node_name);
	else {
		xfree(pre);
		pre = (char*) xstrdup("/slurm");
	}
#endif

	/* create slurm cgroup in the ns
	 * disable notify_on_release to avoid the removal/creation
	 * of this cgroup for each last/first running job on the node */
	if (xcgroup_create(ns, &slurm_cg, pre,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		xfree(pre);
		return pre;
	}
	slurm_cg.notify = 0;
	if (xcgroup_instantiate(&slurm_cg) != XCGROUP_SUCCESS) {
		error("system cgroup: unable to build slurm cgroup for "
		      "ns %s: %m",
		      ns->subsystems);
		xcgroup_destroy(&slurm_cg);
		xfree(pre);
		return pre;
	}
	else {
		debug3("system cgroup: slurm cgroup %s successfully created "
		       "for ns %s: %m",
		       pre, ns->subsystems);
		xcgroup_destroy(&slurm_cg);
	}

	return pre;
}
Ejemplo n.º 4
0
static char* _get_node_rrd_path(char* component_name,
				enum ext_sensors_value_type sensor_type)
{
	char *p;
	char *rrd_file;
	struct stat buf;

	switch (sensor_type) {
	case EXT_SENSORS_VALUE_ENERGY:
		rrd_file = ext_sensors_cnf->energy_rrd_file;
		break;
	case EXT_SENSORS_VALUE_TEMPERATURE:
		rrd_file = ext_sensors_cnf->temp_rrd_file;
		break;
	default:
		error("ext_sensors: _get_node_rrd_path: unknown enum %d",
		      sensor_type);
		return NULL;
	}

	if (!component_name || !strlen(component_name) || !rrd_file)
		return NULL;

	p = xstrdup(rrd_file);
	xstrsubstitute(p, "%n", component_name);

	if (!strcmp(p, rrd_file)) {
		xfree(p);
		return NULL;
	}

	if (stat(p, &buf) == -1) {
		xfree(p);
		return NULL;
	}

	return p;
}
Ejemplo n.º 5
0
extern void attach_system_cgroup_pid(pid_t pid)
{
	char* slurm_cgpath;

	if (read_slurm_cgroup_conf(&slurm_cgroup_conf))
		return;

	slurm_cgpath = (char*) xstrdup(slurm_cgroup_conf.cgroup_prepend);
#ifdef MULTIPLE_SLURMD
	if ( conf->node_name != NULL )
		xstrsubstitute(slurm_cgpath,"%n", conf->node_name);
	else {
		xfree(slurm_cgpath);
		slurm_cgpath = (char*) xstrdup("/slurm");
	}
#endif
	xstrcat(slurm_cgpath,"/system");
	if (xcgroup_ns_load(&slurm_cgroup_conf, &cpuset_ns, "cpuset")
	    == XCGROUP_SUCCESS) {
		if (xcgroup_load(&cpuset_ns, &system_cpuset_cg, slurm_cgpath)
		    == XCGROUP_SUCCESS)
			if (attach_system_cpuset_pid(pid) != SLURM_SUCCESS)
				debug2("system cgroup: unable to attach pid to "
				       "system cpuset cgroup");
	}
	if (xcgroup_ns_load(&slurm_cgroup_conf, &memory_ns, "memory")
	    == XCGROUP_SUCCESS) {
		if (xcgroup_load(&memory_ns, &system_memory_cg, slurm_cgpath)
		    == XCGROUP_SUCCESS)
			if (attach_system_memory_pid(pid) != SLURM_SUCCESS)
				debug2("system cgroup: unable to attach pid to "
				       "system memory cgroup");
	}
	xfree(slurm_cgpath);
	free_slurm_cgroup_conf(&slurm_cgroup_conf);
	return;
}
Ejemplo n.º 6
0
static uint32_t _rrd_get_last_one(char* filename, char* rra_name)
{
	/* RRD library usage notes:
	 * do not use the following lines for compatibility:
	 * 1.3.8-6 : (argv={lastupdate, filename}
	 * status = rrd_lastupdate(argc, argv, &time, &ds_count,
	 *                         &ds_names, &last_ds);
	 * 1.4.7 :
	 * status = rrd_lastupdate_r(filename, &time, &ds_count,
	 *                           &ds_names, &last_ds);
	 */
	rrd_info_t *data, *data_p;
	char line[] = "ds[%s].last_ds", *p, *rra = NULL;
	char *argv[] = {"info", filename, NULL};
	uint32_t temperature = NO_VAL;

	p = xstrdup(line);

	data = rrd_info(2, argv);
	data_p = data;

	if (rra_name == NULL) {
		while (data_p) {
			if (!strncmp(line, data_p->key, 3)) {
				rra = xstrdup(data_p->key + 3);
				xstrsubstitute(rra, strchr(rra, ']'), "");
				break;
			}
			data_p = data_p->next;
		}
	} else
		rra = rra_name;

	if (rra != NULL) {
		xstrsubstitute(p, "%s", rra_name);
		if (rra_name == NULL)
			xfree(rra);
		if (strcmp(p,line) == 0) {
			xfree(p);
			rrd_info_free(data);
			return temperature;
		}
	} else {
		xfree(p);
		rrd_info_free(data);
		return temperature;
	}

	while (data_p) {
		if (!strcmp(p, data_p->key)) {
			if (!sscanf(data_p->value.u_str, "%d", &temperature))
				temperature = 1;
			break;
		}
		data_p = data_p->next;
	}

	xfree(p);
	rrd_info_free(data);

	return temperature;
}
Ejemplo n.º 7
0
int _slurm_cgroup_create(stepd_step_rec_t *job, uint64_t id, uid_t uid, gid_t gid)
{
    /* we do it here as we do not have access to the conf structure */
    /* in libslurm (src/common/xcgroup.c) */
    char *pre = (char *)xstrdup(slurm_cgroup_conf.cgroup_prepend);
#ifdef MULTIPLE_SLURMD
    if ( conf->node_name != NULL )
        xstrsubstitute(pre,"%n", conf->node_name);
    else {
        xfree(pre);
        pre = (char*) xstrdup("/slurm");
    }
#endif

    if (xcgroup_create(&freezer_ns, &slurm_freezer_cg, pre,
                       getuid(), getgid()) != XCGROUP_SUCCESS) {
        return SLURM_ERROR;
    }

    /*
     * While creating the cgroup hierarchy of the step, lock the root
     * cgroup directory. The same lock is hold during removal of the
     * hierarchies of other jobs/steps. This helps to  avoid the race
     * condition with concurrent creation/removal of the intermediate
     * shared directories that could result in the failure of the
     * hierarchy setup
     */
    xcgroup_lock(&freezer_cg);

    /* create slurm cgroup in the freezer ns (it could already exist) */
    if (xcgroup_instanciate(&slurm_freezer_cg) != XCGROUP_SUCCESS)
        goto bail;

    /* build user cgroup relative path if not set (should not be) */
    if (*user_cgroup_path == '\0') {
        if (snprintf(user_cgroup_path, PATH_MAX,
                     "%s/uid_%u", pre, uid) >= PATH_MAX) {
            error("unable to build uid %u cgroup relative "
                  "path : %m", uid);
            xfree(pre);
            goto bail;
        }
    }
    xfree(pre);

    /* build job cgroup relative path if no set (should not be) */
    if (*job_cgroup_path == '\0') {
        if (snprintf(job_cgroup_path, PATH_MAX, "%s/job_%u",
                     user_cgroup_path, job->jobid) >= PATH_MAX) {
            error("unable to build job %u cgroup relative "
                  "path : %m", job->jobid);
            goto bail;
        }
    }

    /* build job step cgroup relative path (should not be) */
    if (*jobstep_cgroup_path == '\0') {
        if (job->stepid == NO_VAL) {
            if (snprintf(jobstep_cgroup_path, PATH_MAX,
                         "%s/step_batch", job_cgroup_path)
                    >= PATH_MAX) {
                error("proctrack/cgroup unable to build job step"
                      " %u.batch freezer cg relative path: %m",
                      job->jobid);
                goto bail;
            }
        } else {
            if (snprintf(jobstep_cgroup_path, PATH_MAX, "%s/step_%u",
                         job_cgroup_path, job->stepid) >= PATH_MAX) {
                error("proctrack/cgroup unable to build job step"
                      " %u.%u freezer cg relative path: %m",
                      job->jobid, job->stepid);
                goto bail;
            }
        }
    }

    /* create user cgroup in the freezer ns (it could already exist) */
    if (xcgroup_create(&freezer_ns, &user_freezer_cg,
                       user_cgroup_path,
                       getuid(), getgid()) != XCGROUP_SUCCESS) {
        xcgroup_destroy(&slurm_freezer_cg);
        goto bail;
    }

    /* create job cgroup in the freezer ns (it could already exist) */
    if (xcgroup_create(&freezer_ns, &job_freezer_cg,
                       job_cgroup_path,
                       getuid(), getgid()) != XCGROUP_SUCCESS) {
        xcgroup_destroy(&slurm_freezer_cg);
        xcgroup_destroy(&user_freezer_cg);
        goto bail;
    }

    /* create step cgroup in the freezer ns (it should not exists) */
    if (xcgroup_create(&freezer_ns, &step_freezer_cg,
                       jobstep_cgroup_path,
                       getuid(), getgid()) != XCGROUP_SUCCESS) {
        xcgroup_destroy(&slurm_freezer_cg);
        xcgroup_destroy(&user_freezer_cg);
        xcgroup_destroy(&job_freezer_cg);
        goto bail;
    }

    if ((xcgroup_instanciate(&user_freezer_cg) != XCGROUP_SUCCESS) ||
            (xcgroup_instanciate(&job_freezer_cg)  != XCGROUP_SUCCESS) ||
            (xcgroup_instanciate(&step_freezer_cg) != XCGROUP_SUCCESS)) {
        xcgroup_destroy(&user_freezer_cg);
        xcgroup_destroy(&job_freezer_cg);
        xcgroup_destroy(&step_freezer_cg);
        goto bail;
    }

    /* inhibit release agent for the step cgroup thus letting
     * slurmstepd being able to add new pids to the container
     * when the job ends (TaskEpilog,...) */
    xcgroup_set_param(&step_freezer_cg,"notify_on_release","0");
    slurm_freezer_init = true;

    xcgroup_unlock(&freezer_cg);
    return SLURM_SUCCESS;

bail:
    xcgroup_destroy(&slurm_freezer_cg);
    xcgroup_unlock(&freezer_cg);
    xcgroup_destroy(&freezer_cg);
    return SLURM_ERROR;
}
Ejemplo n.º 8
0
int _slurm_cgroup_create(stepd_step_rec_t *job, uint64_t id, uid_t uid, gid_t gid)
{
	/* we do it here as we do not have access to the conf structure */
	/* in libslurm (src/common/xcgroup.c) */
	xcgroup_t slurm_cg;
	char* pre = (char*) xstrdup(slurm_cgroup_conf.cgroup_prepend);
#ifdef MULTIPLE_SLURMD
	if ( conf->node_name != NULL )
		xstrsubstitute(pre,"%n", conf->node_name);
	else {
		xfree(pre);
		pre = (char*) xstrdup("/slurm");
	}
#endif

	/* create slurm cgroup in the freezer ns (it could already exist) */
	if (xcgroup_create(&freezer_ns, &slurm_cg,pre,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		return SLURM_ERROR;
	}
	if (xcgroup_instanciate(&slurm_cg) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&slurm_cg);
		return SLURM_ERROR;
	}
	else
		xcgroup_destroy(&slurm_cg);

	/* build user cgroup relative path if not set (should not be) */
	if (*user_cgroup_path == '\0') {
		if (snprintf(user_cgroup_path, PATH_MAX,
			     "%s/uid_%u", pre, uid) >= PATH_MAX) {
			error("unable to build uid %u cgroup relative "
			      "path : %m", uid);
			xfree(pre);
			return SLURM_ERROR;
		}
	}
	xfree(pre);

	/* build job cgroup relative path if no set (should not be) */
	if (*job_cgroup_path == '\0') {
		if (snprintf(job_cgroup_path, PATH_MAX, "%s/job_%u",
			     user_cgroup_path, job->jobid) >= PATH_MAX) {
			error("unable to build job %u cgroup relative "
			      "path : %m", job->jobid);
			return SLURM_ERROR;
		}
	}

	/* build job step cgroup relative path (should not be) */
	if (*jobstep_cgroup_path == '\0') {
		if (job->stepid == NO_VAL) {
			if (snprintf(jobstep_cgroup_path, PATH_MAX,
				     "%s/step_batch", job_cgroup_path)
			    >= PATH_MAX) {
				error("proctrack/cgroup unable to build job step"
				      " %u.batch freezer cg relative path: %m",
				      job->jobid);
				return SLURM_ERROR;
			}
		} else {
			if (snprintf(jobstep_cgroup_path, PATH_MAX, "%s/step_%u",
				     job_cgroup_path, job->stepid) >= PATH_MAX) {
				error("proctrack/cgroup unable to build job step"
				      " %u.%u freezer cg relative path: %m",
				      job->jobid, job->stepid);
				return SLURM_ERROR;
			}
		}
	}

	/* create user cgroup in the freezer ns (it could already exist) */
	if (xcgroup_create(&freezer_ns, &user_freezer_cg,
			   user_cgroup_path,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		return SLURM_ERROR;
	}
	if (xcgroup_instanciate(&user_freezer_cg) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&user_freezer_cg);

		return SLURM_ERROR;
	}

	/* create job cgroup in the freezer ns (it could already exist) */
	if (xcgroup_create(&freezer_ns, &job_freezer_cg,
			   job_cgroup_path,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&user_freezer_cg);
		return SLURM_ERROR;
	}
	if (xcgroup_instanciate(&job_freezer_cg) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&user_freezer_cg);
		xcgroup_destroy(&job_freezer_cg);
		return SLURM_ERROR;
	}

	/* create step cgroup in the freezer ns (it should not exists) */
	if (xcgroup_create(&freezer_ns, &step_freezer_cg,
			   jobstep_cgroup_path,
			   getuid(), getgid()) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&user_freezer_cg);
		xcgroup_destroy(&job_freezer_cg);
		return SLURM_ERROR;
	}
	if (xcgroup_instanciate(&step_freezer_cg) != XCGROUP_SUCCESS) {
		xcgroup_destroy(&user_freezer_cg);
		xcgroup_destroy(&job_freezer_cg);
		xcgroup_destroy(&step_freezer_cg);
		return SLURM_ERROR;
	}

	/* inhibit release agent for the step cgroup thus letting 
	 * slurmstepd being able to add new pids to the container 
	 * when the job ends (TaskEpilog,...) */
	xcgroup_set_param(&step_freezer_cg,"notify_on_release","0");

	return SLURM_SUCCESS;
}