Ejemplo n.º 1
0
int main(
    int argc,
    char **argv)
{

    struct options *user_opts = NULL;
    struct server_request *my_req = NULL;
    struct server_ack *my_ack = NULL;
    int ret = -1;
    PVFS_BMI_addr_t client_addr;
    void *recv_buffer1 = NULL;
    void *recv_buffer2 = NULL;
    bmi_op_id_t server_ops[2];
    bmi_error_code_t error_code;
    int outcount = 0;
    struct BMI_unexpected_info request_info;
    bmi_size_t actual_size;
    bmi_size_t size_list[2];
    void *buffer_list[2];
    int last = 0;
    int i = 0;
    bmi_context_id context;
    char method[24], *cp;
    int len;

    /* grab any command line options */
    user_opts = parse_args(argc, argv);
    if (!user_opts)
    {
	return (-1);
    }

    /* set debugging stuff */
    gossip_enable_stderr();
    gossip_set_debug_mask(0, GOSSIP_BMI_DEBUG_ALL);

    /* convert address to bmi method type by prefixing bmi_ */
    cp = strchr(user_opts->hostid, ':');
    if (!cp)
        return 1;
    len = cp - user_opts->hostid;
    strcpy(method, "bmi_");
    strncpy(method + 4, user_opts->hostid, len);
    method[4+len] = '\0';

    /* initialize local interface (default options) */
    ret = BMI_initialize(method, user_opts->hostid, BMI_INIT_SERVER);
    if (ret < 0)
    {
	errno = -ret;
	perror("BMI_initialize");
	return (-1);
    }

    ret = BMI_open_context(&context);
    if (ret < 0)
    {
	errno = -ret;
	perror("BMI_open_context()");
	return (-1);
    }

    /* wait for an initial request  */
    do
    {
	ret = BMI_testunexpected(1, &outcount, &request_info, 10);
    } while (ret == 0 && outcount == 0);
    if (ret < 0)
    {
	fprintf(stderr, "Request recv failure (bad state).\n");
	errno = -ret;
	perror("BMI_testunexpected");
	return (-1);
    }
    if (request_info.error_code != 0)
    {
	fprintf(stderr, "Request recv failure (bad state).\n");
	return (-1);
    }

    printf("Received a new request.\n");

    if (request_info.size != sizeof(struct server_request))
    {
	fprintf(stderr, "Bad Request!\n");
	exit(-1);
    }

    my_req = (struct server_request *) request_info.buffer;
    client_addr = request_info.addr;

    /* create an ack */
    my_ack = (struct server_ack *) BMI_memalloc(client_addr,
						sizeof(struct server_ack),
						BMI_SEND);
    if (!my_ack)
    {
	fprintf(stderr, "BMI_memalloc failed.\n");
	return (-1);
    }
    memset(my_ack, 0, sizeof(struct server_ack));

    /* create 2 buffers to recv into */
    recv_buffer1 = BMI_memalloc(client_addr, (my_req->size / 2), BMI_RECV);
    recv_buffer2 = BMI_memalloc(client_addr,
				(my_req->size - (my_req->size / 2)), BMI_RECV);
    if (!recv_buffer1 || !recv_buffer2)
    {
	fprintf(stderr, "BMI_memalloc failed.\n");
	return (-1);
    }
    buffer_list[0] = recv_buffer1;
    buffer_list[1] = recv_buffer2;
    size_list[0] = my_req->size / 2;
    size_list[1] = my_req->size - (my_req->size / 2);

    /* post the ack */
    ret = BMI_post_send(&(server_ops[1]), client_addr, my_ack,
			sizeof(struct server_ack), BMI_PRE_ALLOC, 0, NULL,
			context, NULL);
    if (ret < 0)
    {
	fprintf(stderr, "BMI_post_send_failure.\n");
	return (-1);
    }
    if (ret == 0)
    {
	/* turning this into a blocking call for testing :) */
	/* check for completion of ack send */
	do
	{
	    ret = BMI_test(server_ops[1], &outcount, &error_code,
			   &actual_size, NULL, 10, context);
	} while (ret == 0 && outcount == 0);

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

    /* post the recv */
    ret = BMI_post_recv_list(&(server_ops[0]), client_addr, buffer_list,
			     size_list, 2, my_req->size, &actual_size,
			     BMI_PRE_ALLOC, 0, NULL, context, NULL);
    if (ret < 0)
    {
	fprintf(stderr, "BMI_post_recv_failure.\n");
	return (-1);
    }
    if (ret == 0)
    {
	/* turning this into a blocking call for testing :) */
	/* check for completion of data payload recv */
	do
	{
	    ret = BMI_test(server_ops[0], &outcount, &error_code,
			   &actual_size, NULL, 10, context);
	} while (ret == 0 && outcount == 0);

	if (ret < 0 || error_code != 0)
	{
	    fprintf(stderr, "data recv failed.\n");
	    return (-1);
	}
    }

    if (actual_size != my_req->size)
    {
	printf("Short recv.\n");
	printf("diff: %d\n", (int) (my_req->size - actual_size));
    }

    /* check validity of received message */
    for (i = 0; i < ((my_req->size / 2) / sizeof(int)); i++)
    {
	if (((int *) recv_buffer1)[i] != i)
	{
	    fprintf(stderr, "Validation failure, offset %d.\n", i);
	}
    }
    last = i;
    for (i = last;
	 i < (last + ((my_req->size - (my_req->size / 2)) / sizeof(int))); i++)
    {
	if (((int *) recv_buffer2)[i - last] != i)
	{
	    fprintf(stderr, "Validation failure, offset %d.\n", i);
	}
    }

    /* free up the message buffers */
    BMI_memfree(client_addr, recv_buffer1, (my_req->size / 2), BMI_RECV);
    BMI_memfree(client_addr, recv_buffer2, (my_req->size -
					    (my_req->size / 2)), BMI_RECV);
    BMI_memfree(client_addr, my_ack, sizeof(struct server_ack), BMI_SEND);
    BMI_unexpected_free(client_addr, my_req);

    /* shutdown the local interface */
    BMI_close_context(context);
    ret = BMI_finalize();
    if (ret < 0)
    {
	errno = -ret;
	perror("BMI_finalize");
	return (-1);
    }

    /* turn off debugging stuff */
    gossip_disable();

    free(user_opts->hostid);
    free(user_opts);

    return (0);
}
Ejemplo n.º 2
0
int main(
    int argc,
    char **argv)
{
    int ret = -1;
    int outcount = 0, count;
    struct BMI_unexpected_info request_info;
    flow_descriptor *flow_d = NULL;
    double time1, time2;
    int i;
    PINT_Request *req;
    char path_name[PATH_SIZE];
    TROVE_op_id op_id;
    TROVE_coll_id coll_id;
    TROVE_handle file_handle, parent_handle;
    TROVE_ds_state state;
    char *file_name;
    TROVE_keyval_s key, val;
    bmi_context_id context;
    TROVE_context_id trove_context;
    PVFS_handle_extent cur_extent;
    PVFS_handle_extent_array extent_array;

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

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

    /* start up BMI */
    ret = BMI_initialize("bmi_tcp", "tcp://NULL:3335", BMI_INIT_SERVER);
    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);
    }

    ret = trove_initialize(
        TROVE_METHOD_DBPF, NULL, storage_space, 0);
    if (ret < 0)
    {
	fprintf(stderr, "initialize failed: run trove-mkfs first.\n");
	return -1;
    }

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

    /* try to look up collection used to store file system */
    ret = trove_collection_lookup(
        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
    if (ret < 0)
    {
	fprintf(stderr, "collection lookup failed.\n");
	return -1;
    }

    ret = trove_open_context(coll_id, &trove_context);
    if (ret < 0)
    {
	fprintf(stderr, "TROVE_open_context() failure.\n");
	return (-1);
    }

    /* find the parent directory name */
    strcpy(path_name, path_to_file);
    for (i = strlen(path_name); i >= 0; i--)
    {
	if (path_name[i] != '/')
	    path_name[i] = '\0';
	else
	    break;
    }
    file_name = path_to_file + strlen(path_name);
    printf("path is %s\n", path_name);
    printf("file is %s\n", file_name);

    /* find the parent directory handle */
    ret = path_lookup(coll_id, trove_context, path_name, &parent_handle);
    if (ret < 0)
    {
	return -1;
    }

    file_handle = 0;

    cur_extent.first = cur_extent.last = requested_file_handle;
    extent_array.extent_count = 1;
    extent_array.extent_array = &cur_extent;
    ret = trove_dspace_create(coll_id,
			      &extent_array,
			      &file_handle,
			      TROVE_TEST_FILE,
			      NULL, 
				TROVE_FORCE_REQUESTED_HANDLE,
				NULL, trove_context, &op_id, NULL);
    while (ret == 0)
	ret =
	    trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
			      &state, TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0)
    {
	fprintf(stderr, "dspace create failed.\n");
	return -1;
    }

    /* TODO: set attributes of file? */

    /* add new file name/handle pair to parent directory */
    key.buffer = file_name;
    key.buffer_sz = strlen(file_name) + 1;
    val.buffer = &file_handle;
    val.buffer_sz = sizeof(file_handle);
    ret =
	trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL,
			   trove_context, &op_id, NULL);
    while (ret == 0)
	ret =
	    trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
			      &state, TROVE_DEFAULT_TEST_TIMEOUT);
    if (ret < 0)
    {
	fprintf(stderr, "keyval write failed.\n");
	return -1;
    }


    /* wait for an initial communication via BMI */
    /* we don't give a crap about that message except that it tells us
     * where to find the client 
     */
    do
    {
	ret = BMI_testunexpected(1, &outcount, &request_info, 10);
    } while (ret == 0 && outcount == 0);
    if (ret < 0 || request_info.error_code != 0)
    {
	fprintf(stderr, "waitunexpected failure.\n");
	return (-1);
    }
    BMI_unexpected_free(request_info.addr, request_info.buffer);

	/******************************************************/
    /* 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 */

    /* create a flow descriptor */
    flow_d = PINT_flow_alloc();
    if (!flow_d)
    {
	fprintf(stderr, "flow_alloc failed.\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 = 1;
    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 = BMI_ENDPOINT;
    flow_d->src.u.bmi.address = request_info.addr;
    flow_d->dest.endpoint_id = TROVE_ENDPOINT;
    flow_d->dest.u.trove.handle = file_handle;
    flow_d->dest.u.trove.coll_id = coll_id;

	/***************************************************
	 * test bmi to file (analogous to a client side write)
	 */

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

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

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

    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();

    trove_close_context(coll_id, trove_context);
    trove_finalize(TROVE_METHOD_DBPF);

    gossip_disable();
    return (0);
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
        struct options                  *opts = NULL;
        int                             ret = -1;
        bmi_context_id                  context;

        /* grab any command line options */
        opts = parse_args(argc, argv);
        if (!opts) {
                print_usage();
                return (-1);
        }

        /* set debugging stuff */
        gossip_enable_stderr();
        gossip_set_debug_mask(0, GOSSIP_BMI_DEBUG_ALL);

#ifdef WIN32
        /* get performance counter frequency */
        QueryPerformanceFrequency(&freq);
#endif

        /* initialize local interface (default options) */
        if (opts->which == SERVER)
            ret = BMI_initialize(opts->method, opts->hostid, BMI_INIT_SERVER);
        else
            ret = BMI_initialize(NULL, NULL, 0);

        if (ret < 0) {
                errno = -ret;
                perror("BMI_initialize");
                return (-1);
        }

        ret = BMI_open_context(&context);
        if (ret < 0) {
                errno = -ret;
                perror("BMI_open_context()");
                return (-1);
        }

        if (opts->which == SERVER) {
                ret = do_server(opts, &context);
        } else {
                ret = do_client(opts, &context);
        }

        /* shutdown the local interface */
        BMI_close_context(context);
        ret = BMI_finalize();
        if (ret < 0) {
                errno = -ret;
                perror("BMI_finalize");
                return (-1);
        }

        /* turn off debugging stuff */
        gossip_disable();

        return (0);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
    int ret = 1;
    struct PINT_dev_unexp_info info;
    char buf1[] = "Hello ";
    char buf2[] = "World.";
    void* buffer_list[2];
    int size_list[2];
    job_context_id context;
    job_status_s jstat;
    job_id_t tmp_id;

    ret = PINT_dev_initialize("/dev/pvfs2-req", 0);
    if(ret < 0)
    {
        PVFS_perror("PINT_dev_initialize", ret);
        return(-1);
    }

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

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

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

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

    /* post job for unexpected device messages */
    ret = job_dev_unexp(&info, NULL, 0, &jstat, &tmp_id, 0, context);
    if(ret < 0)
    {
        PVFS_perror("job_dev_unexp()", ret);
        return(-1);
    }
    if(ret == 0)
    {
        printf("no immed completion.\n");
        ret = block_on_job(tmp_id, NULL, &jstat, context);
        if(ret < 0)
        {
            PVFS_perror("block_on_job()", ret);
            return(-1);
        }
    }
    else
    {
        printf("immed completion.\n");
    }

    if(jstat.error_code != 0)
    {
        PVFS_perror("job_bmi_unexp() error code", jstat.error_code);
        return(-1);
    }

    printf("Got message: size: %d, tag: %d, payload: %s\n",
           info.size, (int)info.tag, (char*)info.buffer);

    PINT_dev_release_unexpected(&info);

    /* try writing a list message */
    buffer_list[0] = buf1;
    buffer_list[1] = buf2;
    size_list[0] = strlen(buf1);
    size_list[1] = strlen(buf1) + 1;

    ret = job_dev_write_list(buffer_list, size_list, 2, (strlen(buf1) +
                             strlen(buf2) + 1), 7, PINT_DEV_EXT_ALLOC, NULL, 0, &jstat, &tmp_id,
                             context);
    if(ret < 0)
    {
        PVFS_perror("job_dev_write_list()", ret);
        return(-1);
    }
    if(ret == 0)
    {
        printf("no immed completion.\n");
        ret = block_on_job(tmp_id, NULL, &jstat, context);
        if(ret < 0)
        {
            PVFS_perror("block_on_job()", ret);
            return(-1);
        }
    }
    else
    {
        printf("immed completion.\n");
    }

    if(jstat.error_code != 0)
    {
        PVFS_perror("job_bmi_write_list() error code", jstat.error_code);
        return(-1);
    }

    job_close_context(context);
    job_finalize();
    PINT_dev_finalize();
    PINT_flow_finalize();
    BMI_finalize();

    return(0);
}
Ejemplo n.º 7
0
int main(int argc, char **argv)	
{

	int ret = -1;
	struct ack_foo* ack = NULL;
	job_status_s status1;
	struct BMI_unexpected_info req_info;
	job_id_t job_id;
	int outcount;
	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", "tcp://NULL:3414", BMI_INIT_SERVER);
	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 flow interface */
	ret = PINT_flow_initialize("flowproto_multiqueue", 0);
	if(ret < 0)
	{
		fprintf(stderr, "flow_init 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);
	}



	/* post a job for unexpected receive */
	ret = job_bmi_unexp(&req_info, NULL, 0, &status1, &job_id, 0, context);
	if(ret < 0)
	{
		fprintf(stderr, "job_bmi_unexp() failure.\n");
		return(-1);
	}
	if(ret != 1)
	{
#if 0
		/* exercise testworld() interface, block indefinitely */
		outcount = 1;
		ret = job_testworld(&job_id, &outcount, NULL, &status1, -1);
		if(ret < 0 || outcount == 0)
		{	
			fprintf(stderr, "job_testworld() failure.\n");
			return(-1);
		}

		/* alternatively, try out the testsome interface */
		outcount = 1;
		ret = job_testsome(&job_id, &outcount, &foo, NULL, &status1, -1);
		if(ret < 0 || outcount == 0)
		{
			fprintf(stderr, "job_testsome() failure.\n");
			return(-1);
		}
#else

		/* ... or maybe even give job_test() a whirl */
		ret = job_test(job_id, &outcount, NULL, &status1, 5000, context);
		if(ret < 0 || outcount == 0)
		{
			fprintf(stderr, "job_test() failure.\n");
			return(-1);
		}

#endif
	}

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

	/* allocate a buffer for the ack */
	ack = BMI_memalloc(req_info.addr, sizeof(struct ack_foo),
		BMI_SEND);
	if(!ack)
	{
		fprintf(stderr, "BMI_memalloc failure.\n");
		return(-1);
	}

	/* send a message */
	ret = job_bmi_send(req_info.addr, ack, sizeof(struct ack_foo),
		0, BMI_PRE_ALLOC, 0, 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);
	}

	BMI_memfree(req_info.addr, ack, sizeof(struct ack_foo), BMI_RECV);
	BMI_unexpected_free(req_info.addr, req_info.buffer);

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

	return(0);
}