From f4793c7059f0a71fd3e926b1ee2f33b043cf3223 Mon Sep 17 00:00:00 2001 From: nick Date: Mon, 23 Sep 2013 16:58:40 +0100 Subject: [PATCH] bitset: Rename bitset_mapping to bitset --- src/bitset.h | 44 ++++++++++++++++++--------------------- src/client.c | 2 +- src/ioutil.c | 2 +- src/ioutil.h | 4 ++-- src/serve.h | 2 +- tests/unit/check_bitset.c | 28 ++++++++++++------------- 6 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/bitset.h b/src/bitset.h index 9cb0d78..bbb3624 100644 --- a/src/bitset.h +++ b/src/bitset.h @@ -146,7 +146,7 @@ struct bitset_stream { * represent one bit per chunk. We also bundle a lock so that the set can be * written reliably by multiple threads. */ -struct bitset_mapping { +struct bitset { pthread_mutex_t lock; uint64_t size; int resolution; @@ -155,17 +155,13 @@ struct bitset_mapping { char bits[]; }; -/** Allocate a bitset_mapping for a file of the given size, and chunks of the +/** Allocate a bitset for a file of the given size, and chunks of the * given resolution. */ -static inline struct bitset_mapping* bitset_alloc( - uint64_t size, - int resolution -) +static inline struct bitset *bitset_alloc( uint64_t size, int resolution ) { - struct bitset_mapping *bitset = xmalloc( - sizeof(struct bitset_mapping)+ - (size+resolution-1)/resolution + struct bitset *bitset = xmalloc( + sizeof( struct bitset ) + ( size + resolution - 1 ) / resolution ); bitset->size = size; bitset->resolution = resolution; @@ -181,7 +177,7 @@ static inline struct bitset_mapping* bitset_alloc( return bitset; } -static inline void bitset_free( struct bitset_mapping * set ) +static inline void bitset_free( struct bitset * set ) { /* TODO: free our mutex... */ @@ -204,7 +200,7 @@ static inline void bitset_free( struct bitset_mapping * set ) static inline void bitset_stream_enqueue( - struct bitset_mapping * set, + struct bitset * set, enum bitset_stream_events event, uint64_t from, uint64_t len @@ -233,7 +229,7 @@ static inline void bitset_stream_enqueue( } static inline void bitset_stream_dequeue( - struct bitset_mapping * set, + struct bitset * set, struct bitset_stream_entry * out ) { @@ -261,7 +257,7 @@ static inline void bitset_stream_dequeue( return; } -static inline int bitset_stream_size( struct bitset_mapping * set ) +static inline int bitset_stream_size( struct bitset * set ) { int size; @@ -273,7 +269,7 @@ static inline int bitset_stream_size( struct bitset_mapping * set ) } static inline uint64_t bitset_stream_queued_bytes( - struct bitset_mapping * set, + struct bitset * set, enum bitset_stream_events event ) { @@ -293,7 +289,7 @@ static inline uint64_t bitset_stream_queued_bytes( return total; } -static inline void bitset_stream_on( struct bitset_mapping * set ) +static inline void bitset_stream_on( struct bitset * set ) { BITSET_LOCK; set->stream_enabled = 1; @@ -301,7 +297,7 @@ static inline void bitset_stream_on( struct bitset_mapping * set ) BITSET_UNLOCK; } -static inline void bitset_stream_off( struct bitset_mapping * set ) +static inline void bitset_stream_off( struct bitset * set ) { BITSET_LOCK; bitset_stream_enqueue( set, BITSET_STREAM_OFF, 0, set->size ); @@ -313,7 +309,7 @@ static inline void bitset_stream_off( struct bitset_mapping * set ) * file. */ static inline void bitset_set_range( - struct bitset_mapping* set, + struct bitset * set, uint64_t from, uint64_t len) { @@ -330,7 +326,7 @@ static inline void bitset_set_range( /** Set every bit in the bitset. */ -static inline void bitset_set( struct bitset_mapping* set ) +static inline void bitset_set( struct bitset * set ) { bitset_set_range(set, 0, set->size); } @@ -339,7 +335,7 @@ static inline void bitset_set( struct bitset_mapping* set ) * larger file. */ static inline void bitset_clear_range( - struct bitset_mapping* set, + struct bitset * set, uint64_t from, uint64_t len) { @@ -356,7 +352,7 @@ static inline void bitset_clear_range( /** Clear every bit in the bitset. */ -static inline void bitset_clear( struct bitset_mapping *set ) +static inline void bitset_clear( struct bitset * set ) { bitset_clear_range(set, 0, set->size); } @@ -365,7 +361,7 @@ static inline void bitset_clear( struct bitset_mapping *set ) * or unset, atomically. */ static inline uint64_t bitset_run_count_ex( - struct bitset_mapping* set, + struct bitset * set, uint64_t from, uint64_t len, int* run_is_set @@ -393,7 +389,7 @@ static inline uint64_t bitset_run_count_ex( * the bit field. */ static inline uint64_t bitset_run_count( - struct bitset_mapping* set, + struct bitset * set, uint64_t from, uint64_t len) { @@ -402,14 +398,14 @@ static inline uint64_t bitset_run_count( /** Tests whether the bit field is clear for the given file offset. */ -static inline int bitset_is_clear_at( struct bitset_mapping* set, uint64_t at ) +static inline int bitset_is_clear_at( struct bitset * set, uint64_t at ) { return bit_is_clear(set->bits, at/set->resolution); } /** Tests whether the bit field is set for the given file offset. */ -static inline int bitset_is_set_at( struct bitset_mapping* set, uint64_t at ) +static inline int bitset_is_set_at( struct bitset * set, uint64_t at ) { return bit_is_set(set->bits, at/set->resolution); } diff --git a/src/client.c b/src/client.c index 406438b..ac94696 100644 --- a/src/client.c +++ b/src/client.c @@ -85,7 +85,7 @@ void write_not_zeroes(struct client* client, uint64_t from, uint64_t len) NULLCHECK( client->serve ); NULLCHECK( client->serve->allocation_map ); - struct bitset_mapping *map = client->serve->allocation_map; + struct bitset * map = client->serve->allocation_map; while (len > 0) { /* so we have to calculate how much of our input to consider diff --git a/src/ioutil.c b/src/ioutil.c index 1c8d059..14eef32 100644 --- a/src/ioutil.c +++ b/src/ioutil.c @@ -13,7 +13,7 @@ #include "ioutil.h" -int build_allocation_map(struct bitset_mapping* allocation_map, int fd) +int build_allocation_map(struct bitset * allocation_map, int fd) { /* break blocking ioctls down */ const unsigned long max_length = 100*1024*1024; diff --git a/src/ioutil.h b/src/ioutil.h index 6a7ed97..9a7c969 100644 --- a/src/ioutil.h +++ b/src/ioutil.h @@ -12,7 +12,7 @@ ssize_t iobuf_read( int fd, struct iobuf* iobuf, size_t default_size ); ssize_t iobuf_write( int fd, struct iobuf* iobuf ); #include "serve.h" -struct bitset_mapping; /* don't need whole of bitset.h here */ +struct bitset; /* don't need whole of bitset.h here */ /** Scan the file opened in ''fd'', set bits in ''allocation_map'' that * correspond to which blocks are physically allocated on disc (or part- @@ -20,7 +20,7 @@ struct bitset_mapping; /* don't need whole of bitset.h here */ * than you've asked for, any block or part block will count as "allocated" * with the corresponding bit set. Returns 1 if successful, 0 otherwise. */ -int build_allocation_map(struct bitset_mapping* allocation_map, int fd); +int build_allocation_map(struct bitset * allocation_map, int fd); /** Repeat a write() operation that succeeds partially until ''size'' bytes * are written, or an error is returned, when it returns -1 as usual. diff --git a/src/serve.h b/src/serve.h index ddacc94..8d1043a 100644 --- a/src/serve.h +++ b/src/serve.h @@ -73,7 +73,7 @@ struct server { * blocks can never become unallocated again, as is the case with ext3 * at least). */ - struct bitset_mapping* allocation_map; + struct bitset * allocation_map; /* when starting up, this thread builds the allocation_map */ pthread_t allocation_map_builder_thread; /* when the thread has finished, it sets this to 1 */ diff --git a/tests/unit/check_bitset.c b/tests/unit/check_bitset.c index cc3315d..e563207 100644 --- a/tests/unit/check_bitset.c +++ b/tests/unit/check_bitset.c @@ -113,7 +113,7 @@ END_TEST START_TEST(test_bitset) { - struct bitset_mapping* map; + struct bitset * map; uint64_t *num; map = bitset_alloc(6400, 100); @@ -148,7 +148,7 @@ END_TEST START_TEST( test_bitset_set ) { - struct bitset_mapping* map; + struct bitset * map; uint64_t run; map = bitset_alloc(64, 1); @@ -179,7 +179,7 @@ END_TEST START_TEST( test_bitset_clear ) { - struct bitset_mapping* map; + struct bitset * map; uint64_t *num; uint64_t run; @@ -205,7 +205,7 @@ END_TEST START_TEST( test_bitset_set_range ) { - struct bitset_mapping* map = bitset_alloc( 64, 1 ); + struct bitset* map = bitset_alloc( 64, 1 ); assert_bitset_is( map, 0x0000000000000000 ); bitset_set_range( map, 8, 8 ); @@ -222,7 +222,7 @@ END_TEST START_TEST( test_bitset_clear_range ) { - struct bitset_mapping* map = bitset_alloc( 64, 1 ); + struct bitset* map = bitset_alloc( 64, 1 ); bitset_set( map ); assert_bitset_is( map, 0xffffffffffffffff ); @@ -240,7 +240,7 @@ END_TEST START_TEST( test_bitset_run_count ) { - struct bitset_mapping* map = bitset_alloc( 64, 1 ); + struct bitset* map = bitset_alloc( 64, 1 ); uint64_t run; assert_bitset_is( map, 0x0000000000000000 ); @@ -308,7 +308,7 @@ END_TEST START_TEST( test_bitset_set_range_doesnt_push_to_stream ) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); bitset_set_range( map, 0, 64 ); ck_assert_int_eq( 0, bitset_stream_size( map ) ); bitset_free( map ); @@ -317,7 +317,7 @@ END_TEST START_TEST( test_bitset_clear_range_doesnt_push_to_stream ) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); bitset_clear_range( map, 0, 64 ); ck_assert_int_eq( 0, bitset_stream_size( map ) ); bitset_free( map ); @@ -326,7 +326,7 @@ END_TEST START_TEST(test_bitset_stream_on) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); struct bitset_stream_entry result; memset( &result, 0, sizeof( result ) ); @@ -346,7 +346,7 @@ END_TEST START_TEST(test_bitset_stream_off) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); struct bitset_stream_entry result; memset( &result, 0, sizeof( result ) ); @@ -369,7 +369,7 @@ END_TEST START_TEST(test_bitset_stream_with_set_range) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); struct bitset_stream_entry result; memset( &result, 0, sizeof( result ) ); @@ -391,7 +391,7 @@ END_TEST START_TEST(test_bitset_stream_with_clear_range) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); struct bitset_stream_entry result; memset( &result, 0, sizeof( result ) ); @@ -412,7 +412,7 @@ END_TEST START_TEST(test_bitset_stream_size) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); bitset_stream_on( map ); bitset_set_range( map, 0, 32 ); bitset_set_range( map, 16, 32 ); @@ -431,7 +431,7 @@ END_TEST START_TEST(test_bitset_stream_queued_bytes) { - struct bitset_mapping *map = bitset_alloc( 64, 1 ); + struct bitset *map = bitset_alloc( 64, 1 ); bitset_stream_on( map ); bitset_set_range( map, 0, 32 ); bitset_set_range( map, 16, 32 );