1c87621eaSJohn Snow /* 2c87621eaSJohn Snow * Declarations for long-running block device operations 3c87621eaSJohn Snow * 4c87621eaSJohn Snow * Copyright (c) 2011 IBM Corp. 5c87621eaSJohn Snow * Copyright (c) 2012 Red Hat, Inc. 6c87621eaSJohn Snow * 7c87621eaSJohn Snow * Permission is hereby granted, free of charge, to any person obtaining a copy 8c87621eaSJohn Snow * of this software and associated documentation files (the "Software"), to deal 9c87621eaSJohn Snow * in the Software without restriction, including without limitation the rights 10c87621eaSJohn Snow * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11c87621eaSJohn Snow * copies of the Software, and to permit persons to whom the Software is 12c87621eaSJohn Snow * furnished to do so, subject to the following conditions: 13c87621eaSJohn Snow * 14c87621eaSJohn Snow * The above copyright notice and this permission notice shall be included in 15c87621eaSJohn Snow * all copies or substantial portions of the Software. 16c87621eaSJohn Snow * 17c87621eaSJohn Snow * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18c87621eaSJohn Snow * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19c87621eaSJohn Snow * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20c87621eaSJohn Snow * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21c87621eaSJohn Snow * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22c87621eaSJohn Snow * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23c87621eaSJohn Snow * THE SOFTWARE. 24c87621eaSJohn Snow */ 25c87621eaSJohn Snow 26c87621eaSJohn Snow #ifndef BLOCKJOB_INT_H 27c87621eaSJohn Snow #define BLOCKJOB_INT_H 28c87621eaSJohn Snow 29c87621eaSJohn Snow #include "block/blockjob.h" 30c87621eaSJohn Snow 31c87621eaSJohn Snow /** 32c87621eaSJohn Snow * BlockJobDriver: 33c87621eaSJohn Snow * 34c87621eaSJohn Snow * A class type for block job driver. 35c87621eaSJohn Snow */ 36c87621eaSJohn Snow struct BlockJobDriver { 3733e9e9bdSKevin Wolf /** Generic JobDriver callbacks and settings */ 3833e9e9bdSKevin Wolf JobDriver job_driver; 39c87621eaSJohn Snow 40c87621eaSJohn Snow /* 412015c4c2SEmanuele Giuseppe Esposito * I/O API functions. These functions are thread-safe. 422015c4c2SEmanuele Giuseppe Esposito * 432015c4c2SEmanuele Giuseppe Esposito * See include/block/block-io.h for more information about 442015c4c2SEmanuele Giuseppe Esposito * the I/O API. 452015c4c2SEmanuele Giuseppe Esposito */ 462015c4c2SEmanuele Giuseppe Esposito 472015c4c2SEmanuele Giuseppe Esposito /* 4889bd0305SKevin Wolf * Returns whether the job has pending requests for the child or will 4989bd0305SKevin Wolf * submit new requests before the next pause point. This callback is polled 5089bd0305SKevin Wolf * in the context of draining a job node after requesting that the job be 5189bd0305SKevin Wolf * paused, until all activity on the child has stopped. 5289bd0305SKevin Wolf */ 5389bd0305SKevin Wolf bool (*drained_poll)(BlockJob *job); 5489bd0305SKevin Wolf 5589bd0305SKevin Wolf /* 562015c4c2SEmanuele Giuseppe Esposito * Global state (GS) API. These functions run under the BQL. 572015c4c2SEmanuele Giuseppe Esposito * 582015c4c2SEmanuele Giuseppe Esposito * See include/block/block-global-state.h for more information about 592015c4c2SEmanuele Giuseppe Esposito * the GS API. 602015c4c2SEmanuele Giuseppe Esposito */ 612015c4c2SEmanuele Giuseppe Esposito 622015c4c2SEmanuele Giuseppe Esposito /* 63c87621eaSJohn Snow * If the callback is not NULL, it will be invoked before the job is 64c87621eaSJohn Snow * resumed in a new AioContext. This is the place to move any resources 65c87621eaSJohn Snow * besides job->blk to the new AioContext. 66c87621eaSJohn Snow */ 67c87621eaSJohn Snow void (*attached_aio_context)(BlockJob *job, AioContext *new_context); 68e0323a04SVladimir Sementsov-Ogievskiy 69e0323a04SVladimir Sementsov-Ogievskiy void (*set_speed)(BlockJob *job, int64_t speed); 7061a3a5a7SFiona Ebner 7161a3a5a7SFiona Ebner /* 7261a3a5a7SFiona Ebner * Change the @job's options according to @opts. 7361a3a5a7SFiona Ebner * 7461a3a5a7SFiona Ebner * Note that this can already be called before the job coroutine is running. 7561a3a5a7SFiona Ebner */ 7661a3a5a7SFiona Ebner void (*change)(BlockJob *job, BlockJobChangeOptions *opts, Error **errp); 7759fd8254SFiona Ebner 7859fd8254SFiona Ebner /* 7959fd8254SFiona Ebner * Query information specific to this kind of block job. 8059fd8254SFiona Ebner */ 8159fd8254SFiona Ebner void (*query)(BlockJob *job, BlockJobInfo *info); 82c87621eaSJohn Snow }; 83c87621eaSJohn Snow 842015c4c2SEmanuele Giuseppe Esposito /* 852015c4c2SEmanuele Giuseppe Esposito * Global state (GS) API. These functions run under the BQL. 862015c4c2SEmanuele Giuseppe Esposito * 872015c4c2SEmanuele Giuseppe Esposito * See include/block/block-global-state.h for more information about 882015c4c2SEmanuele Giuseppe Esposito * the GS API. 892015c4c2SEmanuele Giuseppe Esposito */ 902015c4c2SEmanuele Giuseppe Esposito 91c87621eaSJohn Snow /** 92c87621eaSJohn Snow * block_job_create: 93c87621eaSJohn Snow * @job_id: The id of the newly-created job, or %NULL to have one 94c87621eaSJohn Snow * generated automatically. 9562bfdf0cSJohn Snow * @driver: The class object for the newly-created job. 9675859b94SJohn Snow * @txn: The transaction this job belongs to, if any. %NULL otherwise. 97c87621eaSJohn Snow * @bs: The block 98c6cc12bfSKevin Wolf * @perm, @shared_perm: Permissions to request for @bs 99c87621eaSJohn Snow * @speed: The maximum speed, in bytes per second, or 0 for unlimited. 100bb02b65cSKevin Wolf * @flags: Creation flags for the Block Job. See @JobCreateFlags. 101c87621eaSJohn Snow * @cb: Completion function for the job. 102c87621eaSJohn Snow * @opaque: Opaque pointer value passed to @cb. 103c87621eaSJohn Snow * @errp: Error object. 104c87621eaSJohn Snow * 105c87621eaSJohn Snow * Create a new long-running block device job and return it. The job 106c87621eaSJohn Snow * will call @cb asynchronously when the job completes. Note that 107c87621eaSJohn Snow * @bs may have been closed at the time the @cb it is called. If 108c87621eaSJohn Snow * this is the case, the job may be reported as either cancelled or 109c87621eaSJohn Snow * completed. 110c87621eaSJohn Snow * 111c87621eaSJohn Snow * This function is not part of the public job interface; it should be 112c87621eaSJohn Snow * called from a wrapper that is specific to the job type. 113c87621eaSJohn Snow */ 114*f3bbc53dSKevin Wolf void * GRAPH_UNLOCKED 115*f3bbc53dSKevin Wolf block_job_create(const char *job_id, const BlockJobDriver *driver, 11662c9e416SKevin Wolf JobTxn *txn, BlockDriverState *bs, uint64_t perm, 117c6cc12bfSKevin Wolf uint64_t shared_perm, int64_t speed, int flags, 118c87621eaSJohn Snow BlockCompletionFunc *cb, void *opaque, Error **errp); 119c87621eaSJohn Snow 120c87621eaSJohn Snow /** 12180fa2c75SKevin Wolf * block_job_free: 12280fa2c75SKevin Wolf * Callback to be used for JobDriver.free in all block jobs. Frees block job 12380fa2c75SKevin Wolf * specific resources in @job. 12480fa2c75SKevin Wolf */ 12580fa2c75SKevin Wolf void block_job_free(Job *job); 12680fa2c75SKevin Wolf 12780fa2c75SKevin Wolf /** 128b15de828SKevin Wolf * block_job_user_resume: 129b15de828SKevin Wolf * Callback to be used for JobDriver.user_resume in all block jobs. Resets the 130b15de828SKevin Wolf * iostatus when the user resumes @job. 131b15de828SKevin Wolf */ 132b15de828SKevin Wolf void block_job_user_resume(Job *job); 133b15de828SKevin Wolf 1342015c4c2SEmanuele Giuseppe Esposito /* 1352015c4c2SEmanuele Giuseppe Esposito * I/O API functions. These functions are thread-safe. 1362015c4c2SEmanuele Giuseppe Esposito * 1372015c4c2SEmanuele Giuseppe Esposito * See include/block/block-io.h for more information about 1382015c4c2SEmanuele Giuseppe Esposito * the I/O API. 1392015c4c2SEmanuele Giuseppe Esposito */ 1402015c4c2SEmanuele Giuseppe Esposito 141b15de828SKevin Wolf /** 142018e5987SKevin Wolf * block_job_ratelimit_processed_bytes: 143dee81d51SKevin Wolf * 144018e5987SKevin Wolf * To be called after some work has been done. Adjusts the delay for the next 145018e5987SKevin Wolf * request. See the documentation of ratelimit_calculate_delay() for details. 146dee81d51SKevin Wolf */ 147018e5987SKevin Wolf void block_job_ratelimit_processed_bytes(BlockJob *job, uint64_t n); 148018e5987SKevin Wolf 149018e5987SKevin Wolf /** 150018e5987SKevin Wolf * Put the job to sleep (assuming that it wasn't canceled) to throttle it to the 151018e5987SKevin Wolf * right speed according to its rate limiting. 152018e5987SKevin Wolf */ 153018e5987SKevin Wolf void block_job_ratelimit_sleep(BlockJob *job); 154dee81d51SKevin Wolf 155dee81d51SKevin Wolf /** 156c87621eaSJohn Snow * block_job_error_action: 157c87621eaSJohn Snow * @job: The job to signal an error for. 158c87621eaSJohn Snow * @on_err: The error action setting. 159c87621eaSJohn Snow * @is_read: Whether the operation was a read. 160c87621eaSJohn Snow * @error: The error that was reported. 161c87621eaSJohn Snow * 162c87621eaSJohn Snow * Report an I/O error for a block job and possibly stop the VM. Return the 163c87621eaSJohn Snow * action that was selected based on @on_err and @error. 164c87621eaSJohn Snow */ 165c87621eaSJohn Snow BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err, 166c87621eaSJohn Snow int is_read, int error); 167c87621eaSJohn Snow 168c87621eaSJohn Snow #endif 169