block.c (46f5ac205a9dc5e2c24274c7df371509a286281f) block.c (ff6ed7141d87d26eafa2b8e4df969623e40fac49)
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

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

2190 int flags,
2191 QDict *snapshot_options,
2192 Error **errp)
2193{
2194 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
2195 char *tmp_filename = g_malloc0(PATH_MAX + 1);
2196 int64_t total_size;
2197 QemuOpts *opts = NULL;
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

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

2190 int flags,
2191 QDict *snapshot_options,
2192 Error **errp)
2193{
2194 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
2195 char *tmp_filename = g_malloc0(PATH_MAX + 1);
2196 int64_t total_size;
2197 QemuOpts *opts = NULL;
2198 BlockDriverState *bs_snapshot;
2198 BlockDriverState *bs_snapshot = NULL;
2199 Error *local_err = NULL;
2200 int ret;
2201
2202 /* if snapshot, we create a temporary backing file and open it
2203 instead of opening 'filename' directly */
2204
2205 /* Get the required size from the image */
2206 total_size = bdrv_getlength(bs);

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

2230 /* Prepare options QDict for the temporary file */
2231 qdict_put_str(snapshot_options, "file.driver", "file");
2232 qdict_put_str(snapshot_options, "file.filename", tmp_filename);
2233 qdict_put_str(snapshot_options, "driver", "qcow2");
2234
2235 bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp);
2236 snapshot_options = NULL;
2237 if (!bs_snapshot) {
2199 Error *local_err = NULL;
2200 int ret;
2201
2202 /* if snapshot, we create a temporary backing file and open it
2203 instead of opening 'filename' directly */
2204
2205 /* Get the required size from the image */
2206 total_size = bdrv_getlength(bs);

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

2230 /* Prepare options QDict for the temporary file */
2231 qdict_put_str(snapshot_options, "file.driver", "file");
2232 qdict_put_str(snapshot_options, "file.filename", tmp_filename);
2233 qdict_put_str(snapshot_options, "driver", "qcow2");
2234
2235 bs_snapshot = bdrv_open(NULL, NULL, snapshot_options, flags, errp);
2236 snapshot_options = NULL;
2237 if (!bs_snapshot) {
2238 ret = -EINVAL;
2239 goto out;
2240 }
2241
2238 goto out;
2239 }
2240
2242 /* bdrv_append() consumes a strong reference to bs_snapshot (i.e. it will
2243 * call bdrv_unref() on it), so in order to be able to return one, we have
2244 * to increase bs_snapshot's refcount here */
2241 /* bdrv_append() consumes a strong reference to bs_snapshot
2242 * (i.e. it will call bdrv_unref() on it) even on error, so in
2243 * order to be able to return one, we have to increase
2244 * bs_snapshot's refcount here */
2245 bdrv_ref(bs_snapshot);
2246 bdrv_append(bs_snapshot, bs, &local_err);
2247 if (local_err) {
2248 error_propagate(errp, local_err);
2245 bdrv_ref(bs_snapshot);
2246 bdrv_append(bs_snapshot, bs, &local_err);
2247 if (local_err) {
2248 error_propagate(errp, local_err);
2249 ret = -EINVAL;
2249 bs_snapshot = NULL;
2250 goto out;
2251 }
2252
2250 goto out;
2251 }
2252
2253 g_free(tmp_filename);
2254 return bs_snapshot;
2255
2256out:
2257 QDECREF(snapshot_options);
2258 g_free(tmp_filename);
2253out:
2254 QDECREF(snapshot_options);
2255 g_free(tmp_filename);
2259 return NULL;
2256 return bs_snapshot;
2260}
2261
2262/*
2263 * Opens a disk image (raw, qcow2, vmdk, ...)
2264 *
2265 * options is a QDict of options to pass to the block drivers, or NULL for an
2266 * empty set of options. The reference to the QDict belongs to the block layer
2267 * after the call (even on failure), so if the caller intends to reuse the

--- 2532 unchanged lines hidden ---
2257}
2258
2259/*
2260 * Opens a disk image (raw, qcow2, vmdk, ...)
2261 *
2262 * options is a QDict of options to pass to the block drivers, or NULL for an
2263 * empty set of options. The reference to the QDict belongs to the block layer
2264 * after the call (even on failure), so if the caller intends to reuse the

--- 2532 unchanged lines hidden ---