1RFIO_PRESEEK(3) Rfio Library Functions
2RFIO_PRESEEK(3)
3
4
5
6[1mNAME[0m
7 rfio_preseek ‐ prefetch chunks of data from a file
8
9[1mSYNOPSIS[0m
10 [1m#include <sys/types.h>[0m
11 [1m#include "rfio_api.h"[0m
12
13 [1mint rfio_preseek (int [4m[22ms[24m[1m, const struct
14iovec *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m
15
16 Under Linux, for large files:
17 [1m#define _LARGEFILE64_SOURCE[0m
18 [1m#include <sys/types.h>[0m
19 [1m#include "rfio_api.h"[0m
20
21 [1mint rfio_preseek64 (int [4m[22ms[24m[1m, const struct
22iovec64 *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m
23
24 For large files, under other systems:
25 [1m#include <sys/types.h>[0m
26 [1m#include "rfio_api.h"[0m
27
28 [1mint rfio_preseek64 (int [4m[22ms[24m[1m, const struct
29iovec64 *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m
30
31[1mDESCRIPTION[0m
32 [1mrfio_preseek [22mprefetches chunks of data at given
33offsets into an inter‐
34 nal buffer (on the client side), using the descriptor [1ms
35[22mgenerated by a
36 previous [1mrfio_open[22m. The actual offset values and
37the lengths are given
38 in the array of structures [1miov[22m. The number of
39chunks is specified by
40 [1miovnb[22m.
41
42 [1mrfio_preseek64 [22mdoes the prefetch for large
43files, using an array of
44 structures of type [1miovec64 [22mrather than an array of
45[1miovec[22m.
46
47 [1mRFIO_READOPT [22mmust be set to RFIO_READBUF, which is
48the default. The
49 default internal buffer size is 128 kB, but the buffer
50size can be set
51 with an entry RFIO IOBUFSIZE in [1mshift.conf[22m. Then
52[1mrfio_read [22mgets the
53 data from that buffer.
54
55[1mEXAMPLES[0m
56 /* tpreseek ‐ write NBRECORDS_TOWRITE records and
57 read back NBRECORDS_TOREAD using the rfio_pre‐
58seek function */
59
60 #include <fcntl.h>
61 #include <stdio.h>
62 #if defined(_WIN32)
63 #include <winsock2.h>
64 #endif
65 #include "rfio_api.h"
66 #define NBRECORDS_TOREAD 5
67 #define NBRECORDS_TOWRITE 10
68
69 main(argc, argv)
70 int argc;
71 char **argv;
72 {
73 char buf[65536];
74 int errflg = 0;
75 int fd;
76 int i;
77 struct iovec iov[NBRECORDS_TOREAD];
78 int iovnb = NBRECORDS_TOREAD;
79 int j;
80 static int lengths[NBRECORDS_TOWRITE] = {4096, 32768,
8116384, 8192,
82 65536, 32768, 16384, 4096, 65536,
838192};
84 static int records_toread[NBRECORDS_TOREAD] = {2, 4,
855, 8, 9};
86 #if defined(_WIN32)
87 WSADATA wsadata;
88 #endif
89
90 if (argc != 2) {
91 fprintf (stderr, "usage: tpreseek pathname0);
92 exit (1);
93 }
94 #if defined(_WIN32)
95 if (WSAStartup (MAKEWORD (2, 0), &wsadata)) {
96 fprintf (stderr, "WSAStartup unsuccessful0);
97 exit (2);
98 }
99 #endif
100 while (! errflg) {
101
102 /* Write variable length records.
103 * Each record is filled with the record index
104 */
105
106 if ((fd = rfio_open (argv[1],
107 O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
108 rfio_perror ("rfio_open");
109 errflg++;
110 break;
111 }
112 for (j = 0; j < NBRECORDS_TOWRITE; j++) {
113 for (i = 0; i < lengths[j]; i++)
114 buf[i] = j;
115 if (rfio_write (fd, buf, lengths[j]) < 0) {
116 rfio_perror ("rfio_write");
117 errflg++;
118 break;
119 }
120 }
121 (void)rfio_close (fd);
122 if (errflg) break;
123
124 /* Prefetch a few records: the actual offsets
125and lengths
126 * of the records is set in the array of iov
127structures
128 */
129
130 if ((fd = rfio_open (argv[1], O_RDONLY)) < 0) {
131 rfio_perror ("rfio_open");
132 errflg++;
133 break;
134 }
135 for (j = 0; j < NBRECORDS_TOREAD; j++) {
136 /* compute record offset */
137 iov[j].iov_base = 0;
138 for (i = 0; i < records_toread[j]; i++)
139 iov[j].iov_base = (char *)
140iov[j].iov_base +
141 lengths[i];
142 /* set length */
143 iov[j].iov_len = lengths[records_tore‐
144ad[j]];
145 }
146 if (rfio_preseek (fd, iov, iovnb) < 0) {
147 rfio_perror ("rfio_preseek");
148 errflg++;
149 break;
150 }
151
152 /* Read back the records and check their cpn‐
153tents */
154
155 for (j = 0; j < NBRECORDS_TOREAD; j++) {
156 if (rfio_lseek (fd, (off_t)
157iov[j].iov_base,
158 SEEK_SET) < 0) {
159 rfio_perror ("rfio_lseek");
160 errflg++;
161 break;
162 }
163 if (rfio_read (fd, buf, iov[j].iov_len) <
1640) {
165 rfio_perror ("rfio_read");
166 errflg++;
167 break;
168 }
169 for (i = 0; i < iov[j].iov_len; i++) {
170 if (buf[i] != records_toread[j]) {
171 fprintf (stderr,
172 "incorrect data read, record
173%d0,
174 records_toread[j]);
175 errflg++;
176 break;
177 }
178 }
179 if (errflg) break;
180 }
181 (void) rfio_close (fd);
182 break;
183 }
184 if (rfio_unlink (argv[1]) < 0) {
185 rfio_perror ("rfio_unlink");
186 errflg++;
187 }
188 #if defined(_WIN32)
189 WSACleanup();
190 #endif
191 exit (errflg ? 1 : 0);
192 }
193
194[1mRETURN VALUE[0m
195 This routine returns 0 if the operation was successful
196or ‐1 if the
197 operation failed. In the latter case, [1mserrno [22mis set
198appropriately.
199
200[1mERRORS[0m
201 [1mEBADF [4m[22ms[24m is not a valid descriptor.
202
203 [1mEINVAL [22mRFIO_READOPT is not set to RFIO_READ‐
204BUF.
205
206 [1mSENOSHOST [22mHost unknown.
207
208 [1mSENOSSERV [22mService unknown.
209
210 [1mSETIMEDOUT [22mTimed out.
211
212 [1mSEBADVERSION [22mVersion ID mismatch.
213
214 [1mSECONNDROP [22mConnection closed by remote end.
215
216 [1mSECOMERR [22mCommunication error.
217
218 [1mSENORCODE [22mHost did not return error number.
219
220[1mSEE ALSO[0m
221 [1mrfio_lseek(3)[22m, [1mrfio_open(3)[22m, [1mr‐
222fio_read(3)[0m
223
224[1mAUTHOR[0m
225 [1mLCG Grid Deployment [22mTeam
226
227
228
229LCG $Date: 2005/03/31 13:13:03 $
230RFIO_PRESEEK(3)
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264