diff options
author | sr | 2013-07-17 13:57:54 +0200 |
---|---|---|
committer | sr | 2013-07-17 13:57:54 +0200 |
commit | 04f5acf26c68533b8d447d4a77be6be4191f27ad (patch) | |
tree | 58b6329787a871e67b702c7534cada595b388727 /src/server/image.c | |
parent | Replace all pthread_spin_* calls with spin_*, so that all locking can be trac... (diff) | |
download | dnbd3-04f5acf26c68533b8d447d4a77be6be4191f27ad.tar.gz dnbd3-04f5acf26c68533b8d447d4a77be6be4191f27ad.tar.xz dnbd3-04f5acf26c68533b8d447d4a77be6be4191f27ad.zip |
Remove all glib dependencies from server
Diffstat (limited to 'src/server/image.c')
-rw-r--r-- | src/server/image.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/server/image.c b/src/server/image.c index 8a01c9a..3e24b86 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -4,7 +4,6 @@ #include "uplink.h" #include "locks.h" -#include <glib/gmacros.h> #include <assert.h> #include <stdio.h> #include <fcntl.h> @@ -26,7 +25,6 @@ pthread_spinlock_t _images_lock; static int image_load_all_internal(char *base, char *path); static int image_try_load(char *base, char *path); static int image_check_blocks_crc32(int fd, uint32_t *crc32list, int *blocks); -static dnbd3_image_t* image_free(dnbd3_image_t *image); // ########################################## @@ -72,6 +70,7 @@ int image_is_complete(dnbd3_image_t *image) int image_save_cache_map(dnbd3_image_t *image) { if ( image == NULL || image->cache_map == NULL ) return TRUE; + assert( image->path != NULL ); char mapfile[strlen( image->path ) + 4 + 1]; int fd; strcpy( mapfile, image->path ); @@ -172,6 +171,7 @@ void image_release(dnbd3_image_t *image) /** * Remove image from images array. Only free it if it has * no active users + * Locks on: _images_lock, image[].lock */ void image_remove(dnbd3_image_t *image) { @@ -188,6 +188,28 @@ void image_remove(dnbd3_image_t *image) } /** + * Free image. DOES NOT check if it's in use. + * DOES NOT lock on anything. + * DO NOT lock on the image when calling. + */ +dnbd3_image_t* image_free(dnbd3_image_t *image) +{ + assert( image != NULL ); + // + image_save_cache_map( image ); + free( image->cache_map ); + free( image->crc32 ); + free( image->path ); + free( image->lower_name ); + uplink_shutdown( image->uplink ); + spin_destroy( &image->lock ); + // + memset( image, 0, sizeof(dnbd3_image_t) ); + free( image ); + return NULL ; +} + +/** * Load all images in given path recursively. * Pass NULL to use path from config. */ @@ -472,22 +494,6 @@ static int image_check_blocks_crc32(int fd, uint32_t *crc32list, int *blocks) return TRUE; } -static dnbd3_image_t* image_free(dnbd3_image_t *image) -{ - assert( image != NULL ); - // - free( image->cache_map ); - free( image->crc32 ); - free( image->path ); - free( image->lower_name ); - uplink_shutdown( image->uplink ); - spin_destroy( &image->lock ); - // - memset( image, 0, sizeof(dnbd3_image_t) ); - free( image ); - return NULL ; -} - /* void image_find_latest() { |