block-backend.c (dde33812a83b9c55b180a85411bfc4d6c39e8b11) block-backend.c (7c8eece45b10fc9b716850345118ed6fa8d17887)
1/*
2 * QEMU Block backends
3 *
4 * Copyright (C) 2014-2016 Red Hat, Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *

--- 61 unchanged lines hidden (view full) ---

70} BlockBackendAIOCB;
71
72static const AIOCBInfo block_backend_aiocb_info = {
73 .get_aio_context = blk_aiocb_get_aio_context,
74 .aiocb_size = sizeof(BlockBackendAIOCB),
75};
76
77static void drive_info_del(DriveInfo *dinfo);
1/*
2 * QEMU Block backends
3 *
4 * Copyright (C) 2014-2016 Red Hat, Inc.
5 *
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
8 *

--- 61 unchanged lines hidden (view full) ---

70} BlockBackendAIOCB;
71
72static const AIOCBInfo block_backend_aiocb_info = {
73 .get_aio_context = blk_aiocb_get_aio_context,
74 .aiocb_size = sizeof(BlockBackendAIOCB),
75};
76
77static void drive_info_del(DriveInfo *dinfo);
78static BlockBackend *bdrv_first_blk(BlockDriverState *bs);
78
79/* All BlockBackends */
80static QTAILQ_HEAD(, BlockBackend) block_backends =
81 QTAILQ_HEAD_INITIALIZER(block_backends);
82
83/* All BlockBackends referenced by the monitor and which are iterated through by
84 * blk_next() */
85static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =

--- 195 unchanged lines hidden (view full) ---

281 * }
282 */
283BlockBackend *blk_next(BlockBackend *blk)
284{
285 return blk ? QTAILQ_NEXT(blk, monitor_link)
286 : QTAILQ_FIRST(&monitor_block_backends);
287}
288
79
80/* All BlockBackends */
81static QTAILQ_HEAD(, BlockBackend) block_backends =
82 QTAILQ_HEAD_INITIALIZER(block_backends);
83
84/* All BlockBackends referenced by the monitor and which are iterated through by
85 * blk_next() */
86static QTAILQ_HEAD(, BlockBackend) monitor_block_backends =

--- 195 unchanged lines hidden (view full) ---

282 * }
283 */
284BlockBackend *blk_next(BlockBackend *blk)
285{
286 return blk ? QTAILQ_NEXT(blk, monitor_link)
287 : QTAILQ_FIRST(&monitor_block_backends);
288}
289
289/*
290 * Iterates over all BlockDriverStates which are attached to a BlockBackend.
291 * This function is for use by bdrv_next().
292 *
293 * @bs must be NULL or a BDS that is attached to a BB.
294 */
295BlockDriverState *blk_next_root_bs(BlockDriverState *bs)
296{
290struct BdrvNextIterator {
291 enum {
292 BDRV_NEXT_BACKEND_ROOTS,
293 BDRV_NEXT_MONITOR_OWNED,
294 } phase;
297 BlockBackend *blk;
295 BlockBackend *blk;
296 BlockDriverState *bs;
297};
298
298
299 if (bs) {
300 assert(bs->blk);
301 blk = bs->blk;
302 } else {
303 blk = NULL;
299/* Iterates over all top-level BlockDriverStates, i.e. BDSs that are owned by
300 * the monitor or attached to a BlockBackend */
301BdrvNextIterator *bdrv_next(BdrvNextIterator *it, BlockDriverState **bs)
302{
303 if (!it) {
304 it = g_new(BdrvNextIterator, 1);
305 *it = (BdrvNextIterator) {
306 .phase = BDRV_NEXT_BACKEND_ROOTS,
307 };
304 }
305
308 }
309
310 /* First, return all root nodes of BlockBackends. In order to avoid
311 * returning a BDS twice when multiple BBs refer to it, we only return it
312 * if the BB is the first one in the parent list of the BDS. */
313 if (it->phase == BDRV_NEXT_BACKEND_ROOTS) {
314 do {
315 it->blk = blk_all_next(it->blk);
316 *bs = it->blk ? blk_bs(it->blk) : NULL;
317 } while (it->blk && (*bs == NULL || bdrv_first_blk(*bs) != it->blk));
318
319 if (*bs) {
320 return it;
321 }
322 it->phase = BDRV_NEXT_MONITOR_OWNED;
323 }
324
325 /* Then return the monitor-owned BDSes without a BB attached. Ignore all
326 * BDSes that are attached to a BlockBackend here; they have been handled
327 * by the above block already */
306 do {
328 do {
307 blk = blk_all_next(blk);
308 } while (blk && !blk->root);
329 it->bs = bdrv_next_monitor_owned(it->bs);
330 *bs = it->bs;
331 } while (*bs && bdrv_has_blk(*bs));
309
332
310 return blk ? blk->root->bs : NULL;
333 return *bs ? it : NULL;
311}
312
313/*
314 * Add a BlockBackend into the list of backends referenced by the monitor, with
315 * the given @name acting as the handle for the monitor.
316 * Strictly for use by blockdev.c.
317 *
318 * @name must not be null or empty.

--- 70 unchanged lines hidden (view full) ---

389/*
390 * Return the BlockDriverState attached to @blk if any, else null.
391 */
392BlockDriverState *blk_bs(BlockBackend *blk)
393{
394 return blk->root ? blk->root->bs : NULL;
395}
396
334}
335
336/*
337 * Add a BlockBackend into the list of backends referenced by the monitor, with
338 * the given @name acting as the handle for the monitor.
339 * Strictly for use by blockdev.c.
340 *
341 * @name must not be null or empty.

--- 70 unchanged lines hidden (view full) ---

412/*
413 * Return the BlockDriverState attached to @blk if any, else null.
414 */
415BlockDriverState *blk_bs(BlockBackend *blk)
416{
417 return blk->root ? blk->root->bs : NULL;
418}
419
397/*
398 * Returns true if @bs has an associated BlockBackend.
399 */
400bool bdrv_has_blk(BlockDriverState *bs)
420static BlockBackend *bdrv_first_blk(BlockDriverState *bs)
401{
402 BdrvChild *child;
403 QLIST_FOREACH(child, &bs->parents, next_parent) {
404 if (child->role == &child_root) {
405 assert(bs->blk);
421{
422 BdrvChild *child;
423 QLIST_FOREACH(child, &bs->parents, next_parent) {
424 if (child->role == &child_root) {
425 assert(bs->blk);
406 return true;
426 return child->opaque;
407 }
408 }
409
410 assert(!bs->blk);
427 }
428 }
429
430 assert(!bs->blk);
411 return false;
431 return NULL;
412}
413
414/*
432}
433
434/*
435 * Returns true if @bs has an associated BlockBackend.
436 */
437bool bdrv_has_blk(BlockDriverState *bs)
438{
439 return bdrv_first_blk(bs) != NULL;
440}
441
442/*
415 * Return @blk's DriveInfo if any, else null.
416 */
417DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
418{
419 return blk->legacy_dinfo;
420}
421
422/*

--- 1276 unchanged lines hidden ---
443 * Return @blk's DriveInfo if any, else null.
444 */
445DriveInfo *blk_legacy_dinfo(BlockBackend *blk)
446{
447 return blk->legacy_dinfo;
448}
449
450/*

--- 1276 unchanged lines hidden ---