reduce: add struct spdk_reduce_vol_request

These structures will be used as contexts for every
I/O request.  Allocate a bunch of these requests
when a volume is initialized or loaded.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ibf4da3081b03dd3950550e4ca1c5a3a50f72fd52

Reviewed-on: https://review.gerrithub.io/433516
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Jim Harris 2018-10-02 05:33:52 -07:00
parent 8489937b2e
commit 202bb34fcc

View File

@ -51,6 +51,8 @@
#define REDUCE_EMPTY_MAP_ENTRY -1ULL
#define REDUCE_NUM_VOL_REQUESTS 256
/* Structure written to offset 0 of both the pm file and the backing device. */
struct spdk_reduce_vol_superblock {
uint8_t signature[8];
@ -72,18 +74,24 @@ struct spdk_reduce_pm_file {
uint64_t size;
};
struct spdk_reduce_vol_request {
TAILQ_ENTRY(spdk_reduce_vol_request) tailq;
};
struct spdk_reduce_vol {
struct spdk_reduce_vol_params params;
struct spdk_reduce_pm_file pm_file;
struct spdk_reduce_backing_dev *backing_dev;
struct spdk_reduce_vol_superblock *backing_super;
struct spdk_reduce_vol_superblock *pm_super;
uint64_t *pm_logical_map;
uint64_t *pm_chunk_maps;
struct spdk_bit_array *allocated_chunk_maps;
struct spdk_bit_array *allocated_backing_io_units;
struct spdk_reduce_vol_request *request_mem;
TAILQ_HEAD(, spdk_reduce_vol_request) requests;
};
/*
@ -219,6 +227,24 @@ struct reduce_init_load_ctx {
void *path;
};
static int
_allocate_vol_requests(struct spdk_reduce_vol *vol)
{
struct spdk_reduce_vol_request *req;
int i;
vol->request_mem = calloc(REDUCE_NUM_VOL_REQUESTS, sizeof(*req));
if (vol->request_mem == NULL) {
return -ENOMEM;
}
for (i = 0; i < REDUCE_NUM_VOL_REQUESTS; i++) {
TAILQ_INSERT_HEAD(&vol->requests, &vol->request_mem[i], tailq);
}
return 0;
}
static void
_init_load_cleanup(struct spdk_reduce_vol *vol, struct reduce_init_load_ctx *ctx)
{
@ -231,6 +257,7 @@ _init_load_cleanup(struct spdk_reduce_vol *vol, struct reduce_init_load_ctx *ctx
spdk_dma_free(vol->backing_super);
spdk_bit_array_free(&vol->allocated_chunk_maps);
spdk_bit_array_free(&vol->allocated_backing_io_units);
free(vol->request_mem);
free(vol);
}
}
@ -239,6 +266,14 @@ static void
_init_write_super_cpl(void *cb_arg, int ziperrno)
{
struct reduce_init_load_ctx *init_ctx = cb_arg;
int rc;
rc = _allocate_vol_requests(init_ctx->vol);
if (rc != 0) {
init_ctx->cb_fn(init_ctx->cb_arg, NULL, rc);
_init_load_cleanup(init_ctx->vol, init_ctx);
return;
}
init_ctx->cb_fn(init_ctx->cb_arg, init_ctx->vol, ziperrno);
/* Only clean up the ctx - the vol has been passed to the application
@ -489,6 +524,11 @@ _load_read_super_and_path_cpl(void *cb_arg, int ziperrno)
goto error;
}
rc = _allocate_vol_requests(vol);
if (rc != 0) {
goto error;
}
_initialize_vol_pm_pointers(vol);
load_ctx->cb_fn(load_ctx->cb_arg, vol, 0);
/* Only clean up the ctx - the vol has been passed to the application