struct timeval start_t, stop_t;
-void handle_args(int argc, char *argv[]);
-void prepare_buf(void);
-void test_open(void);
-void test_non_sync(void);
-void test_sync(int writes_per_op);
-void test_open_syncs(void);
-void test_open_sync(const char *msg, int writes_size);
-void test_file_descriptor_sync(void);
-void print_elapse(struct timeval start_t, struct timeval stop_t);
-void die(char *str);
+static void handle_args(int argc, char *argv[]);
+static void prepare_buf(void);
+static void test_open(void);
+static void test_non_sync(void);
+static void test_sync(int writes_per_op);
+static void test_open_syncs(void);
+static void test_open_sync(const char *msg, int writes_size);
+static void test_file_descriptor_sync(void);
+#ifdef HAVE_FSYNC_WRITETHROUGH
+static int pg_fsync_writethrough(int fd);
+#endif
+static void print_elapse(struct timeval start_t, struct timeval stop_t);
+static void die(char *str);
int
return 0;
}
-void
+static void
handle_args(int argc, char *argv[])
{
static struct option long_options[] = {
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 ||
strcmp(argv[1], "-?") == 0)
{
- fprintf(stderr, "pg_test_fsync [-f filename] [ops-per-test]\n");
+ fprintf(stderr, "pg_test_fsync [-f filename] [-o ops-per-test]\n");
exit(0);
}
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
printf("%d operations per test\n", ops_per_test);
}
-void
+static void
prepare_buf(void)
{
int ops;
buf = (char *) TYPEALIGN(ALIGNOF_XLOG_BUFFER, full_buf);
}
-void
+static void
test_open(void)
{
int tmpfile;
close(tmpfile);
}
-void
+static void
test_sync(int writes_per_op)
{
int tmpfile, ops, writes;
for (writes = 0; writes < writes_per_op; writes++)
if (write(tmpfile, buf, WRITE_SIZE) != WRITE_SIZE)
die("write failed");
- if (fcntl(tmpfile, F_FULLFSYNC ) != 0)
+ if (pg_fsync_writethrough(tmpfile) != 0)
die("fsync failed");
if (lseek(tmpfile, 0, SEEK_SET) == -1)
die("seek failed");
}
}
-void
+static void
test_open_syncs(void)
{
printf("\nCompare open_sync with different write sizes:\n");
}
-void
+static void
test_open_sync(const char *msg, int writes_size)
{
int tmpfile, ops, writes;
#endif
}
-void
+static void
test_file_descriptor_sync(void)
{
int tmpfile, ops;
}
-void
+static void
test_non_sync(void)
{
int tmpfile, ops;
print_elapse(start_t, stop_t);
}
+#ifdef HAVE_FSYNC_WRITETHROUGH
+
+static int
+pg_fsync_writethrough(int fd)
+{
+#ifdef WIN32
+ return _commit(fd);
+#elif defined(F_FULLFSYNC)
+ return (fcntl(fd, F_FULLFSYNC, 0) == -1) ? -1 : 0;
+#else
+ errno = ENOSYS;
+ return -1;
+#endif
+}
+
+#endif
+
/*
* print out the writes per second for tests
*/
-void
+static void
print_elapse(struct timeval start_t, struct timeval stop_t)
{
double total_time = (stop_t.tv_sec - start_t.tv_sec) +
printf(OPS_FORMAT "\n", per_second);
}
-void
+static void
die(char *str)
{
fprintf(stderr, "%s\n", str);