/****** sge_resource_quota_qmaster/rqs_mod() ************************************** * NAME * rqs_mod() -- gdi callback function for modifing resource quota sets * * SYNOPSIS * int rqs_mod(lList **alpp, lListElem *new_rqs, lListElem *rqs, int add, * const char *ruser, const char *rhost, gdi_object_t *object, int * sub_command, monitoring_t *monitor) * * FUNCTION * This function is called from the framework that * add/modify/delete generic gdi objects. * The purpose of this function is it to add new rqs * objects or modify existing resource quota sets. * * INPUTS * lList **alpp - reference to an answer list * lListElem *new_rqs - if a new rqs object will be created by this * function, then new_rqs is a newly initialized * CULL object. * if this function was called due to a modify request * than new_rqs will contain the old data * lListElem *rqs - a reduced rqs object which contains all * necessary information to create a new object * or modify parts of an existing one * int add - 1 if a new element should be added to the master list * 0 to modify an existing object * const char *ruser - username who invoked this gdi request * const char *rhost - hostname of where the gdi request was invoked * gdi_object_t *object - structure of the gdi framework which contains * additional information to perform the request * int sub_command - how should we handle sublist elements * SGE_GDI_CHANGE - modify sublist elements * SGE_GDI_APPEND - add elements to a sublist * SGE_GDI_REMOVE - remove sublist elements * SGE_GDI_SET - replace the complete sublist * monitoring_t *monitor - monitoring structure * * RESULT * int - 0 on success * STATUS_EUNKNOWN if an error occured * * NOTES * MT-NOTE: rqs_mod() is MT safe *******************************************************************************/ int rqs_mod(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *new_rqs, lListElem *rqs, int add, const char *ruser, const char *rhost, gdi_object_t *object, int sub_command, monitoring_t *monitor) { const char *rqs_name = NULL; bool rules_changed = false; bool previous_enabled = (bool)lGetBool(new_rqs, RQS_enabled); DENTER(TOP_LAYER, "rqs_mod"); /* ---- RQS_name */ if (add) { if (attr_mod_str(alpp, rqs, new_rqs, RQS_name, object->object_name)) goto ERROR; } rqs_name = lGetString(new_rqs, RQS_name); /* Name has to be a valid name */ if (add && verify_str_key(alpp, rqs_name, MAX_VERIFY_STRING, MSG_OBJ_RQS, KEY_TABLE) != STATUS_OK) { goto ERROR; } /* ---- RQS_description */ attr_mod_zerostr(rqs, new_rqs, RQS_description, "description"); /* ---- RQS_enabled */ attr_mod_bool(rqs, new_rqs, RQS_enabled, "enabled"); /* ---- RQS_rule */ if (lGetPosViaElem(rqs, RQS_rule, SGE_NO_ABORT)>=0) { rules_changed = true; if (SGE_GDI_IS_SUBCOMMAND_SET(sub_command, SGE_GDI_SET_ALL)) { normalize_sublist(rqs, RQS_rule); attr_mod_sub_list(alpp, new_rqs, RQS_rule, RQS_name, rqs, sub_command, SGE_ATTR_RQSRULES, SGE_OBJ_RQS, 0, NULL); } else { /* *attr cases */ lList *rule_list = lGetList(rqs, RQS_rule); lListElem *rule = NULL; for_each(rule, rule_list) { lList *new_rule_list = lGetList(new_rqs, RQS_rule); lListElem *new_rule = NULL; new_rule = rqs_rule_locate(new_rule_list, lGetString(rule, RQR_name)); if (new_rule != NULL) { /* ---- RQR_limit */ attr_mod_sub_list(alpp, new_rule, RQR_limit, RQRL_name, rule, sub_command, SGE_ATTR_RQSRULES, SGE_OBJ_RQS, 0, NULL); } else { ERROR((SGE_EVENT, SFNMAX, MSG_RESOURCEQUOTA_NORULEDEFINED)); answer_list_add(alpp, SGE_EVENT, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR); goto ERROR; } } }
static bool hgroup_mod_hostlist(lListElem *hgroup, lList **answer_list, lListElem *reduced_elem, int sub_command, lList **add_hosts, lList **rem_hosts, lList **occupant_groups) { bool ret = true; DENTER(TOP_LAYER, "hgroup_mod_hostlist"); if (hgroup != NULL && reduced_elem != NULL) { int pos = lGetPosViaElem(reduced_elem, HGRP_host_list, SGE_NO_ABORT); if (pos >= 0) { lList *list = lGetPosList(reduced_elem, pos); lList *old_href_list = lCopyList("", lGetList(hgroup, HGRP_host_list)); lList *master_list = *(hgroup_list_get_master_list()); lList *href_list = NULL; lList *add_groups = NULL; lList *rem_groups = NULL; if (ret) { ret &= href_list_resolve_hostnames(list, answer_list, true); } if (ret) { attr_mod_sub_list(answer_list, hgroup, HGRP_host_list, HR_name, reduced_elem, sub_command, SGE_ATTR_HOSTLIST, SGE_OBJ_HGROUP, 0); href_list = lGetList(hgroup, HGRP_host_list); } if (ret) { ret &= href_list_find_diff(href_list, answer_list, old_href_list, add_hosts, rem_hosts, &add_groups, &rem_groups); } if (ret && add_groups != NULL) { ret &= hgroup_list_exists(master_list, answer_list, add_groups); } if (ret) { ret &= href_list_find_effective_diff(answer_list, add_groups, rem_groups, master_list, add_hosts, rem_hosts); } if (ret) { ret &= href_list_resolve_hostnames(*add_hosts, answer_list, false); } /* * Try to find cycles in the definition */ if (ret) { ret &= hgroup_find_all_referencees(hgroup, answer_list, master_list, occupant_groups); ret &= href_list_add(occupant_groups, answer_list, lGetHost(hgroup, HGRP_name)); if (ret) { if (*occupant_groups != NULL && add_groups != NULL) { lListElem *add_group = NULL; for_each(add_group, add_groups) { const char *name = lGetHost(add_group, HR_name); if (href_list_has_member(*occupant_groups, name)) { break; } } if (add_group == NULL) { /* * No cycle found => success */ ; } else { SGE_ADD_MSG_ID(sprintf(SGE_EVENT, MSG_HGROUP_CYCLEINDEF_SS, lGetHost(add_group, HR_name), lGetHost(hgroup, HGRP_name))); answer_list_add(answer_list, SGE_EVENT, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR); ret = false; } } } }