Skip to content

Commit 366b581

Browse files
stefanhaRHkevmw
authored andcommitted
virtio-blk: extract cleanup_iothread_vq_mapping() function
This is the cleanup function that must be called after apply_iothread_vq_mapping() succeeds. virtio-scsi will need this function too, so extract it. Signed-off-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Message-ID: <[email protected]> Tested-by: Peter Krempa <[email protected]> Signed-off-by: Kevin Wolf <[email protected]>
1 parent da6eebb commit 366b581

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

hw/block/virtio-blk.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,9 @@ validate_iothread_vq_mapping_list(IOThreadVirtQueueMappingList *list,
14951495
* Fill in the AioContext for each virtqueue in the @vq_aio_context array given
14961496
* the iothread-vq-mapping parameter in @iothread_vq_mapping_list.
14971497
*
1498+
* cleanup_iothread_vq_mapping() must be called to free IOThread object
1499+
* references after this function returns success.
1500+
*
14981501
* Returns: %true on success, %false on failure.
14991502
**/
15001503
static bool apply_iothread_vq_mapping(
@@ -1545,6 +1548,23 @@ static bool apply_iothread_vq_mapping(
15451548
return true;
15461549
}
15471550

1551+
/**
1552+
* cleanup_iothread_vq_mapping:
1553+
* @list: The mapping of virtqueues to IOThreads.
1554+
*
1555+
* Release IOThread object references that were acquired by
1556+
* apply_iothread_vq_mapping().
1557+
*/
1558+
static void cleanup_iothread_vq_mapping(IOThreadVirtQueueMappingList *list)
1559+
{
1560+
IOThreadVirtQueueMappingList *node;
1561+
1562+
for (node = list; node; node = node->next) {
1563+
IOThread *iothread = iothread_by_id(node->value->iothread);
1564+
object_unref(OBJECT(iothread));
1565+
}
1566+
}
1567+
15481568
/* Context: BQL held */
15491569
static bool virtio_blk_vq_aio_context_init(VirtIOBlock *s, Error **errp)
15501570
{
@@ -1611,12 +1631,7 @@ static void virtio_blk_vq_aio_context_cleanup(VirtIOBlock *s)
16111631
assert(!s->ioeventfd_started);
16121632

16131633
if (conf->iothread_vq_mapping_list) {
1614-
IOThreadVirtQueueMappingList *node;
1615-
1616-
for (node = conf->iothread_vq_mapping_list; node; node = node->next) {
1617-
IOThread *iothread = iothread_by_id(node->value->iothread);
1618-
object_unref(OBJECT(iothread));
1619-
}
1634+
cleanup_iothread_vq_mapping(conf->iothread_vq_mapping_list);
16201635
}
16211636

16221637
if (conf->iothread) {

0 commit comments

Comments
 (0)