X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fqache.c;h=eeea2b6b01d7ad121cef2ebbdfbe5317e87c6f38;hb=e22bedb2382ad8c11b00e26b67fadecd30fa90fd;hp=4fb00e7fe55c92776e5f64863fcfe6adf74d1ced;hpb=561a11755d11c05dcb855abc08365b9437198551;p=libucw.git diff --git a/lib/qache.c b/lib/qache.c index 4fb00e7f..eeea2b6b 100644 --- a/lib/qache.c +++ b/lib/qache.c @@ -7,14 +7,16 @@ #undef LOCAL_DEBUG #include "lib/lib.h" +#include "lib/bitops.h" #include "lib/fastbuf.h" +#include "lib/ff-binary.h" #include "lib/qache.h" -#include +#include #include #include +#include #include -#include /* * The cache lives in a mmapped file of the following format: @@ -80,9 +82,9 @@ qache_msync(struct qache *q UNUSED, uns start UNUSED, uns len UNUSED) { #ifndef CONFIG_LINUX /* We don't need msyncing on Linux, since the mappings are guaranteed to be coherent */ - len += (start % PAGE_SIZE); - start -= start % PAGE_SIZE; - len = ALIGN(len, PAGE_SIZE); + len += (start % CPU_PAGE_SIZE); + start -= start % CPU_PAGE_SIZE; + len = ALIGN_TO(len, CPU_PAGE_SIZE); if (msync(q->mmap_data + start, len, MS_ASYNC | MS_INVALIDATE) < 0) log(L_ERROR, "Cache %s: msync failed: %m", q->file_name); #endif @@ -313,7 +315,7 @@ qache_create(struct qache *q, struct qache_params *par) bzero(&h, sizeof(h)); h.magic = QACHE_MAGIC; h.block_size = par->block_size; - h.block_shift = fls(h.block_size); + h.block_shift = bit_fls(h.block_size); h.num_blocks = par->cache_size >> h.block_shift; h.format_id = par->format_id; h.entry_table_start = sizeof(h); @@ -371,7 +373,7 @@ qache_create(struct qache *q, struct qache_params *par) log(L_INFO, "Cache %s: created (%d bytes, %d slots, %d buckets)", q->file_name, par->cache_size, h.max_entries, h.hash_size); if ((q->mmap_data = mmap(NULL, par->cache_size, PROT_READ | PROT_WRITE, MAP_SHARED, q->fd, 0)) == MAP_FAILED) - die("Cache %s: mmap failed (%m)", par->cache_size); + die("Cache %s: mmap failed (%m)", par->file_name); q->file_size = par->cache_size; qache_setup_pointers(q); } @@ -383,12 +385,12 @@ qache_open(struct qache_params *par) q->file_name = xstrdup(par->file_name); ASSERT(par->block_size >= 8 && !(par->block_size & (par->block_size-1))); - par->cache_size = ALIGN(par->cache_size, par->block_size); + par->cache_size = ALIGN_TO(par->cache_size, par->block_size); if (par->force_reset <= 0 && qache_open_existing(q, par)) ; else if (par->force_reset < 0) - die("Cache %s: read-only access requested, but no data available"); + die("Cache %s: read-only access requested, but no data available", q->file_name); else qache_create(q, par); return q;