*items = item_group;
}
+int zero_copy_read_buffer(int fd, struct zlog_entry_list **items, char *bitmap, uint16_t *last_offsets)
+{
+ assert(fd >= 0);
+ assert(items);
+ assert(bitmap);
+ assert(last_offsets);
+
+ if (*items)
+ return -EAGAIN;
+
+ for (size_t i = 0; i < ZLOGGER_DEVICE_COUNT; ++i) {
+ volatile void *const addr = mmap(NULL, ZLOGGER_MAP_SIZE, PROT_READ, MAP_SHARED, fd, ZLOGGER_MAP_SIZE * i);
+ if (addr == MAP_FAILED) {
+ sort_items_list(items); // maybe worth salvaging
+ return -EIO;
+ }
+ load_single_device(addr, items
+ , bitmap + (ZLOGGER_BLOCK_MAP_COUNT / CHAR_BIT) * i
+ , last_offsets + ZLOGGER_BLOCK_MAP_COUNT * i
+ );
+ munmap((void *) addr, ZLOGGER_MAP_SIZE);
+ }
+
+ sort_items_list(items);
+ return 0;
+}
+
static int zero_copy_read(struct fd_info *fdi)
{
struct zero_copy_priv_data *const zpd = (struct zero_copy_priv_data *)fdi->priv_data;
zpd->read_everything = false;
}
- for (size_t i = 0; i < ZLOGGER_DEVICE_COUNT; ++i) {
- volatile void *const addr = mmap(NULL, ZLOGGER_MAP_SIZE, PROT_READ, MAP_SHARED, fdi->fd, ZLOGGER_MAP_SIZE * i);
- if (addr == MAP_FAILED)
- break;
- load_single_device(addr, &zpd->items
- , bitmap + (ZLOGGER_BLOCK_MAP_COUNT / CHAR_BIT) * i
- , zpd->last_block_offsets + ZLOGGER_BLOCK_MAP_COUNT * i
- );
- munmap((void *) addr, ZLOGGER_MAP_SIZE);
- }
-
- sort_items_list(&zpd->items);
+ (void) zero_copy_read_buffer(fdi->fd, &zpd->items, bitmap, zpd->last_block_offsets);
if (zpd->dump)
zpd->eof = true;