⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_info.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**         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 <pbs_ifl.h>#include <pbs_error.h>#include "server_info.h"#include "constant.h"#include "queue_info.h"#include "job_info.h"#include "misc.h"#include "config.h"#include "node_info.h"static char *ident = "$Id: server_info.c,v 2.2.4.4 2000/08/09 00:19:03 hender Exp $";/* * *	query_server - creates a structure of arrays consisting of a server *			and all the queues and jobs that reside in that server * *	  pbs_sd - connection to pbs_server * *	returns a pointer to the server_info struct * */server_info *query_server( int pbs_sd ){  struct batch_status *server;	/* info about the server */  server_info *sinfo;		/* scheduler internal form of server info */  queue_info **qinfo;		/* array of queues on the server */  resource *res;		/* ptr to cycle through sources on server */  /* get server information from pbs server */  if( ( server = pbs_statserver(pbs_sd, NULL, NULL) ) == NULL )  {    fprintf(stderr, "pbs_statserver failed: %d\n", pbs_errno);    return NULL;  }  /* convert batch_status structure into server_info structure */  if( ( sinfo = query_server_info( server ) ) == NULL )  {    pbs_statfree( server );    return NULL;  }  /* get the nodes, if any */  sinfo -> nodes = query_nodes( pbs_sd, sinfo );  /* get the queues */  if( (sinfo -> queues = query_queues( pbs_sd, sinfo )) == NULL )  {    pbs_statfree( server );    free_server( sinfo, 0 );    return NULL;  }  /* count the queues and total up the individual queue states    * for server totals. (total up all the state_count structs)   */  qinfo = sinfo -> queues;  while( *qinfo != NULL )  {    sinfo -> num_queues++;    total_states( &(sinfo -> sc), &((*qinfo) -> sc) );    qinfo++;  }  if( ( sinfo -> jobs = (job_info **) malloc( sizeof(job_info *) * (sinfo -> sc.total + 1)) ) == NULL )  {    free_server(sinfo, 1);    perror("Memory allocation error");    return NULL;  }  set_jobs( sinfo );  sinfo -> running_jobs = 	job_filter( sinfo -> jobs, sinfo -> sc.total, check_run_job, NULL);    res = sinfo -> res;  while(res != NULL)  {    if(res -> assigned == UNSPECIFIED)      res -> assigned = calc_assn_resource(sinfo -> running_jobs, res -> name);        res = res -> next;  }  sinfo -> timesharing_nodes =     node_filter( sinfo -> nodes, sinfo -> num_nodes, is_node_timeshared, NULL);  pbs_statfree( server );  return sinfo;}/* * *	query_server_info - takes info from a batch_status structure about  *			    a server into a server_info structure for easy *			    access * *	  server - batch_status struct of server info *	  last   - the last server so the new one can be added to the chain *		   possibly NULL * *	returns newly allocated and filled server_info struct * */server_info *query_server_info( struct batch_status *server ){  struct attrl *attrp;	/* linked list of attributes */  server_info *sinfo;	/* internal scheduler structure for server info */  resource *resp;	/* a resource to help create the resource list */  sch_resource_t count;	/* used to convert string -> integer */  char *endp;		/* used with strtol() */  if( ( sinfo = new_server_info() ) == NULL )    return NULL;  		/* error */    sinfo -> name = string_dup( server -> name );  attrp = server -> attribs;  while( attrp != NULL )  {    if(!strcmp(attrp -> name, ATTR_dfltque))		/* default_queue */      sinfo -> default_queue = string_dup(attrp -> value);    else if( !strcmp(attrp -> name, ATTR_maxrun) )	/* max_running */    {      count = strtol(attrp -> value, &endp, 10);      if( *endp != '\0' )        count = -1;      sinfo -> max_run = count;    }    else if( !strcmp(attrp -> name, ATTR_maxuserrun) )	/* max_user_run */    {      count = strtol(attrp -> value, &endp, 10);      if( *endp != '\0' )	count = -1;      sinfo -> max_user_run = count;    }    else if( !strcmp(attrp -> name, ATTR_maxgrprun) )	/* max_group_run */    {      count = strtol(attrp -> value, &endp, 10);      if( *endp != '\0' )	count = -1;      sinfo -> max_group_run = count;    }    else if( !strcmp( attrp -> name, ATTR_rescavail ) )	/* resources_available*/    {      count = res_to_num( attrp -> value );      resp = find_alloc_resource(sinfo -> res, attrp -> resource);      if( sinfo -> res == NULL )	sinfo -> res = resp;      if( resp != NULL )	resp -> avail = count;    }    else if( !strcmp( attrp -> name, ATTR_rescmax) )	/* resources_max */    {      count = res_to_num( attrp -> value );      resp = find_alloc_resource(sinfo -> res, attrp -> resource);      if( sinfo -> res == NULL )	sinfo -> res = resp;      if( resp != NULL )	resp -> max = count;    }    else if( !strcmp( attrp -> name, ATTR_rescassn) )	/* resources_assigned */    {      count = res_to_num( attrp -> value );      resp = find_alloc_resource(sinfo -> res, attrp -> resource);      if( sinfo -> res == NULL )	sinfo -> res = resp;      if( resp != NULL )	resp -> assigned = count;    }    attrp = attrp -> next;  }  return sinfo;}/* * *	find_alloc_resource - try and find a resource, and if it is not there *			      alocate space for it and add it to the resource *			      list * *	  resplist - the resoruce list *	  name - the name of the resource * *	returns either the found resource or newly allocated resource * */resource *find_alloc_resource( resource *resplist, char *name ){  resource *resp;		/* used to search through list of resources */  resource *prev = NULL;	/* the previous resources in the list */  resp = resplist;  while( resp != NULL && strcmp(resp -> name, name) )  {    prev = resp;    resp = resp -> next;  }  if( resp == NULL )  {    if( ( resp = new_resource() ) == NULL )      return NULL;        resp -> name = string_dup( name );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -