]>
git.proxmox.com Git - mirror_qemu.git/blob - include/qemu/job.h
2 * Declarations for background jobs
4 * Copyright (c) 2011 IBM Corp.
5 * Copyright (c) 2012, 2018 Red Hat, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 #include "qapi/qapi-types-block-core.h"
30 #include "qemu/queue.h"
32 typedef struct JobDriver JobDriver
;
35 * Long-running operation.
38 /** The ID of the job. May be NULL for internal jobs. */
41 /** The type of this job. */
42 const JobDriver
*driver
;
44 /** Reference count of the block job */
47 /** Current state; See @JobStatus for details. */
50 /** AioContext to run the job coroutine in */
51 AioContext
*aio_context
;
54 * Set to true if the job should cancel itself. The flag must
55 * always be tested just before toggling the busy flag from false
56 * to true. After a job has been cancelled, it should only yield
57 * if #aio_poll will ("sooner or later") reenter the coroutine.
61 /** Element of the list of jobs */
62 QLIST_ENTRY(Job
) job_list
;
66 * Callbacks and other information about a Job driver.
69 /** Derived Job struct size */
72 /** Enum describing the operation */
75 /** Called when the job is freed */
76 void (*free
)(Job
*job
);
81 * Create a new long-running job and return it.
83 * @job_id: The id of the newly-created job, or %NULL for internal jobs
84 * @driver: The class object for the newly-created job.
85 * @ctx: The AioContext to run the job coroutine in.
86 * @errp: Error object.
88 void *job_create(const char *job_id
, const JobDriver
*driver
, AioContext
*ctx
,
92 * Add a reference to Job refcnt, it will be decreased with job_unref, and then
93 * be freed if it comes to be the last reference.
95 void job_ref(Job
*job
);
98 * Release a reference that was previously acquired with job_ref() or
99 * job_create(). If it's the last reference to the object, it will be freed.
101 void job_unref(Job
*job
);
103 /** Returns the JobType of a given Job. */
104 JobType
job_type(const Job
*job
);
106 /** Returns the enum string for the JobType of a given Job. */
107 const char *job_type_str(const Job
*job
);
109 /** Returns whether the job is scheduled for cancellation. */
110 bool job_is_cancelled(Job
*job
);
113 * Get the next element from the list of block jobs after @job, or the
114 * first one if @job is %NULL.
116 * Returns the requested job, or %NULL if there are no more jobs left.
118 Job
*job_next(Job
*job
);
121 * Get the job identified by @id (which must not be %NULL).
123 * Returns the requested job, or %NULL if it doesn't exist.
125 Job
*job_get(const char *id
);
128 * Check whether the verb @verb can be applied to @job in its current state.
129 * Returns 0 if the verb can be applied; otherwise errp is set and -EPERM
132 int job_apply_verb(Job
*job
, JobVerb verb
, Error
**errp
);
134 /* TODO To be removed from the public interface */
135 void job_state_transition(Job
*job
, JobStatus s1
);