1RFIO_PRESEEK(3)             Rfio Library Functions             RFIO_PRESEEK(3)
2
3
4

NAME

6       rfio_preseek - prefetch chunks of data from a file
7

SYNOPSIS

9       #include <sys/types.h>
10       #include "rfio_api.h"
11
12       int rfio_preseek (int s, const struct iovec *iov, int iovnb);
13
14       Under Linux, for large files:
15       #define _LARGEFILE64_SOURCE
16       #include <sys/types.h>
17       #include "rfio_api.h"
18
19       int rfio_preseek64 (int s, const struct iovec64 *iov, int iovnb);
20
21       For large files, under other systems:
22       #include <sys/types.h>
23       #include "rfio_api.h"
24
25       int rfio_preseek64 (int s, const struct iovec64 *iov, int iovnb);
26

DESCRIPTION

28       rfio_preseek  prefetches chunks of data at given offsets into an inter‐
29       nal buffer (on the client side), using the descriptor s generated by  a
30       previous rfio_open.  The actual offset values and the lengths are given
31       in the array of structures iov.  The number of chunks is  specified  by
32       iovnb.
33
34       rfio_preseek64  does  the  prefetch  for large files, using an array of
35       structures of type iovec64 rather than an array of iovec.
36
37       RFIO_READOPT must be set to RFIO_READBUF, which is  the  default.   The
38       default  internal buffer size is 128 kB, but the buffer size can be set
39       with an entry RFIO IOBUFSIZE in shift.conf.  Then  rfio_read  gets  the
40       data from that buffer.
41

EXAMPLES

43       /*   tpreseek - write NBRECORDS_TOWRITE records and
44                 read back NBRECORDS_TOREAD using the rfio_preseek function */
45
46       #include <fcntl.h>
47       #include <stdio.h>
48       #if defined(_WIN32)
49       #include <winsock2.h>
50       #endif
51       #include "rfio_api.h"
52       #define NBRECORDS_TOREAD 5
53       #define NBRECORDS_TOWRITE 10
54
55       main(argc, argv)
56       int argc;
57       char **argv;
58       {
59            char buf[65536];
60            int errflg = 0;
61            int fd;
62            int i;
63            struct iovec iov[NBRECORDS_TOREAD];
64            int iovnb = NBRECORDS_TOREAD;
65            int j;
66            static int lengths[NBRECORDS_TOWRITE] = {4096, 32768, 16384, 8192,
67                              65536, 32768, 16384, 4096, 65536, 8192};
68            static int records_toread[NBRECORDS_TOREAD] = {2, 4, 5, 8, 9};
69       #if defined(_WIN32)
70            WSADATA wsadata;
71       #endif
72
73            if (argc != 2) {
74                 fprintf (stderr, "usage: tpreseek pathname\n");
75                 exit (1);
76            }
77       #if defined(_WIN32)
78            if (WSAStartup (MAKEWORD (2, 0), &wsadata)) {
79                 fprintf (stderr, "WSAStartup unsuccessful\n");
80                 exit (2);
81            }
82       #endif
83            while (! errflg) {
84
85                 /* Write variable length records.
86                  * Each record is filled with the record index
87                  */
88
89                 if ((fd = rfio_open (argv[1],
90                          O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
91                      rfio_perror ("rfio_open");
92                      errflg++;
93                      break;
94                 }
95                 for (j = 0; j < NBRECORDS_TOWRITE; j++) {
96                      for (i = 0; i < lengths[j]; i++)
97                           buf[i] = j;
98                      if (rfio_write (fd, buf, lengths[j]) < 0) {
99                           rfio_perror ("rfio_write");
100                           errflg++;
101                           break;
102                      }
103                 }
104                 (void)rfio_close (fd);
105                 if (errflg) break;
106
107                 /* Prefetch a few records: the actual offsets and lengths
108                  * of the records is set in the array of iov structures
109                  */
110
111                 if ((fd = rfio_open (argv[1], O_RDONLY)) < 0) {
112                      rfio_perror ("rfio_open");
113                      errflg++;
114                      break;
115                 }
116                 for (j = 0; j < NBRECORDS_TOREAD; j++) {
117                      /* compute record offset */
118                      iov[j].iov_base = 0;
119                      for (i = 0; i < records_toread[j]; i++)
120                           iov[j].iov_base = (char *) iov[j].iov_base +
121                               lengths[i];
122                      /* set length */
123                      iov[j].iov_len = lengths[records_toread[j]];
124                 }
125                 if (rfio_preseek (fd, iov, iovnb) < 0) {
126                      rfio_perror ("rfio_preseek");
127                      errflg++;
128                      break;
129                 }
130
131                 /* Read back the records and check their cpntents */
132
133                 for (j = 0; j < NBRECORDS_TOREAD; j++) {
134                      if (rfio_lseek (fd, (off_t) iov[j].iov_base,
135                          SEEK_SET) < 0) {
136                           rfio_perror ("rfio_lseek");
137                           errflg++;
138                           break;
139                      }
140                      if (rfio_read (fd, buf, iov[j].iov_len) < 0) {
141                           rfio_perror ("rfio_read");
142                           errflg++;
143                           break;
144                      }
145                      for (i = 0; i < iov[j].iov_len; i++) {
146                           if (buf[i] != records_toread[j]) {
147                                fprintf (stderr,
148                                    "incorrect data read, record %d\n",
149                                    records_toread[j]);
150                                errflg++;
151                                break;
152                           }
153                      }
154                      if (errflg) break;
155                 }
156                 (void) rfio_close (fd);
157                 break;
158            }
159            if (rfio_unlink (argv[1]) < 0) {
160                 rfio_perror ("rfio_unlink");
161                 errflg++;
162            }
163       #if defined(_WIN32)
164            WSACleanup();
165       #endif
166            exit (errflg ? 1 : 0);
167       }
168

RETURN VALUE

170       This  routine  returns  0  if the operation was successful or -1 if the
171       operation failed. In the latter case, serrno is set appropriately.
172

ERRORS

174       EBADF        s is not a valid descriptor.
175
176       EINVAL       RFIO_READOPT is not set to RFIO_READBUF.
177
178       SENOSHOST    Host unknown.
179
180       SENOSSERV    Service unknown.
181
182       SETIMEDOUT   Timed out.
183
184       SEBADVERSION Version ID mismatch.
185
186       SECONNDROP   Connection closed by remote end.
187
188       SECOMERR     Communication error.
189
190       SENORCODE    Host did not return error number.
191

SEE ALSO

193       rfio_lseek(3), rfio_open(3), rfio_read(3)
194

AUTHOR

196       LCG Grid Deployment Team
197
198
199
200LCG                      $Date: 2005/03/31 13:13:03 $          RFIO_PRESEEK(3)
Impressum