static krb5_error_code KRB5_CALLCONV scc_end_cache_get(krb5_context context, krb5_cc_cursor cursor) { struct cache_iter *ctx = cursor; exec_stmt(context, ctx->db, ctx->drop, 0); sqlite3_finalize(ctx->stmt); sqlite3_close(ctx->db); free(ctx->drop); free(ctx); return 0; }
bool command::process(term & t) { bool ret = false; term resp; #ifdef PRINTCMD char * tmpbuf = print_term(command); REMOTE_LOG(DBG, "========================================\nCOMMAND : %s %s\n========================================\n", CMD_NAME_STR(ERL_INT_VALUE(cmd)), tmpbuf); delete tmpbuf; #endif if(t.is_tuple() && t[1].is_integer()) { int cmd = t[1].v.i; resp.tuple(); resp.add(t[0]); resp.insert().integer(cmd); if((t.length() - 1) != (size_t)CMD_ARGS_COUNT(cmd)) { term & _t = resp.insert().tuple(); _t.insert().atom("error"); _t.insert().atom("badarg"); if(resp.is_undef()) REMOTE_LOG(ERR, "ERROR badarg %s expected %d, got %d\n", CMD_NAME_STR(cmd) , CMD_ARGS_COUNT(cmd), (t.length() - 1)); if(resp.is_undef()) REMOTE_LOG(CRT, "driver error: no resp generated, shutting down port\n"); vector<unsigned char> respv = tc.encode(resp); p.write_cmd(respv); } else { switch(cmd) { case RMOTE_MSG: ret = change_log_flag(t, resp); break; case GET_SESSN: ret = get_session(t, resp); break; case PUT_SESSN: ret = release_conn(t, resp); break; case CMT_SESSN: ret = commit(t, resp); break; case RBK_SESSN: ret = rollback(t, resp); break; case CMD_DSCRB: ret = describe(t, resp); break; case PREP_STMT: ret = prep_sql(t, resp); break; case BIND_ARGS: ret = bind_args(t, resp); break; case EXEC_STMT: ret = exec_stmt(t, resp); break; case FTCH_ROWS: ret = fetch_rows(t, resp); break; case CLSE_STMT: ret = close_stmt(t, resp); break; case GET_LOBDA: ret = get_lob_data(t, resp); break; case CMD_ECHOT: ret = echo(t, resp); break; case SESN_PING: ret = ping(t, resp); break; default: ret = true; break; } } } return ret; }
static krb5_error_code KRB5_CALLCONV scc_end_get (krb5_context context, krb5_ccache id, krb5_cc_cursor *cursor) { struct cred_ctx *ctx = *cursor; krb5_scache *s = SCACHE(id); sqlite3_finalize(ctx->stmt); sqlite3_finalize(ctx->credstmt); exec_stmt(context, s->db, ctx->drop, 0); free(ctx->drop); free(ctx); return 0; }
/** * cray_is_gemini_system - Figure out whether SeaStar (XT) or Gemini (XE) * @handle: connected to sdb.XTAdmin database * Returns * -1 on error * 1 if on a Gemini system * 0 if on a SeaStar system */ int cray_is_gemini_system(MYSQL *handle) { /* * Rationale: * - XT SeaStar systems have one SeaStar ASIC per node. * There are 4 nodes and 4 SeaStar ASICS on each blade, giving * 4 distinct (X,Y,Z) coordinates per blade, so that the total * node count equals the total count of torus coordinates. * - XE Gemini systems connect pairs of nodes to a Gemini chip. * There are 4 nodes on a blade and 2 Gemini chips. Nodes 0/1 * are connected to Gemini chip 0, nodes 2/3 are connected to * Gemini chip 1. This configuration acts as if the nodes were * internally joined in Y dimension; hence there are half as * many (X,Y,Z) coordinates than there are nodes in the system. * - Coordinates may be NULL if a network chip is deactivated. */ const char query[] = "SELECT COUNT(DISTINCT x_coord, y_coord, z_coord) < COUNT(*) " "FROM processor " "WHERE x_coord IS NOT NULL " "AND y_coord IS NOT NULL " "AND z_coord IS NOT NULL"; MYSQL_BIND result[1]; signed char answer; my_bool is_null; my_bool is_error; MYSQL_STMT *stmt; memset(result, 0, sizeof(result)); result[0].buffer_type = MYSQL_TYPE_TINY; result[0].buffer = (char *)&answer; result[0].is_null = &is_null; result[0].error = &is_error; stmt = prepare_stmt(handle, query, NULL, 0, result, 1); if (stmt == NULL) return -1; if (exec_stmt(stmt, query, result, 1) < 0) answer = -1; mysql_stmt_close(stmt); return answer; }
/** * basil_geometry - Verify node attributes, resolve (X,Y,Z) coordinates. */ extern int basil_geometry(struct node_record *node_ptr_array, int node_cnt) { struct node_record *node_ptr, *end = node_ptr_array + node_cnt; /* General */ MYSQL *handle; MYSQL_STMT *stmt = NULL; /* Input parameters */ unsigned int node_id; /* * Use a left outer join here since the attributes table may not be * populated for a given nodeid (e.g. when the node has been disabled * on the SMW via 'xtcli disable'). * The processor table has more authoritative information, if a nodeid * is not listed there, it does not exist. */ const char query[] = "SELECT x_coord, y_coord, z_coord," " cab_position, cab_row, cage, slot, cpu," " LOG2(coremask+1), availmem, " " processor_type " "FROM processor LEFT JOIN attributes " "ON processor_id = nodeid " "WHERE processor_id = ? "; const int PARAM_COUNT = 1; /* node id */ MYSQL_BIND params[PARAM_COUNT]; int x_coord, y_coord, z_coord; int cab, row, cage, slot, cpu; unsigned int node_cpus, node_mem; char proc_type[BASIL_STRING_SHORT]; MYSQL_BIND bind_cols[COLUMN_COUNT]; my_bool is_null[COLUMN_COUNT]; my_bool is_error[COLUMN_COUNT]; int is_gemini, i; memset(params, 0, sizeof(params)); params[0].buffer_type = MYSQL_TYPE_LONG; params[0].is_unsigned = true; params[0].is_null = (my_bool *)0; params[0].buffer = (char *)&node_id; memset(bind_cols, 0, sizeof(bind_cols)); for (i = 0; i < COLUMN_COUNT; i ++) { bind_cols[i].is_null = &is_null[i]; bind_cols[i].error = &is_error[i]; if (i == COL_TYPE) { bind_cols[i].buffer_type = MYSQL_TYPE_STRING; bind_cols[i].buffer_length = sizeof(proc_type); bind_cols[i].buffer = proc_type; } else { bind_cols[i].buffer_type = MYSQL_TYPE_LONG; bind_cols[i].is_unsigned = (i >= COL_CORES); } } bind_cols[COL_X].buffer = (char *)&x_coord; bind_cols[COL_Y].buffer = (char *)&y_coord; bind_cols[COL_Z].buffer = (char *)&z_coord; bind_cols[COL_CAB].buffer = (char *)&cab; bind_cols[COL_ROW].buffer = (char *)&row; bind_cols[COL_CAGE].buffer = (char *)&cage; bind_cols[COL_SLOT].buffer = (char *)&slot; bind_cols[COL_CPU].buffer = (char *)&cpu; bind_cols[COL_CORES].buffer = (char *)&node_cpus; bind_cols[COL_MEMORY].buffer = (char *)&node_mem; handle = cray_connect_sdb(); if (handle == NULL) fatal("can not connect to XTAdmin database on the SDB"); is_gemini = cray_is_gemini_system(handle); if (is_gemini < 0) fatal("can not determine Cray XT/XE system type"); stmt = prepare_stmt(handle, query, params, PARAM_COUNT, bind_cols, COLUMN_COUNT); if (stmt == NULL) fatal("can not prepare statement to resolve Cray coordinates"); for (node_ptr = node_record_table_ptr; node_ptr < end; node_ptr++) { if ((node_ptr->name == NULL) || (sscanf(node_ptr->name, "nid%05u", &node_id) != 1)) { error("can not read basil_node_id from %s", node_ptr->name); continue; } if (exec_stmt(stmt, query, bind_cols, COLUMN_COUNT) < 0) fatal("can not resolve %s coordinates", node_ptr->name); if (fetch_stmt(stmt) == 0) { #if _DEBUG info("proc_type:%s cpus:%u memory:%u", proc_type, node_cpus, node_mem); info("row:%u cage:%u slot:%u cpu:%u xyz:%u:%u:%u", row, cage, slot, cpu, x_coord, y_coord, z_coord); #endif if (strcmp(proc_type, "compute") != 0) { /* * Switching a compute node to be a service node * can not happen at runtime: requires a reboot. */ fatal("Node '%s' is a %s node. " "Only compute nodes can appear in slurm.conf.", node_ptr->name, proc_type); } else if (is_null[COL_CORES] || is_null[COL_MEMORY]) { /* * This can happen if a node has been disabled * on the SMW (using 'xtcli disable <nid>'). The * node will still be listed in the 'processor' * table, but have no 'attributes' entry (NULL * values for CPUs/memory). Also, the node will * be invisible to ALPS, which is why we need to * set it down here already. */ node_cpus = node_mem = 0; node_ptr->node_state = NODE_STATE_DOWN; xfree(node_ptr->reason); node_ptr->reason = xstrdup("node data unknown -" " disabled on SMW?"); error("%s: %s", node_ptr->name, node_ptr->reason); } else if (node_cpus < node_ptr->config_ptr->cpus) { /* * FIXME: Might reconsider this policy. * * FastSchedule is ignored here, it requires the * slurm.conf to be consistent with hardware. * * Assumption is that CPU/Memory do not change * at runtime (Cray has no hot-swappable parts). * * Hence checking it in basil_inventory() would * mean a lot of runtime overhead. */ fatal("slurm.conf: node %s has only Procs=%d", node_ptr->name, node_cpus); } else if (node_mem < node_ptr->config_ptr->real_memory) { fatal("slurm.conf: node %s has RealMemory=%d", node_ptr->name, node_mem); } } else if (is_gemini) { fatal("Non-existing Gemini node '%s' in slurm.conf", node_ptr->name); } else { fatal("Non-existing SeaStar node '%s' in slurm.conf", node_ptr->name); } if (!is_gemini) { /* * SeaStar: each node has unique coordinates */ if (node_ptr->arch == NULL) node_ptr->arch = xstrdup("XT"); } else { /* * Gemini: each 2 nodes share the same network * interface (i.e., nodes 0/1 and 2/3 each have * the same coordinates). Use cage and cpu to * create corresponding "virtual" Y coordinate. */ y_coord = 4 * cage + cpu; if (node_ptr->arch == NULL) node_ptr->arch = xstrdup("XE"); } xfree(node_ptr->node_hostname); xfree(node_ptr->comm_name); /* * Convention: since we are using SLURM in frontend-mode, * we use Node{Addr,HostName} as follows. * * NodeAddr: <X><Y><Z> coordinates in base-36 encoding * * NodeHostName: c#-#c#s#n# using the NID convention * <cabinet>-<row><chassis><slot><node> * - each cabinet can accommodate 3 chassis (c1..c3) * - each chassis has 8 slots (s0..s7) * - each slot contains 2 or 4 nodes (n0..n3) * o either 2 service nodes (n0/n3) * o or 4 compute nodes (n0..n3) * o or 2 gemini chips (g0/g1 serving n0..n3) *free_stmt_result * Example: c0-0c1s0n1 * - c0- = cabinet 0 * - 0 = row 0 * - c1 = chassis 1 * - s0 = slot 0 * - n1 = node 1 */ node_ptr->node_hostname = xstrdup_printf("c%u-%uc%us%un%u", cab, row, cage, slot, cpu); node_ptr->comm_name = xstrdup_printf("%c%c%c", _enc_coord(x_coord), _enc_coord(y_coord), _enc_coord(z_coord)); dim_size[0] = MAX(dim_size[0], (x_coord - 1)); dim_size[1] = MAX(dim_size[1], (y_coord - 1)); dim_size[2] = MAX(dim_size[2], (z_coord - 1)); #if _DEBUG info("%s %s %s cpus=%u, mem=%u", node_ptr->name, node_ptr->node_hostname, node_ptr->comm_name, node_cpus, node_mem); #endif free_stmt_result(stmt); } if (stmt_close(stmt)) error("error closing statement: %s", mysql_stmt_error(stmt)); cray_close_sdb(handle); return basil_get_initial_state(); }
/** * basil_geometry - Check node attributes, resolve (X,Y,Z) coordinates. * * Checks both SDB database and ALPS inventory for consistency. The inventory * part is identical to basil_inventory(), with the difference of being called * before valid bitmaps exist, from select_g_node_init(). * Its dependencies are: * - it needs reset_job_bitmaps() in order to rebuild node_bitmap fields, * - it relies on _sync_nodes_to_jobs() to * o kill active jobs on nodes now marked DOWN, * o reset node state to ALLOCATED if it has been marked IDLE here (which is * an error case, since there is no longer an ALPS reservation for the job, * this is caught by the subsequent basil_inventory()). */ extern int basil_geometry(struct node_record *node_ptr_array, int node_cnt) { struct node_record *node_ptr, *end = node_ptr_array + node_cnt; enum basil_version version = get_basil_version(); struct basil_inventory *inv; /* General mySQL */ MYSQL *handle; MYSQL_STMT *stmt = NULL; /* Input parameters */ unsigned int node_id; /* * Use a left outer join here since the attributes table may not be * populated for a given nodeid (e.g. when the node has been disabled * on the SMW via 'xtcli disable'). * The processor table has more authoritative information, if a nodeid * is not listed there, it does not exist. */ const char query[] = "SELECT x_coord, y_coord, z_coord, " "processor_type FROM processor WHERE processor_id = ? "; const int PARAM_COUNT = 1; /* node id */ MYSQL_BIND params[PARAM_COUNT]; int x_coord, y_coord, z_coord; char proc_type[BASIL_STRING_SHORT]; MYSQL_BIND bind_cols[COLUMN_COUNT]; my_bool is_null[COLUMN_COUNT]; my_bool is_error[COLUMN_COUNT]; int is_gemini, i; time_t now = time(NULL); memset(params, 0, sizeof(params)); params[0].buffer_type = MYSQL_TYPE_LONG; params[0].is_unsigned = true; params[0].is_null = (my_bool *)0; params[0].buffer = (char *)&node_id; memset(bind_cols, 0, sizeof(bind_cols)); for (i = 0; i < COLUMN_COUNT; i ++) { bind_cols[i].is_null = &is_null[i]; bind_cols[i].error = &is_error[i]; if (i == COL_TYPE) { bind_cols[i].buffer_type = MYSQL_TYPE_STRING; bind_cols[i].buffer_length = sizeof(proc_type); bind_cols[i].buffer = proc_type; } else { bind_cols[i].buffer_type = MYSQL_TYPE_LONG; bind_cols[i].is_unsigned = (i >= COL_TYPE); } } bind_cols[COL_X].buffer = (char *)&x_coord; bind_cols[COL_Y].buffer = (char *)&y_coord; bind_cols[COL_Z].buffer = (char *)&z_coord; inv = get_full_inventory(version); if (inv == NULL) fatal("failed to get initial BASIL inventory"); info("BASIL %s initial INVENTORY: %d/%d batch nodes available", bv_names_long[version], inv->batch_avail, inv->batch_total); handle = cray_connect_sdb(); if (handle == NULL) fatal("can not connect to XTAdmin database on the SDB"); is_gemini = cray_is_gemini_system(handle); if (is_gemini < 0) fatal("can not determine Cray XT/XE system type"); stmt = prepare_stmt(handle, query, params, PARAM_COUNT, bind_cols, COLUMN_COUNT); if (stmt == NULL) fatal("can not prepare statement to resolve Cray coordinates"); for (node_ptr = node_record_table_ptr; node_ptr < end; node_ptr++) { struct basil_node *node; char *reason = NULL; if ((node_ptr->name == NULL) || (sscanf(node_ptr->name, "nid%05u", &node_id) != 1)) { error("can not read basil_node_id from %s", node_ptr->name); continue; } if (exec_stmt(stmt, query, bind_cols, COLUMN_COUNT) < 0) fatal("can not resolve %s coordinates", node_ptr->name); if (fetch_stmt(stmt) == 0) { #if _DEBUG info("proc_type:%s xyz:%u:%u:%u", proc_type, x_coord, y_coord, z_coord #endif if (xstrcmp(proc_type, "compute") != 0) { /* * Switching a compute node to be a service node * can not happen at runtime: requires a reboot. */ fatal("Node '%s' is a %s node. " "Only compute nodes can appear in slurm.conf.", node_ptr->name, proc_type); } else if (is_null[COL_X] || is_null[COL_Y] || is_null[COL_Z]) { /* * Similar case to the one above, observed when * a blade has been removed. Node will not * likely show up in ALPS. */ x_coord = y_coord = z_coord = 0; reason = "unknown coordinates - hardware failure?"; } } else if (is_gemini) {
/** * basil_geometry - Check node attributes, resolve (X,Y,Z) coordinates. * * Checks both SDB database and ALPS inventory for consistency. The inventory * part is identical to basil_inventory(), with the difference of being called * before valid bitmaps exist, from select_g_node_init(). * Its dependencies are: * - it needs reset_job_bitmaps() in order to rebuild node_bitmap fields, * - it relies on _sync_nodes_to_jobs() to * o kill active jobs on nodes now marked DOWN, * o reset node state to ALLOCATED if it has been marked IDLE here (which is * an error case, since there is no longer an ALPS reservation for the job, * this is caught by the subsequent basil_inventory()). */ extern int basil_geometry(struct node_record *node_ptr_array, int node_cnt) { struct node_record *node_ptr, *end = node_ptr_array + node_cnt; enum basil_version version = get_basil_version(); struct basil_inventory *inv; /* General mySQL */ MYSQL *handle; MYSQL_STMT *stmt = NULL; /* Input parameters */ unsigned int node_id; /* * Use a left outer join here since the attributes table may not be * populated for a given nodeid (e.g. when the node has been disabled * on the SMW via 'xtcli disable'). * The processor table has more authoritative information, if a nodeid * is not listed there, it does not exist. */ const char query[] = "SELECT x_coord, y_coord, z_coord," " cab_position, cab_row, cage, slot, cpu," " LOG2(coremask+1), availmem, " " processor_type " "FROM processor LEFT JOIN attributes " "ON processor_id = nodeid " "WHERE processor_id = ? "; const int PARAM_COUNT = 1; /* node id */ MYSQL_BIND params[PARAM_COUNT]; int x_coord, y_coord, z_coord; int cab, row, cage, slot, cpu; unsigned int node_cpus, node_mem; char proc_type[BASIL_STRING_SHORT]; MYSQL_BIND bind_cols[COLUMN_COUNT]; my_bool is_null[COLUMN_COUNT]; my_bool is_error[COLUMN_COUNT]; int is_gemini, i; memset(params, 0, sizeof(params)); params[0].buffer_type = MYSQL_TYPE_LONG; params[0].is_unsigned = true; params[0].is_null = (my_bool *)0; params[0].buffer = (char *)&node_id; memset(bind_cols, 0, sizeof(bind_cols)); for (i = 0; i < COLUMN_COUNT; i ++) { bind_cols[i].is_null = &is_null[i]; bind_cols[i].error = &is_error[i]; if (i == COL_TYPE) { bind_cols[i].buffer_type = MYSQL_TYPE_STRING; bind_cols[i].buffer_length = sizeof(proc_type); bind_cols[i].buffer = proc_type; } else { bind_cols[i].buffer_type = MYSQL_TYPE_LONG; bind_cols[i].is_unsigned = (i >= COL_CORES); } } bind_cols[COL_X].buffer = (char *)&x_coord; bind_cols[COL_Y].buffer = (char *)&y_coord; bind_cols[COL_Z].buffer = (char *)&z_coord; bind_cols[COL_CAB].buffer = (char *)&cab; bind_cols[COL_ROW].buffer = (char *)&row; bind_cols[COL_CAGE].buffer = (char *)&cage; bind_cols[COL_SLOT].buffer = (char *)&slot; bind_cols[COL_CPU].buffer = (char *)&cpu; bind_cols[COL_CORES].buffer = (char *)&node_cpus; bind_cols[COL_MEMORY].buffer = (char *)&node_mem; inv = get_full_inventory(version); if (inv == NULL) fatal("failed to get initial BASIL inventory"); info("BASIL %s initial INVENTORY: %d/%d batch nodes available", bv_names_long[version], inv->batch_avail, inv->batch_total); handle = cray_connect_sdb(); if (handle == NULL) fatal("can not connect to XTAdmin database on the SDB"); is_gemini = cray_is_gemini_system(handle); if (is_gemini < 0) fatal("can not determine Cray XT/XE system type"); stmt = prepare_stmt(handle, query, params, PARAM_COUNT, bind_cols, COLUMN_COUNT); if (stmt == NULL) fatal("can not prepare statement to resolve Cray coordinates"); for (node_ptr = node_record_table_ptr; node_ptr < end; node_ptr++) { struct basil_node *node; char *reason = NULL; if ((node_ptr->name == NULL) || (sscanf(node_ptr->name, "nid%05u", &node_id) != 1)) { error("can not read basil_node_id from %s", node_ptr->name); continue; } if (exec_stmt(stmt, query, bind_cols, COLUMN_COUNT) < 0) fatal("can not resolve %s coordinates", node_ptr->name); if (fetch_stmt(stmt) == 0) { #if _DEBUG info("proc_type:%s cpus:%u memory:%u", proc_type, node_cpus, node_mem); info("row:%u cage:%u slot:%u cpu:%u xyz:%u:%u:%u", row, cage, slot, cpu, x_coord, y_coord, z_coord); #endif if (strcmp(proc_type, "compute") != 0) { /* * Switching a compute node to be a service node * can not happen at runtime: requires a reboot. */ fatal("Node '%s' is a %s node. " "Only compute nodes can appear in slurm.conf.", node_ptr->name, proc_type); } else if (is_null[COL_CORES] || is_null[COL_MEMORY]) { /* * This can happen if a node has been disabled * on the SMW (using 'xtcli disable <nid>'). The * node will still be listed in the 'processor' * table, but have no 'attributes' entry (NULL * values for CPUs/memory). Also, the node will * be invisible to ALPS, which is why we need to * set it down here already. */ node_cpus = node_mem = 0; reason = "node data unknown - disabled on SMW?"; } else if (is_null[COL_X] || is_null[COL_Y] || is_null[COL_Z]) { /* * Similar case to the one above, observed when * a blade has been removed. Node will not * likely show up in ALPS. */ x_coord = y_coord = z_coord = 0; reason = "unknown coordinates - hardware failure?"; } else if (node_cpus < node_ptr->config_ptr->cpus) { /* * FIXME: Might reconsider this policy. * * FastSchedule is ignored here, it requires the * slurm.conf to be consistent with hardware. * * Assumption is that CPU/Memory do not change * at runtime (Cray has no hot-swappable parts). * * Hence checking it in basil_inventory() would * mean a lot of runtime overhead. */ fatal("slurm.conf: node %s has only Procs=%d", node_ptr->name, node_cpus); } else if (node_mem < node_ptr->config_ptr->real_memory) { fatal("slurm.conf: node %s has RealMemory=%d", node_ptr->name, node_mem); } } else if (is_gemini) { fatal("Non-existing Gemini node '%s' in slurm.conf", node_ptr->name); } else { fatal("Non-existing SeaStar node '%s' in slurm.conf", node_ptr->name); } if (!is_gemini) { /* * SeaStar: each node has unique coordinates */ if (node_ptr->arch == NULL) node_ptr->arch = xstrdup("XT"); } else { /* * Gemini: each 2 nodes share the same network * interface (i.e., nodes 0/1 and 2/3 each have * the same coordinates). */ if (node_ptr->arch == NULL) node_ptr->arch = xstrdup("XE"); } xfree(node_ptr->node_hostname); xfree(node_ptr->comm_name); /* * Convention: since we are using SLURM in frontend-mode, * we use Node{Addr,HostName} as follows. * * NodeAddr: <X><Y><Z> coordinates in base-36 encoding * * NodeHostName: c#-#c#s#n# using the NID convention * <cabinet>-<row><chassis><slot><node> * - each cabinet can accommodate 3 chassis (c1..c3) * - each chassis has 8 slots (s0..s7) * - each slot contains 2 or 4 nodes (n0..n3) * o either 2 service nodes (n0/n3) * o or 4 compute nodes (n0..n3) * o or 2 gemini chips (g0/g1 serving n0..n3) * * Example: c0-0c1s0n1 * - c0- = cabinet 0 * - 0 = row 0 * - c1 = chassis 1 * - s0 = slot 0 * - n1 = node 1 */ node_ptr->node_hostname = xstrdup_printf("c%u-%uc%us%un%u", cab, row, cage, slot, cpu); node_ptr->comm_name = xstrdup_printf("%c%c%c", _enc_coord(x_coord), _enc_coord(y_coord), _enc_coord(z_coord)); dim_size[0] = MAX(dim_size[0], (x_coord - 1)); dim_size[1] = MAX(dim_size[1], (y_coord - 1)); dim_size[2] = MAX(dim_size[2], (z_coord - 1)); #if _DEBUG info("%s %s %s cpus=%u, mem=%u", node_ptr->name, node_ptr->node_hostname, node_ptr->comm_name, node_cpus, node_mem); #endif /* * Check the current state reported by ALPS inventory, unless it * is already evident that the node has some other problem. */ if (reason == NULL) { for (node = inv->f->node_head; node; node = node->next) if (node->node_id == node_id) break; if (node == NULL) { reason = "not visible to ALPS - check hardware"; } else if (node->state == BNS_DOWN) { reason = "ALPS marked it DOWN"; } else if (node->state == BNS_UNAVAIL) { reason = "node is UNAVAILABLE"; } else if (node->state == BNS_ROUTE) { reason = "node does ROUTING"; } else if (node->state == BNS_SUSPECT) { reason = "entered SUSPECT mode"; } else if (node->state == BNS_ADMINDOWN) { reason = "node is ADMINDOWN"; } else if (node->state != BNS_UP) { reason = "state not UP"; } else if (node->role != BNR_BATCH) { reason = "mode not BATCH"; } else if (node->arch != BNA_XT) { reason = "arch not XT/XE"; } } /* Base state entirely derives from ALPS */ node_ptr->node_state &= NODE_STATE_FLAGS; if (reason) { if (node_ptr->reason) { debug("Initial DOWN node %s - %s", node_ptr->name, node_ptr->reason); } else { info("Initial DOWN node %s - %s", node_ptr->name, reason); node_ptr->reason = xstrdup(reason); } node_ptr->node_state |= NODE_STATE_DOWN; } else { if (node_is_allocated(node)) node_ptr->node_state |= NODE_STATE_ALLOCATED; else node_ptr->node_state |= NODE_STATE_IDLE; xfree(node_ptr->reason); } free_stmt_result(stmt); } if (stmt_close(stmt)) error("error closing statement: %s", mysql_stmt_error(stmt)); cray_close_sdb(handle); free_inv(inv); return SLURM_SUCCESS; }
static krb5_error_code KRB5_CALLCONV scc_get_first (krb5_context context, krb5_ccache id, krb5_cc_cursor *cursor) { krb5_scache *s = SCACHE(id); krb5_error_code ret; struct cred_ctx *ctx; char *str = NULL, *name = NULL; *cursor = NULL; ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); return ENOMEM; } ret = make_database(context, s); if (ret) { free(ctx); return ret; } if (s->cid == SCACHE_INVALID_CID) { krb5_set_error_message(context, KRB5_CC_END, N_("Iterating a invalid scache %s", ""), s->name); free(ctx); return KRB5_CC_END; } ret = asprintf(&name, "credIteration%pPid%d", ctx, (int)getpid()); if (ret < 0 || name == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); free(ctx); return ENOMEM; } ret = asprintf(&ctx->drop, "DROP TABLE %s", name); if (ret < 0 || ctx->drop == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); free(name); free(ctx); return ENOMEM; } ret = asprintf(&str, "CREATE TEMPORARY TABLE %s " "AS SELECT oid,created_at FROM credentials WHERE cid = %lu", name, (unsigned long)s->cid); if (ret < 0 || str == NULL) { free(ctx->drop); free(name); free(ctx); return ENOMEM; } ret = exec_stmt(context, s->db, str, KRB5_CC_IO); free(str); str = NULL; if (ret) { free(ctx->drop); free(name); free(ctx); return ret; } ret = asprintf(&str, "SELECT oid FROM %s ORDER BY created_at", name); if (ret < 0 || str == NULL) { exec_stmt(context, s->db, ctx->drop, 0); free(ctx->drop); free(name); free(ctx); return ret; } ret = prepare_stmt(context, s->db, &ctx->stmt, str); free(str); str = NULL; free(name); if (ret) { exec_stmt(context, s->db, ctx->drop, 0); free(ctx->drop); free(ctx); return ret; } ret = prepare_stmt(context, s->db, &ctx->credstmt, "SELECT cred FROM credentials WHERE oid = ?"); if (ret) { sqlite3_finalize(ctx->stmt); exec_stmt(context, s->db, ctx->drop, 0); free(ctx->drop); free(ctx); return ret; } *cursor = ctx; return 0; }
static krb5_error_code KRB5_CALLCONV scc_store_cred(krb5_context context, krb5_ccache id, krb5_creds *creds) { sqlite_uint64 credid; krb5_scache *s = SCACHE(id); krb5_error_code ret; krb5_data data; ret = make_database(context, s); if (ret) return ret; ret = encode_creds(context, creds, &data); if (ret) return ret; sqlite3_bind_int(s->icred, 1, s->cid); { krb5_enctype etype = 0; int kvno = 0; Ticket t; size_t len; ret = decode_Ticket(creds->ticket.data, creds->ticket.length, &t, &len); if (ret == 0) { if(t.enc_part.kvno) kvno = *t.enc_part.kvno; etype = t.enc_part.etype; free_Ticket(&t); } sqlite3_bind_int(s->icred, 2, kvno); sqlite3_bind_int(s->icred, 3, etype); } sqlite3_bind_blob(s->icred, 4, data.data, data.length, free_data); sqlite3_bind_int(s->icred, 5, time(NULL)); ret = exec_stmt(context, s->db, "BEGIN IMMEDIATE TRANSACTION", KRB5_CC_IO); if (ret) return ret; do { ret = sqlite3_step(s->icred); } while (ret == SQLITE_ROW); sqlite3_reset(s->icred); if (ret != SQLITE_DONE) { ret = KRB5_CC_IO; krb5_set_error_message(context, ret, N_("Failed to add credential: %s", ""), sqlite3_errmsg(s->db)); goto rollback; } credid = sqlite3_last_insert_rowid(s->db); { bind_principal(context, s->db, s->iprincipal, 1, creds->server); sqlite3_bind_int(s->iprincipal, 2, 1); sqlite3_bind_int(s->iprincipal, 3, credid); do { ret = sqlite3_step(s->iprincipal); } while (ret == SQLITE_ROW); sqlite3_reset(s->iprincipal); if (ret != SQLITE_DONE) { ret = KRB5_CC_IO; krb5_set_error_message(context, ret, N_("Failed to add principal: %s", ""), sqlite3_errmsg(s->db)); goto rollback; } } { bind_principal(context, s->db, s->iprincipal, 1, creds->client); sqlite3_bind_int(s->iprincipal, 2, 0); sqlite3_bind_int(s->iprincipal, 3, credid); do { ret = sqlite3_step(s->iprincipal); } while (ret == SQLITE_ROW); sqlite3_reset(s->iprincipal); if (ret != SQLITE_DONE) { ret = KRB5_CC_IO; krb5_set_error_message(context, ret, N_("Failed to add principal: %s", ""), sqlite3_errmsg(s->db)); goto rollback; } } ret = exec_stmt(context, s->db, "COMMIT", KRB5_CC_IO); if (ret) return ret; return 0; rollback: exec_stmt(context, s->db, "ROLLBACK", 0); return ret; }
static krb5_error_code KRB5_CALLCONV scc_initialize(krb5_context context, krb5_ccache id, krb5_principal primary_principal) { krb5_scache *s = SCACHE(id); krb5_error_code ret; ret = make_database(context, s); if (ret) return ret; ret = exec_stmt(context, s->db, "BEGIN IMMEDIATE TRANSACTION", KRB5_CC_IO); if (ret) return ret; if (s->cid == SCACHE_INVALID_CID) { ret = create_cache(context, s); if (ret) goto rollback; } else { sqlite3_bind_int(s->dcred, 1, s->cid); do { ret = sqlite3_step(s->dcred); } while (ret == SQLITE_ROW); sqlite3_reset(s->dcred); if (ret != SQLITE_DONE) { ret = KRB5_CC_IO; krb5_set_error_message(context, ret, N_("Failed to delete old " "credentials: %s", ""), sqlite3_errmsg(s->db)); goto rollback; } } ret = bind_principal(context, s->db, s->ucachep, 1, primary_principal); if (ret) goto rollback; sqlite3_bind_int(s->ucachep, 2, s->cid); do { ret = sqlite3_step(s->ucachep); } while (ret == SQLITE_ROW); sqlite3_reset(s->ucachep); if (ret != SQLITE_DONE) { ret = KRB5_CC_IO; krb5_set_error_message(context, ret, N_("Failed to bind principal to cache %s", ""), sqlite3_errmsg(s->db)); goto rollback; } ret = exec_stmt(context, s->db, "COMMIT", KRB5_CC_IO); if (ret) return ret; return 0; rollback: exec_stmt(context, s->db, "ROLLBACK", 0); return ret; }
static krb5_error_code make_database(krb5_context context, krb5_scache *s) { int created_file = 0; int ret; if (s->db) return 0; ret = open_database(context, s, 0); if (ret) { mode_t oldumask = umask(077); ret = open_database(context, s, SQLITE_OPEN_CREATE); umask(oldumask); if (ret) goto out; created_file = 1; ret = exec_stmt(context, s->db, SQL_CMASTER, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_CCACHE, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_CCREDS, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_CPRINCIPALS, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_SETUP_MASTER, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_TCACHE, KRB5_CC_IO); if (ret) goto out; ret = exec_stmt(context, s->db, SQL_TCRED, KRB5_CC_IO); if (ret) goto out; } #ifdef TRACEME sqlite3_trace(s->db, trace, NULL); #endif ret = prepare_stmt(context, s->db, &s->icred, SQL_ICRED); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->dcred, SQL_DCRED); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->iprincipal, SQL_IPRINCIPAL); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->icache, SQL_ICACHE); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->ucachen, SQL_UCACHE_NAME); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->ucachep, SQL_UCACHE_PRINCIPAL); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->dcache, SQL_DCACHE); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->scache, SQL_SCACHE); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->scache_name, SQL_SCACHE_NAME); if (ret) goto out; ret = prepare_stmt(context, s->db, &s->umaster, SQL_UMASTER); if (ret) goto out; return 0; out: if (s->db) sqlite3_close(s->db); if (created_file) unlink(s->file); return ret; }
static krb5_error_code KRB5_CALLCONV scc_move(krb5_context context, krb5_ccache from, krb5_ccache to) { krb5_scache *sfrom = SCACHE(from); krb5_scache *sto = SCACHE(to); krb5_error_code ret; if (strcmp(sfrom->file, sto->file) != 0) { krb5_set_error_message(context, KRB5_CC_BADNAME, N_("Can't handle cross database " "credential move: %s -> %s", ""), sfrom->file, sto->file); return KRB5_CC_BADNAME; } ret = make_database(context, sfrom); if (ret) return ret; ret = exec_stmt(context, sfrom->db, "BEGIN IMMEDIATE TRANSACTION", KRB5_CC_IO); if (ret) return ret; if (sto->cid != SCACHE_INVALID_CID) { /* drop old cache entry */ sqlite3_bind_int(sfrom->dcache, 1, sto->cid); do { ret = sqlite3_step(sfrom->dcache); } while (ret == SQLITE_ROW); sqlite3_reset(sfrom->dcache); if (ret != SQLITE_DONE) { krb5_set_error_message(context, KRB5_CC_IO, N_("Failed to delete old cache: %d", ""), (int)ret); goto rollback; } } sqlite3_bind_text(sfrom->ucachen, 1, sto->name, -1, NULL); sqlite3_bind_int(sfrom->ucachen, 2, sfrom->cid); do { ret = sqlite3_step(sfrom->ucachen); } while (ret == SQLITE_ROW); sqlite3_reset(sfrom->ucachen); if (ret != SQLITE_DONE) { krb5_set_error_message(context, KRB5_CC_IO, N_("Failed to update new cache: %d", ""), (int)ret); goto rollback; } sto->cid = sfrom->cid; ret = exec_stmt(context, sfrom->db, "COMMIT", KRB5_CC_IO); if (ret) return ret; scc_free(sfrom); return 0; rollback: exec_stmt(context, sfrom->db, "ROLLBACK", 0); scc_free(sfrom); return KRB5_CC_IO; }
static krb5_error_code KRB5_CALLCONV scc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor) { struct cache_iter *ctx; krb5_error_code ret; char *name = NULL, *str = NULL; *cursor = NULL; ctx = calloc(1, sizeof(*ctx)); if (ctx == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); return ENOMEM; } ret = default_db(context, &ctx->db); if (ctx->db == NULL) { free(ctx); return ret; } ret = asprintf(&name, "cacheIteration%pPid%d", ctx, (int)getpid()); if (ret < 0 || name == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); sqlite3_close(ctx->db); free(ctx); return ENOMEM; } ret = asprintf(&ctx->drop, "DROP TABLE %s", name); if (ret < 0 || ctx->drop == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); sqlite3_close(ctx->db); free(name); free(ctx); return ENOMEM; } ret = asprintf(&str, "CREATE TEMPORARY TABLE %s AS SELECT name FROM caches", name); if (ret < 0 || str == NULL) { krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", "")); sqlite3_close(ctx->db); free(name); free(ctx->drop); free(ctx); return ENOMEM; } ret = exec_stmt(context, ctx->db, str, KRB5_CC_IO); free(str); str = NULL; if (ret) { sqlite3_close(ctx->db); free(name); free(ctx->drop); free(ctx); return ret; } ret = asprintf(&str, "SELECT name FROM %s", name); free(name); if (ret < 0 || str == NULL) { exec_stmt(context, ctx->db, ctx->drop, 0); sqlite3_close(ctx->db); free(name); free(ctx->drop); free(ctx); return ENOMEM; } ret = prepare_stmt(context, ctx->db, &ctx->stmt, str); free(str); if (ret) { exec_stmt(context, ctx->db, ctx->drop, 0); sqlite3_close(ctx->db); free(ctx->drop); free(ctx); return ret; } *cursor = ctx; return 0; }