Commit 1266c9b9 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

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: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarJeff Cody <jcody@redhat.com>
parent 4a5f2779
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ static void backup_complete(Job *job, void *opaque)
{
    BackupCompleteData *data = opaque;

    job_completed(job, data->ret);
    job_completed(job, data->ret, NULL);
    g_free(data);
}

+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ static void commit_complete(Job *job, void *opaque)
     * 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
+1 −1
Original line number Diff line number Diff line
@@ -581,7 +581,7 @@ static void mirror_exit(Job *job, void *opaque)
    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);
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ out:
    }

    g_free(s->backing_file_str);
    job_completed(job, data->ret);
    job_completed(job, data->ret, NULL);
    g_free(data);
}

+6 −1
Original line number Diff line number Diff line
@@ -124,6 +124,9 @@ typedef struct Job {
    /** 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;

@@ -466,13 +469,15 @@ 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 @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);
Loading