mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches (v2) # gpg: Signature made Mon 14 Sep 2015 15:56:54 BST using RSA key ID C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" * remotes/kevin/tags/for-upstream: (23 commits) qcow2: Make qcow2_alloc_bytes() more explicit vmdk: Fix next_cluster_sector for compressed write iotests: Add test for checking large image files qcow2: Make size_to_clusters() return uint64_t qemu-iotests: More qcow2 reopen tests qemu-iotests: Reopen qcow2 with lazy-refcounts change qcow2: Support updating driver-specific options in reopen qcow2: Make qcow2_update_options() suitable for transactions qcow2: Fix memory leak in qcow2_update_options() error path qcow2: Leave s unchanged on qcow2_update_options() failure qcow2: Move rest of option handling to qcow2_update_options() qcow2: Move qcow2_update_options() call up qcow2: Factor out qcow2_update_options() qcow2: Improve error message qemu-io: Add command 'reopen' qemu-io: Remove duplicate 'open' error message block: Allow specifying driver-specific options to reopen qcow2: Rename BDRVQcowState to BDRVQcow2State block: Drop bdrv_find_whitelisted_format() block: Drop drv parameter from bdrv_fill_options() ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -85,8 +85,7 @@ static QLIST_HEAD(, BlockDriver) bdrv_drivers =
|
||||
static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
|
||||
const char *reference, QDict *options, int flags,
|
||||
BlockDriverState *parent,
|
||||
const BdrvChildRole *child_role,
|
||||
BlockDriver *drv, Error **errp);
|
||||
const BdrvChildRole *child_role, Error **errp);
|
||||
|
||||
static void bdrv_dirty_bitmap_truncate(BlockDriverState *bs);
|
||||
/* If non-zero, use only whitelisted block drivers */
|
||||
@@ -314,13 +313,6 @@ static int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)
|
||||
return 0;
|
||||
}
|
||||
|
||||
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
|
||||
bool read_only)
|
||||
{
|
||||
BlockDriver *drv = bdrv_find_format(format_name);
|
||||
return drv && bdrv_is_whitelisted(drv, read_only) ? drv : NULL;
|
||||
}
|
||||
|
||||
typedef struct CreateCo {
|
||||
BlockDriver *drv;
|
||||
char *filename;
|
||||
@@ -997,13 +989,13 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
|
||||
* block driver has been specified explicitly.
|
||||
*/
|
||||
static int bdrv_fill_options(QDict **options, const char **pfilename,
|
||||
int *flags, BlockDriver *drv, Error **errp)
|
||||
int *flags, Error **errp)
|
||||
{
|
||||
const char *filename = *pfilename;
|
||||
const char *drvname;
|
||||
bool protocol = *flags & BDRV_O_PROTOCOL;
|
||||
bool parse_filename = false;
|
||||
BlockDriver *tmp_drv;
|
||||
BlockDriver *drv = NULL;
|
||||
Error *local_err = NULL;
|
||||
|
||||
/* Parse json: pseudo-protocol */
|
||||
@@ -1022,15 +1014,15 @@ static int bdrv_fill_options(QDict **options, const char **pfilename,
|
||||
}
|
||||
|
||||
drvname = qdict_get_try_str(*options, "driver");
|
||||
|
||||
/* If the user has explicitly specified the driver, this choice should
|
||||
* override the BDRV_O_PROTOCOL flag */
|
||||
tmp_drv = drv;
|
||||
if (!tmp_drv && drvname) {
|
||||
tmp_drv = bdrv_find_format(drvname);
|
||||
}
|
||||
if (tmp_drv) {
|
||||
protocol = tmp_drv->bdrv_file_open;
|
||||
if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown driver '%s'", drvname);
|
||||
return -ENOENT;
|
||||
}
|
||||
/* If the user has explicitly specified the driver, this choice should
|
||||
* override the BDRV_O_PROTOCOL flag */
|
||||
protocol = drv->bdrv_file_open;
|
||||
}
|
||||
|
||||
if (protocol) {
|
||||
@@ -1054,33 +1046,18 @@ static int bdrv_fill_options(QDict **options, const char **pfilename,
|
||||
/* Find the right block driver */
|
||||
filename = qdict_get_try_str(*options, "filename");
|
||||
|
||||
if (drv) {
|
||||
if (drvname) {
|
||||
error_setg(errp, "Driver specified twice");
|
||||
return -EINVAL;
|
||||
}
|
||||
drvname = drv->format_name;
|
||||
qdict_put(*options, "driver", qstring_from_str(drvname));
|
||||
} else {
|
||||
if (!drvname && protocol) {
|
||||
if (filename) {
|
||||
drv = bdrv_find_protocol(filename, parse_filename, errp);
|
||||
if (!drv) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drvname = drv->format_name;
|
||||
qdict_put(*options, "driver", qstring_from_str(drvname));
|
||||
} else {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
if (!drvname && protocol) {
|
||||
if (filename) {
|
||||
drv = bdrv_find_protocol(filename, parse_filename, errp);
|
||||
if (!drv) {
|
||||
return -EINVAL;
|
||||
}
|
||||
} else if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
if (!drv) {
|
||||
error_setg(errp, "Unknown driver '%s'", drvname);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
drvname = drv->format_name;
|
||||
qdict_put(*options, "driver", qstring_from_str(drvname));
|
||||
} else {
|
||||
error_setg(errp, "Must specify either driver or file");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1227,8 +1204,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
|
||||
assert(bs->backing_hd == NULL);
|
||||
ret = bdrv_open_inherit(&backing_hd,
|
||||
*backing_filename ? backing_filename : NULL,
|
||||
NULL, options, 0, bs, &child_backing,
|
||||
NULL, &local_err);
|
||||
NULL, options, 0, bs, &child_backing, &local_err);
|
||||
if (ret < 0) {
|
||||
bdrv_unref(backing_hd);
|
||||
backing_hd = NULL;
|
||||
@@ -1291,7 +1267,7 @@ BdrvChild *bdrv_open_child(const char *filename,
|
||||
|
||||
bs = NULL;
|
||||
ret = bdrv_open_inherit(&bs, filename, reference, image_options, 0,
|
||||
parent, child_role, NULL, errp);
|
||||
parent, child_role, errp);
|
||||
if (ret < 0) {
|
||||
goto done;
|
||||
}
|
||||
@@ -1385,11 +1361,13 @@ int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
|
||||
qstring_from_str("file"));
|
||||
qdict_put(snapshot_options, "file.filename",
|
||||
qstring_from_str(tmp_filename));
|
||||
qdict_put(snapshot_options, "driver",
|
||||
qstring_from_str("qcow2"));
|
||||
|
||||
bs_snapshot = bdrv_new();
|
||||
|
||||
ret = bdrv_open(&bs_snapshot, NULL, NULL, snapshot_options,
|
||||
flags, &bdrv_qcow2, &local_err);
|
||||
flags, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto out;
|
||||
@@ -1420,11 +1398,11 @@ out:
|
||||
static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
|
||||
const char *reference, QDict *options, int flags,
|
||||
BlockDriverState *parent,
|
||||
const BdrvChildRole *child_role,
|
||||
BlockDriver *drv, Error **errp)
|
||||
const BdrvChildRole *child_role, Error **errp)
|
||||
{
|
||||
int ret;
|
||||
BlockDriverState *file = NULL, *bs;
|
||||
BlockDriver *drv = NULL;
|
||||
const char *drvname;
|
||||
Error *local_err = NULL;
|
||||
int snapshot_flags = 0;
|
||||
@@ -1474,13 +1452,12 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
|
||||
flags = child_role->inherit_flags(parent->open_flags);
|
||||
}
|
||||
|
||||
ret = bdrv_fill_options(&options, &filename, &flags, drv, &local_err);
|
||||
ret = bdrv_fill_options(&options, &filename, &flags, &local_err);
|
||||
if (local_err) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Find the right image format driver */
|
||||
drv = NULL;
|
||||
drvname = qdict_get_try_str(options, "driver");
|
||||
if (drvname) {
|
||||
drv = bdrv_find_format(drvname);
|
||||
@@ -1635,11 +1612,10 @@ close_and_fail:
|
||||
}
|
||||
|
||||
int bdrv_open(BlockDriverState **pbs, const char *filename,
|
||||
const char *reference, QDict *options, int flags,
|
||||
BlockDriver *drv, Error **errp)
|
||||
const char *reference, QDict *options, int flags, Error **errp)
|
||||
{
|
||||
return bdrv_open_inherit(pbs, filename, reference, options, flags, NULL,
|
||||
NULL, drv, errp);
|
||||
NULL, errp);
|
||||
}
|
||||
|
||||
typedef struct BlockReopenQueueEntry {
|
||||
@@ -1660,6 +1636,9 @@ typedef struct BlockReopenQueueEntry {
|
||||
*
|
||||
* bs is the BlockDriverState to add to the reopen queue.
|
||||
*
|
||||
* options contains the changed options for the associated bs
|
||||
* (the BlockReopenQueue takes ownership)
|
||||
*
|
||||
* flags contains the open flags for the associated bs
|
||||
*
|
||||
* returns a pointer to bs_queue, which is either the newly allocated
|
||||
@@ -1667,18 +1646,28 @@ typedef struct BlockReopenQueueEntry {
|
||||
*
|
||||
*/
|
||||
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
|
||||
BlockDriverState *bs, int flags)
|
||||
BlockDriverState *bs,
|
||||
QDict *options, int flags)
|
||||
{
|
||||
assert(bs != NULL);
|
||||
|
||||
BlockReopenQueueEntry *bs_entry;
|
||||
BdrvChild *child;
|
||||
QDict *old_options;
|
||||
|
||||
if (bs_queue == NULL) {
|
||||
bs_queue = g_new0(BlockReopenQueue, 1);
|
||||
QSIMPLEQ_INIT(bs_queue);
|
||||
}
|
||||
|
||||
if (!options) {
|
||||
options = qdict_new();
|
||||
}
|
||||
|
||||
old_options = qdict_clone_shallow(bs->options);
|
||||
qdict_join(options, old_options, false);
|
||||
QDECREF(old_options);
|
||||
|
||||
/* bdrv_open() masks this flag out */
|
||||
flags &= ~BDRV_O_PROTOCOL;
|
||||
|
||||
@@ -1690,13 +1679,15 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
|
||||
}
|
||||
|
||||
child_flags = child->role->inherit_flags(flags);
|
||||
bdrv_reopen_queue(bs_queue, child->bs, child_flags);
|
||||
/* TODO Pass down child flags (backing.*, extents.*, ...) */
|
||||
bdrv_reopen_queue(bs_queue, child->bs, NULL, child_flags);
|
||||
}
|
||||
|
||||
bs_entry = g_new0(BlockReopenQueueEntry, 1);
|
||||
QSIMPLEQ_INSERT_TAIL(bs_queue, bs_entry, entry);
|
||||
|
||||
bs_entry->state.bs = bs;
|
||||
bs_entry->state.options = options;
|
||||
bs_entry->state.flags = flags;
|
||||
|
||||
return bs_queue;
|
||||
@@ -1749,6 +1740,7 @@ cleanup:
|
||||
if (ret && bs_entry->prepared) {
|
||||
bdrv_reopen_abort(&bs_entry->state);
|
||||
}
|
||||
QDECREF(bs_entry->state.options);
|
||||
g_free(bs_entry);
|
||||
}
|
||||
g_free(bs_queue);
|
||||
@@ -1761,7 +1753,7 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp)
|
||||
{
|
||||
int ret = -1;
|
||||
Error *local_err = NULL;
|
||||
BlockReopenQueue *queue = bdrv_reopen_queue(NULL, bs, bdrv_flags);
|
||||
BlockReopenQueue *queue = bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags);
|
||||
|
||||
ret = bdrv_reopen_multiple(queue, &local_err);
|
||||
if (local_err != NULL) {
|
||||
@@ -1837,6 +1829,26 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Options that are not handled are only okay if they are unchanged
|
||||
* compared to the old state. It is expected that some options are only
|
||||
* used for the initial open, but not reopen (e.g. filename) */
|
||||
if (qdict_size(reopen_state->options)) {
|
||||
const QDictEntry *entry = qdict_first(reopen_state->options);
|
||||
|
||||
do {
|
||||
QString *new_obj = qobject_to_qstring(entry->value);
|
||||
const char *new = qstring_get_str(new_obj);
|
||||
const char *old = qdict_get_try_str(reopen_state->bs->options,
|
||||
entry->key);
|
||||
|
||||
if (!old || strcmp(new, old)) {
|
||||
error_setg(errp, "Cannot change the option '%s'", entry->key);
|
||||
ret = -EINVAL;
|
||||
goto error;
|
||||
}
|
||||
} while ((entry = qdict_next(reopen_state->options, entry)));
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
error:
|
||||
@@ -3739,7 +3751,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
const char *backing_fmt, *backing_file;
|
||||
int64_t size;
|
||||
BlockDriver *drv, *proto_drv;
|
||||
BlockDriver *backing_drv = NULL;
|
||||
Error *local_err = NULL;
|
||||
int ret = 0;
|
||||
|
||||
@@ -3813,14 +3824,6 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
}
|
||||
|
||||
backing_fmt = qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT);
|
||||
if (backing_fmt) {
|
||||
backing_drv = bdrv_find_format(backing_fmt);
|
||||
if (!backing_drv) {
|
||||
error_setg(errp, "Unknown backing file format '%s'",
|
||||
backing_fmt);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
// The size for the image must always be specified, with one exception:
|
||||
// If we are using a backing file, we can obtain the size from there
|
||||
@@ -3831,6 +3834,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
char *full_backing = g_new0(char, PATH_MAX);
|
||||
int64_t size;
|
||||
int back_flags;
|
||||
QDict *backing_options = NULL;
|
||||
|
||||
bdrv_get_full_backing_filename_from_filename(filename, backing_file,
|
||||
full_backing, PATH_MAX,
|
||||
@@ -3844,9 +3848,15 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
back_flags =
|
||||
flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
|
||||
|
||||
if (backing_fmt) {
|
||||
backing_options = qdict_new();
|
||||
qdict_put(backing_options, "driver",
|
||||
qstring_from_str(backing_fmt));
|
||||
}
|
||||
|
||||
bs = NULL;
|
||||
ret = bdrv_open(&bs, full_backing, NULL, NULL, back_flags,
|
||||
backing_drv, &local_err);
|
||||
ret = bdrv_open(&bs, full_backing, NULL, backing_options,
|
||||
back_flags, &local_err);
|
||||
g_free(full_backing);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
|
||||
@@ -126,7 +126,7 @@ BlockBackend *blk_new_open(const char *name, const char *filename,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = bdrv_open(&blk->bs, filename, reference, options, flags, NULL, errp);
|
||||
ret = bdrv_open(&blk->bs, filename, reference, options, flags, errp);
|
||||
if (ret < 0) {
|
||||
blk_unref(blk);
|
||||
return NULL;
|
||||
|
||||
+2
-2
@@ -236,11 +236,11 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
|
||||
|
||||
/* convert base & overlay_bs to r/w, if necessary */
|
||||
if (!(orig_base_flags & BDRV_O_RDWR)) {
|
||||
reopen_queue = bdrv_reopen_queue(reopen_queue, base,
|
||||
reopen_queue = bdrv_reopen_queue(reopen_queue, base, NULL,
|
||||
orig_base_flags | BDRV_O_RDWR);
|
||||
}
|
||||
if (!(orig_overlay_flags & BDRV_O_RDWR)) {
|
||||
reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs,
|
||||
reopen_queue = bdrv_reopen_queue(reopen_queue, overlay_bs, NULL,
|
||||
orig_overlay_flags | BDRV_O_RDWR);
|
||||
}
|
||||
if (reopen_queue) {
|
||||
|
||||
+1
-1
@@ -476,7 +476,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
file = NULL;
|
||||
ret = bdrv_open(&file, filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
return ret;
|
||||
|
||||
+1
-1
@@ -793,7 +793,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
qcow_bs = NULL;
|
||||
ret = bdrv_open(&qcow_bs, filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto cleanup;
|
||||
|
||||
+7
-7
@@ -55,14 +55,14 @@ struct Qcow2Cache {
|
||||
static inline void *qcow2_cache_get_table_addr(BlockDriverState *bs,
|
||||
Qcow2Cache *c, int table)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
return (uint8_t *) c->table_array + (size_t) table * s->cluster_size;
|
||||
}
|
||||
|
||||
static inline int qcow2_cache_get_table_idx(BlockDriverState *bs,
|
||||
Qcow2Cache *c, void *table)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
ptrdiff_t table_offset = (uint8_t *) table - (uint8_t *) c->table_array;
|
||||
int idx = table_offset / s->cluster_size;
|
||||
assert(idx >= 0 && idx < c->size && table_offset % s->cluster_size == 0);
|
||||
@@ -73,7 +73,7 @@ static void qcow2_cache_table_release(BlockDriverState *bs, Qcow2Cache *c,
|
||||
int i, int num_tables)
|
||||
{
|
||||
#if QEMU_MADV_DONTNEED != QEMU_MADV_INVALID
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
void *t = qcow2_cache_get_table_addr(bs, c, i);
|
||||
int align = getpagesize();
|
||||
size_t mem_size = (size_t) s->cluster_size * num_tables;
|
||||
@@ -121,7 +121,7 @@ void qcow2_cache_clean_unused(BlockDriverState *bs, Qcow2Cache *c)
|
||||
|
||||
Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
Qcow2Cache *c;
|
||||
|
||||
c = g_new0(Qcow2Cache, 1);
|
||||
@@ -172,7 +172,7 @@ static int qcow2_cache_flush_dependency(BlockDriverState *bs, Qcow2Cache *c)
|
||||
|
||||
static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret = 0;
|
||||
|
||||
if (!c->entries[i].dirty || !c->entries[i].offset) {
|
||||
@@ -229,7 +229,7 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
|
||||
|
||||
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int result = 0;
|
||||
int ret;
|
||||
int i;
|
||||
@@ -306,7 +306,7 @@ int qcow2_cache_empty(BlockDriverState *bs, Qcow2Cache *c)
|
||||
static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
|
||||
uint64_t offset, void **table, bool read_from_disk)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int i;
|
||||
int ret;
|
||||
int lookup_index;
|
||||
|
||||
+42
-34
@@ -32,7 +32,7 @@
|
||||
int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
|
||||
bool exact_size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int new_l1_size2, ret, i;
|
||||
uint64_t *new_l1_table;
|
||||
int64_t old_l1_table_offset, old_l1_size;
|
||||
@@ -148,7 +148,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
|
||||
static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
|
||||
uint64_t **l2_table)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
ret = qcow2_cache_get(bs, s->l2_table_cache, l2_offset, (void**) l2_table);
|
||||
@@ -163,7 +163,7 @@ static int l2_load(BlockDriverState *bs, uint64_t l2_offset,
|
||||
#define L1_ENTRIES_PER_SECTOR (512 / 8)
|
||||
int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t buf[L1_ENTRIES_PER_SECTOR] = { 0 };
|
||||
int l1_start_index;
|
||||
int i, ret;
|
||||
@@ -203,7 +203,7 @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
|
||||
|
||||
static int l2_allocate(BlockDriverState *bs, int l1_index, uint64_t **table)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t old_l2_offset;
|
||||
uint64_t *l2_table = NULL;
|
||||
int64_t l2_offset;
|
||||
@@ -298,7 +298,7 @@ fail:
|
||||
* as contiguous. (This allows it, for example, to stop at the first compressed
|
||||
* cluster which may require a different handling)
|
||||
*/
|
||||
static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
|
||||
static int count_contiguous_clusters(int nb_clusters, int cluster_size,
|
||||
uint64_t *l2_table, uint64_t stop_flags)
|
||||
{
|
||||
int i;
|
||||
@@ -321,7 +321,7 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
|
||||
return i;
|
||||
}
|
||||
|
||||
static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_table)
|
||||
static int count_contiguous_free_clusters(int nb_clusters, uint64_t *l2_table)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -339,7 +339,7 @@ static int count_contiguous_free_clusters(uint64_t nb_clusters, uint64_t *l2_tab
|
||||
/* The crypt function is compatible with the linux cryptoloop
|
||||
algorithm for < 4 GB images. NOTE: out_buf == in_buf is
|
||||
supported */
|
||||
int qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
||||
int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
|
||||
uint8_t *out_buf, const uint8_t *in_buf,
|
||||
int nb_sectors, bool enc,
|
||||
Error **errp)
|
||||
@@ -387,7 +387,7 @@ static int coroutine_fn copy_sectors(BlockDriverState *bs,
|
||||
uint64_t cluster_offset,
|
||||
int n_start, int n_end)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QEMUIOVector qiov;
|
||||
struct iovec iov;
|
||||
int n, ret;
|
||||
@@ -469,7 +469,7 @@ out:
|
||||
int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
||||
int *num, uint64_t *cluster_offset)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
unsigned int l2_index;
|
||||
uint64_t l1_index, l2_offset, *l2_table;
|
||||
int l1_bits, c;
|
||||
@@ -495,6 +495,7 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
||||
if (nb_needed > nb_available) {
|
||||
nb_needed = nb_available;
|
||||
}
|
||||
assert(nb_needed <= INT_MAX);
|
||||
|
||||
*cluster_offset = 0;
|
||||
|
||||
@@ -530,6 +531,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
|
||||
*cluster_offset = be64_to_cpu(l2_table[l2_index]);
|
||||
|
||||
/* nb_needed <= INT_MAX, thus nb_clusters <= INT_MAX, too */
|
||||
nb_clusters = size_to_clusters(s, nb_needed << 9);
|
||||
|
||||
ret = qcow2_get_cluster_type(*cluster_offset);
|
||||
@@ -606,7 +609,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t offset,
|
||||
uint64_t **new_l2_table,
|
||||
int *new_l2_index)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
unsigned int l2_index;
|
||||
uint64_t l1_index, l2_offset;
|
||||
uint64_t *l2_table = NULL;
|
||||
@@ -680,7 +683,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
|
||||
uint64_t offset,
|
||||
int compressed_size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int l2_index, ret;
|
||||
uint64_t *l2_table;
|
||||
int64_t cluster_offset;
|
||||
@@ -725,7 +728,7 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs,
|
||||
|
||||
static int perform_cow(BlockDriverState *bs, QCowL2Meta *m, Qcow2COWRegion *r)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
if (r->nb_sectors == 0) {
|
||||
@@ -754,7 +757,7 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m, Qcow2COWRegion *r)
|
||||
|
||||
int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int i, j = 0, l2_index, ret;
|
||||
uint64_t *old_cluster, *l2_table;
|
||||
uint64_t cluster_offset = m->alloc_offset;
|
||||
@@ -837,7 +840,7 @@ err:
|
||||
* write, but require COW to be performed (this includes yet unallocated space,
|
||||
* which must copy from the backing file)
|
||||
*/
|
||||
static int count_cow_clusters(BDRVQcowState *s, int nb_clusters,
|
||||
static int count_cow_clusters(BDRVQcow2State *s, int nb_clusters,
|
||||
uint64_t *l2_table, int l2_index)
|
||||
{
|
||||
int i;
|
||||
@@ -883,7 +886,7 @@ out:
|
||||
static int handle_dependencies(BlockDriverState *bs, uint64_t guest_offset,
|
||||
uint64_t *cur_bytes, QCowL2Meta **m)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowL2Meta *old_alloc;
|
||||
uint64_t bytes = *cur_bytes;
|
||||
|
||||
@@ -956,11 +959,11 @@ static int handle_dependencies(BlockDriverState *bs, uint64_t guest_offset,
|
||||
static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
|
||||
uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int l2_index;
|
||||
uint64_t cluster_offset;
|
||||
uint64_t *l2_table;
|
||||
unsigned int nb_clusters;
|
||||
uint64_t nb_clusters;
|
||||
unsigned int keep_clusters;
|
||||
int ret;
|
||||
|
||||
@@ -979,6 +982,7 @@ static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
|
||||
|
||||
l2_index = offset_to_l2_index(s, guest_offset);
|
||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
||||
assert(nb_clusters <= INT_MAX);
|
||||
|
||||
/* Find L2 entry for the first involved cluster */
|
||||
ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);
|
||||
@@ -1061,9 +1065,9 @@ out:
|
||||
* restarted, but the whole request should not be failed.
|
||||
*/
|
||||
static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset,
|
||||
uint64_t *host_offset, unsigned int *nb_clusters)
|
||||
uint64_t *host_offset, uint64_t *nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
|
||||
trace_qcow2_do_alloc_clusters_offset(qemu_coroutine_self(), guest_offset,
|
||||
*host_offset, *nb_clusters);
|
||||
@@ -1079,7 +1083,7 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset,
|
||||
*host_offset = cluster_offset;
|
||||
return 0;
|
||||
} else {
|
||||
int ret = qcow2_alloc_clusters_at(bs, *host_offset, *nb_clusters);
|
||||
int64_t ret = qcow2_alloc_clusters_at(bs, *host_offset, *nb_clusters);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -1111,11 +1115,11 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_offset,
|
||||
static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
|
||||
uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int l2_index;
|
||||
uint64_t *l2_table;
|
||||
uint64_t entry;
|
||||
unsigned int nb_clusters;
|
||||
uint64_t nb_clusters;
|
||||
int ret;
|
||||
|
||||
uint64_t alloc_cluster_offset;
|
||||
@@ -1133,6 +1137,7 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
|
||||
|
||||
l2_index = offset_to_l2_index(s, guest_offset);
|
||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
||||
assert(nb_clusters <= INT_MAX);
|
||||
|
||||
/* Find L2 entry for the first involved cluster */
|
||||
ret = get_cluster_table(bs, guest_offset, &l2_table, &l2_index);
|
||||
@@ -1263,7 +1268,7 @@ fail:
|
||||
int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
|
||||
int *num, uint64_t *host_offset, QCowL2Meta **m)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t start, remaining;
|
||||
uint64_t cluster_offset;
|
||||
uint64_t cur_bytes;
|
||||
@@ -1397,7 +1402,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
||||
|
||||
int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret, csize, nb_csectors, sector_offset;
|
||||
uint64_t coffset;
|
||||
|
||||
@@ -1426,9 +1431,10 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
|
||||
* clusters.
|
||||
*/
|
||||
static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
unsigned int nb_clusters, enum qcow2_discard_type type, bool full_discard)
|
||||
uint64_t nb_clusters, enum qcow2_discard_type type,
|
||||
bool full_discard)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l2_table;
|
||||
int l2_index;
|
||||
int ret;
|
||||
@@ -1441,6 +1447,7 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
/* Limit nb_clusters to one L2 table */
|
||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
||||
assert(nb_clusters <= INT_MAX);
|
||||
|
||||
for (i = 0; i < nb_clusters; i++) {
|
||||
uint64_t old_l2_entry;
|
||||
@@ -1501,9 +1508,9 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset,
|
||||
int nb_sectors, enum qcow2_discard_type type, bool full_discard)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t end_offset;
|
||||
unsigned int nb_clusters;
|
||||
uint64_t nb_clusters;
|
||||
int ret;
|
||||
|
||||
end_offset = offset + (nb_sectors << BDRV_SECTOR_BITS);
|
||||
@@ -1545,9 +1552,9 @@ fail:
|
||||
* clusters.
|
||||
*/
|
||||
static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
unsigned int nb_clusters)
|
||||
uint64_t nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l2_table;
|
||||
int l2_index;
|
||||
int ret;
|
||||
@@ -1560,6 +1567,7 @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
/* Limit nb_clusters to one L2 table */
|
||||
nb_clusters = MIN(nb_clusters, s->l2_size - l2_index);
|
||||
assert(nb_clusters <= INT_MAX);
|
||||
|
||||
for (i = 0; i < nb_clusters; i++) {
|
||||
uint64_t old_offset;
|
||||
@@ -1583,8 +1591,8 @@ static int zero_single_l2(BlockDriverState *bs, uint64_t offset,
|
||||
|
||||
int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
unsigned int nb_clusters;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t nb_clusters;
|
||||
int ret;
|
||||
|
||||
/* The zero flag is only supported by version 3 and newer */
|
||||
@@ -1628,7 +1636,7 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
|
||||
int64_t l1_entries,
|
||||
BlockDriverAmendStatusCB *status_cb)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
bool is_active_l1 = (l1_table == s->l1_table);
|
||||
uint64_t *l2_table = NULL;
|
||||
int ret;
|
||||
@@ -1815,7 +1823,7 @@ fail:
|
||||
int qcow2_expand_zero_clusters(BlockDriverState *bs,
|
||||
BlockDriverAmendStatusCB *status_cb)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l1_table = NULL;
|
||||
int64_t l1_entries = 0, visited_l1_entries = 0;
|
||||
int ret;
|
||||
|
||||
+43
-33
@@ -82,7 +82,7 @@ static Qcow2SetRefcountFunc *const set_refcount_funcs[] = {
|
||||
|
||||
int qcow2_refcount_init(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
unsigned int refcount_table_size2, i;
|
||||
int ret;
|
||||
|
||||
@@ -116,7 +116,7 @@ int qcow2_refcount_init(BlockDriverState *bs)
|
||||
|
||||
void qcow2_refcount_close(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
g_free(s->refcount_table);
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ static int load_refcount_block(BlockDriverState *bs,
|
||||
int64_t refcount_block_offset,
|
||||
void **refcount_block)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_LOAD);
|
||||
@@ -231,7 +231,7 @@ static int load_refcount_block(BlockDriverState *bs,
|
||||
int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
|
||||
uint64_t *refcount)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t refcount_table_index, block_index;
|
||||
int64_t refcount_block_offset;
|
||||
int ret;
|
||||
@@ -274,7 +274,7 @@ int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index,
|
||||
* Rounds the refcount table size up to avoid growing the table for each single
|
||||
* refcount block that is allocated.
|
||||
*/
|
||||
static unsigned int next_refcount_table_size(BDRVQcowState *s,
|
||||
static unsigned int next_refcount_table_size(BDRVQcow2State *s,
|
||||
unsigned int min_size)
|
||||
{
|
||||
unsigned int min_clusters = (min_size >> (s->cluster_bits - 3)) + 1;
|
||||
@@ -290,7 +290,7 @@ static unsigned int next_refcount_table_size(BDRVQcowState *s,
|
||||
|
||||
|
||||
/* Checks if two offsets are described by the same refcount block */
|
||||
static int in_same_refcount_block(BDRVQcowState *s, uint64_t offset_a,
|
||||
static int in_same_refcount_block(BDRVQcow2State *s, uint64_t offset_a,
|
||||
uint64_t offset_b)
|
||||
{
|
||||
uint64_t block_a = offset_a >> (s->cluster_bits + s->refcount_block_bits);
|
||||
@@ -308,7 +308,7 @@ static int in_same_refcount_block(BDRVQcowState *s, uint64_t offset_a,
|
||||
static int alloc_refcount_block(BlockDriverState *bs,
|
||||
int64_t cluster_index, void **refcount_block)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
unsigned int refcount_table_index;
|
||||
int ret;
|
||||
|
||||
@@ -605,7 +605,7 @@ fail_block:
|
||||
|
||||
void qcow2_process_discards(BlockDriverState *bs, int ret)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
Qcow2DiscardRegion *d, *next;
|
||||
|
||||
QTAILQ_FOREACH_SAFE(d, &s->discards, next, next) {
|
||||
@@ -625,7 +625,7 @@ void qcow2_process_discards(BlockDriverState *bs, int ret)
|
||||
static void update_refcount_discard(BlockDriverState *bs,
|
||||
uint64_t offset, uint64_t length)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
Qcow2DiscardRegion *d, *p, *next;
|
||||
|
||||
QTAILQ_FOREACH(d, &s->discards, next) {
|
||||
@@ -682,7 +682,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs,
|
||||
bool decrease,
|
||||
enum qcow2_discard_type type)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t start, last, cluster_offset;
|
||||
void *refcount_block = NULL;
|
||||
int64_t old_table_index = -1;
|
||||
@@ -793,7 +793,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs,
|
||||
uint64_t addend, bool decrease,
|
||||
enum qcow2_discard_type type)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int ret;
|
||||
|
||||
ret = update_refcount(bs, cluster_index << s->cluster_bits, 1, addend,
|
||||
@@ -815,7 +815,7 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs,
|
||||
/* return < 0 if error */
|
||||
static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t i, nb_clusters, refcount;
|
||||
int ret;
|
||||
|
||||
@@ -875,10 +875,10 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size)
|
||||
return offset;
|
||||
}
|
||||
|
||||
int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
||||
int nb_clusters)
|
||||
int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
||||
int64_t nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t cluster_index, refcount;
|
||||
uint64_t i;
|
||||
int ret;
|
||||
@@ -916,7 +916,7 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
||||
contiguous sectors. size must be <= cluster_size */
|
||||
int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t offset;
|
||||
size_t free_in_cluster;
|
||||
int ret;
|
||||
@@ -949,11 +949,17 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size)
|
||||
|
||||
if (!offset || ROUND_UP(offset, s->cluster_size) != new_cluster) {
|
||||
offset = new_cluster;
|
||||
free_in_cluster = s->cluster_size;
|
||||
} else {
|
||||
free_in_cluster += s->cluster_size;
|
||||
}
|
||||
}
|
||||
|
||||
assert(offset);
|
||||
ret = update_refcount(bs, offset, size, 1, false, QCOW2_DISCARD_NEVER);
|
||||
if (ret < 0) {
|
||||
offset = 0;
|
||||
}
|
||||
} while (ret == -EAGAIN);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
@@ -992,7 +998,7 @@ void qcow2_free_clusters(BlockDriverState *bs,
|
||||
void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
|
||||
int nb_clusters, enum qcow2_discard_type type)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
|
||||
switch (qcow2_get_cluster_type(l2_entry)) {
|
||||
case QCOW2_CLUSTER_COMPRESSED:
|
||||
@@ -1036,7 +1042,7 @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
|
||||
int qcow2_update_snapshot_refcount(BlockDriverState *bs,
|
||||
int64_t l1_table_offset, int l1_size, int addend)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l1_table, *l2_table, l2_offset, offset, l1_size2, refcount;
|
||||
bool l1_allocated = false;
|
||||
int64_t old_offset, old_l2_offset;
|
||||
@@ -1233,7 +1239,7 @@ fail:
|
||||
/* refcount checking functions */
|
||||
|
||||
|
||||
static size_t refcount_array_byte_size(BDRVQcowState *s, uint64_t entries)
|
||||
static size_t refcount_array_byte_size(BDRVQcow2State *s, uint64_t entries)
|
||||
{
|
||||
/* This assertion holds because there is no way we can address more than
|
||||
* 2^(64 - 9) clusters at once (with cluster size 512 = 2^9, and because
|
||||
@@ -1256,10 +1262,10 @@ static size_t refcount_array_byte_size(BDRVQcowState *s, uint64_t entries)
|
||||
* refcount array buffer will be aligned to a cluster boundary, and the newly
|
||||
* allocated area will be zeroed.
|
||||
*/
|
||||
static int realloc_refcount_array(BDRVQcowState *s, void **array,
|
||||
static int realloc_refcount_array(BDRVQcow2State *s, void **array,
|
||||
int64_t *size, int64_t new_size)
|
||||
{
|
||||
size_t old_byte_size, new_byte_size;
|
||||
int64_t old_byte_size, new_byte_size;
|
||||
void *new_ptr;
|
||||
|
||||
/* Round to clusters so the array can be directly written to disk */
|
||||
@@ -1275,13 +1281,17 @@ static int realloc_refcount_array(BDRVQcowState *s, void **array,
|
||||
|
||||
assert(new_byte_size > 0);
|
||||
|
||||
if (new_byte_size > SIZE_MAX) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
new_ptr = g_try_realloc(*array, new_byte_size);
|
||||
if (!new_ptr) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (new_byte_size > old_byte_size) {
|
||||
memset((void *)((uintptr_t)new_ptr + old_byte_size), 0,
|
||||
memset((char *)new_ptr + old_byte_size, 0,
|
||||
new_byte_size - old_byte_size);
|
||||
}
|
||||
|
||||
@@ -1304,7 +1314,7 @@ static int inc_refcounts(BlockDriverState *bs,
|
||||
int64_t *refcount_table_size,
|
||||
int64_t offset, int64_t size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t start, last, cluster_offset, k, refcount;
|
||||
int ret;
|
||||
|
||||
@@ -1357,7 +1367,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
int64_t *refcount_table_size, int64_t l2_offset,
|
||||
int flags)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l2_table, l2_entry;
|
||||
uint64_t next_contiguous_offset = 0;
|
||||
int i, l2_size, nb_csectors, ret;
|
||||
@@ -1477,7 +1487,7 @@ static int check_refcounts_l1(BlockDriverState *bs,
|
||||
int64_t l1_table_offset, int l1_size,
|
||||
int flags)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l1_table = NULL, l2_offset, l1_size2;
|
||||
int i, ret;
|
||||
|
||||
@@ -1554,7 +1564,7 @@ fail:
|
||||
static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
BdrvCheckMode fix)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
uint64_t *l2_table = qemu_blockalign(bs, s->cluster_size);
|
||||
int ret;
|
||||
uint64_t refcount;
|
||||
@@ -1673,7 +1683,7 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
BdrvCheckMode fix, bool *rebuild,
|
||||
void **refcount_table, int64_t *nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t i, size;
|
||||
int ret;
|
||||
|
||||
@@ -1776,7 +1786,7 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
BdrvCheckMode fix, bool *rebuild,
|
||||
void **refcount_table, int64_t *nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t i;
|
||||
QCowSnapshot *sn;
|
||||
int ret;
|
||||
@@ -1840,7 +1850,7 @@ static void compare_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
int64_t *highest_cluster,
|
||||
void *refcount_table, int64_t nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t i;
|
||||
uint64_t refcount1, refcount2;
|
||||
int ret;
|
||||
@@ -1917,7 +1927,7 @@ static int64_t alloc_clusters_imrt(BlockDriverState *bs,
|
||||
int64_t *imrt_nb_clusters,
|
||||
int64_t *first_free_cluster)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t cluster = *first_free_cluster, i;
|
||||
bool first_gap = true;
|
||||
int contiguous_free_clusters;
|
||||
@@ -1987,7 +1997,7 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
|
||||
void **refcount_table,
|
||||
int64_t *nb_clusters)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int64_t first_free_cluster = 0, reftable_offset = -1, cluster = 0;
|
||||
int64_t refblock_offset, refblock_start, refblock_index;
|
||||
uint32_t reftable_size = 0;
|
||||
@@ -2174,7 +2184,7 @@ fail:
|
||||
int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
|
||||
BdrvCheckMode fix)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
BdrvCheckResult pre_compare_res;
|
||||
int64_t size, highest_cluster, nb_clusters;
|
||||
void *refcount_table = NULL;
|
||||
@@ -2311,7 +2321,7 @@ fail:
|
||||
int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
|
||||
int64_t size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int chk = s->overlap_check & ~ign;
|
||||
int i, j;
|
||||
|
||||
|
||||
+10
-10
@@ -29,7 +29,7 @@
|
||||
|
||||
void qcow2_free_snapshots(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int i;
|
||||
|
||||
for(i = 0; i < s->nb_snapshots; i++) {
|
||||
@@ -43,7 +43,7 @@ void qcow2_free_snapshots(BlockDriverState *bs)
|
||||
|
||||
int qcow2_read_snapshots(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshotHeader h;
|
||||
QCowSnapshotExtraData extra;
|
||||
QCowSnapshot *sn;
|
||||
@@ -136,7 +136,7 @@ fail:
|
||||
/* add at the end of the file a new list of snapshots */
|
||||
static int qcow2_write_snapshots(BlockDriverState *bs)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot *sn;
|
||||
QCowSnapshotHeader h;
|
||||
QCowSnapshotExtraData extra;
|
||||
@@ -278,7 +278,7 @@ fail:
|
||||
static void find_new_snapshot_id(BlockDriverState *bs,
|
||||
char *id_str, int id_str_size)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot *sn;
|
||||
int i;
|
||||
unsigned long id, id_max = 0;
|
||||
@@ -296,7 +296,7 @@ static int find_snapshot_by_id_and_name(BlockDriverState *bs,
|
||||
const char *id,
|
||||
const char *name)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
int i;
|
||||
|
||||
if (id && name) {
|
||||
@@ -338,7 +338,7 @@ static int find_snapshot_by_id_or_name(BlockDriverState *bs,
|
||||
/* if no id is provided, a new one is constructed */
|
||||
int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot *new_snapshot_list = NULL;
|
||||
QCowSnapshot *old_snapshot_list = NULL;
|
||||
QCowSnapshot sn1, *sn = &sn1;
|
||||
@@ -461,7 +461,7 @@ fail:
|
||||
/* copy the snapshot 'snapshot_name' into the current disk image */
|
||||
int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot *sn;
|
||||
int i, snapshot_index;
|
||||
int cur_l1_bytes, sn_l1_bytes;
|
||||
@@ -587,7 +587,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
|
||||
const char *name,
|
||||
Error **errp)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot sn;
|
||||
int snapshot_index, ret;
|
||||
|
||||
@@ -650,7 +650,7 @@ int qcow2_snapshot_delete(BlockDriverState *bs,
|
||||
|
||||
int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
|
||||
{
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QEMUSnapshotInfo *sn_tab, *sn_info;
|
||||
QCowSnapshot *sn;
|
||||
int i;
|
||||
@@ -683,7 +683,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs,
|
||||
Error **errp)
|
||||
{
|
||||
int i, snapshot_index;
|
||||
BDRVQcowState *s = bs->opaque;
|
||||
BDRVQcow2State *s = bs->opaque;
|
||||
QCowSnapshot *sn;
|
||||
uint64_t *new_l1_table;
|
||||
int new_l1_bytes;
|
||||
|
||||
+318
-176
File diff suppressed because it is too large
Load Diff
+13
-13
@@ -222,7 +222,7 @@ typedef uint64_t Qcow2GetRefcountFunc(const void *refcount_array,
|
||||
typedef void Qcow2SetRefcountFunc(void *refcount_array,
|
||||
uint64_t index, uint64_t value);
|
||||
|
||||
typedef struct BDRVQcowState {
|
||||
typedef struct BDRVQcow2State {
|
||||
int cluster_bits;
|
||||
int cluster_size;
|
||||
int cluster_sectors;
|
||||
@@ -293,7 +293,7 @@ typedef struct BDRVQcowState {
|
||||
* override) */
|
||||
char *image_backing_file;
|
||||
char *image_backing_format;
|
||||
} BDRVQcowState;
|
||||
} BDRVQcow2State;
|
||||
|
||||
struct QCowAIOCB;
|
||||
|
||||
@@ -405,28 +405,28 @@ typedef enum QCow2MetadataOverlap {
|
||||
|
||||
#define REFT_OFFSET_MASK 0xfffffffffffffe00ULL
|
||||
|
||||
static inline int64_t start_of_cluster(BDRVQcowState *s, int64_t offset)
|
||||
static inline int64_t start_of_cluster(BDRVQcow2State *s, int64_t offset)
|
||||
{
|
||||
return offset & ~(s->cluster_size - 1);
|
||||
}
|
||||
|
||||
static inline int64_t offset_into_cluster(BDRVQcowState *s, int64_t offset)
|
||||
static inline int64_t offset_into_cluster(BDRVQcow2State *s, int64_t offset)
|
||||
{
|
||||
return offset & (s->cluster_size - 1);
|
||||
}
|
||||
|
||||
static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
|
||||
static inline uint64_t size_to_clusters(BDRVQcow2State *s, uint64_t size)
|
||||
{
|
||||
return (size + (s->cluster_size - 1)) >> s->cluster_bits;
|
||||
}
|
||||
|
||||
static inline int64_t size_to_l1(BDRVQcowState *s, int64_t size)
|
||||
static inline int64_t size_to_l1(BDRVQcow2State *s, int64_t size)
|
||||
{
|
||||
int shift = s->cluster_bits + s->l2_bits;
|
||||
return (size + (1ULL << shift) - 1) >> shift;
|
||||
}
|
||||
|
||||
static inline int offset_to_l2_index(BDRVQcowState *s, int64_t offset)
|
||||
static inline int offset_to_l2_index(BDRVQcow2State *s, int64_t offset)
|
||||
{
|
||||
return (offset >> s->cluster_bits) & (s->l2_size - 1);
|
||||
}
|
||||
@@ -437,12 +437,12 @@ static inline int64_t align_offset(int64_t offset, int n)
|
||||
return offset;
|
||||
}
|
||||
|
||||
static inline int64_t qcow2_vm_state_offset(BDRVQcowState *s)
|
||||
static inline int64_t qcow2_vm_state_offset(BDRVQcow2State *s)
|
||||
{
|
||||
return (int64_t)s->l1_vm_state_index << (s->cluster_bits + s->l2_bits);
|
||||
}
|
||||
|
||||
static inline uint64_t qcow2_max_refcount_clusters(BDRVQcowState *s)
|
||||
static inline uint64_t qcow2_max_refcount_clusters(BDRVQcow2State *s)
|
||||
{
|
||||
return QCOW_MAX_REFTABLE_SIZE >> s->cluster_bits;
|
||||
}
|
||||
@@ -461,7 +461,7 @@ static inline int qcow2_get_cluster_type(uint64_t l2_entry)
|
||||
}
|
||||
|
||||
/* Check whether refcounts are eager or lazy */
|
||||
static inline bool qcow2_need_accurate_refcounts(BDRVQcowState *s)
|
||||
static inline bool qcow2_need_accurate_refcounts(BDRVQcow2State *s)
|
||||
{
|
||||
return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
|
||||
}
|
||||
@@ -509,8 +509,8 @@ int qcow2_update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index,
|
||||
enum qcow2_discard_type type);
|
||||
|
||||
int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size);
|
||||
int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
||||
int nb_clusters);
|
||||
int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset,
|
||||
int64_t nb_clusters);
|
||||
int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size);
|
||||
void qcow2_free_clusters(BlockDriverState *bs,
|
||||
int64_t offset, int64_t size,
|
||||
@@ -537,7 +537,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
|
||||
int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index);
|
||||
void qcow2_l2_cache_reset(BlockDriverState *bs);
|
||||
int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
|
||||
int qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
|
||||
int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num,
|
||||
uint8_t *out_buf, const uint8_t *in_buf,
|
||||
int nb_sectors, bool enc, Error **errp);
|
||||
|
||||
|
||||
+1
-1
@@ -583,7 +583,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
||||
|
||||
bs = NULL;
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
|
||||
+2
-3
@@ -1554,7 +1554,7 @@ static int sd_prealloc(const char *filename, Error **errp)
|
||||
int ret;
|
||||
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
|
||||
NULL, errp);
|
||||
errp);
|
||||
if (ret < 0) {
|
||||
goto out_with_err_set;
|
||||
}
|
||||
@@ -1746,8 +1746,7 @@ static int sd_create(const char *filename, QemuOpts *opts,
|
||||
}
|
||||
|
||||
bs = NULL;
|
||||
ret = bdrv_open(&bs, backing_file, NULL, NULL, BDRV_O_PROTOCOL, NULL,
|
||||
errp);
|
||||
ret = bdrv_open(&bs, backing_file, NULL, NULL, BDRV_O_PROTOCOL, errp);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
+1
-1
@@ -764,7 +764,7 @@ static int vdi_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
goto exit;
|
||||
}
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
|
||||
NULL, &local_err);
|
||||
&local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto exit;
|
||||
|
||||
+1
-1
@@ -1842,7 +1842,7 @@ static int vhdx_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
|
||||
bs = NULL;
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
|
||||
NULL, &local_err);
|
||||
&local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto exit;
|
||||
|
||||
+9
-6
@@ -1324,8 +1324,12 @@ static int vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset,
|
||||
|
||||
write_end_sector = DIV_ROUND_UP(write_offset + write_len, BDRV_SECTOR_SIZE);
|
||||
|
||||
extent->next_cluster_sector = MAX(extent->next_cluster_sector,
|
||||
write_end_sector);
|
||||
if (extent->compressed) {
|
||||
extent->next_cluster_sector = write_end_sector;
|
||||
} else {
|
||||
extent->next_cluster_sector = MAX(extent->next_cluster_sector,
|
||||
write_end_sector);
|
||||
}
|
||||
|
||||
if (ret != write_len) {
|
||||
ret = ret < 0 ? ret : -EIO;
|
||||
@@ -1632,7 +1636,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
|
||||
|
||||
assert(bs == NULL);
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
|
||||
NULL, &local_err);
|
||||
&local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto exit;
|
||||
@@ -1905,8 +1909,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
ret = -ENOENT;
|
||||
goto exit;
|
||||
}
|
||||
ret = bdrv_open(&bs, full_backing, NULL, NULL, BDRV_O_NO_BACKING, NULL,
|
||||
errp);
|
||||
ret = bdrv_open(&bs, full_backing, NULL, NULL, BDRV_O_NO_BACKING, errp);
|
||||
g_free(full_backing);
|
||||
if (ret != 0) {
|
||||
goto exit;
|
||||
@@ -1977,7 +1980,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
assert(new_bs == NULL);
|
||||
ret = bdrv_open(&new_bs, filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, NULL, &local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto exit;
|
||||
|
||||
+1
-1
@@ -794,7 +794,7 @@ static int vpc_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
goto out;
|
||||
}
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, BDRV_O_RDWR | BDRV_O_PROTOCOL,
|
||||
NULL, &local_err);
|
||||
&local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto out;
|
||||
|
||||
+6
-2
@@ -2926,6 +2926,8 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
|
||||
QemuOpts *opts = NULL;
|
||||
int ret;
|
||||
int size = sector2cluster(s, s->sector_count);
|
||||
QDict *options;
|
||||
|
||||
s->used_clusters = calloc(size, 1);
|
||||
|
||||
array_init(&(s->commits), sizeof(commit_t));
|
||||
@@ -2956,9 +2958,11 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp)
|
||||
}
|
||||
|
||||
s->qcow = NULL;
|
||||
ret = bdrv_open(&s->qcow, s->qcow_filename, NULL, NULL,
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str("qcow"));
|
||||
ret = bdrv_open(&s->qcow, s->qcow_filename, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
|
||||
bdrv_qcow, errp);
|
||||
errp);
|
||||
if (ret < 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
+28
-44
@@ -1422,9 +1422,8 @@ typedef struct ExternalSnapshotState {
|
||||
static void external_snapshot_prepare(BlkTransactionState *common,
|
||||
Error **errp)
|
||||
{
|
||||
BlockDriver *drv;
|
||||
int flags, ret;
|
||||
QDict *options = NULL;
|
||||
QDict *options;
|
||||
Error *local_err = NULL;
|
||||
bool has_device = false;
|
||||
const char *device;
|
||||
@@ -1459,12 +1458,6 @@ static void external_snapshot_prepare(BlkTransactionState *common,
|
||||
}
|
||||
|
||||
/* start processing */
|
||||
drv = bdrv_find_format(format);
|
||||
if (!drv) {
|
||||
error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format);
|
||||
return;
|
||||
}
|
||||
|
||||
state->old_bs = bdrv_lookup_bs(has_device ? device : NULL,
|
||||
has_node_name ? node_name : NULL,
|
||||
&local_err);
|
||||
@@ -1523,17 +1516,18 @@ static void external_snapshot_prepare(BlkTransactionState *common,
|
||||
}
|
||||
}
|
||||
|
||||
options = qdict_new();
|
||||
if (has_snapshot_node_name) {
|
||||
options = qdict_new();
|
||||
qdict_put(options, "node-name",
|
||||
qstring_from_str(snapshot_node_name));
|
||||
}
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
|
||||
/* TODO Inherit bs->options or only take explicit options with an
|
||||
* extended QMP command? */
|
||||
assert(state->new_bs == NULL);
|
||||
ret = bdrv_open(&state->new_bs, new_image_file, NULL, options,
|
||||
flags | BDRV_O_NO_BACKING, drv, &local_err);
|
||||
flags | BDRV_O_NO_BACKING, &local_err);
|
||||
/* We will manually add the backing_hd field to the bs later */
|
||||
if (ret != 0) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -1895,13 +1889,19 @@ void qmp_block_passwd(bool has_device, const char *device,
|
||||
|
||||
/* Assumes AioContext is held */
|
||||
static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename,
|
||||
int bdrv_flags, BlockDriver *drv,
|
||||
int bdrv_flags, const char *format,
|
||||
const char *password, Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
QDict *options = NULL;
|
||||
int ret;
|
||||
|
||||
ret = bdrv_open(&bs, filename, NULL, NULL, bdrv_flags, drv, &local_err);
|
||||
if (format) {
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
}
|
||||
|
||||
ret = bdrv_open(&bs, filename, NULL, options, bdrv_flags, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
@@ -1916,7 +1916,6 @@ void qmp_change_blockdev(const char *device, const char *filename,
|
||||
BlockBackend *blk;
|
||||
BlockDriverState *bs;
|
||||
AioContext *aio_context;
|
||||
BlockDriver *drv = NULL;
|
||||
int bdrv_flags;
|
||||
Error *err = NULL;
|
||||
|
||||
@@ -1931,14 +1930,6 @@ void qmp_change_blockdev(const char *device, const char *filename,
|
||||
aio_context = bdrv_get_aio_context(bs);
|
||||
aio_context_acquire(aio_context);
|
||||
|
||||
if (format) {
|
||||
drv = bdrv_find_whitelisted_format(format, bs->read_only);
|
||||
if (!drv) {
|
||||
error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
eject_device(blk, 0, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
@@ -1948,7 +1939,7 @@ void qmp_change_blockdev(const char *device, const char *filename,
|
||||
bdrv_flags = bdrv_is_read_only(bs) ? 0 : BDRV_O_RDWR;
|
||||
bdrv_flags |= bdrv_is_snapshot(bs) ? BDRV_O_SNAPSHOT : 0;
|
||||
|
||||
qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, drv, NULL, errp);
|
||||
qmp_bdrv_open_encrypted(bs, filename, bdrv_flags, format, NULL, errp);
|
||||
|
||||
out:
|
||||
aio_context_release(aio_context);
|
||||
@@ -2466,7 +2457,7 @@ void qmp_drive_backup(const char *device, const char *target,
|
||||
BlockDriverState *source = NULL;
|
||||
BdrvDirtyBitmap *bmap = NULL;
|
||||
AioContext *aio_context;
|
||||
BlockDriver *drv = NULL;
|
||||
QDict *options = NULL;
|
||||
Error *local_err = NULL;
|
||||
int flags;
|
||||
int64_t size;
|
||||
@@ -2506,13 +2497,6 @@ void qmp_drive_backup(const char *device, const char *target,
|
||||
if (!has_format) {
|
||||
format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
|
||||
}
|
||||
if (format) {
|
||||
drv = bdrv_find_format(format);
|
||||
if (!drv) {
|
||||
error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Early check to avoid creating target */
|
||||
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_BACKUP_SOURCE, errp)) {
|
||||
@@ -2540,7 +2524,7 @@ void qmp_drive_backup(const char *device, const char *target,
|
||||
}
|
||||
|
||||
if (mode != NEW_IMAGE_MODE_EXISTING) {
|
||||
assert(format && drv);
|
||||
assert(format);
|
||||
if (source) {
|
||||
bdrv_img_create(target, format, source->filename,
|
||||
source->drv->format_name, NULL,
|
||||
@@ -2556,8 +2540,13 @@ void qmp_drive_backup(const char *device, const char *target,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (format) {
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
}
|
||||
|
||||
target_bs = NULL;
|
||||
ret = bdrv_open(&target_bs, target, NULL, NULL, flags, drv, &local_err);
|
||||
ret = bdrv_open(&target_bs, target, NULL, options, flags, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto out;
|
||||
@@ -2663,9 +2652,8 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
BlockDriverState *bs;
|
||||
BlockDriverState *source, *target_bs;
|
||||
AioContext *aio_context;
|
||||
BlockDriver *drv = NULL;
|
||||
Error *local_err = NULL;
|
||||
QDict *options = NULL;
|
||||
QDict *options;
|
||||
int flags;
|
||||
int64_t size;
|
||||
int ret;
|
||||
@@ -2722,13 +2710,6 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
if (!has_format) {
|
||||
format = mode == NEW_IMAGE_MODE_EXISTING ? NULL : bs->drv->format_name;
|
||||
}
|
||||
if (format) {
|
||||
drv = bdrv_find_format(format);
|
||||
if (!drv) {
|
||||
error_setg(errp, QERR_INVALID_BLOCK_FORMAT, format);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_MIRROR, errp)) {
|
||||
goto out;
|
||||
@@ -2783,7 +2764,7 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
&& mode != NEW_IMAGE_MODE_EXISTING)
|
||||
{
|
||||
/* create new image w/o backing file */
|
||||
assert(format && drv);
|
||||
assert(format);
|
||||
bdrv_img_create(target, format,
|
||||
NULL, NULL, NULL, size, flags, &local_err, false);
|
||||
} else {
|
||||
@@ -2807,17 +2788,20 @@ void qmp_drive_mirror(const char *device, const char *target,
|
||||
goto out;
|
||||
}
|
||||
|
||||
options = qdict_new();
|
||||
if (has_node_name) {
|
||||
options = qdict_new();
|
||||
qdict_put(options, "node-name", qstring_from_str(node_name));
|
||||
}
|
||||
if (format) {
|
||||
qdict_put(options, "driver", qstring_from_str(format));
|
||||
}
|
||||
|
||||
/* Mirroring takes care of copy-on-write using the source's backing
|
||||
* file.
|
||||
*/
|
||||
target_bs = NULL;
|
||||
ret = bdrv_open(&target_bs, target, NULL, options,
|
||||
flags | BDRV_O_NO_BACKING, drv, &local_err);
|
||||
flags | BDRV_O_NO_BACKING, &local_err);
|
||||
if (ret < 0) {
|
||||
error_propagate(errp, local_err);
|
||||
goto out;
|
||||
|
||||
@@ -147,6 +147,7 @@ typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
|
||||
typedef struct BDRVReopenState {
|
||||
BlockDriverState *bs;
|
||||
int flags;
|
||||
QDict *options;
|
||||
void *opaque;
|
||||
} BDRVReopenState;
|
||||
|
||||
@@ -193,8 +194,6 @@ BlockDriver *bdrv_find_protocol(const char *filename,
|
||||
bool allow_protocol_prefix,
|
||||
Error **errp);
|
||||
BlockDriver *bdrv_find_format(const char *format_name);
|
||||
BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
|
||||
bool readonly);
|
||||
int bdrv_create(BlockDriver *drv, const char* filename,
|
||||
QemuOpts *opts, Error **errp);
|
||||
int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
|
||||
@@ -218,10 +217,10 @@ void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
|
||||
int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
|
||||
int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
|
||||
int bdrv_open(BlockDriverState **pbs, const char *filename,
|
||||
const char *reference, QDict *options, int flags,
|
||||
BlockDriver *drv, Error **errp);
|
||||
const char *reference, QDict *options, int flags, Error **errp);
|
||||
BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
|
||||
BlockDriverState *bs, int flags);
|
||||
BlockDriverState *bs,
|
||||
QDict *options, int flags);
|
||||
int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
|
||||
int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp);
|
||||
int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user