summaryrefslogtreecommitdiffstats
path: root/src/server/uplink.c
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-03 14:55:01 +0100
committerSimon Rettberg2020-03-03 14:55:01 +0100
commit5bc3badd013b88201da64dc970600d19451daaec (patch)
treed2aec58cfd872302b61c59125daf972e4dc816be /src/server/uplink.c
parent[SERVER] Remove "working" flag, introduce fine-grained flags (diff)
downloaddnbd3-5bc3badd013b88201da64dc970600d19451daaec.tar.gz
dnbd3-5bc3badd013b88201da64dc970600d19451daaec.tar.xz
dnbd3-5bc3badd013b88201da64dc970600d19451daaec.zip
[SERVER] Also add a flag for uplink queue overload
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r--src/server/uplink.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/server/uplink.c b/src/server/uplink.c
index aba53ba..97cb2a9 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -118,6 +118,8 @@ bool uplink_init(dnbd3_image_t *image, int sock, dnbd3_host_t *host, int version
mutex_unlock( &uplink->sendMutex );
uplink->cycleDetected = false;
image->problem.uplink = true;
+ image->problem.write = true;
+ image->problem.queue = false;
if ( sock != -1 ) {
uplink->better.fd = sock;
int index = altservers_hostToIndex( host );
@@ -191,6 +193,7 @@ static void cancelAllRequests(dnbd3_uplink_t *uplink)
}
}
uplink->queueLen = 0;
+ uplink->image->problem.queue = false;
}
static void uplink_free(ref *ref)
@@ -328,6 +331,9 @@ bool uplink_request(dnbd3_client_t *client, uint64_t handle, uint64_t start, uin
goto fail_lock;
}
freeSlot = uplink->queueLen++;
+ if ( freeSlot > SERVER_UPLINK_QUEUELEN_THRES ) {
+ uplink->image->problem.queue = true;
+ }
}
// Do not send request to uplink server if we have a matching pending request AND the request either has the
// status ULR_NEW/PENDING OR we found a free slot with LOWER index than the one we attach to. Otherwise
@@ -904,6 +910,7 @@ static void uplink_handleReceive(dnbd3_uplink_t *uplink)
continue; // Success, retry write
}
if ( err == EBADF || err == EINVAL || err == EIO ) {
+ uplink->image->problem.write = true;
if ( !tryAgain || !uplink_reopenCacheFd( uplink, true ) )
break;
tryAgain = false;
@@ -983,6 +990,9 @@ static void uplink_handleReceive(dnbd3_uplink_t *uplink)
}
if ( req->status == ULR_FREE && i == uplink->queueLen - 1 ) uplink->queueLen--;
}
+ if ( uplink->queueLen < SERVER_UPLINK_QUEUELEN_THRES ) {
+ uplink->image->problem.queue = false;
+ }
mutex_unlock( &uplink->queueLock );
#ifdef _DEBUG
if ( !served && start != uplink->replicationHandle ) {
@@ -1121,6 +1131,7 @@ static bool uplink_reopenCacheFd(dnbd3_uplink_t *uplink, const bool force)
close( uplink->cacheFd );
}
uplink->cacheFd = open( uplink->image->path, O_WRONLY | O_CREAT, 0644 );
+ uplink->image->problem.write = uplink->cacheFd == -1;
return uplink->cacheFd != -1;
}