2016-10-27 18:07:00 +02:00
|
|
|
/*
|
|
|
|
* Declarations for long-running block device operations
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 IBM Corp.
|
|
|
|
* Copyright (c) 2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLOCKJOB_INT_H
|
|
|
|
#define BLOCKJOB_INT_H
|
|
|
|
|
|
|
|
#include "block/blockjob.h"
|
|
|
|
#include "block/block.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BlockJobDriver:
|
|
|
|
*
|
|
|
|
* A class type for block job driver.
|
|
|
|
*/
|
|
|
|
struct BlockJobDriver {
|
2018-04-12 17:29:59 +02:00
|
|
|
/** Generic JobDriver callbacks and settings */
|
|
|
|
JobDriver job_driver;
|
2016-10-27 18:07:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Optional callback for job types whose completion must be triggered
|
|
|
|
* manually.
|
|
|
|
*/
|
|
|
|
void (*complete)(BlockJob *job, Error **errp);
|
|
|
|
|
2018-03-10 09:27:40 +01:00
|
|
|
/**
|
|
|
|
* If the callback is not NULL, prepare will be invoked when all the jobs
|
|
|
|
* belonging to the same transaction complete; or upon this job's completion
|
|
|
|
* if it is not in a transaction.
|
|
|
|
*
|
|
|
|
* This callback will not be invoked if the job has already failed.
|
|
|
|
* If it fails, abort and then clean will be called.
|
|
|
|
*/
|
|
|
|
int (*prepare)(BlockJob *job);
|
|
|
|
|
2016-10-27 18:07:00 +02:00
|
|
|
/**
|
|
|
|
* If the callback is not NULL, it will be invoked when all the jobs
|
|
|
|
* belonging to the same transaction complete; or upon this job's
|
|
|
|
* completion if it is not in a transaction. Skipped if NULL.
|
|
|
|
*
|
|
|
|
* All jobs will complete with a call to either .commit() or .abort() but
|
|
|
|
* never both.
|
|
|
|
*/
|
|
|
|
void (*commit)(BlockJob *job);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the callback is not NULL, it will be invoked when any job in the
|
|
|
|
* same transaction fails; or upon this job's failure (due to error or
|
|
|
|
* cancellation) if it is not in a transaction. Skipped if NULL.
|
|
|
|
*
|
|
|
|
* All jobs will complete with a call to either .commit() or .abort() but
|
|
|
|
* never both.
|
|
|
|
*/
|
|
|
|
void (*abort)(BlockJob *job);
|
|
|
|
|
blockjob: add .clean property
Cleaning up after we have deferred to the main thread but before the
transaction has converged can be dangerous and result in deadlocks
if the job cleanup invokes any BH polling loops.
A job may attempt to begin cleaning up, but may induce another job to
enter its cleanup routine. The second job, part of our same transaction,
will block waiting for the first job to finish, so neither job may now
make progress.
To rectify this, allow jobs to register a cleanup operation that will
always run regardless of if the job was in a transaction or not, and
if the transaction job group completed successfully or not.
Move sensitive cleanup to this callback instead which is guaranteed to
be run only after the transaction has converged, which removes sensitive
timing constraints from said cleanup.
Furthermore, in future patches these cleanup operations will be performed
regardless of whether or not we actually started the job. Therefore,
cleanup callbacks should essentially confine themselves to undoing create
operations, e.g. setup actions taken in what is now backup_start.
Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1478587839-9834-3-git-send-email-jsnow@redhat.com
Signed-off-by: Jeff Cody <jcody@redhat.com>
2016-11-08 07:50:35 +01:00
|
|
|
/**
|
|
|
|
* If the callback is not NULL, it will be invoked after a call to either
|
|
|
|
* .commit() or .abort(). Regardless of which callback is invoked after
|
|
|
|
* completion, .clean() will always be called, even if the job does not
|
|
|
|
* belong to a transaction group.
|
|
|
|
*/
|
|
|
|
void (*clean)(BlockJob *job);
|
|
|
|
|
2016-10-27 18:07:00 +02:00
|
|
|
/*
|
|
|
|
* If the callback is not NULL, it will be invoked before the job is
|
|
|
|
* resumed in a new AioContext. This is the place to move any resources
|
|
|
|
* besides job->blk to the new AioContext.
|
|
|
|
*/
|
|
|
|
void (*attached_aio_context)(BlockJob *job, AioContext *new_context);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the callback is not NULL, it will be invoked when the job has to be
|
|
|
|
* synchronously cancelled or completed; it should drain BlockDriverStates
|
|
|
|
* as required to ensure progress.
|
|
|
|
*/
|
|
|
|
void (*drain)(BlockJob *job);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* block_job_create:
|
|
|
|
* @job_id: The id of the newly-created job, or %NULL to have one
|
|
|
|
* generated automatically.
|
2018-03-10 09:27:28 +01:00
|
|
|
* @driver: The class object for the newly-created job.
|
2018-03-10 09:27:27 +01:00
|
|
|
* @txn: The transaction this job belongs to, if any. %NULL otherwise.
|
2016-10-27 18:07:00 +02:00
|
|
|
* @bs: The block
|
2017-01-16 17:18:09 +01:00
|
|
|
* @perm, @shared_perm: Permissions to request for @bs
|
2016-10-27 18:07:00 +02:00
|
|
|
* @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
2018-03-10 09:27:28 +01:00
|
|
|
* @flags: Creation flags for the Block Job.
|
|
|
|
* See @BlockJobCreateFlags
|
2016-10-27 18:07:00 +02:00
|
|
|
* @cb: Completion function for the job.
|
|
|
|
* @opaque: Opaque pointer value passed to @cb.
|
|
|
|
* @errp: Error object.
|
|
|
|
*
|
|
|
|
* Create a new long-running block device job and return it. The job
|
|
|
|
* will call @cb asynchronously when the job completes. Note that
|
|
|
|
* @bs may have been closed at the time the @cb it is called. If
|
|
|
|
* this is the case, the job may be reported as either cancelled or
|
|
|
|
* completed.
|
|
|
|
*
|
|
|
|
* This function is not part of the public job interface; it should be
|
|
|
|
* called from a wrapper that is specific to the job type.
|
|
|
|
*/
|
|
|
|
void *block_job_create(const char *job_id, const BlockJobDriver *driver,
|
2018-03-10 09:27:27 +01:00
|
|
|
BlockJobTxn *txn, BlockDriverState *bs, uint64_t perm,
|
2017-01-16 17:18:09 +01:00
|
|
|
uint64_t shared_perm, int64_t speed, int flags,
|
2016-10-27 18:07:00 +02:00
|
|
|
BlockCompletionFunc *cb, void *opaque, Error **errp);
|
|
|
|
|
2018-04-13 18:50:05 +02:00
|
|
|
/**
|
|
|
|
* block_job_free:
|
|
|
|
* Callback to be used for JobDriver.free in all block jobs. Frees block job
|
|
|
|
* specific resources in @job.
|
|
|
|
*/
|
|
|
|
void block_job_free(Job *job);
|
|
|
|
|
2016-10-27 18:07:00 +02:00
|
|
|
/**
|
|
|
|
* block_job_sleep_ns:
|
|
|
|
* @job: The job that calls the function.
|
|
|
|
* @ns: How many nanoseconds to stop for.
|
|
|
|
*
|
|
|
|
* Put the job to sleep (assuming that it wasn't canceled) for @ns
|
2017-11-29 11:25:13 +01:00
|
|
|
* %QEMU_CLOCK_REALTIME nanoseconds. Canceling the job will immediately
|
|
|
|
* interrupt the wait.
|
2016-10-27 18:07:00 +02:00
|
|
|
*/
|
2017-11-29 11:25:11 +01:00
|
|
|
void block_job_sleep_ns(BlockJob *job, int64_t ns);
|
2016-10-27 18:07:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* block_job_yield:
|
|
|
|
* @job: The job that calls the function.
|
|
|
|
*
|
|
|
|
* Yield the block job coroutine.
|
|
|
|
*/
|
|
|
|
void block_job_yield(BlockJob *job);
|
|
|
|
|
2018-01-18 21:19:38 +01:00
|
|
|
/**
|
|
|
|
* block_job_ratelimit_get_delay:
|
|
|
|
*
|
|
|
|
* Calculate and return delay for the next request in ns. See the documentation
|
|
|
|
* of ratelimit_calculate_delay() for details.
|
|
|
|
*/
|
|
|
|
int64_t block_job_ratelimit_get_delay(BlockJob *job, uint64_t n);
|
|
|
|
|
2016-10-27 18:07:00 +02:00
|
|
|
/**
|
2017-05-08 16:13:02 +02:00
|
|
|
* block_job_early_fail:
|
2016-10-27 18:07:00 +02:00
|
|
|
* @bs: The block device.
|
|
|
|
*
|
2017-05-08 16:13:02 +02:00
|
|
|
* The block job could not be started, free it.
|
2016-10-27 18:07:00 +02:00
|
|
|
*/
|
2017-05-08 16:13:02 +02:00
|
|
|
void block_job_early_fail(BlockJob *job);
|
2016-10-27 18:07:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* block_job_completed:
|
|
|
|
* @job: The job being completed.
|
|
|
|
* @ret: The status code.
|
|
|
|
*
|
|
|
|
* Call the completion function that was registered at creation time, and
|
|
|
|
* free @job.
|
|
|
|
*/
|
|
|
|
void block_job_completed(BlockJob *job, int ret);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* block_job_enter:
|
|
|
|
* @job: The job to enter.
|
|
|
|
*
|
|
|
|
* Continue the specified job by entering the coroutine.
|
|
|
|
*/
|
|
|
|
void block_job_enter(BlockJob *job);
|
|
|
|
|
|
|
|
/**
|
2016-10-27 18:07:01 +02:00
|
|
|
* block_job_event_ready:
|
|
|
|
* @job: The job which is now ready to be completed.
|
2016-10-27 18:07:00 +02:00
|
|
|
*
|
|
|
|
* Send a BLOCK_JOB_READY event for the specified job.
|
|
|
|
*/
|
|
|
|
void block_job_event_ready(BlockJob *job);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* block_job_error_action:
|
|
|
|
* @job: The job to signal an error for.
|
|
|
|
* @on_err: The error action setting.
|
|
|
|
* @is_read: Whether the operation was a read.
|
|
|
|
* @error: The error that was reported.
|
|
|
|
*
|
|
|
|
* Report an I/O error for a block job and possibly stop the VM. Return the
|
|
|
|
* action that was selected based on @on_err and @error.
|
|
|
|
*/
|
|
|
|
BlockErrorAction block_job_error_action(BlockJob *job, BlockdevOnError on_err,
|
|
|
|
int is_read, int error);
|
|
|
|
|
|
|
|
#endif
|