block.c (0d83708a1d2effc5d905cd1d61d0ef47d310ad88) block.c (53a7d041858a6787a43012fd04ccf0258389a95d)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

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

938
939static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
940 GSList **ignore, Error **errp)
941{
942 BlockDriverState *bs = child->opaque;
943 return bdrv_can_set_aio_context(bs, ctx, ignore, errp);
944}
945
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

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

938
939static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ctx,
940 GSList **ignore, Error **errp)
941{
942 BlockDriverState *bs = child->opaque;
943 return bdrv_can_set_aio_context(bs, ctx, ignore, errp);
944}
945
946static void bdrv_child_cb_set_aio_ctx(BdrvChild *child, AioContext *ctx,
947 GSList **ignore)
948{
949 BlockDriverState *bs = child->opaque;
950 return bdrv_set_aio_context_ignore(bs, ctx, ignore);
951}
952
946/*
947 * Returns the options and flags that a temporary snapshot should get, based on
948 * the originally requested flags (the originally requested image will have
949 * flags like a backing file)
950 */
951static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
952 int parent_flags, QDict *parent_options)
953{

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

1006 .inherit_options = bdrv_inherited_options,
1007 .drained_begin = bdrv_child_cb_drained_begin,
1008 .drained_poll = bdrv_child_cb_drained_poll,
1009 .drained_end = bdrv_child_cb_drained_end,
1010 .attach = bdrv_child_cb_attach,
1011 .detach = bdrv_child_cb_detach,
1012 .inactivate = bdrv_child_cb_inactivate,
1013 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
953/*
954 * Returns the options and flags that a temporary snapshot should get, based on
955 * the originally requested flags (the originally requested image will have
956 * flags like a backing file)
957 */
958static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
959 int parent_flags, QDict *parent_options)
960{

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

1013 .inherit_options = bdrv_inherited_options,
1014 .drained_begin = bdrv_child_cb_drained_begin,
1015 .drained_poll = bdrv_child_cb_drained_poll,
1016 .drained_end = bdrv_child_cb_drained_end,
1017 .attach = bdrv_child_cb_attach,
1018 .detach = bdrv_child_cb_detach,
1019 .inactivate = bdrv_child_cb_inactivate,
1020 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
1021 .set_aio_ctx = bdrv_child_cb_set_aio_ctx,
1014};
1015
1016/*
1017 * Returns the options and flags that bs->file should get if the use of formats
1018 * (and not only protocols) is permitted for it, based on the given options and
1019 * flags for the parent BDS
1020 */
1021static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options,

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

1033 .inherit_options = bdrv_inherited_fmt_options,
1034 .drained_begin = bdrv_child_cb_drained_begin,
1035 .drained_poll = bdrv_child_cb_drained_poll,
1036 .drained_end = bdrv_child_cb_drained_end,
1037 .attach = bdrv_child_cb_attach,
1038 .detach = bdrv_child_cb_detach,
1039 .inactivate = bdrv_child_cb_inactivate,
1040 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
1022};
1023
1024/*
1025 * Returns the options and flags that bs->file should get if the use of formats
1026 * (and not only protocols) is permitted for it, based on the given options and
1027 * flags for the parent BDS
1028 */
1029static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options,

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

1041 .inherit_options = bdrv_inherited_fmt_options,
1042 .drained_begin = bdrv_child_cb_drained_begin,
1043 .drained_poll = bdrv_child_cb_drained_poll,
1044 .drained_end = bdrv_child_cb_drained_end,
1045 .attach = bdrv_child_cb_attach,
1046 .detach = bdrv_child_cb_detach,
1047 .inactivate = bdrv_child_cb_inactivate,
1048 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
1049 .set_aio_ctx = bdrv_child_cb_set_aio_ctx,
1041};
1042
1043static void bdrv_backing_attach(BdrvChild *c)
1044{
1045 BlockDriverState *parent = c->opaque;
1046 BlockDriverState *backing_hd = c->bs;
1047
1048 assert(!parent->backing_blocker);

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

1157 .detach = bdrv_backing_detach,
1158 .inherit_options = bdrv_backing_options,
1159 .drained_begin = bdrv_child_cb_drained_begin,
1160 .drained_poll = bdrv_child_cb_drained_poll,
1161 .drained_end = bdrv_child_cb_drained_end,
1162 .inactivate = bdrv_child_cb_inactivate,
1163 .update_filename = bdrv_backing_update_filename,
1164 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
1050};
1051
1052static void bdrv_backing_attach(BdrvChild *c)
1053{
1054 BlockDriverState *parent = c->opaque;
1055 BlockDriverState *backing_hd = c->bs;
1056
1057 assert(!parent->backing_blocker);

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

1166 .detach = bdrv_backing_detach,
1167 .inherit_options = bdrv_backing_options,
1168 .drained_begin = bdrv_child_cb_drained_begin,
1169 .drained_poll = bdrv_child_cb_drained_poll,
1170 .drained_end = bdrv_child_cb_drained_end,
1171 .inactivate = bdrv_child_cb_inactivate,
1172 .update_filename = bdrv_backing_update_filename,
1173 .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx,
1174 .set_aio_ctx = bdrv_child_cb_set_aio_ctx,
1165};
1166
1167static int bdrv_open_flags(BlockDriverState *bs, int flags)
1168{
1169 int open_flags = flags;
1170
1171 /*
1172 * Clear flags that are internal to the block layer before opening the

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

5726 bdrv_do_remove_aio_context_notifier(ban);
5727 } else {
5728 ban->attached_aio_context(new_context, ban->opaque);
5729 }
5730 }
5731 bs->walking_aio_notifiers = false;
5732}
5733
1175};
1176
1177static int bdrv_open_flags(BlockDriverState *bs, int flags)
1178{
1179 int open_flags = flags;
1180
1181 /*
1182 * Clear flags that are internal to the block layer before opening the

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

5736 bdrv_do_remove_aio_context_notifier(ban);
5737 } else {
5738 ban->attached_aio_context(new_context, ban->opaque);
5739 }
5740 }
5741 bs->walking_aio_notifiers = false;
5742}
5743
5734/* The caller must own the AioContext lock for the old AioContext of bs, but it
5735 * must not own the AioContext lock for new_context (unless new_context is
5736 * the same as the current context of bs). */
5737void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
5744/* @ignore will accumulate all visited BdrvChild object. The caller is
5745 * responsible for freeing the list afterwards. */
5746void bdrv_set_aio_context_ignore(BlockDriverState *bs,
5747 AioContext *new_context, GSList **ignore)
5738{
5739 BdrvChild *child;
5740
5741 if (bdrv_get_aio_context(bs) == new_context) {
5742 return;
5743 }
5744
5745 bdrv_drained_begin(bs);
5746
5747 QLIST_FOREACH(child, &bs->children, next) {
5748{
5749 BdrvChild *child;
5750
5751 if (bdrv_get_aio_context(bs) == new_context) {
5752 return;
5753 }
5754
5755 bdrv_drained_begin(bs);
5756
5757 QLIST_FOREACH(child, &bs->children, next) {
5748 bdrv_set_aio_context(child->bs, new_context);
5758 if (g_slist_find(*ignore, child)) {
5759 continue;
5760 }
5761 *ignore = g_slist_prepend(*ignore, child);
5762 bdrv_set_aio_context_ignore(child->bs, new_context, ignore);
5749 }
5763 }
5764 QLIST_FOREACH(child, &bs->parents, next_parent) {
5765 if (g_slist_find(*ignore, child)) {
5766 continue;
5767 }
5768 if (child->role->set_aio_ctx) {
5769 *ignore = g_slist_prepend(*ignore, child);
5770 child->role->set_aio_ctx(child, new_context, ignore);
5771 }
5772 }
5750
5751 bdrv_detach_aio_context(bs);
5752
5753 /* This function executes in the old AioContext so acquire the new one in
5754 * case it runs in a different thread.
5755 */
5756 aio_context_acquire(new_context);
5757 bdrv_attach_aio_context(bs, new_context);
5758 bdrv_drained_end(bs);
5759 aio_context_release(new_context);
5760}
5761
5773
5774 bdrv_detach_aio_context(bs);
5775
5776 /* This function executes in the old AioContext so acquire the new one in
5777 * case it runs in a different thread.
5778 */
5779 aio_context_acquire(new_context);
5780 bdrv_attach_aio_context(bs, new_context);
5781 bdrv_drained_end(bs);
5782 aio_context_release(new_context);
5783}
5784
5785/* The caller must own the AioContext lock for the old AioContext of bs, but it
5786 * must not own the AioContext lock for new_context (unless new_context is
5787 * the same as the current context of bs). */
5788void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
5789{
5790 GSList *ignore_list = NULL;
5791 bdrv_set_aio_context_ignore(bs, new_context, &ignore_list);
5792 g_slist_free(ignore_list);
5793}
5794
5762static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx,
5763 GSList **ignore, Error **errp)
5764{
5765 if (g_slist_find(*ignore, c)) {
5766 return true;
5767 }
5768 *ignore = g_slist_prepend(*ignore, c);
5769

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

5826 ignore = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL;
5827 ret = bdrv_can_set_aio_context(bs, ctx, &ignore, errp);
5828 g_slist_free(ignore);
5829
5830 if (!ret) {
5831 return -EPERM;
5832 }
5833
5795static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx,
5796 GSList **ignore, Error **errp)
5797{
5798 if (g_slist_find(*ignore, c)) {
5799 return true;
5800 }
5801 *ignore = g_slist_prepend(*ignore, c);
5802

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

5859 ignore = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL;
5860 ret = bdrv_can_set_aio_context(bs, ctx, &ignore, errp);
5861 g_slist_free(ignore);
5862
5863 if (!ret) {
5864 return -EPERM;
5865 }
5866
5834 bdrv_set_aio_context(bs, ctx);
5867 ignore = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL;
5868 bdrv_set_aio_context_ignore(bs, ctx, &ignore);
5869 g_slist_free(ignore);
5870
5835 return 0;
5836}
5837
5838int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx,
5839 Error **errp)
5840{
5841 return bdrv_child_try_set_aio_context(bs, ctx, NULL, errp);
5842}

--- 479 unchanged lines hidden ---
5871 return 0;
5872}
5873
5874int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx,
5875 Error **errp)
5876{
5877 return bdrv_child_try_set_aio_context(bs, ctx, NULL, errp);
5878}

--- 479 unchanged lines hidden ---