/** * @brief * -__pbs_statvnode() - returns information about virtual nodes (vnodes) * * @param[in] c - communication handle * @param[in] id - object id * @param[in] attrib - pointer to attribute list * @param[in] extend - extend string for encoding req * * @return structure handle * @retval pointer to batch_status struct Success * @retval NULL error * */ struct batch_status * __pbs_statvnode(int c, char *id, struct attrl *attrib, char *extend) { int rc; struct batch_status *ret = NULL; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return NULL; /* first verify the attributes, if verification is enabled */ rc = pbs_verify_attributes(c, PBS_BATCH_StatusNode, MGR_OBJ_NODE, MGR_CMD_NONE, (struct attropl *) attrib); if (rc) return NULL; if (pbs_client_thread_lock_connection(c) != 0) return NULL; ret = PBSD_status(c, PBS_BATCH_StatusNode, id, attrib, extend); /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return ret; }
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); }
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; }
/** * @brief * -wrapper function for pbs_submit where submission takes credentials. * * @param[in] c - communication handle * @param[in] attrib - pointer to attr list * @param[in] script - script to be submitted * @param[in] destination - host where submission happens * @param[in] extend - extend string for encoding req * @param[in] credtype - credential type * @param[in] credlen - credential length * @param[in] credbuf - buffer to hold cred info * * @return string * @retval jobid success * @retval NULL error * */ char * pbs_submit_with_cred(int c, struct attropl *attrib, char *script, char *destination, char *extend, int credtype, size_t credlen, char *credbuf) { char *ret; struct pbs_client_thread_context *ptr; struct cred_info *cred_info; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return NULL; /* lock pthread mutex here for this connection */ /* blocking call, waits for mutex release */ if (pbs_client_thread_lock_connection(c) != 0) return NULL; ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (!ptr) { pbs_errno = PBSE_INTERNAL; (void)pbs_client_thread_unlock_connection(c); return NULL; } if (!ptr->th_cred_info) { cred_info = malloc(sizeof(struct cred_info)); if (!cred_info) { pbs_errno = PBSE_INTERNAL; (void)pbs_client_thread_unlock_connection(c); return NULL; } ptr->th_cred_info = (void *) cred_info; } else cred_info = (struct cred_info *) ptr->th_cred_info; /* copy credentials to static variables */ cred_info->cred_buf = credbuf; cred_info->cred_len = credlen; cred_info->cred_type = credtype; /* pbs_submit takes credentials from static variables */ ret = pbs_submit(c, attrib, script, destination, extend); cred_info->cred_buf = NULL; cred_info->cred_len = 0; cred_info->cred_type = 0; /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return ret; }
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); }
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; }
/** * @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; }
/** * @brief * Return the status of a hook. * * @param[in] c - communication handle * @param[in] id - object name * @param[in] attrib - pointer to attrl structure(list) * @param[in] extend - extend string for req * * @return structure handle * @retval pointer to attr list success * @retval NULL error * */ struct batch_status * __pbs_stathook(int c, char *id, struct attrl *attrib, char *extend) { struct batch_status *ret = NULL; int rc; int hook_obj; if (extend != NULL) { if (strcmp(extend, PBS_HOOK) == 0) { hook_obj = MGR_OBJ_PBS_HOOK; } else if (strcmp(extend, SITE_HOOK) == 0) { hook_obj = MGR_OBJ_SITE_HOOK; } else { return NULL; /* bad extend value */ } } else { hook_obj = MGR_OBJ_SITE_HOOK; } /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return NULL; /* first verify the attributes, if verification is enabled */ rc = pbs_verify_attributes(c, PBS_BATCH_StatusHook, hook_obj, MGR_CMD_NONE, (struct attropl *) attrib); if (rc) return NULL; if (pbs_client_thread_lock_connection(c) != 0) return NULL; ret = PBSD_status(c, PBS_BATCH_StatusHook, id, attrib, extend); /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return ret; }
/** * @brief * Passes submit reservation request to PBSD_submit_resv( ) * * @param[in] c - socket on which connected * @param[in] attrib - the list of attributes for batch request * @parma[in] extend - extension of batch request * * @return char* * @retval SUCCESS returns the reservation ID * @retval ERROR NULL */ char * __pbs_submit_resv(int c, struct attropl *attrib, char *extend) { struct attropl *pal; int rc; char *ret; for (pal = attrib; pal; pal = pal->next) pal->op = SET; /* force operator to SET */ /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return (char *)NULL; /* first verify the attributes, if verification is enabled */ rc = pbs_verify_attributes(c, PBS_BATCH_SubmitResv, MGR_OBJ_RESV, MGR_CMD_NONE, attrib); if (rc) return (char *)NULL; /* lock pthread mutex here for this connection */ /* blocking call, waits for mutex release */ if (pbs_client_thread_lock_connection(c) != 0) return (char *)NULL; /* initiate the queueing of the reservation */ /* Queue job with null string for job id */ ret = PBSD_submit_resv(c, "", attrib, extend); /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return (char *) NULL; return ret; }
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; }
/** * @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; }
/** * @brief * -submit job request * * @param[in] c - communication handle * @param[in] attrib - ponter to attr list * @param[in] script - job script * @param[in] destination - host where job submitted * @param[in] extend - buffer to hold cred info * * @return string * @retval jobid success * @retval NULL error * */ char * __pbs_submit(int c, struct attropl *attrib, char *script, char *destination, char *extend) { struct attropl *pal; char *return_jobid = NULL; int rc; struct pbs_client_thread_context *ptr; struct cred_info *cred_info = NULL; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return return_jobid; ptr = (struct pbs_client_thread_context *) pbs_client_thread_get_context_data(); if (!ptr) { pbs_errno = PBSE_INTERNAL; return return_jobid; } /* first verify the attributes, if verification is enabled */ rc = pbs_verify_attributes(c, PBS_BATCH_QueueJob, MGR_OBJ_JOB, MGR_CMD_NONE, attrib); if (rc) return return_jobid; /* lock pthread mutex here for this connection */ /* blocking call, waits for mutex release */ if (pbs_client_thread_lock_connection(c) != 0) return return_jobid; /* first be sure that the script is readable if specified ... */ if ((script != NULL) && (*script != '\0')) { if (access(script, R_OK) != 0) { pbs_errno = PBSE_BADSCRIPT; if ((connection[c].ch_errtxt = strdup("cannot access script file")) == NULL) pbs_errno = PBSE_SYSTEM; goto error; } } /* initiate the queueing of the job */ for (pal = attrib; pal; pal = pal->next) pal->op = SET; /* force operator to SET */ /* Queue job with null string for job id */ return_jobid = PBSD_queuejob(c, "", destination, attrib, extend, 0, NULL); if (return_jobid == NULL) goto error; /* send script across */ if ((script != NULL) && (*script != '\0')) { if ((rc = PBSD_jscript(c, script, 0, NULL)) != 0) { if (rc == PBSE_JOBSCRIPTMAXSIZE) pbs_errno = rc; else pbs_errno = PBSE_BADSCRIPT; goto error; } } /* OK, the script got across, apparently, so we are */ /* ready to commit */ cred_info = (struct cred_info *) ptr->th_cred_info; /* opaque information */ if (cred_info && cred_info->cred_len > 0) { if (PBSD_jcred(c, cred_info->cred_type, cred_info->cred_buf, cred_info->cred_len, 0, NULL) != 0) { pbs_errno = PBSE_BADCRED; goto error; } } if (PBSD_commit(c, return_jobid, 0, NULL) != 0) goto error; /* unlock the thread lock and update the thread context data */ if (pbs_client_thread_unlock_connection(c) != 0) return NULL; return return_jobid; error: (void)pbs_client_thread_unlock_connection(c); return NULL; }
int pbs_rescquery(int c, char **resclist, int num_resc, int *available, int *allocated, int *reserved, int *down) { int i; struct batch_reply *reply; int rc = 0; /* 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 (resclist == 0) { pbs_errno = connection[c].ch_errno = PBSE_RMNOPARAM; (void)pbs_client_thread_unlock_connection(c); return pbs_errno; } /* send request */ if ((rc = PBS_resc(c, PBS_BATCH_Rescq, resclist, num_resc, (pbs_resource_t)0)) != 0) { (void)pbs_client_thread_unlock_connection(c); return rc; } /* read in reply */ reply = PBSD_rdrpy(c); if ((rc = connection[c].ch_errno) == PBSE_NONE && reply->brp_choice == BATCH_REPLY_CHOICE_RescQuery) { struct brp_rescq *resq = &reply->brp_un.brp_rescq; if (resq == NULL || num_resc != resq->brq_number) { rc = pbs_errno = connection[c].ch_errno = PBSE_IRESVE; goto done; } /* copy in available and allocated numbers */ for (i=0; i<num_resc; i++) { available[i] = resq->brq_avail[i]; allocated[i] = resq->brq_alloc[i]; reserved[i] = resq->brq_resvd[i]; down[i] = resq->brq_down[i]; } } done: 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); }
/** * @brief * -send close connection batch request * * @param[in] connect - socket descriptor * * @return int * @retval 0 success * @retval -1 error * */ int __pbs_disconnect(int connect) { int sock; char x; if (connect < 0 || NCONNECTS <= connect) return 0; if (!connection[connect].ch_inuse) return 0; /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return -1; /* * Use only connection handle level lock since this is * just communication with server */ if (pbs_client_thread_lock_connection(connect) != 0) return -1; /* * check again to ensure that another racing thread * had not already closed the connection */ if (!connection[connect].ch_inuse) { (void)pbs_client_thread_unlock_connection(connect); return 0; } /* send close-connection message */ sock = connection[connect].ch_socket; DIS_tcp_setup(sock); if ((encode_DIS_ReqHdr(sock, PBS_BATCH_Disconnect, pbs_current_user) == 0) && (DIS_tcp_wflush(sock) == 0)) { for (;;) { /* wait for server to close connection */ #ifdef WIN32 if (recv(sock, &x, 1, 0) < 1) #else if (read(sock, &x, 1) < 1) #endif break; } } CS_close_socket(sock); CLOSESOCKET(sock); if (connection[connect].ch_errtxt != NULL) { free(connection[connect].ch_errtxt); connection[connect].ch_errtxt = NULL; } connection[connect].ch_errno = 0; connection[connect].ch_inuse = 0; /* unlock the connection level lock */ if (pbs_client_thread_unlock_connection(connect) != 0) return -1; /* * this is only a per thread work, so outside lock and unlock * connection needs the thread level connect context so this should be * called after unlocking */ if (pbs_client_thread_destroy_connect_context(connect) != 0) return -1; return 0; }