]>
Commit | Line | Data |
---|---|---|
2f0c9fe6 PB |
1 | /* |
2 | * Declarations for long-running block device operations | |
3 | * | |
4 | * Copyright (c) 2011 IBM Corp. | |
5 | * Copyright (c) 2012 Red Hat, Inc. | |
6 | * | |
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: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
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 | |
23 | * THE SOFTWARE. | |
24 | */ | |
175de524 | 25 | |
2f0c9fe6 | 26 | #ifndef BLOCKJOB_H |
175de524 | 27 | #define BLOCKJOB_H |
2f0c9fe6 | 28 | |
33e9e9bd | 29 | #include "qemu/job.h" |
737e150e | 30 | #include "block/block.h" |
f05fee50 | 31 | #include "qemu/ratelimit.h" |
2f0c9fe6 | 32 | |
18bb6928 KW |
33 | #define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */ |
34 | ||
c87621ea JS |
35 | typedef struct BlockJobDriver BlockJobDriver; |
36 | typedef struct BlockJobTxn BlockJobTxn; | |
2f0c9fe6 PB |
37 | |
38 | /** | |
39 | * BlockJob: | |
40 | * | |
41 | * Long-running operation on a BlockDriverState. | |
42 | */ | |
c87621ea | 43 | typedef struct BlockJob { |
33e9e9bd KW |
44 | /** Data belonging to the generic Job infrastructure */ |
45 | Job job; | |
46 | ||
2f0c9fe6 | 47 | /** The job type, including the job vtable. */ |
3fc4b10a | 48 | const BlockJobDriver *driver; |
2f0c9fe6 PB |
49 | |
50 | /** The block device on which the job is operating. */ | |
b6d2e599 | 51 | BlockBackend *blk; |
2f0c9fe6 | 52 | |
ef6dbf1e HR |
53 | /** |
54 | * Set to true when the job is ready to be completed. | |
55 | */ | |
56 | bool ready; | |
57 | ||
32c81a4a PB |
58 | /** Status that is published by the query-block-jobs QMP API */ |
59 | BlockDeviceIoStatus iostatus; | |
60 | ||
2f0c9fe6 PB |
61 | /** Offset that is published by the query-block-jobs QMP API */ |
62 | int64_t offset; | |
63 | ||
64 | /** Length that is published by the query-block-jobs QMP API */ | |
65 | int64_t len; | |
66 | ||
67 | /** Speed that was set with @block_job_set_speed. */ | |
68 | int64_t speed; | |
69 | ||
f05fee50 KW |
70 | /** Rate limiting data structure for implementing @speed. */ |
71 | RateLimit limit; | |
72 | ||
3718d8ab FZ |
73 | /** Block other operations when block job is running */ |
74 | Error *blocker; | |
75 | ||
139a9f02 KW |
76 | /** Called when a cancelled job is finalised. */ |
77 | Notifier finalize_cancelled_notifier; | |
78 | ||
79 | /** Called when a successfully completed job is finalised. */ | |
80 | Notifier finalize_completed_notifier; | |
81 | ||
82 | /** Called when the job transitions to PENDING */ | |
83 | Notifier pending_notifier; | |
84 | ||
23d402d4 AG |
85 | /** BlockDriverStates that are involved in this block job */ |
86 | GSList *nodes; | |
87 | ||
c55a832f FZ |
88 | BlockJobTxn *txn; |
89 | QLIST_ENTRY(BlockJob) txn_list; | |
c87621ea | 90 | } BlockJob; |
2f0c9fe6 | 91 | |
a7112795 AG |
92 | /** |
93 | * block_job_next: | |
94 | * @job: A block job, or %NULL. | |
95 | * | |
96 | * Get the next element from the list of block jobs after @job, or the | |
97 | * first one if @job is %NULL. | |
98 | * | |
99 | * Returns the requested job, or %NULL if there are no more jobs left. | |
100 | */ | |
101 | BlockJob *block_job_next(BlockJob *job); | |
102 | ||
ffb1f10c AG |
103 | /** |
104 | * block_job_get: | |
105 | * @id: The id of the block job. | |
106 | * | |
107 | * Get the block job identified by @id (which must not be %NULL). | |
108 | * | |
109 | * Returns the requested job, or %NULL if it doesn't exist. | |
110 | */ | |
111 | BlockJob *block_job_get(const char *id); | |
112 | ||
23d402d4 AG |
113 | /** |
114 | * block_job_add_bdrv: | |
115 | * @job: A block job | |
76d554e2 | 116 | * @name: The name to assign to the new BdrvChild |
23d402d4 | 117 | * @bs: A BlockDriverState that is involved in @job |
76d554e2 | 118 | * @perm, @shared_perm: Permissions to request on the node |
23d402d4 AG |
119 | * |
120 | * Add @bs to the list of BlockDriverState that are involved in | |
121 | * @job. This means that all operations will be blocked on @bs while | |
122 | * @job exists. | |
123 | */ | |
76d554e2 KW |
124 | int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs, |
125 | uint64_t perm, uint64_t shared_perm, Error **errp); | |
23d402d4 | 126 | |
bbc02b90 KW |
127 | /** |
128 | * block_job_remove_all_bdrv: | |
129 | * @job: The block job | |
130 | * | |
131 | * Remove all BlockDriverStates from the list of nodes that are involved in the | |
132 | * job. This removes the blockers added with block_job_add_bdrv(). | |
133 | */ | |
134 | void block_job_remove_all_bdrv(BlockJob *job); | |
135 | ||
2f0c9fe6 PB |
136 | /** |
137 | * block_job_set_speed: | |
138 | * @job: The job to set the speed for. | |
139 | * @speed: The new value | |
140 | * @errp: Error object. | |
141 | * | |
142 | * Set a rate-limiting parameter for the job; the actual meaning may | |
143 | * vary depending on the job type. | |
144 | */ | |
145 | void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp); | |
146 | ||
147 | /** | |
148 | * block_job_cancel: | |
149 | * @job: The job to be canceled. | |
b76e4458 | 150 | * @force: Quit a job without waiting for data to be in sync. |
2f0c9fe6 PB |
151 | * |
152 | * Asynchronously cancel the specified job. | |
153 | */ | |
b76e4458 | 154 | void block_job_cancel(BlockJob *job, bool force); |
2f0c9fe6 | 155 | |
aeae883b PB |
156 | /** |
157 | * block_job_complete: | |
158 | * @job: The job to be completed. | |
159 | * @errp: Error object. | |
160 | * | |
161 | * Asynchronously complete the specified job. | |
162 | */ | |
163 | void block_job_complete(BlockJob *job, Error **errp); | |
164 | ||
11b61fbc JS |
165 | |
166 | /** | |
167 | * block_job_finalize: | |
168 | * @job: The job to fully commit and finish. | |
169 | * @errp: Error object. | |
170 | * | |
171 | * For jobs that have finished their work and are pending | |
172 | * awaiting explicit acknowledgement to commit their work, | |
173 | * This will commit that work. | |
174 | * | |
175 | * FIXME: Make the below statement universally true: | |
176 | * For jobs that support the manual workflow mode, all graph | |
177 | * changes that occur as a result will occur after this command | |
178 | * and before a successful reply. | |
179 | */ | |
180 | void block_job_finalize(BlockJob *job, Error **errp); | |
181 | ||
75f71059 JS |
182 | /** |
183 | * block_job_dismiss: | |
184 | * @job: The job to be dismissed. | |
185 | * @errp: Error object. | |
186 | * | |
187 | * Remove a concluded job from the query list. | |
188 | */ | |
189 | void block_job_dismiss(BlockJob **job, Error **errp); | |
190 | ||
05df8a6a KW |
191 | /** |
192 | * block_job_progress_update: | |
193 | * @job: The job that has made progress | |
194 | * @done: How much progress the job made | |
195 | * | |
196 | * Updates the progress counter of the job. | |
197 | */ | |
198 | void block_job_progress_update(BlockJob *job, uint64_t done); | |
199 | ||
200 | /** | |
201 | * block_job_progress_set_remaining: | |
202 | * @job: The job whose expected progress end value is set | |
203 | * @remaining: Expected end value of the progress counter of the job | |
204 | * | |
205 | * Sets the expected end value of the progress counter of a job so that a | |
206 | * completion percentage can be calculated when the progress is updated. | |
207 | */ | |
208 | void block_job_progress_set_remaining(BlockJob *job, uint64_t remaining); | |
209 | ||
30e628b7 PB |
210 | /** |
211 | * block_job_query: | |
212 | * @job: The job to get information about. | |
213 | * | |
214 | * Return information about a job. | |
215 | */ | |
559b935f | 216 | BlockJobInfo *block_job_query(BlockJob *job, Error **errp); |
30e628b7 | 217 | |
0ec4dfb8 JS |
218 | /** |
219 | * block_job_user_cancel: | |
220 | * @job: The job to be cancelled. | |
b76e4458 | 221 | * @force: Quit a job without waiting for data to be in sync. |
0ec4dfb8 JS |
222 | * |
223 | * Cancels the specified job, but may refuse to do so if the | |
224 | * operation isn't currently meaningful. | |
225 | */ | |
b76e4458 | 226 | void block_job_user_cancel(BlockJob *job, bool force, Error **errp); |
0df4ba58 | 227 | |
2f0c9fe6 PB |
228 | /** |
229 | * block_job_cancel_sync: | |
230 | * @job: The job to be canceled. | |
231 | * | |
232 | * Synchronously cancel the job. The completion callback is called | |
233 | * before the function returns. The job may actually complete | |
234 | * instead of canceling itself; the circumstances under which this | |
235 | * happens depend on the kind of job that is active. | |
236 | * | |
237 | * Returns the return value from the job if the job actually completed | |
238 | * during the call, or -ECANCELED if it was canceled. | |
239 | */ | |
240 | int block_job_cancel_sync(BlockJob *job); | |
241 | ||
a1a2af07 KW |
242 | /** |
243 | * block_job_cancel_sync_all: | |
244 | * | |
245 | * Synchronously cancels all jobs using block_job_cancel_sync(). | |
246 | */ | |
247 | void block_job_cancel_sync_all(void); | |
248 | ||
345f9e1b HR |
249 | /** |
250 | * block_job_complete_sync: | |
251 | * @job: The job to be completed. | |
252 | * @errp: Error object which may be set by block_job_complete(); this is not | |
253 | * necessarily set on every error, the job return value has to be | |
254 | * checked as well. | |
255 | * | |
256 | * Synchronously complete the job. The completion callback is called before the | |
257 | * function returns, unless it is NULL (which is permissible when using this | |
258 | * function). | |
259 | * | |
260 | * Returns the return value from the job. | |
261 | */ | |
262 | int block_job_complete_sync(BlockJob *job, Error **errp); | |
263 | ||
32c81a4a PB |
264 | /** |
265 | * block_job_iostatus_reset: | |
266 | * @job: The job whose I/O status should be reset. | |
267 | * | |
3bd293c3 | 268 | * Reset I/O status on @job and on BlockDriverState objects it uses, |
e3a4f91b | 269 | * other than job->blk. |
32c81a4a PB |
270 | */ |
271 | void block_job_iostatus_reset(BlockJob *job); | |
272 | ||
c55a832f FZ |
273 | /** |
274 | * block_job_txn_new: | |
275 | * | |
276 | * Allocate and return a new block job transaction. Jobs can be added to the | |
277 | * transaction using block_job_txn_add_job(). | |
278 | * | |
279 | * The transaction is automatically freed when the last job completes or is | |
280 | * cancelled. | |
281 | * | |
282 | * All jobs in the transaction either complete successfully or fail/cancel as a | |
283 | * group. Jobs wait for each other before completing. Cancelling one job | |
284 | * cancels all jobs in the transaction. | |
285 | */ | |
286 | BlockJobTxn *block_job_txn_new(void); | |
287 | ||
288 | /** | |
289 | * block_job_txn_unref: | |
290 | * | |
291 | * Release a reference that was previously acquired with block_job_txn_add_job | |
292 | * or block_job_txn_new. If it's the last reference to the object, it will be | |
293 | * freed. | |
294 | */ | |
295 | void block_job_txn_unref(BlockJobTxn *txn); | |
296 | ||
297 | /** | |
298 | * block_job_txn_add_job: | |
299 | * @txn: The transaction (may be NULL) | |
300 | * @job: Job to add to the transaction | |
301 | * | |
302 | * Add @job to the transaction. The @job must not already be in a transaction. | |
303 | * The caller must call either block_job_txn_unref() or block_job_completed() | |
304 | * to release the reference that is automatically grabbed here. | |
305 | */ | |
306 | void block_job_txn_add_job(BlockJobTxn *txn, BlockJob *job); | |
307 | ||
559b935f JS |
308 | /** |
309 | * block_job_is_internal: | |
310 | * @job: The job to determine if it is user-visible or not. | |
311 | * | |
312 | * Returns true if the job should not be visible to the management layer. | |
313 | */ | |
314 | bool block_job_is_internal(BlockJob *job); | |
315 | ||
bd21935b KW |
316 | /** |
317 | * block_job_driver: | |
318 | * | |
319 | * Returns the driver associated with a block job. | |
320 | */ | |
321 | const BlockJobDriver *block_job_driver(BlockJob *job); | |
322 | ||
2f0c9fe6 | 323 | #endif |