[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH v2 08/25] block: introduce assert_bdrv_graph_writable
From: |
Stefan Hajnoczi |
Subject: |
Re: [RFC PATCH v2 08/25] block: introduce assert_bdrv_graph_writable |
Date: |
Thu, 7 Oct 2021 15:18:36 +0100 |
On Thu, Oct 07, 2021 at 03:47:42PM +0200, Emanuele Giuseppe Esposito wrote:
>
>
> On 07/10/2021 14:02, Paolo Bonzini wrote:
> > > --- a/block/io.c
> > > +++ b/block/io.c
> > > @@ -739,6 +739,11 @@ void bdrv_drain_all(void)
> > > bdrv_drain_all_end();
> > > }
> > > +void assert_bdrv_graph_writable(BlockDriverState *bs)
> > > +{
> > > + g_assert(qatomic_read(&bs->quiesce_counter) > 0 ||
> > > qemu_in_main_thread());
> > > +}
> >
> > Hmm, wait - I think this should be an "&&", not an OR?
> >
>
> You are right, && makes more sense. But as you said, using an AND will make
> the assertion fail in multiple places, because the necessary drains are
> missing. So I am going to remove the check for drains and leave it as todo.
> I will handle this case in another patch.
BTW when an assertion expression tests unrelated things it helps to use
separate assert() calls instead of &&. That way it's obvious which
sub-expression failed from the error message and it's not necessary to
inspect the coredump.
In other words:
assert(a && b) -> Assertion `a && b` failed.
This doesn't tell me whether it was a or b that was false. The assertion
failure is easier to diagnose if you split it:
assert(a); -> Assertion `a` failed.
assert(b); -> Assertion `b` failed.
Stefan
signature.asc
Description: PGP signature
[RFC PATCH v2 10/25] assertions for blockjob_int.h, Emanuele Giuseppe Esposito, 2021/10/05
[RFC PATCH v2 12/25] assertions for blockob.h global state API, Emanuele Giuseppe Esposito, 2021/10/05
[RFC PATCH v2 09/25] include/block/blockjob_int.h: split header into I/O and GS API, Emanuele Giuseppe Esposito, 2021/10/05
[RFC PATCH v2 13/25] include/systemu/blockdev.h: global state API, Emanuele Giuseppe Esposito, 2021/10/05
[RFC PATCH v2 11/25] include/block/blockjob.h: global state API, Emanuele Giuseppe Esposito, 2021/10/05