lib/bdev/ocf: increase capabilites of vbdev_ocf_mngt_stop function

In current code there is no possibility to clean up vbdev in case
of error during management path. This patch introduces new version of
vbdev_ocf_mngt_stop function, now developer can pass handle to
path with rollback functions and therefore clean up not full initialised
vbdev instance. Changes in this path also allows to pass status explicitly
to vbdev_ocf_mngt_stop function.

Signed-off-by: Marcin Dziegielewski <marcin.dziegielewski@intel.com>
Change-Id: Ie9684981e48d24b3e55e4b1ab828dc8c01baa838
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468471
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
Marcin Dziegielewski 2019-09-16 16:47:27 +02:00 committed by Jim Harris
parent 20894340f2
commit 790669cc46
3 changed files with 29 additions and 12 deletions

View File

@ -129,8 +129,19 @@ vbdev_ocf_mngt_poll(struct vbdev_ocf *vbdev, vbdev_ocf_mngt_fn fn)
}
void
vbdev_ocf_mngt_stop(struct vbdev_ocf *vbdev)
vbdev_ocf_mngt_stop(struct vbdev_ocf *vbdev, vbdev_ocf_mngt_fn *rollback_path, int status)
{
if (status) {
vbdev->mngt_ctx.status = status;
}
if (vbdev->mngt_ctx.status && rollback_path) {
vbdev->mngt_ctx.poller_fn = NULL;
vbdev->mngt_ctx.current_step = rollback_path;
(*vbdev->mngt_ctx.current_step)(vbdev);
return;
}
spdk_poller_unregister(&vbdev->mngt_ctx.poller);
if (vbdev->mngt_ctx.cb) {
@ -158,5 +169,11 @@ vbdev_ocf_mngt_continue(struct vbdev_ocf *vbdev, int status)
return;
}
vbdev_ocf_mngt_stop(vbdev);
vbdev_ocf_mngt_stop(vbdev, NULL, 0);
}
int
vbdev_ocf_mngt_get_status(struct vbdev_ocf *vbdev)
{
return vbdev->mngt_ctx.status;
}

View File

@ -57,7 +57,11 @@ void vbdev_ocf_mngt_poll(struct vbdev_ocf *vbdev, vbdev_ocf_mngt_fn fn);
* If next function is NULL, finish management operation and invoke callback */
void vbdev_ocf_mngt_continue(struct vbdev_ocf *vbdev, int status);
/* Stop the execution and invoke callback with last status returned */
void vbdev_ocf_mngt_stop(struct vbdev_ocf *vbdev);
/* Stop the execution, if status is non zero set it,
* if rollback function is not null invoke rollback
* else invoke callback with last status returned */
void vbdev_ocf_mngt_stop(struct vbdev_ocf *vbdev, vbdev_ocf_mngt_fn *rollback_path, int status);
/* Get status */
int vbdev_ocf_mngt_get_status(struct vbdev_ocf *vbdev);
#endif

View File

@ -986,8 +986,7 @@ start_cache(struct vbdev_ocf *vbdev)
int rc;
if (vbdev->ocf_cache) {
vbdev->mngt_ctx.status = -EALREADY;
vbdev_ocf_mngt_stop(vbdev);
vbdev_ocf_mngt_stop(vbdev, NULL, -EALREADY);
return;
}
@ -1005,8 +1004,7 @@ start_cache(struct vbdev_ocf *vbdev)
vbdev->cache_ctx = calloc(1, sizeof(struct vbdev_ocf_cache_ctx));
if (vbdev->cache_ctx == NULL) {
vbdev->mngt_ctx.status = -ENOMEM;
vbdev_ocf_mngt_stop(vbdev);
vbdev_ocf_mngt_stop(vbdev, NULL, -ENOMEM);
return;
}
@ -1016,8 +1014,7 @@ start_cache(struct vbdev_ocf *vbdev)
rc = ocf_mngt_cache_start(vbdev_ocf_ctx, &vbdev->ocf_cache, &vbdev->cfg.cache);
if (rc) {
vbdev_ocf_cache_ctx_put(vbdev->cache_ctx);
vbdev->mngt_ctx.status = rc;
vbdev_ocf_mngt_stop(vbdev);
vbdev_ocf_mngt_stop(vbdev, NULL, rc);
return;
}
@ -1028,8 +1025,7 @@ start_cache(struct vbdev_ocf *vbdev)
if (rc) {
SPDK_ERRLOG("Unable to create mngt_queue: %d\n", rc);
vbdev_ocf_cache_ctx_put(vbdev->cache_ctx);
vbdev->mngt_ctx.status = rc;
vbdev_ocf_mngt_stop(vbdev);
vbdev_ocf_mngt_stop(vbdev, NULL, rc);
return;
}