ftl: separate code to start a transaction

tags/0.1.0
S.J.R. van Schaik 7 years ago
parent 65d269e2d4
commit bea048006a
  1. 57
      source/ftl/ftl.c

@ -44,40 +44,51 @@ size_t ftl_read(struct ftl_map *map, void *data, size_t len, uint32_t va)
len);
}
static int ftl_seek(struct ftl_map *map, uint32_t va)
static int ftl_start_transaction(struct ftl_map *map, uint32_t va)
{
size_t len;
uint32_t page;
int ret;
uint32_t offset, page, dst, src;
if (va >= ftl_get_capacity(map))
if ((map->outstanding.flags & FTL_PRESENT) && map->outstanding.va == va)
return 0;
if (ftl_sync(map) < 0)
return -1;
offset = va & ((1 << map->log2_page_size) - 1);
va >>= map->log2_page_size;
if ((ret = trace_path(map, NULL, &page, va)) < 0 && ret != -ERR_NOT_FOUND)
return -1;
if (prepare_head(map) < 0)
return -1;
map->outstanding.flags |= FTL_PRESENT;
map->outstanding.va = va;
map->outstanding.page = page;
if (ret == -ERR_NOT_FOUND) {
map->outstanding.flags |= FTL_NO_MAPPING;
++map->nused_pages;
}
if (!(map->outstanding.flags & FTL_PRESENT) || map->outstanding.va != va) {
if (ftl_sync(map) < 0)
return -1;
map->offset = 0;
if ((ret = trace_path(map, NULL, &page, va)) < 0 &&
ret != -ERR_NOT_FOUND)
return -1;
return 0;
}
if (prepare_head(map) < 0)
return -1;
static int ftl_seek(struct ftl_map *map, uint32_t va)
{
size_t len;
uint32_t offset, dst, src;
int ret;
map->outstanding.flags |= FTL_PRESENT;
map->outstanding.va = va;
map->outstanding.page = page;
if (va >= ftl_get_capacity(map))
return -1;
if (ret == -ERR_NOT_FOUND) {
map->outstanding.flags |= FTL_NO_MAPPING;
++map->nused_pages;
}
offset = va & ((1 << map->log2_page_size) - 1);
va >>= map->log2_page_size;
map->offset = 0;
}
if (ftl_start_transaction(map, va) < 0)
return -1;
if (offset < map->offset)
return -1;

Loading…
Cancel
Save