summaryrefslogtreecommitdiffstats
path: root/src/server/image.c
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-17 14:20:12 +0100
committerSimon Rettberg2015-12-17 14:20:12 +0100
commit3de54fac10b3dbdcfc3573e175078c7104837ef3 (patch)
tree307abe2cc283900c0ce0594c7d40d833d8b27c92 /src/server/image.c
parent[SERVER] Cancel scanning of image dir if _shutdown is set (diff)
downloaddnbd3-3de54fac10b3dbdcfc3573e175078c7104837ef3.tar.gz
dnbd3-3de54fac10b3dbdcfc3573e175078c7104837ef3.tar.xz
dnbd3-3de54fac10b3dbdcfc3573e175078c7104837ef3.zip
[SERVER] image_markComplete now handles locking so we remove() unlocked
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 );
+ }
}
/**