Commit 2b768821 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

blob: spdk_bs_destroy now only zeroes the super block



The function just needs to zero out metadata so that the
blobstore is effectively destroyed. If the user wants
to unmap the rest of the disk after the blobstore is
destroyed, they are free to do so. On future initializations
of blobstores the code will do the unmapping, so performance
is not impacted.

While here, implement the zeroing using the new
write_zeroes functionality instead of allocating a buffer
full of zeroes.

Change-Id: I7f18be0fd5e13a48b171ab3f4d5f5e12876023bc
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/390307


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent 7331affe
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -167,14 +167,12 @@ void spdk_bs_load(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts,
void spdk_bs_init(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts,
		  spdk_bs_op_with_handle_complete cb_fn, void *cb_arg);

/* Destroy a blob store by unmapping super block and destroying in-memory structures.
 * If unmap_device is set to true, entire device will be unmapped. Otherwise only
 * super block will be unmapped.
/* Destroy a blob store by zeroing the metadata and freeing in-memory structures.
 */
void spdk_bs_destroy(struct spdk_blob_store *bs, bool unmap_device, spdk_bs_op_complete cb_fn,
void spdk_bs_destroy(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn,
		     void *cb_arg);

/* Flush all volatile data to disk and destroy in-memory structures. */
/* Flush all volatile data to disk and free in-memory structures. */
void spdk_bs_unload(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn, void *cb_arg);

/* Set the given blob as the super blob. This will be retrievable immediately after an
+1 −2
Original line number Diff line number Diff line
@@ -127,12 +127,11 @@ int spdk_lvs_unload(struct spdk_lvol_store *lvol_store,
 * All lvols have to be closed beforehand, when doing destroy.
 *
 * \param lvol_store Handle to lvolstore
 * \param umap_device When set to true, unmaps whole lvolstore, otherwise writes zeros in first block
 * \param cb_fn Completion callback
 * \param cb_arg Completion callback custom arguments
 * \return error
 */
int spdk_lvs_destroy(struct spdk_lvol_store *lvol_store, bool unmap_device,
int spdk_lvs_destroy(struct spdk_lvol_store *lvol_store,
		     spdk_lvs_op_complete cb_fn, void *cb_arg);

/**
+0 −1
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ struct spdk_lvs_destroy_req {
	spdk_lvs_op_complete    cb_fn;
	void                    *cb_arg;
	struct spdk_lvol_store	*lvs;
	bool			unmap_device;
};

struct spdk_lvol_with_handle_req {
+1 −1
Original line number Diff line number Diff line
@@ -238,7 +238,7 @@ _vbdev_lvs_remove(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void

	if (all_lvols_closed == true) {
		if (destroy) {
			spdk_lvs_destroy(lvs, false, _vbdev_lvs_remove_cb, lvs_bdev);
			spdk_lvs_destroy(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
		} else {
			spdk_lvs_unload(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
		}
+6 −18
Original line number Diff line number Diff line
@@ -2335,12 +2335,11 @@ _spdk_bs_destroy_trim_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
	spdk_bs_sequence_finish(seq, bserrno);

	_spdk_bs_free(bs);
	spdk_dma_free(ctx->super);
	free(ctx);
}

void
spdk_bs_destroy(struct spdk_blob_store *bs, bool unmap_device, spdk_bs_op_complete cb_fn,
spdk_bs_destroy(struct spdk_blob_store *bs, spdk_bs_op_complete cb_fn,
		void *cb_arg)
{
	struct spdk_bs_cpl	cpl;
@@ -2365,31 +2364,20 @@ spdk_bs_destroy(struct spdk_blob_store *bs, bool unmap_device, spdk_bs_op_comple
		return;
	}

	ctx->super = spdk_dma_zmalloc(sizeof(*ctx->super), 0x1000, NULL);
	if (!ctx->super) {
		free(ctx);
		cb_fn(cb_arg, -ENOMEM);
		return;
	}

	ctx->bs = bs;

	seq = spdk_bs_sequence_start(bs->md_target.md_channel, &cpl);
	if (!seq) {
		spdk_dma_free(ctx->super);
		free(ctx);
		cb_fn(cb_arg, -ENOMEM);
		return;
	}

	if (unmap_device) {
		/* TRIM the entire device */
		spdk_bs_sequence_unmap(seq, 0,  bs->dev->blockcnt,  _spdk_bs_destroy_trim_cpl, ctx);
	} else {
	/* Write zeroes to the super block */
		spdk_bs_sequence_write(seq, ctx->super, _spdk_bs_page_to_lba(bs, 0), _spdk_bs_byte_to_lba(bs,
				       sizeof(*ctx->super)), _spdk_bs_destroy_trim_cpl, ctx);
	}
	spdk_bs_sequence_write_zeroes(seq,
				      _spdk_bs_page_to_lba(bs, 0),
				      _spdk_bs_byte_to_lba(bs, sizeof(struct spdk_bs_super_block)),
				      _spdk_bs_destroy_trim_cpl, ctx);
}

/* END spdk_bs_destroy */
Loading