| 1 | #ifndef __TROVE_TEST_H |
|---|
| 2 | #define __TROVE_TEST_H |
|---|
| 3 | |
|---|
| 4 | #include "pvfs2-internal.h" |
|---|
| 5 | |
|---|
| 6 | enum { |
|---|
| 7 | SSPACE_SIZE = 64, |
|---|
| 8 | FS_SIZE = 64, |
|---|
| 9 | PATH_SIZE = 256, |
|---|
| 10 | FS_COLL_ID = 9, |
|---|
| 11 | ADMIN_COLL_ID = 10 |
|---|
| 12 | }; |
|---|
| 13 | |
|---|
| 14 | enum { |
|---|
| 15 | TROVE_TEST_DIR = 1, |
|---|
| 16 | TROVE_TEST_FILE = 2, |
|---|
| 17 | TROVE_TEST_BSTREAM = 3 |
|---|
| 18 | }; |
|---|
| 19 | |
|---|
| 20 | static inline int path_lookup( |
|---|
| 21 | TROVE_coll_id coll_id, |
|---|
| 22 | /*TROVE_context_id context_id, FIXME: Hacked for now...uses 0*/ |
|---|
| 23 | char *path, |
|---|
| 24 | TROVE_handle *out_handle_p) |
|---|
| 25 | { |
|---|
| 26 | int i=0, ret, count, path_off=0; |
|---|
| 27 | TROVE_ds_state state; |
|---|
| 28 | TROVE_keyval_s key, val; |
|---|
| 29 | TROVE_op_id op_id; |
|---|
| 30 | TROVE_handle handle, parent_handle; |
|---|
| 31 | TROVE_ds_attributes_s s_attr; |
|---|
| 32 | char dir[PATH_SIZE]; |
|---|
| 33 | TROVE_context_id context_id = 0; /* FIXME: Hacked for now */ |
|---|
| 34 | |
|---|
| 35 | /* get root handle */ |
|---|
| 36 | key.buffer = ROOT_HANDLE_KEYSTR; |
|---|
| 37 | key.buffer_sz = ROOT_HANDLE_KEYLEN; |
|---|
| 38 | val.buffer = &handle; |
|---|
| 39 | val.buffer_sz = sizeof(handle); |
|---|
| 40 | ret = trove_collection_geteattr( |
|---|
| 41 | coll_id, &key, &val, 0, NULL, context_id, &op_id); |
|---|
| 42 | while (ret == 0) ret = trove_dspace_test( |
|---|
| 43 | coll_id, op_id, context_id, &count, NULL, NULL, &state, |
|---|
| 44 | TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 45 | if (ret < 0) { |
|---|
| 46 | fprintf(stderr, "collection geteattr (for root handle) failed.\n"); |
|---|
| 47 | return -1; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | #if 0 |
|---|
| 51 | printf("path_lookup: looking up %s, root handle is %d\n", path, (int) handle); |
|---|
| 52 | #endif |
|---|
| 53 | |
|---|
| 54 | for (;;) { |
|---|
| 55 | parent_handle = handle; |
|---|
| 56 | while (path[path_off] == '/') path_off++; /* get past leading "/"s */ |
|---|
| 57 | if (path[path_off] == 0) break; |
|---|
| 58 | |
|---|
| 59 | /* chop off the next part of the path */ |
|---|
| 60 | i = 0; |
|---|
| 61 | while (path[path_off] != 0 && path[path_off] != '/') { |
|---|
| 62 | dir[i] = path[path_off++]; |
|---|
| 63 | i++; |
|---|
| 64 | } |
|---|
| 65 | dir[i] = 0; |
|---|
| 66 | |
|---|
| 67 | key.buffer = dir; |
|---|
| 68 | key.buffer_sz = strlen(dir) + 1; /* including terminator...maybe we shouldn't do that? */ |
|---|
| 69 | val.buffer = &handle; |
|---|
| 70 | val.buffer_sz = sizeof(handle); |
|---|
| 71 | ret = trove_keyval_read( |
|---|
| 72 | coll_id, parent_handle, &key, &val, 0, |
|---|
| 73 | NULL, NULL, context_id, &op_id, NULL); |
|---|
| 74 | while (ret == 0) ret = trove_dspace_test( |
|---|
| 75 | coll_id, op_id, context_id, &count, NULL, NULL, &state, |
|---|
| 76 | TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 77 | if (ret < 0) { |
|---|
| 78 | fprintf(stderr, "keyval read failed.\n"); |
|---|
| 79 | return -1; |
|---|
| 80 | } |
|---|
| 81 | if (state != 0) { |
|---|
| 82 | fprintf(stderr, "keyval read failed.\n"); |
|---|
| 83 | return -1; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /* TODO: verify that this is in fact a directory! */ |
|---|
| 87 | ret = trove_dspace_getattr( |
|---|
| 88 | coll_id, handle, &s_attr, 0, NULL, context_id, &op_id, NULL); |
|---|
| 89 | while (ret == 0) ret = trove_dspace_test( |
|---|
| 90 | coll_id, op_id, context_id, &count, NULL, NULL, &state, |
|---|
| 91 | TROVE_DEFAULT_TEST_TIMEOUT); |
|---|
| 92 | if (ret < 0) return -1; |
|---|
| 93 | if (state != 0) return -1; |
|---|
| 94 | |
|---|
| 95 | if ((int)s_attr.type != TROVE_TEST_DIR) { |
|---|
| 96 | fprintf(stderr, "%s is not a directory.\n", dir); |
|---|
| 97 | return -1; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | #if 0 |
|---|
| 101 | printf(" path_lookup: handle for path component %s is %d\n", dir, (int) handle); |
|---|
| 102 | #endif |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | *out_handle_p = handle; |
|---|
| 106 | return 0; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | #endif |
|---|