Exemplo n.º 1
0
int
equivalentXferFile(lsRcpXfer *lsXfer, char *szLocalFile, char *szRemoteFile,
                    struct stat *psLstat, struct stat *psRstat, char *szRhost)
{
    char *pszH;
    char szHost1[MAXHOSTNAMELEN], szHost2[MAXHOSTNAMELEN];
    char *hostlist[1];
    struct hostInfo *hostinfo;
    char  * szFileName1, * szFileName2;

    if (logclass & (LC_FILE))
        ls_syslog(LOG_DEBUG,"equivalentXferFile(), ls_getmnthost() for '%s'",
                szLocalFile);

    hostlist[0] = szRhost;
    hostinfo = ls_gethostinfo((char *)NULL, (int *)NULL, (char **)hostlist, 1, 0);
    if ( hostinfo == (struct hostInfo *)NULL ) {
	return -1;
    } else {
	if ( strcmp(hostinfo->hostType, "NTX86") == 0
             || strcmp(hostinfo->hostType, "NTALPHA") == 0) {
	    return (1);
	}
    }

    if ((pszH = ls_getmnthost(szLocalFile)) == NULL) {
        return -1;
    }

    strcpy(szHost1, pszH);

    if (logclass & (LC_FILE))
        ls_syslog(LOG_DEBUG,
	    "equivalentXferFile(),ls_rgetmnthost() for '%s' on '%s'"
            , szLocalFile, szRhost);

    if ((pszH = ls_rgetmnthost(szRhost, szRemoteFile)) == NULL) {
        return -1;
    }

    strcpy(szHost2, pszH);

    szFileName1 = strrchr(lsXfer->ppszHostFnames[0],'/');
    szFileName2 = strrchr(lsXfer->ppszDestFnames[0],'/');
    if (szFileName1 == NULL)
        szFileName1 = lsXfer->ppszHostFnames[0];
    else szFileName1 ++;
    if (szFileName2 == NULL)
        szFileName2 = lsXfer->ppszDestFnames[0];
    else szFileName2 ++;
    if ( psLstat->st_ino == psRstat->st_ino
         && (strcmp(szFileName1,szFileName2) == 0)
         && equalHost_(szHost1,szHost2)) {
         return 0;
    }
    return(1);

}
Exemplo n.º 2
0
float *
ls_gethostfactor (char *hostname)
{
    struct hostInfo *hostinfo;
    static float cpufactor;

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

    hostinfo = ls_gethostinfo ("-", NULL, &hostname, 1, 0);
    if (hostinfo == NULL)
        return (NULL);

    cpufactor = hostinfo->cpuFactor;
    return (&cpufactor);

}
Exemplo n.º 3
0
char *
ls_gethostmodel (char *hostname)
{
    struct hostInfo *hostinfo;
    static char hostModel[MAXLSFNAMELEN];

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

    hostinfo = ls_gethostinfo ("-", NULL, &hostname, 1, 0);
    if (hostinfo == NULL)
        return (NULL);

    strcpy (hostModel, hostinfo[0].hostModel);
    return hostModel;

}
Exemplo n.º 4
0
char *
ls_gethosttype (char *hostname)
{
    struct hostInfo *hostinfo;
    static char hostType[MAXLSFNAMELEN];

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

    hostinfo = ls_gethostinfo ("-", NULL, &hostname, 1, 0);
    if (hostinfo == NULL)
        return (NULL);

    strcpy (hostType, hostinfo[0].hostType);
    return (hostType);

}
Exemplo n.º 5
0
static
void doAllHosts(int opCode)
{
    int numhosts = 0, i;
    struct hostInfo *hostinfo;
    int ask = FALSE, try = FALSE;
    char msg[128];

    hostinfo = ls_gethostinfo("-:server", &numhosts, NULL, 0, LOCAL_ONLY);
    if (hostinfo == NULL) {
	ls_perror("ls_gethostinfo");
	fprintf(stderr, "Operation aborted\n");
        exitrc = -1;
	return;
    }

    if (!fFlag) {
	if (opCode == LIM_CMD_REBOOT)
            sprintf(msg, "Do you really want to restart LIMs on all hosts? [y/n] ");
        else
	    sprintf(msg, "Do you really want to shut down LIMs on all hosts? [y/n] ");
	ask = (!getConfirm(msg));
    }

    for (i = 0; i < numhosts; i++)
        if (hostinfo[i].maxCpus > 0)
	    operateHost (hostinfo[i].hostName, opCode, ask);
        else
	    try = 1;
    if (try) {
        fprintf(stderr, "\n%s :\n\n", "Trying unavailable hosts");
        for (i = 0; i < numhosts; i++)
            if (hostinfo[i].maxCpus <= 0)
	        operateHost (hostinfo[i].hostName, opCode, ask);
    }

}
Exemplo n.º 6
0
static int
getTclHostData (struct hostLoad *load, struct tclHostData *tclHostData,
                                                              int freeMem)
{

    static char fname[] = "getTclHostData";
    static time_t lastUpdHostInfo = 0;
    static int numLsfHosts = 0;
    static struct hostInfo *hostInfo = NULL;
    struct hostInfo *temp;
    int i, num;

    if (now - lastUpdHostInfo > 10 * 60) {

        if ((temp = ls_gethostinfo("-:server", &num, 0,
                    0, LOCAL_ONLY)) == NULL) {
            ls_syslog(LOG_ERR, I18N_FUNC_FAIL_MM, fname, "ls_gethostinfo");
	    return -1;
        }
        if (hostInfo != NULL) {
	    freeLsfHostInfo (hostInfo, numLsfHosts);
	    FREEUP (hostInfo);
	    numLsfHosts = 0;
        }

        hostInfo = (struct hostInfo *) my_malloc
                (num * sizeof (struct hostInfo), fname);
        for (i = 0; i < num; i++) {
            copyLsfHostInfo (&hostInfo[i], &temp[i]);

	    if ( logclass & LC_TRACE) {
	        ls_syslog(LOG_DEBUG2, "%s: host <%s> ncpus <%d> maxmem <%u> maxswp <%u> maxtmp <%u> ndisk <%d>",
		    fname, hostInfo[i].hostName, hostInfo[i].maxCpus,
	            hostInfo[i].maxMem, hostInfo[i].maxSwap,
	            hostInfo[i].maxTmp, hostInfo[i].nDisks);
	    }
        }
        numLsfHosts = num;
	lastUpdHostInfo = now;

    }
    if (freeMem == TRUE)  {
        FREEUP (tclHostData->resBitMaps);
        FREEUP (tclHostData->loadIndex);
    }
    for (i = 0; i < numLsfHosts; i++) {
	if (equalHost_(hostInfo[i].hostName, load->hostName))
	    break;
    }
    if (i == numLsfHosts) {
        ls_syslog(LOG_ERR, _i18n_msg_get(ls_catd , NL_SETN, 5716,
	    "%s: Host <%s> is not used by the batch system"), /* catgets 5716 */
	    fname, load->hostName);
        return -1;
    }
    tclHostData->hostName = hostInfo[i].hostName;
    tclHostData->hostType = hostInfo[i].hostType;
    tclHostData->hostModel = hostInfo[i].hostModel;
    tclHostData->maxCpus = hostInfo[i].maxCpus;
    tclHostData->maxMem = hostInfo[i].maxMem;
    tclHostData->maxSwap = hostInfo[i].maxSwap;
    tclHostData->maxTmp = hostInfo[i].maxTmp;
    tclHostData->nDisks = hostInfo[i].nDisks;
    tclHostData->hostInactivityCount = 0;
    tclHostData->rexPriority = 0;
    tclHostData->fromHostType = tclHostData->hostType;
    tclHostData->fromHostModel = tclHostData->hostModel;
    tclHostData->cpuFactor = hostInfo[i].cpuFactor;
    tclHostData->ignDedicatedResource = FALSE;
    tclHostData->resBitMaps = getResMaps(hostInfo[i].nRes,
					       hostInfo[i].resources);
    tclHostData->DResBitMaps = NULL;
    tclHostData->flag = TCL_CHECK_EXPRESSION;
    tclHostData->status = load->status;
    tclHostData->loadIndex
       = (float *) my_malloc (allLsInfo->numIndx * sizeof(float), fname);
    tclHostData->loadIndex[R15S] = (hostInfo[i].cpuFactor != 0.0)?
		((load->li[R15S] + 1.0)/hostInfo[i].cpuFactor):load->li[R15S];
    tclHostData->loadIndex[R1M] = (hostInfo[i].cpuFactor != 0.0)?
		((load->li[R1M] + 1.0)/hostInfo[i].cpuFactor):load->li[R1M];
    tclHostData->loadIndex[R15M] = (hostInfo[i].cpuFactor != 0.0)?
		((load->li[R15M] + 1.0)/hostInfo[i].cpuFactor):load->li[R15M];

    for (i = 3; i < allLsInfo->numIndx; i++)
        tclHostData->loadIndex[i] = load->li[i];

    return 0;

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

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