[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next()
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next() |
Date: |
Fri, 20 May 2016 10:10:17 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Am 20.05.2016 um 10:05 hat Kevin Wolf geschrieben:
> Am 20.05.2016 um 09:54 hat Paolo Bonzini geschrieben:
> > > +/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are
> > > owned by
> > > + * the monitor or attached to a BlockBackend */
> > > +BdrvNextIterator *bdrv_next(BdrvNextIterator *it, BlockDriverState **bs)
> > > +{
> > > + if (!it) {
> > > + it = g_new(BdrvNextIterator, 1);
> >
> > Hmm, who frees it? (Especially if the caller exits the loop
> > prematurely, which means you cannot just free it before returning NULL).
> > I think it's better to:
> >
> > - allocate the iterator on the stack and make bdrv_next return a BDS *
> >
> > - and add a bdrv_first function that does this:
> >
> > > + *it = (BdrvNextIterator) {
> > > + .phase = BDRV_NEXT_BACKEND_ROOTS,
> > > + };
> >
> > and then returns bdrv_next(it);
> >
> > - if desirable add a macro that abstracts the calls to bdrv_first and
> > bdrv_next.
>
> Already posted a fix. I chose to keep the interface and free the
> BdrvNextIterator inside bdrv_next(), when we return NULL after the last
> element.
Oops, should have actually read your email... You're right about callers
that prematurely exit the loop, of course.
I still don't really like first/next interfaces, though. Perhaps start
the iteration with bs == NULL instead of it == NULL?
Kevin
- [Qemu-devel] [PULL 15/31] block: Use BdrvChild callbacks for change_media/resize, (continued)
- [Qemu-devel] [PULL 15/31] block: Use BdrvChild callbacks for change_media/resize, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 28/31] block: clarify error message for qmp-eject, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 25/31] qcow2: fix condition in is_zero_cluster, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 13/31] Revert "block: Forbid I/O throttling on nodes with multiple parents for 2.6", Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 17/31] blockjob: Don't set iostatus of target, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 19/31] block: Remove bdrv_aio_multiwrite(), Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 26/31] qcow2: Fix write_zeroes with partially allocated backing file cluster, Kevin Wolf, 2016/05/19
- [Qemu-devel] [PULL 21/31] block: Avoid bs->blk in bdrv_next(), Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 20/31] block: Add bdrv_has_blk(), Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 22/31] block: Don't return throttling info in query-named-block-nodes, Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 24/31] block: Propagate AioContext change to all children, Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 30/31] qemu-iotests: Simplify 109 with unaligned qemu-img compare, Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 27/31] qemu-iotests: Some more write_zeroes tests, Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 23/31] block: Remove BlockDriverState.blk, Kevin Wolf, 2016/05/19
[Qemu-devel] [PULL 31/31] qemu-iotests: Fix regression in 136 on aio_read invalid, Kevin Wolf, 2016/05/19