📄 job_info.c
字号:
/** OpenPBS (Portable Batch System) v2.3 Software License* * Copyright (c) 1999-2000 Veridian Information Solutions, Inc.* All rights reserved.* * ---------------------------------------------------------------------------* For a license to use or redistribute the OpenPBS software under conditions* other than those described below, or to purchase support for this software,* please contact Veridian Systems, PBS Products Department ("Licensor") at:* * www.OpenPBS.org +1 650 967-4675 sales@OpenPBS.org* 877 902-4PBS (US toll-free)* ---------------------------------------------------------------------------* * This license covers use of the OpenPBS v2.3 software (the "Software") at* your site or location, and, for certain users, redistribution of the* Software to other sites and locations. Use and redistribution of* OpenPBS v2.3 in source and binary forms, with or without modification,* are permitted provided that all of the following conditions are met.* After December 31, 2001, only conditions 3-6 must be met:* * 1. Commercial and/or non-commercial use of the Software is permitted* provided a current software registration is on file at www.OpenPBS.org.* If use of this software contributes to a publication, product, or* service, proper attribution must be given; see www.OpenPBS.org/credit.html* * 2. Redistribution in any form is only permitted for non-commercial,* non-profit purposes. There can be no charge for the Software or any* software incorporating the Software. Further, there can be no* expectation of revenue generated as a consequence of redistributing* the Software.* * 3. Any Redistribution of source code must retain the above copyright notice* and the acknowledgment contained in paragraph 6, this list of conditions* and the disclaimer contained in paragraph 7.* * 4. Any Redistribution in binary form must reproduce the above copyright* notice and the acknowledgment contained in paragraph 6, this list of* conditions and the disclaimer contained in paragraph 7 in the* documentation and/or other materials provided with the distribution.* * 5. Redistributions in any form must be accompanied by information on how to* obtain complete source code for the OpenPBS software and any* modifications and/or additions to the OpenPBS software. The source code* must either be included in the distribution or be available for no more* than the cost of distribution plus a nominal fee, and all modifications* and additions to the Software must be freely redistributable by any party* (including Licensor) without restriction.* * 6. All advertising materials mentioning features or use of the Software must* display the following acknowledgment:* * "This product includes software developed by NASA Ames Research Center,* Lawrence Livermore National Laboratory, and Veridian Information * Solutions, Inc.* Visit www.OpenPBS.org for OpenPBS software support,* products, and information."* * 7. DISCLAIMER OF WARRANTY* * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT* ARE EXPRESSLY DISCLAIMED.* * IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE* U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT,* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.* * This license will be governed by the laws of the Commonwealth of Virginia,* without reference to its choice of law rules.*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <pbs_ifl.h>#include "queue_info.h"#include "job_info.h"#include "constant.h"#include "misc.h"#include "config.h"#include "globals.h"#include "fairshare.h"#include "node_info.h"static char *ident = "$Id: job_info.c,v 2.2.2.1.2.7 2000/08/09 00:18:59 hender Exp $";/* * * query_jobs - create an array of jobs in a specified queue * * pbs_sd - connection to pbs_server * qinfo - queue to get jobs from * * returns pointer to the head of a list of jobs * */job_info **query_jobs( int pbs_sd, queue_info *qinfo ){ /* pbs_selstat() takes a linked list of attropl structs which tell it * what information about what jobs to return. We want all jobs which are * in a specified queue */ struct attropl opl = { NULL, ATTR_q, NULL, NULL, EQ }; /* linked list of jobs returned from pbs_selstat() */ struct batch_status *jobs; /* current job in jobs linked list */ struct batch_status *cur_job; /* array of internal scheduler structures for jobs */ job_info **jinfo_arr; /* current job in jinfo_arr array */ job_info *jinfo; /* number of jobs in jinfo_arr */ int num_jobs = 0; int i; opl.value = qinfo -> name; if( ( jobs = pbs_selstat(pbs_sd, &opl, NULL) ) == NULL ) { if( pbs_errno > 0 ) fprintf(stderr, "pbs_selstat failed: %d\n", pbs_errno); return NULL; } cur_job = jobs; while( cur_job != NULL ) { num_jobs++; cur_job = cur_job -> next; } /* allocate enough space for all the jobs and the NULL sentinal */ if( ( jinfo_arr = (job_info **) malloc( sizeof( jinfo ) * (num_jobs + 1) ) ) == NULL) { perror("Memory allocation error"); pbs_statfree(jobs); return NULL; } cur_job = jobs; for( i = 0; cur_job != NULL; i++ ) { if( ( jinfo = query_job_info(cur_job, qinfo) ) == NULL ) { pbs_statfree( jobs ); free_jobs( jinfo_arr ); return NULL; } /* get the fair share group info node */ if( jinfo -> account != NULL ) jinfo -> ginfo = find_alloc_ginfo(jinfo -> account); /* if the job is not in the queued state, don't even allow * it to be considered to be run. */ if( !jinfo -> is_queued ) jinfo -> can_not_run = 1; jinfo_arr[i] = jinfo; cur_job = cur_job -> next; } jinfo_arr[i] = NULL; pbs_statfree( jobs ); return jinfo_arr;}/* * * query_job_info - takes info from a batch_status about a job and * converts it into a job_info struct * * job - batch_status struct of job * qinfo - queue where job resides * * returns job_info struct */job_info *query_job_info( struct batch_status *job, queue_info *queue ){ job_info *jinfo; /* converted job */ struct attrl *attrp; /* list of attributes returned from server */ int count; /* int used in string -> int conversion */ char *endp; /* used for strtol() */ resource_req *resreq; /* resource_req list for resources requested */ if( ( jinfo = new_job_info() ) == NULL ) return NULL; jinfo -> name = string_dup( job -> name ); attrp = job -> attribs; jinfo -> queue = queue; while( attrp != NULL ) { if( !strcmp( attrp -> name, ATTR_p) ) /* priority */ { count = strtol(attrp -> value, &endp, 10); if( *endp != '\n') jinfo -> priority = count; else jinfo -> priority = -1; } else if( !strcmp(attrp -> name, ATTR_qtime) ) /* queue time */ { count = strtol(attrp -> value, &endp, 10); if( *endp != '\n') jinfo -> qtime = count; else jinfo -> qtime = -1; } else if( !strcmp( attrp -> name, ATTR_state) ) /* state of job */ set_state( attrp -> value, jinfo ); else if( !strcmp( attrp -> name, ATTR_comment) ) /* job comment */ jinfo -> comment = string_dup( attrp -> value ); else if( !strcmp( attrp -> name, ATTR_euser ) ) /* account name */ jinfo -> account = string_dup( attrp -> value ); else if( !strcmp( attrp -> name, ATTR_egroup ) ) /* group name */ jinfo -> group = string_dup( attrp -> value ); else if( !strcmp( attrp -> name, ATTR_exechost ) ) /* where job is running*/ jinfo -> job_node = find_node_info( attrp -> value, queue -> server -> nodes ); else if( !strcmp( attrp -> name, ATTR_l) ) /* resources requested*/ { resreq = find_alloc_resource_req(attrp -> resource, jinfo -> resreq); if( resreq != NULL ) { resreq -> res_str = string_dup(attrp -> value); resreq -> amount = res_to_num(attrp -> value); } if( jinfo -> resreq == NULL ) jinfo -> resreq = resreq; } else if( !strcmp( attrp -> name, ATTR_used ) ) /* resources used */ { resreq = find_alloc_resource_req(attrp -> resource, jinfo -> resused); if( resreq != NULL ) resreq -> amount = res_to_num( attrp -> value ); if( jinfo -> resused == NULL ) jinfo -> resused = resreq; } attrp = attrp -> next; } return jinfo;}/* * * new_job_info - allocate and initialize new job_info structure * * returns new job_info structure * */job_info *new_job_info(){ job_info *jinfo; if( ( jinfo = (job_info *) malloc( sizeof( job_info ) ) ) == NULL ) return NULL; jinfo -> is_queued = 0; jinfo -> is_running = 0; jinfo -> is_held = 0; jinfo -> is_waiting = 0; jinfo -> is_transit = 0; jinfo -> is_exiting = 0; jinfo -> is_suspended = 0; jinfo -> is_starving = 0; jinfo -> can_not_run = 0; jinfo -> can_never_run = 0; jinfo -> name = NULL; jinfo -> comment = NULL; jinfo -> account = NULL; jinfo -> group = NULL; jinfo -> queue = NULL; jinfo -> priority = 0; jinfo -> sch_priority = 0; jinfo -> qtime = 0; jinfo -> resreq = NULL; jinfo -> resused = NULL; jinfo -> ginfo = NULL; jinfo -> job_node = NULL; return jinfo;}/* * * new_resource_req - allocate and initalize new resoruce_req * * returns the new resource_req * */resource_req *new_resource_req(){ resource_req *resreq; if( ( resreq = (resource_req *) malloc( sizeof( resource_req ) ) ) == NULL ) return NULL; resreq -> name = NULL; resreq -> res_str = NULL; resreq -> amount = 0; resreq -> next = NULL; return resreq;}/* * * find_alloc_resource_req - find resource_req by name or allocate * and initalize a new resource_req * also adds new one to the list * * name - resource_req to find * reqlist - list to look through * * returns found or newly allocated resource_req * */resource_req *find_alloc_resource_req( char *name, resource_req *reqlist ){ resource_req *resreq; /* used to find or create resource_req */ resource_req *prev = NULL; /* previous resource_req in list */ resreq = reqlist; while( resreq != NULL && strcmp(resreq -> name, name) ) { prev = resreq; resreq = resreq -> next; } if( resreq == NULL ) { if( ( resreq = new_resource_req() ) == NULL ) return NULL; resreq -> name = string_dup( name ); if( prev != NULL ) prev -> next = resreq; } return resreq;}/* * * free_job_info - free all the memory used by a job_info structure * * jinfo - the job_info to free * * returns nothing * */void free_job_info( job_info *jinfo ){ if( jinfo -> name != NULL ) free(jinfo -> name); if( jinfo -> comment != NULL ) free(jinfo -> comment); if( jinfo -> account != NULL ) free(jinfo -> account); if( jinfo -> group != NULL ) free( jinfo -> group ); free_resource_req_list( jinfo -> resreq ); free_resource_req_list( jinfo -> resused ); free(jinfo);}/* * * free_jobs - free an array of jobs * * jarr - array of jobs to free * * returns nothing * */void free_jobs( job_info **jarr ){ int i; if( jarr == NULL ) return; for( i = 0; jarr[i] != NULL; i++ ) free_job_info(jarr[i]); free(jarr);} /* * * find_resource_req - find a resource_req from a resource_req list *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -