summaryrefslogtreecommitdiffstats
path: root/src/server/uplink.c
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-15 17:45:44 +0100
committerSimon Rettberg2015-12-15 17:45:44 +0100
commit72104f2e83fa724f9667c876dca17a2c5ee9b2a2 (patch)
tree38837580c70b390f0bc35c15d2bc4d0865a9f3c4 /src/server/uplink.c
parent[SERVER] Make listen port configurable (diff)
downloaddnbd3-72104f2e83fa724f9667c876dca17a2c5ee9b2a2.tar.gz
dnbd3-72104f2e83fa724f9667c876dca17a2c5ee9b2a2.tar.xz
dnbd3-72104f2e83fa724f9667c876dca17a2c5ee9b2a2.zip
[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)
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r--src/server/uplink.c18
1 files changed, 12 insertions, 6 deletions
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) {