11/*
2- * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.24 2009/08/10 18:19:06 momjian Exp $
2+ * $PostgreSQL: pgsql/src/tools/fsync/test_fsync.c,v 1.25 2009/09/21 20:20:56 momjian Exp $
33 *
44 *
55 * test_fsync.c
@@ -149,8 +149,12 @@ main(int argc, char *argv[])
149149 die ("Cannot open output file." );
150150 gettimeofday (& start_t , NULL );
151151 for (i = 0 ; i < loops ; i ++ )
152+ {
152153 if (write (tmpfile , buf , WRITE_SIZE ) != WRITE_SIZE )
153154 die ("write failed" );
155+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
156+ die ("seek failed" );
157+ }
154158 gettimeofday (& elapse_t , NULL );
155159 close (tmpfile );
156160 printf ("\tone 16k o_sync write " );
@@ -167,6 +171,8 @@ main(int argc, char *argv[])
167171 die ("write failed" );
168172 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
169173 die ("write failed" );
174+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
175+ die ("seek failed" );
170176 }
171177 gettimeofday (& elapse_t , NULL );
172178 close (tmpfile );
@@ -188,8 +194,12 @@ main(int argc, char *argv[])
188194 die ("Cannot open output file." );
189195 gettimeofday (& start_t , NULL );
190196 for (i = 0 ; i < loops ; i ++ )
197+ {
191198 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
192199 die ("write failed" );
200+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
201+ die ("seek failed" );
202+ }
193203 gettimeofday (& elapse_t , NULL );
194204 close (tmpfile );
195205 printf ("\topen o_dsync, write " );
@@ -205,8 +215,12 @@ main(int argc, char *argv[])
205215 die ("Cannot open output file." );
206216 gettimeofday (& start_t , NULL );
207217 for (i = 0 ; i < loops ; i ++ )
218+ {
208219 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
209220 die ("write failed" );
221+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
222+ die ("seek failed" );
223+ }
210224 gettimeofday (& elapse_t , NULL );
211225 close (tmpfile );
212226 printf ("\topen o_sync, write " );
@@ -226,6 +240,8 @@ main(int argc, char *argv[])
226240 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
227241 die ("write failed" );
228242 fdatasync (tmpfile );
243+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
244+ die ("seek failed" );
229245 }
230246 gettimeofday (& elapse_t , NULL );
231247 close (tmpfile );
@@ -246,6 +262,8 @@ main(int argc, char *argv[])
246262 die ("write failed" );
247263 if (fsync (tmpfile ) != 0 )
248264 die ("fsync failed" );
265+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
266+ die ("seek failed" );
249267 }
250268 gettimeofday (& elapse_t , NULL );
251269 close (tmpfile );
@@ -269,6 +287,8 @@ main(int argc, char *argv[])
269287 die ("write failed" );
270288 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
271289 die ("write failed" );
290+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
291+ die ("seek failed" );
272292 }
273293 gettimeofday (& elapse_t , NULL );
274294 close (tmpfile );
@@ -290,6 +310,8 @@ main(int argc, char *argv[])
290310 die ("write failed" );
291311 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
292312 die ("write failed" );
313+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
314+ die ("seek failed" );
293315 }
294316 gettimeofday (& elapse_t , NULL );
295317 close (tmpfile );
@@ -310,6 +332,8 @@ main(int argc, char *argv[])
310332 if (write (tmpfile , buf , WRITE_SIZE / 2 ) != WRITE_SIZE / 2 )
311333 die ("write failed" );
312334 fdatasync (tmpfile );
335+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
336+ die ("seek failed" );
313337 }
314338 gettimeofday (& elapse_t , NULL );
315339 close (tmpfile );
@@ -332,6 +356,8 @@ main(int argc, char *argv[])
332356 die ("write failed" );
333357 if (fsync (tmpfile ) != 0 )
334358 die ("fsync failed" );
359+ if (lseek (tmpfile , 0 , SEEK_SET ) == -1 )
360+ die ("seek failed" );
335361 }
336362 gettimeofday (& elapse_t , NULL );
337363 close (tmpfile );
0 commit comments