block.c (92140b9f3f07d80e2c27edcc6e32f392be2135e6) block.c (299403aedaeb7f08d8e98aa8614b29d4e5546066)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

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

1227{
1228 BlockDriverState *bs = child->opaque;
1229 bdrv_do_drained_begin_quiesce(bs, NULL, false);
1230}
1231
1232static bool bdrv_child_cb_drained_poll(BdrvChild *child)
1233{
1234 BlockDriverState *bs = child->opaque;
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

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

1227{
1228 BlockDriverState *bs = child->opaque;
1229 bdrv_do_drained_begin_quiesce(bs, NULL, false);
1230}
1231
1232static bool bdrv_child_cb_drained_poll(BdrvChild *child)
1233{
1234 BlockDriverState *bs = child->opaque;
1235 return bdrv_drain_poll(bs, false, NULL, false);
1235 return bdrv_drain_poll(bs, NULL, false);
1236}
1237
1238static void bdrv_child_cb_drained_end(BdrvChild *child)
1239{
1240 BlockDriverState *bs = child->opaque;
1241 bdrv_drained_end(bs);
1242}
1243

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

1477 assert(!(child->role & BDRV_CHILD_PRIMARY));
1478 assert(!bs->backing);
1479 bs->backing = child;
1480 bdrv_backing_attach(child);
1481 } else if (child->role & BDRV_CHILD_PRIMARY) {
1482 assert(!bs->file);
1483 bs->file = child;
1484 }
1236}
1237
1238static void bdrv_child_cb_drained_end(BdrvChild *child)
1239{
1240 BlockDriverState *bs = child->opaque;
1241 bdrv_drained_end(bs);
1242}
1243

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

1477 assert(!(child->role & BDRV_CHILD_PRIMARY));
1478 assert(!bs->backing);
1479 bs->backing = child;
1480 bdrv_backing_attach(child);
1481 } else if (child->role & BDRV_CHILD_PRIMARY) {
1482 assert(!bs->file);
1483 bs->file = child;
1484 }
1485
1486 bdrv_apply_subtree_drain(child, bs);
1487}
1488
1489static void bdrv_child_cb_detach(BdrvChild *child)
1490{
1491 BlockDriverState *bs = child->opaque;
1492
1493 if (child->role & BDRV_CHILD_COW) {
1494 bdrv_backing_detach(child);
1495 }
1496
1485}
1486
1487static void bdrv_child_cb_detach(BdrvChild *child)
1488{
1489 BlockDriverState *bs = child->opaque;
1490
1491 if (child->role & BDRV_CHILD_COW) {
1492 bdrv_backing_detach(child);
1493 }
1494
1497 bdrv_unapply_subtree_drain(child, bs);
1498
1499 assert_bdrv_graph_writable(bs);
1500 QLIST_REMOVE(child, next);
1501 if (child == bs->backing) {
1502 assert(child != bs->file);
1503 bs->backing = NULL;
1504 } else if (child == bs->file) {
1505 bs->file = NULL;
1506 }

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

2877 * all outstanding requests to the old child node.
2878 */
2879 while (drain_saldo > 0 && child->klass->drained_begin) {
2880 bdrv_parent_drained_begin_single(child, true);
2881 drain_saldo--;
2882 }
2883
2884 if (old_bs) {
1495 assert_bdrv_graph_writable(bs);
1496 QLIST_REMOVE(child, next);
1497 if (child == bs->backing) {
1498 assert(child != bs->file);
1499 bs->backing = NULL;
1500 } else if (child == bs->file) {
1501 bs->file = NULL;
1502 }

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

2873 * all outstanding requests to the old child node.
2874 */
2875 while (drain_saldo > 0 && child->klass->drained_begin) {
2876 bdrv_parent_drained_begin_single(child, true);
2877 drain_saldo--;
2878 }
2879
2880 if (old_bs) {
2885 /* Detach first so that the recursive drain sections coming from @child
2886 * are already gone and we only end the drain sections that came from
2887 * elsewhere. */
2888 if (child->klass->detach) {
2889 child->klass->detach(child);
2890 }
2891 assert_bdrv_graph_writable(old_bs);
2892 QLIST_REMOVE(child, next_parent);
2893 }
2894
2895 child->bs = new_bs;
2896
2897 if (new_bs) {
2898 assert_bdrv_graph_writable(new_bs);
2899 QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
2900
2901 /*
2881 if (child->klass->detach) {
2882 child->klass->detach(child);
2883 }
2884 assert_bdrv_graph_writable(old_bs);
2885 QLIST_REMOVE(child, next_parent);
2886 }
2887
2888 child->bs = new_bs;
2889
2890 if (new_bs) {
2891 assert_bdrv_graph_writable(new_bs);
2892 QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent);
2893
2894 /*
2902 * Detaching the old node may have led to the new node's
2903 * quiesce_counter having been decreased. Not a problem, we
2904 * just need to recognize this here and then invoke
2905 * drained_end appropriately more often.
2895 * Polling in bdrv_parent_drained_begin_single() may have led to the new
2896 * node's quiesce_counter having been decreased. Not a problem, we just
2897 * need to recognize this here and then invoke drained_end appropriately
2898 * more often.
2906 */
2907 assert(new_bs->quiesce_counter <= new_bs_quiesce_counter);
2908 drain_saldo += new_bs->quiesce_counter - new_bs_quiesce_counter;
2909
2899 */
2900 assert(new_bs->quiesce_counter <= new_bs_quiesce_counter);
2901 drain_saldo += new_bs->quiesce_counter - new_bs_quiesce_counter;
2902
2910 /* Attach only after starting new drained sections, so that recursive
2911 * drain sections coming from @child don't get an extra .drained_begin
2912 * callback. */
2913 if (child->klass->attach) {
2914 child->klass->attach(child);
2915 }
2916 }
2917
2918 /*
2919 * If the old child node was drained but the new one is not, allow
2920 * requests to come in only after the new node has been attached.

--- 5273 unchanged lines hidden ---
2903 if (child->klass->attach) {
2904 child->klass->attach(child);
2905 }
2906 }
2907
2908 /*
2909 * If the old child node was drained but the new one is not, allow
2910 * requests to come in only after the new node has been attached.

--- 5273 unchanged lines hidden ---