@@ -290,10 +290,11 @@ test_sync(int writes_per_op)
290
290
for (ops = 0 ; alarm_triggered == false; ops ++ )
291
291
{
292
292
for (writes = 0 ; writes < writes_per_op ; writes ++ )
293
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
293
+ if (pg_pwrite (tmpfile ,
294
+ buf ,
295
+ XLOG_BLCKSZ ,
296
+ writes * XLOG_BLCKSZ ) != XLOG_BLCKSZ )
294
297
die ("write failed" );
295
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
296
- die ("seek failed" );
297
298
}
298
299
STOP_TIMER ;
299
300
close (tmpfile );
@@ -315,11 +316,12 @@ test_sync(int writes_per_op)
315
316
for (ops = 0 ; alarm_triggered == false; ops ++ )
316
317
{
317
318
for (writes = 0 ; writes < writes_per_op ; writes ++ )
318
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
319
+ if (pg_pwrite (tmpfile ,
320
+ buf ,
321
+ XLOG_BLCKSZ ,
322
+ writes * XLOG_BLCKSZ ) != XLOG_BLCKSZ )
319
323
die ("write failed" );
320
324
fdatasync (tmpfile );
321
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
322
- die ("seek failed" );
323
325
}
324
326
STOP_TIMER ;
325
327
close (tmpfile );
@@ -339,12 +341,13 @@ test_sync(int writes_per_op)
339
341
for (ops = 0 ; alarm_triggered == false; ops ++ )
340
342
{
341
343
for (writes = 0 ; writes < writes_per_op ; writes ++ )
342
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
344
+ if (pg_pwrite (tmpfile ,
345
+ buf ,
346
+ XLOG_BLCKSZ ,
347
+ writes * XLOG_BLCKSZ ) != XLOG_BLCKSZ )
343
348
die ("write failed" );
344
349
if (fsync (tmpfile ) != 0 )
345
350
die ("fsync failed" );
346
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
347
- die ("seek failed" );
348
351
}
349
352
STOP_TIMER ;
350
353
close (tmpfile );
@@ -362,12 +365,13 @@ test_sync(int writes_per_op)
362
365
for (ops = 0 ; alarm_triggered == false; ops ++ )
363
366
{
364
367
for (writes = 0 ; writes < writes_per_op ; writes ++ )
365
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
368
+ if (pg_pwrite (tmpfile ,
369
+ buf ,
370
+ XLOG_BLCKSZ ,
371
+ writes * XLOG_BLCKSZ ) != XLOG_BLCKSZ )
366
372
die ("write failed" );
367
373
if (pg_fsync_writethrough (tmpfile ) != 0 )
368
374
die ("fsync failed" );
369
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
370
- die ("seek failed" );
371
375
}
372
376
STOP_TIMER ;
373
377
close (tmpfile );
@@ -393,17 +397,17 @@ test_sync(int writes_per_op)
393
397
for (ops = 0 ; alarm_triggered == false; ops ++ )
394
398
{
395
399
for (writes = 0 ; writes < writes_per_op ; writes ++ )
396
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
397
-
400
+ if (pg_pwrite (tmpfile ,
401
+ buf ,
402
+ XLOG_BLCKSZ ,
403
+ writes * XLOG_BLCKSZ ) != XLOG_BLCKSZ )
398
404
/*
399
405
* This can generate write failures if the filesystem has
400
406
* a large block size, e.g. 4k, and there is no support
401
407
* for O_DIRECT writes smaller than the file system block
402
408
* size, e.g. XFS.
403
409
*/
404
410
die ("write failed" );
405
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
406
- die ("seek failed" );
407
411
}
408
412
STOP_TIMER ;
409
413
close (tmpfile );
@@ -457,11 +461,12 @@ test_open_sync(const char *msg, int writes_size)
457
461
for (ops = 0 ; alarm_triggered == false; ops ++ )
458
462
{
459
463
for (writes = 0 ; writes < 16 / writes_size ; writes ++ )
460
- if (write (tmpfile , buf , writes_size * 1024 ) !=
464
+ if (pg_pwrite (tmpfile ,
465
+ buf ,
466
+ writes_size * 1024 ,
467
+ writes * writes_size * 1024 ) !=
461
468
writes_size * 1024 )
462
469
die ("write failed" );
463
- if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
464
- die ("seek failed" );
465
470
}
466
471
STOP_TIMER ;
467
472
close (tmpfile );
@@ -553,16 +558,16 @@ test_non_sync(void)
553
558
printf (LABEL_FORMAT , "write" );
554
559
fflush (stdout );
555
560
561
+ if ((tmpfile = open (filename , O_RDWR | PG_BINARY , 0 )) == -1 )
562
+ die ("could not open output file" );
556
563
START_TIMER ;
557
564
for (ops = 0 ; alarm_triggered == false; ops ++ )
558
565
{
559
- if ((tmpfile = open (filename , O_RDWR | PG_BINARY , 0 )) == -1 )
560
- die ("could not open output file" );
561
- if (write (tmpfile , buf , XLOG_BLCKSZ ) != XLOG_BLCKSZ )
566
+ if (pg_pwrite (tmpfile , buf , XLOG_BLCKSZ , 0 ) != XLOG_BLCKSZ )
562
567
die ("write failed" );
563
- close (tmpfile );
564
568
}
565
569
STOP_TIMER ;
570
+ close (tmpfile );
566
571
}
567
572
568
573
static void
0 commit comments