From 7358f2786564e9a9960779e23ae36a26313f9bf3 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Tue, 6 Mar 2012 19:27:21 +0100 Subject: [SERVER] Cache images on hdd --- src/server/server.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/server/server.c') diff --git a/src/server/server.c b/src/server/server.c index 48dd545..c77fc7e 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "../types.h" #include "../version.h" @@ -64,6 +65,7 @@ void dnbd3_print_version() void dnbd3_cleanup() { + int i, fd; printf("INFO: Cleanup...\n"); pthread_spin_lock(&_spinlock); @@ -75,6 +77,24 @@ void dnbd3_cleanup() pthread_join(*client->thread, NULL); } g_slist_free(_dnbd3_clients); + + // save cache maps to files + for (i = 0; i < _num_images; i++) + { + if (_images[i].cache_file) + { + char tmp[strlen(_images[i].cache_file)+4]; + strcpy(tmp, _images[i].cache_file); + strcat(tmp, ".map"); + fd = open(tmp, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); + + if (fd > 0) + write(fd, _images[i].cache_map, (_images[i].filesize >> 15) * sizeof(char)); + + close(fd); + } + } + pthread_spin_unlock(&_spinlock); close(_sock); -- cgit v1.2.3-55-g7522