From dda952809b49b85a6ab112b5316b6085c06e076c Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Wed, 5 Oct 2022 09:00:02 -0500 Subject: [PATCH] lvol: avoid premature reference to blob As an lvstore is being loaded, blobs are itereated with spdk_bs_iter_next(), which opens a blob, calls lvol_next_lvol(), then closes the blob. Since the blob struct that is passed to load_next_lvol() is only transiently opened, it should not be stored with the lvol. A short while later, the lvstore opens each lvol by calling spdk_lvol_open() from _vbdev_lvs_examine_cb(). At that time, the lvstore holds the open reference and only then is it safe to keep a reference to the blob. Change-Id: I309227b23b59058a58167a9dac35af5fabc29d98 Signed-off-by: Mike Gerdts Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14965 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- lib/lvol/lvol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/lvol/lvol.c b/lib/lvol/lvol.c index bdb47aaa5..aee5d1211 100644 --- a/lib/lvol/lvol.c +++ b/lib/lvol/lvol.c @@ -178,7 +178,10 @@ load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno) goto invalid; } - lvol->blob = blob; + /* + * Do not store a reference to blob now because spdk_bs_iter_next() will close it. + * Storing blob_id for future lookups is fine. + */ lvol->blob_id = blob_id; lvol->lvol_store = lvs; lvol->thin_provision = spdk_blob_is_thin_provisioned(blob);