{
BackupCompleteData *data = opaque;
- job_completed(job, data->ret);
+ job_completed(job, data->ret, NULL);
g_free(data);
}
* bdrv_set_backing_hd() to fail. */
block_job_remove_all_bdrv(bjob);
- job_completed(job, ret);
+ job_completed(job, ret, NULL);
g_free(data);
/* If bdrv_drop_intermediate() didn't already do that, remove the commit
blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);
- job_completed(job, data->ret);
+ job_completed(job, data->ret, NULL);
g_free(data);
bdrv_drained_end(src);
}
g_free(s->backing_file_str);
- job_completed(job, data->ret);
+ job_completed(job, data->ret, NULL);
g_free(data);
}
/** Estimated progress_current value at the completion of the job */
int64_t progress_total;
+ /** Error string for a failed job (NULL if, and only if, job->ret == 0) */
+ char *error;
+
/** ret code passed to job_completed. */
int ret;
/**
* @job: The job being completed.
* @ret: The status code.
+ * @error: The error message for a failing job (only with @ret < 0). If @ret 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. 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);
+void job_completed(Job *job, int ret, Error *error);
/** Asynchronously complete the specified @job. */
void job_complete(Job *job, Error **errp);
static JobInfo *job_query_single(Job *job, Error **errp)
{
JobInfo *info;
- const char *errmsg = NULL;
assert(!job_is_internal(job));
- if (job->ret < 0) {
- errmsg = strerror(-job->ret);
- }
-
info = g_new(JobInfo, 1);
*info = (JobInfo) {
.id = g_strdup(job->id),
.status = job->status,
.current_progress = job->progress_current,
.total_progress = job->progress_total,
- .has_error = !!errmsg,
- .error = g_strdup(errmsg),
+ .has_error = !!job->error,
+ .error = g_strdup(job->error),
};
return info;
QLIST_REMOVE(job, job_list);
+ g_free(job->error);
g_free(job->id);
g_free(job);
}
job->ret = -ECANCELED;
}
if (job->ret) {
+ if (!job->error) {
+ job->error = g_strdup(strerror(-job->ret));
+ }
job_state_transition(job, JOB_STATUS_ABORTING);
}
}
{
if (job->ret == 0 && job->driver->prepare) {
job->ret = job->driver->prepare(job);
+ job_update_rc(job);
}
return job->ret;
}
}
}
-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) {
}
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 {
static void test_job_completed(Job *job, void *opaque)
{
- job_completed(job, 0);
+ job_completed(job, 0, NULL);
}
static void coroutine_fn test_job_start(void *opaque)
rc = -ECANCELED;
}
- job_completed(job, rc);
+ job_completed(job, rc, NULL);
bdrv_unref(bs);
}
{
CancelJob *s = opaque;
s->completed = true;
- job_completed(job, 0);
+ job_completed(job, 0, NULL);
}
static void cancel_job_complete(Job *job, Error **errp)