block.c (12fa4af61fb2a08b156134c3b6717534c637c995) block.c (b2c2832c6140cfe3ddc0de2d77eeb0b77dea8fd3)
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

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

2082 QDict *snapshot_options,
2083 Error **errp)
2084{
2085 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
2086 char *tmp_filename = g_malloc0(PATH_MAX + 1);
2087 int64_t total_size;
2088 QemuOpts *opts = NULL;
2089 BlockDriverState *bs_snapshot;
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

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

2082 QDict *snapshot_options,
2083 Error **errp)
2084{
2085 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
2086 char *tmp_filename = g_malloc0(PATH_MAX + 1);
2087 int64_t total_size;
2088 QemuOpts *opts = NULL;
2089 BlockDriverState *bs_snapshot;
2090 Error *local_err = NULL;
2090 int ret;
2091
2092 /* if snapshot, we create a temporary backing file and open it
2093 instead of opening 'filename' directly */
2094
2095 /* Get the required size from the image */
2096 total_size = bdrv_getlength(bs);
2097 if (total_size < 0) {

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

2131 ret = -EINVAL;
2132 goto out;
2133 }
2134
2135 /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will
2136 * call bdrv_unref() on it), so in order to be able to return one, we have
2137 * to increase bs_snapshot's refcount here */
2138 bdrv_ref(bs_snapshot);
2091 int ret;
2092
2093 /* if snapshot, we create a temporary backing file and open it
2094 instead of opening 'filename' directly */
2095
2096 /* Get the required size from the image */
2097 total_size = bdrv_getlength(bs);
2098 if (total_size < 0) {

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

2132 ret = -EINVAL;
2133 goto out;
2134 }
2135
2136 /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will
2137 * call bdrv_unref() on it), so in order to be able to return one, we have
2138 * to increase bs_snapshot's refcount here */
2139 bdrv_ref(bs_snapshot);
2139 bdrv_append(bs_snapshot, bs);
2140 bdrv_append(bs_snapshot, bs, &local_err);
2141 if (local_err) {
2142 error_propagate(errp, local_err);
2143 ret = -EINVAL;
2144 goto out;
2145 }
2140
2141 g_free(tmp_filename);
2142 return bs_snapshot;
2143
2144out:
2145 QDECREF(snapshot_options);
2146 g_free(tmp_filename);
2147 return NULL;

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

2922 *
2923 * This function does not create any image files.
2924 *
2925 * bdrv_append() takes ownership of a bs_new reference and unrefs it because
2926 * that's what the callers commonly need. bs_new will be referenced by the old
2927 * parents of bs_top after bdrv_append() returns. If the caller needs to keep a
2928 * reference of its own, it must call bdrv_ref().
2929 */
2146
2147 g_free(tmp_filename);
2148 return bs_snapshot;
2149
2150out:
2151 QDECREF(snapshot_options);
2152 g_free(tmp_filename);
2153 return NULL;

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

2928 *
2929 * This function does not create any image files.
2930 *
2931 * bdrv_append() takes ownership of a bs_new reference and unrefs it because
2932 * that's what the callers commonly need. bs_new will be referenced by the old
2933 * parents of bs_top after bdrv_append() returns. If the caller needs to keep a
2934 * reference of its own, it must call bdrv_ref().
2935 */
2930void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top)
2936void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
2937 Error **errp)
2931{
2938{
2939 Error *local_err = NULL;
2940
2932 assert(!atomic_read(&bs_top->in_flight));
2933 assert(!atomic_read(&bs_new->in_flight));
2934
2941 assert(!atomic_read(&bs_top->in_flight));
2942 assert(!atomic_read(&bs_new->in_flight));
2943
2935 bdrv_ref(bs_top);
2944 bdrv_set_backing_hd(bs_new, bs_top, &local_err);
2945 if (local_err) {
2946 error_propagate(errp, local_err);
2947 goto out;
2948 }
2936
2937 change_parent_backing_link(bs_top, bs_new);
2949
2950 change_parent_backing_link(bs_top, bs_new);
2938 /* FIXME Error handling */
2939 bdrv_set_backing_hd(bs_new, bs_top, &error_abort);
2940 bdrv_unref(bs_top);
2941
2942 /* bs_new is now referenced by its new parents, we don't need the
2943 * additional reference any more. */
2951
2952 /* bs_new is now referenced by its new parents, we don't need the
2953 * additional reference any more. */
2954out:
2944 bdrv_unref(bs_new);
2945}
2946
2947void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new)
2948{
2949 assert(!bdrv_requests_pending(old));
2950 assert(!bdrv_requests_pending(new));
2951

--- 1667 unchanged lines hidden ---
2955 bdrv_unref(bs_new);
2956}
2957
2958void bdrv_replace_in_backing_chain(BlockDriverState *old, BlockDriverState *new)
2959{
2960 assert(!bdrv_requests_pending(old));
2961 assert(!bdrv_requests_pending(new));
2962

--- 1667 unchanged lines hidden ---