bitset: Rename bitset_mapping to bitset

This commit is contained in:
nick
2013-09-23 16:58:40 +01:00
parent 0f0697a0aa
commit f4793c7059
6 changed files with 39 additions and 43 deletions

View File

@@ -146,7 +146,7 @@ struct bitset_stream {
* represent one bit per chunk. We also bundle a lock so that the set can be * represent one bit per chunk. We also bundle a lock so that the set can be
* written reliably by multiple threads. * written reliably by multiple threads.
*/ */
struct bitset_mapping { struct bitset {
pthread_mutex_t lock; pthread_mutex_t lock;
uint64_t size; uint64_t size;
int resolution; int resolution;
@@ -155,17 +155,13 @@ struct bitset_mapping {
char bits[]; 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. * given resolution.
*/ */
static inline struct bitset_mapping* bitset_alloc( static inline struct bitset *bitset_alloc( uint64_t size, int resolution )
uint64_t size,
int resolution
)
{ {
struct bitset_mapping *bitset = xmalloc( struct bitset *bitset = xmalloc(
sizeof(struct bitset_mapping)+ sizeof( struct bitset ) + ( size + resolution - 1 ) / resolution
(size+resolution-1)/resolution
); );
bitset->size = size; bitset->size = size;
bitset->resolution = resolution; bitset->resolution = resolution;
@@ -181,7 +177,7 @@ static inline struct bitset_mapping* bitset_alloc(
return bitset; return bitset;
} }
static inline void bitset_free( struct bitset_mapping * set ) static inline void bitset_free( struct bitset * set )
{ {
/* TODO: free our mutex... */ /* TODO: free our mutex... */
@@ -204,7 +200,7 @@ static inline void bitset_free( struct bitset_mapping * set )
static inline void bitset_stream_enqueue( static inline void bitset_stream_enqueue(
struct bitset_mapping * set, struct bitset * set,
enum bitset_stream_events event, enum bitset_stream_events event,
uint64_t from, uint64_t from,
uint64_t len uint64_t len
@@ -233,7 +229,7 @@ static inline void bitset_stream_enqueue(
} }
static inline void bitset_stream_dequeue( static inline void bitset_stream_dequeue(
struct bitset_mapping * set, struct bitset * set,
struct bitset_stream_entry * out struct bitset_stream_entry * out
) )
{ {
@@ -261,7 +257,7 @@ static inline void bitset_stream_dequeue(
return; return;
} }
static inline int bitset_stream_size( struct bitset_mapping * set ) static inline int bitset_stream_size( struct bitset * set )
{ {
int size; int size;
@@ -273,7 +269,7 @@ static inline int bitset_stream_size( struct bitset_mapping * set )
} }
static inline uint64_t bitset_stream_queued_bytes( static inline uint64_t bitset_stream_queued_bytes(
struct bitset_mapping * set, struct bitset * set,
enum bitset_stream_events event enum bitset_stream_events event
) )
{ {
@@ -293,7 +289,7 @@ static inline uint64_t bitset_stream_queued_bytes(
return total; return total;
} }
static inline void bitset_stream_on( struct bitset_mapping * set ) static inline void bitset_stream_on( struct bitset * set )
{ {
BITSET_LOCK; BITSET_LOCK;
set->stream_enabled = 1; set->stream_enabled = 1;
@@ -301,7 +297,7 @@ static inline void bitset_stream_on( struct bitset_mapping * set )
BITSET_UNLOCK; BITSET_UNLOCK;
} }
static inline void bitset_stream_off( struct bitset_mapping * set ) static inline void bitset_stream_off( struct bitset * set )
{ {
BITSET_LOCK; BITSET_LOCK;
bitset_stream_enqueue( set, BITSET_STREAM_OFF, 0, set->size ); 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. * file.
*/ */
static inline void bitset_set_range( static inline void bitset_set_range(
struct bitset_mapping* set, struct bitset * set,
uint64_t from, uint64_t from,
uint64_t len) uint64_t len)
{ {
@@ -330,7 +326,7 @@ static inline void bitset_set_range(
/** Set every bit in the bitset. */ /** 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); bitset_set_range(set, 0, set->size);
} }
@@ -339,7 +335,7 @@ static inline void bitset_set( struct bitset_mapping* set )
* larger file. * larger file.
*/ */
static inline void bitset_clear_range( static inline void bitset_clear_range(
struct bitset_mapping* set, struct bitset * set,
uint64_t from, uint64_t from,
uint64_t len) uint64_t len)
{ {
@@ -356,7 +352,7 @@ static inline void bitset_clear_range(
/** Clear every bit in the bitset. */ /** 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); bitset_clear_range(set, 0, set->size);
} }
@@ -365,7 +361,7 @@ static inline void bitset_clear( struct bitset_mapping *set )
* or unset, atomically. * or unset, atomically.
*/ */
static inline uint64_t bitset_run_count_ex( static inline uint64_t bitset_run_count_ex(
struct bitset_mapping* set, struct bitset * set,
uint64_t from, uint64_t from,
uint64_t len, uint64_t len,
int* run_is_set int* run_is_set
@@ -393,7 +389,7 @@ static inline uint64_t bitset_run_count_ex(
* the bit field. * the bit field.
*/ */
static inline uint64_t bitset_run_count( static inline uint64_t bitset_run_count(
struct bitset_mapping* set, struct bitset * set,
uint64_t from, uint64_t from,
uint64_t len) 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. /** 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); return bit_is_clear(set->bits, at/set->resolution);
} }
/** Tests whether the bit field is set for the given file offset. /** 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); return bit_is_set(set->bits, at/set->resolution);
} }

View File

@@ -85,7 +85,7 @@ void write_not_zeroes(struct client* client, uint64_t from, uint64_t len)
NULLCHECK( client->serve ); NULLCHECK( client->serve );
NULLCHECK( client->serve->allocation_map ); NULLCHECK( client->serve->allocation_map );
struct bitset_mapping *map = client->serve->allocation_map; struct bitset * map = client->serve->allocation_map;
while (len > 0) { while (len > 0) {
/* so we have to calculate how much of our input to consider /* so we have to calculate how much of our input to consider

View File

@@ -13,7 +13,7 @@
#include "ioutil.h" #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 */ /* break blocking ioctls down */
const unsigned long max_length = 100*1024*1024; const unsigned long max_length = 100*1024*1024;

View File

@@ -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 ); ssize_t iobuf_write( int fd, struct iobuf* iobuf );
#include "serve.h" #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 /** Scan the file opened in ''fd'', set bits in ''allocation_map'' that
* correspond to which blocks are physically allocated on disc (or part- * 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" * 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. * 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 /** Repeat a write() operation that succeeds partially until ''size'' bytes
* are written, or an error is returned, when it returns -1 as usual. * are written, or an error is returned, when it returns -1 as usual.

View File

@@ -73,7 +73,7 @@ struct server {
* blocks can never become unallocated again, as is the case with ext3 * blocks can never become unallocated again, as is the case with ext3
* at least). * at least).
*/ */
struct bitset_mapping* allocation_map; struct bitset * allocation_map;
/* when starting up, this thread builds the allocation_map */ /* when starting up, this thread builds the allocation_map */
pthread_t allocation_map_builder_thread; pthread_t allocation_map_builder_thread;
/* when the thread has finished, it sets this to 1 */ /* when the thread has finished, it sets this to 1 */

View File

@@ -113,7 +113,7 @@ END_TEST
START_TEST(test_bitset) START_TEST(test_bitset)
{ {
struct bitset_mapping* map; struct bitset * map;
uint64_t *num; uint64_t *num;
map = bitset_alloc(6400, 100); map = bitset_alloc(6400, 100);
@@ -148,7 +148,7 @@ END_TEST
START_TEST( test_bitset_set ) START_TEST( test_bitset_set )
{ {
struct bitset_mapping* map; struct bitset * map;
uint64_t run; uint64_t run;
map = bitset_alloc(64, 1); map = bitset_alloc(64, 1);
@@ -179,7 +179,7 @@ END_TEST
START_TEST( test_bitset_clear ) START_TEST( test_bitset_clear )
{ {
struct bitset_mapping* map; struct bitset * map;
uint64_t *num; uint64_t *num;
uint64_t run; uint64_t run;
@@ -205,7 +205,7 @@ END_TEST
START_TEST( test_bitset_set_range ) 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 ); assert_bitset_is( map, 0x0000000000000000 );
bitset_set_range( map, 8, 8 ); bitset_set_range( map, 8, 8 );
@@ -222,7 +222,7 @@ END_TEST
START_TEST( test_bitset_clear_range ) START_TEST( test_bitset_clear_range )
{ {
struct bitset_mapping* map = bitset_alloc( 64, 1 ); struct bitset* map = bitset_alloc( 64, 1 );
bitset_set( map ); bitset_set( map );
assert_bitset_is( map, 0xffffffffffffffff ); assert_bitset_is( map, 0xffffffffffffffff );
@@ -240,7 +240,7 @@ END_TEST
START_TEST( test_bitset_run_count ) START_TEST( test_bitset_run_count )
{ {
struct bitset_mapping* map = bitset_alloc( 64, 1 ); struct bitset* map = bitset_alloc( 64, 1 );
uint64_t run; uint64_t run;
assert_bitset_is( map, 0x0000000000000000 ); assert_bitset_is( map, 0x0000000000000000 );
@@ -308,7 +308,7 @@ END_TEST
START_TEST( test_bitset_set_range_doesnt_push_to_stream ) 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 ); bitset_set_range( map, 0, 64 );
ck_assert_int_eq( 0, bitset_stream_size( map ) ); ck_assert_int_eq( 0, bitset_stream_size( map ) );
bitset_free( map ); bitset_free( map );
@@ -317,7 +317,7 @@ END_TEST
START_TEST( test_bitset_clear_range_doesnt_push_to_stream ) 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 ); bitset_clear_range( map, 0, 64 );
ck_assert_int_eq( 0, bitset_stream_size( map ) ); ck_assert_int_eq( 0, bitset_stream_size( map ) );
bitset_free( map ); bitset_free( map );
@@ -326,7 +326,7 @@ END_TEST
START_TEST(test_bitset_stream_on) 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; struct bitset_stream_entry result;
memset( &result, 0, sizeof( result ) ); memset( &result, 0, sizeof( result ) );
@@ -346,7 +346,7 @@ END_TEST
START_TEST(test_bitset_stream_off) 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; struct bitset_stream_entry result;
memset( &result, 0, sizeof( result ) ); memset( &result, 0, sizeof( result ) );
@@ -369,7 +369,7 @@ END_TEST
START_TEST(test_bitset_stream_with_set_range) 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; struct bitset_stream_entry result;
memset( &result, 0, sizeof( result ) ); memset( &result, 0, sizeof( result ) );
@@ -391,7 +391,7 @@ END_TEST
START_TEST(test_bitset_stream_with_clear_range) 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; struct bitset_stream_entry result;
memset( &result, 0, sizeof( result ) ); memset( &result, 0, sizeof( result ) );
@@ -412,7 +412,7 @@ END_TEST
START_TEST(test_bitset_stream_size) 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_stream_on( map );
bitset_set_range( map, 0, 32 ); bitset_set_range( map, 0, 32 );
bitset_set_range( map, 16, 32 ); bitset_set_range( map, 16, 32 );
@@ -431,7 +431,7 @@ END_TEST
START_TEST(test_bitset_stream_queued_bytes) 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_stream_on( map );
bitset_set_range( map, 0, 32 ); bitset_set_range( map, 0, 32 );
bitset_set_range( map, 16, 32 ); bitset_set_range( map, 16, 32 );