diff options
author | Robert Morris <[email protected]> | 2011-08-15 12:44:20 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2011-08-15 12:44:20 -0400 |
commit | 5053dd6a6d2b481bfcddbd91bacc885b9f0e0ff5 (patch) | |
tree | ca7d000f9996082466bdfe8c7a0c9667341f2dfa /usertests.c | |
parent | c95ce31c5978bd43e1f0d34e51a4e3d7bcc41b14 (diff) | |
download | xv6-labs-5053dd6a6d2b481bfcddbd91bacc885b9f0e0ff5.tar.gz xv6-labs-5053dd6a6d2b481bfcddbd91bacc885b9f0e0ff5.tar.bz2 xv6-labs-5053dd6a6d2b481bfcddbd91bacc885b9f0e0ff5.zip |
avoid deadlock by calling begin_trans() before locking any inodes
Diffstat (limited to 'usertests.c')
-rw-r--r-- | usertests.c | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/usertests.c b/usertests.c index ba648a7..8db8385 100644 --- a/usertests.c +++ b/usertests.c @@ -364,6 +364,8 @@ sharedfd(void) int fd, pid, i, n, nc, np; char buf[10]; + printf(1, "sharedfd test\n"); + unlink("sharedfd"); fd = open("sharedfd", O_CREATE|O_RDWR); if(fd < 0){ @@ -655,7 +657,7 @@ linktest(void) printf(1, "linktest ok\n"); } -// test concurrent create and unlink of the same file +// test concurrent create/link/unlink of the same file void concreate(void) { @@ -728,10 +730,15 @@ concreate(void) } if(((i % 3) == 0 && pid == 0) || ((i % 3) == 1 && pid != 0)){ - fd = open(file, 0); - close(fd); + close(open(file, 0)); + close(open(file, 0)); + close(open(file, 0)); + close(open(file, 0)); } else { unlink(file); + unlink(file); + unlink(file); + unlink(file); } if(pid == 0) exit(); @@ -742,6 +749,42 @@ concreate(void) printf(1, "concreate ok\n"); } +// another concurrent link/unlink/create test, +// to look for deadlocks. +void +linkunlink() +{ + int pid, i; + + printf(1, "linkunlink test\n"); + + unlink("x"); + pid = fork(); + if(pid < 0){ + printf(1, "fork failed\n"); + exit(); + } + + unsigned int x = (pid ? 1 : 97); + for(i = 0; i < 100; i++){ + x = x * 1103515245 + 12345; + if((x % 3) == 0){ + close(open("x", O_RDWR | O_CREATE)); + } else if((x % 3) == 1){ + link("cat", "x"); + } else { + unlink("x"); + } + } + + if(pid) + wait(); + else + exit(); + + printf(1, "linkunlink ok\n"); +} + // directory that uses indirect blocks void bigdir(void) @@ -1518,6 +1561,7 @@ main(int argc, char *argv[]) bigfile(); subdir(); concreate(); + linkunlink(); linktest(); unlinkread(); createdelete(); |