diff --git a/src/common/slurm_mcs.c b/src/common/slurm_mcs.c index 11e4041cf0ecdd185d98a4a19189a3863af9f4f9..0d33672fc2bbddc752311ab945274ebcb4eb0ac1 100644 --- a/src/common/slurm_mcs.c +++ b/src/common/slurm_mcs.c @@ -79,20 +79,20 @@ extern int slurm_mcs_init(void) if (init_run && g_mcs_context) return retval; - slurm_mutex_lock(&g_mcs_context_lock); + slurm_mutex_lock(&g_mcs_context_lock); if (g_mcs_context) goto done; xfree(mcs_params); xfree(mcs_params_common); xfree(mcs_params_specific); - type = slurm_get_mcs_plugin(); mcs_params = slurm_get_mcs_plugin_params(); - if (mcs_params == NULL) { + + if (mcs_params == NULL) info("No parameter for mcs plugin, default values set"); - } else { + else { mcs_params_common = xstrdup(mcs_params); sep = index(mcs_params_common, ':'); if (sep != NULL) { @@ -101,6 +101,7 @@ extern int slurm_mcs_init(void) *sep = '\0'; } } + _slurm_mcs_check_and_load_privatedata(mcs_params_common); _slurm_mcs_check_and_load_enforced(mcs_params_common); _slurm_mcs_check_and_load_select(mcs_params_common); @@ -113,8 +114,8 @@ extern int slurm_mcs_init(void) retval = SLURM_ERROR; goto done; } - init_run = true; + init_run = true; done: slurm_mutex_unlock(&g_mcs_context_lock); xfree(type); @@ -140,7 +141,7 @@ extern int slurm_mcs_fini(void) extern int slurm_mcs_reconfig(void) { slurm_mcs_fini(); - return(slurm_mcs_init()); + return slurm_mcs_init(); } /* slurm_mcs_get_params_specific @@ -157,28 +158,32 @@ extern char *slurm_mcs_get_params_specific(void) static int _slurm_mcs_check_and_load_enforced(char *params) { label_strict_enforced = false; + if ((params != NULL) && xstrcasestr(params, "enforced")) label_strict_enforced = true; else info("mcs: MCSParameters = %s. ondemand set.", params); + return SLURM_SUCCESS; } static int _slurm_mcs_check_and_load_select(char *params) { select_value = MCS_SELECT_ONDEMANDSELECT; + if (params == NULL) { return SLURM_SUCCESS; } - if (xstrcasestr(params, "noselect")) { + + if (xstrcasestr(params, "noselect")) select_value = MCS_SELECT_NOSELECT; - } else if (xstrcasestr(params, "ondemandselect")) { + else if (xstrcasestr(params, "ondemandselect")) select_value = MCS_SELECT_ONDEMANDSELECT; - } else if (xstrcasestr(params, "select")) { + else if (xstrcasestr(params, "select")) select_value = MCS_SELECT_SELECT; - } else { + else info("mcs: MCSParameters = %s. ondemandselect set.", params); - } + return SLURM_SUCCESS; } @@ -188,11 +193,12 @@ static int _slurm_mcs_check_and_load_privatedata(char *params) private_data = false; return SLURM_SUCCESS; } - if (xstrcasestr(params, "privatedata")) { + + if (xstrcasestr(params, "privatedata")) private_data = true; - } else { + else private_data = false; - } + return SLURM_SUCCESS; } @@ -201,18 +207,19 @@ extern int slurm_mcs_reset_params(void) label_strict_enforced = false; select_value = MCS_SELECT_ONDEMANDSELECT; private_data = false; + return SLURM_SUCCESS; } extern int slurm_mcs_get_enforced(void) { - return(label_strict_enforced); + return label_strict_enforced; } extern int slurm_mcs_get_select(struct job_record *job_ptr) { if ((select_value == MCS_SELECT_SELECT) || - ((select_value == MCS_SELECT_ONDEMANDSELECT) && + ((select_value == MCS_SELECT_ONDEMANDSELECT) && job_ptr->details && (job_ptr->details->whole_node == WHOLE_NODE_MCS))) return 1; @@ -237,5 +244,6 @@ extern int mcs_g_check_mcs_label(uint32_t user_id, char *mcs_label) { if (slurm_mcs_init() < 0) return 0; - return (int) (*(ops.check))(user_id, mcs_label); + + return (int)(*(ops.check))(user_id, mcs_label); } diff --git a/src/plugins/mcs/account/mcs_account.c b/src/plugins/mcs/account/mcs_account.c index 3496742c5361d060d01959671ff271707da45ebb..e8c78734523fdf476e7164a7e8dae16496861005 100644 --- a/src/plugins/mcs/account/mcs_account.c +++ b/src/plugins/mcs/account/mcs_account.c @@ -98,21 +98,21 @@ extern int mcs_p_set_mcs_label(struct job_record *job_ptr, char *label) { int rc = SLURM_SUCCESS; xfree(job_ptr->mcs_label); + if (label != NULL) { /* test label param */ - if (!xstrcmp(label, job_ptr->account)) { + if (!xstrcmp(label, job_ptr->account)) job_ptr->mcs_label = xstrdup(job_ptr->account); - } else { + else rc = SLURM_ERROR; - } } else { if ((slurm_mcs_get_enforced() == 0) && job_ptr->details && - (job_ptr->details->whole_node != WHOLE_NODE_MCS)) { + (job_ptr->details->whole_node != WHOLE_NODE_MCS)) ; - } else { + else job_ptr->mcs_label = xstrdup(job_ptr->account); - } } + return rc; } @@ -127,14 +127,16 @@ extern int mcs_p_check_mcs_label(uint32_t user_id, char *mcs_label) memset(&assoc_rec, 0, sizeof(slurmdb_assoc_rec_t)); assoc_rec.acct = mcs_label; assoc_rec.uid = user_id; + if (mcs_label != NULL) { if (!assoc_mgr_fill_in_assoc(acct_db_conn, &assoc_rec, - accounting_enforce, - (slurmdb_assoc_rec_t **) - NULL, false)) + accounting_enforce, + (slurmdb_assoc_rec_t **) NULL, + false)) rc = SLURM_SUCCESS; else rc = SLURM_ERROR; } + return rc; } diff --git a/src/plugins/mcs/group/mcs_group.c b/src/plugins/mcs/group/mcs_group.c index bbf3e84c9ceba5f2e9fba63f36ba69fe77766af2..7dc77b2ff2e9dbfd824b4cb446b99237a8519ce8 100644 --- a/src/plugins/mcs/group/mcs_group.c +++ b/src/plugins/mcs/group/mcs_group.c @@ -92,12 +92,15 @@ extern int init(void) { debug("%s loaded", plugin_name); mcs_params_specific = slurm_mcs_get_params_specific(); + if (_check_and_load_params() != 0) { - info("mcs: plugin warning : no group in %s", mcs_params_specific); + info("mcs: plugin warning : no group in %s", + mcs_params_specific); xfree(mcs_params_specific); /* no need to check others options : default values used */ return SLURM_SUCCESS; } + xfree(mcs_params_specific); return SLURM_SUCCESS; } @@ -125,6 +128,7 @@ static int _get_user_groups(uint32_t user_id, uint32_t group_id, user_name = uid_to_string((uid_t) user_id); *ngroups = max_groups; rc = getgrouplist(user_name, (gid_t) group_id, groups, ngroups); + if (rc < 0) { error("getgrouplist(%s): %m", user_name); rc = SLURM_ERROR; @@ -132,6 +136,7 @@ static int _get_user_groups(uint32_t user_id, uint32_t group_id, *ngroups = rc; rc = SLURM_SUCCESS; } + xfree(user_name); return rc; } @@ -154,15 +159,17 @@ static int _check_and_load_params(void) slurm_mcs_reset_params(); return SLURM_ERROR; } + n = strlen(mcs_params_specific); for (i = 0 ; i < n ; i++) { if (mcs_params_specific[i] == '|') nb_mcs_groups = nb_mcs_groups + 1; } + if (nb_mcs_groups == 0) { /* no | in param : just one group */ if (mcs_params_specific != NULL) { - if ( gid_from_string(mcs_params_specific, &gid ) != 0 ) { + if (gid_from_string(mcs_params_specific, &gid ) != 0 ) { info("mcs: Only one invalid group : %s. " "ondemand, ondemandselect set", groups_names); nb_mcs_groups = 0; @@ -190,10 +197,12 @@ static int _check_and_load_params(void) } return SLURM_SUCCESS; } + nb_mcs_groups = nb_mcs_groups + 1; array_mcs_parameter = xmalloc(nb_mcs_groups * sizeof(uint32_t)); tmp_params = xstrdup(mcs_params_specific); groups_names = strtok_r(tmp_params, "|", &name_ptr); + i = 0; while (groups_names) { if (i == (nb_mcs_groups - 1)) { @@ -213,6 +222,7 @@ static int _check_and_load_params(void) i = i + 1; groups_names = strtok_r(NULL, "|", &name_ptr); } + /* if no valid group : deselect all params */ if (nb_valid_group == 0) { slurm_mcs_reset_params(); @@ -220,6 +230,7 @@ static int _check_and_load_params(void) xfree(tmp_params); return SLURM_ERROR; } + xfree(tmp_params); return SLURM_SUCCESS; } @@ -236,20 +247,20 @@ static int _find_mcs_label(gid_t *groups, int ngroups, char **result) struct group *gr; if (ngroups == 0) - rc = SLURM_ERROR; - else { - for( i = 0 ; i < nb_mcs_groups ; i++) { - for ( j = 0 ; j < ngroups ; j++) { - tmp_group = (uint32_t) groups[j]; - if (array_mcs_parameter[i] == tmp_group ) { - gr = getgrgid(groups[j]); - *result = gr->gr_name; - return rc; - } + return SLURM_ERROR; + + for (i = 0; i < nb_mcs_groups; i++) { + for (j = 0; j < ngroups; j++) { + tmp_group = (uint32_t) groups[j]; + if (array_mcs_parameter[i] == tmp_group) { + gr = getgrgid(groups[j]); + *result = gr->gr_name; + return rc; } } - rc = SLURM_ERROR; } + rc = SLURM_ERROR; + return rc; } @@ -266,7 +277,7 @@ static int _check_mcs_label (struct job_record *job_ptr, char *label) int ngroups = -1; /* test if real unix group */ - if ( gid_from_string(label, &gid ) != 0 ) + if (gid_from_string(label, &gid ) != 0) return rc; /* test if this group is owned by the user */ @@ -274,6 +285,7 @@ static int _check_mcs_label (struct job_record *job_ptr, char *label) groups, MAX_GROUPS, &ngroups); if (rc) /* Failed to get groups */ return rc; + rc = SLURM_ERROR; for (i = 0; i < ngroups; i++) { tmp_group = (uint32_t) groups[i]; @@ -282,16 +294,19 @@ static int _check_mcs_label (struct job_record *job_ptr, char *label) break; } } + if (rc == SLURM_ERROR) return rc; + rc = SLURM_ERROR; /* test if mcs_label is in list of possible mcs_label */ - for( i = 0 ; i < nb_mcs_groups ; i++) { - if (array_mcs_parameter[i] == gid ) { + for (i = 0; i < nb_mcs_groups; i++) { + if (array_mcs_parameter[i] == gid) { rc = SLURM_SUCCESS; return rc; } } + return rc; } @@ -311,6 +326,7 @@ extern int mcs_p_set_mcs_label (struct job_record *job_ptr, char *label) if ((slurm_mcs_get_enforced() == 0) && job_ptr->details && (job_ptr->details->whole_node != WHOLE_NODE_MCS)) return SLURM_SUCCESS; + rc = _get_user_groups(job_ptr->user_id,job_ptr->group_id, groups, MAX_GROUPS, &ngroups); if (rc) { /* Failed to get groups */ @@ -319,6 +335,7 @@ extern int mcs_p_set_mcs_label (struct job_record *job_ptr, char *label) else return SLURM_ERROR; } + rc = _find_mcs_label(groups, ngroups, &result); if (rc) { return SLURM_ERROR; @@ -351,9 +368,9 @@ extern int mcs_p_check_mcs_label (uint32_t user_id, char *mcs_label) if (mcs_label != NULL) { /* test if real unix group */ - if ( gid_from_string(mcs_label, &gid ) != 0 ) { + if (gid_from_string(mcs_label, &gid ) != 0) return rc; - } + /* test if this group is owned by the user */ slurm_user_gid = gid_from_uid(user_id); group_id = (uint32_t) slurm_user_gid; @@ -361,6 +378,7 @@ extern int mcs_p_check_mcs_label (uint32_t user_id, char *mcs_label) &ngroups); if (rc) /* Failed to get groups */ return rc; + rc = SLURM_ERROR; for (i = 0; i < ngroups; i++) { tmp_group = (uint32_t) groups[i]; @@ -369,8 +387,8 @@ extern int mcs_p_check_mcs_label (uint32_t user_id, char *mcs_label) break; } } - } else { + } else rc = SLURM_SUCCESS; - } + return rc; } diff --git a/src/plugins/mcs/user/mcs_user.c b/src/plugins/mcs/user/mcs_user.c index 5d5a71991e5feb2d40634ee5c61d3cf5170e546d..2ff26736f70fb1d8ae3b2fed0f1879209ba3110c 100644 --- a/src/plugins/mcs/user/mcs_user.c +++ b/src/plugins/mcs/user/mcs_user.c @@ -95,23 +95,24 @@ extern int mcs_p_set_mcs_label (struct job_record *job_ptr, char *label) { char *user = NULL; int rc = SLURM_SUCCESS; + user = uid_to_string((uid_t) job_ptr->user_id); xfree(job_ptr->mcs_label); + if (label != NULL) { /* test label param */ - if (xstrcmp(label, user) == 0) { + if (xstrcmp(label, user) == 0) job_ptr->mcs_label = xstrdup(user); - } else { + else rc = SLURM_ERROR; - } } else { if ((slurm_mcs_get_enforced() == 0) && job_ptr->details && - (job_ptr->details->whole_node != WHOLE_NODE_MCS)) { + (job_ptr->details->whole_node != WHOLE_NODE_MCS)) ; - } else { + else job_ptr->mcs_label = xstrdup(user); - } } + xfree(user); return rc; } @@ -123,16 +124,16 @@ extern int mcs_p_check_mcs_label (uint32_t user_id, char *mcs_label) { char *user = NULL; int rc = SLURM_SUCCESS; + user = uid_to_string((uid_t) user_id); if (mcs_label != NULL) { - if (xstrcmp(mcs_label, user) == 0) { + if (xstrcmp(mcs_label, user) == 0) rc = SLURM_SUCCESS; - } else { + else rc = SLURM_ERROR; - } - } else { + } else rc = SLURM_SUCCESS; - } + xfree(user); return rc; }