root/branches/cu-security-branch/test/io/flow/test-bmi-cache-server.c @ 8397

Revision 8397, 9.1 KB (checked in by nlmills, 3 years ago)

initial merge with Orange-Branch. much will be broken

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7/* this is a simple test harness that operates on top of the flow
8 * interface
9 */
10
11#include <errno.h>
12#include <stdio.h>
13#include <string.h>
14#include <sys/time.h>
15#include <unistd.h>
16#include <time.h>
17
18#include "gossip.h"
19#include "flow.h"
20#include "flowproto-support.h"
21#include "pint-distribution.h"
22#include "pvfs2-request.h"
23
24#include "trove.h"
25#include "pvfs2-internal.h"
26
27static int block_on_flow(
28    flow_descriptor * flow_d);
29static double Wtime(
30    void);
31int path_lookup(
32    TROVE_coll_id coll_id,
33    TROVE_context_id trove_context,
34    char *path,
35    TROVE_handle * out_handle_p);
36
37enum
38{
39    TEST_SIZE = 1024 * 1024,
40    SSPACE_SIZE = 64,
41    FS_SIZE = 64,
42    PATH_SIZE = 256,
43    FS_COLL_ID = 9,
44    ADMIN_COLL_ID = 10
45};
46
47enum
48{
49    TROVE_TEST_DIR = 1,
50    TROVE_TEST_FILE = 2,
51    TROVE_TEST_BSTREAM = 3
52};
53
54char storage_space[SSPACE_SIZE] = "/tmp/pvfs2-test-space";
55char file_system[FS_SIZE] = "pvfs2-fs";
56char path_to_file[PATH_SIZE] = "/bar";
57TROVE_handle requested_file_handle = 4095;
58
59int main(
60    int argc,
61    char **argv)
62{
63    int ret = -1;
64    int outcount = 0, count;
65    struct BMI_unexpected_info request_info;
66    flow_descriptor *flow_d = NULL;
67    double time1, time2;
68    int i;
69    PINT_Request *req;
70    char path_name[PATH_SIZE];
71    TROVE_op_id op_id;
72    TROVE_coll_id coll_id;
73    TROVE_handle file_handle, parent_handle;
74    TROVE_ds_state state;
75    char *file_name;
76    TROVE_keyval_s key, val;
77    bmi_context_id context;
78    TROVE_context_id trove_context;
79    PVFS_handle_extent cur_extent;
80    PVFS_handle_extent_array extent_array;
81
82        /*************************************************************/
83    /* initialization stuff */
84
85    /* set debugging level */
86    gossip_enable_stderr();
87    gossip_set_debug_mask(0, GOSSIP_FLOW_PROTO_DEBUG | GOSSIP_BMI_DEBUG_TCP );
88
89    /* start up BMI */
90    ret = BMI_initialize("bmi_tcp", "tcp://NULL:3335", BMI_INIT_SERVER);
91    if (ret < 0)
92    {
93        fprintf(stderr, "BMI init failure.\n");
94        return (-1);
95    }
96
97    ret = BMI_open_context(&context);
98    if (ret < 0)
99    {
100        fprintf(stderr, "BMI_open_context() failure.\n");
101        return (-1);
102    }
103
104    ret = trove_initialize(
105        TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0);
106    if (ret < 0)
107    {
108        fprintf(stderr, "initialize failed: run trove-mkfs first.\n");
109        return -1;
110    }
111
112    /* initialize the flow interface. protocol specific */
113    ret = PINT_flow_initialize("flowproto_bmi_cache", 0);
114    if (ret < 0)
115    {
116        fprintf(stderr, "flow init failure.\n");
117        return (-1);
118    }
119
120    /* try to look up collection used to store file system */
121    ret = trove_collection_lookup(
122        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
123    if (ret < 0)
124    {
125        fprintf(stderr, "collection lookup failed.\n");
126        return -1;
127    }
128
129    ret = trove_open_context(coll_id, &trove_context);
130    if (ret < 0)
131    {
132        fprintf(stderr, "TROVE_open_context() failure.\n");
133        return (-1);
134    }
135
136    /* find the parent directory name */
137    strcpy(path_name, path_to_file);
138    for (i = strlen(path_name); i >= 0; i--)
139    {
140        if (path_name[i] != '/')
141            path_name[i] = '\0';
142        else
143            break;
144    }
145    file_name = path_to_file + strlen(path_name);
146    printf("path is %s\n", path_name);
147    printf("file is %s\n", file_name);
148
149    /* find the parent directory handle */
150    ret = path_lookup(coll_id, trove_context, path_name, &parent_handle);
151    if (ret < 0)
152    {
153        return -1;
154    }
155
156    file_handle = 0;
157
158    cur_extent.first = cur_extent.last = requested_file_handle;
159    extent_array.extent_count = 1;
160    extent_array.extent_array = &cur_extent;
161    ret = trove_dspace_create(coll_id,
162                              &extent_array,
163                              &file_handle,
164                              TROVE_TEST_FILE,
165                              NULL,
166                                TROVE_FORCE_REQUESTED_HANDLE,
167                                NULL, trove_context, &op_id, NULL);
168    while (ret == 0)
169        ret =
170            trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
171                              &state, TROVE_DEFAULT_TEST_TIMEOUT);
172    if (ret < 0)
173    {
174        fprintf(stderr, "dspace create failed.\n");
175        return -1;
176    }
177
178    /* TODO: set attributes of file? */
179
180    /* add new file name/handle pair to parent directory */
181    key.buffer = file_name;
182    key.buffer_sz = strlen(file_name) + 1;
183    val.buffer = &file_handle;
184    val.buffer_sz = sizeof(file_handle);
185    ret =
186        trove_keyval_write(coll_id, parent_handle, &key, &val, 0, NULL, NULL,
187                           trove_context, &op_id, NULL);
188    while (ret == 0)
189        ret =
190            trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
191                              &state, TROVE_DEFAULT_TEST_TIMEOUT);
192    if (ret < 0)
193    {
194        fprintf(stderr, "keyval write failed.\n");
195        return -1;
196    }
197
198
199    /* wait for an initial communication via BMI */
200    /* we don't give a crap about that message except that it tells us
201     * where to find the client
202     */
203    do
204    {
205        ret = BMI_testunexpected(1, &outcount, &request_info, 10);
206    } while (ret == 0 && outcount == 0);
207    if (ret < 0 || request_info.error_code != 0)
208    {
209        fprintf(stderr, "waitunexpected failure.\n");
210        return (-1);
211    }
212    BMI_unexpected_free(request_info.addr, request_info.buffer);
213
214        /******************************************************/
215    /* setup request/dist stuff */
216
217    /* request description */
218    /* just want one contiguous region */
219    ret = PVFS_Request_contiguous(TEST_SIZE, PVFS_BYTE, &req);
220    if (ret < 0)
221    {
222        fprintf(stderr, "PVFS_Request_contiguous() failure.\n");
223        return (-1);
224    }
225
226
227        /******************************************************/
228    /* setup communicaton stuff */
229
230    /* create a flow descriptor */
231    flow_d = PINT_flow_alloc();
232    if (!flow_d)
233    {
234        fprintf(stderr, "flow_alloc failed.\n");
235        return (-1);
236    }
237
238    /* file data */
239    flow_d->file_data.fsize = TEST_SIZE;
240    flow_d->file_data.server_nr = 0;
241    flow_d->file_data.server_ct = 1;
242    flow_d->file_data.extend_flag = 1;
243    flow_d->file_data.dist = PINT_dist_create("basic_dist");
244    if (!flow_d->file_data.dist)
245    {
246        fprintf(stderr, "Error: failed to create dist.\n");
247        return (-1);
248    }
249    ret = PINT_dist_lookup(flow_d->file_data.dist);
250    if (ret != 0)
251    {
252        fprintf(stderr, "Error: failed to lookup dist.\n");
253        return (-1);
254    }
255    flow_d->file_req = req;
256    flow_d->tag = 0;
257    flow_d->user_ptr = NULL;
258    flow_d->aggregate_size = TEST_SIZE;
259
260    /* fill in flow details */
261    flow_d->src.endpoint_id = BMI_ENDPOINT;
262    flow_d->src.u.bmi.address = request_info.addr;
263    flow_d->dest.endpoint_id = TROVE_ENDPOINT;
264    flow_d->dest.u.trove.handle = file_handle;
265    flow_d->dest.u.trove.coll_id = coll_id;
266
267        /***************************************************
268         * test bmi to file (analogous to a client side write)
269         */
270
271    time1 = Wtime();
272    ret = block_on_flow(flow_d);
273    if (ret < 0)
274    {
275        return (-1);
276    }
277    time2 = Wtime();
278
279#if 0
280    printf("Server bw (recv): %f MB/sec\n",
281           ((TEST_SIZE) / ((time2 - time1) * 1000000.0)));
282#endif
283
284        /*******************************************************/
285    /* final cleanup and output */
286
287    PINT_flow_free(flow_d);
288
289    /* shut down flow interface */
290    ret = PINT_flow_finalize();
291    if (ret < 0)
292    {
293        fprintf(stderr, "flow finalize failure.\n");
294        return (-1);
295    }
296
297    /* shut down BMI */
298    BMI_close_context(context);
299    BMI_finalize();
300
301    trove_close_context(coll_id, trove_context);
302    trove_finalize(TROVE_METHOD_DBPF);
303
304    gossip_disable();
305    return (0);
306}
307
308static int done_flag = 0;
309static void callback_fn(flow_descriptor* flow_d)
310{
311    done_flag = 1;
312    return;
313}
314
315static int block_on_flow(
316    flow_descriptor * flow_d)
317{
318    int ret = -1;
319    struct timespec req = {0, 1000};
320
321    flow_d->callback = (void*)callback_fn;
322    ret = PINT_flow_post(flow_d);
323    if (ret == 1)
324    {
325        return (0);
326    }
327    if (ret < 0)
328    {
329        fprintf(stderr, "flow post failure.\n");
330        return (ret);
331    }
332
333    while(!done_flag)
334    {
335        nanosleep(&req, NULL);
336    }
337
338    if (flow_d->state != FLOW_COMPLETE)
339    {
340        fprintf(stderr, "flow finished in error state: %d\n", flow_d->state);
341        return (-1);
342    }
343    return (0);
344}
345
346static double Wtime(
347    void)
348{
349    struct timeval t;
350
351    gettimeofday(&t, NULL);
352    return ((double) t.tv_sec + (double) t.tv_usec / 1000000);
353}
354
355int path_lookup(
356    TROVE_coll_id coll_id,
357    TROVE_context_id trove_context,
358    char *path,
359    TROVE_handle * out_handle_p)
360{
361    int ret, count;
362    TROVE_ds_state state;
363    TROVE_keyval_s key, val;
364    TROVE_op_id op_id;
365    TROVE_handle handle;
366
367    /* get root */
368    key.buffer = ROOT_HANDLE_KEYSTR;
369    key.buffer_sz = ROOT_HANDLE_KEYLEN;
370    val.buffer = &handle;
371    val.buffer_sz = sizeof(handle);
372
373    ret = trove_collection_geteattr(coll_id, &key, &val, 0,
374                                    NULL, trove_context, &op_id);
375    while (ret == 0)
376        ret =
377            trove_dspace_test(coll_id, op_id, trove_context, &count, NULL, NULL,
378                              &state, TROVE_DEFAULT_TEST_TIMEOUT);
379    if (ret < 0)
380    {
381        fprintf(stderr, "collection geteattr (for root handle) failed.\n");
382        return -1;
383    }
384
385    /* TODO: handle more than just a root handle! */
386
387    *out_handle_p = handle;
388    return 0;
389}
390
391/*
392 * Local variables:
393 *  c-indent-level: 4
394 *  c-basic-offset: 4
395 * End:
396 *
397 * vim: ts=8 sts=4 sw=4 expandtab
398 */
Note: See TracBrowser for help on using the browser.