diff options
Diffstat (limited to 'src/server/globals.c')
-rw-r--r-- | src/server/globals.c | 86 |
1 files changed, 67 insertions, 19 deletions
diff --git a/src/server/globals.c b/src/server/globals.c index 69e8a6e..f6432cb 100644 --- a/src/server/globals.c +++ b/src/server/globals.c @@ -1,7 +1,7 @@ #include "globals.h" #include "ini.h" #include "locks.h" -#include "../shared/log.h" +#include <dnbd3/shared/log.h> #include <string.h> #include <stdlib.h> #include <inttypes.h> @@ -19,21 +19,26 @@ atomic_int _clientPenalty = 0; atomic_bool _isProxy = false; atomic_int _backgroundReplication = BGR_FULL; atomic_int _bgrMinClients = 0; +atomic_int _bgrWindowSize = 1; atomic_bool _lookupMissingForProxy = true; atomic_bool _sparseFiles = false; +atomic_bool _ignoreAllocErrors = false; atomic_bool _removeMissingImages = true; -atomic_int _uplinkTimeout = SOCKET_TIMEOUT_UPLINK; -atomic_int _clientTimeout = SOCKET_TIMEOUT_CLIENT; +atomic_uint _uplinkTimeout = SOCKET_TIMEOUT_UPLINK; +atomic_uint _clientTimeout = SOCKET_TIMEOUT_CLIENT; atomic_bool _closeUnusedFd = false; atomic_bool _vmdkLegacyMode = false; // Not really needed anymore since we have '+' and '-' in alt-servers atomic_bool _proxyPrivateOnly = false; +atomic_bool _pretendClient = false; +atomic_int _autoFreeDiskSpaceDelay = 3600 * 10; // [limits] atomic_int _maxClients = SERVER_MAX_CLIENTS; atomic_int _maxImages = SERVER_MAX_IMAGES; -atomic_int _maxPayload = 9000000; // 9MB +atomic_uint _maxPayload = 9000000; // 9MB atomic_uint_fast64_t _maxReplicationSize = (uint64_t)100000000000LL; -atomic_bool _pretendClient = false; +atomic_uint _maxPrefetch = 262144; // 256KB +atomic_uint _minRequestSize = 0; /** * True when loading config the first time. Consecutive loads will @@ -57,32 +62,37 @@ static const char* units = "KMGTPEZY"; static bool parse64(const char *in, atomic_int_fast64_t *out, const char *optname); static bool parse64u(const char *in, atomic_uint_fast64_t *out, const char *optname); -static bool parse32(const char *in, atomic_int *out, const char *optname) UNUSED; -static bool parse32u(const char *in, atomic_int *out, const char *optname); +static bool parse32(const char *in, atomic_int *out, const char *optname); +static bool parse32u(const char *in, atomic_uint *out, const char *optname); static int ini_handler(void *custom UNUSED, const char* section, const char* key, const char* value) { if ( initialLoad ) { if ( _basePath == NULL ) SAVE_TO_VAR_STR( dnbd3, basePath ); SAVE_TO_VAR_BOOL( dnbd3, vmdkLegacyMode ); - SAVE_TO_VAR_UINT( dnbd3, listenPort ); - SAVE_TO_VAR_UINT( limits, maxClients ); - SAVE_TO_VAR_UINT( limits, maxImages ); + SAVE_TO_VAR_INT( dnbd3, listenPort ); + SAVE_TO_VAR_INT( limits, maxClients ); + SAVE_TO_VAR_INT( limits, maxImages ); } SAVE_TO_VAR_BOOL( dnbd3, isProxy ); SAVE_TO_VAR_BOOL( dnbd3, proxyPrivateOnly ); SAVE_TO_VAR_INT( dnbd3, bgrMinClients ); + SAVE_TO_VAR_INT( dnbd3, bgrWindowSize ); SAVE_TO_VAR_BOOL( dnbd3, lookupMissingForProxy ); SAVE_TO_VAR_BOOL( dnbd3, sparseFiles ); + SAVE_TO_VAR_BOOL( dnbd3, ignoreAllocErrors ); SAVE_TO_VAR_BOOL( dnbd3, removeMissingImages ); SAVE_TO_VAR_BOOL( dnbd3, closeUnusedFd ); - SAVE_TO_VAR_UINT( dnbd3, serverPenalty ); - SAVE_TO_VAR_UINT( dnbd3, clientPenalty ); + SAVE_TO_VAR_INT( dnbd3, serverPenalty ); + SAVE_TO_VAR_INT( dnbd3, clientPenalty ); SAVE_TO_VAR_UINT( dnbd3, uplinkTimeout ); SAVE_TO_VAR_UINT( dnbd3, clientTimeout ); SAVE_TO_VAR_UINT( limits, maxPayload ); SAVE_TO_VAR_UINT64( limits, maxReplicationSize ); + SAVE_TO_VAR_UINT( limits, maxPrefetch ); + SAVE_TO_VAR_UINT( limits, minRequestSize ); SAVE_TO_VAR_BOOL( dnbd3, pretendClient ); + SAVE_TO_VAR_INT( dnbd3, autoFreeDiskSpaceDelay ); if ( strcmp( section, "dnbd3" ) == 0 && strcmp( key, "backgroundReplication" ) == 0 ) { if ( strcmp( value, "hashblock" ) == 0 ) { _backgroundReplication = BGR_HASHBLOCK; @@ -109,10 +119,13 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key void globals_loadConfig() { char *name = NULL; - asprintf( &name, "%s/%s", _configDir, CONFIG_FILENAME ); + if ( asprintf( &name, "%s/%s", _configDir, CONFIG_FILENAME ) == -1 ) { + logadd( LOG_ERROR, "Memory allocation error for config filename" ); + exit( 1 ); + } if ( name == NULL ) return; if ( initialLoad ) { - mutex_init( &loadLock ); + mutex_init( &loadLock, LOCK_LOAD_CONFIG ); } if ( mutex_trylock( &loadLock ) != 0 ) { logadd( LOG_INFO, "Ignoring config reload request due to already running reload" ); @@ -123,9 +136,30 @@ void globals_loadConfig() if ( initialLoad ) { sanitizeFixedConfig(); } - if ( _backgroundReplication == BGR_FULL && _sparseFiles && _bgrMinClients < 5 ) { - logadd( LOG_WARNING, "Ignoring 'sparseFiles=true' since backgroundReplication is set to true and bgrMinClients is too low" ); - _sparseFiles = false; + if ( _isProxy ) { + if ( _backgroundReplication == BGR_FULL && _sparseFiles && _bgrMinClients < 5 ) { + logadd( LOG_WARNING, "Ignoring 'sparseFiles=true' since backgroundReplication is set to true and bgrMinClients is too low" ); + _sparseFiles = false; + } + if ( _bgrWindowSize < 1 ) { + _bgrWindowSize = 1; + } else if ( _bgrWindowSize > UPLINK_MAX_QUEUE - 10 ) { + _bgrWindowSize = UPLINK_MAX_QUEUE - 10; + logadd( LOG_MINOR, "Limiting bgrWindowSize to %d, because of UPLINK_MAX_QUEUE", + _bgrWindowSize ); + } + if ( _maxPayload < 256 * 1024 ) { + logadd( LOG_WARNING, "maxPayload was increased to 256k" ); + _maxPayload = 256 * 1024; + } + if ( _maxPrefetch > _maxPayload ) { + logadd( LOG_WARNING, "Reducing maxPrefetch to maxPayload" ); + _maxPrefetch = _maxPayload; + } + if ( _minRequestSize > _maxPayload ) { + logadd( LOG_WARNING, "Reducing minRequestSize to maxPayload" ); + _minRequestSize = _maxPayload; + } } // Dump config as interpreted char buffer[2000]; @@ -229,6 +263,15 @@ static bool parse64(const char *in, atomic_int_fast64_t *out, const char *optnam while ( *end == ' ' ) end++; if ( *end == '\0' ) { exp = 0; + } else if ( *end == 'm' ) { + exp = 1; + base = 60; + } else if ( *end == 'h' ) { + exp = 1; + base = 3600; + } else if ( *end == 'd' ) { + exp = 1; + base = 24 * 3600; } else { char *pos = strchr( units, *end > 'Z' ? (*end - 32) : *end ); if ( pos == NULL ) { @@ -270,7 +313,7 @@ static bool parse32(const char *in, atomic_int *out, const char *optname) return true; } -static bool parse32u(const char *in, atomic_int *out, const char *optname) +static bool parse32u(const char *in, atomic_uint *out, const char *optname) { atomic_int_fast64_t v; if ( !parse64( in, &v, optname ) ) return false; @@ -278,7 +321,7 @@ static bool parse32u(const char *in, atomic_int *out, const char *optname) logadd( LOG_WARNING, "'%s' must be between %d and %d, but is '%s'", optname, (int)0, (int)INT_MAX, in ); return false; } - *out = (int)v; + *out = (unsigned int)v; return true; } @@ -309,8 +352,10 @@ size_t globals_dumpConfig(char *buffer, size_t size) PBOOL(backgroundReplication); } PINT(bgrMinClients); + PINT(bgrWindowSize); PBOOL(lookupMissingForProxy); PBOOL(sparseFiles); + PBOOL(ignoreAllocErrors); PBOOL(removeMissingImages); PINT(uplinkTimeout); PINT(clientTimeout); @@ -318,11 +363,14 @@ size_t globals_dumpConfig(char *buffer, size_t size) PBOOL(vmdkLegacyMode); PBOOL(proxyPrivateOnly); PBOOL(pretendClient); + PINT(autoFreeDiskSpaceDelay); P_ARG("[limits]\n"); PINT(maxClients); PINT(maxImages); PINT(maxPayload); PUINT64(maxReplicationSize); + PINT(maxPrefetch); + PINT(minRequestSize); return size - rem; } |