Commit 4f6096fa authored by Jim Harris's avatar Jim Harris
Browse files

blob: add _spdk_blob_verify_md_op



These are common functions that can be called from
any function that reads or modifies a blob's metadata to
perform necessary asserts.

This will also fix several places where blob metadata
functions were asserting the calling thread context,
but not the current state of the blob.

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: I9e16c082a27c439311f8ff214335adadfa715497

Reviewed-on: https://review.gerrithub.io/401053


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarMaciej Szwed <maciej.szwed@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 7d4705a2
Loading
Loading
Loading
Loading
+20 −22
Original line number Diff line number Diff line
@@ -59,6 +59,14 @@ static int _spdk_blob_get_xattr_value(struct spdk_blob *blob, const char *name,
				      const void **value, size_t *value_len, bool internal);
static int _spdk_blob_remove_xattr(struct spdk_blob *blob, const char *name, bool internal);

static void
_spdk_blob_verify_md_op(struct spdk_blob *blob)
{
	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);
	assert(blob->state != SPDK_BLOB_STATE_LOADING);
}

static inline size_t
divide_round_up(size_t num, size_t divisor)
{
@@ -83,7 +91,7 @@ _spdk_blob_insert_cluster(struct spdk_blob *blob, uint32_t cluster_num, uint64_t
{
	uint64_t *cluster_lba = &blob->active.clusters[cluster_num];

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

	if (*cluster_lba != 0) {
		return -EEXIST;
@@ -3215,6 +3223,7 @@ _spdk_blob_set_xattrs(struct spdk_blob *blob, const struct spdk_blob_xattr_opts
static void
_spdk_blob_set_thin_provision(struct spdk_blob *blob)
{
	_spdk_blob_verify_md_op(blob);
	blob->invalid_flags |= SPDK_BLOB_THIN_PROV;
	blob->state = SPDK_BLOB_STATE_DIRTY;
}
@@ -3300,8 +3309,7 @@ spdk_blob_resize(struct spdk_blob *blob, uint64_t sz)
{
	int			rc;

	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);
	_spdk_blob_verify_md_op(blob);

	SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Resizing blob %lu to %lu clusters\n", blob->id, sz);

@@ -3371,6 +3379,8 @@ _spdk_bs_delete_open_cpl(void *cb_arg, struct spdk_blob *blob, int bserrno)
		return;
	}

	_spdk_blob_verify_md_op(blob);

	if (blob->open_ref > 1) {
		/*
		 * Someone has this blob open (besides this delete context).
@@ -3492,7 +3502,7 @@ void spdk_bs_open_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
/* START spdk_blob_set_read_only */
int spdk_blob_set_read_only(struct spdk_blob *blob)
{
	assert(spdk_get_thread() == blob->bs->md_thread);
	_spdk_blob_verify_md_op(blob);

	blob->data_ro_flags |= SPDK_BLOB_READ_ONLY;

@@ -3538,13 +3548,10 @@ _spdk_blob_sync_md(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *cb
void
spdk_blob_sync_md(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *cb_arg)
{
	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);
	_spdk_blob_verify_md_op(blob);

	SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Syncing blob %lu\n", blob->id);

	assert(blob->state != SPDK_BLOB_STATE_LOADING);

	if (blob->md_ro) {
		assert(blob->state == SPDK_BLOB_STATE_CLEAN);
		cb_fn(cb_arg, 0);
@@ -3657,13 +3664,10 @@ void spdk_blob_close(struct spdk_blob *blob, spdk_blob_op_complete cb_fn, void *
	struct spdk_bs_cpl	cpl;
	spdk_bs_sequence_t	*seq;

	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);
	_spdk_blob_verify_md_op(blob);

	SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Closing blob %lu\n", blob->id);

	assert(blob->state != SPDK_BLOB_STATE_LOADING);

	if (blob->open_ref == 0) {
		cb_fn(cb_arg, -EBADF);
		return;
@@ -3876,10 +3880,7 @@ _spdk_blob_set_xattr(struct spdk_blob *blob, const char *name, const void *value
	struct spdk_xattr_tailq *xattrs;
	struct spdk_xattr 	*xattr;

	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);

	assert(blob->state != SPDK_BLOB_STATE_LOADING);
	_spdk_blob_verify_md_op(blob);

	if (blob->md_ro) {
		return -EPERM;
@@ -3933,10 +3934,7 @@ _spdk_blob_remove_xattr(struct spdk_blob *blob, const char *name, bool internal)
	struct spdk_xattr_tailq *xattrs;
	struct spdk_xattr	*xattr;

	assert(blob != NULL);
	assert(spdk_get_thread() == blob->bs->md_thread);

	assert(blob->state != SPDK_BLOB_STATE_LOADING);
	_spdk_blob_verify_md_op(blob);

	if (blob->md_ro) {
		return -EPERM;
@@ -3975,7 +3973,7 @@ _spdk_blob_get_xattr_value(struct spdk_blob *blob, const char *name,
	struct spdk_xattr	*xattr;
	struct spdk_xattr_tailq *xattrs;

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

	xattrs = internal ? &blob->xattrs_internal : &blob->xattrs;

@@ -4026,7 +4024,7 @@ _spdk_blob_get_xattr_names(struct spdk_xattr_tailq *xattrs, struct spdk_xattr_na
int
spdk_blob_get_xattr_names(struct spdk_blob *blob, struct spdk_xattr_names **names)
{
	assert(spdk_get_thread() == blob->bs->md_thread);
	_spdk_blob_verify_md_op(blob);

	return _spdk_blob_get_xattr_names(&blob->xattrs, names);
}