diff --git a/lib/bdev/ocf/vbdev_ocf.c b/lib/bdev/ocf/vbdev_ocf.c index 86c71081cd..64edc14801 100644 --- a/lib/bdev/ocf/vbdev_ocf.c +++ b/lib/bdev/ocf/vbdev_ocf.c @@ -306,8 +306,40 @@ wait_for_requests(struct vbdev_ocf *vbdev) vbdev_ocf_mngt_poll(vbdev, wait_for_requests_poll); } +static void +flush_vbdev_cmpl(ocf_cache_t cache, void *priv, int error) +{ + struct vbdev_ocf *vbdev = priv; + + ocf_mngt_cache_unlock(cache); + vbdev_ocf_mngt_continue(vbdev, error); +} + +static void +flush_vbdev_poll(struct vbdev_ocf *vbdev) +{ + if (!ocf_cache_is_running(vbdev->ocf_cache)) { + vbdev_ocf_mngt_continue(vbdev, -EINVAL); + return; + } + + if (ocf_mngt_cache_trylock(vbdev->ocf_cache)) { + return; + } + + vbdev_ocf_mngt_poll(vbdev, NULL); + ocf_mngt_cache_flush(vbdev->ocf_cache, false, flush_vbdev_cmpl, vbdev); +} + +static void +flush_vbdev(struct vbdev_ocf *vbdev) +{ + vbdev_ocf_mngt_poll(vbdev, flush_vbdev_poll); +} + /* Procedures called during unregister */ vbdev_ocf_mngt_fn unregister_path[] = { + flush_vbdev, wait_for_requests, stop_vbdev, detach_cache,