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");