ftl: separate code to start a transaction

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

@ -44,24 +44,18 @@ size_t ftl_read(struct ftl_map *map, void *data, size_t len, uint32_t va)
len); 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; int ret;
uint32_t offset, page, dst, src;
if (va >= ftl_get_capacity(map))
return -1;
offset = va & ((1 << map->log2_page_size) - 1); if ((map->outstanding.flags & FTL_PRESENT) && map->outstanding.va == va)
va >>= map->log2_page_size; return 0;
if (!(map->outstanding.flags & FTL_PRESENT) || map->outstanding.va != va) {
if (ftl_sync(map) < 0) if (ftl_sync(map) < 0)
return -1; return -1;
if ((ret = trace_path(map, NULL, &page, va)) < 0 && if ((ret = trace_path(map, NULL, &page, va)) < 0 && ret != -ERR_NOT_FOUND)
ret != -ERR_NOT_FOUND)
return -1; return -1;
if (prepare_head(map) < 0) if (prepare_head(map) < 0)
@ -77,8 +71,25 @@ static int ftl_seek(struct ftl_map *map, uint32_t va)
} }
map->offset = 0; map->offset = 0;
return 0;
} }
static int ftl_seek(struct ftl_map *map, uint32_t va)
{
size_t len;
uint32_t offset, dst, src;
int ret;
if (va >= ftl_get_capacity(map))
return -1;
offset = va & ((1 << map->log2_page_size) - 1);
va >>= map->log2_page_size;
if (ftl_start_transaction(map, va) < 0)
return -1;
if (offset < map->offset) if (offset < map->offset)
return -1; return -1;

Loading…
Cancel
Save