root/trunk/test/client/sysint/io-test.c @ 7500

Revision 7500, 6.2 KB (checked in by slang, 4 years ago)

fixes to tests to work with hints.

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include <time.h>
8#include "client.h"
9#include <sys/time.h>
10#include <unistd.h>
11#include <sys/types.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include <assert.h>
15#include "pvfs2-util.h"
16#include "pvfs2-mgmt.h"
17#include "pvfs2-internal.h"
18
19#define DEFAULT_IO_SIZE 8*1024*1024
20
21int main(int argc, char **argv)
22{
23    PVFS_sysresp_lookup resp_lk;
24    PVFS_sysresp_create resp_cr;
25    PVFS_sysresp_io resp_io;
26    char *filename = NULL;
27    int ret = -1, io_size = DEFAULT_IO_SIZE;
28    int *io_buffer = NULL;
29    int i, errors, buffer_size;
30    PVFS_fs_id fs_id;
31    char name[512] = {0};
32    char *entry_name = NULL;
33    PVFS_credentials credentials;
34    PVFS_object_ref parent_refn;
35    PVFS_sys_attr attr;
36    PVFS_object_ref pinode_refn;
37    PVFS_Request file_req;
38    PVFS_Request mem_req;
39    void *buffer = NULL;
40    PVFS_sysresp_getattr resp_getattr;
41    PVFS_handle *dfile_array = NULL;
42
43    if (argc != 2)
44    {
45        fprintf(stderr, "Usage: %s <file name>\n", argv[0]);
46        return (-1);
47    }
48
49    /* create a buffer for running I/O on */
50    io_buffer = (int *) malloc(io_size * sizeof(int));
51    if (!io_buffer)
52    {
53        return (-1);
54    }
55
56    /* put some data in the buffer so we can verify */
57    for (i = 0; i < io_size; i++)
58    {
59        io_buffer[i] = i;
60    }
61
62    ret = PVFS_util_init_defaults();
63    if (ret < 0)
64    {
65        PVFS_perror("PVFS_util_init_defaults", ret);
66        return (-1);
67    }
68    ret = PVFS_util_get_default_fsid(&fs_id);
69    if (ret < 0)
70    {
71        PVFS_perror("PVFS_util_get_default_fsid", ret);
72        return (-1);
73    }
74
75    if (argv[1][0] == '/')
76    {
77        snprintf(name, 512, "%s", argv[1]);
78    }
79    else
80    {
81        snprintf(name, 512, "/%s", argv[1]);
82    }
83
84    PVFS_util_gen_credentials(&credentials);
85    ret = PVFS_sys_lookup(fs_id, name, &credentials,
86                          &resp_lk, PVFS2_LOOKUP_LINK_FOLLOW, NULL);
87    if (ret == -PVFS_ENOENT)
88    {
89        PVFS_sysresp_getparent gp_resp;
90
91        printf("IO-TEST: lookup failed; creating new file.\n");
92
93        memset(&gp_resp, 0, sizeof(PVFS_sysresp_getparent));
94        ret = PVFS_sys_getparent(fs_id, name, &credentials, &gp_resp, NULL);
95        if (ret < 0)
96        {
97            PVFS_perror("PVFS_sys_getparent failed", ret);
98            return ret;
99        }
100
101        attr.owner = credentials.uid;
102        attr.group = credentials.gid;
103        attr.perms = PVFS_U_WRITE | PVFS_U_READ;
104        attr.atime = attr.ctime = attr.mtime = time(NULL);
105        attr.mask = PVFS_ATTR_SYS_ALL_SETABLE;
106        parent_refn = gp_resp.parent_ref;
107
108        entry_name = rindex(name, (int)'/');
109        assert(entry_name);
110        entry_name++;
111        assert(entry_name);
112
113        ret = PVFS_sys_create(entry_name, parent_refn, attr,
114                              &credentials, NULL, &resp_cr, NULL, NULL);
115        if (ret < 0)
116        {
117            PVFS_perror("PVFS_sys_create() failure", ret);
118            return (-1);
119        }
120
121        pinode_refn.fs_id = fs_id;
122        pinode_refn.handle = resp_cr.ref.handle;
123    }
124    else
125    {
126        printf("IO-TEST: lookup succeeded; performing I/O on "
127               "existing file.\n");
128
129        pinode_refn.fs_id = fs_id;
130        pinode_refn.handle = resp_lk.ref.handle;
131    }
132
133        /**************************************************************
134         * carry out I/O operation
135         */
136
137    printf("IO-TEST: performing write on handle: %ld, fs: %d\n",
138           (long) pinode_refn.handle, (int) pinode_refn.fs_id);
139
140    buffer = io_buffer;
141    buffer_size = io_size * sizeof(int);
142
143    /*
144      file datatype is tiled, so we can get away with a trivial type
145      here
146    */
147    file_req = PVFS_BYTE;
148
149    ret = PVFS_Request_contiguous(io_size * sizeof(int),
150                                  PVFS_BYTE, &(mem_req));
151    if (ret < 0)
152    {
153        PVFS_perror("PVFS_request_contiguous failure", ret);
154        return (-1);
155    }
156
157    ret = PVFS_sys_write(pinode_refn, file_req, 0, buffer, mem_req,
158                         &credentials, &resp_io, NULL);
159    if (ret < 0)
160    {
161        PVFS_perror("PVFS_sys_write failure", ret);
162        return (-1);
163    }
164
165    printf("IO-TEST: wrote %d bytes.\n", (int) resp_io.total_completed);
166
167    /* uncomment and try out the readback-and-verify stuff that follows
168     * once reading back actually works */
169    memset(io_buffer, 0, io_size * sizeof(int));
170
171    /* verify */
172    printf("IO-TEST: performing read on handle: %ld, fs: %d\n",
173           (long) pinode_refn.handle, (int) pinode_refn.fs_id);
174
175    ret = PVFS_sys_read(pinode_refn, file_req, 0, buffer, mem_req,
176                        &credentials, &resp_io, NULL);
177    if (ret < 0)
178    {
179        PVFS_perror("PVFS_sys_read failure", ret);
180        return (-1);
181    }
182    printf("IO-TEST: read %d bytes.\n", (int) resp_io.total_completed);
183    if ((io_size * sizeof(int)) != resp_io.total_completed)
184    {
185        fprintf(stderr, "Error: SHORT READ! skipping verification...\n");
186    }
187    else
188    {
189        errors = 0;
190        for (i = 0; i < io_size; i++)
191        {
192            if (i != io_buffer[i])
193            {
194                fprintf(stderr,
195                        "error: element %d differs: should be %d, is %d\n", i,
196                        i, io_buffer[i]);
197                errors++;
198            }
199        }
200        if (errors != 0)
201        {
202            fprintf(stderr, "ERROR: found %d errors\n", errors);
203        }
204        else
205        {
206            printf("IO-TEST: no errors found.\n");
207        }
208    }
209
210    /* test out some of the mgmt functionality */
211    ret = PVFS_sys_getattr(pinode_refn, PVFS_ATTR_SYS_ALL_NOSIZE,
212                           &credentials, &resp_getattr, NULL);
213    if (ret < 0)
214    {
215        PVFS_perror("PVFS_sys_getattr", ret);
216        return (-1);
217    }
218
219    printf("Target file had %d datafiles:\n", resp_getattr.attr.dfile_count);
220
221    dfile_array = (PVFS_handle *) malloc(resp_getattr.attr.dfile_count
222                                         * sizeof(PVFS_handle));
223    if (!dfile_array)
224    {
225        perror("malloc");
226        return (-1);
227    }
228
229    ret = PVFS_mgmt_get_dfile_array(pinode_refn, &credentials,
230                                    dfile_array, resp_getattr.attr.dfile_count, NULL);
231    if (ret < 0)
232    {
233        PVFS_perror("PVFS_mgmt_get_dfile_array", ret);
234        return (-1);
235    }
236    for (i = 0; i < resp_getattr.attr.dfile_count; i++)
237    {
238        printf("%llu\n", llu(dfile_array[i]));
239    }
240
241        /**************************************************************
242         * shut down pending interfaces
243         */
244
245    ret = PVFS_sys_finalize();
246    if (ret < 0)
247    {
248        fprintf(stderr, "Error: PVFS_sys_finalize() failed with errcode = %d\n",
249                ret);
250        return (-1);
251    }
252
253    free(filename);
254    free(io_buffer);
255    return (0);
256}
257
258/*
259 * Local variables:
260 *  c-indent-level: 4
261 *  c-basic-offset: 4
262 * End:
263 *
264 * vim: ts=8 sts=4 sw=4 expandtab
265 */
Note: See TracBrowser for help on using the browser.