|
|
383d26 |
From d384736e7c77d64142f33fabc0aa50878d8f252e Mon Sep 17 00:00:00 2001
|
|
|
383d26 |
From: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Date: Mon, 10 Sep 2018 18:17:40 +0200
|
|
|
383d26 |
Subject: [PATCH 02/25] jobs: canonize Error object
|
|
|
383d26 |
|
|
|
383d26 |
RH-Author: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Message-id: <20180910181803.11781-3-jsnow@redhat.com>
|
|
|
383d26 |
Patchwork-id: 82085
|
|
|
383d26 |
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 02/25] jobs: canonize Error object
|
|
|
383d26 |
Bugzilla: 1626061
|
|
|
383d26 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
383d26 |
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Jobs presently use both an Error object in the case of the create job,
|
|
|
383d26 |
and char strings in the case of generic errors elsewhere.
|
|
|
383d26 |
|
|
|
383d26 |
Unify the two paths as just j->err, and remove the extra argument from
|
|
|
383d26 |
job_completed. The integer error code for job_completed is kept for now,
|
|
|
383d26 |
to be removed shortly in a separate patch.
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
Message-id: 20180830015734.19765-3-jsnow@redhat.com
|
|
|
383d26 |
[mreitz: Dropped a superfluous g_strdup()]
|
|
|
383d26 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
383d26 |
Signed-off-by: Max Reitz <mreitz@redhat.com>
|
|
|
383d26 |
(cherry picked from commit 3d1f8b07a4c241f81949eff507d9f3a8fd73b87b)
|
|
|
383d26 |
Signed-off-by: John Snow <jsnow@redhat.com>
|
|
|
383d26 |
|
|
|
383d26 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
383d26 |
---
|
|
|
383d26 |
block/backup.c | 2 +-
|
|
|
383d26 |
block/commit.c | 2 +-
|
|
|
383d26 |
block/create.c | 5 ++---
|
|
|
383d26 |
block/mirror.c | 2 +-
|
|
|
383d26 |
block/stream.c | 2 +-
|
|
|
383d26 |
include/qemu/job.h | 14 ++++++++------
|
|
|
383d26 |
job-qmp.c | 5 +++--
|
|
|
383d26 |
job.c | 18 ++++++------------
|
|
|
383d26 |
tests/test-bdrv-drain.c | 2 +-
|
|
|
383d26 |
tests/test-blockjob-txn.c | 2 +-
|
|
|
383d26 |
tests/test-blockjob.c | 2 +-
|
|
|
383d26 |
11 files changed, 26 insertions(+), 30 deletions(-)
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/block/backup.c b/block/backup.c
|
|
|
383d26 |
index a142518..a5bf699 100644
|
|
|
383d26 |
--- a/block/backup.c
|
|
|
383d26 |
+++ b/block/backup.c
|
|
|
383d26 |
@@ -388,7 +388,7 @@ static void backup_complete(Job *job, void *opaque)
|
|
|
383d26 |
{
|
|
|
383d26 |
BackupCompleteData *data = opaque;
|
|
|
383d26 |
|
|
|
383d26 |
- job_completed(job, data->ret, NULL);
|
|
|
383d26 |
+ job_completed(job, data->ret);
|
|
|
383d26 |
g_free(data);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/block/commit.c b/block/commit.c
|
|
|
383d26 |
index 905a1c5..af7579d 100644
|
|
|
383d26 |
--- a/block/commit.c
|
|
|
383d26 |
+++ b/block/commit.c
|
|
|
383d26 |
@@ -117,7 +117,7 @@ static void commit_complete(Job *job, void *opaque)
|
|
|
383d26 |
* bdrv_set_backing_hd() to fail. */
|
|
|
383d26 |
block_job_remove_all_bdrv(bjob);
|
|
|
383d26 |
|
|
|
383d26 |
- job_completed(job, ret, NULL);
|
|
|
383d26 |
+ job_completed(job, ret);
|
|
|
383d26 |
g_free(data);
|
|
|
383d26 |
|
|
|
383d26 |
/* If bdrv_drop_intermediate() didn't already do that, remove the commit
|
|
|
383d26 |
diff --git a/block/create.c b/block/create.c
|
|
|
383d26 |
index 04733c3..26a385c 100644
|
|
|
383d26 |
--- a/block/create.c
|
|
|
383d26 |
+++ b/block/create.c
|
|
|
383d26 |
@@ -35,14 +35,13 @@ typedef struct BlockdevCreateJob {
|
|
|
383d26 |
BlockDriver *drv;
|
|
|
383d26 |
BlockdevCreateOptions *opts;
|
|
|
383d26 |
int ret;
|
|
|
383d26 |
- Error *err;
|
|
|
383d26 |
} BlockdevCreateJob;
|
|
|
383d26 |
|
|
|
383d26 |
static void blockdev_create_complete(Job *job, void *opaque)
|
|
|
383d26 |
{
|
|
|
383d26 |
BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
|
|
|
383d26 |
|
|
|
383d26 |
- job_completed(job, s->ret, s->err);
|
|
|
383d26 |
+ job_completed(job, s->ret);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
|
|
|
383d26 |
@@ -50,7 +49,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Error **errp)
|
|
|
383d26 |
BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);
|
|
|
383d26 |
|
|
|
383d26 |
job_progress_set_remaining(&s->common, 1);
|
|
|
383d26 |
- s->ret = s->drv->bdrv_co_create(s->opts, &s->err);
|
|
|
383d26 |
+ s->ret = s->drv->bdrv_co_create(s->opts, errp);
|
|
|
383d26 |
job_progress_update(&s->common, 1);
|
|
|
383d26 |
|
|
|
383d26 |
qapi_free_BlockdevCreateOptions(s->opts);
|
|
|
383d26 |
diff --git a/block/mirror.c b/block/mirror.c
|
|
|
383d26 |
index 03b326d..459f944 100644
|
|
|
383d26 |
--- a/block/mirror.c
|
|
|
383d26 |
+++ b/block/mirror.c
|
|
|
383d26 |
@@ -581,7 +581,7 @@ static void mirror_exit(Job *job, void *opaque)
|
|
|
383d26 |
blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
|
|
|
383d26 |
blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
|
|
|
383d26 |
|
|
|
383d26 |
- job_completed(job, data->ret, NULL);
|
|
|
383d26 |
+ job_completed(job, data->ret);
|
|
|
383d26 |
|
|
|
383d26 |
g_free(data);
|
|
|
383d26 |
bdrv_drained_end(src);
|
|
|
383d26 |
diff --git a/block/stream.c b/block/stream.c
|
|
|
383d26 |
index b4b987d..26a7753 100644
|
|
|
383d26 |
--- a/block/stream.c
|
|
|
383d26 |
+++ b/block/stream.c
|
|
|
383d26 |
@@ -93,7 +93,7 @@ out:
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
g_free(s->backing_file_str);
|
|
|
383d26 |
- job_completed(job, data->ret, NULL);
|
|
|
383d26 |
+ job_completed(job, data->ret);
|
|
|
383d26 |
g_free(data);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/include/qemu/job.h b/include/qemu/job.h
|
|
|
383d26 |
index e81cc34..905dfdd 100644
|
|
|
383d26 |
--- a/include/qemu/job.h
|
|
|
383d26 |
+++ b/include/qemu/job.h
|
|
|
383d26 |
@@ -124,12 +124,16 @@ typedef struct Job {
|
|
|
383d26 |
/** Estimated progress_current value at the completion of the job */
|
|
|
383d26 |
int64_t progress_total;
|
|
|
383d26 |
|
|
|
383d26 |
- /** Error string for a failed job (NULL if, and only if, job->ret == 0) */
|
|
|
383d26 |
- char *error;
|
|
|
383d26 |
-
|
|
|
383d26 |
/** ret code passed to job_completed. */
|
|
|
383d26 |
int ret;
|
|
|
383d26 |
|
|
|
383d26 |
+ /**
|
|
|
383d26 |
+ * Error object for a failed job.
|
|
|
383d26 |
+ * If job->ret is nonzero and an error object was not set, it will be set
|
|
|
383d26 |
+ * to strerror(-job->ret) during job_completed.
|
|
|
383d26 |
+ */
|
|
|
383d26 |
+ Error *err;
|
|
|
383d26 |
+
|
|
|
383d26 |
/** The completion function that will be called when the job completes. */
|
|
|
383d26 |
BlockCompletionFunc *cb;
|
|
|
383d26 |
|
|
|
383d26 |
@@ -469,15 +473,13 @@ void job_transition_to_ready(Job *job);
|
|
|
383d26 |
/**
|
|
|
383d26 |
* @job: The job being completed.
|
|
|
383d26 |
* @ret: The status code.
|
|
|
383d26 |
- * @error: The error message for a failing job (only with @ret < 0). If @ret is
|
|
|
383d26 |
- * negative, but NULL is given for @error, strerror() is used.
|
|
|
383d26 |
*
|
|
|
383d26 |
* Marks @job as completed. If @ret is non-zero, the job transaction it is part
|
|
|
383d26 |
* of is aborted. If @ret is zero, the job moves into the WAITING state. If it
|
|
|
383d26 |
* is the last job to complete in its transaction, all jobs in the transaction
|
|
|
383d26 |
* move from WAITING to PENDING.
|
|
|
383d26 |
*/
|
|
|
383d26 |
-void job_completed(Job *job, int ret, Error *error);
|
|
|
383d26 |
+void job_completed(Job *job, int ret);
|
|
|
383d26 |
|
|
|
383d26 |
/** Asynchronously complete the specified @job. */
|
|
|
383d26 |
void job_complete(Job *job, Error **errp);
|
|
|
383d26 |
diff --git a/job-qmp.c b/job-qmp.c
|
|
|
383d26 |
index 410775d..a969b2b 100644
|
|
|
383d26 |
--- a/job-qmp.c
|
|
|
383d26 |
+++ b/job-qmp.c
|
|
|
383d26 |
@@ -146,8 +146,9 @@ static JobInfo *job_query_single(Job *job, Error **errp)
|
|
|
383d26 |
.status = job->status,
|
|
|
383d26 |
.current_progress = job->progress_current,
|
|
|
383d26 |
.total_progress = job->progress_total,
|
|
|
383d26 |
- .has_error = !!job->error,
|
|
|
383d26 |
- .error = g_strdup(job->error),
|
|
|
383d26 |
+ .has_error = !!job->err,
|
|
|
383d26 |
+ .error = job->err ? \
|
|
|
383d26 |
+ g_strdup(error_get_pretty(job->err)) : NULL,
|
|
|
383d26 |
};
|
|
|
383d26 |
|
|
|
383d26 |
return info;
|
|
|
383d26 |
diff --git a/job.c b/job.c
|
|
|
383d26 |
index 0d07700..020ee0d 100644
|
|
|
383d26 |
--- a/job.c
|
|
|
383d26 |
+++ b/job.c
|
|
|
383d26 |
@@ -369,7 +369,7 @@ void job_unref(Job *job)
|
|
|
383d26 |
|
|
|
383d26 |
QLIST_REMOVE(job, job_list);
|
|
|
383d26 |
|
|
|
383d26 |
- g_free(job->error);
|
|
|
383d26 |
+ error_free(job->err);
|
|
|
383d26 |
g_free(job->id);
|
|
|
383d26 |
g_free(job);
|
|
|
383d26 |
}
|
|
|
383d26 |
@@ -541,7 +541,7 @@ static void coroutine_fn job_co_entry(void *opaque)
|
|
|
383d26 |
|
|
|
383d26 |
assert(job && job->driver && job->driver->run);
|
|
|
383d26 |
job_pause_point(job);
|
|
|
383d26 |
- job->ret = job->driver->run(job, NULL);
|
|
|
383d26 |
+ job->ret = job->driver->run(job, &job->err);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
|
|
|
383d26 |
@@ -661,8 +661,8 @@ static void job_update_rc(Job *job)
|
|
|
383d26 |
job->ret = -ECANCELED;
|
|
|
383d26 |
}
|
|
|
383d26 |
if (job->ret) {
|
|
|
383d26 |
- if (!job->error) {
|
|
|
383d26 |
- job->error = g_strdup(strerror(-job->ret));
|
|
|
383d26 |
+ if (!job->err) {
|
|
|
383d26 |
+ error_setg(&job->err, "%s", strerror(-job->ret));
|
|
|
383d26 |
}
|
|
|
383d26 |
job_state_transition(job, JOB_STATUS_ABORTING);
|
|
|
383d26 |
}
|
|
|
383d26 |
@@ -860,17 +860,11 @@ static void job_completed_txn_success(Job *job)
|
|
|
383d26 |
}
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
-void job_completed(Job *job, int ret, Error *error)
|
|
|
383d26 |
+void job_completed(Job *job, int ret)
|
|
|
383d26 |
{
|
|
|
383d26 |
assert(job && job->txn && !job_is_completed(job));
|
|
|
383d26 |
|
|
|
383d26 |
job->ret = ret;
|
|
|
383d26 |
- if (error) {
|
|
|
383d26 |
- assert(job->ret < 0);
|
|
|
383d26 |
- job->error = g_strdup(error_get_pretty(error));
|
|
|
383d26 |
- error_free(error);
|
|
|
383d26 |
- }
|
|
|
383d26 |
-
|
|
|
383d26 |
job_update_rc(job);
|
|
|
383d26 |
trace_job_completed(job, ret, job->ret);
|
|
|
383d26 |
if (job->ret) {
|
|
|
383d26 |
@@ -888,7 +882,7 @@ void job_cancel(Job *job, bool force)
|
|
|
383d26 |
}
|
|
|
383d26 |
job_cancel_async(job, force);
|
|
|
383d26 |
if (!job_started(job)) {
|
|
|
383d26 |
- job_completed(job, -ECANCELED, NULL);
|
|
|
383d26 |
+ job_completed(job, -ECANCELED);
|
|
|
383d26 |
} else if (job->deferred_to_main_loop) {
|
|
|
383d26 |
job_completed_txn_abort(job);
|
|
|
383d26 |
} else {
|
|
|
383d26 |
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
|
|
|
383d26 |
index 798445a..8937894 100644
|
|
|
383d26 |
--- a/tests/test-bdrv-drain.c
|
|
|
383d26 |
+++ b/tests/test-bdrv-drain.c
|
|
|
383d26 |
@@ -498,7 +498,7 @@ typedef struct TestBlockJob {
|
|
|
383d26 |
|
|
|
383d26 |
static void test_job_completed(Job *job, void *opaque)
|
|
|
383d26 |
{
|
|
|
383d26 |
- job_completed(job, 0, NULL);
|
|
|
383d26 |
+ job_completed(job, 0);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
static int coroutine_fn test_job_run(Job *job, Error **errp)
|
|
|
383d26 |
diff --git a/tests/test-blockjob-txn.c b/tests/test-blockjob-txn.c
|
|
|
383d26 |
index 3194924..82cedee 100644
|
|
|
383d26 |
--- a/tests/test-blockjob-txn.c
|
|
|
383d26 |
+++ b/tests/test-blockjob-txn.c
|
|
|
383d26 |
@@ -34,7 +34,7 @@ static void test_block_job_complete(Job *job, void *opaque)
|
|
|
383d26 |
rc = -ECANCELED;
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
- job_completed(job, rc, NULL);
|
|
|
383d26 |
+ job_completed(job, rc);
|
|
|
383d26 |
bdrv_unref(bs);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
diff --git a/tests/test-blockjob.c b/tests/test-blockjob.c
|
|
|
383d26 |
index b0462bf..408a226 100644
|
|
|
383d26 |
--- a/tests/test-blockjob.c
|
|
|
383d26 |
+++ b/tests/test-blockjob.c
|
|
|
383d26 |
@@ -167,7 +167,7 @@ static void cancel_job_completed(Job *job, void *opaque)
|
|
|
383d26 |
{
|
|
|
383d26 |
CancelJob *s = opaque;
|
|
|
383d26 |
s->completed = true;
|
|
|
383d26 |
- job_completed(job, 0, NULL);
|
|
|
383d26 |
+ job_completed(job, 0);
|
|
|
383d26 |
}
|
|
|
383d26 |
|
|
|
383d26 |
static void cancel_job_complete(Job *job, Error **errp)
|
|
|
383d26 |
--
|
|
|
383d26 |
1.8.3.1
|
|
|
383d26 |
|