示例#1
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));

}
示例#2
0
struct hostLoad *
ls_loadinfo(char *resreq,
            int *numhosts,
            int options,
            char *fromhost,
            char **hostlist,
            int listsize,
            char ***indxnamelist)
{
    static char fname[] = "ls_loadinfo";
    struct decisionReq loadReq;
    char *indexfilter;
    int i, j, *num;
    int one = 1;  
    char  tempresreq[MAXLINELEN];
    int isClus;

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

    if (!indxnamelist) {
        lserrno = LSE_BAD_ARGS;
        return(NULL);
    }
    if (hostlist && listsize)
        loadReq.ofWhat = OF_HOSTS;
    else
        loadReq.ofWhat = OF_ANY;

    loadReq.options = options;
    strcpy(loadReq.hostType, " ");          

    if (numhosts == 0)
        num = &one;
    else
        num = numhosts;

    loadReq.numHosts = *num;

    if (! *num) {
        if (loadReq.ofWhat == OF_HOSTS)
            loadReq.numHosts = listsize;
        else
            loadReq.numHosts = 9999;
        loadReq.options &= ~EXACT;
    }     

    if (loadReq.ofWhat == OF_HOSTS) { 		
        char clusterinlist=0;

        loadReq.numPrefs = listsize + 1;
        loadReq.preferredHosts = calloc(loadReq.numPrefs, sizeof (char *));
        if (loadReq.preferredHosts == NULL) {
            lserrno = LSE_MALLOC;
            return (NULL);
        }

        for (i=1; i<loadReq.numPrefs; i++) {
            if ( (isClus = ls_isclustername(hostlist[i-1])) < 0 ) {
		break;
	    } else if (isClus == 0) {
                if ((Gethostbyname_(hostlist[i - 1])) == NULL) {
                    lserrno = LSE_BAD_HOST;
                    break;
                }
                loadReq.preferredHosts[i] = putstr_(hostlist[i - 1]);
            } else {
                
                loadReq.preferredHosts[i] = putstr_(hostlist[i-1]);
                clusterinlist = 1;
            }

            if (loadReq.preferredHosts[i] == NULL) {
                for (j=1; j<i; j++)
                    free(loadReq.preferredHosts[j]);
                lserrno = LSE_MALLOC;
                break;
            }
        }        

        if (i < loadReq.numPrefs) {
            for (j=1; j<i; j++)
                free(loadReq.preferredHosts[j]);
            free(loadReq.preferredHosts);
            return (NULL);
        }

        if (*num > listsize && (loadReq.options & EXACT) && !clusterinlist) {
            lserrno = LSE_NO_HOST;
            for (j=1; j<i; j++)
                free(loadReq.preferredHosts[j]);
            free(loadReq.preferredHosts);
            return (NULL);
        }

        
        if (clusterinlist && !*num) {
            loadReq.numHosts = 9999;
            loadReq.options &= ~EXACT;
        }

    } else {
        
        loadReq.numPrefs = 1;
        loadReq.preferredHosts = (char **)
                  calloc(loadReq.numPrefs, sizeof (char *));
        if (loadReq.preferredHosts == NULL) {
            lserrno = LSE_MALLOC;
            return (NULL);
        }        
    }
                                           
    if (*indxnamelist) {	
        indexfilter = namestofilter_(*indxnamelist);
        if (!indexfilter)
            return NULL; 
    } else			
        indexfilter = NULL;

    if (resreq && indexfilter) {
        if ((strlen(resreq) + strlen(indexfilter)) < MAXLINELEN - 8) {
           char tmp[MAXLINELEN/2];
           sprintf(tmp,"filter[%s]", indexfilter);
           strcpy(tempresreq, resreq);
           strcat(tempresreq, tmp);
           resreq = tempresreq;
        } else {
            lserrno = LSE_BAD_ARGS;
            return(NULL);
        }
    } else if (indexfilter) {
        sprintf(tempresreq,"filter[%s]",indexfilter); 
        resreq = tempresreq; 
    }

    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: loadReq.ofWhat=%d loadReq.numHosts=%d loadReq..numPrefs=%d", fname,loadReq.ofWhat, loadReq.numHosts,loadReq.numPrefs);

    return (loadinfo_(resreq, &loadReq, fromhost, num, indxnamelist));
 
} 
示例#3
0
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;
}
示例#4
0
static struct groupInfoEnt *
getGrpInfo(char **groups, int *numGroups, int options)
{
    int                            i;
    char *                         clusterName = NULL;
    static  struct groupInfoReply  reply;
    struct  infoReq                groupInfo;

    memset((struct infoReq *)&groupInfo, '\0', sizeof(struct infoReq));

    if (numGroups != NULL && *numGroups < 0) {
        lsberrno = LSBE_BAD_ARG;
        return NULL;
    }

    if (*numGroups < 0 || *numGroups > MAX_GROUPS) {
        lsberrno = LSBE_BAD_ARG;
        return NULL;
    }


    if (numGroups == NULL || *numGroups == 0 || groups == NULL) {

        options |= GRP_ALL;


        groupInfo.options = options;
        groupInfo.resReq = "";

    }
    else {


        for (i = 0; i < *numGroups; i++) {
            if (ls_isclustername(groups[i]) <= 0 || (options & USER_GRP))
                continue;

            options |= GRP_ALL;
            clusterName = groups[i];
        }


        if (clusterName == NULL) {
            groupInfo.options  = options;
            groupInfo.numNames = *numGroups;
            groupInfo.names    = groups;
            groupInfo.resReq   = "";
        } else {

            groupInfo.options  = options;
            groupInfo.numNames = 0;
            groupInfo.names    = NULL;
            groupInfo.resReq   = "";
        }

    }


    if (sendGrpReq(clusterName,
                   options,
                   &groupInfo,
                   &reply) < 0) {

        *numGroups = reply.numGroups;
        return NULL;
    }

    *numGroups = reply.numGroups;

    return(reply.groups);

}
示例#5
0
int
main(int argc, char **argv)
{
    static char fname[] = "lsload:main";
    int i,j, num, numneeded;
    char *resreq = NULL;
    struct hostLoad *hosts;
    char *hostnames[MAXLISTSIZE];
    char statusbuf[20];
    int options = 0;
    static char **loadval;
    char *indexfilter = NULL;
    char **nlp;
    static char *defaultindex[] = {"r15s", "r1m", "r15m", "ut", "pg", "ls",
                                   "it", "tmp", "swp", "mem", NULL};
    int	achar;
    char longFormat = FALSE;
    char wideFormat = FALSE;
    char badHost = FALSE, sOption = FALSE, otherOption = FALSE;
    int extView = FALSE;
    char **shareNames, **shareValues, **formats;
    int isClus, retVal = 0;
    int rc;

    num = 0;
    numneeded = 0;
    opterr = 0;

    rc = _i18n_init ( I18N_CAT_MIN );


    if (ls_initdebug(argv[0]) < 0) {
        ls_perror("ls_initdebug");
        exit(-1);
    }
    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname);


    for (i = 1; i < argc; i++) {
       if (strcmp(argv[i], "-h") == 0) {
           usage(argv[0]);
           exit (0);
       } else if (strcmp(argv[i], "-V") == 0) {
           fputs(_LS_VERSION_, stderr);
           exit(0);
       } else if (strcmp(argv[i], "-s") == 0) {
           if (otherOption == TRUE) {
               usage(argv[0]);
               exit(-1);
           }
           sOption = TRUE;
           optind = i + 1;
       } else if (strcmp(argv[i], "-e") == 0) {
           if (otherOption == TRUE || sOption == FALSE) {
               usage(argv[0]);
               exit(-1);
           }
           extView = TRUE;
           optind = i + 1;
       } else if (strcmp(argv[i], "-R") == 0 || strcmp(argv[i], "-l") == 0
                  || strcmp(argv[i], "-I") == 0 || strcmp(argv[i], "-N") == 0
                  || strcmp(argv[i], "-E") == 0 || strcmp(argv[i], "-n") == 0
		  || strcmp(argv[i], "-w") == 0 ) {
            otherOption = TRUE;
            if (sOption == TRUE) {
                usage(argv[0]);
                exit(-1);
            }
        }
    }

    if (sOption == TRUE) {
        displayShareResource(argc, argv, optind, FALSE, extView);
        return(0);
    }

    while ((achar = getopt(argc, argv, "R:I:NEln:w")) != EOF)
    {
	switch (achar)
	{
	case 'R':
            resreq = optarg;
            break;
	case 'I':
            indexfilter = optarg;
            break;

	case 'N':
	    if (options & EFFECTIVE)
		usage(argv[0]);
            options = NORMALIZE;
	    break;

        case 'E':
	    if (options & NORMALIZE)
		usage(argv[0]);
             options = EFFECTIVE;
	     break;
	case 'n':
            numneeded = atoi(optarg);
            if (numneeded <= 0)
                usage(argv[0]);
            break;

        case 'l':
	    longFormat = TRUE;
	    if (wideFormat == TRUE)
		usage(argv[0]);
	    break;

	case 'w':
	    wideFormat = TRUE;
	    if (longFormat == TRUE)
		usage(argv[0]);
	    break;

	case 'V':
	    fputs(_LS_VERSION_, stderr);
	    exit(0);

	case 'h':
	default:
            usage(argv[0]);

        }
    }

    for ( ; optind < argc ; optind++)
    {
        if (num>=MAXLISTSIZE) {
            fprintf(stderr, _i18n_msg_get(ls_catd,NL_SETN,1951, "too many hosts specified (maximum %d)\n"), /* catgets  1951  */
			MAXLISTSIZE);
            exit(-1);
        }
        if ( (isClus = ls_isclustername(argv[optind])) < 0 ) {
	    fprintf(stderr, "lsload: %s\n", ls_sysmsg());
            badHost = TRUE;
	    continue;
	} else if ( (isClus == 0) &&
		    (!Gethostbyname_(argv[optind])) ) {
	    fprintf(stderr, "\
%s: invalid hostname %s\n", __func__, argv[optind]);
            badHost = TRUE;
            continue;
	}
        hostnames[num] = argv[optind];
        num++;
    }
示例#6
0
int
main(int argc, char **argv)
{
    static char fname[] = "lsplace/main";
    char *resreq = NULL;
    char *hostnames[MAXLISTSIZE];
    char **desthosts;
    int cc = 0;
    int needed = 1;
    int wanted = 1;
    int i;
    char locality=FALSE;
    int	achar;
    char badHost = FALSE;
    int rc;

    rc = _i18n_init ( I18N_CAT_MIN );	

    if (ls_initdebug(argv[0]) < 0) {
        ls_perror("ls_initdebug");
        exit(-1);
    }
    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname); 

    opterr = 0;
    while ((achar = getopt(argc, argv, "VR:Lhn:w:")) != EOF)
    {
	switch (achar)
	{
	case 'L':
            locality=TRUE;
            break;

	case 'R':
            resreq = optarg;
            break;

        case 'n':		
            for (i = 0 ; optarg[i] ; i++) 
                if (! isdigit(optarg[i])) 
                    usage(argv[0]);
            needed = atoi(optarg);
            break;

        case 'w':		
            for (i = 0 ; optarg[i] ; i++) 
                if (! isdigit(optarg[i])) 
                    usage(argv[0]);
            wanted = atoi(optarg);
            break;

	case 'V':
	    fputs(_LS_VERSION_, stderr);
	    exit(0);

	case 'h':
	default:
            usage(argv[0]);
        }
    }

    for ( ; optind < argc ; optind++)
    {
        if (cc>=MAXLISTSIZE) {
            fprintf(stderr, 
		_i18n_msg_get(ls_catd,NL_SETN,2201, "%s: too many hosts specified (max %d)\n"), /* catgets  2201  */
		argv[0], MAXLISTSIZE);
            exit(-1);
        }

        if (ls_isclustername(argv[optind]) <= 0
            && !Gethostbyname_(argv[optind])) {
            fprintf(stderr, "\
%s: invalid hostname %s\n", argv[0], argv[optind]);
            badHost = TRUE;
            continue;
        }
        hostnames[cc] = argv[optind];
        cc++;
    }
示例#7
0
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);

} 
示例#8
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));

}
示例#9
0
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);
} 
示例#10
0
int
main(int argc, char **argv)
{
    static char fname[] = "lshosts/main";
    char   *namebufs[256];
    struct hostInfo *hostinfo;
    int    numhosts = 0;
    struct hostent *hp;
    int    i, j;
    char   *resReq = NULL;
    char   longformat = FALSE;
    char   longname = FALSE;
    char   staticResource = FALSE, otherOption = FALSE;
    int extView = FALSE;
    int achar;
    int     unknown;
    int     options=0;
    int isClus;
    int rc;


    rc = _i18n_init ( I18N_CAT_MIN );

    if (ls_initdebug(argv[0]) < 0) {
        ls_perror("ls_initdebug");
        exit(-1);
    }
    if (logclass & (LC_TRACE))
        ls_syslog(LOG_DEBUG, "%s: Entering this routine...", fname);

    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "-h") == 0) {
            usage(argv[0]);
            exit (0);
        } else if (strcmp(argv[i], "-V") == 0) {
            fputs(_LS_VERSION_, stderr);
            exit(0);
        } else if (strcmp(argv[i], "-s") == 0) {
            if (otherOption == TRUE) {
                usage(argv[0]);
                exit(-1);
            }
            staticResource = TRUE;
            optind = i + 1;
        } else if (strcmp(argv[i], "-e") == 0) {
            if (otherOption == TRUE || staticResource == FALSE) {
                usage(argv[0]);
                exit(-1);
            }
            optind = i + 1;
            extView = TRUE;
        } else if (strcmp(argv[i], "-R") == 0 || strcmp(argv[i], "-l") == 0
                  || strcmp(argv[i], "-w") == 0) {
            otherOption = TRUE;
            if (staticResource == TRUE) {
                usage(argv[0]);
                exit(-1);
            }
        }
    }

    if (staticResource == TRUE) {
        displayShareResource(argc, argv, optind, TRUE, extView );
    } else {
        while ((achar = getopt(argc, argv, "R:lw")) != EOF) {
 	    switch (achar) {
            case 'R':
	        if (strlen(optarg) > MAXLINELEN) {
                        printf(" %s", I18N(1645, "The resource requirement string exceeds the maximum length of 512 characters. Specify a shorter resource requirement.\n")); /* catgets  1645  */
		        exit (-1);
	        }
	        resReq = optarg;
	        break;
            case 'l':
	        longformat = TRUE;
	        break;
            case 'w':
	        longname = TRUE;
	        break;
            default:
	        usage(argv[0]);
	        exit(-1);
	    }
        }

        i=0;
        unknown = 0;
        for ( ; optind < argc ; optind++) {
    	    if (strcmp(argv[optind],"allclusters") == 0) {
	        options = ALL_CLUSTERS;
	        i = 0;
                break;
            }
            if ( (isClus = ls_isclustername(argv[optind])) < 0 ) {
	        fprintf(stderr, "lshosts: %s\n", ls_sysmsg());
                unknown = 1;
                continue;
            } else if ((isClus == 0) &&
                       ((hp = Gethostbyname_(argv[optind])) == NULL)) {
                fprintf(stderr, "\
%s: gethostbyname() failed for host %s.\n", __func__, argv[optind]);
                unknown = 1;
                continue;
            }
            namebufs[i] = strdup(hp->h_name);
            if (namebufs[i] == NULL) {
                perror("strdup()");
                exit(-1);
            }
            i++;
        }

        if (i == 0 && unknown == 1)
            exit(-1);

        if (i == 0) {
            TIMEIT(0, (hostinfo = ls_gethostinfo(resReq, &numhosts, NULL, 0,
                                                 options)), "ls_gethostinfo");
            if (hostinfo == NULL) {
                ls_perror("ls_gethostinfo()");
                exit(-1);
            }
        } else {
    	    TIMEIT(0, (hostinfo = ls_gethostinfo(resReq, &numhosts, namebufs,
                                                 i, 0)), "ls_gethostinfo");
	    if (hostinfo == NULL) {
	        ls_perror("ls_gethostinfo");
	        exit(-1);
	    }
        }

        if (!longformat && !longname) {
	    char *buf1, *buf2, *buf3, *buf4, *buf5;
	    char *buf6, *buf7, *buf8, *buf9;

	    buf1 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1628, "HOST_NAME")); /* catgets 1628 */
	    buf2 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1602, "type")); /* catgets  1602  */
	    buf3 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1603, "model")); /* catgets  1603  */
	    buf4 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1604, "cpuf")); /* catgets  1604 */
	    buf5 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1605, "ncpus")); /* catgets  1605  */
	    buf6 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1607, "maxmem")); /* catgets  1607  */
	    buf7 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1608, "maxswp")); /* catgets  1608  */
	    buf8 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1611, "server")); /* catgets  1611  */
	    buf9 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1614, "RESOURCES")); /* catgets  1614  */

            printf("%-11.11s %7.7s %8.8s %5.5s %5.5s %6.6s %6.6s %6.6s %9.9s\n",
		buf1, buf2, buf3, buf4, buf5, buf6, buf7, buf8, buf9);

	    FREEUP(buf1);
	    FREEUP(buf2);
	    FREEUP(buf3);
	    FREEUP(buf4);
	    FREEUP(buf5);
	    FREEUP(buf6);
	    FREEUP(buf7);
	    FREEUP(buf8);
	    FREEUP(buf9);

        } else if (longname) {
	    char *buf1, *buf2, *buf3, *buf4, *buf5;
	    char *buf6, *buf7, *buf8, *buf9;

	    buf1 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1628, "HOST_NAME")); /* catgets  1628 */
	    buf2 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1602, "type")); /* catgets  1602  */
	    buf3 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1603, "model")); /* catgets  1603  */
	    buf4 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1604, "cpuf")); /* catgets  1604  */
	    buf5 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1605, "ncpus")); /* catgets  1605  */
	    buf6 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1607, "maxmem")); /* catgets  1607  */
	    buf7 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1608, "maxswp")); /* catgets  1608  */
	    buf8 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1611, "server")); /* catgets  1611  */
	    buf9 = putstr_(_i18n_msg_get(ls_catd,NL_SETN,1614, "RESOURCES")); /* catgets  1614  */

            printf("%-25.25s %10.10s %11.11s %5.5s %5.5s %6.6s %6.6s %6.6s %9.9s\n",
		buf1, buf2, buf3, buf4, buf5, buf6, buf7, buf8, buf9);

	    FREEUP(buf1);
	    FREEUP(buf2);
	    FREEUP(buf3);
	    FREEUP(buf4);
	    FREEUP(buf5);
	    FREEUP(buf6);
	    FREEUP(buf7);
	    FREEUP(buf8);
	    FREEUP(buf9);
        }

        for (i=0;i<numhosts;i++) {
            char *server;
            int first;

            if (longformat) {
                print_long(&hostinfo[i]);
                continue;
            }

            if (hostinfo[i].isServer)
                server = I18N_Yes;
            else
                server = I18N_No;


    	    if(longname)
	        printf("%-25s %10s %11s %5.1f ", hostinfo[i].hostName,
	               hostinfo[i].hostType, hostinfo[i].hostModel,
                       hostinfo[i].cpuFactor);
            else
	        printf("%-11.11s %7.7s %8.8s %5.1f ", hostinfo[i].hostName,
	               hostinfo[i].hostType, hostinfo[i].hostModel,
                       hostinfo[i].cpuFactor);

	    if (hostinfo[i].maxCpus > 0)
	        printf("%5d",hostinfo[i].maxCpus);
	    else
                printf("%5.5s", "-");

	    if (hostinfo[i].maxMem > 0)
	        printf(" %5dM",hostinfo[i].maxMem);
	    else
	        printf(" %6.6s", "-");

            if (hostinfo[i].maxSwap > 0)
	        printf(" %5dM",hostinfo[i].maxSwap);
            else
	        printf(" %6.6s", "-");

            printf(" %6.6s", server);
            printf(" (");

            first = TRUE;
	    for (j=0; j<hostinfo[i].nRes; j++) {
                if (! first)
                   printf(" ");
	        printf("%s", hostinfo[i].resources[j]);
                first = FALSE;
            }

            fputs(")\n", stdout);
        }


        _i18n_end ( ls_catd );
        exit(0);
    }