]>
git.proxmox.com Git - mirror_qemu.git/blob - include/block/blockjob_int.h
2 * Declarations for long-running block device operations
4 * Copyright (c) 2011 IBM Corp.
5 * Copyright (c) 2012 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
26 #ifndef BLOCKJOB_INT_H
27 #define BLOCKJOB_INT_H
29 #include "block/blockjob.h"
30 #include "block/block.h"
35 * A class type for block job driver.
37 struct BlockJobDriver
{
38 /** Generic JobDriver callbacks and settings */
42 * If the callback is not NULL, prepare will be invoked when all the jobs
43 * belonging to the same transaction complete; or upon this job's completion
44 * if it is not in a transaction.
46 * This callback will not be invoked if the job has already failed.
47 * If it fails, abort and then clean will be called.
49 int (*prepare
)(BlockJob
*job
);
52 * If the callback is not NULL, it will be invoked before the job is
53 * resumed in a new AioContext. This is the place to move any resources
54 * besides job->blk to the new AioContext.
56 void (*attached_aio_context
)(BlockJob
*job
, AioContext
*new_context
);
59 * If the callback is not NULL, it will be invoked when the job has to be
60 * synchronously cancelled or completed; it should drain BlockDriverStates
61 * as required to ensure progress.
63 * Block jobs must use the default implementation for job_driver.drain,
64 * which will in turn call this callback after doing generic block job
67 void (*drain
)(BlockJob
*job
);
72 * @job_id: The id of the newly-created job, or %NULL to have one
73 * generated automatically.
74 * @driver: The class object for the newly-created job.
75 * @txn: The transaction this job belongs to, if any. %NULL otherwise.
77 * @perm, @shared_perm: Permissions to request for @bs
78 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
79 * @flags: Creation flags for the Block Job. See @JobCreateFlags.
80 * @cb: Completion function for the job.
81 * @opaque: Opaque pointer value passed to @cb.
82 * @errp: Error object.
84 * Create a new long-running block device job and return it. The job
85 * will call @cb asynchronously when the job completes. Note that
86 * @bs may have been closed at the time the @cb it is called. If
87 * this is the case, the job may be reported as either cancelled or
90 * This function is not part of the public job interface; it should be
91 * called from a wrapper that is specific to the job type.
93 void *block_job_create(const char *job_id
, const BlockJobDriver
*driver
,
94 JobTxn
*txn
, BlockDriverState
*bs
, uint64_t perm
,
95 uint64_t shared_perm
, int64_t speed
, int flags
,
96 BlockCompletionFunc
*cb
, void *opaque
, Error
**errp
);
100 * Callback to be used for JobDriver.free in all block jobs. Frees block job
101 * specific resources in @job.
103 void block_job_free(Job
*job
);
106 * block_job_user_resume:
107 * Callback to be used for JobDriver.user_resume in all block jobs. Resets the
108 * iostatus when the user resumes @job.
110 void block_job_user_resume(Job
*job
);
114 * Callback to be used for JobDriver.drain in all block jobs. Drains the main
115 * block node associated with the block jobs and calls BlockJobDriver.drain for
116 * job-specific actions.
118 void block_job_drain(Job
*job
);
122 * @job: The job that calls the function.
124 * Yield the block job coroutine.
126 void block_job_yield(BlockJob
*job
);
129 * block_job_ratelimit_get_delay:
131 * Calculate and return delay for the next request in ns. See the documentation
132 * of ratelimit_calculate_delay() for details.
134 int64_t block_job_ratelimit_get_delay(BlockJob
*job
, uint64_t n
);
137 * block_job_completed:
138 * @job: The job being completed.
139 * @ret: The status code.
141 * Call the completion function that was registered at creation time, and
144 void block_job_completed(BlockJob
*job
, int ret
);
148 * @job: The job to enter.
150 * Continue the specified job by entering the coroutine.
152 void block_job_enter(BlockJob
*job
);
155 * block_job_event_ready:
156 * @job: The job which is now ready to be completed.
158 * Send a BLOCK_JOB_READY event for the specified job.
160 void block_job_event_ready(BlockJob
*job
);
163 * block_job_error_action:
164 * @job: The job to signal an error for.
165 * @on_err: The error action setting.
166 * @is_read: Whether the operation was a read.
167 * @error: The error that was reported.
169 * Report an I/O error for a block job and possibly stop the VM. Return the
170 * action that was selected based on @on_err and @error.
172 BlockErrorAction
block_job_error_action(BlockJob
*job
, BlockdevOnError on_err
,
173 int is_read
, int error
);