2012-09-28 19:22:47 +04: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.
|
|
|
|
*/
|
2016-06-29 16:29:06 +03:00
|
|
|
|
2012-09-28 19:22:47 +04:00
|
|
|
#ifndef BLOCKJOB_H
|
2016-06-29 16:29:06 +03:00
|
|
|
#define BLOCKJOB_H
|
2012-09-28 19:22:47 +04:00
|
|
|
|
2018-04-12 18:29:59 +03:00
|
|
|
#include "qemu/job.h"
|
2012-12-17 21:19:44 +04:00
|
|
|
#include "block/block.h"
|
2018-01-18 22:20:24 +03:00
|
|
|
#include "qemu/ratelimit.h"
|
2012-09-28 19:22:47 +04:00
|
|
|
|
2018-01-18 22:25:40 +03:00
|
|
|
#define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */
|
|
|
|
|
2016-10-27 19:07:00 +03:00
|
|
|
typedef struct BlockJobDriver BlockJobDriver;
|
2012-09-28 19:22:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BlockJob:
|
|
|
|
*
|
|
|
|
* Long-running operation on a BlockDriverState.
|
|
|
|
*/
|
2016-10-27 19:07:00 +03:00
|
|
|
typedef struct BlockJob {
|
2018-04-12 18:29:59 +03:00
|
|
|
/** Data belonging to the generic Job infrastructure */
|
|
|
|
Job job;
|
|
|
|
|
block: introduce block job error
The following behaviors are possible:
'report': The behavior is the same as in 1.1. An I/O error,
respectively during a read or a write, will complete the job immediately
with an error code.
'ignore': An I/O error, respectively during a read or a write, will be
ignored. For streaming, the job will complete with an error and the
backing file will be left in place. For mirroring, the sector will be
marked again as dirty and re-examined later.
'stop': The job will be paused and the job iostatus will be set to
failed or nospace, while the VM will keep running. This can only be
specified if the block device has rerror=stop and werror=stop or enospc.
'enospc': Behaves as 'stop' for ENOSPC errors, 'report' for others.
In all cases, even for 'report', the I/O error is reported as a QMP
event BLOCK_JOB_ERROR, with the same arguments as BLOCK_IO_ERROR.
It is possible that while stopping the VM a BLOCK_IO_ERROR event will be
reported and will clobber the event from BLOCK_JOB_ERROR, or vice versa.
This is not really avoidable since stopping the VM completes all pending
I/O requests. In fact, it is already possible now that a series of
BLOCK_IO_ERROR events are reported with rerror=stop, because vm_stop
calls bdrv_drain_all and this can generate further errors.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-09-28 19:22:58 +04:00
|
|
|
/** Status that is published by the query-block-jobs QMP API */
|
|
|
|
BlockDeviceIoStatus iostatus;
|
|
|
|
|
2012-09-28 19:22:47 +04:00
|
|
|
/** Speed that was set with @block_job_set_speed. */
|
|
|
|
int64_t speed;
|
|
|
|
|
2018-01-18 22:20:24 +03:00
|
|
|
/** Rate limiting data structure for implementing @speed. */
|
|
|
|
RateLimit limit;
|
|
|
|
|
2014-05-23 17:29:43 +04:00
|
|
|
/** Block other operations when block job is running */
|
|
|
|
Error *blocker;
|
|
|
|
|
2018-04-23 19:04:57 +03:00
|
|
|
/** Called when a cancelled job is finalised. */
|
|
|
|
Notifier finalize_cancelled_notifier;
|
|
|
|
|
|
|
|
/** Called when a successfully completed job is finalised. */
|
|
|
|
Notifier finalize_completed_notifier;
|
|
|
|
|
|
|
|
/** Called when the job transitions to PENDING */
|
|
|
|
Notifier pending_notifier;
|
|
|
|
|
2018-04-25 15:56:09 +03:00
|
|
|
/** Called when the job transitions to READY */
|
|
|
|
Notifier ready_notifier;
|
|
|
|
|
2018-08-17 15:53:05 +03:00
|
|
|
/** Called when the job coroutine yields or terminates */
|
|
|
|
Notifier idle_notifier;
|
|
|
|
|
2016-10-28 10:08:04 +03:00
|
|
|
/** BlockDriverStates that are involved in this block job */
|
|
|
|
GSList *nodes;
|
2016-10-27 19:07:00 +03:00
|
|
|
} BlockJob;
|
2012-09-28 19:22:47 +04:00
|
|
|
|
2022-03-03 18:16:03 +03:00
|
|
|
/*
|
|
|
|
* Global state (GS) API. These functions run under the BQL.
|
|
|
|
*
|
|
|
|
* See include/block/block-global-state.h for more information about
|
|
|
|
* the GS API.
|
|
|
|
*/
|
|
|
|
|
2016-04-04 16:43:51 +03:00
|
|
|
/**
|
|
|
|
* block_job_next:
|
|
|
|
* @job: A block job, or %NULL.
|
|
|
|
*
|
|
|
|
* Get the next element from the list of block jobs after @job, or the
|
|
|
|
* first one if @job is %NULL.
|
|
|
|
*
|
|
|
|
* Returns the requested job, or %NULL if there are no more jobs left.
|
|
|
|
*/
|
|
|
|
BlockJob *block_job_next(BlockJob *job);
|
|
|
|
|
2016-07-05 17:28:54 +03:00
|
|
|
/**
|
|
|
|
* block_job_get:
|
|
|
|
* @id: The id of the block job.
|
|
|
|
*
|
|
|
|
* Get the block job identified by @id (which must not be %NULL).
|
|
|
|
*
|
|
|
|
* Returns the requested job, or %NULL if it doesn't exist.
|
|
|
|
*/
|
|
|
|
BlockJob *block_job_get(const char *id);
|
|
|
|
|
2016-10-28 10:08:04 +03:00
|
|
|
/**
|
|
|
|
* block_job_add_bdrv:
|
|
|
|
* @job: A block job
|
2017-01-17 13:56:42 +03:00
|
|
|
* @name: The name to assign to the new BdrvChild
|
2016-10-28 10:08:04 +03:00
|
|
|
* @bs: A BlockDriverState that is involved in @job
|
2017-01-17 13:56:42 +03:00
|
|
|
* @perm, @shared_perm: Permissions to request on the node
|
2016-10-28 10:08:04 +03:00
|
|
|
*
|
|
|
|
* Add @bs to the list of BlockDriverState that are involved in
|
|
|
|
* @job. This means that all operations will be blocked on @bs while
|
|
|
|
* @job exists.
|
|
|
|
*/
|
2017-01-17 13:56:42 +03:00
|
|
|
int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
|
|
|
|
uint64_t perm, uint64_t shared_perm, Error **errp);
|
2016-10-28 10:08:04 +03:00
|
|
|
|
2017-02-28 14:45:58 +03:00
|
|
|
/**
|
|
|
|
* block_job_remove_all_bdrv:
|
|
|
|
* @job: The block job
|
|
|
|
*
|
|
|
|
* Remove all BlockDriverStates from the list of nodes that are involved in the
|
|
|
|
* job. This removes the blockers added with block_job_add_bdrv().
|
|
|
|
*/
|
|
|
|
void block_job_remove_all_bdrv(BlockJob *job);
|
|
|
|
|
2019-06-06 18:41:31 +03:00
|
|
|
/**
|
|
|
|
* block_job_has_bdrv:
|
|
|
|
* @job: The block job
|
|
|
|
*
|
|
|
|
* Searches for @bs in the list of nodes that are involved in the
|
|
|
|
* job.
|
|
|
|
*/
|
|
|
|
bool block_job_has_bdrv(BlockJob *job, BlockDriverState *bs);
|
|
|
|
|
2012-09-28 19:22:47 +04:00
|
|
|
/**
|
|
|
|
* block_job_set_speed:
|
|
|
|
* @job: The job to set the speed for.
|
|
|
|
* @speed: The new value
|
|
|
|
* @errp: Error object.
|
|
|
|
*
|
|
|
|
* Set a rate-limiting parameter for the job; the actual meaning may
|
|
|
|
* vary depending on the job type.
|
|
|
|
*/
|
2021-02-02 15:49:49 +03:00
|
|
|
bool block_job_set_speed(BlockJob *job, int64_t speed, Error **errp);
|
2012-09-28 19:22:47 +04:00
|
|
|
|
2012-09-28 19:22:48 +04:00
|
|
|
/**
|
|
|
|
* block_job_query:
|
|
|
|
* @job: The job to get information about.
|
|
|
|
*
|
|
|
|
* Return information about a job.
|
|
|
|
*/
|
2016-10-27 19:06:55 +03:00
|
|
|
BlockJobInfo *block_job_query(BlockJob *job, Error **errp);
|
2012-09-28 19:22:48 +04:00
|
|
|
|
block: introduce block job error
The following behaviors are possible:
'report': The behavior is the same as in 1.1. An I/O error,
respectively during a read or a write, will complete the job immediately
with an error code.
'ignore': An I/O error, respectively during a read or a write, will be
ignored. For streaming, the job will complete with an error and the
backing file will be left in place. For mirroring, the sector will be
marked again as dirty and re-examined later.
'stop': The job will be paused and the job iostatus will be set to
failed or nospace, while the VM will keep running. This can only be
specified if the block device has rerror=stop and werror=stop or enospc.
'enospc': Behaves as 'stop' for ENOSPC errors, 'report' for others.
In all cases, even for 'report', the I/O error is reported as a QMP
event BLOCK_JOB_ERROR, with the same arguments as BLOCK_IO_ERROR.
It is possible that while stopping the VM a BLOCK_IO_ERROR event will be
reported and will clobber the event from BLOCK_JOB_ERROR, or vice versa.
This is not really avoidable since stopping the VM completes all pending
I/O requests. In fact, it is already possible now that a series of
BLOCK_IO_ERROR events are reported with rerror=stop, because vm_stop
calls bdrv_drain_all and this can generate further errors.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-09-28 19:22:58 +04:00
|
|
|
/**
|
|
|
|
* block_job_iostatus_reset:
|
|
|
|
* @job: The job whose I/O status should be reset.
|
|
|
|
*
|
2012-10-18 18:49:27 +04:00
|
|
|
* Reset I/O status on @job and on BlockDriverState objects it uses,
|
2016-05-30 12:28:11 +03:00
|
|
|
* other than job->blk.
|
block: introduce block job error
The following behaviors are possible:
'report': The behavior is the same as in 1.1. An I/O error,
respectively during a read or a write, will complete the job immediately
with an error code.
'ignore': An I/O error, respectively during a read or a write, will be
ignored. For streaming, the job will complete with an error and the
backing file will be left in place. For mirroring, the sector will be
marked again as dirty and re-examined later.
'stop': The job will be paused and the job iostatus will be set to
failed or nospace, while the VM will keep running. This can only be
specified if the block device has rerror=stop and werror=stop or enospc.
'enospc': Behaves as 'stop' for ENOSPC errors, 'report' for others.
In all cases, even for 'report', the I/O error is reported as a QMP
event BLOCK_JOB_ERROR, with the same arguments as BLOCK_IO_ERROR.
It is possible that while stopping the VM a BLOCK_IO_ERROR event will be
reported and will clobber the event from BLOCK_JOB_ERROR, or vice versa.
This is not really avoidable since stopping the VM completes all pending
I/O requests. In fact, it is already possible now that a series of
BLOCK_IO_ERROR events are reported with rerror=stop, because vm_stop
calls bdrv_drain_all and this can generate further errors.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-09-28 19:22:58 +04:00
|
|
|
*/
|
|
|
|
void block_job_iostatus_reset(BlockJob *job);
|
|
|
|
|
2022-03-03 18:16:03 +03:00
|
|
|
/*
|
|
|
|
* block_job_get_aio_context:
|
|
|
|
*
|
|
|
|
* Returns aio context associated with a block job.
|
|
|
|
*/
|
|
|
|
AioContext *block_job_get_aio_context(BlockJob *job);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common functions that are neither I/O nor Global State.
|
|
|
|
*
|
|
|
|
* See include/block/block-common.h for more information about
|
|
|
|
* the Common API.
|
|
|
|
*/
|
|
|
|
|
2016-10-27 19:06:55 +03:00
|
|
|
/**
|
|
|
|
* block_job_is_internal:
|
|
|
|
* @job: The job to determine if it is user-visible or not.
|
|
|
|
*
|
|
|
|
* Returns true if the job should not be visible to the management layer.
|
|
|
|
*/
|
|
|
|
bool block_job_is_internal(BlockJob *job);
|
|
|
|
|
2018-01-19 17:54:40 +03:00
|
|
|
/**
|
|
|
|
* block_job_driver:
|
|
|
|
*
|
|
|
|
* Returns the driver associated with a block job.
|
|
|
|
*/
|
|
|
|
const BlockJobDriver *block_job_driver(BlockJob *job);
|
|
|
|
|
2012-09-28 19:22:47 +04:00
|
|
|
#endif
|