/* lsb_getlimits() */ struct resLimitReply * lsb_getlimits() { XDR xdrs; struct LSFHeader hdr; char *reply; int cc; char buf[sizeof(struct LSFHeader)]; struct resLimitReply *limitReply; initLSFHeader_(&hdr); hdr.opCode = BATCH_RESLIMIT_INFO; xdrmem_create(&xdrs, buf, sizeof(struct LSFHeader), XDR_ENCODE); if (! xdr_LSFHeader(&xdrs, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); return NULL; } reply = NULL; cc = callmbd(NULL, buf, XDR_GETPOS(&xdrs), &reply, &hdr, NULL, NULL, NULL); if (cc < 0) { xdr_destroy(&xdrs); lsberrno = LSBE_PROTOCOL; return NULL; } xdr_destroy(&xdrs); if (hdr.opCode != LSBE_NO_ERROR) { FREEUP(reply); lsberrno = hdr.opCode; return NULL; } xdrmem_create(&xdrs, reply, XDR_DECODE_SIZE_(cc), XDR_DECODE); limitReply = calloc(1, sizeof(struct resLimitReply)); if(!xdr_resLimitReply(&xdrs, limitReply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); if (cc) { FREEUP(reply); FREEUP(limitReply); } return NULL; } xdr_destroy(&xdrs); if (cc) FREEUP(reply); return limitReply; }
int callLim_(enum limReqCode reqCode, void *dsend, bool_t (*xdr_sfunc)(), void *drecv, bool_t (*xdr_rfunc)(), char *host, int options, struct LSFHeader *hdr) { struct LSFHeader reqHdr; struct LSFHeader replyHdr; XDR xdrs; char sbuf[8*MSGSIZE]; char rbuf[MAXMSGLEN]; char *repBuf; enum limReplyCode limReplyCode; static char first = TRUE; int reqLen; masterLimDown = FALSE; if (first) { if (initLimSock_() < 0) return(-1); first = FALSE; if (genParams_[LSF_API_CONNTIMEOUT].paramValue) { conntimeout_ = atoi(genParams_[LSF_API_CONNTIMEOUT].paramValue); if (conntimeout_ <= 0) conntimeout_ = CONNECT_TIMEOUT; } if (genParams_[LSF_API_RECVTIMEOUT].paramValue) { recvtimeout_ = atoi(genParams_[LSF_API_RECVTIMEOUT].paramValue); if (recvtimeout_ <= 0) recvtimeout_ = RECV_TIMEOUT; } } initLSFHeader_(&reqHdr); reqHdr.opCode = reqCode; reqHdr.refCode = getRefNum_(); reqHdr.version = OPENLAVA_VERSION; xdrmem_create(&xdrs, sbuf, 8*MSGSIZE, XDR_ENCODE); if (!xdr_encodeMsg(&xdrs, dsend, &reqHdr, xdr_sfunc, 0, NULL)) { xdr_destroy(&xdrs); lserrno = LSE_BAD_XDR; return -1; } reqLen = XDR_GETPOS(&xdrs); xdr_destroy(&xdrs); if (options & _USE_TCP_) { if (callLimTcp_(sbuf, &repBuf, reqLen, &replyHdr, options) < 0) return -1; if (replyHdr.length != 0) xdrmem_create(&xdrs, repBuf, XDR_DECODE_SIZE_(replyHdr.length), XDR_DECODE); else xdrmem_create(&xdrs, rbuf, MAXMSGLEN, XDR_DECODE); } else { if (callLimUdp_(sbuf, rbuf, reqLen, &reqHdr, host, options) < 0) return -1; if (options & _NON_BLOCK_) return 0; xdrmem_create(&xdrs, rbuf, MAXMSGLEN, XDR_DECODE); } if (!(options & _USE_TCP_)) { if (!xdr_LSFHeader(&xdrs, &replyHdr)) { xdr_destroy(&xdrs); lserrno = LSE_BAD_XDR; return -1; } } limReplyCode = replyHdr.opCode; lsf_lim_version = (int)replyHdr.version; switch (limReplyCode) { case LIME_NO_ERR: if (drecv != NULL) { if (! (*xdr_rfunc) (&xdrs, drecv, &replyHdr)) { xdr_destroy(&xdrs); if (options & _USE_TCP_) FREEUP(repBuf); lserrno = LSE_BAD_XDR; return -1; } } xdr_destroy(&xdrs); if (options & _USE_TCP_) FREEUP(repBuf); if (hdr != NULL) *hdr = replyHdr; return (0); default: xdr_destroy(&xdrs); if (options & _USE_TCP_) FREEUP(repBuf); err_return_(limReplyCode); return (-1); } }
struct queueInfoEnt * lsb_queueinfo (char **queues, int *numQueues, char *hosts, char *users, int options) { mbdReqType mbdReqtype; static struct infoReq queueInfoReq; static struct queueInfoReply reply; static struct queueInfoEnt **qInfo = NULL; struct queueInfoEnt **qTmp; XDR xdrs; XDR xdrs2; char *request_buf; char *reply_buf; int cc; int i; static struct LSFHeader hdr; char *clusterName = NULL; if (qInfo != NULL) { for (i = 0; i < reply.numQueues; i++) { xdr_lsffree(xdr_queueInfoEnt, (char*)qInfo[i], &hdr); } } if (numQueues == NULL) { lsberrno = LSBE_BAD_ARG; return NULL; } if ((queues == NULL && *numQueues > 1) || (*numQueues < 0)) { lsberrno = LSBE_BAD_ARG; return NULL; } queueInfoReq.options = 0; if (queueInfoReq.names) { FREEUP (queueInfoReq.names); } if (numQueues == NULL || *numQueues == 0) queueInfoReq.options |= ALL_QUEUE; else if (queues == NULL && *numQueues == 1) queueInfoReq.options |= DFT_QUEUE; if ((queueInfoReq.options & ALL_QUEUE) || (queueInfoReq.options & DFT_QUEUE)) { if ((queueInfoReq.names = malloc(3 * sizeof(char *))) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } queueInfoReq.names[0] = ""; queueInfoReq.numNames = 1; cc = 1; } else { if ((queueInfoReq.names = calloc(*numQueues + 2, sizeof(char*))) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } queueInfoReq.numNames = *numQueues; for (i = 0; i < *numQueues; i++) { if (queues[i] && strlen(queues[i]) + 1 < MAXHOSTNAMELEN) { queueInfoReq.names[i] = queues[i]; } else { free (queueInfoReq.names); queueInfoReq.names = NULL; lsberrno = LSBE_BAD_QUEUE; *numQueues = i; return NULL; } } cc = queueInfoReq.numNames; } if (users != NULL) { if (strlen(users) + 1 < MAX_LSB_NAME_LEN) { queueInfoReq.options |= CHECK_USER; queueInfoReq.names[cc] = users; cc++; } else { lsberrno = LSBE_BAD_USER; *numQueues = 0; return NULL; } } if (hosts != NULL) { if (ls_isclustername(hosts) <= 0) { if (strlen (hosts) + 1 < MAXHOSTNAMELEN) { queueInfoReq.options |= CHECK_HOST; queueInfoReq.names[cc] = hosts; cc++; } else { lsberrno = LSBE_BAD_HOST; *numQueues = 0; return NULL; } } else clusterName = hosts; } queueInfoReq.resReq = ""; mbdReqtype = BATCH_QUE_INFO; cc = sizeof(struct infoReq) + cc * MAXHOSTNAMELEN + cc + 128; if ((request_buf = malloc (cc)) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); initLSFHeader_(&hdr); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg(&xdrs, (char *)&queueInfoReq, &hdr, xdr_infoReq, 0, NULL)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); free (request_buf); return NULL; } if ((cc = callmbd(clusterName, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy(&xdrs); free (request_buf); return NULL; } xdr_destroy(&xdrs); free (request_buf); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_BAD_QUEUE) { xdrmem_create(&xdrs2, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (!xdr_queueInfoReply(&xdrs2, &reply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs2); if (cc) free(reply_buf); *numQueues = 0; return NULL; } xdr_destroy(&xdrs2); if (cc) free(reply_buf); if (lsberrno == LSBE_BAD_QUEUE) { *numQueues = reply.badQueue; return NULL; } if ((qTmp = myrealloc(qInfo, reply.numQueues * sizeof(struct queueInfoEnt *))) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } qInfo = qTmp; for (i = 0; i < reply.numQueues; i++) qInfo[i] = &(reply.queues[i]); *numQueues = reply.numQueues; return qInfo[0]; } if (cc) free(reply_buf); *numQueues = 0; return NULL; }
static int sendGrpReq (char *clusterName, int options, struct infoReq *groupInfo, struct groupInfoReply *reply) { XDR xdrs; char request_buf[MSGSIZE]; char * reply_buf; struct LSFHeader hdr; mbdReqType mbdReqtype; int cc; xdr_lsffree(xdr_groupInfoReply, (char *)reply, &hdr); mbdReqtype = BATCH_GRP_INFO; xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg(&xdrs, (char *)groupInfo, &hdr, xdr_infoReq, 0, NULL)){ lsberrno = LSBE_XDR; xdr_destroy(&xdrs); return -1; } if ((cc = callmbd (clusterName, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy(&xdrs); return -1; } xdr_destroy(&xdrs); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_BAD_GROUP ) { xdrmem_create(&xdrs, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (!xdr_groupInfoReply(&xdrs, reply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); if (cc) free(reply_buf); return -1; } xdr_destroy(&xdrs); if (cc) free(reply_buf); return 0; } if (cc) free(reply_buf); return -1; }
struct parameterInfo * lsb_parameterinfo (char **names, int *numUsers, int options) { mbdReqType mbdReqtype; XDR xdrs; struct LSFHeader hdr; char *request_buf; char *reply_buf; static struct parameterInfo paramInfo; struct parameterInfo *reply; static struct infoReq infoReq; static int alloc = FALSE; int cc = 0; infoReq.options = options; if (alloc == TRUE) { alloc = FALSE; FREEUP(infoReq.names); } if (numUsers) infoReq.numNames = *numUsers; else infoReq.numNames = 0; if (names) infoReq.names = names; else { if ((infoReq.names = malloc(sizeof(char *))) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } alloc = TRUE; infoReq.names[0] = ""; cc = 1; } infoReq.resReq = ""; mbdReqtype = BATCH_PARAM_INFO; cc = sizeof(struct infoReq) + cc * MAXHOSTNAMELEN + cc + 100; if ((request_buf = malloc (cc)) == NULL) { lsberrno = LSBE_NO_MEM; return NULL; } xdrmem_create(&xdrs, request_buf, cc, XDR_ENCODE); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg(&xdrs, (char *)&infoReq, &hdr, xdr_infoReq, 0, NULL)) { xdr_destroy(&xdrs); free (request_buf); lsberrno = LSBE_XDR; return NULL; } if ((cc = callmbd (NULL,request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy(&xdrs); free (request_buf); return NULL; } xdr_destroy(&xdrs); free (request_buf); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_BAD_USER) { xdrmem_create(&xdrs, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); reply = ¶mInfo; if(!xdr_parameterInfo (&xdrs, reply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); if (cc) free(reply_buf); return NULL; } xdr_destroy(&xdrs); if (cc) free(reply_buf); return(reply); } if (cc) free(reply_buf); return NULL; }
struct userInfoEnt * lsb_userinfo (char **users, int *numUsers) { mbdReqType mbdReqtype; XDR xdrs; struct LSFHeader hdr; char *reply_buf; char *request_buf; struct userInfoReply userInfoReply, *reply; static struct infoReq userInfoReq; int i, cc = 0, numReq = -1; char lsfUserName[MAXLINELEN]; if (numUsers) { numReq = *numUsers; *numUsers = 0; } if (numReq < 0) { lsberrno = LSBE_BAD_ARG; return (NULL); } if (userInfoReq.names) free (userInfoReq.names); if (numUsers == NULL || numReq == 0) { userInfoReq.numNames = 0; if ((userInfoReq.names = (char **) malloc (sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.names[0] = ""; cc = 1; } else if (numReq == 1 && users == NULL) { if (getLSFUser_ (lsfUserName, MAXLINELEN) != 0) { return (NULL); } userInfoReq.numNames = 1; if ((userInfoReq.names = (char **) malloc (sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.names[0] = lsfUserName; cc = 1; } else { if ((userInfoReq.names = (char **) calloc (numReq, sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } userInfoReq.numNames = numReq; for (i = 0; i < numReq; i++) { if (users[i] && strlen (users[i]) + 1 < MAXHOSTNAMELEN) userInfoReq.names[i] = users[i]; else { free (userInfoReq.names); lsberrno = LSBE_BAD_USER; *numUsers = i; return (NULL); } } cc = numReq; } userInfoReq.resReq = ""; mbdReqtype = BATCH_USER_INFO; cc = sizeof (struct infoReq) + cc * MAXHOSTNAMELEN + cc + 100; if ((request_buf = malloc (cc)) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } xdrmem_create (&xdrs, request_buf, cc, XDR_ENCODE); initLSFHeader_ (&hdr); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg (&xdrs, (char *) &userInfoReq, &hdr, xdr_infoReq, 0, NULL)) { xdr_destroy (&xdrs); free (request_buf); lsberrno = LSBE_XDR; return (NULL); } if ((cc = callmbd (NULL, request_buf, XDR_GETPOS (&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy (&xdrs); free (request_buf); return (NULL); } xdr_destroy (&xdrs); free (request_buf); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR || lsberrno == LSBE_BAD_USER) { xdrmem_create (&xdrs, reply_buf, XDR_DECODE_SIZE_ (cc), XDR_DECODE); reply = &userInfoReply; if (!xdr_userInfoReply (&xdrs, reply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy (&xdrs); if (cc) free (reply_buf); return (NULL); } xdr_destroy (&xdrs); if (cc) free (reply_buf); if (lsberrno == LSBE_BAD_USER) { *numUsers = reply->badUser; return (NULL); } *numUsers = reply->numUsers; return (reply->users); } if (cc) free (reply_buf); return (NULL); }
struct jobInfoHead * lsb_openjobinfo_a (LS_LONG_INT jobId, char *jobName, char *userName, char *queueName, char *hostName, int options) { static int first = TRUE; static struct jobInfoReq jobInfoReq; static struct jobInfoHead jobInfoHead; mbdReqType mbdReqtype; XDR xdrs, xdrs2; char request_buf[MSGSIZE]; char *reply_buf, *clusterName = NULL; int cc, aa; struct LSFHeader hdr; char lsfUserName[MAXLINELEN]; if (first) { if ( !(jobInfoReq.jobName = (char *) malloc(MAX_CMD_DESC_LEN)) || !(jobInfoReq.queue = (char *) malloc(MAX_LSB_NAME_LEN)) || !(jobInfoReq.userName = (char *) malloc(MAX_LSB_NAME_LEN)) || !(jobInfoReq.host = (char *) malloc(MAXHOSTNAMELEN))) { lsberrno = LSBE_SYS_CALL; return(NULL); } first = FALSE; } if (queueName == NULL) jobInfoReq.queue[0] = '\0'; else { if (strlen (queueName) >= MAX_LSB_NAME_LEN - 1) { lsberrno = LSBE_BAD_QUEUE; return(NULL); } TIMEIT(1, strcpy(jobInfoReq.queue, queueName), "strcpy"); } if (hostName == NULL) jobInfoReq.host[0] = '\0'; else { if (ls_isclustername(hostName) > 0) { jobInfoReq.host[0] = '\0'; clusterName = hostName; } else { struct hostent *hp; TIMEIT(0, (hp = Gethostbyname_(hostName)), "getHostOfficialByName_"); if (hp != NULL) { struct hostInfo *hostinfo; char officialNameBuf[MAXHOSTNAMELEN]; strcpy(officialNameBuf, hp->h_name); hostinfo = ls_gethostinfo("-", NULL, (char **)&hp->h_name, 1, LOCAL_ONLY); if (hostinfo == NULL) { strcpy(jobInfoReq.host, hostName); } else { strcpy(jobInfoReq.host, officialNameBuf); } } else { if (strlen (hostName) >= MAXHOSTNAMELEN - 1) { lsberrno = LSBE_BAD_HOST; return(NULL); } strcpy(jobInfoReq.host, hostName); } } } if (jobName == NULL) jobInfoReq.jobName[0] = '\0'; else { if (strlen (jobName) >= MAX_CMD_DESC_LEN - 1) { lsberrno = LSBE_BAD_JOB; return(NULL); } strcpy(jobInfoReq.jobName, jobName); } if (userName == NULL ) { TIMEIT(0, (cc = getLSFUser_(lsfUserName, MAXLINELEN)), "getLSFUser_"); if (cc != 0) { return (NULL); } TIMEIT(1, strcpy(jobInfoReq.userName, lsfUserName), "strcpy"); } else { if (strlen (userName) >= MAX_LSB_NAME_LEN - 1) { lsberrno = LSBE_BAD_USER; return(NULL); } strcpy(jobInfoReq.userName, userName); } if ((options & ~(JOBID_ONLY | JOBID_ONLY_ALL | HOST_NAME | NO_PEND_REASONS)) == 0) jobInfoReq.options = CUR_JOB; else jobInfoReq.options = options; if (jobId < 0) { lsberrno = LSBE_BAD_ARG; return(NULL); } jobInfoReq.jobId = jobId; mbdReqtype = BATCH_JOB_INFO; xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); hdr.opCode = mbdReqtype; TIMEIT(1, (aa = xdr_encodeMsg(&xdrs, (char *) &jobInfoReq , &hdr, xdr_jobInfoReq, 0, NULL)), "xdr_encodeMsg"); if (aa == FALSE) { lsberrno = LSBE_XDR; return(NULL); } TIMEIT(0, (cc = callmbd (clusterName, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, &mbdSock, NULL, NULL)), "callmbd"); if (cc == -1) { xdr_destroy(&xdrs); return (NULL); } xdr_destroy(&xdrs); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR) { xdrmem_create(&xdrs2, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (! xdr_jobInfoHead (&xdrs2, &jobInfoHead, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs2); if (cc) free(reply_buf); return(NULL); } xdr_destroy(&xdrs2); if (cc) free(reply_buf); return (&jobInfoHead); } if (cc) free(reply_buf); return(NULL); }
struct jobInfoEnt * lsb_readjobinfo(int *more) { XDR xdrs; int num, i, aa; struct LSFHeader hdr; char *buffer = NULL; static struct jobInfoReply jobInfoReply; static struct jobInfoEnt jobInfo; static struct submitReq submitReq; static int first = TRUE; static int npids = 0; static struct pidInfo *pidInfo = NULL; static int npgids = 0; static int *pgid = NULL; TIMEIT(0, (num = readNextPacket(&buffer, _lsb_recvtimeout, &hdr, mbdSock)), "readNextPacket"); if (num < 0) { closeSession(mbdSock); lsberrno = LSBE_EOF; return NULL; } if (first) { if ( (submitReq.fromHost = malloc(MAXHOSTNAMELEN)) == NULL || (submitReq.jobFile = malloc(MAXFILENAMELEN)) == NULL || (submitReq.inFile = malloc(MAXFILENAMELEN)) == NULL || (submitReq.outFile = malloc(MAXFILENAMELEN)) == NULL || (submitReq.errFile = malloc(MAXFILENAMELEN)) == NULL || (submitReq.inFileSpool = malloc(MAXFILENAMELEN)) == NULL || (submitReq.commandSpool = malloc(MAXFILENAMELEN)) == NULL || (submitReq.hostSpec = malloc(MAXHOSTNAMELEN)) == NULL || (submitReq.chkpntDir = malloc(MAXFILENAMELEN)) == NULL || (submitReq.subHomeDir = malloc(MAXFILENAMELEN)) == NULL || (jobInfoReply.userName = malloc(MAXLSFNAMELEN)) == NULL || (submitReq.cwd = malloc(MAXFILENAMELEN)) == NULL) { lsberrno = LSBE_NO_MEM; FREEUP(submitReq.fromHost); FREEUP(submitReq.jobFile); FREEUP(submitReq.inFile); FREEUP(submitReq.outFile); FREEUP(submitReq.errFile); FREEUP(submitReq.inFileSpool); FREEUP(submitReq.commandSpool); FREEUP(submitReq.hostSpec); FREEUP(submitReq.chkpntDir); FREEUP(submitReq.subHomeDir); FREEUP(jobInfoReply.userName); FREEUP(submitReq.cwd); free(buffer); return NULL; } submitReq.xf = NULL; submitReq.nxf = 0; jobInfoReply.numToHosts = 0; submitReq.numAskedHosts = 0; first = FALSE; } jobInfoReply.jobBill = &submitReq; if (jobInfoReply.numToHosts > 0) { for (i=0; i<jobInfoReply.numToHosts; i++) FREEUP(jobInfoReply.toHosts[i]); FREEUP(jobInfoReply.toHosts); jobInfoReply.numToHosts = 0; jobInfoReply.toHosts = NULL; } if (submitReq.xf) { free(submitReq.xf); submitReq.xf = NULL; } FREEUP( jobInfoReply.execHome ); FREEUP( jobInfoReply.execCwd ); FREEUP( jobInfoReply.execUsername ); FREEUP( jobInfoReply.parentGroup ); FREEUP( jobInfoReply.jName ); TIMEIT(1, xdrmem_create(&xdrs, buffer, XDR_DECODE_SIZE_(hdr.length), XDR_DECODE), "xdrmem_create"); TIMEIT(1, (aa = xdr_jobInfoReply(&xdrs, &jobInfoReply, &hdr)), "xdr_jobInfoReply"); if (aa == FALSE) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); free(buffer); jobInfoReply.toHosts = NULL; jobInfoReply.numToHosts = 0; return NULL; } TIMEIT(1, xdr_destroy(&xdrs), "xdr_destroy"); free(buffer); jobInfo.jobId = jobInfoReply.jobId; jobInfo.status = jobInfoReply.status; jobInfo.numReasons = jobInfoReply.numReasons; jobInfo.reasonTb = jobInfoReply.reasonTb; jobInfo.reasons = jobInfoReply.reasons; jobInfo.subreasons = jobInfoReply.subreasons; jobInfo.startTime = jobInfoReply.startTime; jobInfo.predictedStartTime = jobInfoReply.predictedStartTime; jobInfo.endTime = jobInfoReply.endTime; jobInfo.cpuTime = jobInfoReply.cpuTime; jobInfo.numExHosts = jobInfoReply.numToHosts; jobInfo.exHosts = jobInfoReply.toHosts; jobInfo.nIdx = jobInfoReply.nIdx; jobInfo.loadSched = jobInfoReply.loadSched; jobInfo.loadStop = jobInfoReply.loadStop; jobInfo.exitStatus = jobInfoReply.exitStatus; jobInfo.reserveTime = jobInfoReply.reserveTime; jobInfo.jobPid = jobInfoReply.jobPid; jobInfo.port = jobInfoReply.port; jobInfo.jobPriority = jobInfoReply.jobPriority; jobInfo.user = jobInfoReply.userName; jobInfo.execUid = jobInfoReply.execUid; jobInfo.execHome = jobInfoReply.execHome; jobInfo.execCwd = jobInfoReply.execCwd; jobInfo.execUsername = jobInfoReply.execUsername; jobInfo.jType = jobInfoReply.jType; jobInfo.parentGroup = jobInfoReply.parentGroup; jobInfo.jName = jobInfoReply.jName; for (i=0; i<NUM_JGRP_COUNTERS; i++) jobInfo.counter[i] = jobInfoReply.counter[i]; jobInfo.submitTime = jobInfoReply.jobBill->submitTime; jobInfo.umask = jobInfoReply.jobBill->umask; jobInfo.cwd = jobInfoReply.jobBill->cwd; jobInfo.subHomeDir = jobInfoReply.jobBill->subHomeDir; jobInfo.submit.options = jobInfoReply.jobBill->options; jobInfo.submit.options2 = jobInfoReply.jobBill->options2; jobInfo.submit.numProcessors = jobInfoReply.jobBill->numProcessors; jobInfo.submit.maxNumProcessors = jobInfoReply.jobBill->maxNumProcessors; jobInfo.submit.jobName = jobInfoReply.jobBill->jobName; jobInfo.submit.command = jobInfoReply.jobBill->command; jobInfo.submit.resReq = jobInfoReply.jobBill->resReq; jobInfo.submit.queue = jobInfoReply.jobBill->queue; jobInfo.fromHost = jobInfoReply.jobBill->fromHost; jobInfo.submit.inFile = jobInfoReply.jobBill->inFile; jobInfo.submit.outFile = jobInfoReply.jobBill->outFile; jobInfo.submit.errFile = jobInfoReply.jobBill->errFile; jobInfo.submit.beginTime = jobInfoReply.jobBill->beginTime; jobInfo.submit.termTime = jobInfoReply.jobBill->termTime; jobInfo.submit.userPriority = jobInfoReply.jobBill->userPriority; for (i=0; i<LSF_RLIM_NLIMITS; i++) { jobInfo.submit.rLimits[i] = jobInfoReply.jobBill->rLimits[i]; } jobInfo.submit.hostSpec = jobInfoReply.jobBill->hostSpec; jobInfo.submit.sigValue = jobInfoReply.jobBill->sigValue; jobInfo.submit.chkpntDir = jobInfoReply.jobBill->chkpntDir; jobInfo.submit.dependCond = jobInfoReply.jobBill->dependCond; jobInfo.submit.preExecCmd = jobInfoReply.jobBill->preExecCmd; jobInfo.submit.chkpntPeriod = jobInfoReply.jobBill->chkpntPeriod; jobInfo.submit.numAskedHosts = jobInfoReply.jobBill->numAskedHosts; jobInfo.submit.askedHosts = jobInfoReply.jobBill->askedHosts; jobInfo.submit.projectName = jobInfoReply.jobBill->projectName; jobInfo.submit.mailUser = jobInfoReply.jobBill->mailUser; jobInfo.submit.loginShell = jobInfoReply.jobBill->loginShell; jobInfo.submit.nxf = jobInfoReply.jobBill->nxf; jobInfo.submit.xf = jobInfoReply.jobBill->xf; jobInfo.jRusageUpdateTime = jobInfoReply.jRusageUpdateTime; jobInfo.runRusage.npids = npids; jobInfo.runRusage.pidInfo = pidInfo; jobInfo.runRusage.npgids = npgids; jobInfo.runRusage.pgid = pgid; copyJUsage(&(jobInfo.runRusage), &jobInfoReply.runRusage); npids = jobInfo.runRusage.npids; pidInfo = jobInfo.runRusage.pidInfo; npgids = jobInfo.runRusage.npgids; pgid = jobInfo.runRusage.pgid; if (jobInfoReply.runRusage.npids > 0) { FREEUP(jobInfoReply.runRusage.pidInfo); jobInfoReply.runRusage.npids = 0; } if (jobInfoReply.runRusage.npgids > 0) { FREEUP(jobInfoReply.runRusage.pgid); jobInfoReply.runRusage.npgids = 0; } if (more) *more = hdr.reserved; return &jobInfo; }
struct lsbSharedResourceInfo * lsb_sharedresourceinfo(char **resources, int *numResources, char *hostName, int options) { static char fname[] = "lsb_sharedresourceinfo"; static struct lsbShareResourceInfoReply lsbResourceInfoReply; struct resourceInfoReq resourceInfoReq; int cc = 0, i; char *clusterName = NULL; static struct LSFHeader hdr; char *request_buf; char *reply_buf; mbdReqType mbdReqtype; XDR xdrs, xdrs2; #define FREE_MEMORY \ { \ free(request_buf); \ free(resourceInfoReq.resourceNames); \ } #define FREE_REPLY_BUFFER \ { \ if (cc) \ free(reply_buf); \ } if (logclass & (LC_TRACE)) ls_syslog(LOG_DEBUG1, "%s: Entering this routine...", fname); if (lsbResourceInfoReply.numResources > 0) xdr_lsffree(xdr_lsbShareResourceInfoReply, (char *)&lsbResourceInfoReply, &hdr); if (numResources == NULL || *numResources < 0 || (resources == NULL && *numResources != 0) || (resources != NULL && *numResources == 0)) { lsberrno = LSBE_BAD_ARG; return (NULL); } resourceInfoReq.options = 0; if (*numResources == 0) { if ((resourceInfoReq.resourceNames = (char **) malloc(sizeof (char *))) == NULL) { lsberrno = LSBE_NO_MEM; return (NULL); } resourceInfoReq.resourceNames[0] = ""; resourceInfoReq.numResourceNames = 1; cc += 2; } else { if ((resourceInfoReq.resourceNames = (char **) malloc (*numResources * sizeof(char *))) == NULL) { lsberrno = LSBE_NO_MEM; return(NULL); } for (i = 0; i < *numResources; i++) { if (resources[i] && strlen (resources[i]) + 1 < MAXLSFNAMELEN) { resourceInfoReq.resourceNames[i] = resources[i]; cc += MAXLSFNAMELEN; } else { free (resourceInfoReq.resourceNames); lserrno = LSBE_BAD_RESOURCE; return (NULL); } } resourceInfoReq.numResourceNames = *numResources; } if (hostName != NULL) { if (ls_isclustername(hostName) <= 0) { if (strlen (hostName) + 1 < MAXHOSTNAMELEN) { resourceInfoReq.hostName = hostName; } else { lsberrno = LSBE_BAD_HOST; return (NULL); } } else { clusterName = hostName; cc += MAXHOSTNAMELEN; } } else resourceInfoReq.hostName = " "; mbdReqtype = BATCH_RESOURCE_INFO; cc = sizeof(struct resourceInfoReq) + cc + 100; if ((request_buf = malloc (cc)) == NULL) { lsberrno = LSBE_NO_MEM; return(NULL); } xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); initLSFHeader_(&hdr); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg(&xdrs, (char*)&resourceInfoReq, &hdr, xdr_resourceInfoReq, 0, NULL)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); FREE_MEMORY; return(NULL); } if ((cc = callmbd(clusterName, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy(&xdrs); FREE_MEMORY; return (NULL); } FREE_MEMORY; lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR) { xdrmem_create(&xdrs2, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (!xdr_lsbShareResourceInfoReply(&xdrs2, &lsbResourceInfoReply, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs2); FREE_REPLY_BUFFER; return(NULL); } xdr_destroy(&xdrs2); FREE_REPLY_BUFFER; *numResources = lsbResourceInfoReply.numResources; return (lsbResourceInfoReply.resources); } FREE_REPLY_BUFFER; return (NULL); }
int lsb_movejob (LS_LONG_INT jobId, int *position, int opCode) { struct jobMoveReq jobMoveReq; char request_buf[MSGSIZE]; char *reply_buf; XDR xdrs; mbdReqType mbdReqtype; int cc; struct LSFHeader hdr; struct lsfAuth auth; if (opCode != TO_TOP && opCode != TO_BOTTOM) { lsberrno = LSBE_BAD_ARG; return -1; } if (position == NULL ) { lsberrno = LSBE_BAD_ARG; return -1; } if (jobId <= 0 || *position <= 0) { lsberrno = LSBE_BAD_ARG; return -1; } if (authTicketTokens_(&auth, NULL) == -1) return -1; jobMoveReq.jobId = jobId; jobMoveReq.position = *position; jobMoveReq.opCode = opCode; mbdReqtype = BATCH_JOB_MOVE; xdrmem_create(&xdrs, request_buf, MSGSIZE, XDR_ENCODE); hdr.opCode = mbdReqtype; if (!xdr_encodeMsg(&xdrs, (char *) &jobMoveReq, &hdr, xdr_jobMoveReq, 0, &auth)) { xdr_destroy(&xdrs); lsberrno = LSBE_XDR; return -1; } if ((cc = callmbd (NULL, request_buf, XDR_GETPOS(&xdrs), &reply_buf, &hdr, NULL, NULL, NULL)) == -1) { xdr_destroy(&xdrs); return -1; } xdr_destroy(&xdrs); lsberrno = hdr.opCode; if (lsberrno == LSBE_NO_ERROR) { xdrmem_create(&xdrs, reply_buf, XDR_DECODE_SIZE_(cc), XDR_DECODE); if (!xdr_jobMoveReq(&xdrs, &jobMoveReq, &hdr)) { lsberrno = LSBE_XDR; xdr_destroy(&xdrs); if (cc) free(reply_buf); return -1; } *position = jobMoveReq.position ; xdr_destroy(&xdrs); if (cc) free(reply_buf); return 0; } if (cc) free(reply_buf); return -1; }