module/raid: add callback for IO resume completion

Function raid_bdev_resume takes as input parameters also a function
pointer and a context to be called at the end of the resume operation.
If no callback should be called, NULL parameters can be passed.

Signed-off-by: Damiano Cipriani <damiano.cipriani@suse.com>
This commit is contained in:
Damiano Cipriani 2023-08-29 16:22:31 +02:00 committed by Damiano Cipriani
parent 4542f9b140
commit 4c06a1e600
2 changed files with 43 additions and 12 deletions

View File

@ -1590,6 +1590,25 @@ raid_bdev_suspend(struct raid_bdev *raid_bdev, raid_bdev_suspended_cb cb, void *
return 0; return 0;
} }
typedef void (*raid_bdev_resumed_cb)(void *cb_ctx, int rc);
struct raid_bdev_resume_ctx {
raid_bdev_resumed_cb resumed_cb;
void *resumed_cb_ctx;
};
static void
raid_bdev_resume_done(struct spdk_io_channel_iter *i, int status)
{
struct raid_bdev_resume_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
if (ctx->resumed_cb) {
ctx->resumed_cb(ctx->resumed_cb_ctx, status);
}
free(ctx);
}
static void static void
raid_bdev_channel_resume(struct spdk_io_channel_iter *i) raid_bdev_channel_resume(struct spdk_io_channel_iter *i)
{ {
@ -1611,7 +1630,7 @@ raid_bdev_channel_resume(struct spdk_io_channel_iter *i)
} }
static void static void
raid_bdev_resume(struct raid_bdev *raid_bdev) raid_bdev_resume(struct raid_bdev *raid_bdev, raid_bdev_resumed_cb cb, void *cb_ctx)
{ {
assert(spdk_get_thread() == spdk_thread_get_app_thread()); assert(spdk_get_thread() == spdk_thread_get_app_thread());
assert(raid_bdev->suspend_cnt > 0); assert(raid_bdev->suspend_cnt > 0);
@ -1621,7 +1640,19 @@ raid_bdev_resume(struct raid_bdev *raid_bdev)
pthread_mutex_unlock(&raid_bdev->mutex); pthread_mutex_unlock(&raid_bdev->mutex);
if (raid_bdev->suspend_cnt == 0) { if (raid_bdev->suspend_cnt == 0) {
spdk_for_each_channel(raid_bdev, raid_bdev_channel_resume, raid_bdev, NULL); struct raid_bdev_resume_ctx *ctx;
ctx = malloc(sizeof(*ctx));
if (ctx == NULL) {
cb(cb_ctx, -ENOMEM);
return;
}
ctx->resumed_cb = cb;
ctx->resumed_cb_ctx = cb_ctx;
spdk_for_each_channel(raid_bdev, raid_bdev_channel_resume, ctx, raid_bdev_resume_done);
} else if (cb) {
cb(cb_ctx, 0);
} }
} }
@ -1650,7 +1681,7 @@ raid_bdev_remove_base_bdev_write_sb_cb(bool success, struct raid_bdev *raid_bdev
SPDK_ERRLOG("Failed to write raid bdev '%s' superblock\n", raid_bdev->bdev.name); SPDK_ERRLOG("Failed to write raid bdev '%s' superblock\n", raid_bdev->bdev.name);
} }
raid_bdev_resume(raid_bdev); raid_bdev_resume(raid_bdev, NULL, NULL);
} }
static void static void
@ -1685,7 +1716,7 @@ raid_bdev_remove_base_bdev_done(struct spdk_io_channel_iter *i, int status)
raid_bdev_remove_base_bdev_write_sb_cb(false, raid_bdev); raid_bdev_remove_base_bdev_write_sb_cb(false, raid_bdev);
} }
} else { } else {
raid_bdev_resume(raid_bdev); raid_bdev_resume(raid_bdev, NULL, NULL);
} }
} }

View File

@ -2098,7 +2098,7 @@ test_raid_suspend_resume(void)
SPDK_CU_ASSERT_FATAL(rc == 0); SPDK_CU_ASSERT_FATAL(rc == 0);
poll_threads(); poll_threads();
CU_ASSERT(suspend_cb_called == true); CU_ASSERT(suspend_cb_called == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
/* suspend/resume with one idle io channel */ /* suspend/resume with one idle io channel */
@ -2112,7 +2112,7 @@ test_raid_suspend_resume(void)
poll_threads(); poll_threads();
CU_ASSERT(suspend_cb_called == true); CU_ASSERT(suspend_cb_called == true);
CU_ASSERT(raid_ch->is_suspended == true); CU_ASSERT(raid_ch->is_suspended == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch->is_suspended == false); CU_ASSERT(raid_ch->is_suspended == false);
@ -2132,13 +2132,13 @@ test_raid_suspend_resume(void)
SPDK_CU_ASSERT_FATAL(rc == 0); SPDK_CU_ASSERT_FATAL(rc == 0);
CU_ASSERT(suspend_cb_called == true); CU_ASSERT(suspend_cb_called == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch->is_suspended == true); CU_ASSERT(raid_ch->is_suspended == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch->is_suspended == true); CU_ASSERT(raid_ch->is_suspended == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch->is_suspended == false); CU_ASSERT(raid_ch->is_suspended == false);
@ -2167,7 +2167,7 @@ test_raid_suspend_resume(void)
CU_ASSERT(raid_ch->num_ios == 0); CU_ASSERT(raid_ch->num_ios == 0);
CU_ASSERT(TAILQ_FIRST(&raid_ch->suspended_ios) == (struct raid_bdev_io *)bdev_io->driver_ctx); CU_ASSERT(TAILQ_FIRST(&raid_ch->suspended_ios) == (struct raid_bdev_io *)bdev_io->driver_ctx);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch->is_suspended == false); CU_ASSERT(raid_ch->is_suspended == false);
verify_io(bdev_io, req.base_bdevs.num_base_bdevs, raid_ch, pbdev, g_child_io_status_flag); verify_io(bdev_io, req.base_bdevs.num_base_bdevs, raid_ch, pbdev, g_child_io_status_flag);
@ -2245,7 +2245,7 @@ test_raid_suspend_resume_create_ch(void)
CU_ASSERT(raid_ch1->is_suspended == true); CU_ASSERT(raid_ch1->is_suspended == true);
CU_ASSERT(raid_ch2->is_suspended == true); CU_ASSERT(raid_ch2->is_suspended == true);
set_thread(0); set_thread(0);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
poll_threads(); poll_threads();
CU_ASSERT(raid_ch1->is_suspended == false); CU_ASSERT(raid_ch1->is_suspended == false);
CU_ASSERT(raid_ch2->is_suspended == false); CU_ASSERT(raid_ch2->is_suspended == false);
@ -2261,7 +2261,7 @@ test_raid_suspend_resume_create_ch(void)
poll_threads(); poll_threads();
CU_ASSERT(suspend_cb_called == true); CU_ASSERT(suspend_cb_called == true);
CU_ASSERT(raid_ch1->is_suspended == true); CU_ASSERT(raid_ch1->is_suspended == true);
raid_bdev_resume(pbdev); raid_bdev_resume(pbdev, NULL, NULL);
set_thread(2); set_thread(2);
ch2 = spdk_get_io_channel(pbdev); ch2 = spdk_get_io_channel(pbdev);