summaryrefslogtreecommitdiffstats
path: root/src/server/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/image.c')
-rw-r--r--src/server/image.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/server/image.c b/src/server/image.c
index 1d1d6b7..6d486c4 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -162,17 +162,22 @@ void image_updateCachemap(dnbd3_image_t *image, uint64_t start, uint64_t end, co
/**
* Mark image as complete by freeing the cache_map and deleting the map file on disk
- * DOES NOT LOCK ON THE IMAGE, DO SO BEFORE CALLING
+ * Locks on: image.lock
*/
void image_markComplete(dnbd3_image_t *image)
{
+ char mapfile[PATHLEN] = "";
assert( image != NULL );
- if ( image->cache_map == NULL ) return;
- free( image->cache_map );
- image->cache_map = NULL;
- char mapfile[strlen( image->path ) + 4 + 1];
- sprintf( mapfile, "%s.map", image->path );
- remove( mapfile );
+ spin_lock( &image->lock );
+ if ( image->cache_map != NULL ) {
+ free( image->cache_map );
+ image->cache_map = NULL;
+ snprintf( mapfile, PATHLEN, "%s.map", image->path );
+ }
+ spin_unlock( &image->lock );
+ if ( mapfile[0] != '\0' ) {
+ remove( mapfile );
+ }
}
/**