Skip to content

Commit 303b7fc

Browse files
committed
Modify pg_test_fsync to match the behavior of git head in regards to
O_DIRECT behavior.
1 parent 5ca543f commit 303b7fc

File tree

1 file changed

+27
-81
lines changed

1 file changed

+27
-81
lines changed

contrib/pg_test_fsync/pg_test_fsync.c

Lines changed: 27 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define XLOG_BLCKSZ_K (XLOG_BLCKSZ / 1024)
2424

2525
#define LABEL_FORMAT " %-32s"
26-
#define NA_FORMAT LABEL_FORMAT "%18s"
26+
#define NA_FORMAT "%18s"
2727
#define OPS_FORMAT "%9.3f ops/sec"
2828

2929
static const char *progname;
@@ -134,6 +134,11 @@ handle_args(int argc, char *argv[])
134134
}
135135

136136
printf("%d operations per test\n", ops_per_test);
137+
#if PG_O_DIRECT != 0
138+
printf("O_DIRECT supported on this platform for open_datasync and open_sync.\n");
139+
#else
140+
printf("Direct I/O is not supported on this platform.\n");
141+
#endif
137142
}
138143

139144
static void
@@ -184,43 +189,19 @@ test_sync(int writes_per_op)
184189
/*
185190
* Test open_datasync if available
186191
*/
187-
#ifdef OPEN_DATASYNC_FLAG
188-
printf(LABEL_FORMAT, "open_datasync"
189-
#if PG_O_DIRECT != 0
190-
" (non-direct I/O)*"
191-
#endif
192-
);
192+
printf(LABEL_FORMAT, "open_datasync");
193193
fflush(stdout);
194194

195-
if ((tmpfile = open(filename, O_RDWR | O_DSYNC, 0)) == -1)
196-
die("could not open output file");
197-
gettimeofday(&start_t, NULL);
198-
for (ops = 0; ops < ops_per_test; ops++)
199-
{
200-
for (writes = 0; writes < writes_per_op; writes++)
201-
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
202-
die("write failed");
203-
if (lseek(tmpfile, 0, SEEK_SET) == -1)
204-
die("seek failed");
205-
}
206-
gettimeofday(&stop_t, NULL);
207-
close(tmpfile);
208-
print_elapse(start_t, stop_t);
209-
210-
/*
211-
* If O_DIRECT is enabled, test that with open_datasync
212-
*/
213-
#if PG_O_DIRECT != 0
195+
#ifdef OPEN_DATASYNC_FLAG
214196
if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
215197
{
216-
printf(NA_FORMAT, "o_direct", "n/a**\n");
198+
printf(NA_FORMAT, "n/a*\n");
217199
fs_warning = true;
218200
}
219201
else
220202
{
221-
printf(LABEL_FORMAT, "open_datasync (direct I/O)");
222-
fflush(stdout);
223-
203+
if ((tmpfile = open(filename, O_RDWR | O_DSYNC | PG_O_DIRECT, 0)) == -1)
204+
die("could not open output file");
224205
gettimeofday(&start_t, NULL);
225206
for (ops = 0; ops < ops_per_test; ops++)
226207
{
@@ -234,19 +215,17 @@ test_sync(int writes_per_op)
234215
close(tmpfile);
235216
print_elapse(start_t, stop_t);
236217
}
237-
#endif
238-
239218
#else
240-
printf(NA_FORMAT, "open_datasync", "n/a\n");
219+
printf(NA_FORMAT, "n/a\n");
241220
#endif
242221

243222
/*
244223
* Test fdatasync if available
245224
*/
246-
#ifdef HAVE_FDATASYNC
247225
printf(LABEL_FORMAT, "fdatasync");
248226
fflush(stdout);
249227

228+
#ifdef HAVE_FDATASYNC
250229
if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
251230
die("could not open output file");
252231
gettimeofday(&start_t, NULL);
@@ -263,7 +242,7 @@ test_sync(int writes_per_op)
263242
close(tmpfile);
264243
print_elapse(start_t, stop_t);
265244
#else
266-
printf(NA_FORMAT, "fdatasync", "n/a\n");
245+
printf(NA_FORMAT, "n/a\n");
267246
#endif
268247

269248
/*
@@ -292,10 +271,10 @@ test_sync(int writes_per_op)
292271
/*
293272
* If fsync_writethrough is available, test as well
294273
*/
295-
#ifdef HAVE_FSYNC_WRITETHROUGH
296274
printf(LABEL_FORMAT, "fsync_writethrough");
297275
fflush(stdout);
298276

277+
#ifdef HAVE_FSYNC_WRITETHROUGH
299278
if ((tmpfile = open(filename, O_RDWR, 0)) == -1)
300279
die("could not open output file");
301280
gettimeofday(&start_t, NULL);
@@ -313,49 +292,23 @@ test_sync(int writes_per_op)
313292
close(tmpfile);
314293
print_elapse(start_t, stop_t);
315294
#else
316-
printf(NA_FORMAT, "fsync_writethrough", "n/a\n");
295+
printf(NA_FORMAT, "n/a\n");
317296
#endif
318297

319298
/*
320299
* Test open_sync if available
321300
*/
322-
#ifdef OPEN_SYNC_FLAG
323-
printf(LABEL_FORMAT, "open_sync"
324-
#if PG_O_DIRECT != 0
325-
" (non-direct I/O)*"
326-
#endif
327-
);
301+
printf(LABEL_FORMAT, "open_sync");
328302
fflush(stdout);
329303

330-
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG, 0)) == -1)
331-
die("could not open output file");
332-
gettimeofday(&start_t, NULL);
333-
for (ops = 0; ops < ops_per_test; ops++)
334-
{
335-
for (writes = 0; writes < writes_per_op; writes++)
336-
if (write(tmpfile, buf, XLOG_BLCKSZ) != XLOG_BLCKSZ)
337-
die("write failed");
338-
if (lseek(tmpfile, 0, SEEK_SET) == -1)
339-
die("seek failed");
340-
}
341-
gettimeofday(&stop_t, NULL);
342-
close(tmpfile);
343-
print_elapse(start_t, stop_t);
344-
345-
/*
346-
* If O_DIRECT is enabled, test that with open_sync
347-
*/
348-
#if PG_O_DIRECT != 0
304+
#ifdef OPEN_SYNC_FLAG
349305
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
350306
{
351-
printf(NA_FORMAT, "o_direct", "n/a**\n");
307+
printf(NA_FORMAT, "n/a*\n");
352308
fs_warning = true;
353309
}
354310
else
355311
{
356-
printf(LABEL_FORMAT, "open_sync (direct I/O)");
357-
fflush(stdout);
358-
359312
gettimeofday(&start_t, NULL);
360313
for (ops = 0; ops < ops_per_test; ops++)
361314
{
@@ -369,20 +322,13 @@ test_sync(int writes_per_op)
369322
close(tmpfile);
370323
print_elapse(start_t, stop_t);
371324
}
372-
#endif
373-
374325
#else
375-
printf(NA_FORMAT, "open_sync", "n/a\n");
376-
#endif
377-
378-
#if defined(OPEN_DATASYNC_FLAG) || defined(OPEN_SYNC_FLAG)
379-
if (PG_O_DIRECT != 0)
380-
printf("* This non-direct I/O mode is not used by Postgres.\n");
326+
printf(NA_FORMAT, "n/a\n");
381327
#endif
382328

383329
if (fs_warning)
384330
{
385-
printf("** This file system and its mount options do not support direct\n");
331+
printf("* This file system and its mount options do not support direct\n");
386332
printf("I/O, e.g. ext4 in journaled mode.\n");
387333
}
388334
}
@@ -407,16 +353,16 @@ test_open_syncs(void)
407353
static void
408354
test_open_sync(const char *msg, int writes_size)
409355
{
410-
#ifdef OPEN_SYNC_FLAG
411356
int tmpfile, ops, writes;
412357

358+
printf(LABEL_FORMAT, msg);
359+
fflush(stdout);
360+
361+
#ifdef OPEN_SYNC_FLAG
413362
if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
414-
printf(NA_FORMAT, "o_direct", "n/a**\n");
363+
printf(NA_FORMAT, "n/a*\n");
415364
else
416365
{
417-
printf(LABEL_FORMAT, msg);
418-
fflush(stdout);
419-
420366
gettimeofday(&start_t, NULL);
421367
for (ops = 0; ops < ops_per_test; ops++)
422368
{
@@ -433,7 +379,7 @@ test_open_sync(const char *msg, int writes_size)
433379
}
434380

435381
#else
436-
printf(NA_FORMAT, "open_sync", "n/a\n");
382+
printf(NA_FORMAT, "n/a\n");
437383
#endif
438384
}
439385

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy