int enqueueTaskMsg_(int s, int taskID, struct LSFHeader *msgHdr) { struct tid *tEnt; char *msgBuf; struct lsTMsgHdr *header; tEnt = tid_find(taskID); if (tEnt == NULL) { return -1; } header = (struct lsTMsgHdr *)malloc(sizeof(struct lsTMsgHdr)); if (! header) { lserrno = LSE_MALLOC; return -1; } header->len = 0; header->msgPtr = NULL; if (s < 0) { header->type = LSTMSG_IOERR; lsQueueDataAppend_((char *)header, tEnt->tMsgQ); return 0; } /* or 0xffff ? */ if (msgHdr->reserved == 0 && msgHdr->length == 0) { header->type = LSTMSG_EOF; lsQueueDataAppend_((char *)header, tEnt->tMsgQ); return 0; } if (msgHdr->length == 0) msgBuf = malloc(1); else msgBuf = malloc(msgHdr->length); if (msgBuf == NULL) { lserrno = LSE_MALLOC; return -1; } if (b_read_fix(s, (char *)msgBuf, msgHdr->length) != msgHdr->length) { free(msgBuf); lserrno = LSE_MSG_SYS; return -1; } header->type = LSTMSG_DATA; header->len = msgHdr->length; header->msgPtr = msgBuf; lsQueueDataAppend_((char *)header, tEnt->tMsgQ); return 0; }
int ls_rkill(int rtid, int sig) { int s; struct tid *tid; char host[MAXHOSTNAMELEN]; int rc; if (rtid < 0) { lserrno = LSE_BAD_ARGS; return -1; } if (rtid == 0) { rc = lsRSig_(NULL, rtid, sig, RSIG_ID_ISTID); return rc; } if ((tid = tid_find(rtid)) == NULL) { return -1; } s = tid->sock; gethostbysock_(s, host); rc = lsRSig_(host, rtid, sig, RSIG_ID_ISTID); return rc; }
void * lsRGetpidAsync_(int taskid, int *pid) { struct _buf_ { struct LSFHeader hdrBuf; struct resPid pidBuf; } buf; LS_REQUEST_T *request; struct resPid pidReq; int s; struct tid *tid; char host[MAXHOSTNAMELEN]; if ((tid = tid_find(taskid)) == NULL) { return(NULL); } s = tid->sock; gethostbysock_(s, host); if (!FD_ISSET(s,&connection_ok_)){ FD_SET(s,&connection_ok_); if (ackReturnCode_(s) < 0) { closesocket(s); _lostconnection_(host); return (NULL); } } pidReq.rpid = taskid; pidReq.pid = -1; if (callRes_(s, RES_GETPID, (char *) &pidReq, (char *) &buf, sizeof(buf), xdr_resGetpid, 0, 0, NULL) == -1) { closesocket(s); _lostconnection_(host); return (NULL); } request = lsReqHandCreate_(taskid, currentSN, s, (void *)pid, rgetpidCompletionHandler_, (appCompletionHandler) NULL, NULL); if (request != NULL) if (lsQueueDataAppend_((char *)request, requestQ)) return(NULL); return (void *)request; }
int ls_sndmsg(int tid, char *buf, int count, task_sock) { int cc, sock; struct tid *tid; if (amSlave_ == TRUE) sock = msock_; else { if ((tid = tid_find(tid, task_sock)) == NULL) return (-1); sock = tid->sock; } return(b_write_fix( sock, buf, count) ); }
int ls_rcvmsg(int tid, char *buf, int count) { int cc; int sock; if (amSlave_ == TRUE) sock = msock_; else { if ( tid < 0) { } else { if ( (sock = tid_find(tid, task_sock)) < 0) { lserrno = LSE_RES_INVCHILD; return(-1); } } } return(b_read_fix( sock, buf, count) ); }
LS_REQUEST_T * lsIRGetRusage_(int rpid, struct jRusage *ru, appCompletionHandler appHandler, void *appExtra, int options) { struct { struct LSFHeader hdr; struct resRusage rusageReq; } requestBuf; struct lsRequest *request; struct resRusage rusageReq; int s; struct tid *tid; char host[MAXHOSTNAMELEN]; if ((tid = tid_find(rpid)) == NULL) { return NULL; } s = tid->sock; gethostbysock_(s, host); if (!FD_ISSET(s,&connection_ok_)){ FD_SET(s,&connection_ok_); if (ackReturnCode_(s) < 0) { closesocket(s); _lostconnection_(host); return NULL; } } rusageReq.rid = rpid; if (options == 0 || (options & RID_ISTID)) rusageReq.whatid = RES_RID_ISTID; else rusageReq.whatid = RES_RID_ISPID; if (callRes_(s, RES_RUSAGE, (char *)&rusageReq, (char *)&requestBuf, sizeof(requestBuf), xdr_resGetRusage, 0, 0, NULL) == -1) { closesocket(s); _lostconnection_(host); return NULL; } request = lsReqHandCreate_(rpid, currentSN, s, (void *)ru, rgetRusageCompletionHandler_, appHandler, appExtra); if (request == NULL) return NULL; if (lsQueueDataAppend_((char *)request, requestQ)) { lsReqFree_(request); return NULL; } return(request); }
int lsMsgWait_(int inTidCnt, int *tidArray, int *rdyTidCnt, int inFdCnt, int *fdArray, int *rdyFdCnt, int *outFdArray, struct timeval *timeout, int options) { int i; fd_set rm; struct tid *taskEnt; int maxfd; int nready; char hdrBuf[sizeof(struct LSFHeader)]; struct LSFHeader msgHdr; int rc; int rdycnt; XDR xdrs; bool_t tMsgQNonEmpty; int nBitsSet; bool_t anythingRdy; if ((! rdyTidCnt && ! rdyFdCnt) || (! tidArray && !fdArray) || (! inTidCnt && ! inFdCnt)) return 0; for (i = 0; i < inFdCnt; i++) outFdArray[i] = -1; Again: tMsgQNonEmpty = FALSE; FD_ZERO(&rm); nBitsSet = 0; if (rdyTidCnt) *rdyTidCnt = 0; if (rdyFdCnt) *rdyFdCnt = 0; if (inFdCnt > 0 && fdArray) for (i = 0; i < inFdCnt; i++) { if (FD_NOT_VALID(fdArray[i])) { lserrno = LSE_BAD_ARGS; rc = -1; goto Fail; } FD_SET(fdArray[i], &rm); nBitsSet++; } rdycnt = 0; if (inTidCnt && tidArray) { for (i = 0; i < inTidCnt; i++) { rc = lsMsgRdy_(tidArray[i], NULL); if (rc > 0) { tMsgQNonEmpty = TRUE; rdycnt++; continue; } taskEnt = tid_find(tidArray[i]); if (taskEnt == NULL) { rc = -1; goto Fail; } if (FD_NOT_VALID(taskEnt->sock)) { lserrno = LSE_BAD_ARGS; rc = -1; goto Fail; } nBitsSet++; FD_SET(taskEnt->sock, &rm); } if (tMsgQNonEmpty) { *rdyTidCnt = rdycnt; return 0; } } if (nBitsSet == 0) return 0; maxfd = sysconf(_SC_OPEN_MAX); if (maxfd > 1024) maxfd = 1024-1; nready = select(maxfd, &rm, NULL, NULL, timeout); if (nready < 0) { if (errno == EINTR) { goto Again; } else { lserrno = LSE_SELECT_SYS; rc = -1; goto Fail; } } if (rdyFdCnt) { rdycnt = 0; for (i = 0; i < inFdCnt; i++) { if (FD_ISSET(fdArray[i], &rm)) { rdycnt++; outFdArray[i] = fdArray[i]; } else outFdArray[i] = -1; } *rdyFdCnt = rdycnt; } if (nready == 0) { if (rdyTidCnt) *rdyTidCnt = 0; return 0; } if (rdyTidCnt) { rdycnt = 0; xdrmem_create(&xdrs, hdrBuf, sizeof(struct LSFHeader), XDR_DECODE); for (i = 0; i < inTidCnt; i++) { taskEnt = tidFindIgnoreConn_(tidArray[i]); if (taskEnt == NULL) { rc = -1; xdr_destroy(&xdrs); goto Fail; } if (FD_NOT_VALID(taskEnt->sock)) continue; if (! FD_ISSET(taskEnt->sock, &rm)) continue; xdr_setpos(&xdrs, 0); rc = readDecodeHdr_(taskEnt->sock, hdrBuf, b_read_fix, &xdrs, &msgHdr); if (rc < 0) { int nTids; int *tidSameConns; int tidIDx; rc = tidSameConnection_(taskEnt->sock, &nTids, &tidSameConns); for (tidIDx = 0; tidIDx < nTids; tidIDx++) { rc = enqueueTaskMsg_(-1, tidSameConns[tidIDx], NULL); if (rc < 0) { free(tidSameConns); xdr_destroy(&xdrs); goto Fail; } } rdycnt += nTids; free(tidSameConns); _lostconnection_(taskEnt->host); } else if (msgHdr.opCode != RES_NONRES) { rc = ackAsyncReturnCode_(taskEnt->sock, &msgHdr); if (rc < 0) { xdr_destroy(&xdrs); goto Fail; } } else { rc = enqueueTaskMsg_(taskEnt->sock, msgHdr.refCode, &msgHdr); if (rc < 0) { xdr_destroy(&xdrs); goto Fail; } FD_CLR(taskEnt->sock, &rm); rdycnt++; } } xdr_destroy(&xdrs); *rdyTidCnt = rdycnt; } anythingRdy = FALSE; if (rdyTidCnt) if (*rdyTidCnt > 0) anythingRdy = TRUE; if (rdyFdCnt) if (*rdyFdCnt > 0) anythingRdy = TRUE; if (! anythingRdy) goto Again; rc = 0; Fail: return rc; }
int lsMsgSnd_(int taskid, char *buffer, int len, int options) { struct LSFHeader header; char headerBuf[sizeof(struct LSFHeader)]; XDR xdrs; struct tid *tEnt; int rc; char hostname[MAXHOSTNAMELEN]; tEnt = tid_find(taskid); if (! tEnt) return -1; if (tEnt->sock < 0) { lserrno = LSE_LOSTCON; return -1; } #ifdef OS_HAS_PTHREAD pthread_mutex_lock(&fdLSLIBWriteMutex); #endif header.opCode = RES_NONRES; header.refCode = currentSN = REQUESTSN; header.length = len; header.reserved = taskid; gethostbysock_(tEnt->sock, hostname); if (strcmp(hostname, "LSF_HOST_NULL")) _setcurseqno_(hostname, currentSN); xdrmem_create(&xdrs, headerBuf, LSF_HEADER_LEN, XDR_ENCODE); if (!xdr_LSFHeader(&xdrs, &header)) { lserrno = LSE_BAD_XDR; xdr_destroy(&xdrs); rc = -1; goto AbortSnd; } xdr_destroy(&xdrs); rc = b_write_fix(tEnt->sock, headerBuf, LSF_HEADER_LEN); if (rc < 0) { if (errno == EPIPE) { close(tEnt->sock); tEnt->sock = -1; _lostconnection_(hostname); lserrno = LSE_LOSTCON; } rc = -1; goto AbortSnd; } rc = b_write_fix(tEnt->sock, buffer, len); if (rc < 0) { if (errno == EPIPE) { close(tEnt->sock); tEnt->sock = -1; _lostconnection_(hostname); lserrno = LSE_LOSTCON; } rc = -1; goto AbortSnd; } if (ackReturnCode_(tEnt->sock) < 0) { rc = -1; goto AbortSnd; } AbortSnd: #ifdef OS_HAS_PTHREAD pthread_mutex_unlock(&fdLSLIBWriteMutex); #endif return rc; }