diff options
Diffstat (limited to 'content/fs_backing_store.c')
-rw-r--r-- | content/fs_backing_store.c | 173 |
1 files changed, 94 insertions, 79 deletions
diff --git a/content/fs_backing_store.c b/content/fs_backing_store.c index 2e7b3919a..cedb8a49f 100644 --- a/content/fs_backing_store.c +++ b/content/fs_backing_store.c @@ -519,11 +519,11 @@ invalidate_entry(struct store_state *state, struct store_entry *bse) * This entry cannot be immediately removed as it has * associated allocation so wait for allocation release. */ - LOG(("invalidating entry with referenced allocation")); + LOG("invalidating entry with referenced allocation"); return NSERROR_OK; } - LOG(("Removing entry for %p", bse)); + LOG("Removing entry for %p", bse); /* remove the entry from the index */ ret = remove_store_entry(state, &bse); @@ -533,12 +533,12 @@ invalidate_entry(struct store_state *state, struct store_entry *bse) ret = invalidate_element(state, bse, ENTRY_ELEM_META); if (ret != NSERROR_OK) { - LOG(("Error invalidating metadata element")); + LOG("Error invalidating metadata element"); } ret = invalidate_element(state, bse, ENTRY_ELEM_DATA); if (ret != NSERROR_OK) { - LOG(("Error invalidating data element")); + LOG("Error invalidating data element"); } return NSERROR_OK; @@ -620,8 +620,8 @@ static nserror store_evict(struct store_state *state) return NSERROR_OK; } - LOG(("Evicting entries to reduce %d by %d", - state->total_alloc, state->hysteresis)); + LOG("Evicting entries to reduce %"PRIu64" by %zd", + state->total_alloc, state->hysteresis); /* allocate storage for the list */ elist = malloc(sizeof(entry_ident_t) * state->last_entry); @@ -658,7 +658,7 @@ static nserror store_evict(struct store_state *state) free(elist); - LOG(("removed %d in %d entries", removed, ent)); + LOG("removed %zd in %d entries", removed, ent); return ret; } @@ -773,7 +773,7 @@ static nserror write_blocks(struct store_state *state) &state->blocks[elem_idx][bfidx].use_map[0], BLOCK_USE_MAP_SIZE); if (wr != BLOCK_USE_MAP_SIZE) { - LOG(("writing block file %d use index on file number %d failed", elem_idx, bfidx)); + LOG("writing block file %d use index on file number %d failed", elem_idx, bfidx); goto wr_err; } written += wr; @@ -829,19 +829,19 @@ static nserror set_block_extents(struct store_state *state) return NSERROR_OK; } - LOG(("Starting")); + LOG("Starting"); for (elem_idx = 0; elem_idx < ENTRY_ELEM_COUNT; elem_idx++) { for (bfidx = 0; bfidx < BLOCK_FILE_COUNT; bfidx++) { if (state->blocks[elem_idx][bfidx].fd != -1) { /* ensure block file is correct extent */ ftr = ftruncate(state->blocks[elem_idx][bfidx].fd, 1U << (log2_block_size[elem_idx] + BLOCK_ENTRY_COUNT)); if (ftr == -1) { - LOG(("Truncate failed errno:%d", errno)); + LOG("Truncate failed errno:%d", errno); } } } } - LOG(("Complete")); + LOG("Complete"); state->blocks_opened = false; @@ -886,7 +886,7 @@ get_store_entry(struct store_state *state, nsurl *url, struct store_entry **bse) entry_ident_t ident; unsigned int sei; /* store entry index */ - LOG(("url:%s", nsurl_access(url))); + LOG("url:%s", nsurl_access(url)); /* use the url hash as the entry identifier */ ident = nsurl_hash(url); @@ -894,13 +894,13 @@ get_store_entry(struct store_state *state, nsurl *url, struct store_entry **bse) sei = BS_ENTRY_INDEX(ident, state); if (sei == 0) { - LOG(("Failed to find ident 0x%x in index", ident)); + LOG("Failed to find ident 0x%x in index", ident); return NSERROR_NOT_FOUND; } if (state->entries[sei].ident != ident) { /* entry ident did not match */ - LOG(("ident did not match entry")); + LOG("ident did not match entry"); return NSERROR_NOT_FOUND; } @@ -975,7 +975,7 @@ set_store_entry(struct store_state *state, nserror ret; struct store_entry_element *elem; - LOG(("url:%s", nsurl_access(url))); + LOG("url:%s", nsurl_access(url)); /* evict entries as required and ensure there is at least one * new entry available. @@ -1013,8 +1013,7 @@ set_store_entry(struct store_state *state, * to see if the old entry is in use and if * not prefer the newly stored entry instead? */ - LOG(("Entry index collision trying to replace %x with %x", - se->ident, ident)); + LOG("Entry index collision trying to replace %x with %x", se->ident, ident); return NSERROR_PERMISSION; } } @@ -1027,7 +1026,7 @@ set_store_entry(struct store_state *state, /* this entry cannot be removed as it has associated * allocation. */ - LOG(("attempt to overwrite entry with in use data")); + LOG("attempt to overwrite entry with in use data"); return NSERROR_PERMISSION; } @@ -1086,7 +1085,7 @@ store_open(struct store_state *state, fname = store_fname(state, ident, elem_idx); if (fname == NULL) { - LOG(("filename error")); + LOG("filename error"); return -1; } @@ -1094,13 +1093,13 @@ store_open(struct store_state *state, if (openflags & O_CREAT) { ret = netsurf_mkdir_all(fname); if (ret != NSERROR_OK) { - LOG(("file path \"%s\" could not be created", fname)); + LOG("file path \"%s\" could not be created", fname); free(fname); return -1; } } - LOG(("opening %s", fname)); + LOG("opening %s", fname); fd = open(fname, openflags, S_IRUSR | S_IWUSR); free(fname); @@ -1127,9 +1126,9 @@ build_entrymap(struct store_state *state) { unsigned int eloop; - LOG(("Allocating %d bytes for max of %d buckets", - (1 << state->ident_bits) * sizeof(entry_index_t), - 1 << state->ident_bits)); + LOG("Allocating %ld bytes for max of %d buckets", + (1 << state->ident_bits) * sizeof(entry_index_t), + 1 << state->ident_bits); state->addrmap = calloc(1 << state->ident_bits, sizeof(entry_index_t)); if (state->addrmap == NULL) { @@ -1205,10 +1204,10 @@ read_entries(struct store_state *state) entries_size = (1 << state->entry_bits) * sizeof(struct store_entry); - LOG(("Allocating %d bytes for max of %d entries of %d length elements %d length", - entries_size, 1 << state->entry_bits, - sizeof(struct store_entry), - sizeof(struct store_entry_element))); + LOG("Allocating %zd bytes for max of %d entries of %ld length elements %ld length", + entries_size, 1 << state->entry_bits, + sizeof(struct store_entry), + sizeof(struct store_entry_element)); state->entries = calloc(1, entries_size); if (state->entries == NULL) { @@ -1223,7 +1222,7 @@ read_entries(struct store_state *state) close(fd); if (rd > 0) { state->last_entry = rd / sizeof(struct store_entry); - LOG(("Read %d entries", state->last_entry)); + LOG("Read %d entries", state->last_entry); } } else { /* could rebuild entries from fs */ @@ -1254,7 +1253,7 @@ read_blocks(struct store_state *state) return ret; } - LOG(("Initialising block use map from %s", fname)); + LOG("Initialising block use map from %s", fname); fd = open(fname, O_RDWR); free(fname); @@ -1266,7 +1265,7 @@ read_blocks(struct store_state *state) &state->blocks[elem_idx][bfidx].use_map[0], BLOCK_USE_MAP_SIZE); if (rd <= 0) { - LOG(("reading block file %d use index on file number %d failed", elem_idx, bfidx)); + LOG("reading block file %d use index on file number %d failed", elem_idx, bfidx); goto rd_err; } } @@ -1275,7 +1274,7 @@ read_blocks(struct store_state *state) close(fd); } else { - LOG(("Initialising block use map to defaults")); + LOG("Initialising block use map to defaults"); /* ensure block 0 (invalid sentinal) is skipped */ state->blocks[ENTRY_ELEM_DATA][0].use_map[0] = 1; state->blocks[ENTRY_ELEM_META][0].use_map[0] = 1; @@ -1345,7 +1344,7 @@ write_control(struct store_state *state) return ret; } - LOG(("writing control file \"%s\"", fname)); + LOG("writing control file \"%s\"", fname); ret = netsurf_mkdir_all(fname); if (ret != NSERROR_OK) { @@ -1393,7 +1392,7 @@ read_control(struct store_state *state) return ret; } - LOG(("opening control file \"%s\"", fname)); + LOG("opening control file \"%s\"", fname); fcontrol = fopen(fname, "rb"); @@ -1510,7 +1509,7 @@ initialise(const struct llcache_store_parameters *parameters) /* read store control and create new if required */ ret = read_control(newstate); if (ret != NSERROR_OK) { - LOG(("read control failed %s", messages_get_errorcode(ret))); + LOG("read control failed %s", messages_get_errorcode(ret)); ret = write_control(newstate); if (ret == NSERROR_OK) { unlink_entries(newstate); @@ -1559,12 +1558,15 @@ initialise(const struct llcache_store_parameters *parameters) storestate = newstate; - LOG(("FS backing store init successful")); + LOG("FS backing store init successful"); - LOG(("path:%s limit:%d hyst:%d addr:%d entries:%d", - newstate->path, newstate->limit, newstate->hysteresis, - newstate->ident_bits, newstate->entry_bits)); - LOG(("Using %lld/%lld", newstate->total_alloc, newstate->limit)); + LOG("path:%s limit:%zd hyst:%zd addr:%d entries:%d", + newstate->path, + newstate->limit, + newstate->hysteresis, + newstate->ident_bits, + newstate->entry_bits); + LOG("Using %"PRIu64"/%zd", newstate->total_alloc, newstate->limit); return NSERROR_OK; } @@ -1603,14 +1605,14 @@ finalise(void) /* avoid division by zero */ if (op_count > 0) { - LOG(("Cache total/hit/miss/fail (counts) %d/%d/%d/%d (100%%/%d%%/%d%%/%d%%)", - op_count, - storestate->hit_count, - storestate->miss_count, - 0, - (storestate->hit_count * 100) / op_count, - (storestate->miss_count * 100) / op_count, - 0)); + LOG("Cache total/hit/miss/fail (counts) %d/%zd/%zd/%d (100%%/%zd%%/%zd%%/%d%%)", + op_count, + storestate->hit_count, + storestate->miss_count, + 0, + (storestate->hit_count * 100) / op_count, + (storestate->miss_count * 100) / op_count, + 0); } free(storestate->path); @@ -1644,7 +1646,7 @@ static nserror store_write_block(struct store_state *state, state->blocks[elem_idx][bf].fd = store_open(state, bf, elem_idx + ENTRY_ELEM_COUNT, O_CREAT | O_RDWR); if (state->blocks[elem_idx][bf].fd == -1) { - LOG(("Open failed errno %d", errno)); + LOG("Open failed errno %d", errno); return NSERROR_SAVE_FAILED; } @@ -1659,15 +1661,21 @@ static nserror store_write_block(struct store_state *state, bse->elem[elem_idx].size, offst); if (wr != (ssize_t)bse->elem[elem_idx].size) { - LOG(("Write failed %d of %d bytes from %p at 0x%x block %d errno %d", - wr, bse->elem[elem_idx].size, bse->elem[elem_idx].data, - offst, bse->elem[elem_idx].block, errno)); + LOG("Write failed %zd of %d bytes from %p at 0x%jx block %d errno %d", + wr, + bse->elem[elem_idx].size, + bse->elem[elem_idx].data, + (uintmax_t)offst, + bse->elem[elem_idx].block, + errno); return NSERROR_SAVE_FAILED; } - LOG(("Wrote %d bytes from %p at 0x%x block %d", - wr, bse->elem[elem_idx].data, - offst, bse->elem[elem_idx].block)); + LOG("Wrote %zd bytes from %p at 0x%jx block %d", + wr, + bse->elem[elem_idx].data, + (uintmax_t)offst, + bse->elem[elem_idx].block); return NSERROR_OK; } @@ -1691,7 +1699,7 @@ static nserror store_write_file(struct store_state *state, fd = store_open(state, bse->ident, elem_idx, O_CREAT | O_WRONLY); if (fd < 0) { perror(""); - LOG(("Open failed %d errno %d", fd, errno)); + LOG("Open failed %d errno %d", fd, errno); return NSERROR_SAVE_FAILED; } @@ -1700,15 +1708,17 @@ static nserror store_write_file(struct store_state *state, close(fd); if (wr != (ssize_t)bse->elem[elem_idx].size) { - LOG(("Write failed %d of %d bytes from %p errno %d", - wr, bse->elem[elem_idx].size, bse->elem[elem_idx].data, - err)); + LOG("Write failed %zd of %d bytes from %p errno %d", + wr, + bse->elem[elem_idx].size, + bse->elem[elem_idx].data, + err); /** @todo Delete the file? */ return NSERROR_SAVE_FAILED; } - LOG(("Wrote %d bytes from %p", wr, bse->elem[elem_idx].data)); + LOG("Wrote %zd bytes from %p", wr, bse->elem[elem_idx].data); return NSERROR_OK; } @@ -1749,7 +1759,7 @@ store(nsurl *url, /* set the store entry up */ ret = set_store_entry(storestate, url, elem_idx, data, datalen, &bse); if (ret != NSERROR_OK) { - LOG(("store entry setting failed")); + LOG("store entry setting failed"); return ret; } @@ -1772,7 +1782,7 @@ static nserror entry_release_alloc(struct store_entry_element *elem) if ((elem->flags & ENTRY_ELEM_FLAG_HEAP) != 0) { elem->ref--; if (elem->ref == 0) { - LOG(("freeing %p", elem->data)); + LOG("freeing %p", elem->data); free(elem->data); elem->flags &= ~ENTRY_ELEM_FLAG_HEAP; } @@ -1804,7 +1814,7 @@ static nserror store_read_block(struct store_state *state, state->blocks[elem_idx][bf].fd = store_open(state, bf, elem_idx + ENTRY_ELEM_COUNT, O_CREAT | O_RDWR); if (state->blocks[elem_idx][bf].fd == -1) { - LOG(("Open failed errno %d", errno)); + LOG("Open failed errno %d", errno); return NSERROR_SAVE_FAILED; } @@ -1819,15 +1829,21 @@ static nserror store_read_block(struct store_state *state, bse->elem[elem_idx].size, offst); if (rd != (ssize_t)bse->elem[elem_idx].size) { - LOG(("Failed reading %d of %d bytes into %p from 0x%x block %d errno %d", - rd, bse->elem[elem_idx].size, bse->elem[elem_idx].data, - offst, bse->elem[elem_idx].block, errno)); + LOG("Failed reading %zd of %d bytes into %p from 0x%jx block %d errno %d", + rd, + bse->elem[elem_idx].size, + bse->elem[elem_idx].data, + (uintmax_t)offst, + bse->elem[elem_idx].block, + errno); return NSERROR_SAVE_FAILED; } - LOG(("Read %d bytes into %p from 0x%x block %d", - rd, bse->elem[elem_idx].data, - offst, bse->elem[elem_idx].block)); + LOG("Read %zd bytes into %p from 0x%jx block %d", + rd, + bse->elem[elem_idx].data, + (uintmax_t)offst, + bse->elem[elem_idx].block); return NSERROR_OK; } @@ -1852,7 +1868,7 @@ static nserror store_read_file(struct store_state *state, /* separate file in backing store */ fd = store_open(storestate, bse->ident, elem_idx, O_RDONLY); if (fd < 0) { - LOG(("Open failed %d errno %d", fd, errno)); + LOG("Open failed %d errno %d", fd, errno); /** @todo should this invalidate the entry? */ return NSERROR_NOT_FOUND; } @@ -1862,7 +1878,7 @@ static nserror store_read_file(struct store_state *state, bse->elem[elem_idx].data + tot, bse->elem[elem_idx].size - tot); if (rd <= 0) { - LOG(("read error returned %d errno %d", rd, errno)); + LOG("read error returned %zd errno %d", rd, errno); ret = NSERROR_NOT_FOUND; break; } @@ -1871,7 +1887,7 @@ static nserror store_read_file(struct store_state *state, close(fd); - LOG(("Read %d bytes into %p", tot, bse->elem[elem_idx].data)); + LOG("Read %zd bytes into %p", tot, bse->elem[elem_idx].data); return ret; } @@ -1904,13 +1920,13 @@ fetch(nsurl *url, /* fetch store entry */ ret = get_store_entry(storestate, url, &bse); if (ret != NSERROR_OK) { - LOG(("entry not found")); + LOG("entry not found"); storestate->miss_count++; return ret; } storestate->hit_count++; - LOG(("retriving cache data for url:%s", nsurl_access(url))); + LOG("retriving cache data for url:%s", nsurl_access(url)); /* calculate the entry element index */ if ((bsflags & BACKING_STORE_META) != 0) { @@ -1925,17 +1941,16 @@ fetch(nsurl *url, /* use the existing allocation and bump the ref count. */ elem->ref++; - LOG(("Using existing entry (%p) allocation %p refs:%d", - bse, elem->data, elem->ref)); + LOG("Using existing entry (%p) allocation %p refs:%d", bse, elem->data, elem->ref); } else { /* allocate from the heap */ elem->data = malloc(elem->size); if (elem->data == NULL) { - LOG(("Failed to create new heap allocation")); + LOG("Failed to create new heap allocation"); return NSERROR_NOMEM; } - LOG(("Created new heap allocation %p", elem->data)); + LOG("Created new heap allocation %p", elem->data); /* mark the entry as having a valid heap allocation */ elem->flags |= ENTRY_ELEM_FLAG_HEAP; @@ -1984,7 +1999,7 @@ static nserror release(nsurl *url, enum backing_store_flags bsflags) ret = get_store_entry(storestate, url, &bse); if (ret != NSERROR_OK) { - LOG(("entry not found")); + LOG("entry not found"); return ret; } |