qcow2.c (235e59cf03ed75d0ce96c97343194ed11c146231) qcow2.c (af175e85f92c870386ad74f466e29537b79611d3)
1/*
2 * Block driver for the QCOW version 2 format
3 *
4 * Copyright (c) 2004-2006 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

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

985 QDict *encryptopts = NULL;
986 Error *local_err = NULL;
987 int ret;
988
989 qdict_extract_subqdict(options, &encryptopts, "encrypt.");
990 encryptfmt = qdict_get_try_str(encryptopts, "format");
991
992 opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort);
1/*
2 * Block driver for the QCOW version 2 format
3 *
4 * Copyright (c) 2004-2006 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

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

985 QDict *encryptopts = NULL;
986 Error *local_err = NULL;
987 int ret;
988
989 qdict_extract_subqdict(options, &encryptopts, "encrypt.");
990 encryptfmt = qdict_get_try_str(encryptopts, "format");
991
992 opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort);
993 if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
994 error_propagate(errp, local_err);
993 if (!qemu_opts_absorb_qdict(opts, options, errp)) {
995 ret = -EINVAL;
996 goto fail;
997 }
998
999 /* get L2 table/refcount block cache size from command line options */
1000 read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size,
1001 &refcount_cache_size, &local_err);
1002 if (local_err) {

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

1590 goto fail;
1591 }
1592
1593 QLIST_INIT(&s->cluster_allocs);
1594 QTAILQ_INIT(&s->discards);
1595
1596 /* read qcow2 extensions */
1597 if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL,
994 ret = -EINVAL;
995 goto fail;
996 }
997
998 /* get L2 table/refcount block cache size from command line options */
999 read_cache_sizes(bs, opts, &l2_cache_size, &l2_cache_entry_size,
1000 &refcount_cache_size, &local_err);
1001 if (local_err) {

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

1589 goto fail;
1590 }
1591
1592 QLIST_INIT(&s->cluster_allocs);
1593 QTAILQ_INIT(&s->discards);
1594
1595 /* read qcow2 extensions */
1596 if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL,
1598 flags, &update_header, &local_err)) {
1599 error_propagate(errp, local_err);
1597 flags, &update_header, errp)) {
1600 ret = -EINVAL;
1601 goto fail;
1602 }
1603
1604 /* Open external data file */
1605 s->data_file = bdrv_open_child(NULL, options, "data-file", bs,
1606 &child_of_bds, BDRV_CHILD_DATA,
1607 true, &local_err);

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

3352 BlockBackend *blk = NULL;
3353 BlockDriverState *bs = NULL;
3354 BlockDriverState *data_bs = NULL;
3355 QCowHeader *header;
3356 size_t cluster_size;
3357 int version;
3358 int refcount_order;
3359 uint64_t* refcount_table;
1598 ret = -EINVAL;
1599 goto fail;
1600 }
1601
1602 /* Open external data file */
1603 s->data_file = bdrv_open_child(NULL, options, "data-file", bs,
1604 &child_of_bds, BDRV_CHILD_DATA,
1605 true, &local_err);

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

3350 BlockBackend *blk = NULL;
3351 BlockDriverState *bs = NULL;
3352 BlockDriverState *data_bs = NULL;
3353 QCowHeader *header;
3354 size_t cluster_size;
3355 int version;
3356 int refcount_order;
3357 uint64_t* refcount_table;
3360 Error *local_err = NULL;
3361 int ret;
3362 uint8_t compression_type = QCOW2_COMPRESSION_TYPE_ZLIB;
3363
3364 assert(create_options->driver == BLOCKDEV_DRIVER_QCOW2);
3365 qcow2_opts = &create_options->u.qcow2;
3366
3367 bs = bdrv_open_blockdev_ref(qcow2_opts->file, errp);
3368 if (bs == NULL) {

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

3578 options = qdict_new();
3579 qdict_put_str(options, "driver", "qcow2");
3580 qdict_put_str(options, "file", bs->node_name);
3581 if (data_bs) {
3582 qdict_put_str(options, "data-file", data_bs->node_name);
3583 }
3584 blk = blk_new_open(NULL, NULL, options,
3585 BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
3358 int ret;
3359 uint8_t compression_type = QCOW2_COMPRESSION_TYPE_ZLIB;
3360
3361 assert(create_options->driver == BLOCKDEV_DRIVER_QCOW2);
3362 qcow2_opts = &create_options->u.qcow2;
3363
3364 bs = bdrv_open_blockdev_ref(qcow2_opts->file, errp);
3365 if (bs == NULL) {

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

3575 options = qdict_new();
3576 qdict_put_str(options, "driver", "qcow2");
3577 qdict_put_str(options, "file", bs->node_name);
3578 if (data_bs) {
3579 qdict_put_str(options, "data-file", data_bs->node_name);
3580 }
3581 blk = blk_new_open(NULL, NULL, options,
3582 BDRV_O_RDWR | BDRV_O_RESIZE | BDRV_O_NO_FLUSH,
3586 &local_err);
3583 errp);
3587 if (blk == NULL) {
3584 if (blk == NULL) {
3588 error_propagate(errp, local_err);
3589 ret = -EIO;
3590 goto out;
3591 }
3592
3593 ret = qcow2_alloc_clusters(blk_bs(blk), 3 * cluster_size);
3594 if (ret < 0) {
3595 error_setg_errno(errp, -ret, "Could not allocate clusters for qcow2 "
3596 "header and refcount table");

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

3660 options = qdict_new();
3661 qdict_put_str(options, "driver", "qcow2");
3662 qdict_put_str(options, "file", bs->node_name);
3663 if (data_bs) {
3664 qdict_put_str(options, "data-file", data_bs->node_name);
3665 }
3666 blk = blk_new_open(NULL, NULL, options,
3667 BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
3585 ret = -EIO;
3586 goto out;
3587 }
3588
3589 ret = qcow2_alloc_clusters(blk_bs(blk), 3 * cluster_size);
3590 if (ret < 0) {
3591 error_setg_errno(errp, -ret, "Could not allocate clusters for qcow2 "
3592 "header and refcount table");

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

3656 options = qdict_new();
3657 qdict_put_str(options, "driver", "qcow2");
3658 qdict_put_str(options, "file", bs->node_name);
3659 if (data_bs) {
3660 qdict_put_str(options, "data-file", data_bs->node_name);
3661 }
3662 blk = blk_new_open(NULL, NULL, options,
3663 BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO,
3668 &local_err);
3664 errp);
3669 if (blk == NULL) {
3665 if (blk == NULL) {
3670 error_propagate(errp, local_err);
3671 ret = -EIO;
3672 goto out;
3673 }
3674
3675 ret = 0;
3676out:
3677 blk_unref(blk);
3678 bdrv_unref(bs);

--- 2191 unchanged lines hidden ---
3666 ret = -EIO;
3667 goto out;
3668 }
3669
3670 ret = 0;
3671out:
3672 blk_unref(blk);
3673 bdrv_unref(bs);

--- 2191 unchanged lines hidden ---