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

📄 attr_fn_resc.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * set_resc - set value of attribute of type ATR_TYPE_RESR to another * *	For each resource in the list headed by the "new" attribute, *	the correspondingly name resource in the list headed by "old" *	is modified.   * *	The mapping of the operations incr and decr depend on the type *	of each individual resource.   *	Returns: 0 if ok *		>0 if error */int set_resc(old, new, op)	struct attribute *old;	struct attribute *new;	enum batch_op op;{	enum batch_op local_op;	resource *newresc;	resource *oldresc;	int	  rc;	assert(old && new);	newresc = (resource *)GET_NEXT(new->at_val.at_list);	while (newresc != (resource *)0) {		local_op = op;			/* search for old that has same definition as new */		oldresc = find_resc_entry(old, newresc->rs_defin);		if (oldresc == (resource *)0) {			/* add new resource to list */			oldresc = add_resource_entry(old,newresc->rs_defin);			if (oldresc == (resource *)0) {				log_err(-1,"set_resc","Unable to malloc space");				return (PBSE_SYSTEM);			}		}		/*		 * unlike other attributes, resources can be "unset"		 * if new is "set" to a value, the old one is set to that		 * value; if the new resource is unset (no value), then the		 * old resource is unset by freeing it.		 */		if (newresc->rs_value.at_flags & ATR_VFLAG_SET) {		    /* call resource type dependent  set routine */			if ((rc = oldresc->rs_defin->rs_set(&oldresc->rs_value,			     &newresc->rs_value, local_op)) != 0)				return (rc);		} else {			oldresc->rs_defin->rs_free(&oldresc->rs_value);		}		newresc = (resource *)GET_NEXT(newresc->rs_link);	}	old->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY;	return (0);}/* * comp_resc - compare two attributes of type ATR_TYPE_RESR * *	DANGER Will Robinson, DANGER * *	As you can see from the returns, this is different from the *	at_comp model...   * *	Returns: 0 if compare successful: *		   sets comp_resc_gt to count of "greater than" compares *				attr > with *		   sets comp_resc_eq to count of "equal to" compares *				attr == with *		   sets comp_resc_lt to count of "less than" compares *				attr < with *		-1 if error */int comp_resc(attr, with)	struct attribute *attr;	struct attribute *with;{	resource *atresc;	resource *wiresc;	int rc;	comp_resc_gt = 0;	comp_resc_eq = 0;	comp_resc_lt = 0;	comp_resc_nc = 0;	if ((attr == (attribute *)0) || (with == (attribute *)0))		return (-1);	wiresc = (resource *)GET_NEXT(with->at_val.at_list);	while (wiresc != (resource *)0) {	    if ((wiresc->rs_value.at_flags & ATR_VFLAG_SET) &&	        ((wiresc->rs_value.at_flags & ATR_VFLAG_DEFLT) == 0)) {		atresc = find_resc_entry(attr, wiresc->rs_defin);		if (atresc != (resource *)0) {			if (atresc->rs_value.at_flags & ATR_VFLAG_SET) {			    if ((rc=atresc->rs_defin->rs_comp(&atresc->rs_value, 				      &wiresc->rs_value)) > 0)					comp_resc_gt++;			    else if (rc < 0)					comp_resc_lt++;			    else					comp_resc_eq++;			}		} else {				comp_resc_nc++;		}	    }	    wiresc = (resource *)GET_NEXT(wiresc->rs_link);	}	return (0);}	/* * free_resc - free space associated with attribute value * *	For each entry in the resource list, the entry is delinked, *	the resource entry value space freed (by calling the resource  *	free routine), and then the resource structure is freed. */void free_resc(pattr)	attribute *pattr;{	resource *next;	resource *pr;	pr = (resource *)GET_NEXT(pattr->at_val.at_list);	while (pr != (resource *)0) {		next = (resource *)GET_NEXT(pr->rs_link);		delete_link(&pr->rs_link);		pr->rs_defin->rs_free(&pr->rs_value);		(void)free(pr);		pr = next;	}	CLEAR_HEAD(pattr->at_val.at_list);	pattr->at_flags &= ~ATR_VFLAG_SET;}/* * find_resc_def - find the resource_def structure for a resource with *	a given name * *	Returns: pointer to the structure or NULL */resource_def *find_resc_def (rscdf, name, limit)	resource_def *rscdf;	/* address of array of resource_def structs */	char         *name;	/* name of resource */	int	      limit;	/* number of members in resource_def array */{	while (limit--) {		if (strcmp(rscdf->rs_name, name) == 0)			return (rscdf);		rscdf++;	}	return ((resource_def *)0);}/* * find_resc_entry - find a resource (value) entry in a list headed in an * an attribute that points to the specified resource_def structure  * *	Returns: pointer to struct resource  or NULL */resource *find_resc_entry(pattr, rscdf)	attribute	*pattr;	resource_def	*rscdf;{	resource *pr;	pr = (resource *)GET_NEXT(pattr->at_val.at_list);	while (pr != (resource *)0) {		if (pr->rs_defin == rscdf)			break;		pr = (resource *)GET_NEXT(pr->rs_link);	}	return (pr);}/*  * add_resource_entry - add and "unset" entry for a resource type to a *	list headed in an attribute.  Just for later displaying, the *	resource list is maintained in an alphabetic order. *	The parent attribute is marked with ATR_VFLAG_SET and ATR_VFLAG_MODIFY * *	Returns: pointer to the newly added entry or NULL if unable *		 to add it (malloc failed).  If the resource already *		 exists (it shouldn't) then that one is returned. */resource *add_resource_entry (pattr, prdef)	attribute	*pattr;	resource_def	*prdef;{	int 		 i;	resource	*new;	resource	*pr;	pr = (resource *)GET_NEXT(pattr->at_val.at_list);	while (pr != (resource *)0) {		i = strcmp(pr->rs_defin->rs_name, prdef->rs_name);		if (i == 0)	/* found an matching entry */			return (pr);		else if (i > 0)			break;		pr = (resource *)GET_NEXT(pr->rs_link);	}	new = (resource *)malloc(sizeof (resource));	if (new == (resource *)0) {		log_err(-1, "add_resource_entry", "unable to malloc space");		return ((resource *)0);	}	CLEAR_LINK(new->rs_link);	new->rs_defin = prdef;	new->rs_value.at_type = prdef->rs_type;	new->rs_value.at_flags = 0;	prdef->rs_free(&new->rs_value);	if (pr != (resource *)0) {		insert_link(&pr->rs_link, &new->rs_link, new,LINK_INSET_BEFORE);	} else {		append_link(&pattr->at_val.at_list, &new->rs_link, new);	}	pattr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY;	return (new);}/* * action_resc - the at_action for the resource_list attribute *	For each resource in the list, if it has its own action routine, *	call it. */int action_resc(pattr, pobject, actmode)	attribute *pattr;	void *pobject;	int actmode;{	resource *pr;	pr = (resource *)GET_NEXT(pattr->at_val.at_list);	while (pr) {		if ( (pr->rs_value.at_flags & ATR_VFLAG_MODIFY) &&		     (pr->rs_defin->rs_action) ) 			    pr->rs_defin->rs_action(pr, pattr, actmode);		pr->rs_value.at_flags &= ~ATR_VFLAG_MODIFY;		pr = (resource *)GET_NEXT(pr->rs_link);	}	return (0);}

⌨️ 快捷键说明

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