int encode_c(

  pbs_attribute  *attr,   /* ptr to pbs_attribute */
  tlist_head     *phead,  /* head of attrlist list */
  char           *atname, /* pbs_attribute name */
  char           *rsname, /* resource name or null */
  int             mode,   /* encode mode, unused here */
  int             perm)   /* only used for resources */

  {

  svrattrl *pal;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  pal = attrlist_create(atname, rsname, 2);

  if (pal == (svrattrl *)0)
    return (-1);

  *pal->al_value   = attr->at_val.at_char;

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
Beispiel #2
0
int encode_ll(

  pbs_attribute  *attr,   /* ptr to pbs_attribute */
  tlist_head     *phead,   /* head of attrlist list */
  char           *atname,  /* pbs_attribute name */
  char           *rsname,  /* resource name or null */
  int             mode,   /* encode mode, unused here */
  int             perm)  /* only used for resources */

  {
  size_t   ct;
  char cvn[MAXLONGLEN+1];
  svrattrl *pal;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  snprintf(cvn, MAXLONGLEN, LLD, attr->at_val.at_ll);

  ct = strlen(cvn);

  if ((pal = attrlist_create(atname, rsname, ct + 1)) == NULL)
    return (-1);

  memcpy(pal->al_value, cvn, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
Beispiel #3
0
int
encode_size(attribute *attr, pbs_list_head *phead, char *atname, char *rsname, int mode, svrattrl **rtnl)
{
	size_t	     ct;
	char	     cvnbuf[CVNBUFSZ];
	svrattrl *pal;
	void from_size(struct size_value *, char *);

	if (!attr)
		return (-1);
	if (!(attr->at_flags & ATR_VFLAG_SET))
		return (0);

	from_size(&attr->at_val.at_size, cvnbuf);
	ct = strlen(cvnbuf) + 1;

	pal = attrlist_create(atname, rsname, ct);
	if (pal == (svrattrl *)0)
		return (-1);

	(void)memcpy(pal->al_value, cvnbuf, ct);
	pal->al_flags = attr->at_flags;
	if (phead)
		append_link(phead, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (1);
}
Beispiel #4
0
int
encode_c(attribute *attr, pbs_list_head *phead, char *atname, char *rsname, int mode, svrattrl **rtnl)

{

	svrattrl *pal;

	if (!attr)
		return (-1);
	if (!(attr->at_flags & ATR_VFLAG_SET))
		return (0);

	pal = attrlist_create(atname, rsname, 2);
	if (pal == NULL)
		return (-1);

	*pal->al_value   = attr->at_val.at_char;
	*(pal->al_value+1) = '\0';
	pal->al_flags = attr->at_flags;
	if (phead)
		append_link(phead, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (1);
}
Beispiel #5
0
svrattrl *fill_svrattr_info(

  const char *aname,    /* I */ /* attribute name */
  const char *avalue,   /* I */ /* attribute value */
  const char *rname,   /* i */ /* resource name */
  char       *log_buf,  /* O */ /* error buffer */
  size_t      buf_len)  /* I */ /* len of error buffer */

  {
  size_t vsize = 0;
  svrattrl *pal = NULL;

  if (avalue)
    vsize = strlen(avalue) + 1;

  if ((pal = attrlist_create(aname, rname, vsize)))
    {
    if (avalue) 
      strcpy(pal->al_value, avalue);
    CLEAR_LINK(pal->al_link);
    }
  else
    snprintf(log_buf, buf_len, "Error: could not allocate memory for svrattrl in %s", __func__);

  return pal;
  }
Beispiel #6
0
int
encode_f(attribute *attr, pbs_list_head *phead, char *atname, char *rsname, int mode, svrattrl **rtnl)
{
	size_t	  ct;
	char	  cvnbuf[CVNBUFSZ];
	svrattrl *pal;

	if (!attr)
		return (-1);
	if (!(attr->at_flags & ATR_VFLAG_SET))
		return (0);

	(void)snprintf(cvnbuf, CVNBUFSZ, "%-.*f",
		float_digits(attr->at_val.at_float, FLOAT_NUM_DIGITS),
		attr->at_val.at_float);
	ct = strlen(cvnbuf) + 1;

	pal = attrlist_create(atname, rsname, ct);
	if (pal == NULL)
		return (-1);

	(void)memcpy(pal->al_value, cvnbuf, ct);
	pal->al_flags = attr->at_flags;
	if (phead)
		append_link(phead, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (1);
}
Beispiel #7
0
int
decode_unkn(struct attribute *patr, char *name, char *rescn, char *value)
{
	svrattrl *entry;
	size_t	     valln;


	if (patr == NULL)
		return (PBSE_INTERNAL);

	if (!(patr->at_flags & ATR_VFLAG_SET))
		CLEAR_HEAD(patr->at_val.at_list);

	if (name == NULL)
		return (PBSE_INTERNAL);

	if (value == NULL)
		valln = 0;
	else
		valln = strlen(value) + 1;

	entry = attrlist_create(name, rescn, valln);
	if (entry == NULL)
		return (PBSE_SYSTEM);

	if (valln)
		memcpy(entry->al_value, value, valln);

	append_link(&patr->at_val.at_list, &entry->al_link, entry);
	patr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY | ATR_VFLAG_MODCACHE;
	return (0);
}
Beispiel #8
0
int
encode_sharing(attribute *pattr, pbs_list_head *ph, char *aname, char *rname, int mode, svrattrl **rtnl)
{
	int       n;
	svrattrl *pal;
	char *vn_str;

	if (!pattr)
		return -(PBSE_INTERNAL);

	if (!(pattr->at_flags & ATR_VFLAG_SET))
		return (0);      /*nothing to report back*/

	n = (int)pattr->at_val.at_long;
	vn_str = vnode_sharing_to_str((enum vnode_sharing) n);
	if (vn_str == NULL)
		return -(PBSE_INTERNAL);

	pal = attrlist_create(aname, rname, (int)strlen(vn_str)+1);
	if (pal == NULL)
		return -(PBSE_SYSTEM);

	(void)strcpy(pal->al_value, vn_str);
	pal->al_flags = ATR_VFLAG_SET;
	if (ph)
		append_link(ph, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (0);             /*success*/
}
Beispiel #9
0
int
encode_state(attribute *pattr, pbs_list_head *ph, char *aname, char *rname, int mode, svrattrl **rtnl)
{
	int	  i;
	svrattrl *pal;
	unsigned long	  state;
	static   char	state_str[ MAX_ENCODE_BFR ];
	int      offline_str_seen;
	char	 *ns_name;

	if (!pattr)
		return -(PBSE_INTERNAL);

	if (!(pattr->at_flags & ATR_VFLAG_SET))
		return (0);      /*nothing to report back*/

	state = pattr->at_val.at_long & INUSE_SUBNODE_MASK;
	if (!state)
		strcpy(state_str, ND_free);

	else {
		state_str[0] = '\0';
		offline_str_seen = 0;
		for (i=0; ns[i].name; i++) {
			if (state & ns[i].bit) {
				ns_name = ns[i].name;
				if (strcmp(ns_name, ND_offline) == 0) {
					offline_str_seen = 1;
				} else if (strcmp(ns_name,
					ND_offline_by_mom) == 0) {
					if (offline_str_seen)
						continue;
					/* ND_offline_by_mom will always be */
					/* shown externally as ND_offline */
					ns_name = ND_offline;
				}

				if (state_str[0] != '\0') {
					(void)strcat(state_str, ",");
				}
				(void)strcat(state_str, ns_name);
			}
		}
	}

	pal = attrlist_create(aname, rname, (int)strlen(state_str)+1);
	if (pal == NULL)
		return -(PBSE_SYSTEM);

	(void)strcpy(pal->al_value, state_str);
	pal->al_flags = ATR_VFLAG_SET;
	if (ph)
		append_link(ph, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (0);             /*success*/
}
Beispiel #10
0
END_TEST

START_TEST(test_two)
  {
  svrattrl *attrl = attrlist_create("Fred","Wilma",20);
  svrattrl *attrl2 = attrlist_create("Barney","Betty",20);
  fail_unless(strcmp(attrl->al_name,"Fred") == 0);
  fail_unless(strcmp(attrl->al_resc,"Wilma") == 0);
  fail_unless(attrl->al_nameln == 5);
  fail_unless(attrl->al_rescln == 6);
  fail_unless(!is_link_initialized((list_link *)attrl));
  append_link((tlist_head *)attrl,(list_link *)attrl2,(void *)attrl2);
  fail_unless(is_link_initialized((list_link *)attrl));
  attrl2->al_atopl.op = UNSET;
  attrl_fixlink((tlist_head *)attrl);
  fail_unless(attrl2->al_atopl.op == SET);
  free_attrlist((tlist_head *)attrl);

  }
Beispiel #11
0
struct attrlist *
attrlist_cons(struct attrlist *next, struct attr *a)
{
	struct attrlist *al;

	al = attrlist_create();
	al->al_next = next;
	al->al_this = a;
	return al;
}
int encode_tv(

  pbs_attribute  *attr,   /* ptr to pbs_attribute (value in attr->at_val.at_long) */
  tlist_head     *phead,  /* head of attrlist list (optional) */
  const char    *atname, /* pbs_attribute name */
  const char    *rsname, /* resource name (optional) */
  int             mode,   /* endcode mode (not used) */
  int             perm)   /* only used for resources */

  {
  size_t 		 ct;
  char 	 		 cvnbuf[ENCODE_TC_BUF_SIZE];
  time_t	 	 secs;
  suseconds_t	 usecs;
  struct timeval *tv;
  svrattrl 		 *pal;


  if (( attr == NULL )||(phead == NULL))
		{
		/* FAILURE */
		return(-1);
		}

  if ( !(attr->at_flags & ATR_VFLAG_SET))
		{
		return(0);
		}

  tv = &attr->at_val.at_timeval;
  secs = tv->tv_sec;
  usecs = tv->tv_usec;

  sprintf(cvnbuf, "%ld.%06ld", secs, usecs);

  ct = strlen(cvnbuf);

  pal = attrlist_create(atname, rsname, ct+1);

  if (pal == NULL)
    {
      /* FAILURE */
      return(-1);
    }

  memcpy(pal->al_value, cvnbuf, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return(1);
  }
Beispiel #13
0
int encode_rcost(

  pbs_attribute *attr,   /* ptr to pbs_attribute */
  tlist_head    *phead,   /* head of attrlist list */
  const char   *atname,  /* pbs_attribute name */
  const char   *rsname,  /* resource name or null */
  int            mode,   /* encode mode, unused here */
  int            perm)  /* used only with resources */

  {
  svrattrl *pal;

  struct resource_cost *pcost;

  if (!attr)
    {
    /* FAILURE */

    return(-1);
    }

  if (!(attr->at_flags & ATR_VFLAG_SET))
    {
    /* NO-OP */

    return(0);
    }

  pcost = (struct resource_cost *)GET_NEXT(attr->at_val.at_list);

  while (pcost != NULL)
    {
    rsname = pcost->rc_def->rs_name;

    if ((pal = attrlist_create(atname, rsname, 23)) == NULL)
      {
      /* FAILURE */

      return(-1);
      }

    snprintf(pal->al_value, 22, "%ld", pcost->rc_cost);

    pal->al_flags = attr->at_flags;

    append_link(phead, &pal->al_link, pal);

    pcost = (struct resource_cost *)GET_NEXT(pcost->rc_link);
    }

  return(1);
  }
Beispiel #14
0
END_TEST

START_TEST(test_two)
  {
  svrattrl *attrl = attrlist_create("Fred","Wilma",20);
  pbs_attribute a;

  memset(&a,0,sizeof(a));
  fail_unless(decode_arst(&a,NULL,NULL,"th\"is=this,is=is,a=a,com\\ma=comma,del\nimited=bleck,string=strung",0)==0);
  fail_unless(encode_arst(&a,(tlist_head *)attrl,"Billy","bob",ATR_ENCODE_SAVE,0)==1);



  }
Beispiel #15
0
int encode_frequency(

  pbs_attribute  *attr,    /* ptr to pbs_attribute */
  tlist_head     *phead,   /* head of attrlist list */
  const char    *atname,  /* pbs_attribute name */
  const char    *rsname,  /* resource name (optional) */
  int             mode,    /* encode mode (not used) */
  int             perm)    /* only used for resources */

  {
  size_t    ct;
  char     cvnbuf[ENCODE_FREQUENCY_SIZE];
  svrattrl *pal;

  if (attr == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  if (!(attr->at_flags & ATR_VFLAG_SET))
    {
    return(0);
    }

  from_frequency(&attr->at_val.at_frequency, cvnbuf);

  ct = strlen(cvnbuf);

  pal = attrlist_create(atname, rsname, ct + 1);

  if (pal == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  memcpy(pal->al_value, cvnbuf, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  /* SUCCESS */

  return(1);
  }
Beispiel #16
0
int encode_size(

  attribute *attr,    /* ptr to attribute */
  tlist_head *phead,   /* head of attrlist list */
  char      *atname,  /* attribute name */
  char      *rsname,  /* resource name (optional) */
  int        mode)    /* encode mode (not used) */

  {
  size_t    ct;
  char     cvnbuf[CVNBUFSZ];
  svrattrl *pal;

  if (attr == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  if (!(attr->at_flags & ATR_VFLAG_SET))
    {
    return(0);
    }

  from_size(&attr->at_val.at_size, cvnbuf);

  ct = strlen(cvnbuf) + 1;

  pal = attrlist_create(atname, rsname, ct);

  if (pal == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  memcpy(pal->al_value, cvnbuf, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  /* SUCCESS */

  return(1);
  }
Beispiel #17
0
END_TEST

START_TEST(test_two)
  {
  svrattrl *attrl = attrlist_create("Fred","Wilma",20);
  pbs_attribute f;
  pbs_attribute t;

  memset(&f,0,sizeof(f));
  decode_l(&f,NULL,NULL,"567890",0);
  memset(&t,0,sizeof(t));
  decode_l(&t,NULL,NULL,"1235689",0);

  fail_unless(encode_l(&f,(tlist_head *)attrl,"FALSE",NULL,0,0) == 1);
  fail_unless(encode_l(&t,(tlist_head *)attrl,"TRUE",NULL,0,0) == 1);
  }
int encode_hold(

  pbs_attribute  *attr,   /* ptr to pbs_attribute */
  tlist_head     *phead,  /* head of attrlist */
  char           *atname, /* name of pbs_attribute */
  char           *rsname, /* resource name or null */
  int             mode,   /* encode mode, unused here */
  int             perm)   /* only used for resources */


  {
  int       i;
  svrattrl *pal;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  pal = attrlist_create(atname, rsname, HOLD_ENCODE_SIZE + 1);

  if (pal == (svrattrl *)0)
    return (-1);

  i = 0;

  if (attr->at_val.at_long == 0)
    *(pal->al_value + i++) = 'n';
  else
    {
    if (attr->at_val.at_long & HOLD_s)
      *(pal->al_value + i++) = 's';

    if (attr->at_val.at_long & HOLD_o)
      *(pal->al_value + i++) = 'o';

    if (attr->at_val.at_long & HOLD_u)
      *(pal->al_value + i++) = 'u';
    }

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
Beispiel #19
0
int
encode_time(attribute *attr, pbs_list_head *phead, char *atname, char *rsname, int mode, svrattrl **rtnl)
{
	size_t ct;
	unsigned long n;
	unsigned long hr;
	unsigned int min;
	unsigned int sec;
	svrattrl *pal;
	char *pv;
	char cvnbuf[CVNBUFSZ] = {'\0'};

	if (!attr)
		return (-1);
	if (!(attr->at_flags & ATR_VFLAG_SET))
		return (0);
	if (attr->at_val.at_long < 0)
		return (-1);

	n = attr->at_val.at_long;
	hr = n / 3600;
	n %= 3600;
	min = n / 60;
	sec = n % 60;

	pv = cvnbuf;
	(void)sprintf(pv, "%02lu:%02u:%02u", hr, min, sec);
	pv += strlen(pv);

	ct = strlen(cvnbuf) + 1;

	pal = attrlist_create(atname, rsname, ct);
	if (pal == NULL)
		return (-1);

	(void)memcpy(pal->al_value, cvnbuf, ct);
	pal->al_flags = attr->at_flags;
	if (phead)
		append_link(phead, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (1);
}
Beispiel #20
0
int encode_b(

  pbs_attribute  *attr,   /* ptr to pbs_attribute */
  tlist_head     *phead,  /* head of pbs_attribute list */
  const char     *atname, /* pbs_attribute name */
  const char     *rsname, /* resource name or null */
  int            UNUSED(mode),   /* encode mode, unused here */
  int            UNUSED(perm))   /* only used for resources */

  {
  size_t   ct;
  svrattrl *pal;
  const char  *value;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  if (attr->at_val.at_long)
    {
    value = true_val;
    }
  else
    {
    value = false_val;
    }

  ct = strlen(value);

  pal = attrlist_create(atname, rsname, ct+1);

  if (pal == (svrattrl *)0)
    return (-1);

  strncpy(pal->al_value, value, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
int encode_str(

  pbs_attribute  *attr,    /* ptr to pbs_attribute */
  tlist_head     *phead,   /* head of attrlist */
  const char    *atname,  /* name of pbs_attribute */
  const char    *rsname,  /* resource name or null */
  int             mode,    /* encode mode, unused here */
  int             perm)    /* only used for resources */

  {
  svrattrl *pal;
  int len = 0;

  if (attr == NULL)
    {
    return(-1);
    }

  if (!(attr->at_flags & ATR_VFLAG_SET) ||
      !attr->at_val.at_str ||
      (*attr->at_val.at_str == '\0'))
    {
    return(0);
    }

  len = strlen(attr->at_val.at_str);

  pal = attrlist_create(atname, rsname, len + 1);

  if (pal == NULL)
    {
    return(-1);
    }

  strncpy(pal->al_value, attr->at_val.at_str, len);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return(1);
  }
int encode_ntype(
  
  pbs_attribute  *pattr, /*struct pbs_attribute being encoded  */
  tlist_head     *ph,    /*head of a list of  "svrattrl"   */
  char           *aname, /*pbs_attribute's name    */
  char           *rname, /*resource's name (null if none)  */
  int             mode,  /*mode code, unused here   */
  int             perm)  /* only used for resources */

  {
  svrattrl *pal;
  short     ntype;
  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, ND_cluster);

  else
    strcpy(ntype_str, ND_timeshared);

  pal = attrlist_create(aname, rname, (int)strlen(ntype_str) + 1);

  if (pal == (svrattrl *)0)
    return -(PBSE_SYSTEM);

  strcpy(pal->al_value, ntype_str);

  pal->al_flags = ATR_VFLAG_SET;

  append_link(ph, &pal->al_link, pal);

  return (0);             /*success*/
  }
Beispiel #23
0
/**
 *
 * @brief
 *	Encodes a node type attribute into a svrattrl structure
 *
 * @param[in]	pattr - struct attribute being encoded
 * @param[in]	ph - head of a list of 'svrattrl' structs which are to be
 *		     return.
 * @param[out]  aname - attribute's name
 * @param[out]  rname - resource's name (null if none)
 * @param[out]	mode - mode code, unused here
 * @param[out]	rtnl - the return value, a pointer to svrattrl
 *
 * @note
 * 	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
 *
 * @return 	int
 * @retval    	< 0	an error encountered; value is negative of an error code
 * @retval    	0	ok, encode happened and svrattrl created and linked in,
 *		     	or nothing to encode
 *
 */
int
encode_ntype(attribute *pattr, pbs_list_head *ph, char *aname, char *rname, int mode, svrattrl **rtnl)
{
	svrattrl *pal;
	short	 ntype;

	static   char	ntype_str[ MAX_ENCODE_BFR ];
	int	 i;

	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;
	ntype_str[0] = '\0';
	for (i=0; nt[i].name; i++) {
		if (ntype == nt[i].bit) {
			strcpy(ntype_str, nt[i].name);
			break;
		}
	}

	if (ntype_str[0] == '\0') {
		return -(PBSE_ATVALERANGE);
	}

	pal = attrlist_create(aname, rname, (int)strlen(ntype_str)+1);
	if (pal == NULL)
		return -(PBSE_SYSTEM);

	(void)strcpy(pal->al_value, ntype_str);
	pal->al_flags = ATR_VFLAG_SET;
	if (ph)
		append_link(ph, &pal->al_link, pal);
	if (rtnl)
		*rtnl = pal;

	return (0);             /*success*/
}
int decode_unkn(

  pbs_attribute *patr,  /* May be Modified on Return */
  char          *name,
  char          *rescn,
  char          *value,
  int            perm)  /* only used for resources */

  {
  svrattrl *entry;
  size_t      valln;


  if (patr == NULL)
    return (PBSE_INTERNAL);

  if (!(patr->at_flags & ATR_VFLAG_SET))
    CLEAR_HEAD(patr->at_val.at_list);

  if (name == (char *)0)
    return (PBSE_INTERNAL);

  if (value == (char *)0)
    valln = 0;
  else
    valln = strlen(value) + 1;

  entry = attrlist_create(name, rescn, valln);

  if (entry == (svrattrl *)0)
    return (PBSE_SYSTEM);

  if (valln)
    memcpy(entry->al_value, value, valln - 1);

  append_link(&patr->at_val.at_list, &entry->al_link, entry);

  patr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY;

  return (0);
  }
Beispiel #25
0
int encode_procct(

  pbs_attribute  *attr,   /* ptr to pbs_attribute */
  tlist_head     *phead,  /* head of attrlist list */
  const char    *atname, /* pbs_attribute name */
  const char    *rsname, /* resource name or null */
  int            UNUSED(mode),   /* encode mode, unused here */
  int            UNUSED(perm))   /* only used for resources */

  {
  size_t   ct;
  char   cvnbuf[32];
  svrattrl *pal;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  sprintf(cvnbuf, "%ld", attr->at_val.at_long);

  ct = strlen(cvnbuf);

  pal = attrlist_create(atname, rsname, ct + 1);

  if (pal == (svrattrl *)0)
    return (-1);

  memcpy(pal->al_value, cvnbuf, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
Beispiel #26
0
int
encode_ll(
  attribute *attr,   /* ptr to attribute */
  tlist_head *phead,   /* head of attrlist list */
  char *atname,  /* attribute name */
  char *rsname,  /* resource name or null */
  int mode   /* encode mode, unused here */
)
  {
  size_t   ct;
  const char *cvn;
  svrattrl *pal;

  if (!attr)
    return (-1);

  if (!(attr->at_flags & ATR_VFLAG_SET))
    return (0);

  cvn = uLTostr(attr->at_val.at_ll, 10);

  ct = strlen(cvn) + 1;

  pal = attrlist_create(atname, rsname, ct);

  if (pal == (svrattrl *)0)
    return (-1);

  (void)memcpy(pal->al_value, cvn, ct);

  pal->al_flags = attr->at_flags;

  append_link(phead, &pal->al_link, pal);

  return (1);
  }
Beispiel #27
0
int encode_svrstate(

  pbs_attribute  *pattr,   /* ptr to pbs_attribute */
  tlist_head     *phead,   /* head of attrlist list */
  char           *atname,  /* pbs_attribute name */
  char           *rsname,  /* null */
  int             mode,    /* encode mode */
  int             perm)    /* only used for resources */

  {
  svrattrl *pal;
  char *psname;

  if (pattr == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  if ((mode == ATR_ENCODE_SAVE)   ||
      (pattr->at_val.at_long <= SV_STATE_DOWN) ||
      (pattr->at_val.at_long > SV_STATE_SHUTSIG))
    {
    /* SUCCESS */

    return(0);  /* don't bother to encode it */
    }

  psname = svr_state_names[pattr->at_val.at_long];

  if (pattr->at_val.at_long == SV_STATE_RUN)
    {
    pthread_mutex_lock(server.sv_attr_mutex);
    if (server.sv_attr[SRV_ATR_scheduling].at_val.at_long == 0)
      psname = svr_idle;
    else 
      {
      pthread_mutex_lock(scheduler_sock_jobct_mutex);
      if (scheduler_sock != -1)
        psname = svr_sched;
      pthread_mutex_unlock(scheduler_sock_jobct_mutex);
      }
    pthread_mutex_unlock(server.sv_attr_mutex);
    }

  pal = attrlist_create(atname, rsname, strlen(psname) + 1);

  if (pal == NULL)
    {
    /* FAILURE */

    return(-1);
    }

  strcpy(pal->al_value, psname);

  pal->al_flags = pattr->at_flags;

  append_link(phead, &pal->al_link, pal);

  /* SUCCESS */

  return(1);
  }  /* END encode_svrstate() */
Beispiel #28
0
static void req_stat_job_step2(

  struct stat_cntl *cntl)  /* I/O (free'd on return) */

  {
  svrattrl              *pal;
  job                   *pjob = NULL;

  struct batch_request  *preq;
  struct batch_reply    *preply;
  int                    rc = 0;
  enum TJobStatTypeEnum  type;
  pbs_queue             *pque = NULL;
  int                    exec_only = 0;

  int                    bad = 0;
  long                   DTime;  /* delta time - only report full pbs_attribute list if J->MTime > DTime */
  static svrattrl       *dpal = NULL;
  int                    job_array_index = 0;
  job_array             *pa = NULL;
  char                   log_buf[LOCAL_LOG_BUF_SIZE];
  all_jobs_iterator      *iter;

  preq   = cntl->sc_origrq;
  type   = (enum TJobStatTypeEnum)cntl->sc_type;
  preply = &preq->rq_reply;

  /* See pbs_server_attributes(1B) for details on "poll_jobs" behaviour */

  if (dpal == NULL)
    {
    /* build 'delta' pbs_attribute list */

    svrattrl *tpal;

    tlist_head dalist;

    int aindex;

    int atrlist[] =
      {
      JOB_ATR_jobname,
      JOB_ATR_resc_used,
      JOB_ATR_LAST
      };

    CLEAR_LINK(dalist);

    for (aindex = 0;atrlist[aindex] != JOB_ATR_LAST;aindex++)
      {
      if ((tpal = attrlist_create("", "", 23)) == NULL)
        {
        return;
        }

      tpal->al_valln = atrlist[aindex];

      if (dpal == NULL)
        dpal = tpal;

      append_link(&dalist, &tpal->al_link, tpal);
      }
    }  /* END if (dpal == NULL) */

  if (type == tjstArray)
    {
    pa = get_array(preq->rq_ind.rq_status.rq_id);

    if (pa == NULL)
      {
      req_reject(PBSE_UNKARRAYID, 0, preq, NULL, "unable to find array");
      return;
      }
    }

  {
  all_jobs *ajptr = NULL;

  if (type == tjstQueue)
    ajptr = cntl->sc_pque->qu_jobs;

  else if (type == tjstSummarizeArraysQueue)
    ajptr = cntl->sc_pque->qu_jobs_array_sum;

  else if (type == tjstSummarizeArraysServer)
    ajptr = &array_summary;

  else
    ajptr = &alljobs;

  ajptr->lock();
  iter = ajptr->get_iterator();
  ajptr->unlock();
  }

  /*
   * now ready for part 3, building the status reply,
   * loop through again
   */

  if ((type == tjstSummarizeArraysQueue) || 
      (type == tjstSummarizeArraysServer))
    {
    /* No array can be owned for these options */
    update_array_statuses();
    }


  if (type == tjstJob)
    pjob = svr_find_job(preq->rq_ind.rq_status.rq_id, FALSE);

  else if (type == tjstQueue)
    pjob = next_job(cntl->sc_pque->qu_jobs,iter);

  else if (type == tjstSummarizeArraysQueue)
    pjob = next_job(cntl->sc_pque->qu_jobs_array_sum,iter);

  else if (type == tjstSummarizeArraysServer)
    pjob = next_job(&array_summary,iter);

  else if (type == tjstArray)
    {
    job_array_index = -1;
    pjob = NULL;
    /* increment job_array_index until we find a non-null pointer or hit the end */
    while (++job_array_index < pa->ai_qs.array_size)
      {
      if (pa->job_ids[job_array_index] != NULL)
        {
        if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
          {
          break;
          }
        }
      }
    }
  else
    pjob = next_job(&alljobs,iter);

  DTime = 0;

  if (preq->rq_extend != NULL)
    {
    char *ptr;

    /* FORMAT:  { EXECQONLY | DELTA:<EPOCHTIME> } */

    if (strstr(preq->rq_extend, EXECQUEONLY))
      exec_only = 1;

    ptr = strstr(preq->rq_extend, "DELTA:");

    if (ptr != NULL)
      {
      ptr += strlen("delta:");

      DTime = strtol(ptr, NULL, 10);
      }
    }

  if ((type == tjstTruncatedServer) || 
      (type == tjstTruncatedQueue))
    {
    long sentJobCounter;
    long qjcounter;
    long qmaxreport;
    all_queues_iterator *iter = NULL;

    svr_queues.lock();
    iter = svr_queues.get_iterator();
    svr_queues.unlock();

    /* loop through all queues */
    while ((pque = next_queue(&svr_queues,iter)) != NULL)
      {
      qjcounter = 0;

      if ((exec_only == 1) &&
          (pque->qu_qs.qu_type != QTYPE_Execution))
        {
        /* ignore routing queues */
        unlock_queue(pque, __func__, "ignore queue", LOGLEVEL);
        continue;
        }

      if (((pque->qu_attr[QA_ATR_MaxReport].at_flags & ATR_VFLAG_SET) != 0) &&
          (pque->qu_attr[QA_ATR_MaxReport].at_val.at_long >= 0))
        {
        qmaxreport = pque->qu_attr[QA_ATR_MaxReport].at_val.at_long;
        }
      else
        {
        qmaxreport = TMAX_JOB;
        }

      if (LOGLEVEL >= 5)
        {
        sprintf(log_buf,"giving scheduler up to %ld idle jobs in queue %s\n",
          qmaxreport,
          pque->qu_qs.qu_name);

        log_event(PBSEVENT_SYSTEM,PBS_EVENTCLASS_QUEUE,pque->qu_qs.qu_name,log_buf);
        }

      sentJobCounter = 0;

      /* loop through jobs in queue */
      if (pjob != NULL)
        unlock_ji_mutex(pjob, __func__, "5", LOGLEVEL);

      all_jobs_iterator *jobiter = NULL;
      pque->qu_jobs->lock();
      jobiter = pque->qu_jobs->get_iterator();
      pque->qu_jobs->unlock();

      while ((pjob = next_job(pque->qu_jobs,jobiter)) != NULL)
        {
        if ((qjcounter >= qmaxreport) &&
            (pjob->ji_qs.ji_state == JOB_STATE_QUEUED))
          {
          /* max_report of queued jobs reached for queue */
          unlock_ji_mutex(pjob, __func__, "6", LOGLEVEL);

          continue;
          }

        pal = (svrattrl *)GET_NEXT(preq->rq_ind.rq_status.rq_attr);

        rc = status_job(
               pjob,
               preq,
               (pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long >= DTime) ? pal : dpal,
               &preply->brp_un.brp_status,
               &bad);

        if ((rc != 0) && (rc != PBSE_PERM))
          {
          req_reject(rc, bad, preq, NULL, NULL);

          unlock_ji_mutex(pjob, __func__, "7", LOGLEVEL);
          unlock_queue(pque, __func__, "perm", LOGLEVEL);

          delete iter;

          return;
          }

        sentJobCounter++;

        if (pjob->ji_qs.ji_state == JOB_STATE_QUEUED)
          qjcounter++;

        unlock_ji_mutex(pjob, __func__, "8", LOGLEVEL);
        }    /* END foreach (pjob from pque) */

      if (LOGLEVEL >= 5)
        {
        sprintf(log_buf,"sent scheduler %ld total jobs for queue %s\n",
          sentJobCounter,
          pque->qu_qs.qu_name);

        log_event(PBSEVENT_SYSTEM,PBS_EVENTCLASS_QUEUE,pque->qu_qs.qu_name,log_buf);
        }
    
      unlock_queue(pque, __func__, "end while", LOGLEVEL);
      }      /* END for (pque) */

    reply_send_svr(preq);

    delete iter;

    return;
    } /* END if ((type == tjstTruncatedServer) || ...) */

  while (pjob != NULL)
    {
    /* go ahead and build the status reply for this job */

    if (exec_only)
      {
      if (cntl->sc_pque != NULL)
        {
        if (cntl->sc_pque->qu_qs.qu_type != QTYPE_Execution)
          goto nextjob;
        }
      else
        {
        if (pa != NULL)
          pthread_mutex_unlock(pa->ai_mutex);
        pque = get_jobs_queue(&pjob);
        if (pa != NULL)
          pthread_mutex_lock(pa->ai_mutex);

        if ((pjob == NULL) ||
            (pque == NULL))
          goto nextjob;
        
        mutex_mgr pque_mutex = mutex_mgr(pque->qu_mutex, true);
        if (pque->qu_qs.qu_type != QTYPE_Execution)
          {
          goto nextjob;
          }
        }
      }

    pal = (svrattrl *)GET_NEXT(preq->rq_ind.rq_status.rq_attr);

    rc = status_job(
           pjob,
           preq,
           pal,
           &preply->brp_un.brp_status,
           &bad);

    if ((rc != 0) && 
        (rc != PBSE_PERM))
      {
      if (pa != NULL)
        {
        unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
        }

      unlock_ji_mutex(pjob, __func__, "9", LOGLEVEL);

      req_reject(rc, bad, preq, NULL, NULL);

      delete iter;

      return;
      }

    /* get next job */

nextjob:

    if (pjob != NULL)
      unlock_ji_mutex(pjob, __func__, "10", LOGLEVEL);

    if (type == tjstJob)
      break;

    if (type == tjstQueue)
      pjob = next_job(cntl->sc_pque->qu_jobs,iter);
    else if (type == tjstSummarizeArraysQueue)
      pjob = next_job(cntl->sc_pque->qu_jobs_array_sum,iter);
    else if (type == tjstSummarizeArraysServer)
      pjob = next_job(&array_summary,iter);
    else if (type == tjstArray)
      {
      pjob = NULL;
      /* increment job_array_index until we find a non-null pointer or hit the end */
      while (++job_array_index < pa->ai_qs.array_size)
        {
        if (pa->job_ids[job_array_index] != NULL)
          {
          if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
            {
            break;
            }
          }
        }
      }
    else
      pjob = next_job(&alljobs,iter);

    rc = 0;
    }  /* END while (pjob != NULL) */

  delete iter;

  if (pa != NULL)
    {
    unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
    }
 
  reply_send_svr(preq);

  if (LOGLEVEL >= 7)
    {
    log_event(PBSEVENT_SYSTEM,
      PBS_EVENTCLASS_JOB,
      "req_statjob",
      "Successfully returned the status of queued jobs\n");
    }

  return;
  }  /* END req_stat_job_step2() */
Beispiel #29
0
static void req_stat_job_step2(

  struct stat_cntl *cntl)  /* I/O (free'd on return) */

  {
  svrattrl              *pal;
  job                   *pjob = NULL;

  struct batch_request  *preq;
  struct batch_reply    *preply;
  int                    rc = 0;
  enum TJobStatTypeEnum  type;
  pbs_queue             *pque = NULL;
  int                    exec_only = 0;

  int                    bad = 0;
  long                   DTime;  /* delta time - only report full pbs_attribute list if J->MTime > DTime */
  static svrattrl       *dpal = NULL;
  int                    job_array_index = 0;
  job_array             *pa = NULL;
  char                   log_buf[LOCAL_LOG_BUF_SIZE];
  int                    iter;
  time_t                 time_now = time(NULL);
  long                   poll_jobs = 0;
  char                   job_id[PBS_MAXSVRJOBID+1];
  int                    job_substate = -1;
  time_t                 job_momstattime = -1;

  preq   = cntl->sc_origrq;
  type   = (enum TJobStatTypeEnum)cntl->sc_type;
  preply = &preq->rq_reply;

  /* See pbs_server_attributes(1B) for details on "poll_jobs" behaviour */

  if (dpal == NULL)
    {
    /* build 'delta' pbs_attribute list */

    svrattrl *tpal;

    tlist_head dalist;

    int aindex;

    int atrlist[] =
      {
      JOB_ATR_jobname,
      JOB_ATR_resc_used,
      JOB_ATR_LAST
      };

    CLEAR_LINK(dalist);

    for (aindex = 0;atrlist[aindex] != JOB_ATR_LAST;aindex++)
      {
      if ((tpal = attrlist_create("", "", 23)) == NULL)
        {
        return;
        }

      tpal->al_valln = atrlist[aindex];

      if (dpal == NULL)
        dpal = tpal;

      append_link(&dalist, &tpal->al_link, tpal);
      }
    }  /* END if (dpal == NULL) */

  if (type == tjstArray)
    {
    pa = get_array(preq->rq_ind.rq_status.rq_id);

    if (pa == NULL)
      {
      req_reject(PBSE_UNKARRAYID, 0, preq, NULL, "unable to find array");
      return;
      }
    }

  iter = -1;

  get_svr_attr_l(SRV_ATR_PollJobs, &poll_jobs);
  if (!poll_jobs)
    {
    /* polljobs not set - indicates we may need to obtain fresh data from
       MOM */

    if (cntl->sc_jobid[0] == '\0')
      pjob = NULL;
    else
      pjob = svr_find_job(cntl->sc_jobid, FALSE);

    while (1)
      {
      if (pjob == NULL)
        {
        /* start from the first job */

        if (type == tjstJob)
          {
          pjob = svr_find_job(preq->rq_ind.rq_status.rq_id, FALSE);
          }
        else if (type == tjstQueue)
          {
          pjob = next_job(cntl->sc_pque->qu_jobs,&iter);
          }
        else if (type == tjstArray)
          {
          job_array_index = 0;
          /* increment job_array_index until we find a non-null pointer or hit the end */
          while (job_array_index < pa->ai_qs.array_size)
            {
            if (pa->job_ids[job_array_index] != NULL)
              {
              if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
                {
                unlock_ji_mutex(pjob, __func__, "2", LOGLEVEL);
                break;
                }
              }

            job_array_index++;
            }
          }
        else
          {
          pjob = next_job(&alljobs,&iter);
          }

        }    /* END if (pjob == NULL) */
      else
        {
        strcpy(job_id, pjob->ji_qs.ji_jobid);
        unlock_ji_mutex(pjob, __func__, "3", LOGLEVEL);

        if (type == tjstJob)
          break;

        if (type == tjstQueue)
          pjob = next_job(cntl->sc_pque->qu_jobs,&iter);
        else if (type == tjstArray)
          {
          pjob = NULL;
          /* increment job_array_index until we find a non-null pointer or hit the end */
          while (++job_array_index < pa->ai_qs.array_size)
            {
            if (pa->job_ids[job_array_index] != NULL)
              {
              if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
                {
                unlock_ji_mutex(pjob, __func__, "3", LOGLEVEL);
                break;
                }
              }
            }
          }
        else
          pjob = next_job(&alljobs,&iter);
          
        }

      if (pjob == NULL)
        break;

      strcpy(job_id, pjob->ji_qs.ji_jobid);
      job_substate = pjob->ji_qs.ji_substate;
      job_momstattime = pjob->ji_momstat;
      strcpy(cntl->sc_jobid, job_id);
      unlock_ji_mutex(pjob, __func__, "4", LOGLEVEL);
      pjob = NULL;

      /* PBS_RESTAT_JOB defaults to 30 seconds */
      if ((job_substate == JOB_SUBSTATE_RUNNING) &&
          ((time_now - job_momstattime) > JobStatRate))
        {
        /* go to MOM for status */
        if ((rc = stat_to_mom(job_id, cntl)) == PBSE_MEM_MALLOC)
          break;

        if (rc != 0)
          {
          pjob = svr_find_job(job_id, FALSE);

          rc = 0;

          continue;
          }
        
        if (pa != NULL)
          unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);

        return; /* will pick up after mom replies */
        }
      }    /* END while(1) */

    if (rc != 0)
      {
      if (pa != NULL)
        unlock_ai_mutex(pa, __func__, "2", LOGLEVEL);

      reply_free(preply);

      req_reject(rc, 0, preq, NULL, "cannot get update from mom");

      return;
      }
    }    /* END if (!server.sv_attr[SRV_ATR_PollJobs].at_val.at_long) */

  /*
   * now ready for part 3, building the status reply,
   * loop through again
   */

  if ((type == tjstSummarizeArraysQueue) || 
      (type == tjstSummarizeArraysServer))
    {
    /* No array can be owned for these options */
    update_array_statuses();
    }

  if (type == tjstJob)
    pjob = svr_find_job(preq->rq_ind.rq_status.rq_id, FALSE);

  else if (type == tjstQueue)
    pjob = next_job(cntl->sc_pque->qu_jobs,&iter);

  else if (type == tjstSummarizeArraysQueue)
    pjob = next_job(cntl->sc_pque->qu_jobs_array_sum,&iter);

  else if (type == tjstSummarizeArraysServer)
    pjob = next_job(&array_summary,&iter);

  else if (type == tjstArray)
    {
    job_array_index = -1;
    pjob = NULL;
    /* increment job_array_index until we find a non-null pointer or hit the end */
    while (++job_array_index < pa->ai_qs.array_size)
      {
      if (pa->job_ids[job_array_index] != NULL)
        {
        if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
          {
          break;
          }
        }
      }
    }
  else
    pjob = next_job(&alljobs,&iter);

  DTime = 0;

  if (preq->rq_extend != NULL)
    {
    char *ptr;

    /* FORMAT:  { EXECQONLY | DELTA:<EPOCHTIME> } */

    if (strstr(preq->rq_extend, EXECQUEONLY))
      exec_only = 1;

    ptr = strstr(preq->rq_extend, "DELTA:");

    if (ptr != NULL)
      {
      ptr += strlen("delta:");

      DTime = strtol(ptr, NULL, 10);
      }
    }


  if ((type == tjstTruncatedServer) || 
      (type == tjstTruncatedQueue))
    {
    long sentJobCounter;
    long qjcounter;
    long qmaxreport;
    int  iter = -1;

    /* loop through all queues */
    while ((pque = next_queue(&svr_queues,&iter)) != NULL)
      {
      qjcounter = 0;

      if ((exec_only == 1) &&
          (pque->qu_qs.qu_type != QTYPE_Execution))
        {
        /* ignore routing queues */
        unlock_queue(pque, __func__, "ignore queue", LOGLEVEL);
        continue;
        }

      if (((pque->qu_attr[QA_ATR_MaxReport].at_flags & ATR_VFLAG_SET) != 0) &&
          (pque->qu_attr[QA_ATR_MaxReport].at_val.at_long >= 0))
        {
        qmaxreport = pque->qu_attr[QA_ATR_MaxReport].at_val.at_long;
        }
      else
        {
        qmaxreport = TMAX_JOB;
        }

      if (LOGLEVEL >= 5)
        {
        sprintf(log_buf,"giving scheduler up to %ld idle jobs in queue %s\n",
          qmaxreport,
          pque->qu_qs.qu_name);

        log_event(PBSEVENT_SYSTEM,PBS_EVENTCLASS_QUEUE,pque->qu_qs.qu_name,log_buf);
        }

      sentJobCounter = 0;

      /* loop through jobs in queue */
      if (pjob != NULL)
        unlock_ji_mutex(pjob, __func__, "5", LOGLEVEL);

      iter = -1;

      while ((pjob = next_job(pque->qu_jobs,&iter)) != NULL)
        {
        if ((qjcounter >= qmaxreport) &&
            (pjob->ji_qs.ji_state == JOB_STATE_QUEUED))
          {
          /* max_report of queued jobs reached for queue */
          unlock_ji_mutex(pjob, __func__, "6", LOGLEVEL);

          continue;
          }

        pal = (svrattrl *)GET_NEXT(preq->rq_ind.rq_status.rq_attr);

        rc = status_job(
               pjob,
               preq,
               (pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long >= DTime) ? pal : dpal,
               &preply->brp_un.brp_status,
               &bad);

        if ((rc != 0) && (rc != PBSE_PERM))
          {
          req_reject(rc, bad, preq, NULL, NULL);

          if (pa != NULL)
            {
            unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
            }
          unlock_ji_mutex(pjob, __func__, "7", LOGLEVEL);
          unlock_queue(pque, __func__, "perm", LOGLEVEL);
          return;
          }

        sentJobCounter++;

        if (pjob->ji_qs.ji_state == JOB_STATE_QUEUED)
          qjcounter++;

        unlock_ji_mutex(pjob, __func__, "8", LOGLEVEL);
        }    /* END foreach (pjob from pque) */

      if (LOGLEVEL >= 5)
        {
        sprintf(log_buf,"sent scheduler %ld total jobs for queue %s\n",
          sentJobCounter,
          pque->qu_qs.qu_name);

        log_event(PBSEVENT_SYSTEM,PBS_EVENTCLASS_QUEUE,pque->qu_qs.qu_name,log_buf);
        }
    
      unlock_queue(pque, __func__, "end while", LOGLEVEL);
      }      /* END for (pque) */
      
    if (pa != NULL)
      unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);

    reply_send_svr(preq);

    return;
    }        /* END if ((type == tjstTruncatedServer) || ...) */

  while (pjob != NULL)
    {
    /* go ahead and build the status reply for this job */

    if (exec_only)
      {
      if (cntl->sc_pque != NULL)
        {
        if (cntl->sc_pque->qu_qs.qu_type != QTYPE_Execution)
          goto nextjob;
        }
      else
        {
        if (pa != NULL)
          pthread_mutex_unlock(pa->ai_mutex);
        pque = get_jobs_queue(&pjob);
        if (pa != NULL)
          pthread_mutex_lock(pa->ai_mutex);

        if ((pjob == NULL) ||
            (pque == NULL))
          goto nextjob;
        
        if (pque->qu_qs.qu_type != QTYPE_Execution)
          {
          unlock_queue(pque, __func__, "not exec", LOGLEVEL);
        
          goto nextjob;
          }

        unlock_queue(pque, __func__, "exec", LOGLEVEL);
        }
      }

    pal = (svrattrl *)GET_NEXT(preq->rq_ind.rq_status.rq_attr);

    rc = status_job(
           pjob,
           preq,
           pal,
           &preply->brp_un.brp_status,
           &bad);

    if ((rc != 0) && 
        (rc != PBSE_PERM))
      {
      if (pa != NULL)
        {
        unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
        }
      unlock_ji_mutex(pjob, __func__, "9", LOGLEVEL);

      req_reject(rc, bad, preq, NULL, NULL);

      return;
      }

    /* get next job */

nextjob:

    if (pjob != NULL)
      unlock_ji_mutex(pjob, __func__, "10", LOGLEVEL);

    if (type == tjstJob)
      break;

    if (type == tjstQueue)
      pjob = next_job(cntl->sc_pque->qu_jobs,&iter);
    else if (type == tjstSummarizeArraysQueue)
      pjob = next_job(cntl->sc_pque->qu_jobs_array_sum,&iter);
    else if (type == tjstSummarizeArraysServer)
      pjob = next_job(&array_summary,&iter);
    else if (type == tjstArray)
      {
      pjob = NULL;
      /* increment job_array_index until we find a non-null pointer or hit the end */
      while (++job_array_index < pa->ai_qs.array_size)
        {
        if (pa->job_ids[job_array_index] != NULL)
          {
          if ((pjob = svr_find_job(pa->job_ids[job_array_index], FALSE)) != NULL)
            {
            break;
            }
          }
        }
      }
    else
      pjob = next_job(&alljobs,&iter);

    rc = 0;
    }  /* END while (pjob != NULL) */

  if (pa != NULL)
    {
    unlock_ai_mutex(pa, __func__, "1", LOGLEVEL);
    }
 
  reply_send_svr(preq);

  if (LOGLEVEL >= 7)
    {
    log_event(PBSEVENT_SYSTEM,
      PBS_EVENTCLASS_JOB,
      "req_statjob",
      "Successfully returned the status of queued jobs\n");
    }

  return;
  }  /* END req_stat_job_step2() */
Beispiel #30
0
/* Is this dead code? It isn't called anywhere. */
int add_walltime_remaining(
   
  int             index,
  pbs_attribute  *pattr,
  tlist_head     *phead)

  {
  int            len = 0;
  char           buf[MAXPATHLEN+1];
  const char   *pname;
  svrattrl      *pal;
  resource      *pres;
  
  int            found = 0;
  long  remaining = 0;
  long  upperBound = 0;
  time_t         time_now   = time(NULL);

  /* encode walltime remaining, this is custom because walltime 
   * remaining isn't an pbs_attribute */
  if ((pattr + JOB_ATR_state)->at_val.at_char != 'R')
    {
    /* only for running jobs, do nothing */
    return(PBSE_NONE);
    }
  
  if (((pattr + JOB_ATR_resource)->at_val.at_list.ll_next != NULL) &&
      ((pattr + JOB_ATR_resource)->at_flags & ATR_VFLAG_SET))
    {
    pres = (resource *)GET_NEXT((pattr + JOB_ATR_resource)->at_val.at_list);
    
    if ((pattr + JOB_ATR_comp_time)->at_flags & ATR_VFLAG_SET)
      upperBound = (pattr + JOB_ATR_comp_time)->at_val.at_long;
    else
      upperBound = time_now;
    
    /* find the walltime resource */
    for (;pres != NULL;pres = (resource *)GET_NEXT(pres->rs_link))
      {
      pname = pres->rs_defin->rs_name;
      
      if (strcmp(pname, "walltime") == 0)
        {
        /* found walltime */
        long value = pres->rs_value.at_val.at_long;
        remaining = value - (time_now - (pattr + index)->at_val.at_long);
        found = upperBound * 12;
        found = TRUE;
        break;
        }
      }
    }
  
  if (found == TRUE)
    {
    snprintf(buf,MAXPATHLEN,"%ld",remaining);
    
    len = strlen(buf);
    pal = attrlist_create("Walltime","Remaining",len+1);
    
    if (pal != NULL)
      {
      memcpy(pal->al_value,buf,len);
      pal->al_flags = ATR_VFLAG_SET;
      append_link(phead,&pal->al_link,pal);
      }
    }

  return(PBSE_NONE);
  } /* END add_walltime_remaining() */