root/branches/Orange-Branch/test/io/trove/trove-ls.c @ 7959

Revision 7959, 5.0 KB (checked in by dbonnie, 4 years ago)

Merge with work from this summer. Metadata and data storage spaces can now be located on different disks. Fixed a small bug in string encoding. Updated test code to reflect new Trove dual-storage space API. Genconfig updated as well as affected admin apps. In the correct branch this time.

Line 
1/*
2 * (C) 2002 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include <unistd.h>
8#include <string.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <getopt.h>
12
13#include <trove.h>
14#include "trove-test.h"
15#include "pvfs2-internal.h"
16
17char storage_space[SSPACE_SIZE] = "/tmp/trove-test-space";
18char file_system[FS_SIZE] = "fs-foo";
19char path_to_dir[PATH_SIZE] = "/";
20TROVE_handle requested_file_handle = 4095;
21
22int parse_args(int argc, char **argv);
23
24#define KEYVAL_ARRAY_LEN 10
25
26int main(int argc, char **argv)
27{
28    int ret, it_ret, ga_ret, num_processed, count, i,j;
29    TROVE_op_id op_id;
30    TROVE_coll_id coll_id;
31    TROVE_handle handle;
32    TROVE_ds_state state;
33    TROVE_keyval_s key[KEYVAL_ARRAY_LEN], val[KEYVAL_ARRAY_LEN];
34    TROVE_ds_position pos = TROVE_ITERATE_START;
35    char path_name[PATH_SIZE];
36    TROVE_ds_attributes_s s_attr;
37    TROVE_context_id trove_context = -1;
38
39    TROVE_handle ls_handle[KEYVAL_ARRAY_LEN];
40    char ls_name[KEYVAL_ARRAY_LEN][PATH_SIZE];
41
42    ret = parse_args(argc, argv);
43    if (ret < 0) {
44        fprintf(stderr, "argument parsing failed.\n");
45        return -1;
46    }
47
48    ret = trove_initialize(
49        TROVE_METHOD_DBPF, NULL, storage_space, storage_space, 0);
50    if (ret < 0) {
51        fprintf(stderr, "initialize failed.\n");
52        return -1;
53    }
54
55    /* try to look up collection used to store file system */
56    ret = trove_collection_lookup(
57        TROVE_METHOD_DBPF, file_system, &coll_id, NULL, &op_id);
58    if (ret < 0) {
59        fprintf(stderr, "collection lookup failed.\n");
60        return -1;
61    }
62
63    ret = trove_open_context(coll_id, &trove_context);
64    if (ret < 0)
65    {
66        fprintf(stderr, "trove_open_context failed\n");
67        return -1;
68    }
69
70    strcpy(path_name, path_to_dir);
71#if 0
72    printf("path is %s\n", path_name);
73#endif
74
75    /* find the directory handle */
76    ret = path_lookup(coll_id, path_name, &handle);
77    if (ret < 0) {
78        return -1;
79    }
80
81    /* TODO: verify that this is in fact a directory! */
82    ret = trove_dspace_getattr(coll_id,
83                               handle,
84                               &s_attr,
85                               0 /* flags */,
86                               NULL,
87                               trove_context,
88                               &op_id,
89                               NULL);
90    while (ret == 0) ret = trove_dspace_test(
91        coll_id, op_id, trove_context, &count, NULL, NULL, &state,
92        TROVE_DEFAULT_TEST_TIMEOUT);
93    if (ret < 0) return -1;
94
95    if (s_attr.type != TROVE_TEST_DIR) {
96        fprintf(stderr, "%s is not a directory.\n", path_name);
97        return -1;
98    }
99
100    /* iterate through keyvals in directory */
101
102    /* trove_keyval_iterate will let the caller know how much progress was made
103     * through the 'count' parameter.  The caller should check 'count' after
104     * calling trove_keval_iterate: if it is different, that means EOF reached
105     */
106
107    for (j=0; j< KEYVAL_ARRAY_LEN; j++ ) {
108            key[j].buffer = ls_name[j];
109            key[j].buffer_sz = PATH_SIZE;
110            val[j].buffer = &ls_handle[j];
111            val[j].buffer_sz = sizeof(ls_handle);
112    }
113
114    for (;;) {
115        num_processed = KEYVAL_ARRAY_LEN;
116        it_ret = trove_keyval_iterate(coll_id,
117                                      handle,
118                                      &pos,
119                                      key,
120                                      val,
121                                      &num_processed,
122                                      0,
123                                      NULL,
124                                      NULL,
125                                      trove_context,
126                                      &op_id,
127                                      NULL);
128        if (it_ret == -1) return -1;
129
130        while (it_ret == 0) it_ret = trove_dspace_test(
131            coll_id, op_id, trove_context, &count, NULL, NULL, &state,
132            TROVE_DEFAULT_TEST_TIMEOUT);
133        if (it_ret < 0) return -1;
134       
135        if (num_processed == 0) return 0;
136       
137        for(i = 0; i < num_processed; i++ ) {
138            TROVE_ds_attributes_s ds_attr;
139
140            ga_ret = trove_dspace_getattr(coll_id,
141                                          ls_handle[i],
142                                          &ds_attr,
143                                          0 /* flags */,
144                                          NULL,
145                                          trove_context,
146                                          &op_id,
147                                          NULL);
148            if (ga_ret == -1) return -1;
149            count = 1;
150            while (ga_ret == 0) ga_ret = trove_dspace_test(
151                coll_id, op_id, trove_context, &count, NULL, NULL, &state,
152                TROVE_DEFAULT_TEST_TIMEOUT);
153
154            printf("%s/%s (handle = %llu, uid = %d, gid = %d, perm = %o, type = %d)\n",
155                   path_name,
156                   (char *) key[i].buffer,
157                   llu(*(TROVE_handle *) val[i].buffer),
158                   (int) ds_attr.uid,
159                   (int) ds_attr.gid,
160                   ds_attr.mode,
161                   ds_attr.type);
162        }
163    }
164
165    trove_close_context(coll_id, trove_context);
166    trove_finalize(TROVE_METHOD_DBPF);
167   
168    return 0;
169}
170
171int parse_args(int argc, char **argv)
172{
173    int c;
174
175    while ((c = getopt(argc, argv, "s:c:p:")) != EOF) {
176        switch (c) {
177            case 's':
178                strncpy(storage_space, optarg, SSPACE_SIZE);
179                break;
180            case 'c': /* collection */
181                strncpy(file_system, optarg, FS_SIZE);
182                break;
183            case 'p':
184                strncpy(path_to_dir, optarg, PATH_SIZE);
185                break;
186            case '?':
187            default:
188                fprintf(stderr, "%s: [-c collection] [-p path]\n", argv[0]);
189                return -1;
190        }
191    }
192    return 0;
193}
194
195/*
196 * Local variables:
197 *  c-indent-level: 4
198 *  c-basic-offset: 4
199 * End:
200 *
201 * vim: ts=8 sts=4 sw=4 expandtab
202 */
Note: See TracBrowser for help on using the browser.