From c69de1bef59ba0d824cd9d5e9da602cb23c29e4b Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 24 Sep 2020 17:26:59 +0200 Subject: block/export: Move refcount from NBDExport to BlockExport Having a refcount makes sense for all types of block exports. It is also a prerequisite for keeping a list of all exports at the BlockExport level. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Message-Id: <20200924152717.287415-14-kwolf@redhat.com> Acked-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/export/export.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'block/export') diff --git a/block/export/export.c b/block/export/export.c index 05bc5e3744..baba4e94ff 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -49,6 +49,20 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) return drv->create(export, errp); } +void blk_exp_ref(BlockExport *exp) +{ + assert(exp->refcount > 0); + exp->refcount++; +} + +void blk_exp_unref(BlockExport *exp) +{ + assert(exp->refcount > 0); + if (--exp->refcount == 0) { + exp->drv->delete(exp); + } +} + void qmp_block_export_add(BlockExportOptions *export, Error **errp) { blk_exp_add(export, errp); -- cgit v1.2.3-55-g7522