From 87a0945c50d8e4b5e5c696742f290d024308d4c6 Mon Sep 17 00:00:00 2001 From: Maciej Szwed Date: Fri, 20 Oct 2017 16:07:10 +0200 Subject: [PATCH] lvol: add lvol reference counter to spdk_lvol_open() This patch is a continuation of patch https://review.gerrithub.io/#/c/383252/ on which this series should be rebased. This series introduces spdk_lvol_open function where reference counter should be also used. Signed-off-by: Maciej Szwed Change-Id: I962db95eaba34c7c18e639076ad86696e8209196 Reviewed-on: https://review.gerrithub.io/383264 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- lib/lvol/lvol.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/lvol/lvol.c b/lib/lvol/lvol.c index 64c306772d..669ba5cf4d 100644 --- a/lib/lvol/lvol.c +++ b/lib/lvol/lvol.c @@ -82,6 +82,7 @@ _spdk_lvol_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno) goto end; } + lvol->ref_count++; lvol->blob = blob; end: req->cb_fn(req->cb_arg, lvol, lvolerrno); @@ -101,6 +102,12 @@ spdk_lvol_open(struct spdk_lvol *lvol, spdk_lvol_op_with_handle_complete cb_fn, return; } + if (lvol->ref_count > 0) { + lvol->ref_count++; + cb_fn(cb_arg, lvol, 0); + return; + } + req = calloc(1, sizeof(*req)); if (req == NULL) { SPDK_ERRLOG("Cannot alloc memory for request structure\n"); @@ -988,6 +995,15 @@ spdk_lvol_close(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_ar return; } + if (lvol->ref_count > 1) { + lvol->ref_count--; + cb_fn(cb_arg, 0); + return; + } else if (lvol->ref_count == 0) { + cb_fn(cb_arg, -EINVAL); + return; + } + req = calloc(1, sizeof(*req)); if (!req) { SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");