From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, Stefan Hajnoczi <stefanha@redhat.com>,
jtc@redhat.com, Jeff Cody <jcody@redhat.com>,
Max Reitz <mreitz@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH v2 8/9] jobs: remove ret argument to job_completed; privatize it
Date: Thu, 23 Aug 2018 18:08:55 -0400 [thread overview]
Message-ID: <20180823220856.10094-9-jsnow@redhat.com> (raw)
In-Reply-To: <20180823220856.10094-1-jsnow@redhat.com>
Jobs are now expected to return their retcode on the stack, from the
.run callback, so we can remove that argument.
job_cancel does not need to set -ECANCELED because job_completed will
update the return code itself if the job was canceled.
While we're here, make job_completed static to job.c and remove it from
job.h; move the documentation of return code to the .run() callback and
to the job->ret property, accordingly.
Signed-off-by: John Snow <jsnow@redhat.com>
---
include/qemu/job.h | 24 +++++++++++-------------
job.c | 11 ++++++-----
trace-events | 2 +-
3 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/include/qemu/job.h b/include/qemu/job.h
index c67f6a647e..2990f28edc 100644
--- a/include/qemu/job.h
+++ b/include/qemu/job.h
@@ -124,7 +124,7 @@ typedef struct Job {
/** Estimated progress_current value at the completion of the job */
int64_t progress_total;
- /** ret code passed to job_completed. */
+ /** Return code from @run callback; 0 on success and -errno on failure. */
int ret;
/** Error object for a failed job **/
@@ -168,7 +168,16 @@ struct JobDriver {
/** Enum describing the operation */
JobType job_type;
- /** Mandatory: Entrypoint for the Coroutine. */
+ /**
+ * Mandatory: Entrypoint for the Coroutine.
+ *
+ * This callback will be invoked when moving from CREATED to RUNNING.
+ *
+ * If this callback returns nonzero, the job transaction it is part of is
+ * aborted. If it returns zero, the job moves into the WAITING state. If it
+ * is the last job to complete in its transaction, all jobs in the
+ * transaction move from WAITING to PENDING.
+ */
int coroutine_fn (*run)(Job *job, Error **errp);
/**
@@ -492,17 +501,6 @@ void job_early_fail(Job *job);
/** Moves the @job from RUNNING to READY */
void job_transition_to_ready(Job *job);
-/**
- * @job: The job being completed.
- * @ret: The status code.
- *
- * Marks @job as completed. If @ret is non-zero, the job transaction it is part
- * of is aborted. If @ret is zero, the job moves into the WAITING state. If it
- * is the last job to complete in its transaction, all jobs in the transaction
- * move from WAITING to PENDING.
- */
-void job_completed(Job *job, int ret);
-
/** Asynchronously complete the specified @job. */
void job_complete(Job *job, Error **errp);
diff --git a/job.c b/job.c
index bc8dad4e71..213042b762 100644
--- a/job.c
+++ b/job.c
@@ -535,6 +535,8 @@ void job_drain(Job *job)
}
}
+static void job_completed(Job *job);
+
static void job_exit(void *opaque)
{
Job *job = (Job *)opaque;
@@ -545,7 +547,7 @@ static void job_exit(void *opaque)
job->driver->exit(job);
aio_context_release(aio_context);
}
- job_completed(job, job->ret);
+ job_completed(job);
}
/**
@@ -883,13 +885,12 @@ static void job_completed_txn_success(Job *job)
}
}
-void job_completed(Job *job, int ret)
+static void job_completed(Job *job)
{
assert(job && job->txn && !job_is_completed(job));
- job->ret = ret;
job_update_rc(job);
- trace_job_completed(job, ret, job->ret);
+ trace_job_completed(job, job->ret);
if (job->ret) {
job_completed_txn_abort(job);
} else {
@@ -905,7 +906,7 @@ void job_cancel(Job *job, bool force)
}
job_cancel_async(job, force);
if (!job_started(job)) {
- job_completed(job, -ECANCELED);
+ job_completed(job);
} else if (job->deferred_to_main_loop) {
job_completed_txn_abort(job);
} else {
diff --git a/trace-events b/trace-events
index c445f54773..4fd2cb4b97 100644
--- a/trace-events
+++ b/trace-events
@@ -107,7 +107,7 @@ gdbstub_err_checksum_incorrect(uint8_t expected, uint8_t got) "got command packe
# job.c
job_state_transition(void *job, int ret, const char *legal, const char *s0, const char *s1) "job %p (ret: %d) attempting %s transition (%s-->%s)"
job_apply_verb(void *job, const char *state, const char *verb, const char *legal) "job %p in state %s; applying verb %s (%s)"
-job_completed(void *job, int ret, int jret) "job %p ret %d corrected ret %d"
+job_completed(void *job, int ret) "job %p ret %d"
# job-qmp.c
qmp_job_cancel(void *job) "job %p"
--
2.14.4
next prev parent reply other threads:[~2018-08-23 22:09 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 22:08 [Qemu-devel] [PATCH v2 0/9] jobs: Job Exit Refactoring Pt 1 John Snow
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 1/9] jobs: change start callback to run callback John Snow
2018-08-27 9:30 ` Max Reitz
2018-08-30 0:06 ` John Snow
2018-08-31 9:06 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 2/9] jobs: canonize Error object John Snow
2018-08-27 9:41 ` Max Reitz
2018-08-27 10:43 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 3/9] jobs: add exit shim John Snow
2018-08-27 10:00 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 4/9] block/commit: utilize job_exit shim John Snow
2018-08-27 10:28 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 5/9] block/mirror: " John Snow
2018-08-27 10:30 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 6/9] jobs: " John Snow
2018-08-27 10:37 ` Max Reitz
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 7/9] block/backup: make function variables consistently named John Snow
2018-08-27 10:41 ` Max Reitz
2018-08-23 22:08 ` John Snow [this message]
2018-08-27 10:52 ` [Qemu-devel] [PATCH v2 8/9] jobs: remove ret argument to job_completed; privatize it Max Reitz
2018-08-27 18:43 ` John Snow
2018-08-23 22:08 ` [Qemu-devel] [PATCH v2 9/9] jobs: remove job_defer_to_main_loop John Snow
2018-08-27 10:56 ` Max Reitz
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=20180823220856.10094-9-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=jcody@redhat.com \
--cc=jtc@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).