1f4c12f11SAustin Clements // Demonstrate that moving the "acquire" in iderw after the loop that 2f4c12f11SAustin Clements // appends to the idequeue results in a race. 3f4c12f11SAustin Clements 4f4c12f11SAustin Clements // For this to work, you should also add a spin within iderw's 5*9b972c06SFrans Kaashoek // idequeue traversal loop. Adding the following demonstrated a panic 6*9b972c06SFrans Kaashoek // after about 5 runs of stressfs in QEMU on a 2.1GHz CPU: 7*9b972c06SFrans Kaashoek // for (i = 0; i < 40000; i++) 8*9b972c06SFrans Kaashoek // asm volatile(""); 9f4c12f11SAustin Clements 10f4c12f11SAustin Clements #include "types.h" 11f4c12f11SAustin Clements #include "stat.h" 12f4c12f11SAustin Clements #include "user.h" 13f4c12f11SAustin Clements #include "fs.h" 14f4c12f11SAustin Clements #include "fcntl.h" 15f4c12f11SAustin Clements 16f4c12f11SAustin Clements int 17f4c12f11SAustin Clements main(int argc, char *argv[]) 18f4c12f11SAustin Clements { 191a81e38bSRuss Cox int fd, i; 201a81e38bSRuss Cox char path[] = "stressfs0"; 21*9b972c06SFrans Kaashoek char data[512]; 221a81e38bSRuss Cox 23f4c12f11SAustin Clements printf(1, "stressfs starting\n"); 24*9b972c06SFrans Kaashoek memset(data, 'a', sizeof(data)); 25f4c12f11SAustin Clements 261a81e38bSRuss Cox for(i = 0; i < 4; i++) 271a81e38bSRuss Cox if(fork() > 0) 28f4c12f11SAustin Clements break; 29f4c12f11SAustin Clements 30*9b972c06SFrans Kaashoek printf(1, "write %d\n", i); 31f4c12f11SAustin Clements 32f4c12f11SAustin Clements path[8] += i; 331a81e38bSRuss Cox fd = open(path, O_CREATE | O_RDWR); 34*9b972c06SFrans Kaashoek for(i = 0; i < 20; i++) 35*9b972c06SFrans Kaashoek // printf(fd, "%d\n", i); 36*9b972c06SFrans Kaashoek write(fd, data, sizeof(data)); 37*9b972c06SFrans Kaashoek close(fd); 38*9b972c06SFrans Kaashoek 39*9b972c06SFrans Kaashoek printf(1, "read\n"); 40*9b972c06SFrans Kaashoek 41*9b972c06SFrans Kaashoek fd = open(path, O_RDONLY); 42*9b972c06SFrans Kaashoek for (i = 0; i < 20; i++) 43*9b972c06SFrans Kaashoek read(fd, data, sizeof(data)); 44f4c12f11SAustin Clements close(fd); 45f4c12f11SAustin Clements 46f4c12f11SAustin Clements wait(); 47f4c12f11SAustin Clements 48f4c12f11SAustin Clements exit(); 49f4c12f11SAustin Clements } 50