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 <maciej.szwed@intel.com> Change-Id: I962db95eaba34c7c18e639076ad86696e8209196 Reviewed-on: https://review.gerrithub.io/383264 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
70e25b39ac
commit
87a0945c50
@ -82,6 +82,7 @@ _spdk_lvol_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lvol->ref_count++;
|
||||||
lvol->blob = blob;
|
lvol->blob = blob;
|
||||||
end:
|
end:
|
||||||
req->cb_fn(req->cb_arg, lvol, lvolerrno);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lvol->ref_count > 0) {
|
||||||
|
lvol->ref_count++;
|
||||||
|
cb_fn(cb_arg, lvol, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
req = calloc(1, sizeof(*req));
|
req = calloc(1, sizeof(*req));
|
||||||
if (req == NULL) {
|
if (req == NULL) {
|
||||||
SPDK_ERRLOG("Cannot alloc memory for request structure\n");
|
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;
|
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));
|
req = calloc(1, sizeof(*req));
|
||||||
if (!req) {
|
if (!req) {
|
||||||
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user