summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Moyer <jmoyer@redhat.com>2009-04-17 08:50:22 +0200
committerJens Axboe <jens.axboe@oracle.com>2009-04-17 08:50:22 +0200
commit60886290e2ba6ddae1213f3a13929193180c8c55 (patch)
tree61ee51a7ab1b177f0c97e7fb39ff079f57b4412a
parentbb4a66074cecd59afc37f0053fdf42661503f51c (diff)
downloadblktrace-60886290e2ba6ddae1213f3a13929193180c8c55.tar.gz
blktrace-60886290e2ba6ddae1213f3a13929193180c8c55.tar.bz2
handle race to mkdir at startup
I ran into a problem when specifying -D dirname-that-doesnt-yet-exist. Blktrace would fail, spewing the following messages: [root@megadeth blktrace]# ./blktrace -d /dev/cciss/c0d1 -D ./2.6.30-rc2-cfq-local Destination dir ./2.6.30-rc2-cfq-local/ can't be made: 17/File exists Destination dir ./2.6.30-rc2-cfq-local/ can't be made: 17/File exists Destination dir ./2.6.30-rc2-cfq-local/ can't be made: 17/File exists Destination dir ./2.6.30-rc2-cfq-local/ can't be made: 17/File exists Destination dir ./2.6.30-rc2-cfq-local/ can't be made: 17/File exists FAILED to start thread on CPU 0: 1/Operation not permitted FAILED to start thread on CPU 4: 1/Operation not permitted FAILED to start thread on CPU 5: 1/Operation not permitted FAILED to start thread on CPU 6: 1/Operation not permitted FAILED to start thread on CPU 7: 1/Operation not permitted I tracked it down to the fact that there is no synchronization between threads when trying to create the output directory. The fix is simple, just allow the race to happen and detect it. It's not really worth putting in any extra synchronization. It looks like no place else in that startup path needs synchronization either. This patch fixes the issue for me. I tested it by running the very command that caused me headaches 100% of the time before. I also did a chattr +i on the directory and verified that it would really fail in the case where it couldn't create the directory. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
-rw-r--r--blktrace.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/blktrace.c b/blktrace.c
index 656ab7a..b4c919d 100644
--- a/blktrace.c
+++ b/blktrace.c
@@ -1477,7 +1477,12 @@ static int fill_ofname(struct io_info *iop, int cpu)
iop->ofn, errno, strerror(errno));
return 1;
}
- if (mkdir(iop->ofn, 0755) < 0) {
+ /*
+ * There is no synchronization between multiple threads
+ * trying to create the directory at once. It's harmless
+ * to let them try, so just detect the problem and move on.
+ */
+ if (mkdir(iop->ofn, 0755) < 0 && errno != EEXIST) {
fprintf(stderr,
"Destination dir %s can't be made: %d/%s\n",
iop->ofn, errno, strerror(errno));