Example #1
0
static int
getname_ (enum limReqCode limReqCode, char *name, int namesize)
{
    int options;

    if (initenv_ (NULL, NULL) < 0)
        return (-1);

    if (limReqCode == LIM_GET_CLUSNAME)
    {
        struct stringLen str;
        str.name = name;
        str.len = namesize;
        if (callLim_ (limReqCode,
                      NULL, NULL, &str, xdr_stringLen, NULL, _LOCAL_, NULL) < 0)
            return -1;
        return 0;
    }

    /* Force the library not to call _LOCAL_ LIM since
     * it may not know the master yet, this is the
     * case of LIM_ADD_HOST.
     */
    if (limReqCode == LIM_GET_MASTINFO2)
        options = _SERVER_HOSTS_ONLY_;
    else
        options = _LOCAL_;

    if (callLim_ (limReqCode, NULL,	/* no data to send */
                  NULL, &masterInfo_, xdr_masterInfo, NULL,	/* host LSF_SERVER_HOSTS */
                  options, NULL) < 0)
        return (-1);

    if (memcmp (&sockIds_[MASTER].sin_addr,
                &masterInfo_.addr, sizeof (in_addr_t)))
    {
        CLOSECD (limchans_[MASTER]);
        CLOSECD (limchans_[TCP]);
    }

    memcpy (&sockIds_[MASTER].sin_addr, &masterInfo_.addr, sizeof (in_addr_t));
    memcpy (&sockIds_[TCP].sin_addr, &masterInfo_.addr, sizeof (in_addr_t));
    sockIds_[TCP].sin_port = masterInfo_.portno;
    masterknown_ = TRUE;
    strncpy (name, masterInfo_.hostName, namesize);
    name[namesize - 1] = '\0';

    return 0;
}
Example #2
0
int
ls_loadadj(char *resreq, struct placeInfo *placeinfo, int listsize)
{
    struct jobXfer loadadjReq;
    int i;
    
    if(listsize <= 0 || placeinfo == NULL) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    loadadjReq.numHosts = listsize;
    loadadjReq.placeInfo = placeinfo;
    for (i = 0; i < listsize; i++) {
        if (Gethostbyname_(placeinfo[i].hostName) == NULL) {
            return -1;
        }
        strcpy(placeinfo[i].hostName, placeinfo[i].hostName);

        if (placeinfo[i].numtask < 0)
            placeinfo[i].numtask = 0;
    }

    if(resreq != NULL) {
        strcpy(loadadjReq.resReq, resreq);
    } else
        loadadjReq.resReq[0] = '\0';

    if (callLim_(LIM_LOAD_ADJ, &loadadjReq, xdr_jobXfer, NULL, NULL,
	      NULL, _USE_TCP_, NULL) < 0)
	return (-1);

    return (0);

} 
Example #3
0
struct clusterInfo *
ls_clusterinfo (char *resReq, int *numclusters, char **clusterList,
                int listsize, int options)
{
    struct clusterInfoReq clusterInfoReq;
    static struct clusterInfoReply clusterInfoReply;
    struct shortLsInfo shortlsInfo;
    int count, ret_val;

    if (listsize != 0 && clusterList == NULL)
    {
        lserrno = LSE_BAD_ARGS;
        return NULL;
    }

    if (initenv_ (NULL, NULL) < 0)
        return (NULL);

    for (count = 0; count < listsize; count++)
    {
        ret_val = ls_isclustername (clusterList[count]);
        if (ret_val <= 0)
        {
            if (ret_val < 0)
            {
                return (NULL);
            }

            lserrno = LSE_BAD_CLUSTER;
            return (NULL);
        }
    }

    if (resReq)
        clusterInfoReq.resReq = resReq;
    else
        clusterInfoReq.resReq = "";

    clusterInfoReq.clusters = clusterList;
    clusterInfoReq.listsize = listsize;
    clusterInfoReq.options = options;

    clusterInfoReply.shortLsInfo = &shortlsInfo;
    if (callLim_ (LIM_GET_CLUSINFO, &clusterInfoReq, xdr_clusterInfoReq,
                  &clusterInfoReply, xdr_clusterInfoReply, NULL, 0, NULL) < 0)
        return (NULL);

    if (numclusters != NULL)
        *numclusters = clusterInfoReply.nClus;
    return (expandSCinfo (&clusterInfoReply));

}
Example #4
0
struct lsInfo *
ls_info (void)
{
    static struct lsInfo lsInfo;

    if (initenv_ (NULL, NULL) < 0)
        return NULL;

    if (callLim_ (LIM_GET_INFO,
                  NULL, NULL, &lsInfo, xdr_lsInfo, NULL, _USE_TCP_, NULL) < 0)
        return NULL;

    return &lsInfo;
}
Example #5
0
float *
ls_getmodelfactor (char *modelname)
{
    static float cpuf;
    struct stringLen str;

    if (!modelname)
        return (ls_gethostfactor (NULL));

    if (initenv_ (NULL, NULL) < 0)
        return (NULL);

    str.name = modelname;
    str.len = MAXLSFNAMELEN;
    if (callLim_ (LIM_GET_CPUF, &str, xdr_stringLen, &cpuf, xdr_float,
                  NULL, 0, NULL) < 0)
        return (NULL);

    return (&cpuf);

}
Example #6
0
/* ls_deletelock()
 */
int
ls_deletelock(struct lsLockRequest *r)
{
    if (r == NULL
        || r->name == NULL) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    if (callLim_(LIM_DEL_LOCK,
                 r,
                 xdr_requestlock,
                 NULL,
                 NULL,
                 NULL,
                 _USE_TCP_,
                 NULL) < 0)
        return -1;

    return 0;
}
Example #7
0
int
expSyntax_ (char *resReq)
{
  struct stringLen str;

  if (initenv_ (NULL, NULL) < 0)
    return (-1);

  if (!resReq)
    resReq = " ";

  str.name = resReq;
  str.len = MAXLINELEN;

  if (callLim_ (LIM_CHK_RESREQ, &str, xdr_stringLen,
		NULL, NULL, NULL, 0, NULL) < 0)
    return (-1);

  return 0;

}
Example #8
0
int
setLockOnOff_(int on, time_t duration, char *hname)
{
    struct limLock lockReq;
    char *host = hname;

    if (initenv_(NULL, NULL) <0)
        return -1;

    lockReq.on = on;

    lockReq.uid = getuid();

    if (getLSFUser_(lockReq.lsfUserName, sizeof(lockReq.lsfUserName)) < 0) {
        return -1;
    }

    if (duration == 0)
        lockReq.time = 77760000;
    else
        lockReq.time = duration;

    if (host == NULL)
        host = ls_getmyhostname();

    if (callLim_(LIM_LOCK_HOST,
                 &lockReq,
                 xdr_limLock,
                 NULL,
                 NULL,
                 host,
                 0,
                 NULL) < 0)
        return -1;

    return 0;

}
Example #9
0
int
oneLimDebug(struct debugReq *pdebug, char *hostname)
{
    struct debugReq debugData;
    char *host = hostname;
    char space[ ]=" ";
    enum limReqCode limReqCode;

    limReqCode = LIM_DEBUGREQ;
    debugData.opCode = pdebug->opCode;
    debugData.logClass = pdebug->logClass;
    debugData.level    = pdebug->level;
    debugData.hostName = space;
    debugData.options  = pdebug->options;
    strcpy (debugData.logFileName, pdebug->logFileName);

    if (callLim_(limReqCode, &debugData, xdr_debugReq, NULL,
                 NULL, host, 0, NULL) < 0)
        return (-1);

    return (0);

}
Example #10
0
int
ls_limcontrol(char *hname, int opCode)
{
    enum limReqCode limReqCode;
    struct lsfAuth auth;

    memset(&auth, 0, sizeof(struct lsfAuth));

    switch (opCode) {
        case LIM_CMD_SHUTDOWN:
            limReqCode = LIM_SHUTDOWN;
            break;
        case LIM_CMD_REBOOT:
            limReqCode = LIM_REBOOT;
            break;
        default:
            lserrno = LSE_BAD_OPCODE;
            return -1;
    }

    putEauthClientEnvVar("user");
    putEauthServerEnvVar("lim");
    getAuth_(&auth, hname);

    if (callLim_(limReqCode,
                 &auth,
                 xdr_lsfAuth,
                 NULL,
                 NULL,
                 hname,
                 0,
                 NULL) < 0)
        return -1;

    return 0;

}
Example #11
0
/* ls_createlock()
 */
int
ls_createlock(struct lsLock *ls)
{
    struct LSFHeader hdr;

    if (ls == NULL
        || ls->name == NULL) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    if (callLim_(LIM_MK_LOCK,
                 ls,
                 xdr_createlock,
                 NULL,
                 NULL,
                 NULL,
                 _USE_TCP_,
                 &hdr) < 0) {
        return -1;
    }

    return 0;
}
Example #12
0
int
ls_servavail(int servId, int nonblock)
{
    int options = 0;

    if (nonblock)
        options |= _NON_BLOCK_;

    if (initenv_(NULL, NULL) < 0)
        return -1;

    if (callLim_(LIM_SERV_AVAIL,
                 &servId,
                 xdr_int,
                 NULL,
                 NULL,
                 ls_getmyhostname(),
                 options,
                 NULL) < 0)
        return -1;

    return 0;

}
Example #13
0
/* ls_getlock()
 */
int
ls_getlock(struct lsLockRequest *r)
{
    struct LSFHeader hdr;

    if (r == NULL
        || r->name == NULL) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    if (callLim_(LIM_GET_LOCK,
                 r,
                 xdr_requestlock,
                 NULL,
                 NULL,
                 NULL,
                 _USE_TCP_,
                 &hdr) < 0) {
        return -1;
    }

    return 0;
}
Example #14
0
/* ls_loackstatus()
 */
int
ls_lockstatus(struct lsLockRequest *ls,
              struct lsLockStatus *s)
{
    if (ls == NULL
        || ls->name == NULL
        || s == NULL) {
        lserrno = LSE_BAD_ARGS;
        return -1;
    }

    if (callLim_(LIM_LOCK_STATUS,
                 ls,
                 xdr_statuslock,
                 NULL,
                 NULL,
                 NULL,
                 _USE_TCP_,
                 NULL) < 0) {
        return -1;
    }

    return 0;
}
Example #15
0
struct hostInfo *
ls_gethostinfo (char *resReq, int *numhosts, char **hostlist, int listsize,
                int options)
{
    static char fname[] = "ls_gethostinfo";
    struct decisionReq hostInfoReq;
    static struct hostInfoReply hostInfoReply;
    struct shortLsInfo lsInfo;
    char *hname;
    int cc, i;

    if (logclass & (LC_TRACE))
        ls_syslog (LOG_DEBUG1, "%s: Entering this routine...", fname);

    if ((hname = ls_getmyhostname ()) == NULL)
        return (NULL);

    if (listsize)
    {
        if (hostlist == NULL)
        {
            lserrno = LSE_BAD_ARGS;
            return NULL;
        }
        hostInfoReq.preferredHosts = (char **)
                                     calloc (listsize + 1, sizeof (char *));
        if (hostInfoReq.preferredHosts == NULL)
        {
            lserrno = LSE_MALLOC;
            return NULL;
        }
        for (i = 0; i < listsize; i++)
        {
            if (hostlist[i] == NULL)
            {
                lserrno = LSE_BAD_ARGS;
                break;
            }

            cc = ls_isclustername (hostlist[i]);
            if (cc <= 0)
            {
                if (cc < 0)
                    break;
                if (Gethostbyname_ (hostlist[i]) == NULL)
                {
                    lserrno = LSE_BAD_HOST;
                    break;
                }
                hostInfoReq.preferredHosts[i + 1] = putstr_ (hostlist[i]);
            }
            else
                hostInfoReq.preferredHosts[i + 1] = putstr_ (hostlist[i]);

            if (!hostInfoReq.preferredHosts[i + 1])
            {
                lserrno = LSE_MALLOC;
                break;
            }
        }
        if (i < listsize)
        {
            int j;
            for (j = 1; j < i + 1; j++)
                free (hostInfoReq.preferredHosts[j]);
            free (hostInfoReq.preferredHosts);
            return (NULL);
        }
        hostInfoReq.ofWhat = OF_HOSTS;
    }
    else
    {
        hostInfoReq.preferredHosts = (char **) calloc (1, sizeof (char *));
        if (hostInfoReq.preferredHosts == NULL)
        {
            lserrno = LSE_MALLOC;
            return NULL;
        }
        hostInfoReq.ofWhat = OF_ANY;
    }
    hostInfoReq.options = options;
    strcpy (hostInfoReq.hostType, " ");

    hostInfoReq.preferredHosts[0] = putstr_ (hname);
    hostInfoReq.numPrefs = listsize + 1;

    if (resReq != NULL)
        strcpy (hostInfoReq.resReq, resReq);
    else
        strcpy (hostInfoReq.resReq, " ");

    hostInfoReply.shortLsInfo = &lsInfo;
    hostInfoReq.numHosts = 0;
    cc = callLim_ (LIM_GET_HOSTINFO,
                   &hostInfoReq,
                   xdr_decisionReq,
                   &hostInfoReply, xdr_hostInfoReply, NULL, _USE_TCP_, NULL);

    for (i = 0; i < hostInfoReq.numPrefs; i++)
        free (hostInfoReq.preferredHosts[i]);
    free (hostInfoReq.preferredHosts);
    if (cc < 0)
        return NULL;

    if (numhosts != NULL)
        *numhosts = hostInfoReply.nHost;
    return (expandSHinfo (&hostInfoReply));

}
Example #16
0
struct hostLoad *
loadinfo_(char *resReq, struct decisionReq *loadReqPtr, char *fromhost, int *numHosts, char ***outnlist)
{
    static char fname[] = "loadinfo_";
    static struct loadReply loadReply;
    int i;
    char *hname;
    int options = 0;

    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname);

    if (loadReqPtr->numHosts <=0) {
        lserrno = LSE_BAD_ARGS;
	goto error;
    }

    if (!fromhost) {
	if ((hname = ls_getmyhostname()) == NULL)
	    goto error;
        loadReqPtr->preferredHosts[0] = putstr_(hname);
    } else 
        loadReqPtr->preferredHosts[0] = putstr_(fromhost);

    if (loadReqPtr->preferredHosts[0] == NULL) {
	lserrno = LSE_MALLOC;
	goto error;
    }
	
    if (resReq) {
        strncpy(loadReqPtr->resReq, resReq, MAXLINELEN);
    } else
        strcpy(loadReqPtr->resReq, " ");

    loadReqPtr->resReq[MAXLINELEN-1] = '\0';
    if (loadReqPtr->ofWhat == OF_HOSTS && loadReqPtr->numPrefs == 2
	 && loadReqPtr->numHosts == 1 
	 && equalHost_(loadReqPtr->preferredHosts[1], 
	 loadReqPtr->preferredHosts[0]))
        options |= _LOCAL_;
    else
	options |= _USE_TCP_;

    if (callLim_(LIM_LOAD_REQ, loadReqPtr, xdr_decisionReq, 
	    &loadReply, xdr_loadReply, NULL, options, NULL) < 0)
	goto error;
    if (loadReply.flags & LOAD_REPLY_SHARED_RESOURCE) {
        sharedResConfigured_ = TRUE;
    }
    for (i=0; i<loadReqPtr->numPrefs; i++) 
	FREEUP(loadReqPtr->preferredHosts[i]);
    FREEUP (loadReqPtr->preferredHosts);
    *numHosts = loadReply.nEntry;
    *outnlist = loadReply.indicies;
    return (loadReply.loadMatrix);

error:
    for (i=0; i<loadReqPtr->numPrefs; i++) 
	FREEUP(loadReqPtr->preferredHosts[i]);
    FREEUP (loadReqPtr->preferredHosts);
    return (NULL);

} 
Example #17
0
struct lsSharedResourceInfo *
ls_sharedresourceinfo (char **resources, int *numResources, char *hostName,
                       int options)
{
    static char fname[] = "ls_sharedresourceinfo";
    static struct resourceInfoReq resourceInfoReq;
    int cc, i;
    static struct resourceInfoReply resourceInfoReply;
    static struct LSFHeader replyHdr;
    static int first = TRUE;

    if (logclass & (LC_TRACE))
        ls_syslog (LOG_DEBUG1, "%s: Entering this routine...", fname);

    if (first == TRUE)
    {
        resourceInfoReply.numResources = 0;
        resourceInfoReq.resourceNames = NULL;
        resourceInfoReq.numResourceNames = 0;
        resourceInfoReq.hostName = NULL;
        first = FALSE;
    }

    if (resourceInfoReply.numResources > 0)
        xdr_lsffree (xdr_resourceInfoReply, (char *) &resourceInfoReply,
                     &replyHdr);
    FREEUP (resourceInfoReq.resourceNames);
    FREEUP (resourceInfoReq.hostName);

    if (numResources == NULL || *numResources < 0
            || (resources == NULL && *numResources > 0))
    {
        lserrno = LSE_BAD_ARGS;
        return (NULL);
    }
    if (*numResources == 0 && resources == NULL)
    {
        if ((resourceInfoReq.resourceNames =
                    (char **) malloc (sizeof (char *))) == NULL)
        {
            lserrno = LSE_MALLOC;
            return (NULL);
        }
        resourceInfoReq.resourceNames[0] = "";
        resourceInfoReq.numResourceNames = 1;
    }
    else
    {
        if ((resourceInfoReq.resourceNames =
                    (char **) malloc (*numResources * sizeof (char *))) == NULL)
        {
            lserrno = LSE_MALLOC;
            return (NULL);
        }
        for (i = 0; i < *numResources; i++)
        {
            if (resources[i] && strlen (resources[i]) + 1 < MAXLSFNAMELEN)
                resourceInfoReq.resourceNames[i] = resources[i];
            else
            {
                FREEUP (resourceInfoReq.resourceNames);
                lserrno = LSE_BAD_RESOURCE;
                *numResources = i;
                return (NULL);
            }
            resourceInfoReq.numResourceNames = *numResources;
        }
    }
    if (hostName != NULL)
    {
        if (strlen (hostName) > MAXHOSTNAMELEN - 1
                || Gethostbyname_ (hostName) == NULL)
        {
            lserrno = LSE_BAD_HOST;
            return (NULL);
        }
        resourceInfoReq.hostName = putstr_ (hostName);
    }
    else
        resourceInfoReq.hostName = putstr_ (" ");


    if (resourceInfoReq.hostName == NULL)
    {
        lserrno = LSE_MALLOC;
        return (NULL);
    }
    cc = callLim_ (LIM_GET_RESOUINFO, &resourceInfoReq, xdr_resourceInfoReq,
                   &resourceInfoReply, xdr_resourceInfoReply, NULL, _USE_TCP_,
                   &replyHdr);
    if (cc < 0)
    {
        return NULL;
    }

    *numResources = resourceInfoReply.numResources;
    return (resourceInfoReply.resources);

}