bdev/ocf: simplify check for running cache instance
There are additional conditions which SPDK tracks, that are known before issuing call to OCF. Two main ones are: - if vbdev->ocf_cache was not yet created [start_cache()] - if the cache bdev was opened [attach_base()] Both happen for the first cache bdev once. Then for consecutive vbdev_ocf on same cache bdev, reference will be copied. This call will simplify checking both conditions. Calling into OCF with NULL or stale ocf_cache pointer, rightly so will cause issues with ASAN. Related #1498 Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Change-Id: Ib202c15bda4cbbffa1516c69168e8bfb80370047 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3573 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
e12a4f6ec8
commit
868ba17780
@ -135,6 +135,15 @@ get_other_cache_base(struct vbdev_ocf_base *base)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
is_ocf_cache_running(struct vbdev_ocf *vbdev)
|
||||
{
|
||||
if (vbdev->cache.attached && vbdev->ocf_cache) {
|
||||
return ocf_cache_is_running(vbdev->ocf_cache);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get existing OCF cache instance
|
||||
* that is started by other vbdev */
|
||||
static ocf_cache_t
|
||||
@ -149,7 +158,7 @@ get_other_cache_instance(struct vbdev_ocf *vbdev)
|
||||
if (strcmp(cmp->cache.name, vbdev->cache.name)) {
|
||||
continue;
|
||||
}
|
||||
if (cmp->ocf_cache) {
|
||||
if (is_ocf_cache_running(cmp)) {
|
||||
return cmp->ocf_cache;
|
||||
}
|
||||
}
|
||||
@ -230,7 +239,7 @@ remove_core_cache_lock_cmpl(ocf_cache_t cache, void *priv, int error)
|
||||
static void
|
||||
detach_core(struct vbdev_ocf *vbdev)
|
||||
{
|
||||
if (vbdev->ocf_cache && ocf_cache_is_running(vbdev->ocf_cache)) {
|
||||
if (is_ocf_cache_running(vbdev)) {
|
||||
ocf_mngt_cache_lock(vbdev->ocf_cache, remove_core_cache_lock_cmpl, vbdev);
|
||||
} else {
|
||||
vbdev_ocf_mngt_continue(vbdev, 0);
|
||||
@ -291,7 +300,7 @@ stop_vbdev_cache_lock_cmpl(ocf_cache_t cache, void *priv, int error)
|
||||
static void
|
||||
stop_vbdev(struct vbdev_ocf *vbdev)
|
||||
{
|
||||
if (!ocf_cache_is_running(vbdev->ocf_cache)) {
|
||||
if (!is_ocf_cache_running(vbdev)) {
|
||||
vbdev_ocf_mngt_continue(vbdev, 0);
|
||||
return;
|
||||
}
|
||||
@ -334,7 +343,7 @@ flush_vbdev_cache_lock_cmpl(ocf_cache_t cache, void *priv, int error)
|
||||
static void
|
||||
flush_vbdev(struct vbdev_ocf *vbdev)
|
||||
{
|
||||
if (!ocf_cache_is_running(vbdev->ocf_cache)) {
|
||||
if (!is_ocf_cache_running(vbdev)) {
|
||||
vbdev_ocf_mngt_continue(vbdev, -EINVAL);
|
||||
return;
|
||||
}
|
||||
@ -1040,7 +1049,7 @@ start_cache(struct vbdev_ocf *vbdev)
|
||||
ocf_cache_t existing;
|
||||
int rc;
|
||||
|
||||
if (vbdev->ocf_cache) {
|
||||
if (is_ocf_cache_running(vbdev)) {
|
||||
vbdev_ocf_mngt_stop(vbdev, NULL, -EALREADY);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user