📄 attr_node_func.c
字号:
* to a work buffer area */ slen = strlen( val ); /*bufr either on stack or heap*/ if( slen - 512 < 0 ) sbufp = strbuf; else { if( !(sbufp = (char *)malloc( slen + 1 )) ) return (PBSE_SYSTEM); } strcpy( sbufp, val ); if( (str = parse_comma_string( sbufp )) == (char *)0 ) { if( slen >= 512 ) free( sbufp ); return rc; } flag = 0; if( rc = set_nodeflag( str, &flag ) ) { if( slen >= 512 ) free( sbufp ); return rc; } currflag = flag; /*calling parse_comma_string with a null ptr continues where*/ /*last call left off. The initial comma separated string */ /*copy pointed to by sbufp is modified with each func call */ while( str = parse_comma_string( (char *)0 ) ) { if( rc = set_nodeflag( str, &flag ) ) break; if( (currflag == 0 && flag) || (currflag && flag == 0) ) { rc = PBSE_MUTUALEX; /*free is mutually exclusive*/ break; } currflag = flag; } if( !rc ) { pattr->at_val.at_short = flag; pattr->at_flags |= ATR_VFLAG_SET|ATR_VFLAG_MODIFY; } if( slen >= 512 ) /*buffer on heap, not stack*/ free( sbufp ); return rc;}/* * decode_ntype * 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". * Although we have only "time-shared" and "cluster" at this * point in PBS's evolution, there may come a time when other * ntype values are needed. The one thing that is assumed is * that the types are going to be mutually exclusive */ int decode_ntype(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 tmp = 0; if( val == (char *)0 ) rc = (PBSE_BADNDATVAL); else if( !strcmp(val, ND_timeshared) ) tmp = NTYPE_TIMESHARED; else if( !strcmp(val, ND_cluster) ) tmp = NTYPE_CLUSTER; else rc = (PBSE_BADNDATVAL); if( !rc ) { pattr->at_val.at_short = tmp; pattr->at_flags |= ATR_VFLAG_SET|ATR_VFLAG_MODIFY; } return rc;}/* * free_prop_list * For each element of a null terminated prop list call free * to clean up any string buffer that hangs from the element. * After this, call free to remove the struct prop. */void free_prop_list( prop ) struct prop *prop;{ struct prop *pp; while( prop ) { pp = prop->next; free(prop); prop = pp; }}/* * set_node_state - the information in the "short" attribute, *new, is used to * update the information in the "short" attribute, *pattr. * the mode of the update is goverened by the argument "op" * (SET,INCR,DECR) */int set_node_state( pattr, new, op) attribute *pattr; /*attribute gets modified */ attribute *new; /*carries new, modifying info*/ /*that got decoded into 'new"*/ enum batch_op op;{ int rc = 0; assert( pattr && new && (new->at_flags & ATR_VFLAG_SET) ); switch( op ) { case SET: pattr->at_val.at_short = new->at_val.at_short; break; case INCR: if(pattr->at_val.at_short && new->at_val.at_short == 0) { rc = PBSE_BADNDATVAL; /*"free" mutually exclusive*/ break; } pattr->at_val.at_short |= new->at_val.at_short; break; case DECR: if( pattr->at_val.at_short && new->at_val.at_short == 0 ) { rc = PBSE_BADNDATVAL; /*"free" mutually exclusive*/ break; } pattr->at_val.at_short &= ~new->at_val.at_short; break; default: rc = PBSE_INTERNAL; } if ( !rc ) pattr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY; return rc;}/* * set_node_ntype - the value entry in attribute "new" is a short. It was * generated by the decode routine is used to update the * value portion of the attribute *pattr * the mode of the update is goverened by the argument "op" * (SET,INCR,DECR) */int set_node_ntype ( pattr, new, op) attribute *pattr; /*attribute gets modified */ attribute *new; /*carries new, modifying info*/ /*that got decoded into 'new"*/ enum batch_op op;{ int rc = 0; assert( pattr && new && (new->at_flags & ATR_VFLAG_SET) ); switch( op ) { case SET: pattr->at_val.at_short = new->at_val.at_short; break; case INCR: if( pattr->at_val.at_short != new->at_val.at_short ) { rc = PBSE_MUTUALEX; /*types are mutually exclusive*/ } break; case DECR: if( pattr->at_val.at_short != new->at_val.at_short ) rc = PBSE_MUTUALEX; /*types are mutually exclusive*/ else if( pattr->at_val.at_short == NTYPE_TIMESHARED ) pattr->at_val.at_short = NTYPE_CLUSTER; else pattr->at_val.at_short = NTYPE_TIMESHARED; break; default: rc = PBSE_INTERNAL; } if ( !rc ) pattr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY; return rc;}/* * set_nodeflag - Use the input string's value to set a bit in * the "flags" variable pointed to by pflags * Each call sets one more bit in the flags * variable or it clears the flags variable * in the case where *str is the value "free" */static int set_nodeflag( str, pflag) char *str; short *pflag;{ int rc = 0; if( *str == '\0' ) return (PBSE_BADNDATVAL); if( !strcmp(str, ND_free) ) *pflag = 0; else if( !strcmp(str, ND_offline) ) *pflag = *pflag | INUSE_OFFLINE ; else if( !strcmp(str, ND_down) ) *pflag = *pflag | INUSE_DOWN ; else if( !strcmp(str, ND_reserve) ) *pflag = *pflag | INUSE_RESERVE ; else { rc = PBSE_BADNDATVAL; } return rc;}/* * node_state - Either derive a "state" attribute from the node * or update node's "inuse" field using the "state" * attribute. */int node_state( new, pnode, actmode) attribute *new; /*derive state into this attribute*/ void *pnode; /*pointer to a pbsnode struct */ int actmode; /*action mode; "NEW" or "ALTER" */{ int rc = 0; struct pbsnode* np; np = (struct pbsnode*)pnode; /*because of def of at_action args*/ switch( actmode ) { case ATR_ACTION_NEW: /*derive attribute*/ new->at_val.at_short = np->nd_state; break; case ATR_ACTION_ALTER: np->nd_state = new->at_val.at_short; break; default: rc = PBSE_INTERNAL; } return rc;}/* * node_ntype - Either derive an "ntype" attribute from the node * or update node's "ntype" field using the * attribute's data */int node_ntype ( new, pnode, actmode) attribute *new; /*derive ntype into this attribute*/ void *pnode; /*pointer to a pbsnode struct */ int actmode; /*action mode; "NEW" or "ALTER" */{ int rc = 0; struct pbsnode* np; np = (struct pbsnode*)pnode; /*because of def of at_action args*/ switch( actmode ) { case ATR_ACTION_NEW: /*derive attribute*/ new->at_val.at_short = np->nd_ntype; break; case ATR_ACTION_ALTER: np->nd_ntype = new->at_val.at_short; break; default: rc = PBSE_INTERNAL; } return rc;}/* * node_prop_list - Either derive a "prop list" attribute from the node * or update node's prop list from attribute's prop list. */int node_prop_list( new, pnode, actmode) attribute *new; /*derive props into this attribute*/ void *pnode; /*pointer to a pbsnode struct */ int actmode; /*action mode; "NEW" or "ALTER" */{ int rc = 0, i; struct pbsnode *np; attribute temp; np = (struct pbsnode*)pnode; /*because of at_action arg type*/ switch( actmode ) { case ATR_ACTION_NEW: /* if node has a property list, then copy array_strings */ /* into temp to use to setup a copy, otherwise setup empty */ if (np->nd_prop) { /* setup temporary attribute with the array_strings */ /* from the node */ temp.at_val.at_arst = np->nd_prop; temp.at_flags = ATR_VFLAG_SET; temp.at_type = ATR_TYPE_ARST; rc = set_arst(new, &temp, SET); } else { /* Node has no properties, setup empty attribute */ new->at_val.at_arst = 0; new->at_flags = 0; new->at_type = ATR_TYPE_ARST; } break; case ATR_ACTION_ALTER: /* update node with new attr_strings */ np->nd_prop = new->at_val.at_arst; /* update number of properties listed in node */ /* does not include name and subnode property */ if (np->nd_prop) np->nd_nprops = np->nd_prop->as_usedptr; else np->nd_nprops = 0; break; default: rc = PBSE_INTERNAL; } return rc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -