/** * @brief * free_node_partition - free a node_partition structure * * @param[in] np - the node_partition to free * */ void free_node_partition(node_partition *np) { if (np == NULL) return; if (np->name != NULL) free(np->name); np->def = NULL; if (np->res_val != NULL) free(np->res_val); if (np->res != NULL) free_resource_list(np->res); if (np->ninfo_arr != NULL) free(np->ninfo_arr); if (np->bkts != NULL) free_node_bucket_array(np->bkts); free(np); }
/* * * free_queue_info - free space used by a queue info struct * * qinfo - queue to free * * returns nothing * */ void free_queue_info(queue_info *qinfo) { if (qinfo -> name != NULL) free(qinfo -> name); if (qinfo -> qres != NULL) free_resource_list(qinfo -> qres); if (qinfo -> running_jobs != NULL) free(qinfo -> running_jobs); free(qinfo); }
/** * @brief * free_queue_info - free space used by a queue info struct * * @param[in,out] qinfo - queue to free * * @return nothing * */ void free_queue_info(queue_info *qinfo) { if (qinfo->name != NULL) free(qinfo->name); if (qinfo->qres != NULL) free_resource_list(qinfo->qres); if (qinfo->running_jobs != NULL) free(qinfo->running_jobs); if (qinfo->nodes != NULL) free(qinfo->nodes); if (qinfo->nodes_in_partition != NULL) free(qinfo->nodes_in_partition); if (qinfo->alljobcounts != NULL) free_counts_list(qinfo->alljobcounts); if (qinfo->group_counts != NULL) free_counts_list(qinfo->group_counts); if (qinfo->project_counts != NULL) free_counts_list(qinfo->project_counts); if (qinfo->user_counts != NULL) free_counts_list(qinfo->user_counts); if (qinfo->total_alljobcounts != NULL) free_counts_list(qinfo->total_alljobcounts); if (qinfo->total_group_counts != NULL) free_counts_list(qinfo->total_group_counts); if (qinfo->total_project_counts != NULL) free_counts_list(qinfo->total_project_counts); if (qinfo->total_user_counts != NULL) free_counts_list(qinfo->total_user_counts); if (qinfo->nodepart != NULL) free_node_partition_array(qinfo->nodepart); if (qinfo->allpart != NULL) free_node_partition(qinfo->allpart); if (qinfo->node_group_key != NULL) free_string_array(qinfo->node_group_key); if (qinfo->liminfo != NULL) { lim_free_liminfo(qinfo->liminfo); qinfo->liminfo = NULL; } if (qinfo->partition != NULL) free(qinfo->partition); free(qinfo); }
/* * * free_server_info - free the space used by a server_info structure * * returns norhing * */ void free_server_info(server_info *sinfo) { if (sinfo -> name != NULL) free(sinfo -> name); if (sinfo -> default_queue != NULL) free(sinfo -> default_queue); if (sinfo -> jobs != NULL) free(sinfo -> jobs); if (sinfo -> running_jobs != NULL) free(sinfo -> running_jobs); if (sinfo -> timesharing_nodes != NULL) free(sinfo -> timesharing_nodes); free_resource_list(sinfo -> res); free(sinfo); }
int main(int argc, const char **argv) { vector<const char*> args; Config_t config; char *config_file; int i; global_config = &config; //** Make the global point to what's loaded memset(global_config, 0, sizeof(Config_t)); //** init the data global_network = NULL; if (argc < 2) { printf("ibp_server [-d] config_file\n\n"); printf("-d - Run as a daemon\n"); printf("config_file - Configuration file\n"); return(0); } int astart = 1; int daemon = 0; if (strcmp(argv[astart], "-d") == 0) { daemon = 1; argv[astart] = ""; astart++; } config_file = (char *)argv[astart]; argv_to_vec(argc, argv, args); parse_config_options(args); // These are for EBOFS //*** Open the config file ***** printf("Config file: %s\n\n", config_file); GKeyFile *keyfile; GKeyFileFlags flags; GError *error = NULL; keyfile = g_key_file_new(); flags = G_KEY_FILE_NONE; /* Load the GKeyFile from disk or return. */ if (!g_key_file_load_from_file (keyfile, config_file, flags, &error)) { g_error (error->message); return(-1); } //** Parse the global options first *** parse_config(keyfile, &config); init_thread_slots(2*config.server.max_threads); //** Make pigeon holes dns_cache_init(1000); init_subnet_list(config.server.iface[0].hostname); //*** Install the commands: loads Vectable info and parses config options only **** install_commands(keyfile); g_key_file_free(keyfile); //Free the keyfile context set_starttime(); log_preamble(&config); configure_signals(); //** Setup the signal handlers //*** Set up the shutdown variables pthread_mutex_init(&shutdown_lock, NULL); pthread_mutex_unlock(&shutdown_lock); shutdown_now = 0; //*** Make the searchable version of the resources *** config.rl = create_resource_list(config.res, config.n_resources); // log_printf(0, "Looking up resource 2 and printing info.....\n") // print_resource(resource_lookup(config.rl, "2"), log_fd()); init_stats(config.server.stats_size); lock_alloc_init(); //***Launch as a daemon if needed*** if (args.size() == 2) { //*** Launch as a daemon *** if ((strcmp(config.server.logfile, "stdout") == 0) || (strcmp(config.server.logfile, "stderr") == 0)) { log_printf(0, "Can't launch as a daemom because log_file is either stdout or stderr\n"); log_printf(0, "Running in normal mode\n"); } else if (fork() == 0) { //** This is the daemon log_printf(0, "Running as a daemon.\n"); flush_log(); fclose(stdin); //** Need to close all the std* devices ** fclose(stdout); fclose(stderr); char fname[1024]; fname[1023] = '\0'; snprintf(fname, 1023, "%s.stdout", config.server.logfile); assert((stdout = fopen(fname, "w")) != NULL); snprintf(fname, 1023, "%s.stderr", config.server.logfile); assert((stderr = fopen(fname, "w")) != NULL); // stdout = stderr = log_fd(); //** and reassign them to the log device printf("ibp_server.c: STDOUT=STDERR=LOG_FD() dnoes not work!!!!!!!!!!!!!!!!!!!!!!!!\n"); } else { //** Parent exits exit(0); } } // test_alloc(); //** Used for testing allocation speed only //*** Initialize all command data structures. This is mainly 3rd party commands *** initialize_commands(); //** Launch the garbage collection threads for (i=0; i<config.n_resources; i++) launch_resource_cleanup_thread(&(config.res[i])); //*** Start the activity log *** alog_open(); server_loop(&config); //***** Main processing loop ****** //*** Shutdown the activity log *** alog_close(); //*** Destroy all the 3rd party structures *** destroy_commands(); lock_alloc_destroy(); destroy_thread_slots(); shutdown(&config); free_resource_list(config.rl); free_stats(); log_printf(0, "main: Completed shutdown. Exiting\n"); // close_log(); // close_debug(); }
/** * @brief * simulate the minimum amount of a resource list * for an event list until a point in time. The * comparison we are simulating the minimum for is * (resources_available.foo - resources_assigned.foo) * The minimum is simulated by holding resources_available * constant and maximizing the resources_assigned value * * @note * This function only simulates START and END events. If at some * point in the future we start simulating events such as * qmgr -c 's s resources_available.ncpus + =5' this function will * will have to be revisited. * * @param[in] reslist - resource list to simulate * @param[in] end - end time * @param[in] calendar - calendar to simulate * @param[in] incl_arr - only use events for resresvs in this array (can be NULL) * @param[in] exclude - job/resv to ignore (possibly NULL) * * @return static pointer to amount of resources available during * @retval the entire length from now to end * @retval NULL : on error * * @par MT-safe: No */ schd_resource * simulate_resmin(schd_resource *reslist, time_t end, event_list *calendar, resource_resv **incl_arr, resource_resv *exclude) { static schd_resource *retres = NULL; /* return pointer */ schd_resource *cur_res; schd_resource *cur_resmin; resource_req *req; schd_resource *res; schd_resource *resmin = NULL; timed_event *te; resource_resv *resresv; unsigned int event_mask = (TIMED_RUN_EVENT | TIMED_END_EVENT); if (reslist == NULL) return NULL; /* if there is no calendar, then there is nothing to do */ if (calendar == NULL) return reslist; /* If there are no run events in the calendar between now and the end time * then there is nothing to do. Nothing will reduce resources (only increase) */ if (exists_run_event(calendar, end) == 0) return reslist; if (retres != NULL) { free_resource_list(retres); retres = NULL; } if ((res = dup_resource_list(reslist)) == NULL) return NULL; if ((resmin = dup_resource_list(reslist)) == NULL) { free_resource_list(res); return NULL; } te = get_next_event(calendar); for (te = find_init_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask); te != NULL && (end == 0 || te->event_time < end); te = find_next_timed_event(te, IGNORE_DISABLED_EVENTS, event_mask)) { resresv = (resource_resv*) te->event_ptr; if (incl_arr == NULL || find_resource_resv_by_rank(incl_arr, resresv->rank) !=NULL) { if (resresv != exclude) { req = resresv->resreq; for (; req != NULL; req = req->next) { if (req->type.is_consumable) { cur_res = find_alloc_resource(res, req->def); if (cur_res == NULL) { free_resource_list(res); free_resource_list(resmin); return NULL; } if (te->event_type == TIMED_RUN_EVENT) cur_res->assigned += req->amount; else cur_res->assigned -= req->amount; cur_resmin = find_alloc_resource(resmin, req->def); if (cur_resmin == NULL) { free_resource_list(res); free_resource_list(resmin); return NULL; } if (cur_res->assigned > cur_resmin->assigned) cur_resmin->assigned = cur_res->assigned; } } } } } free_resource_list(res); retres = resmin; return retres; }
static char *remote_completion(const char *text, int state) { static struct resource *reslist, *current; static int len; static time_t last_fetch; static char *last_path; char *name; if (state == 0) { /* Check to see if we should refresh the dumb cache. * or, initialize the local cache of remote filenames * The remote resource list persists until a completion * in a new context is requested or the cache expires. */ /* TODO get cache expire time from config, currently from cadaver.h * TODO cache and fetch on deep/absolute paths: (path: /a/b/, text: c/d) */ if (last_fetch < (time(NULL) - COMPLETION_CACHE_EXPIRE) || !last_path || strcmp(session.uri.path, last_path) != 0) { if (last_path != NULL) { free(last_path); } if (reslist != NULL) { free_resource_list(reslist); } /* Hide the connection status */ ne_set_notifier(session.sess, NULL, NULL); if (fetch_resource_list(session.sess, session.uri.path, 1, 0, &reslist) != NE_OK) { reslist = NULL; } /* Restore the session connection printing */ ne_set_notifier(session.sess, notifier, NULL); last_path = ne_strdup(session.uri.path); } current = reslist; len = strlen(text); time(&last_fetch); } while (current) { /* Massage the absolute URI to a URI relative to our path */ /* Copy & paste & search & replace from ls.c */ if (ne_path_has_trailing_slash(current->uri)) { current->uri[strlen(current->uri)-1] = '\0'; } name = strrchr(current->uri, '/'); if (name != NULL && strlen(name+1) > 0) { name++; } else { name = current->uri; } name = ne_path_unescape(name); if (strncmp(text, name, len) == 0) { current = current->next; /* FIXME: readline docs say readline will free() this when * it's finished with, although 'memprof' shows that it * leaks. */ return name; } current = current->next; } return NULL; }