smalloc: unlink pool file in add_pool()
authorJens Axboe <jens.axboe@oracle.com>
Thu, 4 Dec 2008 13:30:13 +0000 (14:30 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 4 Dec 2008 13:30:13 +0000 (14:30 +0100)
Don't defer until cleanup time, since we may not clean up if fio
crashes or is killed in other ways.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
smalloc.c

index 7f3c10b137498d01f812e4807298b2f2b06e6870..fc6ac526c33d95cac6c88f2bfe371f724f0d426c 100644 (file)
--- a/smalloc.c
+++ b/smalloc.c
@@ -224,7 +224,13 @@ static int add_pool(struct pool *pool, unsigned int alloc_size)
                goto out_unlink;
 #endif
 
+       /*
+        * Unlink pool file now. It wont get deleted until the fd is closed,
+        * which happens both for cleanup or unexpected quit. This way we
+        * don't leave temp files around in case of a crash.
+        */
        pool->fd = fd;
+       unlink(pool->file);
 
        nr_pools++;
        return 0;
@@ -252,7 +258,10 @@ void sinit(void)
 
 static void cleanup_pool(struct pool *pool)
 {
-       unlink(pool->file);
+       /*
+        * This will also remove the temporary file we used as a backing
+        * store, it was already unlinked
+        */
        close(pool->fd);
        munmap(pool->map, pool->mmap_size);