mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 17:53:56 -06:00
block: Mark bdrv_co_truncate() and callers GRAPH_RDLOCK
This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_truncate() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20230203152202.49054-4-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
32125b1460
commit
c2b8e31516
11 changed files with 44 additions and 28 deletions
|
@ -2372,6 +2372,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
IO_OR_GS_CODE();
|
IO_OR_GS_CODE();
|
||||||
|
GRAPH_RDLOCK_GUARD();
|
||||||
if (!blk_is_available(blk)) {
|
if (!blk_is_available(blk)) {
|
||||||
error_setg(errp, "No medium inserted");
|
error_setg(errp, "No medium inserted");
|
||||||
return -ENOMEDIUM;
|
return -ENOMEDIUM;
|
||||||
|
|
|
@ -359,7 +359,7 @@ block_crypto_co_create_generic(BlockDriverState *bs, int64_t size,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
||||||
PreallocMode prealloc, BdrvRequestFlags flags,
|
PreallocMode prealloc, BdrvRequestFlags flags,
|
||||||
Error **errp)
|
Error **errp)
|
||||||
|
|
|
@ -3380,6 +3380,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
||||||
int64_t old_size, new_bytes;
|
int64_t old_size, new_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
IO_CODE();
|
IO_CODE();
|
||||||
|
assert_bdrv_graph_readable();
|
||||||
|
|
||||||
/* if bs->drv == NULL, bs is closed, so there's nothing to do here */
|
/* if bs->drv == NULL, bs is closed, so there's nothing to do here */
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
|
|
|
@ -165,9 +165,9 @@ static int64_t block_status(BDRVParallelsState *s, int64_t sector_num,
|
||||||
return start_off;
|
return start_off;
|
||||||
}
|
}
|
||||||
|
|
||||||
static coroutine_fn int64_t allocate_clusters(BlockDriverState *bs,
|
static int64_t coroutine_fn GRAPH_RDLOCK
|
||||||
int64_t sector_num,
|
allocate_clusters(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors, int *pnum)
|
int nb_sectors, int *pnum)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
BDRVParallelsState *s = bs->opaque;
|
BDRVParallelsState *s = bs->opaque;
|
||||||
|
@ -329,6 +329,8 @@ static coroutine_fn int parallels_co_writev(BlockDriverState *bs,
|
||||||
QEMUIOVector hd_qiov;
|
QEMUIOVector hd_qiov;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
qemu_iovec_init(&hd_qiov, qiov->niov);
|
qemu_iovec_init(&hd_qiov, qiov->niov);
|
||||||
|
|
||||||
while (nb_sectors > 0) {
|
while (nb_sectors > 0) {
|
||||||
|
@ -414,9 +416,9 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int coroutine_fn parallels_co_check(BlockDriverState *bs,
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
BdrvCheckResult *res,
|
parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res,
|
||||||
BdrvCheckMode fix)
|
BdrvCheckMode fix)
|
||||||
{
|
{
|
||||||
BDRVParallelsState *s = bs->opaque;
|
BDRVParallelsState *s = bs->opaque;
|
||||||
int64_t size, prev_off, high_off;
|
int64_t size, prev_off, high_off;
|
||||||
|
|
|
@ -370,7 +370,7 @@ static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs,
|
||||||
flags);
|
flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
preallocate_co_truncate(BlockDriverState *bs, int64_t offset,
|
preallocate_co_truncate(BlockDriverState *bs, int64_t offset,
|
||||||
bool exact, PreallocMode prealloc,
|
bool exact, PreallocMode prealloc,
|
||||||
BdrvRequestFlags flags, Error **errp)
|
BdrvRequestFlags flags, Error **errp)
|
||||||
|
|
17
block/qcow.c
17
block/qcow.c
|
@ -350,11 +350,10 @@ static int qcow_reopen_prepare(BDRVReopenState *state,
|
||||||
* return 0 if not allocated, 1 if *result is assigned, and negative
|
* return 0 if not allocated, 1 if *result is assigned, and negative
|
||||||
* errno on failure.
|
* errno on failure.
|
||||||
*/
|
*/
|
||||||
static int coroutine_fn get_cluster_offset(BlockDriverState *bs,
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
uint64_t offset, int allocate,
|
get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate,
|
||||||
int compressed_size,
|
int compressed_size, int n_start, int n_end,
|
||||||
int n_start, int n_end,
|
uint64_t *result)
|
||||||
uint64_t *result)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int min_index, i, j, l1_index, l2_index, ret;
|
int min_index, i, j, l1_index, l2_index, ret;
|
||||||
|
@ -536,6 +535,8 @@ static int coroutine_fn qcow_co_block_status(BlockDriverState *bs,
|
||||||
int64_t n;
|
int64_t n;
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
qemu_co_mutex_lock(&s->lock);
|
qemu_co_mutex_lock(&s->lock);
|
||||||
ret = get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset);
|
ret = get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset);
|
||||||
qemu_co_mutex_unlock(&s->lock);
|
qemu_co_mutex_unlock(&s->lock);
|
||||||
|
@ -630,6 +631,8 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offset,
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
void *orig_buf;
|
void *orig_buf;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
if (qiov->niov > 1) {
|
if (qiov->niov > 1) {
|
||||||
buf = orig_buf = qemu_try_blockalign(bs, qiov->size);
|
buf = orig_buf = qemu_try_blockalign(bs, qiov->size);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
|
@ -726,6 +729,8 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offset,
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
void *orig_buf;
|
void *orig_buf;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
s->cluster_cache_offset = -1; /* disable compressed cache */
|
s->cluster_cache_offset = -1; /* disable compressed cache */
|
||||||
|
|
||||||
/* We must always copy the iov when encrypting, so we
|
/* We must always copy the iov when encrypting, so we
|
||||||
|
@ -1056,6 +1061,8 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
||||||
uint8_t *buf, *out_buf;
|
uint8_t *buf, *out_buf;
|
||||||
uint64_t cluster_offset;
|
uint64_t cluster_offset;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
buf = qemu_blockalign(bs, s->cluster_size);
|
buf = qemu_blockalign(bs, s->cluster_size);
|
||||||
if (bytes != s->cluster_size) {
|
if (bytes != s->cluster_size) {
|
||||||
if (bytes > s->cluster_size ||
|
if (bytes > s->cluster_size ||
|
||||||
|
|
|
@ -3183,9 +3183,9 @@ static int qcow2_set_up_encryption(BlockDriverState *bs,
|
||||||
*
|
*
|
||||||
* Returns: 0 on success, -errno on failure.
|
* Returns: 0 on success, -errno on failure.
|
||||||
*/
|
*/
|
||||||
static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offset,
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
uint64_t new_length, PreallocMode mode,
|
preallocate_co(BlockDriverState *bs, uint64_t offset, uint64_t new_length,
|
||||||
Error **errp)
|
PreallocMode mode, Error **errp)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
uint64_t bytes;
|
uint64_t bytes;
|
||||||
|
@ -4209,9 +4209,9 @@ fail:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
bool exact, PreallocMode prealloc,
|
qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
||||||
BdrvRequestFlags flags, Error **errp)
|
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
|
||||||
{
|
{
|
||||||
BDRVQcow2State *s = bs->opaque;
|
BDRVQcow2State *s = bs->opaque;
|
||||||
uint64_t old_length;
|
uint64_t old_length;
|
||||||
|
@ -4672,6 +4672,8 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs,
|
||||||
AioTaskPool *aio = NULL;
|
AioTaskPool *aio = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
if (has_data_file(bs)) {
|
if (has_data_file(bs)) {
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -384,9 +384,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offset,
|
static int coroutine_fn GRAPH_RDLOCK
|
||||||
bool exact, PreallocMode prealloc,
|
raw_co_truncate(BlockDriverState *bs, int64_t offset, bool exact,
|
||||||
BdrvRequestFlags flags, Error **errp)
|
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
|
||||||
{
|
{
|
||||||
BDRVRawState *s = bs->opaque;
|
BDRVRawState *s = bs->opaque;
|
||||||
|
|
||||||
|
|
|
@ -2130,6 +2130,8 @@ static int coroutine_fn
|
||||||
vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes,
|
||||||
QEMUIOVector *qiov)
|
QEMUIOVector *qiov)
|
||||||
{
|
{
|
||||||
|
assume_graph_lock(); /* FIXME */
|
||||||
|
|
||||||
if (bytes == 0) {
|
if (bytes == 0) {
|
||||||
/* The caller will write bytes 0 to signal EOF.
|
/* The caller will write bytes 0 to signal EOF.
|
||||||
* When receive it, we align EOF to a sector boundary. */
|
* When receive it, we align EOF to a sector boundary. */
|
||||||
|
|
|
@ -72,9 +72,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,
|
||||||
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
|
int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset,
|
||||||
int64_t bytes, BdrvRequestFlags flags);
|
int64_t bytes, BdrvRequestFlags flags);
|
||||||
|
|
||||||
int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
int coroutine_fn GRAPH_RDLOCK
|
||||||
PreallocMode prealloc, BdrvRequestFlags flags,
|
bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact,
|
||||||
Error **errp);
|
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
|
||||||
|
|
||||||
int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs);
|
int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs);
|
||||||
int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs);
|
int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs);
|
||||||
|
|
|
@ -677,9 +677,10 @@ struct BlockDriver {
|
||||||
* If @exact is true and this function fails but would succeed
|
* If @exact is true and this function fails but would succeed
|
||||||
* with @exact = false, it should return -ENOTSUP.
|
* with @exact = false, it should return -ENOTSUP.
|
||||||
*/
|
*/
|
||||||
int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t offset,
|
int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_truncate)(
|
||||||
bool exact, PreallocMode prealloc,
|
BlockDriverState *bs, int64_t offset, bool exact,
|
||||||
BdrvRequestFlags flags, Error **errp);
|
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
|
||||||
|
|
||||||
int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs);
|
int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs);
|
||||||
int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)(
|
int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)(
|
||||||
BlockDriverState *bs);
|
BlockDriverState *bs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue