2012-09-28 17:22:47 +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.
|
|
|
|
*/
|
2016-06-29 15:29:06 +02:00
|
|
|
|
2012-09-28 17:22:47 +02:00
|
|
|
#ifndef BLOCKJOB_H
|
2016-06-29 15:29:06 +02:00
|
|
|
#define BLOCKJOB_H
|
2012-09-28 17:22:47 +02:00
|
|
|
|
2018-04-12 17:29:59 +02:00
|
|
|
#include "qemu/job.h"
|
2012-12-17 18:19:44 +01:00
|
|
|
#include "block/block.h"
|
2018-01-18 20:20:24 +01:00
|
|
|
#include "qemu/ratelimit.h"
|
2012-09-28 17:22:47 +02:00
|
|
|
|
2018-01-18 20:25:40 +01:00
|
|
|
#define BLOCK_JOB_SLICE_TIME 100000000ULL /* ns */
|
|
|
|
|
2016-10-27 18:07:00 +02:00
|
|
|
typedef struct BlockJobDriver BlockJobDriver;
|
2012-09-28 17:22:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BlockJob:
|
|
|
|
*
|
|
|
|
* Long-running operation on a BlockDriverState.
|
|
|
|
*/
|
2016-10-27 18:07:00 +02:00
|
|
|
typedef struct BlockJob {
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* Data belonging to the generic Job infrastructure.
|
|
|
|
* Protected by job mutex.
|
|
|
|
*/
|
2018-04-12 17:29:59 +02:00
|
|
|
Job job;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* Status that is published by the query-block-jobs QMP API.
|
|
|
|
* Protected by job mutex.
|
|
|
|
*/
|
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 17:22:58 +02:00
|
|
|
BlockDeviceIoStatus iostatus;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* Speed that was set with @block_job_set_speed.
|
|
|
|
* Always modified and read under QEMU global mutex (GLOBAL_STATE_CODE).
|
|
|
|
*/
|
2012-09-28 17:22:47 +02:00
|
|
|
int64_t speed;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* Rate limiting data structure for implementing @speed.
|
|
|
|
* RateLimit API is thread-safe.
|
|
|
|
*/
|
2018-01-18 20:20:24 +01:00
|
|
|
RateLimit limit;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* Block other operations when block job is running.
|
|
|
|
* Always modified and read under QEMU global mutex (GLOBAL_STATE_CODE).
|
|
|
|
*/
|
2014-05-23 15:29:43 +02:00
|
|
|
Error *blocker;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/** All notifiers are set once in block_job_create() and never modified. */
|
|
|
|
|
2018-04-23 18:04:57 +02: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 14:56:09 +02:00
|
|
|
/** Called when the job transitions to READY */
|
|
|
|
Notifier ready_notifier;
|
|
|
|
|
2018-08-17 14:53:05 +02:00
|
|
|
/** Called when the job coroutine yields or terminates */
|
|
|
|
Notifier idle_notifier;
|
|
|
|
|
2022-09-26 11:32:07 +02:00
|
|
|
/**
|
|
|
|
* BlockDriverStates that are involved in this block job.
|
|
|
|
* Always modified and read under QEMU global mutex (GLOBAL_STATE_CODE).
|
|
|
|
*/
|
2016-10-28 09:08:04 +02:00
|
|
|
GSList *nodes;
|
2016-10-27 18:07:00 +02:00
|
|
|
} BlockJob;
|
2012-09-28 17:22:47 +02:00
|
|
|
|
2022-03-03 16:16:03 +01: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 15:43:51 +02:00
|
|
|
/**
|
2022-09-26 11:32:13 +02:00
|
|
|
* block_job_next_locked:
|
2016-04-04 15:43:51 +02:00
|
|
|
* @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.
|
2022-09-26 11:32:13 +02:00
|
|
|
* Called with job lock held.
|
2016-04-04 15:43:51 +02:00
|
|
|
*/
|
2022-09-26 11:32:00 +02:00
|
|
|
BlockJob *block_job_next_locked(BlockJob *job);
|
|
|
|
|
2016-07-05 16:28:54 +02: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.
|
2022-09-26 11:32:13 +02:00
|
|
|
* Called with job lock *not* held.
|
2016-07-05 16:28:54 +02:00
|
|
|
*/
|
|
|
|
BlockJob *block_job_get(const char *id);
|
|
|
|
|
2022-09-26 11:32:00 +02:00
|
|
|
/* Same as block_job_get(), but called with job lock held. */
|
|
|
|
BlockJob *block_job_get_locked(const char *id);
|
|
|
|
|
2016-10-28 09:08:04 +02:00
|
|
|
/**
|
|
|
|
* block_job_add_bdrv:
|
|
|
|
* @job: A block job
|
2017-01-17 11:56:42 +01:00
|
|
|
* @name: The name to assign to the new BdrvChild
|
2016-10-28 09:08:04 +02:00
|
|
|
* @bs: A BlockDriverState that is involved in @job
|
2017-01-17 11:56:42 +01:00
|
|
|
* @perm, @shared_perm: Permissions to request on the node
|
2016-10-28 09:08:04 +02: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 11:56:42 +01: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 09:08:04 +02:00
|
|
|
|
2017-02-28 12:45:58 +01: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 17:41:31 +02: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 17:22:47 +02:00
|
|
|
/**
|
2022-09-26 11:32:13 +02:00
|
|
|
* block_job_set_speed_locked:
|
2012-09-28 17:22:47 +02:00
|
|
|
* @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.
|
2022-09-26 11:32:13 +02:00
|
|
|
*
|
|
|
|
* Called with job lock held, but might release it temporarily.
|
2022-09-26 11:32:00 +02:00
|
|
|
*/
|
|
|
|
bool block_job_set_speed_locked(BlockJob *job, int64_t speed, Error **errp);
|
|
|
|
|
2012-09-28 17:22:48 +02:00
|
|
|
/**
|
2022-09-26 11:32:13 +02:00
|
|
|
* block_job_query_locked:
|
2012-09-28 17:22:48 +02:00
|
|
|
* @job: The job to get information about.
|
|
|
|
*
|
|
|
|
* Return information about a job.
|
2022-09-26 11:32:13 +02:00
|
|
|
*
|
|
|
|
* Called with job lock held.
|
2012-09-28 17:22:48 +02:00
|
|
|
*/
|
2022-09-26 11:32:00 +02:00
|
|
|
BlockJobInfo *block_job_query_locked(BlockJob *job, Error **errp);
|
|
|
|
|
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 17:22:58 +02:00
|
|
|
/**
|
2022-09-26 11:32:13 +02:00
|
|
|
* block_job_iostatus_reset_locked:
|
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 17:22:58 +02:00
|
|
|
* @job: The job whose I/O status should be reset.
|
|
|
|
*
|
2012-10-18 16:49:27 +02:00
|
|
|
* Reset I/O status on @job and on BlockDriverState objects it uses,
|
2016-05-30 11:28:11 +02:00
|
|
|
* other than job->blk.
|
2022-09-26 11:32:13 +02:00
|
|
|
*
|
|
|
|
* Called with job lock held.
|
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 17:22:58 +02:00
|
|
|
*/
|
2022-09-26 11:32:00 +02:00
|
|
|
void block_job_iostatus_reset_locked(BlockJob *job);
|
|
|
|
|
2022-03-03 16:16:03 +01: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 18:06:55 +02: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 15:54:40 +01:00
|
|
|
/**
|
|
|
|
* block_job_driver:
|
|
|
|
*
|
|
|
|
* Returns the driver associated with a block job.
|
|
|
|
*/
|
|
|
|
const BlockJobDriver *block_job_driver(BlockJob *job);
|
|
|
|
|
2012-09-28 17:22:47 +02:00
|
|
|
#endif
|