From 9c482e75728556f969132eee8b0a402a508e46a6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 28 Jan 2020 16:43:46 +0100 Subject: [SERVER] Lookup image on storage even in proxy mode In proxy mode, when rid 0 is requested, we now first query our uplink servers for the latest revision and if this fails, like in non-proxy mode, we'll see what the latest version on disk is. --- src/server/image.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/server/image.c') diff --git a/src/server/image.c b/src/server/image.c index 9581a92..16dae45 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -1143,8 +1143,7 @@ static dnbd3_image_t *loadImageServer(char * const name, const uint16_t requeste * revision 0 is requested, it will: * a) Try to clone it from an authoritative dnbd3 server, if * the server is running in proxy mode. - * b) Try to load it from disk by constructing the appropriate file name, if not - * running in proxy mode. + * b) Try to load it from disk by constructing the appropriate file name. * * If the return value is not NULL, * image_release needs to be called on the image at some point. @@ -1152,21 +1151,25 @@ static dnbd3_image_t *loadImageServer(char * const name, const uint16_t requeste */ dnbd3_image_t* image_getOrLoad(char * const name, const uint16_t revision) { + dnbd3_image_t *image; // specific revision - try shortcut if ( revision != 0 ) { - dnbd3_image_t *image = image_get( name, revision, true ); - if ( image != NULL ) return image; + image = image_get( name, revision, true ); + if ( image != NULL ) + return image; } const size_t len = strlen( name ); // Sanity check if ( len == 0 || name[len - 1] == '/' || name[0] == '/' || name[0] == '.' || strstr( name, "/." ) != NULL ) return NULL; - // Call specific function depending on whether this is a proxy or not + // If in proxy mode, check with upstream server first if ( _isProxy ) { - return loadImageProxy( name, revision, len ); - } else { - return loadImageServer( name, revision ); + image = loadImageProxy( name, revision, len ); + if ( image != NULL ) + return image; } + // Lookup on local storage + return loadImageServer( name, revision ); } /** -- cgit v1.2.3-55-g7522