stressfs.c 1.0 KB

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