John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 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_INT_H |
| 27 | #define BLOCKJOB_INT_H |
| 28 | |
| 29 | #include "block/blockjob.h" |
| 30 | #include "block/block.h" |
| 31 | |
| 32 | /** |
| 33 | * BlockJobDriver: |
| 34 | * |
| 35 | * A class type for block job driver. |
| 36 | */ |
| 37 | struct BlockJobDriver { |
Kevin Wolf | 33e9e9b | 2018-04-12 17:29:59 +0200 | [diff] [blame] | 38 | /** Generic JobDriver callbacks and settings */ |
| 39 | JobDriver job_driver; |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 40 | |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 41 | /* |
Kevin Wolf | 89bd030 | 2018-03-22 14:11:20 +0100 | [diff] [blame] | 42 | * Returns whether the job has pending requests for the child or will |
| 43 | * submit new requests before the next pause point. This callback is polled |
| 44 | * in the context of draining a job node after requesting that the job be |
| 45 | * paused, until all activity on the child has stopped. |
| 46 | */ |
| 47 | bool (*drained_poll)(BlockJob *job); |
| 48 | |
| 49 | /* |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 50 | * If the callback is not NULL, it will be invoked before the job is |
| 51 | * resumed in a new AioContext. This is the place to move any resources |
| 52 | * besides job->blk to the new AioContext. |
| 53 | */ |
| 54 | void (*attached_aio_context)(BlockJob *job, AioContext *new_context); |
Vladimir Sementsov-Ogievskiy | e0323a0 | 2021-01-17 00:46:50 +0300 | [diff] [blame] | 55 | |
| 56 | void (*set_speed)(BlockJob *job, int64_t speed); |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * block_job_create: |
| 61 | * @job_id: The id of the newly-created job, or %NULL to have one |
| 62 | * generated automatically. |
John Snow | 62bfdf0 | 2018-03-10 03:27:28 -0500 | [diff] [blame] | 63 | * @driver: The class object for the newly-created job. |
John Snow | 75859b9 | 2018-03-10 03:27:27 -0500 | [diff] [blame] | 64 | * @txn: The transaction this job belongs to, if any. %NULL otherwise. |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 65 | * @bs: The block |
Kevin Wolf | c6cc12b | 2017-01-16 17:18:09 +0100 | [diff] [blame] | 66 | * @perm, @shared_perm: Permissions to request for @bs |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 67 | * @speed: The maximum speed, in bytes per second, or 0 for unlimited. |
Kevin Wolf | bb02b65 | 2018-04-19 17:54:56 +0200 | [diff] [blame] | 68 | * @flags: Creation flags for the Block Job. See @JobCreateFlags. |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 69 | * @cb: Completion function for the job. |
| 70 | * @opaque: Opaque pointer value passed to @cb. |
| 71 | * @errp: Error object. |
| 72 | * |
| 73 | * Create a new long-running block device job and return it. The job |
| 74 | * will call @cb asynchronously when the job completes. Note that |
| 75 | * @bs may have been closed at the time the @cb it is called. If |
| 76 | * this is the case, the job may be reported as either cancelled or |
| 77 | * completed. |
| 78 | * |
| 79 | * This function is not part of the public job interface; it should be |
| 80 | * called from a wrapper that is specific to the job type. |
| 81 | */ |
| 82 | void *block_job_create(const char *job_id, const BlockJobDriver *driver, |
Kevin Wolf | 62c9e41 | 2018-04-19 16:09:52 +0200 | [diff] [blame] | 83 | JobTxn *txn, BlockDriverState *bs, uint64_t perm, |
Kevin Wolf | c6cc12b | 2017-01-16 17:18:09 +0100 | [diff] [blame] | 84 | uint64_t shared_perm, int64_t speed, int flags, |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 85 | BlockCompletionFunc *cb, void *opaque, Error **errp); |
| 86 | |
| 87 | /** |
Kevin Wolf | 80fa2c7 | 2018-04-13 18:50:05 +0200 | [diff] [blame] | 88 | * block_job_free: |
| 89 | * Callback to be used for JobDriver.free in all block jobs. Frees block job |
| 90 | * specific resources in @job. |
| 91 | */ |
| 92 | void block_job_free(Job *job); |
| 93 | |
| 94 | /** |
Kevin Wolf | b15de82 | 2018-04-18 17:10:26 +0200 | [diff] [blame] | 95 | * block_job_user_resume: |
| 96 | * Callback to be used for JobDriver.user_resume in all block jobs. Resets the |
| 97 | * iostatus when the user resumes @job. |
| 98 | */ |
| 99 | void block_job_user_resume(Job *job); |
| 100 | |
| 101 | /** |
Kevin Wolf | dee81d5 | 2018-01-18 21:19:38 +0100 | [diff] [blame] | 102 | * block_job_ratelimit_get_delay: |
| 103 | * |
| 104 | * Calculate and return delay for the next request in ns. See the documentation |
| 105 | * of ratelimit_calculate_delay() for details. |
| 106 | */ |
| 107 | int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n); |
| 108 | |
| 109 | /** |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 110 | * block_job_error_action: |
| 111 | * @job: The job to signal an error for. |
| 112 | * @on_err: The error action setting. |
| 113 | * @is_read: Whether the operation was a read. |
| 114 | * @error: The error that was reported. |
| 115 | * |
| 116 | * Report an I/O error for a block job and possibly stop the VM. Return the |
| 117 | * action that was selected based on @on_err and @error. |
| 118 | */ |
| 119 | BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, |
| 120 | int is_read, int error); |
| 121 | |
John Snow | c87621e | 2016-10-27 12:07:00 -0400 | [diff] [blame] | 122 | #endif |