From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
To: qemu-block@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Juan Quintela" <quintela@redhat.com>,
qemu-devel@nongnu.org, "John Snow" <jsnow@redhat.com>,
"Emanuele Giuseppe Esposito" <eesposit@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [PATCH v5 13/31] block.c: add assertions to static functions
Date: Wed, 24 Nov 2021 01:44:00 -0500 [thread overview]
Message-ID: <20211124064418.3120601-14-eesposit@redhat.com> (raw)
In-Reply-To: <20211124064418.3120601-1-eesposit@redhat.com>
Following the assertion derived from the API split,
propagate the assertion also in the static functions.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
block.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 5516c84ec4..b77ab0a104 100644
--- a/block.c
+++ b/block.c
@@ -434,6 +434,7 @@ BlockDriverState *bdrv_new(void)
static BlockDriver *bdrv_do_find_format(const char *format_name)
{
BlockDriver *drv1;
+ assert(qemu_in_main_thread());
QLIST_FOREACH(drv1, &bdrv_drivers, list) {
if (!strcmp(drv1->format_name, format_name)) {
@@ -593,6 +594,8 @@ static int64_t create_file_fallback_truncate(BlockBackend *blk,
int64_t size;
int ret;
+ assert(qemu_in_main_thread());
+
ret = blk_truncate(blk, minimum_size, false, PREALLOC_MODE_OFF, 0,
&local_err);
if (ret < 0 && ret != -ENOTSUP) {
@@ -631,6 +634,8 @@ static int create_file_fallback_zero_first_sector(BlockBackend *blk,
int64_t bytes_to_clear;
int ret;
+ assert(qemu_in_main_thread());
+
bytes_to_clear = MIN(current_size, BDRV_SECTOR_SIZE);
if (bytes_to_clear) {
ret = blk_pwrite_zeroes(blk, 0, bytes_to_clear, BDRV_REQ_MAY_UNMAP);
@@ -891,6 +896,7 @@ static BlockDriver *find_hdev_driver(const char *filename)
{
int score_max = 0, score;
BlockDriver *drv = NULL, *d;
+ assert(qemu_in_main_thread());
QLIST_FOREACH(d, &bdrv_drivers, list) {
if (d->bdrv_probe_device) {
@@ -908,6 +914,7 @@ static BlockDriver *find_hdev_driver(const char *filename)
static BlockDriver *bdrv_do_find_protocol(const char *protocol)
{
BlockDriver *drv1;
+ assert(qemu_in_main_thread());
QLIST_FOREACH(drv1, &bdrv_drivers, list) {
if (drv1->protocol_name && !strcmp(drv1->protocol_name, protocol)) {
@@ -1016,6 +1023,8 @@ static int find_image_format(BlockBackend *file, const char *filename,
uint8_t buf[BLOCK_PROBE_BUF_SIZE];
int ret = 0;
+ assert(qemu_in_main_thread());
+
/* Return the raw BlockDriver * to scsi-generic devices or empty drives */
if (blk_is_sg(file) || !blk_is_inserted(file) || blk_getlength(file) == 0) {
*pdrv = &bdrv_raw;
@@ -1097,6 +1106,7 @@ static BlockdevDetectZeroesOptions bdrv_parse_detect_zeroes(QemuOpts *opts,
BlockdevDetectZeroesOptions detect_zeroes =
qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, value,
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err);
+ assert(qemu_in_main_thread());
g_free(value);
if (local_err) {
error_propagate(errp, local_err);
@@ -1214,6 +1224,7 @@ static void bdrv_child_cb_drained_end(BdrvChild *child,
static int bdrv_child_cb_inactivate(BdrvChild *child)
{
BlockDriverState *bs = child->opaque;
+ assert(qemu_in_main_thread());
assert(bs->open_flags & BDRV_O_INACTIVE);
return 0;
}
@@ -1241,6 +1252,7 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
int parent_flags, QDict *parent_options)
{
*child_flags = (parent_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY;
+ assert(qemu_in_main_thread());
/* For temporary files, unconditional cache=unsafe is fine */
qdict_set_default_str(child_options, BDRV_OPT_CACHE_DIRECT, "off");
@@ -1260,6 +1272,7 @@ static void bdrv_backing_attach(BdrvChild *c)
BlockDriverState *parent = c->opaque;
BlockDriverState *backing_hd = c->bs;
+ assert(qemu_in_main_thread());
assert(!parent->backing_blocker);
error_setg(&parent->backing_blocker,
"node is used as backing hd of '%s'",
@@ -1298,6 +1311,7 @@ static void bdrv_backing_detach(BdrvChild *c)
{
BlockDriverState *parent = c->opaque;
+ assert(qemu_in_main_thread());
assert(parent->backing_blocker);
bdrv_op_unblock_all(c->bs, parent->backing_blocker);
error_free(parent->backing_blocker);
@@ -1310,6 +1324,7 @@ static int bdrv_backing_update_filename(BdrvChild *c, BlockDriverState *base,
BlockDriverState *parent = c->opaque;
bool read_only = bdrv_is_read_only(parent);
int ret;
+ assert(qemu_in_main_thread());
if (read_only) {
ret = bdrv_reopen_set_read_only(parent, false, errp);
@@ -1341,6 +1356,7 @@ static void bdrv_inherited_options(BdrvChildRole role, bool parent_is_format,
int parent_flags, QDict *parent_options)
{
int flags = parent_flags;
+ assert(qemu_in_main_thread());
/*
* First, decide whether to set, clear, or leave BDRV_O_PROTOCOL.
@@ -1479,6 +1495,7 @@ AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c)
static int bdrv_open_flags(BlockDriverState *bs, int flags)
{
int open_flags = flags;
+ assert(qemu_in_main_thread());
/*
* Clear flags that are internal to the block layer before opening the
@@ -1491,6 +1508,8 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
static void update_flags_from_options(int *flags, QemuOpts *opts)
{
+ assert(qemu_in_main_thread());
+
*flags &= ~(BDRV_O_CACHE_MASK | BDRV_O_RDWR | BDRV_O_AUTO_RDONLY);
if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
@@ -1512,6 +1531,7 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
static void update_options_from_flags(QDict *options, int flags)
{
+ assert(qemu_in_main_thread());
if (!qdict_haskey(options, BDRV_OPT_CACHE_DIRECT)) {
qdict_put_bool(options, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE);
}
@@ -1533,6 +1553,7 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
Error **errp)
{
char *gen_node_name = NULL;
+ assert(qemu_in_main_thread());
if (!node_name) {
node_name = gen_node_name = id_generate(ID_BLOCK);
@@ -1779,6 +1800,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
assert(bs->file == NULL);
assert(options != NULL && bs->options != options);
+ assert(qemu_in_main_thread());
opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
if (!qemu_opts_absorb_qdict(opts, options, errp)) {
@@ -1904,6 +1926,7 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
QObject *options_obj;
QDict *options;
int ret;
+ assert(qemu_in_main_thread());
ret = strstart(filename, "json:", &filename);
assert(ret);
@@ -1931,6 +1954,7 @@ static void parse_json_protocol(QDict *options, const char **pfilename,
{
QDict *json_options;
Error *local_err = NULL;
+ assert(qemu_in_main_thread());
/* Parse json: pseudo-protocol */
if (!*pfilename || !g_str_has_prefix(*pfilename, "json:")) {
@@ -2184,6 +2208,8 @@ static GSList *bdrv_topological_dfs(GSList *list, GHashTable *found,
BdrvChild *child;
g_autoptr(GHashTable) local_found = NULL;
+ assert(qemu_in_main_thread());
+
if (!found) {
assert(!list);
found = local_found = g_hash_table_new(NULL, NULL);
@@ -2295,6 +2321,7 @@ typedef struct BdrvReplaceChildState {
static void bdrv_replace_child_commit(void *opaque)
{
BdrvReplaceChildState *s = opaque;
+ assert(qemu_in_main_thread());
if (s->free_empty_child && !s->child->bs) {
bdrv_child_free(s->child);
@@ -2307,6 +2334,7 @@ static void bdrv_replace_child_abort(void *opaque)
BdrvReplaceChildState *s = opaque;
BlockDriverState *new_bs = s->child->bs;
+ assert(qemu_in_main_thread());
/*
* old_bs reference is transparently moved from @s to s->child.
*
@@ -2872,6 +2900,7 @@ static void bdrv_replace_child_noperm(BdrvChild **childp,
static void bdrv_child_free(BdrvChild *child)
{
assert(!child->bs);
+ assert(qemu_in_main_thread());
assert(!child->next.le_prev); /* not in children list */
g_free(child->name);
@@ -2952,6 +2981,7 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs,
assert(child);
assert(*child == NULL);
assert(child_class->get_parent_desc);
+ assert(qemu_in_main_thread());
new_child = g_new(BdrvChild, 1);
*new_child = (BdrvChild) {
@@ -3032,6 +3062,7 @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
uint64_t perm, shared_perm;
assert(parent_bs->drv);
+ assert(qemu_in_main_thread());
if (bdrv_recurse_has_child(child_bs, parent_bs)) {
error_setg(errp, "Making '%s' a %s child of '%s' would create a cycle",
@@ -3057,6 +3088,7 @@ static void bdrv_detach_child(BdrvChild **childp)
{
BlockDriverState *old_bs = (*childp)->bs;
+ assert(qemu_in_main_thread());
bdrv_replace_child_noperm(childp, NULL, true);
if (old_bs) {
@@ -3305,6 +3337,8 @@ static int bdrv_set_file_or_backing_noperm(BlockDriverState *parent_bs,
BdrvChild *child = is_backing ? parent_bs->backing : parent_bs->file;
BdrvChildRole role;
+ assert(qemu_in_main_thread());
+
if (!parent_bs->drv) {
/*
* Node without drv is an object without a class :/. TODO: finally fix
@@ -3384,6 +3418,7 @@ static int bdrv_set_backing_noperm(BlockDriverState *bs,
BlockDriverState *backing_hd,
Transaction *tran, Error **errp)
{
+ assert(qemu_in_main_thread());
return bdrv_set_file_or_backing_noperm(bs, backing_hd, true, tran, errp);
}
@@ -3659,6 +3694,8 @@ static BlockDriverState *bdrv_append_temp_snapshot(BlockDriverState *bs,
BlockDriverState *bs_snapshot = NULL;
int ret;
+ assert(qemu_in_main_thread());
+
/* if snapshot, we create a temporary backing file and open it
instead of opening 'filename' directly */
@@ -4485,6 +4522,8 @@ static int bdrv_reopen_parse_file_or_backing(BDRVReopenState *reopen_state,
QObject *value;
const char *str;
+ assert(qemu_in_main_thread());
+
value = qdict_get(reopen_state->options, child_name);
if (value == NULL) {
return 0;
@@ -5024,7 +5063,7 @@ static void bdrv_remove_filter_or_cow_child_abort(void *opaque)
static void bdrv_remove_filter_or_cow_child_commit(void *opaque)
{
BdrvRemoveFilterOrCowChild *s = opaque;
-
+ assert(qemu_in_main_thread());
bdrv_child_free(s->child);
}
@@ -5157,6 +5196,7 @@ static int bdrv_replace_node_common(BlockDriverState *from,
BlockDriverState *to_cow_parent = NULL;
int ret;
+ assert(qemu_in_main_thread());
assert(to != NULL);
if (detach_subchain) {
@@ -5315,6 +5355,7 @@ static void bdrv_delete(BlockDriverState *bs)
{
assert(bdrv_op_blocker_is_empty(bs));
assert(!bs->refcnt);
+ assert(qemu_in_main_thread());
/* remove from list, if necessary */
if (bs->node_name[0] != '\0') {
@@ -6318,6 +6359,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event)
static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs)
{
+ assert(qemu_in_main_thread());
while (bs && bs->drv && !bs->drv->bdrv_debug_breakpoint) {
bs = bdrv_primary_bs(bs);
}
@@ -7128,6 +7170,7 @@ void bdrv_coroutine_enter(BlockDriverState *bs, Coroutine *co)
static void bdrv_do_remove_aio_context_notifier(BdrvAioNotifier *ban)
{
+ assert(qemu_in_main_thread());
QLIST_REMOVE(ban, list);
g_free(ban);
}
--
2.27.0
next prev parent reply other threads:[~2021-11-24 7:08 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 6:43 [PATCH v5 00/31] block layer: split block APIs in global state and I/O Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 01/31] main-loop.h: introduce qemu_in_main_thread() Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 02/31] include/block/block: split header into I/O and global state API Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 03/31] assertions for block " Emanuele Giuseppe Esposito
2021-12-16 15:17 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 04/31] include/sysemu/block-backend: split header into I/O and global state (GS) API Emanuele Giuseppe Esposito
2021-12-10 14:21 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 05/31] block-backend: special comments for blk_set/get_perm due to fuse Emanuele Giuseppe Esposito
2021-12-10 14:38 ` Hanna Reitz
2021-12-15 8:57 ` Emanuele Giuseppe Esposito
2021-12-15 10:13 ` Emanuele Giuseppe Esposito
2021-12-16 14:00 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 06/31] block/block-backend.c: assertions for block-backend Emanuele Giuseppe Esposito
2021-12-10 15:37 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 07/31] include/block/block_int: split header into I/O and global state API Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 08/31] assertions for block_int " Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 09/31] block: introduce assert_bdrv_graph_writable Emanuele Giuseppe Esposito
2021-12-10 17:43 ` Hanna Reitz
2021-12-14 19:48 ` Emanuele Giuseppe Esposito
2021-12-16 14:01 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 10/31] block.c: modify .attach and .detach callbacks of child_of_bds Emanuele Giuseppe Esposito
2021-12-16 14:57 ` Hanna Reitz
2021-12-16 16:05 ` Emanuele Giuseppe Esposito
2021-12-16 16:12 ` Hanna Reitz
2021-11-24 6:43 ` [PATCH v5 11/31] include/block/blockjob_int.h: split header into I/O and GS API Emanuele Giuseppe Esposito
2021-11-24 6:43 ` [PATCH v5 12/31] assertions for blockjob_int.h Emanuele Giuseppe Esposito
2021-11-24 6:44 ` Emanuele Giuseppe Esposito [this message]
2021-12-16 16:08 ` [PATCH v5 13/31] block.c: add assertions to static functions Hanna Reitz
2021-12-16 16:39 ` Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 14/31] include/block/blockjob.h: global state API Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 15/31] assertions for blockjob.h " Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 16/31] include/sysemu/blockdev.h: " Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 17/31] assertions for blockdev.h " Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 18/31] include/block/snapshot: global state API + assertions Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 19/31] block/copy-before-write.h: " Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 20/31] block/coroutines: I/O API Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 21/31] block_int-common.h: split function pointers in BlockDriver Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 22/31] block_int-common.h: assertion in the callers of BlockDriver function pointers Emanuele Giuseppe Esposito
2021-12-16 18:43 ` Hanna Reitz
2021-12-17 15:53 ` Emanuele Giuseppe Esposito
2021-12-17 16:00 ` Hanna Reitz
2021-11-24 6:44 ` [PATCH v5 23/31] block_int-common.h: split function pointers in BdrvChildClass Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 24/31] block_int-common.h: assertions in the callers of BdrvChildClass function pointers Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 25/31] block-backend-common.h: split function pointers in BlockDevOps Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 26/31] job.h: split function pointers in JobDriver Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 27/31] job.h: assertions in the callers of JobDriver funcion pointers Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 28/31] block.c: assert BQL lock held in bdrv_co_invalidate_cache Emanuele Giuseppe Esposito
2021-12-17 11:04 ` Hanna Reitz
2021-12-17 16:38 ` Emanuele Giuseppe Esposito
2021-12-20 12:20 ` Emanuele Giuseppe Esposito
2021-12-23 17:11 ` Hanna Reitz
2022-01-19 15:57 ` Hanna Reitz
2022-01-19 17:44 ` Hanna Reitz
2022-01-19 18:34 ` Kevin Wolf
2022-01-20 13:22 ` Paolo Bonzini
2022-01-20 13:48 ` Kevin Wolf
2022-01-21 10:22 ` Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 29/31] jobs: introduce pre_run function in JobDriver Emanuele Giuseppe Esposito
2021-11-24 6:44 ` [PATCH v5 30/31] crypto: delegate permission functions to JobDriver .pre_run Emanuele Giuseppe Esposito
2021-12-17 12:29 ` Hanna Reitz
2021-12-17 14:32 ` Hanna Reitz
2021-12-20 15:47 ` Emanuele Giuseppe Esposito
2021-12-23 17:15 ` Hanna Reitz
2021-11-24 6:44 ` [PATCH v5 31/31] block.c: assertions to the block layer permissions API Emanuele Giuseppe Esposito
2021-11-29 13:32 ` [PATCH v5 00/31] block layer: split block APIs in global state and I/O Stefan Hajnoczi
2021-11-30 8:39 ` Emanuele Giuseppe Esposito
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124064418.3120601-14-eesposit@redhat.com \
--to=eesposit@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=richard.henderson@linaro.org \
--cc=stefanha@redhat.com \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).