blobstore: freeze I/O during resize

Signed-off-by: Piotr Pelplinski <piotr.pelplinski@intel.com>
Change-Id: I23c34d4dcb542aa9ab3fa8cb734cf9cc0e0fc5da

Reviewed-on: https://review.gerrithub.io/409144
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Piotr Pelplinski 2018-04-26 14:21:35 +02:00 committed by Jim Harris
parent 0af5182e19
commit 69fa57cdf0
3 changed files with 65 additions and 3 deletions

View File

@ -534,6 +534,7 @@ void spdk_bs_open_blob(struct spdk_blob_store *bs, spdk_blob_id blobid,
/** /**
* Resize a blob to 'sz' clusters. These changes are not persisted to disk until * Resize a blob to 'sz' clusters. These changes are not persisted to disk until
* spdk_bs_md_sync_blob() is called. * spdk_bs_md_sync_blob() is called.
* If called before previous resize finish, it will fail with errno -EBUSY
* *
* \param blob Blob to resize. * \param blob Blob to resize.
* \param sz The new number of clusters. * \param sz The new number of clusters.

View File

@ -4441,10 +4441,55 @@ void spdk_bs_inflate_blob(struct spdk_blob_store *bs, struct spdk_io_channel *ch
/* END spdk_bs_inflate_blob */ /* END spdk_bs_inflate_blob */
/* START spdk_blob_resize */ /* START spdk_blob_resize */
struct spdk_bs_resize_ctx {
spdk_blob_op_complete cb_fn;
void *cb_arg;
struct spdk_blob *blob;
uint64_t sz;
int rc;
};
static void
_spdk_bs_resize_unfreeze_cpl(void *cb_arg, int rc)
{
struct spdk_bs_resize_ctx *ctx = (struct spdk_bs_resize_ctx *)cb_arg;
if (rc != 0) {
SPDK_ERRLOG("Unfreeze failed, rc=%d\n", rc);
}
if (ctx->rc != 0) {
SPDK_ERRLOG("Unfreeze failed, ctx->rc=%d\n", ctx->rc);
rc = ctx->rc;
}
ctx->blob->resize_in_progress = false;
ctx->cb_fn(ctx->cb_arg, rc);
free(ctx);
}
static void
_spdk_bs_resize_freeze_cpl(void *cb_arg, int rc)
{
struct spdk_bs_resize_ctx *ctx = (struct spdk_bs_resize_ctx *)cb_arg;
if (rc != 0) {
ctx->blob->resize_in_progress = false;
ctx->cb_fn(ctx->cb_arg, rc);
free(ctx);
return;
}
ctx->rc = _spdk_blob_resize(ctx->blob, ctx->sz);
_spdk_blob_unfreeze_io(ctx->blob, _spdk_bs_resize_unfreeze_cpl, ctx);
}
void void
spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_fn, void *cb_arg) spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_fn, void *cb_arg)
{ {
int rc; struct spdk_bs_resize_ctx *ctx;
_spdk_blob_verify_md_op(blob); _spdk_blob_verify_md_op(blob);
@ -4460,8 +4505,23 @@ spdk_blob_resize(struct spdk_blob *blob, uint64_t sz, spdk_blob_op_complete cb_f
return; return;
} }
rc = _spdk_blob_resize(blob, sz); if (blob->resize_in_progress) {
cb_fn(cb_arg, rc); cb_fn(cb_arg, -EBUSY);
return;
}
ctx = calloc(1, sizeof(*ctx));
if (!ctx) {
cb_fn(cb_arg, -ENOMEM);
return;
}
blob->resize_in_progress = true;
ctx->cb_fn = cb_fn;
ctx->cb_arg = cb_arg;
ctx->blob = blob;
ctx->sz = sz;
_spdk_blob_freeze_io(blob, _spdk_bs_resize_freeze_cpl, ctx);
} }
/* END spdk_blob_resize */ /* END spdk_blob_resize */

View File

@ -149,6 +149,7 @@ struct spdk_blob {
TAILQ_ENTRY(spdk_blob) link; TAILQ_ENTRY(spdk_blob) link;
uint32_t frozen_refcnt; uint32_t frozen_refcnt;
bool resize_in_progress;
}; };
struct spdk_blob_store { struct spdk_blob_store {