From 24c13cb8b2d8caf744a5369854da4d6f9f68945c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 7 Mar 2019 22:38:28 +0100 Subject: [FUSE] Add --sticky mode to ignore alt-servers announced by servers --- src/fuse/connection.c | 10 +++++++--- src/fuse/connection.h | 2 +- src/fuse/main.c | 10 ++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/fuse/connection.c b/src/fuse/connection.c index 294983b..fc9f05b 100644 --- a/src/fuse/connection.c +++ b/src/fuse/connection.c @@ -31,6 +31,7 @@ static bool connectionInitDone = false; static bool threadInitDone = false; static pthread_mutex_t mutexInit = PTHREAD_MUTEX_INITIALIZER; static bool keepRunning = true; +static bool learnNewServers; // List of pending requests static struct { @@ -95,7 +96,7 @@ static bool throwDataAway(int sockFd, uint32_t amount); static void enqueueRequest(dnbd3_async_t *request); static dnbd3_async_t* removeRequest(dnbd3_async_t *request); -bool connection_init(const char *hosts, const char *lowerImage, const uint16_t rid) +bool connection_init(const char *hosts, const char *lowerImage, const uint16_t rid, const bool doLearnNew) { int sock = -1; char host[SHORTBUF]; @@ -114,6 +115,7 @@ bool connection_init(const char *hosts, const char *lowerImage, const uint16_t r dnbd3_host_t tempHosts[MAX_HOSTS_PER_ADDRESS]; const char *current, *end; int altIndex = 0; + learnNewServers = doLearnNew; memset( altservers, 0, sizeof altservers ); connection.sockFd = -1; current = hosts; @@ -453,7 +455,9 @@ static void* connection_backgroundThread(void *something UNUSED) const bool panic = connection.sockFd == -1; // Check alt servers if ( panic || timing_reachedPrecise( &nextRttCheck, &now ) ) { - addAltServers(); + if ( learnNewServers ) { + addAltServers(); + } sortAltServers(); probeAltServers(); if ( panic || timing_diff( &connection.startupTime, &now ) <= STARTUP_MODE_DURATION ) { @@ -853,7 +857,7 @@ static void switchConnection(int sockFd, alt_server_t *srv) */ static void requestAltServers() { - if ( connection.sockFd == -1 ) + if ( connection.sockFd == -1 || !learnNewServers ) return; dnbd3_request_t request = { 0 }; request.magic = dnbd3_packet_magic; diff --git a/src/fuse/connection.h b/src/fuse/connection.h index c919d95..cae554c 100644 --- a/src/fuse/connection.h +++ b/src/fuse/connection.h @@ -20,7 +20,7 @@ typedef struct _dnbd3_async { bool success; // Will be set to true if the request succeeded } dnbd3_async_t; -bool connection_init(const char *hosts, const char *image, const uint16_t rid); +bool connection_init(const char *hosts, const char *image, const uint16_t rid, const bool learnNewServers); bool connection_initThreads(); diff --git a/src/fuse/main.c b/src/fuse/main.c index e1b2633..1a5643c 100644 --- a/src/fuse/main.c +++ b/src/fuse/main.c @@ -277,11 +277,12 @@ static void printUsage(char *argv0, int exitCode) printf( " -l --log Write log to given location\n" ); printf( " -o --option Mount options to pass to libfuse\n" ); printf( " -r --rid Revision to use (omit or pass 0 for latest)\n" ); + printf( " -S --sticky Use only servers from command line (no learning from servers)\n" ); printf( " -s Single threaded mode\n" ); exit( exitCode ); } -static const char *optString = "dfHh:i:l:o:r:sVv"; +static const char *optString = "dfHh:i:l:o:r:SsVv"; static const struct option longOpts[] = { { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'H' }, @@ -290,6 +291,7 @@ static const struct option longOpts[] = { { "log", required_argument, NULL, 'l' }, { "option", required_argument, NULL, 'o' }, { "rid", required_argument, NULL, 'r' }, + { "sticky", no_argument, NULL, 'S' }, { "version", no_argument, NULL, 'v' }, { 0, 0, 0, 0 } }; @@ -303,6 +305,7 @@ int main(int argc, char *argv[]) char **newArgv; int newArgc; int opt, lidx; + bool learnNewServers = true; if ( argc <= 1 || strcmp( argv[1], "--help" ) == 0 || strcmp( argv[1], "--usage" ) == 0 ) { printUsage( argv[0], 0 ); @@ -358,6 +361,9 @@ int main(int argc, char *argv[]) case 's': newArgv[newArgc++] = "-s"; break; + case 'S': + learnNewServers = false; + break; case 'f': newArgv[newArgc++] = "-f"; break; @@ -380,7 +386,7 @@ int main(int argc, char *argv[]) } } - if ( !connection_init( server_address, image_Name, rid ) ) { + if ( !connection_init( server_address, image_Name, rid, learnNewServers ) ) { logadd( LOG_ERROR, "Could not connect to any server. Bye.\n" ); return EXIT_FAILURE; } -- cgit v1.2.3-55-g7522