2009-11-23 22:27:26 +00:00
|
|
|
// Demonstrate that moving the "acquire" in iderw after the loop that
|
|
|
|
// appends to the idequeue results in a race.
|
|
|
|
|
|
|
|
// For this to work, you should also add a spin within iderw's
|
2011-09-27 16:59:47 +00:00
|
|
|
// idequeue traversal loop. Adding the following demonstrated a panic
|
|
|
|
// after about 5 runs of stressfs in QEMU on a 2.1GHz CPU:
|
|
|
|
// for (i = 0; i < 40000; i++)
|
|
|
|
// asm volatile("");
|
2009-11-23 22:27:26 +00:00
|
|
|
|
2019-06-11 13:57:14 +00:00
|
|
|
#include "kernel/types.h"
|
|
|
|
#include "kernel/stat.h"
|
|
|
|
#include "user/user.h"
|
|
|
|
#include "kernel/fs.h"
|
|
|
|
#include "kernel/fcntl.h"
|
2009-11-23 22:27:26 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2011-01-11 18:01:13 +00:00
|
|
|
int fd, i;
|
|
|
|
char path[] = "stressfs0";
|
2011-09-27 16:59:47 +00:00
|
|
|
char data[512];
|
2011-01-11 18:01:13 +00:00
|
|
|
|
2019-08-27 17:13:03 +00:00
|
|
|
printf("stressfs starting\n");
|
2011-09-27 16:59:47 +00:00
|
|
|
memset(data, 'a', sizeof(data));
|
2009-11-23 22:27:26 +00:00
|
|
|
|
2011-01-11 18:01:13 +00:00
|
|
|
for(i = 0; i < 4; i++)
|
|
|
|
if(fork() > 0)
|
2009-11-23 22:27:26 +00:00
|
|
|
break;
|
|
|
|
|
2019-08-27 17:13:03 +00:00
|
|
|
printf("write %d\n", i);
|
2009-11-23 22:27:26 +00:00
|
|
|
|
|
|
|
path[8] += i;
|
2011-01-11 18:01:13 +00:00
|
|
|
fd = open(path, O_CREATE | O_RDWR);
|
2011-09-27 16:59:47 +00:00
|
|
|
for(i = 0; i < 20; i++)
|
|
|
|
// printf(fd, "%d\n", i);
|
|
|
|
write(fd, data, sizeof(data));
|
|
|
|
close(fd);
|
|
|
|
|
2019-08-27 17:13:03 +00:00
|
|
|
printf("read\n");
|
2011-09-27 16:59:47 +00:00
|
|
|
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
for (i = 0; i < 20; i++)
|
|
|
|
read(fd, data, sizeof(data));
|
2009-11-23 22:27:26 +00:00
|
|
|
close(fd);
|
|
|
|
|
2019-09-10 16:30:10 +00:00
|
|
|
wait(0);
|
2016-08-25 13:13:00 +00:00
|
|
|
|
2019-09-10 16:30:10 +00:00
|
|
|
exit(0);
|
2009-11-23 22:27:26 +00:00
|
|
|
}
|