From 443bb114d963a99082eef916025268a5a107092b Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 4 Dec 2008 14:30:13 +0100 Subject: [PATCH] smalloc: unlink pool file in add_pool() 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 --- smalloc.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/smalloc.c b/smalloc.c index 7f3c10b1..fc6ac526 100644 --- 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); -- 2.25.1