]> git.proxmox.com Git - mirror_qemu.git/blob - include/block/blockjob.h
job: Add job_is_ready()
[mirror_qemu.git] / include / block / blockjob.h
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 */
25
26 #ifndef BLOCKJOB_H
27 #define BLOCKJOB_H
28
29 #include "qemu/job.h"
30 #include "block/block.h"
31 #include "qemu/ratelimit.h"
32
33 #define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */
34
35 typedef struct BlockJobDriver BlockJobDriver;
36
37 /**
38 * BlockJob:
39 *
40 * Long-running operation on a BlockDriverState.
41 */
42 typedef struct BlockJob {
43 /** Data belonging to the generic Job infrastructure */
44 Job job;
45
46 /** The job type, including the job vtable. */
47 const BlockJobDriver *driver;
48
49 /** The block device on which the job is operating. */
50 BlockBackend *blk;
51
52 /** Status that is published by the query-block-jobs QMP API */
53 BlockDeviceIoStatus iostatus;
54
55 /** Offset that is published by the query-block-jobs QMP API */
56 int64_t offset;
57
58 /** Length that is published by the query-block-jobs QMP API */
59 int64_t len;
60
61 /** Speed that was set with @block_job_set_speed. */
62 int64_t speed;
63
64 /** Rate limiting data structure for implementing @speed. */
65 RateLimit limit;
66
67 /** Block other operations when block job is running */
68 Error *blocker;
69
70 /** Called when a cancelled job is finalised. */
71 Notifier finalize_cancelled_notifier;
72
73 /** Called when a successfully completed job is finalised. */
74 Notifier finalize_completed_notifier;
75
76 /** Called when the job transitions to PENDING */
77 Notifier pending_notifier;
78
79 /** BlockDriverStates that are involved in this block job */
80 GSList *nodes;
81 } BlockJob;
82
83 /**
84 * block_job_next:
85 * @job: A block job, or %NULL.
86 *
87 * Get the next element from the list of block jobs after @job, or the
88 * first one if @job is %NULL.
89 *
90 * Returns the requested job, or %NULL if there are no more jobs left.
91 */
92 BlockJob *block_job_next(BlockJob *job);
93
94 /**
95 * block_job_get:
96 * @id: The id of the block job.
97 *
98 * Get the block job identified by @id (which must not be %NULL).
99 *
100 * Returns the requested job, or %NULL if it doesn't exist.
101 */
102 BlockJob *block_job_get(const char *id);
103
104 /**
105 * block_job_add_bdrv:
106 * @job: A block job
107 * @name: The name to assign to the new BdrvChild
108 * @bs: A BlockDriverState that is involved in @job
109 * @perm, @shared_perm: Permissions to request on the node
110 *
111 * Add @bs to the list of BlockDriverState that are involved in
112 * @job. This means that all operations will be blocked on @bs while
113 * @job exists.
114 */
115 int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
116 uint64_t perm, uint64_t shared_perm, Error **errp);
117
118 /**
119 * block_job_remove_all_bdrv:
120 * @job: The block job
121 *
122 * Remove all BlockDriverStates from the list of nodes that are involved in the
123 * job. This removes the blockers added with block_job_add_bdrv().
124 */
125 void block_job_remove_all_bdrv(BlockJob *job);
126
127 /**
128 * block_job_set_speed:
129 * @job: The job to set the speed for.
130 * @speed: The new value
131 * @errp: Error object.
132 *
133 * Set a rate-limiting parameter for the job; the actual meaning may
134 * vary depending on the job type.
135 */
136 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
137
138 /**
139 * block_job_progress_update:
140 * @job: The job that has made progress
141 * @done: How much progress the job made
142 *
143 * Updates the progress counter of the job.
144 */
145 void block_job_progress_update(BlockJob *job, uint64_t done);
146
147 /**
148 * block_job_progress_set_remaining:
149 * @job: The job whose expected progress end value is set
150 * @remaining: Expected end value of the progress counter of the job
151 *
152 * Sets the expected end value of the progress counter of a job so that a
153 * completion percentage can be calculated when the progress is updated.
154 */
155 void block_job_progress_set_remaining(BlockJob *job, uint64_t remaining);
156
157 /**
158 * block_job_query:
159 * @job: The job to get information about.
160 *
161 * Return information about a job.
162 */
163 BlockJobInfo *block_job_query(BlockJob *job, Error **errp);
164
165 /**
166 * block_job_iostatus_reset:
167 * @job: The job whose I/O status should be reset.
168 *
169 * Reset I/O status on @job and on BlockDriverState objects it uses,
170 * other than job->blk.
171 */
172 void block_job_iostatus_reset(BlockJob *job);
173
174 /**
175 * block_job_is_internal:
176 * @job: The job to determine if it is user-visible or not.
177 *
178 * Returns true if the job should not be visible to the management layer.
179 */
180 bool block_job_is_internal(BlockJob *job);
181
182 /**
183 * block_job_driver:
184 *
185 * Returns the driver associated with a block job.
186 */
187 const BlockJobDriver *block_job_driver(BlockJob *job);
188
189 #endif