[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC v2 10/10] Fix some calls from coroutine_fn to no_coroutine_fn
From: |
Alberto Faria |
Subject: |
[RFC v2 10/10] Fix some calls from coroutine_fn to no_coroutine_fn |
Date: |
Fri, 29 Jul 2022 14:00:39 +0100 |
These calls were found by static-analyzer.py.
Not all occurrences of this problem were fixed.
Signed-off-by: Alberto Faria <afaria@redhat.com>
---
block/commit.c | 2 +-
block/io.c | 4 ++--
block/mirror.c | 4 ++--
block/parallels.c | 28 ++++++++++++++--------------
block/qcow.c | 10 +++++-----
block/qcow2-snapshot.c | 6 +++---
block/qcow2.c | 24 ++++++++++++------------
block/qed-table.c | 2 +-
block/qed.c | 12 ++++++------
block/vdi.c | 17 +++++++++--------
block/vhdx.c | 8 ++++----
block/vmdk.c | 11 ++++++-----
blockdev.c | 2 +-
13 files changed, 66 insertions(+), 64 deletions(-)
diff --git a/block/commit.c b/block/commit.c
index 38571510cb..945945de05 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -135,7 +135,7 @@ static int coroutine_fn commit_run(Job *job, Error **errp)
}
if (base_len < len) {
- ret = blk_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL);
+ ret = blk_co_truncate(s->base, len, false, PREALLOC_MODE_OFF, 0, NULL);
if (ret) {
return ret;
}
diff --git a/block/io.c b/block/io.c
index c2ed14cedb..a7d16eae02 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2736,8 +2736,8 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState
*bs, int64_t offset,
return 1;
}
- ret = bdrv_common_block_status_above(bs, NULL, false, false, offset,
- bytes, &pnum, NULL, NULL, NULL);
+ ret = bdrv_co_common_block_status_above(bs, NULL, false, false, offset,
+ bytes, &pnum, NULL, NULL, NULL);
if (ret < 0) {
return ret;
diff --git a/block/mirror.c b/block/mirror.c
index 3c4ab1159d..3cbb610118 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -921,8 +921,8 @@ static int coroutine_fn mirror_run(Job *job, Error **errp)
* active layer. */
if (s->base == blk_bs(s->target)) {
if (s->bdev_length > target_length) {
- ret = blk_truncate(s->target, s->bdev_length, false,
- PREALLOC_MODE_OFF, 0, NULL);
+ ret = blk_co_truncate(s->target, s->bdev_length, false,
+ PREALLOC_MODE_OFF, 0, NULL);
if (ret < 0) {
goto immediate_exit;
}
diff --git a/block/parallels.c b/block/parallels.c
index a229c06f25..46baea6387 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -204,18 +204,18 @@ static int64_t allocate_clusters(BlockDriverState *bs,
int64_t sector_num,
* force the safer-but-slower fallocate.
*/
if (s->prealloc_mode == PRL_PREALLOC_MODE_TRUNCATE) {
- ret = bdrv_truncate(bs->file,
- (s->data_end + space) << BDRV_SECTOR_BITS,
- false, PREALLOC_MODE_OFF, BDRV_REQ_ZERO_WRITE,
- NULL);
+ ret = bdrv_co_truncate(bs->file,
+ (s->data_end + space) << BDRV_SECTOR_BITS,
+ false, PREALLOC_MODE_OFF,
+ BDRV_REQ_ZERO_WRITE, NULL);
if (ret == -ENOTSUP) {
s->prealloc_mode = PRL_PREALLOC_MODE_FALLOCATE;
}
}
if (s->prealloc_mode == PRL_PREALLOC_MODE_FALLOCATE) {
- ret = bdrv_pwrite_zeroes(bs->file,
- s->data_end << BDRV_SECTOR_BITS,
- space << BDRV_SECTOR_BITS, 0);
+ ret = bdrv_co_pwrite_zeroes(bs->file,
+ s->data_end << BDRV_SECTOR_BITS,
+ space << BDRV_SECTOR_BITS, 0);
}
if (ret < 0) {
return ret;
@@ -277,8 +277,8 @@ static coroutine_fn int
parallels_co_flush_to_os(BlockDriverState *bs)
if (off + to_write > s->header_size) {
to_write = s->header_size - off;
}
- ret = bdrv_pwrite(bs->file, off, to_write, (uint8_t *)s->header + off,
- 0);
+ ret = bdrv_co_pwrite(bs->file, off, to_write,
+ (uint8_t *)s->header + off, 0);
if (ret < 0) {
qemu_co_mutex_unlock(&s->lock);
return ret;
@@ -503,8 +503,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState
*bs,
* In order to really repair the image, we must shrink it.
* That means we have to pass exact=true.
*/
- ret = bdrv_truncate(bs->file, res->image_end_offset, true,
- PREALLOC_MODE_OFF, 0, &local_err);
+ ret = bdrv_co_truncate(bs->file, res->image_end_offset, true,
+ PREALLOC_MODE_OFF, 0, &local_err);
if (ret < 0) {
error_report_err(local_err);
res->check_errors++;
@@ -599,12 +599,12 @@ static int coroutine_fn
parallels_co_create(BlockdevCreateOptions* opts,
memset(tmp, 0, sizeof(tmp));
memcpy(tmp, &header, sizeof(header));
- ret = blk_pwrite(blk, 0, BDRV_SECTOR_SIZE, tmp, 0);
+ ret = blk_co_pwrite(blk, 0, BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) {
goto exit;
}
- ret = blk_pwrite_zeroes(blk, BDRV_SECTOR_SIZE,
- (bat_sectors - 1) << BDRV_SECTOR_BITS, 0);
+ ret = blk_co_pwrite_zeroes(blk, BDRV_SECTOR_SIZE,
+ (bat_sectors - 1) << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
goto exit;
}
diff --git a/block/qcow.c b/block/qcow.c
index 311aaa8705..7dc29358ba 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -890,14 +890,14 @@ static int coroutine_fn
qcow_co_create(BlockdevCreateOptions *opts,
}
/* write all the data */
- ret = blk_pwrite(qcow_blk, 0, sizeof(header), &header, 0);
+ ret = blk_co_pwrite(qcow_blk, 0, sizeof(header), &header, 0);
if (ret < 0) {
goto exit;
}
if (qcow_opts->has_backing_file) {
- ret = blk_pwrite(qcow_blk, sizeof(header), backing_filename_len,
- qcow_opts->backing_file, 0);
+ ret = blk_co_pwrite(qcow_blk, sizeof(header), backing_filename_len,
+ qcow_opts->backing_file, 0);
if (ret < 0) {
goto exit;
}
@@ -906,8 +906,8 @@ static int coroutine_fn
qcow_co_create(BlockdevCreateOptions *opts,
tmp = g_malloc0(BDRV_SECTOR_SIZE);
for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE);
i++) {
- ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
- BDRV_SECTOR_SIZE, tmp, 0);
+ ret = blk_co_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
+ BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) {
g_free(tmp);
goto exit;
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index d1d46facbf..62e8a0335d 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -441,9 +441,9 @@ int coroutine_fn
qcow2_check_read_snapshot_table(BlockDriverState *bs,
} QEMU_PACKED snapshot_table_pointer;
/* qcow2_do_open() discards this information in check mode */
- ret = bdrv_pread(bs->file, offsetof(QCowHeader, nb_snapshots),
- sizeof(snapshot_table_pointer), &snapshot_table_pointer,
- 0);
+ ret = bdrv_co_pread(bs->file, offsetof(QCowHeader, nb_snapshots),
+ sizeof(snapshot_table_pointer),
&snapshot_table_pointer,
+ 0);
if (ret < 0) {
result->check_errors++;
fprintf(stderr, "ERROR failed to read the snapshot table pointer from "
diff --git a/block/qcow2.c b/block/qcow2.c
index d3dad0142e..524207fcfe 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1305,7 +1305,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
uint64_t l1_vm_state_index;
bool update_header = false;
- ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0);
+ ret = bdrv_co_pread(bs->file, 0, sizeof(header), &header, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read qcow2 header");
goto fail;
@@ -1381,9 +1381,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
if (header.header_length > sizeof(header)) {
s->unknown_header_fields_size = header.header_length - sizeof(header);
s->unknown_header_fields = g_malloc(s->unknown_header_fields_size);
- ret = bdrv_pread(bs->file, sizeof(header),
- s->unknown_header_fields_size,
- s->unknown_header_fields, 0);
+ ret = bdrv_co_pread(bs->file, sizeof(header),
+ s->unknown_header_fields_size,
+ s->unknown_header_fields, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read unknown qcow2 header "
"fields");
@@ -1578,8 +1578,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
ret = -ENOMEM;
goto fail;
}
- ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_size * L1E_SIZE,
- s->l1_table, 0);
+ ret = bdrv_co_pread(bs->file, s->l1_table_offset, s->l1_size *
L1E_SIZE,
+ s->l1_table, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read L1 table");
goto fail;
@@ -1696,8 +1696,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
ret = -EINVAL;
goto fail;
}
- ret = bdrv_pread(bs->file, header.backing_file_offset, len,
- bs->auto_backing_file, 0);
+ ret = bdrv_co_pread(bs->file, header.backing_file_offset, len,
+ bs->auto_backing_file, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read backing file name");
goto fail;
@@ -3666,7 +3666,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options,
Error **errp)
cpu_to_be64(QCOW2_INCOMPAT_EXTL2);
}
- ret = blk_pwrite(blk, 0, cluster_size, header, 0);
+ ret = blk_co_pwrite(blk, 0, cluster_size, header, 0);
g_free(header);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write qcow2 header");
@@ -3676,7 +3676,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options,
Error **errp)
/* Write a refcount table with one refcount block */
refcount_table = g_malloc0(2 * cluster_size);
refcount_table[0] = cpu_to_be64(2 * cluster_size);
- ret = blk_pwrite(blk, cluster_size, 2 * cluster_size, refcount_table, 0);
+ ret = blk_co_pwrite(blk, cluster_size, 2 * cluster_size, refcount_table,
0);
g_free(refcount_table);
if (ret < 0) {
@@ -3731,8 +3731,8 @@ qcow2_co_create(BlockdevCreateOptions *create_options,
Error **errp)
}
/* Okay, now that we have a valid image, let's give it the right size */
- ret = blk_truncate(blk, qcow2_opts->size, false, qcow2_opts->preallocation,
- 0, errp);
+ ret = blk_co_truncate(blk, qcow2_opts->size, false,
+ qcow2_opts->preallocation, 0, errp);
if (ret < 0) {
error_prepend(errp, "Could not resize image: ");
goto out;
diff --git a/block/qed-table.c b/block/qed-table.c
index 1cc844b1a5..aa203f2627 100644
--- a/block/qed-table.c
+++ b/block/qed-table.c
@@ -100,7 +100,7 @@ static int coroutine_fn qed_write_table(BDRVQEDState *s,
uint64_t offset,
}
if (flush) {
- ret = bdrv_flush(s->bs);
+ ret = bdrv_co_flush(s->bs);
if (ret < 0) {
goto out;
}
diff --git a/block/qed.c b/block/qed.c
index 9114cde42f..72e95852de 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -387,7 +387,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState
*bs, QDict *options,
int64_t file_size;
int ret;
- ret = bdrv_pread(bs->file, 0, sizeof(le_header), &le_header, 0);
+ ret = bdrv_co_pread(bs->file, 0, sizeof(le_header), &le_header, 0);
if (ret < 0) {
error_setg(errp, "Failed to read QED header");
return ret;
@@ -485,7 +485,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState
*bs, QDict *options,
}
/* From here on only known autoclear feature bits are valid */
- bdrv_flush(bs->file->bs);
+ bdrv_co_flush(bs->file->bs);
}
s->l1_table = qed_alloc_table(s);
@@ -686,7 +686,7 @@ static int coroutine_fn
bdrv_qed_co_create(BlockdevCreateOptions *opts,
* The QED format associates file length with allocation status,
* so a new file (which is empty) must have a length of 0.
*/
- ret = blk_truncate(blk, 0, true, PREALLOC_MODE_OFF, 0, errp);
+ ret = blk_co_truncate(blk, 0, true, PREALLOC_MODE_OFF, 0, errp);
if (ret < 0) {
goto out;
}
@@ -705,18 +705,18 @@ static int coroutine_fn
bdrv_qed_co_create(BlockdevCreateOptions *opts,
}
qed_header_cpu_to_le(&header, &le_header);
- ret = blk_pwrite(blk, 0, sizeof(le_header), &le_header, 0);
+ ret = blk_co_pwrite(blk, 0, sizeof(le_header), &le_header, 0);
if (ret < 0) {
goto out;
}
- ret = blk_pwrite(blk, sizeof(le_header), header.backing_filename_size,
+ ret = blk_co_pwrite(blk, sizeof(le_header), header.backing_filename_size,
qed_opts->backing_file, 0);
if (ret < 0) {
goto out;
}
l1_table = g_malloc0(l1_size);
- ret = blk_pwrite(blk, header.l1_table_offset, l1_size, l1_table, 0);
+ ret = blk_co_pwrite(blk, header.l1_table_offset, l1_size, l1_table, 0);
if (ret < 0) {
goto out;
}
diff --git a/block/vdi.c b/block/vdi.c
index e942325455..2ecf47216a 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -664,7 +664,8 @@ vdi_co_pwritev(BlockDriverState *bs, int64_t offset,
int64_t bytes,
* so this full-cluster write does not overlap a partial write
* of the same cluster, issued from the "else" branch.
*/
- ret = bdrv_pwrite(bs->file, data_offset, s->block_size, block, 0);
+ ret = bdrv_co_pwrite(bs->file, data_offset, s->block_size, block,
+ 0);
qemu_co_rwlock_unlock(&s->bmap_lock);
} else {
nonallocating_write:
@@ -709,7 +710,7 @@ nonallocating_write:
assert(VDI_IS_ALLOCATED(bmap_first));
*header = s->header;
vdi_header_to_le(header);
- ret = bdrv_pwrite(bs->file, 0, sizeof(*header), header, 0);
+ ret = bdrv_co_pwrite(bs->file, 0, sizeof(*header), header, 0);
g_free(header);
if (ret < 0) {
@@ -726,8 +727,8 @@ nonallocating_write:
base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
logout("will write %u block map sectors starting from entry %u\n",
n_sectors, bmap_first);
- ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE,
- n_sectors * SECTOR_SIZE, base, 0);
+ ret = bdrv_co_pwrite(bs->file, offset * SECTOR_SIZE,
+ n_sectors * SECTOR_SIZE, base, 0);
}
return ret;
@@ -845,7 +846,7 @@ static int coroutine_fn
vdi_co_do_create(BlockdevCreateOptions *create_options,
vdi_header_print(&header);
}
vdi_header_to_le(&header);
- ret = blk_pwrite(blk, offset, sizeof(header), &header, 0);
+ ret = blk_co_pwrite(blk, offset, sizeof(header), &header, 0);
if (ret < 0) {
error_setg(errp, "Error writing header");
goto exit;
@@ -866,7 +867,7 @@ static int coroutine_fn
vdi_co_do_create(BlockdevCreateOptions *create_options,
bmap[i] = VDI_UNALLOCATED;
}
}
- ret = blk_pwrite(blk, offset, bmap_size, bmap, 0);
+ ret = blk_co_pwrite(blk, offset, bmap_size, bmap, 0);
if (ret < 0) {
error_setg(errp, "Error writing bmap");
goto exit;
@@ -875,8 +876,8 @@ static int coroutine_fn
vdi_co_do_create(BlockdevCreateOptions *create_options,
}
if (image_type == VDI_TYPE_STATIC) {
- ret = blk_truncate(blk, offset + blocks * block_size, false,
- PREALLOC_MODE_OFF, 0, errp);
+ ret = blk_co_truncate(blk, offset + blocks * block_size, false,
+ PREALLOC_MODE_OFF, 0, errp);
if (ret < 0) {
error_prepend(errp, "Failed to statically allocate file");
goto exit;
diff --git a/block/vhdx.c b/block/vhdx.c
index e10e78ebfd..f7dd4eb092 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -2012,15 +2012,15 @@ static int coroutine_fn
vhdx_co_create(BlockdevCreateOptions *opts,
creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
&creator_items, NULL);
signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
- ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, sizeof(signature), &signature,
- 0);
+ ret = blk_co_pwrite(blk, VHDX_FILE_ID_OFFSET, sizeof(signature),
&signature,
+ 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write file signature");
goto delete_and_exit;
}
if (creator) {
- ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
- creator_items * sizeof(gunichar2), creator, 0);
+ ret = blk_co_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
+ creator_items * sizeof(gunichar2), creator, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write creator field");
goto delete_and_exit;
diff --git a/block/vmdk.c b/block/vmdk.c
index fe07a54866..d7886a52e1 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1897,7 +1897,8 @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t
cluster_offset,
cluster_buf = g_malloc(buf_bytes);
uncomp_buf = g_malloc(cluster_bytes);
BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED);
- ret = bdrv_pread(extent->file, cluster_offset, buf_bytes, cluster_buf, 0);
+ ret = bdrv_co_pread(extent->file, cluster_offset, buf_bytes, cluster_buf,
+ 0);
if (ret < 0) {
goto out;
}
@@ -2142,8 +2143,8 @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t
offset, int64_t bytes,
return length;
}
length = QEMU_ALIGN_UP(length, BDRV_SECTOR_SIZE);
- ret = bdrv_truncate(s->extents[i].file, length, false,
- PREALLOC_MODE_OFF, 0, NULL);
+ ret = bdrv_co_truncate(s->extents[i].file, length, false,
+ PREALLOC_MODE_OFF, 0, NULL);
if (ret < 0) {
return ret;
}
@@ -2584,7 +2585,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
desc_offset = 0x200;
}
- ret = blk_pwrite(blk, desc_offset, desc_len, desc, 0);
+ ret = blk_co_pwrite(blk, desc_offset, desc_len, desc, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write description");
goto exit;
@@ -2592,7 +2593,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
/* bdrv_pwrite write padding zeros to align to sector, we don't need that
* for description file */
if (desc_offset == 0) {
- ret = blk_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, 0, errp);
+ ret = blk_co_truncate(blk, desc_len, false, PREALLOC_MODE_OFF, 0,
errp);
if (ret < 0) {
goto exit;
}
diff --git a/blockdev.c b/blockdev.c
index 9230888e34..beeb51211a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2453,7 +2453,7 @@ void coroutine_fn qmp_block_resize(bool has_device, const
char *device,
bdrv_co_unlock(bs);
old_ctx = bdrv_co_enter(bs);
- blk_truncate(blk, size, false, PREALLOC_MODE_OFF, 0, errp);
+ blk_co_truncate(blk, size, false, PREALLOC_MODE_OFF, 0, errp);
bdrv_co_leave(bs, old_ctx);
bdrv_co_lock(bs);
--
2.37.1
- [RFC v2 00/10] Introduce an extensible static analyzer, Alberto Faria, 2022/07/29
- [RFC v2 01/10] Add an extensible static analyzer, Alberto Faria, 2022/07/29
- [RFC v2 02/10] Drop unused static function return values, Alberto Faria, 2022/07/29
- [RFC v2 03/10] static-analyzer: Support adding tests to checks, Alberto Faria, 2022/07/29
- [RFC v2 04/10] static-analyzer: Avoid reanalyzing unmodified translation units, Alberto Faria, 2022/07/29
- [RFC v2 05/10] static-analyzer: Enforce coroutine_fn restrictions for direct calls, Alberto Faria, 2022/07/29
- [RFC v2 06/10] Fix some direct calls from non-coroutine_fn to coroutine_fn, Alberto Faria, 2022/07/29
- [RFC v2 07/10] static-analyzer: Enforce coroutine_fn restrictions on function pointers, Alberto Faria, 2022/07/29
- [RFC v2 08/10] Fix some bad coroutine_fn indirect calls and pointer assignments, Alberto Faria, 2022/07/29
- [RFC v2 09/10] block: Add no_coroutine_fn marker, Alberto Faria, 2022/07/29
- [RFC v2 10/10] Fix some calls from coroutine_fn to no_coroutine_fn,
Alberto Faria <=