Commit 478c2e6f authored by Maciej Szwed's avatar Maciej Szwed Committed by Jim Harris
Browse files

blobstore: Move snapshot check on deletion after blob is opened



Currently someone can create clone while blob is being
opened for deletion. This patch moves check for blob if
it is a snpashot after the blob is opened.

Signed-off-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Change-Id: Ia4b8b7cb956522a29784aa349d677eb87886e4db

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/451682


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 7250ec64
Loading
Loading
Loading
Loading
+23 −16
Original line number Diff line number Diff line
@@ -4972,6 +4972,14 @@ spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_f

/* START spdk_bs_delete_blob */

static void
_spdk_bs_delete_ebusy_close_cpl(void *cb_arg, int bserrno)
{
	spdk_bs_sequence_t *seq = cb_arg;

	spdk_bs_sequence_finish(seq, -EBUSY);
}

static void
_spdk_bs_delete_close_cpl(void *cb_arg, int bserrno)
{
@@ -5030,6 +5038,21 @@ _spdk_bs_delete_open_cpl(void *cb_arg, struct spdk_blob *blob, int bserrno)
		return;
	}

	/* Check if this is a snapshot with clones */
	TAILQ_FOREACH(snapshot, &blob->bs->snapshots, link) {
		if (snapshot->id == blob->id) {
			break;
		}
	}
	if (snapshot != NULL) {
		/* If snapshot have clones, we cannot remove it */
		if (!TAILQ_EMPTY(&snapshot->clones)) {
			SPDK_ERRLOG("Cannot remove snapshot with clones\n");
			spdk_blob_close(blob, _spdk_bs_delete_ebusy_close_cpl, seq);
			return;
		}
	}

	bserrno = _spdk_bs_blob_list_remove(blob);
	if (bserrno != 0) {
		SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Remove blob #%" PRIu64 " from a list\n", blob->id);
@@ -5067,27 +5090,11 @@ spdk_bs_delete_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
{
	struct spdk_bs_cpl	cpl;
	spdk_bs_sequence_t	*seq;
	struct spdk_blob_list	*snapshot_entry = NULL;

	SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Deleting blob %lu\n", blobid);

	assert(spdk_get_thread() == bs->md_thread);

	/* Check if this is a snapshot with clones */
	TAILQ_FOREACH(snapshot_entry, &bs->snapshots, link) {
		if (snapshot_entry->id == blobid) {
			break;
		}
	}
	if (snapshot_entry != NULL) {
		/* If snapshot have clones, we cannot remove it */
		if (!TAILQ_EMPTY(&snapshot_entry->clones)) {
			SPDK_ERRLOG("Cannot remove snapshot with clones\n");
			cb_fn(cb_arg, -EBUSY);
			return;
		}
	}

	cpl.type = SPDK_BS_CPL_TYPE_BLOB_BASIC;
	cpl.u.blob_basic.cb_fn = cb_fn;
	cpl.u.blob_basic.cb_arg = cb_arg;