From 72104f2e83fa724f9667c876dca17a2c5ee9b2a2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 15 Dec 2015 17:45:44 +0100 Subject: [SERVER] Remove non-working images from list, plus refactoring Now that we can automatically load unknown images from disk on request, it makes sense to remove non-working images from the image list. On future requests, we will look for them on disk again, which is nice in case of temporary storage hickups. Also, some more ore less related locking has been refined (loading images, replicating images) --- src/server/uplink.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index 7fa3c96..29c42af 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -158,19 +158,19 @@ bool uplink_request(dnbd3_client_t *client, uint64_t handle, uint64_t start, uin spin_lock( &client->image->lock ); if ( client->image->uplink == NULL ) { spin_unlock( &client->image->lock ); - logadd( LOG_DEBUG1, "Uplink request for image with no uplink (%s)\n", client->image->lower_name ); + logadd( LOG_DEBUG1, "Uplink request for image with no uplink" ); return false; } dnbd3_connection_t * const uplink = client->image->uplink; if ( uplink->shutdown ) { spin_unlock( &client->image->lock ); - logadd( LOG_DEBUG1, "Uplink request for image with uplink shutting down (%s)\n", client->image->lower_name ); + logadd( LOG_DEBUG1, "Uplink request for image with uplink shutting down" ); return false; } // Check if the client is the same host as the uplink. If so assume this is a circular proxy chain if ( isSameAddress( &uplink->currentServer, &client->host ) ) { spin_unlock( &client->image->lock ); - logadd( LOG_DEBUG1, "Proxy cycle detected.\n" ); + logadd( LOG_DEBUG1, "Proxy cycle detected" ); return false; } @@ -572,9 +572,15 @@ static void uplink_handleReceive(dnbd3_connection_t *link) const uint64_t end = inReply.handle + inReply.size; link->bytesReceived += inReply.size; // 1) Write to cache file - assert( link->image->cacheFd != -1 ); - ret = (int)pwrite( link->image->cacheFd, link->recvBuffer, inReply.size, start ); - if ( ret > 0 ) image_updateCachemap( link->image, start, start + ret, true ); + if ( link->image->cacheFd != -1 ) { + ret = (int)pwrite( link->image->cacheFd, link->recvBuffer, inReply.size, start ); + if ( ret > 0 ) image_updateCachemap( link->image, start, start + ret, true ); + if ( ret == -1 && ( errno == EBADF || errno == EINVAL || errno == EIO ) ) { + const int fd = link->image->cacheFd; + link->image->cacheFd = -1; + close( fd ); + } + } // 2) Figure out which clients are interested in it spin_lock( &link->queueLock ); for (i = 0; i < link->queueLen; ++i) { -- cgit v1.2.3-55-g7522