summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-02-24 14:13:01 +0100
committerSimon Rettberg2020-02-24 14:13:01 +0100
commitdd0880b8ee67f9a69802a2a3ef26cd5df6881129 (patch)
tree04cdf5c186b2c5959c77484b6198bcdb21a19329
parent[SERVER] Lookup image on storage even in proxy mode (diff)
downloaddnbd3-master.tar.gz
dnbd3-master.tar.xz
dnbd3-master.zip
[SERVER] Introduce ignoreAllocErrorsHEADmaster
If enabled, a failed fallocate will not abort image replication, but retry with sparse mode.
-rw-r--r--src/server/globals.c3
-rw-r--r--src/server/globals.h6
-rw-r--r--src/server/image.c9
3 files changed, 16 insertions, 2 deletions
diff --git a/src/server/globals.c b/src/server/globals.c
index f8c3f66..2e87400 100644
--- a/src/server/globals.c
+++ b/src/server/globals.c
@@ -21,6 +21,7 @@ atomic_int _backgroundReplication = BGR_FULL;
atomic_int _bgrMinClients = 0;
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;
@@ -75,6 +76,7 @@ static int ini_handler(void *custom UNUSED, const char* section, const char* key
SAVE_TO_VAR_INT( dnbd3, bgrMinClients );
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 );
@@ -322,6 +324,7 @@ size_t globals_dumpConfig(char *buffer, size_t size)
PINT(bgrMinClients);
PBOOL(lookupMissingForProxy);
PBOOL(sparseFiles);
+ PBOOL(ignoreAllocErrors);
PBOOL(removeMissingImages);
PINT(uplinkTimeout);
PINT(clientTimeout);
diff --git a/src/server/globals.h b/src/server/globals.h
index df8c595..b1336dc 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -255,6 +255,12 @@ extern atomic_bool _lookupMissingForProxy;
extern atomic_bool _sparseFiles;
/**
+ * If true, don't abort image replication if preallocating
+ * the image fails, but retry with sparse file.
+ */
+extern atomic_bool _ignoreAllocErrors;
+
+/**
* Port to listen on (default: #define PORT (5003))
*/
extern atomic_int _listenPort;
diff --git a/src/server/image.c b/src/server/image.c
index 16dae45..6017e59 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -1111,14 +1111,19 @@ bool image_create(char *image, int revision, uint64_t size)
logadd( LOG_DEBUG1, "Could not allocate %d bytes for %s (errno=%d)", mapsize, cache, err );
}
// Now write image
+ bool fallback = false;
if ( !_sparseFiles && !file_alloc( fdImage, 0, size ) ) {
logadd( LOG_ERROR, "Could not allocate %" PRIu64 " bytes for %s (errno=%d)", size, path, errno );
logadd( LOG_ERROR, "It is highly recommended to use a file system that supports preallocating disk"
" space without actually writing all zeroes to the block device." );
logadd( LOG_ERROR, "If you cannot fix this, try setting sparseFiles=true, but don't expect"
" divine performance during replication." );
- goto failure_cleanup;
- } else if ( _sparseFiles && !file_setSize( fdImage, size ) ) {
+ if ( !_ignoreAllocErrors ) {
+ goto failure_cleanup;
+ }
+ fallback = true;
+ }
+ if ( ( _sparseFiles || fallback ) && !file_setSize( fdImage, size ) ) {
logadd( LOG_ERROR, "Could not create sparse file of %" PRIu64 " bytes for %s (errno=%d)", size, path, errno );
logadd( LOG_ERROR, "Make sure you have enough disk space, check directory permissions, fs errors etc." );
goto failure_cleanup;