int sge_get_path(const char *qualified_hostname, lList *lp, const char *cwd, const char *owner, const char *job_name, u_long32 job_number, u_long32 ja_task_number, int type, char *pathstr, size_t pathstr_len) { lListElem *ep = NULL; const char *path = NULL, *host = NULL; DENTER(TOP_LAYER, "sge_get_path"); *pathstr = '\0'; /* * check if there's a path for this host */ ep = lGetElemHost(lp, PN_host, qualified_hostname); if (ep != NULL) { path = expand_path(lGetString(ep, PN_path), job_number, ja_task_number, job_name, owner, qualified_hostname); host = lGetHost(ep, PN_host); } else { /* * hostname: wasn't set, look for a default */ for_each(ep, lp) { path = expand_path(lGetString(ep, PN_path), job_number, ja_task_number, job_name, owner, qualified_hostname); host = lGetHost(ep, PN_host); if (host == NULL) { break; } } }
/****** sgeobj/href/href_list_locate() **************************************** * NAME * href_list_locate() -- Find an entry in the reference list * * SYNOPSIS * lListElem* * href_list_locate(const lList *this_list, const char *name) * * FUNCTION * Find an entry in the reference list. * * INPUTS * const lList *this_list - HR_Type * const char *name - host or groupname * * RESULT * lListElem* - Pointer to host or hostgroup element or NULL *******************************************************************************/ lListElem * href_list_locate(const lList *this_list, const char *name) { lListElem *ret = NULL; /* HR_Type */ DENTER(HOSTREF_LAYER, "href_list_locate"); if (this_list != NULL && name != NULL) { ret = lGetElemHost(this_list, HR_name, name); } DEXIT; return ret; }
static bool cqueue_add_qinstances(sge_gdi_ctx_class_t *ctx, lListElem *cqueue, lList **answer_list, lList *add_hosts, monitoring_t *monitor) { bool ret = true; DENTER(TOP_LAYER, "cqueue_add_qinstances"); if (cqueue != NULL && add_hosts != NULL) { lListElem *href = NULL; for_each(href, add_hosts) { const char *hostname = lGetHost(href, HR_name); lList *list = lGetList(cqueue, CQ_qinstances); lListElem* qinstance = lGetElemHost(list, QU_qhostname, hostname); if (qinstance != NULL) { if (qinstance_state_is_orphaned(qinstance)) { sge_qmaster_qinstance_state_set_orphaned(qinstance, false); lSetUlong(qinstance, QU_tag, SGE_QI_TAG_MOD); } else { /* * We might already have this QI if it is in orphaned state. * If this is not true, than there is a bug! */ ERROR((SGE_EVENT, MSG_QINSTANCE_QIALREADYHERE_S, hostname)); answer_list_add(answer_list, SGE_EVENT, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR); } } else { bool is_ambiguous = false; if (list == NULL) { list = lCreateList("", QU_Type); lSetList(cqueue, CQ_qinstances, list); } qinstance = qinstance_create(ctx, cqueue, answer_list, hostname, &is_ambiguous, monitor); if (is_ambiguous) { DPRINTF(("qinstance %s has ambiguous conf\n", hostname)); } lSetUlong(qinstance, QU_tag, SGE_QI_TAG_ADD); lAppendElem(list, qinstance); } } }
/****** sgeobj/qinstance/qinstance_list_locate() ****************************** * NAME * qinstance_list_locate() -- find a qinstance * * SYNOPSIS * lListElem * * qinstance_list_locate(const lList *this_list, * const char *hostname, const char *cqueue_name) * * FUNCTION * Find a qinstance in "this_list" which is part of the cluster queue * with the name "cqueue_name" and resides on the host with the name * "hostname". * * INPUTS * const lList *this_list - QU_Type list * const char *hostname - hostname * const char *cqueue_name - cluster queue name * * RESULT * lListElem * - QU_Type element * * NOTES * MT-NOTE: qinstance_list_locate() is MT safe *******************************************************************************/ lListElem * qinstance_list_locate(const lList *this_list, const char *hostname, const char *cqueue_name) { lListElem *ret = NULL; if (cqueue_name == NULL) { ret = lGetElemHost(this_list, QU_qhostname, hostname); } else { for_each(ret, this_list) { const char *qname = lGetString(ret, QU_qname); const char *hname = lGetHost(ret, QU_qhostname); /* use qinstance expression */ if (!sge_eval_expression(TYPE_CSTR, cqueue_name, qname, NULL)) { if (!sge_eval_expression(TYPE_HOST, hostname, hname, NULL)) { break; } } } } return ret; }
lListElem * host_list_locate(const lList *host_list, const char *hostname) { lListElem *ret = NULL; DENTER(TOP_LAYER, "host_list_locate"); if (host_list != NULL) { if (hostname != NULL) { const lListElem *element = lFirst(host_list); if (element != NULL) { int nm = NoName; if (object_has_type(element, EH_Type)) { nm = object_get_primary_key(EH_Type); } else if (object_has_type(element, AH_Type)) { nm = object_get_primary_key(AH_Type); } else if (object_has_type(element, SH_Type)) { nm = object_get_primary_key(SH_Type); } ret = lGetElemHost(host_list, nm, hostname); } } else { CRITICAL((SGE_EVENT, MSG_SGETEXT_NULLPTRPASSED_S, SGE_FUNC)); } } else { /* * This is a normal case and no error * if e.g. someone tries to find a element at qmaster startup to * check if a certain element should be added */ ret = NULL; } DRETURN(ret); }
int do_qhost(void *ctx, lList *host_list, lList *user_list, lList *resource_match_list, lList *resource_list, u_long32 show, lList **alpp, qhost_report_handler_t* report_handler) { lList *cl = NULL; lList *ehl = NULL; lList *ql = NULL; lList *jl = NULL; lList *pel = NULL; lListElem *ep; lCondition *where = NULL; bool have_lists = true; int print_header = 1; int ret = QHOST_SUCCESS; bool show_binding = ((show & QHOST_DISPLAY_BINDING) == QHOST_DISPLAY_BINDING) ? true : false; #define HEAD_FORMAT_BINDING "%-23s %-13.13s%4.4s %4.4s %4.4s %5.5s %7.7s %7.7s %7.7s %7.7s\n" #define HEAD_FORMAT "%-23s %-13.13s%4.4s %5.5s %7.7s %7.7s %7.7s %7.7s\n" DENTER(TOP_LAYER, "do_qhost"); have_lists = get_all_lists(ctx, alpp, &ql, &jl, &cl, &ehl, &pel, host_list, user_list, show); if (have_lists == false) { free_all_lists(&ql, &jl, &cl, &ehl, &pel); DRETURN(QHOST_ERROR); } /* ** delete ok message */ lFreeList(alpp); centry_list_init_double(cl); /* ** handle -l request for host */ if (lGetNumberOfElem(resource_match_list)) { int selected; lListElem *global = NULL; if (centry_list_fill_request(resource_match_list, alpp, cl, true, true, false)) { /* TODO: error message gets written by centry_list_fill_request into SGE_EVENT */ free_all_lists(&ql, &jl, &cl, &ehl, &pel); DRETURN(QHOST_ERROR); } { /* clean host list */ lListElem *host = NULL; for_each(host, ehl) { lSetUlong(host, EH_tagged, 0); } } /* prepare request */ global = lGetElemHost(ehl, EH_name, "global"); selected = sge_select_queue(resource_match_list, NULL, global, ehl, cl, true, -1, NULL, NULL, NULL); if (selected) { for_each(ep, ehl) { lSetUlong(ep, EH_tagged, 1); } } else {
/****** qquota_output/qquota_output() ******************************************** * NAME * qquota_output() -- qquota output function * * SYNOPSIS * bool qquota_output(void *ctx, lList *host_list, lList *resource_match_list, * lList *user_list, lList *pe_list, lList *project_list, lList * *cqueue_list, lList **alpp, report_handler_t* report_handler) * * FUNCTION * print resource quota rule and the limit * * INPUTS * void *ctx - gdi handler * lList *host_list - selected hosts * lList *resource_match_list - selected resources * lList *user_list - selected users * lList *pe_list - selecte pes * lList *project_list - selected projects * lList *cqueue_list - selected cluster queues * lList **alpp - answer list * report_handler_t* report_handler - report handler for xml output * * RESULT * bool - true on success * false on error * * NOTES * MT-NOTE: qquota_output() is MT safe * *******************************************************************************/ bool qquota_output(sge_gdi_ctx_class_t *ctx, lList *host_list, lList *resource_match_list, lList *user_list, lList *pe_list, lList *project_list, lList *cqueue_list, lList **alpp, report_handler_t* report_handler) { lList *rqs_list = NULL; lList *centry_list = NULL; lList *userset_list = NULL; lList *hgroup_list = NULL; lList *exechost_list = NULL; lListElem* global_host = NULL; lListElem* exec_host = NULL; lList* printed_rules = NULL; /* Hash list of already printed resource quota rules (possible with -u user1,user2,user3...) */ bool ret = true; int xml_ret = 0; qquota_filter_t qquota_filter = { "*", "*", "*", "*", "*" }; dstring rule_name = DSTRING_INIT; DENTER(TOP_LAYER, "qquota_output"); /* If no user is requested on command line we set the current user as default */ qquota_filter.user = ctx->get_username(ctx); ret = get_all_lists(ctx, &rqs_list, ¢ry_list, &userset_list, &hgroup_list, &exechost_list, host_list, alpp); if (ret == true) { lListElem *rqs = NULL; printed_rules = lCreateList("rule_hash", ST_Type); global_host = host_list_locate(exechost_list, SGE_GLOBAL_NAME); if (report_handler != NULL) { xml_ret = report_handler->report_started(report_handler, alpp); if (xml_ret != QQUOTA_SUCCESS) { ret = false; goto qquota_output_error; } } for_each(rqs, rqs_list) { lListElem *rule = NULL; int rule_count = 1; if (lGetBool(rqs, RQS_enabled) == false) { continue; } for_each(rule, lGetList(rqs, RQS_rule)) { lListElem *user_ep = lFirst(user_list); lListElem *project_ep = lFirst(project_list); lListElem *pe_ep = lFirst(pe_list); lListElem *queue_ep = lFirst(cqueue_list); lListElem *host_ep = lFirst(host_list); do { if (user_ep != NULL) { qquota_filter.user = lGetString(user_ep, ST_name); } do { if (project_ep != NULL) { qquota_filter.project = lGetString(project_ep, ST_name); } do { if (pe_ep != NULL) { qquota_filter.pe = lGetString(pe_ep, ST_name); } do { if (queue_ep != NULL) { qquota_filter.queue = lGetString(queue_ep, ST_name); } do { if (host_ep != NULL) { qquota_filter.host = lGetString(host_ep, ST_name); } if (rqs_is_matching_rule(rule, qquota_filter.user, NULL, qquota_filter.project, qquota_filter.pe, qquota_filter.host, qquota_filter.queue, userset_list, hgroup_list)) { lListElem *limit = NULL; for_each(limit, lGetList(rule, RQR_limit)) { const char *limit_name = lGetString(limit, RQRL_name); lList *rue_list = lGetList(limit, RQRL_usage); lListElem *raw_centry = centry_list_locate(centry_list, limit_name); lListElem *rue_elem = NULL; if (raw_centry == NULL) { /* undefined centries can be ignored */ DPRINTF(("centry %s not defined -> IGNORING\n", limit_name)); continue; } if ((resource_match_list != NULL) && ((centry_list_locate(resource_match_list, limit_name) == NULL) && (centry_list_locate(resource_match_list, lGetString(raw_centry, CE_shortcut)) == NULL))) { DPRINTF(("centry %s was not requested on CLI -> IGNORING\n", limit_name)); continue; } if (lGetString(rule, RQR_name)) { sge_dstring_sprintf(&rule_name, "%s/%s", lGetString(rqs, RQS_name), lGetString(rule, RQR_name)); } else { sge_dstring_sprintf(&rule_name, "%s/%d", lGetString(rqs, RQS_name), rule_count); } if (lGetUlong(raw_centry, CE_consumable)) { /* for consumables we need to walk through the utilization and search for matching values */ DPRINTF(("found centry %s - consumable\n", limit_name)); for_each(rue_elem, rue_list) { u_long32 dominant = 0; const char *rue_name = lGetString(rue_elem, RUE_name); char *cp = NULL; stringT user, project, pe, queue, host; dstring limit_str = DSTRING_INIT; dstring value_str = DSTRING_INIT; qquota_filter_t qf = { NULL, NULL, NULL, NULL, NULL }; /* check user name */ cp = qquota_get_next_filter(user, rue_name); /* usergroups have the same beginning character @ as host groups */ if (is_hgroup_name(qquota_filter.user)) { lListElem *ugroup = NULL; if ((ugroup = userset_list_locate(userset_list, &qquota_filter.user[1])) != NULL) { if (sge_contained_in_access_list(user, NULL, ugroup, NULL) == 0) { continue; } } } else { if ((strcmp(user, "-") != 0) && (strcmp(qquota_filter.user, "*") != 0) && (fnmatch(qquota_filter.user, user, 0) != 0)) { continue; } } /* check project */ cp = qquota_get_next_filter(project, cp); if ((strcmp(project, "-") != 0) && (strcmp(qquota_filter.project, "*") != 0) && (fnmatch(qquota_filter.project, project, 0) != 0)) { continue; } /* check parallel environment */ cp = qquota_get_next_filter(pe, cp); if ((strcmp(pe, "-") != 0) && (strcmp(qquota_filter.pe, "*") != 0) && (fnmatch(qquota_filter.pe, pe, 0) != 0) ) { continue; } /* check cluster queue */ cp = qquota_get_next_filter(queue, cp); if ((strcmp(queue, "-") != 0) && (strcmp(qquota_filter.queue, "*") != 0) && (fnmatch(qquota_filter.queue, queue, 0) != 0)) { continue; } /* check host name */ cp = qquota_get_next_filter(host, cp); if (is_hgroup_name(qquota_filter.host)) { lListElem *hgroup = NULL; if ((hgroup = hgroup_list_locate(hgroup_list, qquota_filter.host)) != NULL) { lList *host_list = NULL; hgroup_find_all_references(hgroup, NULL, hgroup_list, &host_list, NULL); if (host_list == NULL && lGetElemHost(host_list, HR_name, host) == NULL) { lFreeList(&host_list); continue; } lFreeList(&host_list); } } else { if ((strcmp(host, "-") != 0) && (strcmp(qquota_filter.host, "*") != 0) && (fnmatch(qquota_filter.host, host, 0) != 0) ) { continue; } } if (lGetBool(limit, RQRL_dynamic)) { exec_host = host_list_locate(exechost_list, host); sge_dstring_sprintf(&limit_str, "%d", (int)scaled_mixed_load(lGetString(limit, RQRL_value), global_host, exec_host, centry_list)); } else { lSetDouble(raw_centry, CE_pj_doubleval, lGetDouble(limit, RQRL_dvalue)); sge_get_dominant_stringval(raw_centry, &dominant, &limit_str); } lSetDouble(raw_centry,CE_pj_doubleval, lGetDouble(rue_elem, RUE_utilized_now)); sge_get_dominant_stringval(raw_centry, &dominant, &value_str); qf.user = user; qf.project = project; qf.pe = pe; qf.queue = queue; qf.host = host; ret = qquota_print_out_rule(rule, rule_name, limit_name, sge_dstring_get_string(&value_str), sge_dstring_get_string(&limit_str), qf, raw_centry, report_handler, printed_rules, alpp); sge_dstring_free(&limit_str); sge_dstring_free(&value_str); } } else { /* static values */ qquota_filter_t qf = { NULL, NULL, NULL, NULL, NULL }; DPRINTF(("found centry %s - static value\n", limit_name)); ret = qquota_print_out_rule(rule, rule_name, limit_name, NULL, lGetString(limit, RQRL_value), qf, raw_centry, report_handler, printed_rules, alpp); } } } } while ((host_ep = lNext(host_ep))); } while ((queue_ep = lNext(queue_ep))); } while ((pe_ep = lNext(pe_ep))); } while ((project_ep = lNext(project_ep)));
/* * Read the cluster configuration from secondary storage using 'aSpoolContext'. * This is the bootstrap function for the configuration module. It does populate * the list with the cluster configuration. */ int sge_read_configuration(sge_gdi_ctx_class_t *ctx, lListElem *aSpoolContext, lList **config_list, lList *anAnswer) { lListElem *local = NULL; lListElem *global = NULL; int ret = -1; const char *cell_root = ctx->get_cell_root(ctx); const char *qualified_hostname = ctx->get_qualified_hostname(ctx); u_long32 progid = ctx->get_who(ctx); DENTER(TOP_LAYER, "sge_read_configuration"); SGE_LOCK(LOCK_MASTER_CONF, LOCK_WRITE); spool_read_list(&anAnswer, aSpoolContext, config_list, SGE_TYPE_CONFIG); /* * For Urubu (6.2u2) we won't have and update script. Therefore the master * has to be able to cope with a missing "jsv_url" string. * * TODO: Nethertheless we have to add the "jsv_url" to the update script * for the first release after Urubu. */ { lListElem *global = lGetElemHost(*config_list, CONF_name, "global"); if (global != NULL) { lList *entries = lGetList(global, CONF_entries); lListElem *jsv_url = lGetElemStr(entries, CF_name, "jsv_url"); if (jsv_url == NULL) { jsv_url = lAddSubStr(global, CF_name, "jsv_url", CONF_entries, CF_Type); if (jsv_url != NULL) { lSetString(jsv_url, CF_value, "none"); } } } } /* * For Urubu (6.2u2) we won't have and update script. Therefore the master * has to be able to cope with a missing "jsv_allowed_mod" string. * * TODO: Nethertheless we have to add the "jsv_allowed_mod" to the update * script for the first release after Urubu. */ { lListElem *global = lGetElemHost(*config_list, CONF_name, "global"); if (global != NULL) { lList *entries = lGetList(global, CONF_entries); lListElem *jsv_url = lGetElemStr(entries, CF_name, "jsv_allowed_mod"); if (jsv_url == NULL) { jsv_url = lAddSubStr(global, CF_name, "jsv_allowed_mod", CONF_entries, CF_Type); if (jsv_url != NULL) { lSetString(jsv_url, CF_value, "ac,h,i,e,o,j,M,N,p,w"); } } } } SGE_UNLOCK(LOCK_MASTER_CONF, LOCK_WRITE); answer_list_output(&anAnswer); DPRINTF(("qualified_hostname: '%s'\n", qualified_hostname)); if ((local = sge_get_configuration_for_host(qualified_hostname)) == NULL) { /* write a warning into messages file, if no local config exists*/ WARNING((SGE_EVENT, MSG_CONF_NOLOCAL_S, qualified_hostname)); } if ((global = sge_get_configuration_for_host(SGE_GLOBAL_NAME)) == NULL) { ERROR((SGE_EVENT, SFNMAX, MSG_CONF_NOGLOBAL)); DRETURN(-1); } ret = merge_configuration(&anAnswer, progid, cell_root, global, local, NULL); answer_list_output(&anAnswer); lFreeElem(&local); lFreeElem(&global); if (0 != ret) { ERROR((SGE_EVENT, MSG_CONFIG_ERRORXMERGINGCONFIGURATIONY_IS, ret, qualified_hostname)); DRETURN(-1); } sge_show_conf(); DRETURN(0); }