1 /* Test 70 - regression test for m_out vfs race condition.
3 * Regression test for vfs overwriting m_out fields by competing threads.
4 * lseek() uses one of these fields too so this test performs concurrent
5 * lseek()s to trigger this situation.
7 * The program consists of 2 processes, each seeking to different ranges in
8 * a test file. The bug would return the wrong value in one of the messaeg
9 * fields so the lseek() return value would be wrong sometimes.
11 * The first instance seeks from 0 to SEEKWINDOW, the other instance seeks
12 * from SEEKWINDOW to SEEKWINDOW+SEEKWINDOW.
16 #include <sys/types.h>
26 #define SEEKWINDOW 1000
31 char template[30] = "tempfile.XXXXXXXX";
32 int iteration
, fd
= mkstemp(template);
33 int limit
= seekbase
+ SEEKWINDOW
;
35 /* make a temporary file, unlink it so it's always gone
36 * afterwards, and make it the size we need.
38 if(fd
< 0) { perror("mkstemp"); e(2); return 1; }
39 if(unlink(template) < 0) { perror("unlink"); e(3); return 1; }
40 if(ftruncate(fd
, limit
) < 0) { perror("ftruncate"); e(4); return 1; }
42 /* try lseek() lots of times with different arguments and make
43 * sure we get the right return value back, while this happens
44 * in a concurrent process too.
46 #define ITERATIONS 5000
47 for(iteration
= 0; iteration
< ITERATIONS
; iteration
++) {
49 for(o
= seekbase
; o
< limit
; o
++) {
51 if((r
=lseek(fd
, o
, SEEK_SET
)) != o
) {
52 if(r
< 0) perror("lseek");
53 fprintf(stderr
, "%d/%d %d != %d\n",
54 iteration
, ITERATIONS
, r
, o
);
71 if((f
=fork()) < 0) { e(1); quit(); }
73 if(f
== 0) { exit(doseeks(0)); }
75 if(doseeks(SEEKWINDOW
)) { e(10); }
77 if (waitpid(f
, &result
, 0) == -1) e(11);
78 if (WEXITSTATUS(result
) != 0) e(12);
82 return(-1); /* impossible */