From dfb102b79a6e593c5cdc4723e497305406a15fe3 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 26 Jan 2018 13:44:36 -0700 Subject: [PATCH] blob: add md_thread to struct spdk_blob_store For now, use this to add some assert() calls to ensure per-blob metadata operations are only called from the thread that initialized/loaded the blobstore. Upcoming patches will utilize this for metadata updates required due to cluster allocations on thin provisioned blobs. In that case, the cluster allocations may not always be done on the metadata thread - but we want the metadata thread to actually do the metadata sync operation to guard against races from allocations on multiple threads in parallel. Signed-off-by: Jim Harris Change-Id: Ifa0adfe8b7e61ba770449d1e076126ecb9d7a556 Reviewed-on: https://review.gerrithub.io/396712 Reviewed-by: Ben Walker Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- lib/blob/blobstore.c | 7 +++++++ lib/blob/blobstore.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 83687a0c8..38a2685a3 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -1638,6 +1638,8 @@ _spdk_bs_alloc(struct spdk_bs_dev *dev, struct spdk_bs_opts *opts) TAILQ_INIT(&bs->blobs); bs->dev = dev; + bs->md_thread = spdk_get_thread(); + assert(bs->md_thread != NULL); /* * Do not use _spdk_bs_lba_to_cluster() here since blockcnt may not be an @@ -2934,6 +2936,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_DEBUGLOG(SPDK_LOG_BLOB, "Resizing blob %lu to %lu clusters\n", blob->id, sz); @@ -3125,6 +3128,8 @@ void spdk_blob_set_read_only(struct spdk_blob *b) { struct spdk_blob_data *blob = __blob_to_data(b); + assert(spdk_get_thread() == blob->bs->md_thread); + blob->data_ro_flags |= SPDK_BLOB_READ_ONLY; blob->state = SPDK_BLOB_STATE_DIRTY; @@ -3154,6 +3159,7 @@ spdk_blob_sync_md(struct spdk_blob *_blob, spdk_blob_op_complete cb_fn, void *cb spdk_bs_sequence_t *seq; assert(blob != NULL); + assert(spdk_get_thread() == blob->bs->md_thread); SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Syncing blob %lu\n", blob->id); @@ -3221,6 +3227,7 @@ void spdk_blob_close(struct spdk_blob *b, spdk_blob_op_complete cb_fn, void *cb_ assert(b != NULL); blob = __blob_to_data(b); assert(blob != NULL); + assert(spdk_get_thread() == blob->bs->md_thread); SPDK_DEBUGLOG(SPDK_LOG_BLOB, "Closing blob %lu\n", blob->id); diff --git a/lib/blob/blobstore.h b/lib/blob/blobstore.h index 4b11d075b..2869a747d 100644 --- a/lib/blob/blobstore.h +++ b/lib/blob/blobstore.h @@ -151,6 +151,8 @@ struct spdk_blob_store { struct spdk_io_channel *md_channel; uint32_t max_channel_ops; + struct spdk_thread *md_thread; + struct spdk_bs_dev *dev; struct spdk_bit_array *used_md_pages;