Exemplo n.º 1
0
void
pingReq(XDR *xdrs, struct sockaddr_in *from, struct LSFHeader *reqHdr)
{
    static char fname[] = "pingReq()";
    char buf[MSGSIZE/4];
    XDR  xdrs2;
    enum limReplyCode limReplyCode;
    struct LSFHeader replyHdr;

    limReplyCode = LIME_NO_ERR;
    replyHdr.opCode  = (short) limReplyCode;
    replyHdr.refCode = reqHdr->refCode;
    xdrmem_create(&xdrs2, buf, MSGSIZE/4, XDR_ENCODE);
    if (!xdr_LSFHeader(&xdrs2, &replyHdr) ||
        !xdr_string(&xdrs2, &myHostPtr->hostName, MAXHOSTNAMELEN)) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_string");
        xdr_destroy(&xdrs2);
        return;
    }

    if (chanSendDgram_(limSock, buf, XDR_GETPOS(&xdrs2), from) < 0) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "chanSendDgram_",
                  sockAdd2Str_(from));
        xdr_destroy(&xdrs2);
        return;
    }
    xdr_destroy(&xdrs2);
    return;

}
Exemplo n.º 2
0
void
clusNameReq(XDR *xdrs, struct sockaddr_in *from, struct LSFHeader *reqHdr)
{
    XDR    xdrs2;
    static char buf[MSGSIZE];
    enum limReplyCode limReplyCode;
    char *sp;
    struct LSFHeader replyHdr;

    memset(&buf, 0, sizeof(buf));

    initLSFHeader_(&replyHdr);

    limReplyCode = LIME_NO_ERR;
    replyHdr.opCode  = (short) limReplyCode;
    replyHdr.refCode = reqHdr->refCode;

    /* send back my cluster name
     */
    sp = myClusterPtr->clName;

    xdrmem_create(&xdrs2, buf, MSGSIZE, XDR_ENCODE);

    if (!xdr_LSFHeader(&xdrs2, &replyHdr)
        || !xdr_string(&xdrs2, &sp, MAXLSFNAMELEN)) {
        ls_syslog(LOG_ERR, "\
%s: failed decoding message from %s", __func__, sockAdd2Str_(from));
        xdr_destroy(&xdrs2);
        return;
    }
Exemplo n.º 3
0
static int
replyHdrWithRC(int rc, int chfd, int jobId)
{
    XDR                     xdrs2;
    char                    reply_buf[MSGSIZE];
    static char             fname[] = "replyHdrWithRC";
    struct LSFHeader        replyHdr;

    xdrmem_create(&xdrs2, reply_buf, MSGSIZE, XDR_ENCODE);
    replyHdr.opCode = rc;
    replyHdr.length = 0;

    if (!xdr_LSFHeader(&xdrs2, &replyHdr)) {
	ls_syslog(LOG_ERR, "%s: xdr_LSFHeader() failed for job <%d>", fname,
		  jobId);
	xdr_destroy(&xdrs2);
	return -1;
    }

    if (chanWrite_(chfd, reply_buf, XDR_GETPOS(&xdrs2)) <= 0) {
        ls_syslog(LOG_ERR, "%s: chanWrite_(%d) failed for job <%d>: %m",
		  fname, XDR_GETPOS(&xdrs2), jobId);
	xdr_destroy(&xdrs2);
	return -1;
    }
    xdr_destroy(&xdrs2);
    return 0;
}				/* replyHdrWithRC */
Exemplo n.º 4
0
/* 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;
}
Exemplo n.º 5
0
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);
    }

}
Exemplo n.º 6
0
void
clusInfoReq(XDR *xdrs, struct sockaddr_in *from, struct LSFHeader *reqHdr)
{
    static char fname[] = "clusInfoReq()";
    XDR    xdrs2;
    char buf[MSGSIZE*2];
    enum limReplyCode limReplyCode;
    struct LSFHeader replyHdr;
    struct clusterInfoReply clusterInfoReply;
    struct clusterInfoReq clusterInfoReq;

    limReplyCode = LIME_NO_ERR;
    clusterInfoReply.clusterMatrix = NULL;

    memset(&clusterInfoReq, 0, sizeof(clusterInfoReq));
    if (!xdr_clusterInfoReq(xdrs, &clusterInfoReq, reqHdr)) {
        ls_syslog(LOG_WARNING, I18N_FUNC_FAIL, fname, "xdr_clusterInfoReq");
        limReplyCode = LIME_BAD_DATA;
        goto Reply1;
    }

    if (!masterMe && clusterInfoReq.options == FROM_MASTER){
        wrongMaster(from, buf, reqHdr, -1);
        if (clusterInfoReq.resReq)
            FREEUP(clusterInfoReq.resReq);
        return;
    }

    clusterInfoReply.shortLsInfo = getCShortInfo (reqHdr);

    clusterInfoReply.nClus = 1;
    clusterInfoReply.clusterMatrix = malloc(sizeof (struct shortCInfo));
    if (clusterInfoReply.clusterMatrix == NULL) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL_M, fname, "malloc");
        limReplyCode = LIME_NO_MEM;
        goto Reply;
    }

    {
        strcpy(clusterInfoReply.clusterMatrix[0].clName,
               myClusterPtr->clName);
        if ((myClusterPtr->status & CLUST_INFO_AVAIL) &&
            (masterMe || (!masterMe && myClusterPtr->masterPtr != NULL))) {
            clusterInfoReply.clusterMatrix[0].status = CLUST_STAT_OK;
            strcpy(clusterInfoReply.clusterMatrix[0].masterName,
                   myClusterPtr->masterPtr->hostName);

            strcpy(clusterInfoReply.clusterMatrix[0].managerName,
                   myClusterPtr->managerName);

            clusterInfoReply.clusterMatrix[0].managerId
                = myClusterPtr->managerId;
            clusterInfoReply.clusterMatrix[0].numServers
                = myClusterPtr->numHosts;
            clusterInfoReply.clusterMatrix[0].numClients
                = myClusterPtr->numClients;
            clusterInfoReply.clusterMatrix[0].resClass
                = myClusterPtr->resClass;
            clusterInfoReply.clusterMatrix[0].typeClass
                = myClusterPtr->typeClass;
            clusterInfoReply.clusterMatrix[0].modelClass
                = myClusterPtr->modelClass;
            clusterInfoReply.clusterMatrix[0].numIndx
                = myClusterPtr->numIndx;
            clusterInfoReply.clusterMatrix[0].numUsrIndx
                = myClusterPtr->numUsrIndx;
            clusterInfoReply.clusterMatrix[0].usrIndxClass
                = myClusterPtr->usrIndxClass;
            clusterInfoReply.clusterMatrix[0].nAdmins
                = myClusterPtr->nAdmins;
            clusterInfoReply.clusterMatrix[0].adminIds
                = myClusterPtr->adminIds;
            clusterInfoReply.clusterMatrix[0].admins
                = myClusterPtr->admins;
            if (reqHdr->version < 4) {
                clusterInfoReply.clusterMatrix[0].nRes = 0;
            } else {
                clusterInfoReply.clusterMatrix[0].nRes
                    = allInfo.nRes;
                clusterInfoReply.clusterMatrix[0].resBitMaps
                    = myClusterPtr->resBitMaps;
            }
            clusterInfoReply.clusterMatrix[0].nTypes = allInfo.nTypes;
            clusterInfoReply.clusterMatrix[0].hostTypeBitMaps =
                myClusterPtr->hostTypeBitMaps;
            clusterInfoReply.clusterMatrix[0].nModels = allInfo.nModels;
            clusterInfoReply.clusterMatrix[0].hostModelBitMaps =
                myClusterPtr->hostModelBitMaps;

            if (logclass & (LC_TRACE | LC_COMM))
                ls_syslog(LOG_DEBUG1, "clusterInfo:clusterInfoReply.clusterMatrix[%d].nRes=%d, name=%s", 0, clusterInfoReply.clusterMatrix[0].nRes, clusterInfoReply.clusterMatrix[0].masterName);
        } else {
            clusterInfoReply.clusterMatrix[0].status = CLUST_STAT_UNAVAIL;
            clusterInfoReply.clusterMatrix[0].masterName[0] = '\0';
            clusterInfoReply.clusterMatrix[0].managerName[0] = '\0';
            clusterInfoReply.clusterMatrix[0].managerId  = 0;
            clusterInfoReply.clusterMatrix[0].numServers = 0;
            clusterInfoReply.clusterMatrix[0].numClients = 0;
            clusterInfoReply.clusterMatrix[0].resClass  = 0;
            clusterInfoReply.clusterMatrix[0].typeClass = 0;
            clusterInfoReply.clusterMatrix[0].modelClass  = 0;
            clusterInfoReply.clusterMatrix[0].numIndx =0;
            clusterInfoReply.clusterMatrix[0].numUsrIndx  = 0;
            clusterInfoReply.clusterMatrix[0].usrIndxClass  = 0;
            clusterInfoReply.clusterMatrix[0].nAdmins =   0;
            clusterInfoReply.clusterMatrix[0].nRes =   0;
            clusterInfoReply.clusterMatrix[0].nTypes = 0;
            clusterInfoReply.clusterMatrix[0].nModels = 0;
        }
    }

Reply:
    free(clusterInfoReq.resReq);

Reply1:
    initLSFHeader_(&replyHdr);
    replyHdr.opCode  = (short) limReplyCode;
    replyHdr.refCode = reqHdr->refCode;

    xdrmem_create(&xdrs2, buf, MSGSIZE*2, XDR_ENCODE);
    if (!xdr_LSFHeader(&xdrs2, &replyHdr)) {
        ls_syslog(LOG_ERR, I18N_FUNC_FAIL, fname, "xdr_LSFHeader");
        if (clusterInfoReply.clusterMatrix != NULL)
            free(clusterInfoReply.clusterMatrix);
        xdr_destroy(&xdrs2);
        return;
    }

    if (limReplyCode == LIME_NO_ERR) {
        if (!xdr_clusterInfoReply(&xdrs2, &clusterInfoReply, &replyHdr)) {
            ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL, fname, "xdr_clusterInfoReply");
            xdr_destroy(&xdrs2);
            if (clusterInfoReply.clusterMatrix != NULL)
                free(clusterInfoReply.clusterMatrix);
            return;
        }
    }

    if (chanSendDgram_(limSock, buf, XDR_GETPOS(&xdrs2), from) < 0) {
        ls_syslog(LOG_ERR, I18N_FUNC_S_FAIL_M, fname, "chanSendDgram_",
                  sockAdd2Str_(from));
        xdr_destroy(&xdrs2);
        if (clusterInfoReply.clusterMatrix != NULL)
            free(clusterInfoReply.clusterMatrix);
        return;
    }

    if (clusterInfoReply.clusterMatrix != NULL)
        free(clusterInfoReply.clusterMatrix);

    xdr_destroy(&xdrs2);
    return;

}
Exemplo n.º 7
0
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;

}