int pbs_gpumode_err(
    
  int   c,
  char *node,
  char *gpuid,
  int   gpumode,
  int  *local_errno)

  {
  int                 rc;

  struct batch_reply *reply;

  if ((node == (char *)0) || (gpumode < 0 || gpumode > 3) || (gpuid == (char *)0))
    return (PBSE_IVALREQ);
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  /* send request */

  if ((rc = PBSD_gpu_put(c, node, gpuid, gpumode, -1, -1, NULL)) != 0)
    return (rc);

  /* read reply */

  reply = PBSD_rdrpy(local_errno, c);

  PBSD_FreeReply(reply);

  return connection[c].ch_errno;
  } /* END pbs_gpumode_err() */
Exemple #2
0
int pbs_rescrelease(
    
  int        c,
  resource_t rh)

  {

  struct batch_reply *reply;
  int                 rc;
  int                 local_errno = 0;

  pthread_mutex_lock(connection[c].ch_mutex);

  if ((rc = PBS_resc(c, PBS_BATCH_ReleaseResc, (char **)0, 0, rh)) != 0)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    return (rc);
    }


  /* now get reply */
  reply = PBSD_rdrpy(&local_errno, c);

  PBSD_FreeReply(reply);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);

  return(rc);
  }
Exemple #3
0
int
pbs_rescrelease(int c, pbs_resource_t rh)
{
	struct batch_reply *reply;
	int	rc;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	if ((rc = PBS_resc(c, PBS_BATCH_ReleaseResc, (char **)0, 0, rh)) != 0) {
		(void)pbs_client_thread_unlock_connection(c);
		return (rc);
	}

	/* now get reply */

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return (rc);
}
Exemple #4
0
int
pbs_gpureset(int c, char *node, char *gpuid, int permanent, int vol)
  {
  int      rc;

  struct batch_reply *reply;

  if ((node == (char *)0) || ((permanent != 1) && (permanent != 0)) ||
      ((vol != 1) && (vol != 0)) || (gpuid == (char *)0) ||
      ((permanent == 1) && (vol == 1)))
    return (pbs_errno = PBSE_IVALREQ);

  /* send request */

  if ((rc = PBSD_gpu_put(c, node, gpuid, -1, permanent, vol, NULL)) != 0)
    return (rc);

  /* read reply */

  reply = PBSD_rdrpy(c);

  PBSD_FreeReply(reply);

  return connection[c].ch_errno;
  }
Exemple #5
0
int pbs_rescquery(

  int    c,
  char **resclist, /* In - list of queries */
  int    num_resc, /* In - number in list  */
  int   *available,  /* Out - number available per query */
  int   *allocated,  /* Out - number allocated per query */
  int   *reserved, /* Out - number reserved  per query */
  int   *down)  /* Out - number down/off  per query */

  {
  int                 i;

  struct batch_reply *reply;
  int                 rc = 0;
  int                 local_errno = 0;

  pthread_mutex_lock(connection[c].ch_mutex);

  if (resclist == NULL)
    {
    connection[c].ch_errno = PBSE_RMNOPARAM;

    pthread_mutex_unlock(connection[c].ch_mutex);

    return(PBSE_RMNOPARAM);
    }

  /* send request */

  if ((rc = PBS_resc(c, PBS_BATCH_Rescq, resclist, num_resc, (resource_t)0)) != 0)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    return(rc);
    }

  /* read in reply */

  reply = PBSD_rdrpy(&local_errno, c);

  if (((rc = connection[c].ch_errno) == PBSE_NONE))
    {
    /* copy in available and allocated numbers */

    for (i = 0;i < num_resc;++i)
      {
      *(available + i) = *(reply->brp_un.brp_rescq.brq_avail + i);
      *(allocated + i) = *(reply->brp_un.brp_rescq.brq_alloc + i);
      *(reserved  + i) = *(reply->brp_un.brp_rescq.brq_resvd + i);
      *(down      + i) = *(reply->brp_un.brp_rescq.brq_down  + i);
      }
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);

  return(rc);
  }  /* END pbs_rescquery() */
Exemple #6
0
int
__pbs_orderjob(int c, char *job1, char *job2, char *extend)
{
	struct batch_reply *reply;
	int rc;
	int sock;


	if ((job1 == NULL) || (*job1 == '\0') ||
		(job2 == NULL) || (*job2 == '\0'))
		return (pbs_errno = PBSE_IVALREQ);

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_OrderJob, pbs_current_user)) ||
		(rc = encode_DIS_MoveJob(sock, job1, job2)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* read reply */

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Exemple #7
0
/**
 * @brief
 *	Returns pointer to status record
 *
 * @param[in]   c - index into connection table
 *
 * @return returns a pointer to a batch_status structure
 * @retval pointer to batch status on SUCCESS
 * @retval NULL on failure
 */
struct batch_status *PBSD_status_get(int c)
{
	struct brp_cmdstat  *stp; /* pointer to a returned status record */
	struct batch_status *bsp  = NULL;
	struct batch_status *rbsp = NULL;
	struct batch_reply  *reply;
	int i;

	/* read reply from stream into presentation element */

	reply = PBSD_rdrpy(c);
	if (reply == NULL) {
		pbs_errno = PBSE_PROTOCOL;
	} else if (reply->brp_choice != BATCH_REPLY_CHOICE_NULL  &&
		reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
		reply->brp_choice != BATCH_REPLY_CHOICE_Status) {
		pbs_errno = PBSE_PROTOCOL;
	} else if (connection[c].ch_errno == 0) {
		/* have zero or more attrl structs to decode here */
		stp = reply->brp_un.brp_statc;
		i = 0;
		pbs_errno = 0;
		while (stp != NULL) {
			if (i++ == 0) {
				rbsp = bsp = alloc_bs();
				if (bsp == NULL) {
					pbs_errno = PBSE_SYSTEM;
					break;
				}
			} else {
				bsp->next = alloc_bs();
				bsp = bsp->next;
				if (bsp == NULL) {
					pbs_errno = PBSE_SYSTEM;
					break;
				}
			}
			if ((bsp->name = strdup(stp->brp_objname)) == NULL) {
				pbs_errno = PBSE_SYSTEM;
				break;
			}
			bsp->attribs = stp->brp_attrl;
			if (stp->brp_attrl)
				stp->brp_attrl = 0;
			bsp->next = NULL;
			stp = stp->brp_stlink;
		}
		if (pbs_errno) {
			pbs_statfree(rbsp);
			rbsp = NULL;
		}
	}
	PBSD_FreeReply(reply);
	return rbsp;
}
Exemple #8
0
int PBSD_rdytocmt(

  int   connect,
  char *jobid)

  {
  int                 rc;

  struct batch_reply *reply;
  int                 sock;
  struct tcp_chan *chan = NULL;
  
  if ((connect < 0) || 
      (connect >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  pthread_mutex_lock(connection[connect].ch_mutex);
  sock = connection[connect].ch_socket;
  pthread_mutex_unlock(connection[connect].ch_mutex);

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    return(PBSE_MEM_MALLOC);
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RdytoCommit, pbs_current_user)) ||
      (rc = encode_DIS_JobId(chan, jobid)) ||
      (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
    pthread_mutex_lock(connection[connect].ch_mutex);
    connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
    pthread_mutex_unlock(connection[connect].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }
  DIS_tcp_cleanup(chan);

  /* read reply */

  reply = PBSD_rdrpy(&rc, connect);

  PBSD_FreeReply(reply);

  return(rc);
  }
Exemple #9
0
int
pbs_rescreserve(int c, char **rl, int num_resc, pbs_resource_t *prh)
{
	int	rc;
	struct batch_reply *reply;


	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	if (rl == NULL) {
		pbs_errno = connection[c].ch_errno = PBSE_RMNOPARAM;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	if (prh == NULL) {
		pbs_errno = connection[c].ch_errno = PBSE_RMBADPARAM;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	/* send request */

	if ((rc = PBS_resc(c, PBS_BATCH_ReserveResc, rl, num_resc, *prh)) != 0) {
		(void)pbs_client_thread_unlock_connection(c);
		return (rc);
	}

	/*
	 * now get reply, if reservation successful, the reservation handle,
	 * pbs_resource_t, is in the  aux field
	 */

	reply = PBSD_rdrpy(c);

	if (((rc = connection[c].ch_errno) == PBSE_NONE) ||
		(rc == PBSE_RMPART)) {
		*prh = reply->brp_auxcode;
	}
	PBSD_FreeReply(reply);

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return (rc);
}
Exemple #10
0
int
PBSD_ucred(int c, char *user, int type, char *buf, int len)
{
	int			rc;
	struct batch_reply	*reply = NULL;
	int			sock;

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	DIS_tcp_setup(sock);

	if ((rc =encode_DIS_ReqHdr(sock, PBS_BATCH_UserCred, pbs_current_user)) ||
		(rc = encode_DIS_UserCred(sock, user, type, buf, len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}
	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Exemple #11
0
int pbs_lock(

  int   c,      /* I */
  int   action, /* I */
  char *extend) /* I */

  {

  struct batch_reply *reply;

  int rc = 0;
  int sock;

  /* send request */

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  DIS_tcp_setup(sock);

  if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_SchedulerLock, pbs_current_user)) ||
      (rc = encode_DIS_SchedLock(sock, action)) ||
      (rc = encode_DIS_ReqExtend(sock, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  if (DIS_tcp_wflush(sock))
    {
    pbs_errno = PBSE_PROTOCOL;

    return(pbs_errno);
    }

  /* read in reply */

  reply = PBSD_rdrpy(c);
  rc = connection[c].ch_errno;

  PBSD_FreeReply(reply);

  return(rc);
  }  /* END pbs_terminate() */
Exemple #12
0
/**
 * @brief
 *	-send manager request and read reply.
 *
 * @param[in] c - communication handle
 * @param[in] function - req type
 * @param[in] command - command
 * @param[in] objtype - object type
 * @param[in] objname - object name
 * @param[in] aoplp - attribute list
 * @param[in] extend - extend string for req
 *
 * @return	int
 * @retval	0	success
 * @retval	!0	error
 *
 */ 
int
PBSD_manager(int c, int function, int command, int objtype, char *objname, struct attropl *aoplp, char *extend)
{
	int i;
	struct batch_reply *reply;
	int rc;

	/* initialize the thread context data, if not initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* verify the object name if creating a new one */
	if (command == MGR_CMD_CREATE)
		if (pbs_verify_object_name(objtype, objname) != 0)
			return pbs_errno;

	/* now verify the attributes, if verification is enabled */
	if ((pbs_verify_attributes(c, function, objtype,
		command, aoplp)) != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* send the manage request */
	i = PBSD_mgr_put(c, function, command, objtype, objname, aoplp, extend, 0, NULL);
	if (i) {
		(void)pbs_client_thread_unlock_connection(c);
		return i;
	}

	/* read reply from stream into presentation element */

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Exemple #13
0
int PBSD_commit(

    int   connect,  /* I */
    char *jobid)    /* I */

{

    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Commit, pbs_current_user)) ||
             (rc = encode_DIS_JobId(chan, jobid)) ||
             (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }
    DIS_tcp_cleanup(chan);

    /* PBSD_rdrpy sets connection[connect].ch_errno */
    reply = PBSD_rdrpy(&rc, connect);

    PBSD_FreeReply(reply);
    return(rc);
}  /* END PBSD_commit() */
Exemple #14
0
int PBSD_manager(

  int c,
  int function,
  int command,
  int objtype,
  char *objname,
  struct attropl *aoplp,
  char *extend)

  {
  int rc;

  struct batch_reply *reply;

  /* send the manage request */

  rc = PBSD_mgr_put(
         c,
         function,
         command,
         objtype,
         objname,
         aoplp,
         extend);

  if (rc != 0)
    {
    return(rc);
    }

  /* read reply from stream into presentation element */

  reply = PBSD_rdrpy(c);

  PBSD_FreeReply(reply);

  return(connection[c].ch_errno);
  }  /* END PBSD_manager() */
Exemple #15
0
int
pbs_gpumode(int c, char *node, char *gpuid, int gpumode)
  {
  int      rc;

  struct batch_reply *reply;

  if ((node == (char *)0) || (gpumode < 0 || gpumode > 3) || (gpuid == (char *)0))
    return (pbs_errno = PBSE_IVALREQ);

  /* send request */

  if ((rc = PBSD_gpu_put(c, node, gpuid, gpumode, -1, -1, NULL)) != 0)
    return (rc);

  /* read reply */

  reply = PBSD_rdrpy(c);

  PBSD_FreeReply(reply);

  return connection[c].ch_errno;
  }
Exemple #16
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc = PBSE_NONE;

  int                 fd;
  FILE               *munge_pipe;
  char                munge_buf[MUNGE_SIZE];
  char                munge_command[MUNGE_SIZE];
  char               *ptr; /* pointer to the current place to copy data into munge_buf */
  int                 bytes_read;
  int                 total_bytes_read = 0;
  int                 local_errno = 0;
  
  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan *chan = NULL;

  snprintf(munge_command,sizeof(munge_command),
    "munge -n 2>/dev/null");

  memset(munge_buf, 0, MUNGE_SIZE);
  ptr = munge_buf; 

  if ((munge_pipe = popen(munge_command,"r")) == NULL)
    {
    /* FAILURE */
    return(-1);
    }

  fd = fileno(munge_pipe);

  while ((bytes_read = read_ac_socket(fd, ptr, MUNGE_SIZE - total_bytes_read)) > 0)
    {
    total_bytes_read += bytes_read;
    ptr += bytes_read;
    }

  pclose(munge_pipe);

  if (bytes_read == -1)
    {
    /* read failed */
    local_errno = errno;
    log_err(local_errno, __func__, "error reading pipe in PBSD_munge_authenticate");
    return -1;
    }
  
  /* if we got no bytes back then Munge may not be installed etc. */
  if (total_bytes_read == 0)
    {
    return(PBSE_MUNGE_NOT_FOUND);
    }

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();  
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return rc;
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    rc = PBSE_MEM_MALLOC;
    }
  else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_AltAuthenUser,pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, munge_buf)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    /* ERROR */
    }
  else
    {
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_errno, handle)) != NULL)
      free(reply);

    rc = PBSE_NONE;
    }
  if (chan != NULL)
    DIS_tcp_cleanup(chan);
  return rc;
  } /* END PBSD_munge_authenticate() */
Exemple #17
0
int PBSD_munge_authenticate(

  int psock,  /* I */
  int handle) /* I */

  {
  int                 rc;

  munge_ctx_t         mctx = NULL;
  munge_err_t         mret = EMUNGE_SNAFU;
  char               *mcred = NULL;

  /* user id and name stuff */
  struct passwd      *pwent;
  uid_t               myrealuid;
  struct batch_reply *reply;
  unsigned short      user_port = 0;
  struct sockaddr_in  sockname;
  socklen_t           socknamelen = sizeof(sockname);
  struct tcp_chan    *chan;

  if ((mctx = munge_ctx_create()) == NULL)
    {
    return(-1);
    }

  if ((mret = munge_encode (&mcred, mctx, NULL, 0)) != EMUNGE_SUCCESS)
    {
    const char *merrmsg = NULL;
    if (!(merrmsg = munge_ctx_strerror(mctx)))
      {
      merrmsg = munge_strerror(mret);
      }

    fprintf(stderr, "munge_encode failed: %s (%d)\n", merrmsg, mret);
    munge_ctx_destroy(mctx);
    return(PBSE_MUNGE_NOT_FOUND); /*TODO more fine-grained error codes? */
    }
  
  munge_ctx_destroy(mctx);

  /* We got the certificate. Now make the PBS_BATCH_AltAuthenUser request */
  myrealuid = getuid();
  pwent = getpwuid(myrealuid);
  
  rc = getsockname(psock, (struct sockaddr *)&sockname, &socknamelen);
  
  if (rc == -1)
    {
    fprintf(stderr, "getsockname failed: %d\n", errno);
    return(-1);
    }
  
  user_port = ntohs(sockname.sin_port);
  
  if ((chan = DIS_tcp_setup(psock)) == NULL)
    {
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AltAuthenUser, pwent->pw_name)) ||
           (rc = diswui(chan, user_port)) ||
           (rc = diswst(chan, mcred)) ||
           (rc = encode_DIS_ReqExtend(chan, NULL)) ||
           (rc = DIS_tcp_wflush(chan)))
    {
    PBSD_munge_cred_destroy(&mcred);
    /* ERROR */
    return(rc);
    }
  else
    {
    int local_err = PBSE_NONE;
    PBSD_munge_cred_destroy(&mcred);
    /* read the reply */
    if ((reply = PBSD_rdrpy(&local_err, handle)) != NULL)
      free(reply);
    
    return(PBSE_NONE);
    }

  return(-1);
  }
int pbs_asyrunjob_err(

  int   c,
  char *jobid,    /* I */
  char *location,
  char *extend,
  int  *local_errno)

  {
  int                 rc;

  struct batch_reply *reply;
  unsigned int        resch = 0;
  int                 sock;
  struct tcp_chan *chan = NULL;

  if ((c < 0) || (jobid == NULL) || (*jobid == '\0'))
    {
    return(PBSE_IVALREQ);
    }

  if (location == NULL)
    location = "";

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_AsyrunJob, pbs_current_user))
      || (rc = encode_DIS_RunJob(chan, jobid, location, resch))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return(PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(local_errno, c);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
  DIS_tcp_cleanup(chan);
  return(rc);
  }  /* END pbs_asyrunjob_err() */
int pbs_orderjob_err(
    
  int   c,
  char *job1,
  char *job2,
  char *extend,
  int  *local_errno)

  {
  struct batch_reply *reply;
  int                 rc;
  int                 sock;
  struct tcp_chan *chan = NULL;


  if ((job1 == (char *)0) || (*job1 == '\0') ||
      (job2 == (char *)0) || (*job2 == '\0'))
    return (PBSE_IVALREQ);
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ);
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_OrderJob, pbs_current_user))
      || (rc = encode_DIS_MoveJob(chan, job1, job2))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* read reply */

  reply = PBSD_rdrpy(local_errno, c);

  PBSD_FreeReply(reply);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);

  return(rc);
  } /* END pbs_orderjob_err() */
Exemple #20
0
int
__pbs_rerunjob(int c, char *jobid, char *extend)
{
	int	rc;
	struct batch_reply *reply;
	int	sock;
	time_t  old_tcp_timeout;

	if ((jobid == NULL) || (*jobid == '\0'))
		return (pbs_errno = PBSE_IVALREQ);

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_Rerun, pbs_current_user)) ||
		(rc = encode_DIS_JobId(sock, jobid)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* write data */

	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* Set timeout value to very long value as rerun request */
	/* goes from Server to Mom and may take a long time      */
	old_tcp_timeout = pbs_tcp_timeout;
	pbs_tcp_timeout = PBS_DIS_TCP_TIMEOUT_VLONG;

	/* read reply from stream into presentation element */

	reply = PBSD_rdrpy(c);

	/* reset timeout */
	pbs_tcp_timeout = old_tcp_timeout;


	PBSD_FreeReply(reply);

	rc = connection[c].ch_errno;

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
int pbs_runjob_err(

  int   c,
  char *jobid,
  char *location,
  char *extend,
  int  *rc)

  {
  struct batch_reply   *reply;
  unsigned int          resch = 0;
  int                   sock;
  struct tcp_chan *chan = NULL;

  /* NOTE:  set_task sets WORK_Deferred_Child : request remains until child terminates */

  if ((jobid == NULL) ||
      (*jobid == '\0'))
    {
    *rc = PBSE_IVALREQ;
    return (*rc) * -1;
    }
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(PBSE_IVALREQ * -1);
    }

  if (location == NULL)
    {
    location = (char *)"";
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    *rc = PBSE_PROTOCOL;
    return(*rc);
    }
  /* send run request */
  else if ((*rc = encode_DIS_ReqHdr(chan, PBS_BATCH_RunJob, pbs_current_user)) ||
           (*rc = encode_DIS_RunJob(chan, jobid, location, resch)) ||
           (*rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[*rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);

    DIS_tcp_cleanup(chan);

    return(PBSE_PROTOCOL);
    }

  if ((*rc = DIS_tcp_wflush(chan)) != PBSE_NONE)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    
    DIS_tcp_cleanup(chan);

    return(PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(rc, c);

/*  *rc = connection[c].ch_errno; */

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
    
  DIS_tcp_cleanup(chan);

  return(*rc);
  }  /* END pbs_runjob_err() */
char *pbs_locjob_err(
    
  int   c,
  char *jobid,
  char *extend,
  int  *local_errno)

  {
  int rc;

  struct batch_reply *reply;
  char       *ploc = (char *)0;
  int sock;
  struct tcp_chan *chan = NULL;

  if ((jobid == (char *)0) || (*jobid == '\0'))
    {
    *local_errno = PBSE_IVALREQ;
    return(NULL);
    }
  
  if ((c < 0) || 
      (c >= PBS_NET_MAX_CONNECTIONS))
    {
    return(NULL);
    }

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    return NULL;
    }
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_LocateJob, pbs_current_user))
      || (rc = encode_DIS_JobId(chan, jobid))
      || (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* write data over tcp stream */

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    *local_errno = PBSE_PROTOCOL;
    DIS_tcp_cleanup(chan);
    return(NULL);
    }

  /* read reply from stream */

  reply = PBSD_rdrpy(local_errno,c);

  if (reply == NULL)
    {
    *local_errno = PBSE_PROTOCOL;
    }
  else if (reply->brp_choice != BATCH_REPLY_CHOICE_NULL &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
           reply->brp_choice != BATCH_REPLY_CHOICE_Locate)
    {
#ifndef NDEBUG
    fprintf(stderr, "advise: pbs_locjob\tUnexpected reply choice\n\n");
#endif /* NDEBUG */
    *local_errno = PBSE_PROTOCOL;
    }
  else if (connection[c].ch_errno == 0)
    {
    ploc = strdup(reply->brp_un.brp_locate);
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);
  DIS_tcp_cleanup(chan);
  return(ploc);
  } /* END pbs_locjob_err() */
Exemple #23
0
/**
 * @brief
 *	-send async run job batch request.
 *
 * @param[in] c - connection handle
 * @param[in] jobid- job identifier
 * @param[in] location - string of vnodes/resources to be allocated to the job 
 * @param[in] extend - extend string for encoding req
 *
 * @return      int
 * @retval      0       success
 * @retval      !0      error
 *
 */
int
pbs_asyrunjob(int c, char *jobid, char *location, char *extend)
{
	int	rc;
	struct batch_reply   *reply;
	unsigned long resch = 0;
	int	sock;

	if ((jobid == (char *)0) || (*jobid == '\0'))
		return (pbs_errno = PBSE_IVALREQ);
	if (location == (char *)0)
		location = "";

	sock = connection[c].ch_socket;

	/* initialize the thread context data, if not already initialized */
	if (pbs_client_thread_init_thread_context() != 0)
		return pbs_errno;

	/* lock pthread mutex here for this connection */
	/* blocking call, waits for mutex release */
	if (pbs_client_thread_lock_connection(c) != 0)
		return pbs_errno;

	/* setup DIS support routines for following DIS calls */

	DIS_tcp_setup(sock);

	/* send run request */

	if ((rc = encode_DIS_ReqHdr(sock, PBS_BATCH_AsyrunJob,
		pbs_current_user)) ||
		(rc = encode_DIS_Run(sock, jobid, location, resch)) ||
		(rc = encode_DIS_ReqExtend(sock, extend))) {
		connection[c].ch_errtxt = strdup(dis_emsg[rc]);
		if (connection[c].ch_errtxt == NULL) {
			pbs_errno = PBSE_SYSTEM;
		} else {
			pbs_errno = PBSE_PROTOCOL;
		}
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	if (DIS_tcp_wflush(sock)) {
		pbs_errno = PBSE_PROTOCOL;
		(void)pbs_client_thread_unlock_connection(c);
		return pbs_errno;
	}

	/* get reply */

	reply = PBSD_rdrpy(c);
	rc = connection[c].ch_errno;

	PBSD_FreeReply(reply);

	/* unlock the thread lock and update the thread context data */
	if (pbs_client_thread_unlock_connection(c) != 0)
		return pbs_errno;

	return rc;
}
Exemple #24
0
int PBSD_commit_get_sid(

    int   connect, /* I */
    long *sid,     /* O */
    char *jobid)   /* I */

{
    struct batch_reply *reply;
    int                 rc;
    int                 sock;
    int                 local_errno = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_Commit, pbs_current_user)) ||
             (rc = encode_DIS_JobId(chan, jobid)) ||
             (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    DIS_tcp_cleanup(chan);

    /* PBSD_rdrpy sets connection[connect].ch_errno */
    reply = PBSD_rdrpy(&local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    rc = connection[connect].ch_errno;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if (reply == NULL)
    {
        /* couldn't read a response */
        if (rc == PBSE_NONE)
            rc = PBSE_PROTOCOL;
    }
    else
    {
        /* read the sid if given and no error */
        if (rc == PBSE_NONE)
        {
            if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
            {
                if (sid != NULL)
                    *sid = atol(reply->brp_un.brp_txt.brp_str);
            }
            else
                /* (reply->brp_choice == BATCH_REPLY_CHOICE_NULL) */
            {
                *sid = reply->brp_code;
            }
        }

        PBSD_FreeReply(reply);
    }

    return(rc);
} /* END PBSD_commit_get_sid() */
Exemple #25
0
int pbs_stagein(
    
  int   c,
  char *jobid,
  char *location,
  char *extend)

  {
  int                   rc;
  int                   local_errno = 0;

  struct batch_reply   *reply;
  int                   sock;
  struct tcp_chan *chan = NULL;


  if ((jobid == (char *)0) || (*jobid == '\0'))
    return (PBSE_IVALREQ);

  if (location == (char *)0)
    location = (char *)"";

  pthread_mutex_lock(connection[c].ch_mutex);

  sock = connection[c].ch_socket;

  /* setup DIS support routines for following DIS calls */

  if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    rc = PBSE_PROTOCOL;
    return rc;
    }
    /* send stagein request, a run request with a different id */
  else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_StageIn, pbs_current_user)) ||
      (rc = encode_DIS_RunJob(chan, jobid, location, 0)) ||
      (rc = encode_DIS_ReqExtend(chan, extend)))
    {
    connection[c].ch_errtxt = strdup(dis_emsg[rc]);

    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  if (DIS_tcp_wflush(chan))
    {
    pthread_mutex_unlock(connection[c].ch_mutex);
    DIS_tcp_cleanup(chan);
    return (PBSE_PROTOCOL);
    }

  /* get reply */

  reply = PBSD_rdrpy(&local_errno, c);

  rc = connection[c].ch_errno;

  pthread_mutex_unlock(connection[c].ch_mutex);

  PBSD_FreeReply(reply);
  DIS_tcp_cleanup(chan);
  return(rc);
  }
Exemple #26
0
/**
 * @brief
 *	 encode a Job Credential Batch Request
 *
 * @param[in] c - socket descriptor
 * @param[in] type - credential type
 * @param[in] buf - credentials
 * @param[in] len - credential length
 * @param[in] rpp - indication for whether to use rpp
 * @param[in] msgid - msg id
 *
 * @return	int
 * @retval	0		success
 * @retval	!0(pbse error)	error
 *
 */
int
PBSD_jcred(int c, int type, char *buf, int len, int rpp, char **msgid)
{
	int			rc;
	struct batch_reply	*reply = NULL;
	int			sock;

	if (!rpp) {
		sock = connection[c].ch_socket;
		DIS_tcp_setup(sock);
	} else {
		sock = c;
		if ((rc = is_compose_cmd(sock, IS_CMD, msgid)) != DIS_SUCCESS)
			return rc;
	}

#ifdef  PBS_CRED_GRIDPROXY
	if (type == PBS_CREDTYPE_GRIDPROXY) {
		OM_uint32		major, minor;
		gss_buffer_desc		input, output;
		/*
		 OM_uint32		flag = GSS_C_CONF_FLAG|GSS_C_DELEG_FLAG;
		 */
		OM_uint32		flag = GSS_C_CONF_FLAG;
		gss_ctx_id_t		context = GSS_C_NO_CONTEXT;
		OM_uint32		life;
		int			ret;

		output.length = 0;
		input.length = 0;

		for (;;) {
			major = gss_init_sec_context(&minor,
				GSS_C_NO_CREDENTIAL, &context,
				GSS_C_NO_NAME, GSS_C_NO_OID, flag, 0,
				GSS_C_NO_CHANNEL_BINDINGS, &input, NULL,
				&output, NULL, NULL);

			if (reply)
				PBSD_FreeReply(reply);

			rc = PBSD_GSS_context(sock, output.value, output.length);
			if (rc) {
				connection[c].ch_errtxt = strdup(dis_emsg[rc]);
				if (connection[c].ch_errtxt == NULL)
					return (pbs_errno = PBSE_SYSTEM);
				return (pbs_errno = PBSE_PROTOCOL);
			}

			if (GSS_ERROR(major)) {
				connection[c].ch_errtxt =
					pbs_gss_error("gss_init_sec_context",
					major, minor);
				return (pbs_errno = PBSE_PROTOCOL);
			}

			reply = PBSD_rdrpy(c);
			if (reply == NULL)
				return (pbs_errno = PBSE_PROTOCOL);
			if (pbs_errno != PBSE_NONE) {
				PBSD_FreeReply(reply);
				return pbs_errno;
			}
			if (reply->brp_choice == BATCH_REPLY_CHOICE_Text) {
				input.length = reply->brp_un.brp_txt.brp_txtlen;
				input.value = reply->brp_un.brp_txt.brp_str;
			}
			else {
				input.length = 0;
				input.value = NULL;
			}
			if (input.length == 0 &&
				(major & GSS_S_CONTINUE_NEEDED) == 0)
				break;
		}
		if (reply)
			PBSD_FreeReply(reply);

		(void)gss_release_buffer(&minor, &output);
		if (major != GSS_S_COMPLETE || context == GSS_C_NO_CONTEXT) {
			connection[c].ch_errtxt =
				strdup("context could not be established");
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
			return (pbs_errno = PBSE_PROTOCOL);
		}

		input.value = buf;
		input.length = len;
		output.length = 0;
		major = gss_seal(&minor, context, 1, GSS_C_QOP_DEFAULT,
			&input, &ret, &output);
		if (major != GSS_S_COMPLETE) {
			connection[c].ch_errtxt =
				pbs_gss_error("gss_seal", major, minor);
			return (pbs_errno = PBSE_PROTOCOL);
		}
		if (ret == 0) {
			connection[c].ch_errtxt =
				strdup("confidentiality not available");
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
			return (pbs_errno = PBSE_PROTOCOL);
		}

		buf = output.value;
		len = output.length;

		output.length = 0;
		major = gss_delete_sec_context(&minor, &context, &output);
		if (major == GSS_S_COMPLETE && output.length > 0) {
			(void)gss_process_context_token(&minor,
				context, &output);
			(void)gss_release_buffer(&minor, &output);
		}
	}
#endif

	if ((rc =encode_DIS_ReqHdr(sock, PBS_BATCH_JobCred, pbs_current_user)) ||
		(rc = encode_DIS_JobCred(sock, type, buf, len)) ||
		(rc = encode_DIS_ReqExtend(sock, (char *)0))) {
		if (!rpp) {
			connection[c].ch_errtxt = strdup(dis_emsg[rc]);
			if (connection[c].ch_errtxt == NULL)
				return (pbs_errno = PBSE_SYSTEM);
		}
		return (pbs_errno = PBSE_PROTOCOL);
	}

	if (rpp) {
		pbs_errno = PBSE_NONE;
		if (rpp_flush(sock))
			pbs_errno = PBSE_PROTOCOL;

		return (pbs_errno);
	}

	if (DIS_tcp_wflush(sock)) {
		return (pbs_errno = PBSE_PROTOCOL);
	}

	reply = PBSD_rdrpy(c);

	PBSD_FreeReply(reply);

	return connection[c].ch_errno;
}
Exemple #27
0
static int PBSD_scbuf(

    int   c,  /* connection handle     */
    int   reqtype, /* request type */
    int   seq,  /* file chunk sequence number */
    char *buf,  /* file chunk */
    int   len,  /* length of chunk */
    char *jobid,  /* job id (for types 1 and 2 only) */
    enum job_file which) /* standard file type, see libpbs.h */

{

    struct batch_reply *reply;

    int                 rc;
    int                 sock;
    int                 local_errno = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[c].ch_mutex);
    sock = connection[c].ch_socket;
    pthread_mutex_unlock(connection[c].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_MEM_MALLOC);
    }
    else if (jobid == NULL)
        jobid = ""; /* use null string for null pointer */

    if ((rc = encode_DIS_ReqHdr(chan, reqtype, pbs_current_user)) ||
            (rc = encode_DIS_JobFile(chan, seq, buf, len, jobid, which)) ||
            (rc = encode_DIS_ReqExtend(chan, NULL)))
    {
        pthread_mutex_lock(connection[c].ch_mutex);
        connection[c].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[c].ch_mutex);
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }

    if (DIS_tcp_wflush(chan))
    {
        DIS_tcp_cleanup(chan);
        return(PBSE_PROTOCOL);
    }
    DIS_tcp_cleanup(chan);

    /* read reply */

    reply = PBSD_rdrpy(&local_errno, c);

    PBSD_FreeReply(reply);

    pthread_mutex_lock(connection[c].ch_mutex);
    rc = connection[c].ch_errno;
    pthread_mutex_unlock(connection[c].ch_mutex);


    return(rc);
}
Exemple #28
0
int pbs_rescreserve(
  
  int          c,        /* connection */
  char       **rl,       /* list of resources */
  int          num_resc, /* number of items in list */
  resource_t  *prh)      /* ptr to resource reservation handle */

  {
  int                 rc;
  int                 local_errno = 0;

  struct batch_reply *reply;

  pthread_mutex_lock(connection[c].ch_mutex);

  if (rl == NULL)
    {
    connection[c].ch_errno = PBSE_RMNOPARAM;

    pthread_mutex_unlock(connection[c].ch_mutex);

    return (PBSE_RMNOPARAM);
    }

  if (prh == NULL)
    {
    connection[c].ch_errno = PBSE_RMBADPARAM;

    pthread_mutex_unlock(connection[c].ch_mutex);

    return (PBSE_RMBADPARAM);
    }

  /* send request */

  if ((rc = PBS_resc(c, PBS_BATCH_ReserveResc, rl, num_resc, *prh)) != 0)
    {
    pthread_mutex_unlock(connection[c].ch_mutex);

    return (rc);
    }

  /*
   * now get reply, if reservation successful, the reservation handle,
   * resource_t, is in the  aux field
   */

  reply = PBSD_rdrpy(&local_errno, c);

  if (((rc = connection[c].ch_errno) == PBSE_NONE) ||
      (rc == PBSE_RMPART))
    {
    *prh = reply->brp_auxcode;
    }

  PBSD_FreeReply(reply);

  pthread_mutex_unlock(connection[c].ch_mutex);

  return (rc);
  } /* END pbs_rescreserve() */
Exemple #29
0
char *PBSD_queuejob(

    int             connect,     /* I */
    int            *local_errno, /* O */
    char           *jobid,       /* I */
    char           *destin,
    struct attropl *attrib,
    char           *extend)

{
    struct batch_reply *reply;
    char               *return_jobid = NULL;
    int                 rc;
    int                 sock;
    struct tcp_chan    *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    connection[connect].ch_errno = 0;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(NULL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan,PBS_BATCH_QueueJob,pbs_current_user)) ||
             (rc = encode_DIS_QueueJob(chan, jobid, destin, attrib)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        connection[connect].ch_errtxt = strdup(dis_emsg[rc]);
        pthread_mutex_unlock(connection[connect].ch_mutex);

        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    if (DIS_tcp_wflush(chan))
    {
        *local_errno = PBSE_PROTOCOL;
        DIS_tcp_cleanup(chan);
        return(NULL);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */

    reply = PBSD_rdrpy(local_errno, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        *local_errno = PBSE_PROTOCOL;
    }
    else if (connection[connect].ch_errno == 0)
    {
        return_jobid = strdup(reply->brp_un.brp_jid);
    }
    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return(return_jobid);
}  /* END PBSD_queuejob() */
Exemple #30
0
int PBSD_QueueJob_hash(

    int             connect,     /* I */
    char           *jobid,       /* I */
    char           *destin,
    memmgr        **mm,
    job_data       *job_attr,
    job_data       *res_attr,
    char           *extend,
    char          **job_id,
    char          **msg)

{
    struct batch_reply *reply;
    int                 rc = PBSE_NONE;
    int                 sock;
    int                 tmp_size = 0;
    struct tcp_chan *chan = NULL;

    pthread_mutex_lock(connection[connect].ch_mutex);
    sock = connection[connect].ch_socket;
    pthread_mutex_unlock(connection[connect].ch_mutex);

    if ((chan = DIS_tcp_setup(sock)) == NULL)
    {
        return(PBSE_PROTOCOL);
    }
    /* first, set up the body of the Queue Job request */
    else if ((rc = encode_DIS_ReqHdr(chan, PBS_BATCH_QueueJob, pbs_current_user)) ||
             (rc = encode_DIS_QueueJob_hash(chan, jobid, destin, mm, job_attr, res_attr)) ||
             (rc = encode_DIS_ReqExtend(chan, extend)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            if ((rc >= 0) &&
                    (rc <= DIS_INVALID))
                connection[connect].ch_errtxt = memmgr_strdup(mm, (char *)dis_emsg[rc], &tmp_size);
        }
        *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);

        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    if ((rc = DIS_tcp_wflush(chan)))
    {
        pthread_mutex_lock(connection[connect].ch_mutex);
        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
        pthread_mutex_unlock(connection[connect].ch_mutex);

        DIS_tcp_cleanup(chan);

        return(rc);
    }

    DIS_tcp_cleanup(chan);

    /* read reply from stream into presentation element */
    reply = PBSD_rdrpy(&rc, connect);

    pthread_mutex_lock(connection[connect].ch_mutex);
    if (reply == NULL)
    {
        if (rc == PBSE_TIMEOUT)
            rc = PBSE_EXPIRED;
    }
    else if (reply->brp_choice &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Text &&
             reply->brp_choice != BATCH_REPLY_CHOICE_Queue)
    {
        rc = PBSE_PROTOCOL;

        if (connection[connect].ch_errtxt == NULL)
        {
            *msg = memmgr_strdup(mm, connection[connect].ch_errtxt, &tmp_size);
        }
    }
    else if (reply->brp_choice == BATCH_REPLY_CHOICE_Text)
    {
        *msg = memmgr_strdup(mm, reply->brp_un.brp_txt.brp_str, &tmp_size);
    }
    else if (connection[connect].ch_errno == 0)
    {
        *job_id = memmgr_strdup(mm, reply->brp_un.brp_jid, &tmp_size);
    }

    pthread_mutex_unlock(connection[connect].ch_mutex);

    PBSD_FreeReply(reply);

    return rc;
}  /* END PBSD_queuejob() */