blockdev.c (0db832f42e445398b2815cd740e9cd915e7dd644) blockdev.c (b2c2832c6140cfe3ddc0de2d77eeb0b77dea8fd3)
1/*
2 * QEMU host block devices
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
8 *

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

1763
1764 if (state->new_bs->backing != NULL) {
1765 error_setg(errp, "The snapshot already has a backing image");
1766 return;
1767 }
1768
1769 if (!state->new_bs->drv->supports_backing) {
1770 error_setg(errp, "The snapshot does not support backing images");
1/*
2 * QEMU host block devices
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * later. See the COPYING file in the top-level directory.
8 *

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

1763
1764 if (state->new_bs->backing != NULL) {
1765 error_setg(errp, "The snapshot already has a backing image");
1766 return;
1767 }
1768
1769 if (!state->new_bs->drv->supports_backing) {
1770 error_setg(errp, "The snapshot does not support backing images");
1771 return;
1771 }
1772 }
1773
1774 /* This removes our old bs and adds the new bs. This is an operation that
1775 * can fail, so we need to do it in .prepare; undoing it for abort is
1776 * always possible. */
1777 bdrv_ref(state->new_bs);
1778 bdrv_append(state->new_bs, state->old_bs, &local_err);
1779 if (local_err) {
1780 error_propagate(errp, local_err);
1781 return;
1782 }
1772}
1773
1774static void external_snapshot_commit(BlkActionState *common)
1775{
1776 ExternalSnapshotState *state =
1777 DO_UPCAST(ExternalSnapshotState, common, common);
1778
1779 bdrv_set_aio_context(state->new_bs, state->aio_context);
1780
1783}
1784
1785static void external_snapshot_commit(BlkActionState *common)
1786{
1787 ExternalSnapshotState *state =
1788 DO_UPCAST(ExternalSnapshotState, common, common);
1789
1790 bdrv_set_aio_context(state->new_bs, state->aio_context);
1791
1781 /* This removes our old bs and adds the new bs */
1782 bdrv_append(state->new_bs, state->old_bs);
1783 /* We don't need (or want) to use the transactional
1784 * bdrv_reopen_multiple() across all the entries at once, because we
1785 * don't want to abort all of them if one of them fails the reopen */
1786 if (!state->old_bs->copy_on_read) {
1787 bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR,
1788 NULL);
1789 }
1790}
1791
1792static void external_snapshot_abort(BlkActionState *common)
1793{
1794 ExternalSnapshotState *state =
1795 DO_UPCAST(ExternalSnapshotState, common, common);
1796 if (state->new_bs) {
1792 /* We don't need (or want) to use the transactional
1793 * bdrv_reopen_multiple() across all the entries at once, because we
1794 * don't want to abort all of them if one of them fails the reopen */
1795 if (!state->old_bs->copy_on_read) {
1796 bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDWR,
1797 NULL);
1798 }
1799}
1800
1801static void external_snapshot_abort(BlkActionState *common)
1802{
1803 ExternalSnapshotState *state =
1804 DO_UPCAST(ExternalSnapshotState, common, common);
1805 if (state->new_bs) {
1797 bdrv_unref(state->new_bs);
1806 if (state->new_bs->backing) {
1807 bdrv_replace_in_backing_chain(state->new_bs, state->old_bs);
1808 }
1798 }
1799}
1800
1801static void external_snapshot_clean(BlkActionState *common)
1802{
1803 ExternalSnapshotState *state =
1804 DO_UPCAST(ExternalSnapshotState, common, common);
1805 if (state->aio_context) {
1806 bdrv_drained_end(state->old_bs);
1807 aio_context_release(state->aio_context);
1809 }
1810}
1811
1812static void external_snapshot_clean(BlkActionState *common)
1813{
1814 ExternalSnapshotState *state =
1815 DO_UPCAST(ExternalSnapshotState, common, common);
1816 if (state->aio_context) {
1817 bdrv_drained_end(state->old_bs);
1818 aio_context_release(state->aio_context);
1819 bdrv_unref(state->new_bs);
1808 }
1809}
1810
1811typedef struct DriveBackupState {
1812 BlkActionState common;
1813 BlockDriverState *bs;
1814 AioContext *aio_context;
1815 BlockJob *job;

--- 2269 unchanged lines hidden ---
1820 }
1821}
1822
1823typedef struct DriveBackupState {
1824 BlkActionState common;
1825 BlockDriverState *bs;
1826 AioContext *aio_context;
1827 BlockJob *job;

--- 2269 unchanged lines hidden ---