From: Kevin Wolf <kwolf@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-block@nongnu.org, pkrempa@redhat.com, jtc@redhat.com,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC v3 03/14] blockjobs: add state transition table
Date: Mon, 29 Jan 2018 18:17:55 +0100 [thread overview]
Message-ID: <20180129171755.GM6141@localhost.localdomain> (raw)
In-Reply-To: <20180127020515.27137-4-jsnow@redhat.com>
Am 27.01.2018 um 03:05 hat John Snow geschrieben:
> The state transition table has mostly been implied. We're about to make
> it a bit more complex, so let's make the STM explicit instead.
>
> Perform state transitions with a function that for now just asserts the
> transition is appropriate.
>
> undefined: May only transition to 'created'.
> created: May only transition to 'running'.
> It cannot transition to pause directly, but if a created job
> is requested to pause prior to starting, it will transition
> synchronously to 'running' and then to 'paused'.
> running: May transition either to 'paused' or 'ready'.
> paused: May transition to either 'running' or 'ready', but only in
> terms of returning to that prior state.
> p->r->y is not possible, but this is not encapsulated by the
> STM table.
Do you mean y->p->r->y here? If not, I don't understand.
> ready: May transition to paused.
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> blockjob.c | 39 ++++++++++++++++++++++++++++++++++-----
> 1 file changed, 34 insertions(+), 5 deletions(-)
>
> diff --git a/blockjob.c b/blockjob.c
> index 6eb783a354..d084a1e318 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -42,6 +42,35 @@
> * block_job_enter. */
> static QemuMutex block_job_mutex;
>
> +/* BlockJob State Transition Table */
> +bool BlockJobSTT[BLOCK_JOB_STATUS__MAX][BLOCK_JOB_STATUS__MAX] = {
> + /* U, C, R, P, Y */
> + /* U: */ [BLOCK_JOB_STATUS_UNDEFINED] = {0, 1, 0, 0, 0},
> + /* C: */ [BLOCK_JOB_STATUS_CREATED] = {0, 0, 1, 0, 0},
> + /* R: */ [BLOCK_JOB_STATUS_RUNNING] = {0, 0, 0, 1, 1},
> + /* P: */ [BLOCK_JOB_STATUS_PAUSED] = {0, 0, 1, 0, 1},
> + /* Y: */ [BLOCK_JOB_STATUS_READY] = {0, 0, 0, 1, 0},
> +};
> +
> +static void block_job_state_transition(BlockJob *job, BlockJobStatus s1)
> +{
> + BlockJobStatus s0 = job->status;
> + if (s0 == s1) {
> + return;
> + }
> + assert(s1 >= 0 && s1 <= BLOCK_JOB_STATUS__MAX);
> + assert(BlockJobSTT[s0][s1]);
> + switch (s1) {
> + case BLOCK_JOB_STATUS_WAITING:
> + case BLOCK_JOB_STATUS_PENDING:
> + case BLOCK_JOB_STATUS_CONCLUDED:
> + assert(job->manual);
> + default:
> + break;
> + }
This doesn't compile because the constants don't exist yet.
Apart from that, I think the assertion is misguided, too. Which states a
job goes through shouldn't depend on whether the client wants to
complete the job manually or have it completed automatically. The
difference should only be which state transitions are automatic.
In other words, WAITING/PENDING/CONCLUDED may never be visible in
query-block-job for automatically completed jobs, but the jobs should
still (synchronously) go through all of these states.
> + job->status = s1;
> +}
> +
Kevin
next prev parent reply other threads:[~2018-01-29 17:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-27 2:05 [Qemu-devel] [RFC v3 00/14] blockjobs: add explicit job management John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 01/14] blockjobs: add manual property John Snow
2018-01-29 16:59 ` Kevin Wolf
2018-01-29 17:34 ` John Snow
2018-01-29 17:46 ` Kevin Wolf
2018-01-29 17:52 ` John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 02/14] blockjobs: Add status enum John Snow
2018-01-29 17:04 ` Kevin Wolf
2018-01-29 17:38 ` John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 03/14] blockjobs: add state transition table John Snow
2018-01-29 17:17 ` Kevin Wolf [this message]
2018-01-29 19:07 ` John Snow
2018-01-29 19:56 ` Kevin Wolf
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 04/14] blockjobs: RFC add block_job_verb permission table John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 05/14] blockjobs: add block_job_dismiss John Snow
2018-01-29 17:38 ` Kevin Wolf
2018-01-29 20:33 ` John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 06/14] blockjobs: add CONCLUDED state John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 07/14] blockjobs: ensure abort is called for cancelled jobs John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 08/14] blockjobs: add commit, abort, clean helpers John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 09/14] blockjobs: add prepare callback John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 10/14] blockjobs: Add waiting event John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 11/14] blockjobs: add PENDING status and event John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 12/14] blockjobs: add block-job-finalize John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 13/14] blockjobs: Expose manual property John Snow
2018-01-27 2:05 ` [Qemu-devel] [RFC v3 14/14] iotests: test manual job dismissal John Snow
2018-01-27 2:25 ` [Qemu-devel] [RFC v3 00/14] blockjobs: add explicit job management no-reply
2018-02-01 0:08 ` John Snow
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180129171755.GM6141@localhost.localdomain \
--to=kwolf@redhat.com \
--cc=jsnow@redhat.com \
--cc=jtc@redhat.com \
--cc=pkrempa@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).