mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
job: Add error message for failing jobs
So far we relied on job->ret and strerror() to produce an error message for failed jobs. Not surprisingly, this tends to result in completely useless messages. This adds a Job.error field that can contain an error string for a failing job, and a parameter to job_completed() that sets the field. As a default, if NULL is passed, we continue to use strerror(job->ret). All existing callers are changed to pass NULL. They can be improved in separate patches. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Jeff Cody <jcody@redhat.com>
This commit is contained in:
parent
4a5f2779ba
commit
1266c9b9f5
10 changed files with 29 additions and 17 deletions
16
job.c
16
job.c
|
@ -369,6 +369,7 @@ void job_unref(Job *job)
|
|||
|
||||
QLIST_REMOVE(job, job_list);
|
||||
|
||||
g_free(job->error);
|
||||
g_free(job->id);
|
||||
g_free(job);
|
||||
}
|
||||
|
@ -660,6 +661,9 @@ static void job_update_rc(Job *job)
|
|||
job->ret = -ECANCELED;
|
||||
}
|
||||
if (job->ret) {
|
||||
if (!job->error) {
|
||||
job->error = g_strdup(strerror(-job->ret));
|
||||
}
|
||||
job_state_transition(job, JOB_STATUS_ABORTING);
|
||||
}
|
||||
}
|
||||
|
@ -782,6 +786,7 @@ static int job_prepare(Job *job)
|
|||
{
|
||||
if (job->ret == 0 && job->driver->prepare) {
|
||||
job->ret = job->driver->prepare(job);
|
||||
job_update_rc(job);
|
||||
}
|
||||
return job->ret;
|
||||
}
|
||||
|
@ -855,10 +860,17 @@ static void job_completed_txn_success(Job *job)
|
|||
}
|
||||
}
|
||||
|
||||
void job_completed(Job *job, int ret)
|
||||
void job_completed(Job *job, int ret, Error *error)
|
||||
{
|
||||
assert(job && job->txn && !job_is_completed(job));
|
||||
|
||||
job->ret = ret;
|
||||
if (error) {
|
||||
assert(job->ret < 0);
|
||||
job->error = g_strdup(error_get_pretty(error));
|
||||
error_free(error);
|
||||
}
|
||||
|
||||
job_update_rc(job);
|
||||
trace_job_completed(job, ret, job->ret);
|
||||
if (job->ret) {
|
||||
|
@ -876,7 +888,7 @@ void job_cancel(Job *job, bool force)
|
|||
}
|
||||
job_cancel_async(job, force);
|
||||
if (!job_started(job)) {
|
||||
job_completed(job, -ECANCELED);
|
||||
job_completed(job, -ECANCELED, NULL);
|
||||
} else if (job->deferred_to_main_loop) {
|
||||
job_completed_txn_abort(job);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue