From nobody Wed Nov 5 12:35:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1534533585642152.91731476090683; Fri, 17 Aug 2018 12:19:45 -0700 (PDT) Received: from localhost ([::1]:36089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqkHg-0003eN-FH for importer@patchew.org; Fri, 17 Aug 2018 15:19:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqk90-0001Jh-I3 for qemu-devel@nongnu.org; Fri, 17 Aug 2018 15:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqk3i-0006mR-2J for qemu-devel@nongnu.org; Fri, 17 Aug 2018 15:05:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57902) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fqk3g-0006i4-0x; Fri, 17 Aug 2018 15:05:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 553833084218; Fri, 17 Aug 2018 19:05:15 +0000 (UTC) Received: from probe.redhat.com (ovpn-123-11.rdu2.redhat.com [10.10.123.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4ACB916C66; Fri, 17 Aug 2018 19:05:14 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 17 Aug 2018 15:04:52 -0400 Message-Id: <20180817190457.8292-3-jsnow@redhat.com> In-Reply-To: <20180817190457.8292-1-jsnow@redhat.com> References: <20180817190457.8292-1-jsnow@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 17 Aug 2018 19:05:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/7] jobs: canonize Error object X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, John Snow , Jeff Cody , jtc@redhat.com, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Jobs presently use both an Error object in the case of the create job, and char strings in the case of generic errors elsewhere. Unify the two paths as just j->err, and remove the extra argument from job_completed. The integer error code for job_completed is kept for now for use by pre-emptive cancellation. Signed-off-by: John Snow Reviewed-by: Eric Blake --- block/backup.c | 2 +- block/commit.c | 2 +- block/create.c | 5 ++--- block/mirror.c | 2 +- block/stream.c | 2 +- include/qemu/job.h | 10 ++++------ job-qmp.c | 5 +++-- job.c | 19 ++++++------------- tests/test-bdrv-drain.c | 2 +- tests/test-blockjob-txn.c | 2 +- tests/test-blockjob.c | 2 +- 11 files changed, 22 insertions(+), 31 deletions(-) diff --git a/block/backup.c b/block/backup.c index 5d47781840..1e965d54e5 100644 --- a/block/backup.c +++ b/block/backup.c @@ -388,7 +388,7 @@ static void backup_complete(Job *job, void *opaque) { BackupCompleteData *data =3D opaque; =20 - job_completed(job, data->ret, NULL); + job_completed(job, data->ret); g_free(data); } =20 diff --git a/block/commit.c b/block/commit.c index a0ea86ff64..4a17bb73ec 100644 --- a/block/commit.c +++ b/block/commit.c @@ -117,7 +117,7 @@ static void commit_complete(Job *job, void *opaque) * bdrv_set_backing_hd() to fail. */ block_job_remove_all_bdrv(bjob); =20 - job_completed(job, ret, NULL); + job_completed(job, ret); g_free(data); =20 /* If bdrv_drop_intermediate() didn't already do that, remove the comm= it diff --git a/block/create.c b/block/create.c index 04733c3618..26a385c6c7 100644 --- a/block/create.c +++ b/block/create.c @@ -35,14 +35,13 @@ typedef struct BlockdevCreateJob { BlockDriver *drv; BlockdevCreateOptions *opts; int ret; - Error *err; } BlockdevCreateJob; =20 static void blockdev_create_complete(Job *job, void *opaque) { BlockdevCreateJob *s =3D container_of(job, BlockdevCreateJob, common); =20 - job_completed(job, s->ret, s->err); + job_completed(job, s->ret); } =20 static int coroutine_fn blockdev_create_run(Job *job, Error **errp) @@ -50,7 +49,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Err= or **errp) BlockdevCreateJob *s =3D container_of(job, BlockdevCreateJob, common); =20 job_progress_set_remaining(&s->common, 1); - s->ret =3D s->drv->bdrv_co_create(s->opts, &s->err); + s->ret =3D s->drv->bdrv_co_create(s->opts, errp); job_progress_update(&s->common, 1); =20 qapi_free_BlockdevCreateOptions(s->opts); diff --git a/block/mirror.c b/block/mirror.c index 691763db41..be5dc6b7b0 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -710,7 +710,7 @@ static void mirror_exit(Job *job, void *opaque) blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort); =20 bs_opaque->job =3D NULL; - job_completed(job, data->ret, NULL); + job_completed(job, data->ret); =20 g_free(data); bdrv_drained_end(src); diff --git a/block/stream.c b/block/stream.c index b4b987df7e..26a775386b 100644 --- a/block/stream.c +++ b/block/stream.c @@ -93,7 +93,7 @@ out: } =20 g_free(s->backing_file_str); - job_completed(job, data->ret, NULL); + job_completed(job, data->ret); g_free(data); } =20 diff --git a/include/qemu/job.h b/include/qemu/job.h index 9cf463d228..5c92c53ef0 100644 --- a/include/qemu/job.h +++ b/include/qemu/job.h @@ -124,12 +124,12 @@ typedef struct Job { /** Estimated progress_current value at the completion of the job */ int64_t progress_total; =20 - /** Error string for a failed job (NULL if, and only if, job->ret =3D= =3D 0) */ - char *error; - /** ret code passed to job_completed. */ int ret; =20 + /** Error object for a failed job **/ + Error *err; + /** The completion function that will be called when the job completes= . */ BlockCompletionFunc *cb; =20 @@ -484,15 +484,13 @@ void job_transition_to_ready(Job *job); /** * @job: The job being completed. * @ret: The status code. - * @error: The error message for a failing job (only with @ret < 0). If @r= et is - * negative, but NULL is given for @error, strerror() is used. * * 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. I= f it * is the last job to complete in its transaction, all jobs in the transac= tion * move from WAITING to PENDING. */ -void job_completed(Job *job, int ret, Error *error); +void job_completed(Job *job, int ret); =20 /** Asynchronously complete the specified @job. */ void job_complete(Job *job, Error **errp); diff --git a/job-qmp.c b/job-qmp.c index 410775df61..a969b2bbf0 100644 --- a/job-qmp.c +++ b/job-qmp.c @@ -146,8 +146,9 @@ static JobInfo *job_query_single(Job *job, Error **errp) .status =3D job->status, .current_progress =3D job->progress_current, .total_progress =3D job->progress_total, - .has_error =3D !!job->error, - .error =3D g_strdup(job->error), + .has_error =3D !!job->err, + .error =3D job->err ? \ + g_strdup(error_get_pretty(job->err)) : NULL, }; =20 return info; diff --git a/job.c b/job.c index 898260b2b3..c9de1af556 100644 --- a/job.c +++ b/job.c @@ -369,7 +369,7 @@ void job_unref(Job *job) =20 QLIST_REMOVE(job, job_list); =20 - g_free(job->error); + error_free(job->err); g_free(job->id); g_free(job); } @@ -535,7 +535,6 @@ void job_drain(Job *job) } } =20 - /** * All jobs must allow a pause point before entering their job proper. This * ensures that jobs can be paused prior to being started, then resumed la= ter. @@ -546,7 +545,7 @@ static void coroutine_fn job_co_entry(void *opaque) =20 assert(job && job->driver && job->driver->run); job_pause_point(job); - job->ret =3D job->driver->run(job, NULL); + job->ret =3D job->driver->run(job, &job->err); } =20 =20 @@ -666,8 +665,8 @@ static void job_update_rc(Job *job) job->ret =3D -ECANCELED; } if (job->ret) { - if (!job->error) { - job->error =3D g_strdup(strerror(-job->ret)); + if (!job->err) { + error_setg_errno(&job->err, -job->ret, "job failed"); } job_state_transition(job, JOB_STATUS_ABORTING); } @@ -865,17 +864,11 @@ static void job_completed_txn_success(Job *job) } } =20 -void job_completed(Job *job, int ret, Error *error) +void job_completed(Job *job, int ret) { assert(job && job->txn && !job_is_completed(job)); =20 job->ret =3D ret; - if (error) { - assert(job->ret < 0); - job->error =3D g_strdup(error_get_pretty(error)); - error_free(error); - } - job_update_rc(job); trace_job_completed(job, ret, job->ret); if (job->ret) { @@ -893,7 +886,7 @@ void job_cancel(Job *job, bool force) } job_cancel_async(job, force); if (!job_started(job)) { - job_completed(job, -ECANCELED, NULL); + job_completed(job, -ECANCELED); } else if (job->deferred_to_main_loop) { job_completed_txn_abort(job); } else { diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index a7533861f6..00604dfc0c 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -754,7 +754,7 @@ typedef struct TestBlockJob { =20 static void test_job_completed(Job *job, void *opaque) { - job_completed(job, 0, NULL); + job_completed(job, 0); } =20 static int coroutine_fn test_job_run(Job *job, Error **errp) diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c index 3194924071..82cedee78b 100644 --- a/tests/test-blockjob-txn.c +++ b/tests/test-blockjob-txn.c @@ -34,7 +34,7 @@ static void test_block_job_complete(Job *job, void *opaqu= e) rc =3D -ECANCELED; } =20 - job_completed(job, rc, NULL); + job_completed(job, rc); bdrv_unref(bs); } =20 diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c index b0462bfdec..408a226939 100644 --- a/tests/test-blockjob.c +++ b/tests/test-blockjob.c @@ -167,7 +167,7 @@ static void cancel_job_completed(Job *job, void *opaque) { CancelJob *s =3D opaque; s->completed =3D true; - job_completed(job, 0, NULL); + job_completed(job, 0); } =20 static void cancel_job_complete(Job *job, Error **errp) --=20 2.14.4