Exemplo n.º 1
0
int main(int argc, char **argv)
{
    int ret = -1;
    char *retc = NULL;
    PVFS_fs_id cur_fs;
    struct options* user_opts = NULL;
    char pvfs_path[PVFS_NAME_MAX] = {0};
    int i;
    PVFS_credentials creds;
    int io_server_count;
    int64_t **perf_matrix;
    uint64_t* end_time_ms_array;
    uint32_t* next_id_array;
    PVFS_BMI_addr_t *addr_array, server_addr;
    char *cmd_buffer = (char *)malloc(CMD_BUF_SIZE);
    int max_keys, key_count;

    /* look at command line arguments */
    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
        fprintf(stderr, "Error: failed to parse command line arguments.\n");
        usage(argc, argv);
        return(-1);
    }

    ret = PVFS_util_init_defaults();
    if (ret < 0)
    {
        PVFS_perror("PVFS_util_init_defaults", ret);
        return(-1);
    }

    PVFS_util_gen_credentials(&creds);
    if (user_opts->server_addr_set)
    {
        if (PVFS_util_get_default_fsid(&cur_fs) < 0)
        {
            /* Can't find a file system */
            fprintf(stderr, "Error: failed to find a file system.\n");
            usage(argc, argv);
            return(-1);
        }
        if (user_opts->server_addr &&
                (BMI_addr_lookup (&server_addr, user_opts->server_addr) == 0))
        {
            /* set up single server */
            addr_array = (PVFS_BMI_addr_t *)malloc(sizeof(PVFS_BMI_addr_t));
            addr_array[0] = server_addr;
            io_server_count = 1;
        }
        else
        {
            /* bad argument - address not found */
            fprintf(stderr, "Error: failed to parse server address.\n");
            usage(argc, argv);
            return(-1);
        }
    }
    else
    {
        /* will sample all servers */
        /* translate local path into pvfs2 relative path */
        ret = PVFS_util_resolve(user_opts->mnt_point,
                                &cur_fs, pvfs_path, PVFS_NAME_MAX);
        if (ret < 0)
        {
            PVFS_perror("PVFS_util_resolve", ret);
            return(-1);
        }

        /* count how many I/O servers we have */
        ret = PVFS_mgmt_count_servers(cur_fs, &creds, PVFS_MGMT_IO_SERVER,
                                    &io_server_count);
        if (ret < 0)
        {
            PVFS_perror("PVFS_mgmt_count_servers", ret);
	        return(-1);
        }
    
        /* build a list of servers to talk to */
        addr_array = (PVFS_BMI_addr_t *)
	    malloc(io_server_count * sizeof(PVFS_BMI_addr_t));
        if (addr_array == NULL)
        {
	        perror("malloc");
	        return -1;
        }
        ret = PVFS_mgmt_get_server_array(cur_fs,
				     &creds,
				     PVFS_MGMT_IO_SERVER,
				     addr_array,
				     &io_server_count);
        if (ret < 0)
        {
	        PVFS_perror("PVFS_mgmt_get_server_array", ret);
	        return -1;
        }
    }

    /* count keys */
    for (max_keys = 0; key_table[max_keys].key_number >= 0; max_keys++);

    /* allocate a 2 dimensional array for statistics */
    perf_matrix = (int64_t **)malloc(io_server_count * sizeof(int64_t *));
    if (!perf_matrix)
    {
        perror("malloc");
        return(-1);
    }
    for(i=0; i<io_server_count; i++)
    {
	    perf_matrix[i] = (int64_t *)malloc(HISTORY * (max_keys + 2)
                                        * sizeof(int64_t));
	    if (perf_matrix[i] == NULL)
	    {
	        perror("malloc");
	        return -1;
	    }
    }

    /* allocate an array to keep up with what iteration of statistics
     * we need from each server 
     */
    next_id_array = (uint32_t *) malloc(io_server_count * sizeof(uint32_t));
    if (next_id_array == NULL)
    {
	     perror("malloc");
	     return -1;
    }
    memset(next_id_array, 0, io_server_count*sizeof(uint32_t));

    /* allocate an array to keep up with end times from each server */
    end_time_ms_array = (uint64_t *)malloc(io_server_count * sizeof(uint64_t));
    if (end_time_ms_array == NULL)
    {
	    perror("malloc");
	    return -1;
    }


    /* loop for ever, grabbing stats when requested */
    while (1)
    {
        int srv = 0;
        time_t snaptime = 0;
        const char *returnType = NULL; 
        int64_t returnValue = 0;
        /* wait for a request from SNMP driver */
        retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
        if (!retc)
        {
            /* error on read */
            return -1;
        }

        /* if PING output PONG */
        if (!strncasecmp(cmd_buffer, "PING", 4))
        {
            fprintf(stdout,"PONG\n");
	        fflush(stdout);
            continue;
        }

        /* try to parse GET command */
        if (!strncasecmp(cmd_buffer, "GET", 3))
        {
            char *c;
            /* found GET read OID */
            retc = fgets(cmd_buffer, CMD_BUF_SIZE, stdin);
            if (!retc)
            {
                /* error on read */
                return -1;
            }
            /* replace newlines with null char */
            for(c = cmd_buffer; *c != '\0'; c++)
                if (*c == '\n')
                    *c = '\0';
        }
        else
        {
            /* bad command */
            fprintf(stdout, "NONE\n");
            fflush(stdout);
            continue;
        }

        /* good command - read counters */
        if (time(NULL) - snaptime > 60)
        {
            snaptime = time(NULL);
            key_count = max_keys;
	        ret = PVFS_mgmt_perf_mon_list(cur_fs,
				          &creds,
				          perf_matrix, 
				          end_time_ms_array,
				          addr_array,
				          next_id_array,
				          io_server_count, 
                          &key_count,
				          HISTORY,
				          NULL, NULL);
	        if (ret < 0)
	        {
	            PVFS_perror("PVFS_mgmt_perf_mon_list", ret);
	            return -1;
	        }
        }

        /* format requested OID */
        if (perf_matrix[srv][key_count] != 0)
        {
            int k;
            /* this is a valid measurement */
            for(k = 0; k < max_keys &&
                    strcmp(cmd_buffer, key_table[k].key_oid); k++);
            /* out of for loop k equals selected key */
            if (k < max_keys)
            {
                returnType = key_table[k].key_type;
                returnValue = perf_matrix[srv][key_table[k].key_number];
            }
            else
            {
                /* invalid command */
                fprintf(stdout,"NONE\n");
                fflush(stdout);
                continue;
            }
        }
        else
        {
            /* invalid measurement */
            fprintf(stdout,"NONE\n");
            fflush(stdout);
            continue;
        }
        fprintf(stdout, "%s\n%llu\n", returnType, llu(returnValue));
        fflush(stdout);
        /* return to top for next command */
    }

    PVFS_sys_finalize();

    return(ret);
}
Exemplo n.º 2
0
int main(
    int argc,
    char **argv)
{
    int ret = -1;
    int outcount = 0;
    void *mybuffer;
    PVFS_BMI_addr_t server_addr;
    bmi_op_id_t op;
    bmi_error_code_t error_code;
    flow_descriptor *flow_d = NULL;
    int i = 0;
    bmi_size_t actual_size;
    double time1, time2;
    PINT_Request *req;
    bmi_context_id context;

	/*************************************************************/
    /* initialization stuff */

    /* set debugging level */
    gossip_enable_stderr();
    gossip_set_debug_mask(
        0, (GOSSIP_FLOW_PROTO_DEBUG | GOSSIP_BMI_DEBUG_TCP));

    /* Dist init */
    PINT_dist_initialize(NULL);

    /* start up BMI */
    ret = BMI_initialize("bmi_tcp", NULL, 0);
    if (ret < 0)
    {
	fprintf(stderr, "BMI init failure.\n");
	return (-1);
    }

    ret = BMI_open_context(&context);
    if (ret < 0)
    {
	fprintf(stderr, "BMI_open_context() failure.\n");
	return (-1);
    }

    /* initialize the flow interface */
    ret = PINT_flow_initialize("flowproto_multiqueue", 0);
    if (ret < 0)
    {
	fprintf(stderr, "flow init failure.\n");
	return (-1);
    }

    /* send some random crap to the other side to start up communication */
    ret = BMI_addr_lookup(&server_addr, "tcp://localhost:3335");
    if (ret < 0)
    {
	fprintf(stderr, "BMI lookup failure.\n");
	return (-1);
    }

    ret = BMI_post_sendunexpected(&op, server_addr, &mybuffer, 1,
				  BMI_EXT_ALLOC, 0, NULL, context, NULL);
    if (ret < 0)
    {
	fprintf(stderr, "BMI_post_sendunexpected failure.\n");
	return (-1);
    }
    if (ret == 0)
    {
	/* turning this into a blocking call for testing :) */
	/* check for completion of request */
	do
	{
	    ret = BMI_test(op, &outcount, &error_code, &actual_size,
			   NULL, 10, context);
	} while (ret == 0 && outcount == 0);

	if (ret < 0 || error_code != 0)
	{
	    fprintf(stderr, "Request send failed.\n");
	    if (ret < 0)
	    {
		errno = -ret;
		perror("BMI_test");
	    }
	    return (-1);
	}
    }

	/******************************************************/
    /* setup request/dist stuff */

    /* request description */
    /* just want one contiguous region */
    ret = PVFS_Request_contiguous(TEST_SIZE, PVFS_BYTE, &req);
    if (ret < 0)
    {
	fprintf(stderr, "PVFS_Request_contiguous() failure.\n");
	return (-1);
    }


	/******************************************************/
    /* setup communicaton stuff */

    /* memory buffer to xfer */
    mybuffer = (void *) malloc(TEST_SIZE);
    if (!mybuffer)
    {
	fprintf(stderr, "mem.\n");
	return (-1);
    }
    /* mark it so that we can check correctness */
    for (i = 0; i < (TEST_SIZE / (sizeof(int))); i++)
    {
	((int *) mybuffer)[i] = i;
    }

    /* create a flow descriptor */
    flow_d = PINT_flow_alloc();
    if (!flow_d)
    {
	fprintf(stderr, "mem.\n");
	return (-1);
    }

    /* file data */
    flow_d->file_data.fsize = TEST_SIZE;
    flow_d->file_data.server_nr = 0;
    flow_d->file_data.server_ct = 1;
    flow_d->file_data.extend_flag = 0;
    flow_d->file_data.dist = PINT_dist_create("basic_dist");
    if (!flow_d->file_data.dist)
    {
	fprintf(stderr, "Error: failed to create dist.\n");
	return (-1);
    }
    ret = PINT_dist_lookup(flow_d->file_data.dist);
    if (ret != 0)
    {
	fprintf(stderr, "Error: failed to lookup dist.\n");
	return (-1);
    }


    flow_d->file_req = req;
    flow_d->tag = 0;
    flow_d->user_ptr = NULL;
    flow_d->aggregate_size = TEST_SIZE;

    /* fill in flow details */
    flow_d->src.endpoint_id = MEM_ENDPOINT;
    flow_d->src.u.mem.buffer = mybuffer;
    flow_d->dest.endpoint_id = BMI_ENDPOINT;
    flow_d->dest.u.bmi.address = server_addr;

	/***************************************************
	 * test memory to bmi (analogous to client side write)
	 */

    time1 = Wtime();
    ret = block_on_flow(flow_d);
    if (ret < 0)
    {
	return (-1);
    }
    time2 = Wtime();

	/*******************************************************/
    /* final cleanup and output */

#if 0
    printf("Client bw (send): %f MB/sec\n",
	   ((TEST_SIZE) / ((time2 - time1) * 1000000.0)));
#endif

    PINT_flow_free(flow_d);

    /* shut down flow interface */
    ret = PINT_flow_finalize();
    if (ret < 0)
    {
	fprintf(stderr, "flow finalize failure.\n");
	return (-1);
    }

    /* shut down BMI */
    BMI_close_context(context);
    BMI_finalize();

    free(mybuffer);

    gossip_disable();
    return (0);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{

    int ret = -1;
    struct request_foo* req = NULL;
    struct ack_foo* ack = NULL;
    PVFS_BMI_addr_t server_addr;
    job_status_s status1;
    job_id_t tmp_id;
    job_context_id context;

    /* set debugging level */
    gossip_enable_stderr();
    gossip_set_debug_mask(0, 0);

    /* start the BMI interface */
    ret = BMI_initialize("bmi_tcp", NULL, 0);
    if(ret < 0)
    {
        fprintf(stderr, "BMI_initialize failure.\n");
        return(-1);
    }

    ret = trove_initialize(
              TROVE_METHOD_DBPF, NULL, "/tmp/pvfs2-test-space", 0);
    if(ret < 0)
    {
        fprintf(stderr, "trove_initialize failure.\n");
        return(-1);
    }

    /* start the job interface */
    ret = job_initialize(0);
    if(ret < 0)
    {
        fprintf(stderr, "job_initialize failure.\n");
        return(-1);
    }

    ret = job_open_context(&context);
    if(ret < 0)
    {
        fprintf(stderr, "job_open_context() failure.\n");
        return(-1);
    }

    /* lookup the server to get a BMI style address for it */
    ret = BMI_addr_lookup(&server_addr, "tcp://localhost:3414");
    if(ret < 0)
    {
        fprintf(stderr, "BMI_addr_lookup failure.\n");
        return(-1);
    }

    /* allocate some buffers for the req and ack */
    req = BMI_memalloc(server_addr, sizeof(struct request_foo),
                       BMI_SEND);
    ack = BMI_memalloc(server_addr, sizeof(struct ack_foo),
                       BMI_RECV);
    if(!ack || ! req)
    {
        fprintf(stderr, "BMI_memalloc failure.\n");
        return(-1);
    }

    /* send a message */
    ret = job_bmi_send(server_addr, req, sizeof(struct request_foo),
                       0, BMI_PRE_ALLOC, 1, NULL, 0, &status1, &tmp_id, context,
                       JOB_TIMEOUT_INF, NULL);
    if(ret < 0)
    {
        fprintf(stderr, "job_bmi_send() failure.\n");
        return(-1);
    }
    if(ret == 0)
    {
        int count = 0;
        ret = job_test(tmp_id, &count, NULL, &status1, -1, context);
        if(ret < 0)
        {
            fprintf(stderr, "job_test() failure.\n");
            return(-1);
        }
    }

    /* check status */
    if(status1.error_code != 0)
    {
        fprintf(stderr, "job failure.\n");
        return(-1);
    }

    /* receive a message */
    ret = job_bmi_recv(server_addr, ack, sizeof(struct ack_foo),
                       0, BMI_PRE_ALLOC, NULL, 0, &status1, &tmp_id, context,
                       JOB_TIMEOUT_INF, NULL);
    if(ret < 0)
    {
        fprintf(stderr, "job_bmi_recv() failure.\n");
        return(-1);
    }
    if(ret == 0)
    {
        int count = 0;
        ret = job_test(tmp_id, &count, NULL, &status1, -1, context);
        if(ret < 0)
        {
            fprintf(stderr, "job_test() failure.\n");
            return(-1);
        }
    }

    /* check status */
    if(status1.error_code != 0)
    {
        fprintf(stderr, "job failure.\n");
        return(-1);
    }

    /* check the size */
    if(status1.actual_size != sizeof(struct ack_foo))
    {
        fprintf(stderr, "short recv.\n");
        return(-1);
    }

    /* free memory buffers */
    BMI_memfree(server_addr, req, sizeof(struct request_foo),
                BMI_SEND);
    BMI_memfree(server_addr, ack, sizeof(struct ack_foo),
                BMI_RECV);

    /* shut down the interfaces */
    job_close_context(context);
    job_finalize();
    BMI_finalize();
    trove_finalize(TROVE_METHOD_DBPF);

    return(0);
}