📄 server_info.c
字号:
if( prev != NULL ) prev -> next = resp; } return resp;}/* * * find_resource - finds a resource in a resource list * * reslist - resource list * name - name of resource to find * * returns resource if found or NULL if not * */resource *find_resource( resource *reslist, const char *name ){ resource *resp; /* used to search through list of resources */ resp = reslist; while(resp != NULL && strcmp(resp -> name, name) ) resp = resp -> next; return resp;}/* * * 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);}/* * * free_resource - free a resource struct * * res - the resource to free * * returns nothing * */void free_resource( resource *res ){ res -> next = NULL; free(res -> name); free(res);}/* * * free_resource_list - free a resource list * * reslist - the reslist to free * * returns nothing * */void free_resource_list( resource *res_list ){ resource *tmp; /* temporary next resource holder */ resource *res; /* current resource to free */ res = res_list; while(res != NULL) { tmp = res -> next; free_resource(res); res = tmp; }}/* * * new_server_info - allocate and initalize a new server_info struct * * returns pointer to new allocated struct * */server_info *new_server_info( ){ server_info *sinfo; /* the new server */ if( ( sinfo = (server_info *) malloc(sizeof( server_info ) ) ) == NULL ) return NULL; sinfo -> name = NULL; sinfo -> res = NULL; sinfo -> default_queue = NULL; sinfo -> queues = NULL; sinfo -> jobs = NULL; sinfo -> running_jobs = NULL; sinfo -> nodes = NULL; sinfo -> timesharing_nodes = NULL; sinfo -> num_queues = 0; sinfo -> num_nodes = 0; sinfo -> max_run = INFINITY; sinfo -> max_user_run = INFINITY; sinfo -> max_group_run = INFINITY; init_state_count( &(sinfo -> sc) ); return sinfo;}/* * * new_resource - allocate and initialize new resoruce struct * * returns new struct * */resource *new_resource(){ resource *resp; /* the new resource */ if( ( resp = malloc( sizeof( resource ) ) ) == NULL ) return NULL; resp -> next = NULL; resp -> max = INFINITY; resp -> assigned = UNSPECIFIED; resp -> avail = UNSPECIFIED; return resp;}/* * * print_server_info - print server_info structure * * sinfo - the struct to print * brief - only print the name of the server * * returns nothing * */void print_server_info( server_info *sinfo, char brief ){ resource *resp; /* used in printing the resources */ if( sinfo == NULL ) return; if( sinfo -> name != NULL ) printf("Server name: %s\n", sinfo -> name); if( !brief ) { printf("default_queue: %s\n", sinfo -> default_queue); printf("max_run: %d\n", sinfo -> max_run); printf("max_user_run: %d\n", sinfo -> max_user_run); printf("max_group_run: %d\n", sinfo -> max_group_run); printf("num_nodes: %d\n", sinfo -> num_nodes); printf("num_queues: %d\n", sinfo -> num_queues); print_state_count(&sinfo -> sc); resp = sinfo -> res; while( resp != NULL ) { printf("res %s max: %-10ld avail: %-10ld assigned: %-10ld\n", resp -> name, resp -> max, resp -> avail, resp -> assigned); resp = resp -> next; } }}/* * * free_server - free a server and possibly its queues also * * sinfo - the server_info list head * free_queues_too - flag to free the queues attached to server also * * returns nothing * */void free_server( server_info *sinfo, int free_objs_too ){ if( sinfo == NULL ) return; if( free_objs_too ) { free_queues( sinfo -> queues, 1); free_nodes( sinfo -> nodes ); } free_server_info( sinfo );}/* * * update_server_on_run - update server_info strucutre when a job is run * * sinfo - the server to update * qinfo - the queue the job is in * jinfo - the job that was run * * returns nothing * */void update_server_on_run(server_info *sinfo,queue_info *qinfo, job_info *jinfo){ resource_req *resreq; /* used to cycle through resources to update */ resource *res; /* used in finding a resource to update */ sinfo -> sc.running++; sinfo -> sc.queued--; resreq = jinfo -> resreq; while( resreq != NULL ) { res = find_resource( sinfo -> res, resreq -> name ); if( res ) res -> assigned += resreq -> amount; resreq = resreq -> next; }}/* * * set_jobs - create a large server job array of all the jobs on the * system by coping all the jobs from the queue job arrays * * sinfo - the server * * returns nothing */void set_jobs( server_info *sinfo ){ queue_info **qinfo; /* used to cycle through the array of queues */ job_info **jinfo; /* used in copying jobs to server array */ int i = 0, j; qinfo = sinfo -> queues; while( *qinfo != NULL ) { jinfo = (*qinfo) -> jobs; if( jinfo != NULL ) { for( j = 0; jinfo[j] != NULL; j++, i++ ) sinfo -> jobs[i] = jinfo[j]; } qinfo++; } sinfo -> jobs[i] = NULL;}/* * * check_run_job - function used by job_filter to filter out * non-running jobs. * * job - the job to check * arg - optional arg * * returns 1 if the job is running * */int check_run_job( job_info *job, void *arg ){ return job -> is_running;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -