📄 attr_node_func.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 <pbs_config.h> /* the master config generated by configure */#include <sys/types.h>#include <ctype.h>#include <memory.h>#ifndef NDEBUG#include <stdio.h>#endif#include <stdlib.h>#include <string.h>#include <assert.h>#include "pbs_ifl.h"#include "list_link.h"#include "attribute.h"#include "server_limits.h"#include "net_connect.h"#include "job.h"#include "pbs_nodes.h"#include "pbs_error.h"static char ident[] = "@(#) $RCSfile: attr_node_func.c,v $ $Revision: 2.5.4.5 $";/* * This file contains functions for deriving attribute values from a pbsnode * and for updating the "state" (inuse), "node type" (ntype) or "properties" * list using the "value" carried in an attribute. * * Included are: * * global: * decode_state() "functions for at_decode func pointer" * decode_ntype() * decode_props() * * encode_state() "functions for at_encode func pointer" * encode_ntype() * encode_props() * encode_jobs() * * set_node_state() "functions for at_set func pointer" * set_node_ntype() * * node_state() "functions for at_action func pointer" * node_ntype() * node_prop_list() * * free_prop_list() * free_prop_attr() "function for at_free func pointer" * * local: * load_prop() * set_nodeflag() * * The prototypes are declared in "attr_func.h" *//* * Set of forward declarations for functions used before defined * keeps the compiler happy*/static int set_nodeflag A_(( char*, short*));static int load_prop A_(( char*, struct prop* ));/* * encode_state * Once the node's "inuse" field is converted to an attribute, * the attribute can be passed to this function for encoding into * an svrattrl structure * Returns <0 an error encountered; value is negative of an error code * 0 ok, encode happened and svrattrl created and linked in, * or nothing to encode */ int encode_state(pattr, ph, aname, rname, mode) attribute *pattr; /*struct attribute being encoded */ list_head *ph; /*head of a list of "svrattrl" */ /*structs which are to be returned*/ char *aname; /*attribute's name */ char *rname; /*resource's name (null if none) */ int mode; /*mode code, unused here */{ int i; svrattrl *pal; short state; static struct node_state { short bit; char *name; } ns[] = { {INUSE_UNKNOWN, ND_state_unknown}, {INUSE_DOWN, ND_down}, {INUSE_OFFLINE, ND_offline}, {INUSE_RESERVE, ND_reserve}, {INUSE_JOB, ND_job_exclusive}, {INUSE_JOBSHARE,ND_job_sharing}, {INUSE_BUSY, ND_busy}, {0, (char *)0} }; static char state_str[ MAX_ENCODE_BFR ]; if ( !pattr ) return -(PBSE_INTERNAL); if ( !(pattr->at_flags & ATR_VFLAG_SET) ) return (0); /*nothing to report back*/ state = pattr->at_val.at_short & (INUSE_SUBNODE_MASK | INUSE_UNKNOWN); if (!state) strcpy( state_str, ND_free ); else { state_str[0] = '\0'; for (i=0; ns[i].name; i++) { if (state & ns[i].bit) { if (state_str[0] != '\0') (void)strcat(state_str, ","); (void)strcat(state_str, ns[i].name); } } } pal = attrlist_create(aname,rname,(int)strlen(state_str)+1); if (pal == (svrattrl *)0) return -(PBSE_SYSTEM); (void)strcpy(pal->al_value, state_str); pal->al_flags = ATR_VFLAG_SET; append_link(ph, &pal->al_link, pal); return (0); /*success*/}/* * encode_ntype * Once the node's "ntype" field is converted to an attribute, * the attribute can be passed to this function for encoding into * an svrattrl structure * Returns <0 an error encountered; value is negative of an error code * 0 ok, encode happened and svrattrl created and linked in, * or nothing to encode */ int encode_ntype(pattr, ph, aname, rname, mode) attribute *pattr; /*struct attribute being encoded */ list_head *ph; /*head of a list of "svrattrl" */ /*structs which are to be returned*/ char *aname; /*attribute's name */ char *rname; /*resource's name (null if none) */ int mode; /*mode code, unused here */{ svrattrl *pal; short ntype; static char *nt[] = { ND_cluster, ND_timeshared }; static char ntype_str[ MAX_ENCODE_BFR ]; if ( !pattr ) return -(PBSE_INTERNAL); if ( !(pattr->at_flags & ATR_VFLAG_SET) ) return (0); /*nothing to report back*/ ntype = pattr->at_val.at_short & PBSNODE_NTYPE_MASK; if (!ntype) strcpy( ntype_str, nt[0] ); else strcpy( ntype_str, nt[1] ); pal = attrlist_create(aname,rname,(int)strlen(ntype_str)+1); if (pal == (svrattrl *)0) return -(PBSE_SYSTEM); (void)strcpy(pal->al_value, ntype_str); pal->al_flags = ATR_VFLAG_SET; append_link(ph, &pal->al_link, pal); return (0); /*success*/}/* * encode_jobs * Once the node's struct jobinfo pointer is put in the data area of * temporary attribute containing a pointer to the parent node, this * function will walk the list of jobs and generate the comma separated * list to send back via an svrattrl structure. * Returns <0 an error encountered; value is negative of an error code * 0 ok, encode happened and svrattrl created and linked in, * or nothing to encode */ int encode_jobs(pattr, ph, aname, rname, mode) attribute *pattr; /*struct attribute being encoded */ list_head *ph; /*head of a list of "svrattrl" */ /*structs which are to be returned*/ char *aname; /*attribute's name */ char *rname; /*resource's name (null if none) */ int mode; /*mode code, unused here */{ svrattrl *pal; struct jobinfo *jip; struct pbsnode *pnode; struct pbssubn *psubn; int i; int jobcnt; /*number of jobs using the node */ int strsize; /*computed string size */ char *job_str; /*holds comma separated list of jobs*/ if ( !pattr ) return (-1); if ( !(pattr->at_flags & ATR_VFLAG_SET) || !pattr->at_val.at_jinfo ) return (0); /*nothing to report back */ /*cnt number of jobs and estimate size of string buffer required*/ jobcnt = 0; strsize = 1; /*allow for terminating null char*/ pnode = pattr->at_val.at_jinfo; for (psubn = pnode->nd_psn; psubn; psubn = psubn->next) { for ( jip = psubn->jobs; jip; jip = jip->next) { jobcnt++; strsize += strlen( jip->job->ji_qs.ji_jobid ) + 6; } } if( jobcnt == 0 ) return (0); /*no jobs currently on this node*/ else if ( !(job_str = (char *)malloc( strsize )) ) return -(PBSE_SYSTEM); job_str[0] = '\0'; i = 0; for (psubn = pnode->nd_psn; psubn; psubn = psubn->next) { for ( jip = psubn->jobs; jip; jip = jip->next) { if (i != 0 ) strcat(job_str, ", "); else i++; sprintf(job_str + strlen(job_str), "%d/%s", psubn->index, jip->job->ji_qs.ji_jobid); } } pal = attrlist_create(aname, rname, (int)strlen(job_str) + 1 ); if ( pal == (svrattrl *)0 ) { free(job_str); return -(PBSE_SYSTEM); } (void)strcpy(pal->al_value, job_str); pal->al_flags = ATR_VFLAG_SET; free( job_str ); append_link(ph, &pal->al_link, pal); return (0); /*success*/}/* * decode_state * In this case, the two arguments that get used are * pattr-- it points to an attribute whose value is a short, * and the argument "val". * Once the "value" argument, val, is decoded from its form * as a string of comma separated substrings, the component * values are used to set the appropriate bits in the attribute's * value field. */ int decode_state(pattr, name, rescn, val) attribute *pattr; char *name; /* attribute name */ char *rescn; /* resource name, unused here */ char *val; /* attribute value */{ int rc = 0; /*return code; 0==success*/ short flag, currflag; char *str; char strbuf[512]; /*should handle most vals*/ char *sbufp; int slen; if(val == (char *)0) return (PBSE_BADNDATVAL); /* * determine string storage requirement and copy the string "val"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -