From 6018052c8584f697b5a0fff19ba6d00ad8df2ee4 Mon Sep 17 00:00:00 2001 From: sr Date: Tue, 16 Jul 2013 12:11:45 +0200 Subject: Fix bugs from rewrite so it actually works --- src/server/image.c | 22 +++++++++++++--------- src/server/server.c | 3 +++ src/server/uplink.c | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/server/image.c b/src/server/image.c index 78b528a..4fe465b 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -104,8 +104,10 @@ dnbd3_image_t* image_get(char *name, uint16_t revision) pthread_spin_lock( &_images_lock ); for (i = 0; i < _num_images; ++i) { dnbd3_image_t * const image = _images[i]; - if ( image == NULL ) continue; - if ( strcmp( image->lower_name, name ) == 0 && revision == image->rid ) { + printf( "Comparing '%s' and '%s'..\n", name, image->lower_name ); + if ( image == NULL || strcmp( image->lower_name, name ) != 0 ) continue; + printf( "RID %d and %d\n", (int)revision, (int)image->rid ); + if ( revision == image->rid ) { candidate = image; break; } else if ( revision == 0 && (candidate == NULL || candidate->rid < image->rid) ) { @@ -121,13 +123,11 @@ dnbd3_image_t* image_get(char *name, uint16_t revision) pthread_spin_lock( &candidate->lock ); pthread_spin_unlock( &_images_lock ); - if ( candidate == NULL ) return NULL ; // Not found // Found, see if it works struct stat st; - if ( !candidate->working || stat( candidate->path, &st ) < 0 ) { - candidate->working = FALSE; - pthread_spin_unlock( &candidate->lock ); - return NULL ; // Not working (anymore) + if ( stat( candidate->path, &st ) < 0 ) { + printf( "File '%s' has gone away...\n", candidate->path ); + candidate->working = FALSE; // No file? OUT! } candidate->users++; pthread_spin_unlock( &candidate->lock ); @@ -220,6 +220,7 @@ static int image_load_all_internal(char *base, char *path) char subpath[len]; struct stat st; while ( (entry = readdir( dir )) != NULL ) { + if ( strcmp( entry->d_name, "." ) == 0 || strcmp( entry->d_name, ".." ) == 0 ) continue; if ( strlen( entry->d_name ) > SUBDIR_LEN ) { memlogf( "[WARNING] Skipping entry %s: Too long (max %d bytes)", entry->d_name, (int)SUBDIR_LEN ); continue; @@ -266,7 +267,7 @@ static int image_try_load(char *base, char *path) // Copy virtual path assert( *virtBase != '/' ); char *src = virtBase, *dst = imgName; - while ( src < lastSlash ) { + while ( src <= lastSlash ) { *dst++ = *src++; } *dst = '\0'; @@ -315,8 +316,9 @@ static int image_try_load(char *base, char *path) } // 1. Allocate memory for the cache map if the image is incomplete sprintf( mapFile, "%s.map", path ); - int fdMap = open( path, O_RDONLY ); + int fdMap = open( mapFile, O_RDONLY ); if ( fdMap >= 0 ) { + printf( "Opened %s, cache_map is %p\n", mapFile, cache_map ); size_t map_size = IMGSIZE_TO_MAPBYTES( fileSize ); cache_map = calloc( 1, map_size ); int rd = read( fdMap, cache_map, map_size ); @@ -403,6 +405,7 @@ static int image_try_load(char *base, char *path) image->atime = time( NULL ); } image->working = (image->cache_map == NULL ); + printf( "Map: %p, work: %d\n", image->cache_map, (int)image->working ); pthread_spin_init( &image->lock, PTHREAD_PROCESS_PRIVATE ); // Get rid of cache map if image is complete if ( image->cache_map != NULL && image_is_complete( image ) ) { @@ -429,6 +432,7 @@ static int image_try_load(char *base, char *path) goto load_error; } _images[_num_images++] = image; + printf( "[DEBUG] Loaded image '%s'\n", image->lower_name ); } pthread_spin_unlock( &_images_lock ); function_return = TRUE; diff --git a/src/server/server.c b/src/server/server.c index 97bf00a..85461ff 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -199,6 +199,9 @@ int main(int argc, char *argv[]) if ( demonize ) daemon( 1, 0 ); + _basePath = strdup("/home/sr/vmware/"); + _vmdkLegacyMode = TRUE; + pthread_spin_init( &_clients_lock, PTHREAD_PROCESS_PRIVATE ); pthread_spin_init( &_images_lock, PTHREAD_PROCESS_PRIVATE ); pthread_spin_init( &_alts_lock, PTHREAD_PROCESS_PRIVATE ); diff --git a/src/server/uplink.c b/src/server/uplink.c index 7675a76..797b287 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -13,7 +13,7 @@ pthread_spinlock_t _alts_lock; */ int uplink_get_matching_alt_servers(dnbd3_host_t *host, dnbd3_server_entry_t *output, int size) { - if ( host == NULL || host->type == 0 ) return 0; + if ( host == NULL || host->type == 0 || _num_alts == 0 ) return 0; int i, j; int count = 0; int distance[size]; -- cgit v1.2.3-55-g7522