rfio_preseek man page

RFIO_PRESEEK(3) Rfio Library Functions RFIO_PRESEEK(3)

[1mNAME[0m
rfio_preseek - prefetch chunks of data from a file

[1mSYNOPSIS[0m
[1m#include <sys/types.h>[0m
[1m#include "rfio_api.h"[0m

[1mint rfio_preseek (int [4m[22ms[24m[1m, const struct iovec *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m

Under Linux, for large files:
[1m#define _LARGEFILE64_SOURCE[0m
[1m#include <sys/types.h>[0m
[1m#include "rfio_api.h"[0m

[1mint rfio_preseek64 (int [4m[22ms[24m[1m, const struct iovec64 *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m

For large files, under other systems:
[1m#include <sys/types.h>[0m
[1m#include "rfio_api.h"[0m

[1mint rfio_preseek64 (int [4m[22ms[24m[1m, const struct iovec64 *[4m[22miov[24m[1m, int [4m[22miovnb[24m[1m);[0m

[1mDESCRIPTION[0m
[1mrfio_preseek [22mprefetches chunks of data at given offsets into an inter-
nal buffer (on the client side), using the descriptor [1ms [22mgenerated by a
previous [1mrfio_open[22m. The actual offset values and the lengths are given
in the array of structures [1miov[22m. The number of chunks is specified by
[1miovnb[22m.

[1mrfio_preseek64 [22mdoes the prefetch for large files, using an array of
structures of type [1miovec64 [22mrather than an array of [1miovec[22m.

[1mRFIO_READOPT [22mmust be set to RFIO_READBUF, which is the default. The
default internal buffer size is 128 kB, but the buffer size can be set
with an entry RFIO IOBUFSIZE in [1mshift.conf[22m. Then [1mrfio_read [22mgets the
data from that buffer.

[1mEXAMPLES[0m
/* tpreseek - write NBRECORDS_TOWRITE records and
read back NBRECORDS_TOREAD using the rfio_preseek function */

#include <fcntl.h>
#include <stdio.h>
#if defined(_WIN32)
#include <winsock2.h>
#endif
#include "rfio_api.h"
#define NBRECORDS_TOREAD 5
#define NBRECORDS_TOWRITE 10

main(argc, argv)
int argc;
char **argv;
{
char buf[65536];
int errflg = 0;
int fd;
int i;
struct iovec iov[NBRECORDS_TOREAD];
int iovnb = NBRECORDS_TOREAD;
int j;
static int lengths[NBRECORDS_TOWRITE] = {4096, 32768, 16384, 8192,
65536, 32768, 16384, 4096, 65536, 8192};
static int records_toread[NBRECORDS_TOREAD] = {2, 4, 5, 8, 9};
#if defined(_WIN32)
WSADATA wsadata;
#endif

if (argc != 2) {
fprintf (stderr, "usage: tpreseek pathname0);
exit (1);
}
#if defined(_WIN32)
if (WSAStartup (MAKEWORD (2, 0), &wsadata)) {
fprintf (stderr, "WSAStartup unsuccessful0);
exit (2);
}
#endif
while (! errflg) {

/* Write variable length records.
* Each record is filled with the record index
*/

if ((fd = rfio_open (argv[1],
O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
rfio_perror ("rfio_open");
errflg++;
break;
}
for (j = 0; j < NBRECORDS_TOWRITE; j++) {
for (i = 0; i < lengths[j]; i++)
buf[i] = j;
if (rfio_write (fd, buf, lengths[j]) < 0) {
rfio_perror ("rfio_write");
errflg++;
break;
}
}
(void)rfio_close (fd);
if (errflg) break;

/* Prefetch a few records: the actual offsets and lengths
* of the records is set in the array of iov structures
*/

if ((fd = rfio_open (argv[1], O_RDONLY)) < 0) {
rfio_perror ("rfio_open");
errflg++;
break;
}
for (j = 0; j < NBRECORDS_TOREAD; j++) {
/* compute record offset */
iov[j].iov_base = 0;
for (i = 0; i < records_toread[j]; i++)
iov[j].iov_base = (char *) iov[j].iov_base +
lengths[i];
/* set length */
iov[j].iov_len = lengths[records_toread[j]];
}
if (rfio_preseek (fd, iov, iovnb) < 0) {
rfio_perror ("rfio_preseek");
errflg++;
break;
}

/* Read back the records and check their cpntents */

for (j = 0; j < NBRECORDS_TOREAD; j++) {
if (rfio_lseek (fd, (off_t) iov[j].iov_base,
SEEK_SET) < 0) {
rfio_perror ("rfio_lseek");
errflg++;
break;
}
if (rfio_read (fd, buf, iov[j].iov_len) < 0) {
rfio_perror ("rfio_read");
errflg++;
break;
}
for (i = 0; i < iov[j].iov_len; i++) {
if (buf[i] != records_toread[j]) {
fprintf (stderr,
"incorrect data read, record %d0,
records_toread[j]);
errflg++;
break;
}
}
if (errflg) break;
}
(void) rfio_close (fd);
break;
}
if (rfio_unlink (argv[1]) < 0) {
rfio_perror ("rfio_unlink");
errflg++;
}
#if defined(_WIN32)
WSACleanup();
#endif
exit (errflg ? 1 : 0);
}

[1mRETURN VALUE[0m
This routine returns 0 if the operation was successful or -1 if the
operation failed. In the latter case, [1mserrno [22mis set appropriately.

[1mERRORS[0m
[1mEBADF [4m[22ms[24m is not a valid descriptor.

[1mEINVAL [22mRFIO_READOPT is not set to RFIO_READBUF.

[1mSENOSHOST [22mHost unknown.

[1mSENOSSERV [22mService unknown.

[1mSETIMEDOUT [22mTimed out.

[1mSEBADVERSION [22mVersion ID mismatch.

[1mSECONNDROP [22mConnection closed by remote end.

[1mSECOMERR [22mCommunication error.

[1mSENORCODE [22mHost did not return error number.

[1mSEE ALSO[0m
[1mrfio_lseek(3)[22m, [1mrfio_open(3)[22m, [1mrfio_read(3)[0m

[1mAUTHOR[0m
[1mLCG Grid Deployment [22mTeam

LCG $Date: 2005/03/31 13:13:03 $ RFIO_PRESEEK(3)

Referenced By

rfio_preseek64(3) is an alias of rfio_preseek(3).