Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit303b7fc

Browse files
committed
Modify pg_test_fsync to match the behavior of git head in regards to
O_DIRECT behavior.
1 parent5ca543f commit303b7fc

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
#defineXLOG_BLCKSZ_K(XLOG_BLCKSZ / 1024)
2424

2525
#defineLABEL_FORMAT" %-32s"
26-
#defineNA_FORMATLABEL_FORMAT"%18s"
26+
#defineNA_FORMAT"%18s"
2727
#defineOPS_FORMAT"%9.3f ops/sec"
2828

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

136136
printf("%d operations per test\n",ops_per_test);
137+
#ifPG_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
staticvoid
@@ -184,43 +189,19 @@ test_sync(int writes_per_op)
184189
/*
185190
* Test open_datasync if available
186191
*/
187-
#ifdefOPEN_DATASYNC_FLAG
188-
printf(LABEL_FORMAT,"open_datasync"
189-
#ifPG_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-
#ifPG_O_DIRECT!=0
195+
#ifdefOPEN_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-
#ifdefHAVE_FDATASYNC
247225
printf(LABEL_FORMAT,"fdatasync");
248226
fflush(stdout);
249227

228+
#ifdefHAVE_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-
#ifdefHAVE_FSYNC_WRITETHROUGH
296274
printf(LABEL_FORMAT,"fsync_writethrough");
297275
fflush(stdout);
298276

277+
#ifdefHAVE_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-
#ifdefOPEN_SYNC_FLAG
323-
printf(LABEL_FORMAT,"open_sync"
324-
#ifPG_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-
#ifPG_O_DIRECT!=0
304+
#ifdefOPEN_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
staticvoid
408354
test_open_sync(constchar*msg,intwrites_size)
409355
{
410-
#ifdefOPEN_SYNC_FLAG
411356
inttmpfile,ops,writes;
412357

358+
printf(LABEL_FORMAT,msg);
359+
fflush(stdout);
360+
361+
#ifdefOPEN_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)

[8]ページ先頭

©2009-2025 Movatter.jp