From 51cc7103be13a9cb756d6a89d7e3306d4ef517ed Mon Sep 17 00:00:00 2001 From: sr Date: Fri, 31 Aug 2012 22:30:52 +0200 Subject: [SERVER] Added soft and hard timeouts for image deletion: reject any new clients for an image where the soft timeout has been reached, kill all clients for an image where the hard timeout has been reached and remove it from the server. Check for the hard timeout every five minutes [SERVER] Re-Implement image deletion to work with image names instead of vids [SERVER] Add helper functions to simplify dealing with libxml2 --- src/server/net.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/server/net.c') diff --git a/src/server/net.c b/src/server/net.c index 49cfb24..b1a7b20 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -175,9 +175,15 @@ void *dnbd3_handle_query(void *dnbd3_client) { pthread_spin_lock(&_spinlock); image = dnbd3_get_image(image_name, rid, 0); + const time_t now = time(NULL); if (!image) { - printf("[DEBUG] Client requested non-existent image '%s' (rid:%d, protocol:%d)\n", image_name, (int)rid, (int)client_version); + printf("[DEBUG] Client requested non-existent image '%s' (rid:%d)\n", image_name, (int)rid); + } + else if ((image->delete_soft != 0 && image->delete_soft < now) + || (image->delete_hard != 0 && image->delete_hard < now)) + { + printf("[DEBUG] Client requested end-of-life image '%s' (rid:%d)\n", image_name, (int)rid); } else { @@ -267,6 +273,7 @@ void *dnbd3_handle_query(void *dnbd3_client) { printf("[ERROR] sendfile failed (image to net)\n"); close(client->sock); + client->sock = -1; } break; } @@ -296,6 +303,7 @@ void *dnbd3_handle_query(void *dnbd3_client) { printf("[ERROR] sendfile failed (copy to cache 1)\n"); close(client->sock); + client->sock = -1; // Reset these so we don't update the cache map with false information dirty = 0; todo_size = 0; @@ -320,6 +328,7 @@ void *dnbd3_handle_query(void *dnbd3_client) { printf("[ERROR] sendfile failed (copy to cache 2)\n"); close(client->sock); + client->sock = -1; break; } dirty = 1; @@ -344,6 +353,7 @@ void *dnbd3_handle_query(void *dnbd3_client) { memlogf("[ERROR] sendfile failed (cache to net)\n"); close(client->sock); + client->sock = -1; } break; @@ -374,13 +384,14 @@ void *dnbd3_handle_query(void *dnbd3_client) } } - close(client->sock); - if (image_file != -1) close(image_file); - if (image_cache != -1) close(image_cache); pthread_spin_lock(&_spinlock); _dnbd3_clients = g_slist_remove(_dnbd3_clients, client); pthread_spin_unlock(&_spinlock); - free(client); + if (client->sock != -1) + close(client->sock); + if (image_file != -1) close(image_file); + if (image_cache != -1) close(image_cache); + g_free(client); pthread_exit((void *) 0); } -- cgit v1.2.3-55-g7522