block.c (fb62b5889695825ea22f29d4eadb9ac1b8935a71) block.c (307261b243df2edde538f3ed5c9d80e168529355)
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

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

1715 int ret, open_flags;
1716 const char *filename;
1717 const char *driver_name = NULL;
1718 const char *node_name = NULL;
1719 const char *discard;
1720 QemuOpts *opts;
1721 BlockDriver *drv;
1722 Error *local_err = NULL;
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2020 Virtuozzo International GmbH.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal

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

1715 int ret, open_flags;
1716 const char *filename;
1717 const char *driver_name = NULL;
1718 const char *node_name = NULL;
1719 const char *discard;
1720 QemuOpts *opts;
1721 BlockDriver *drv;
1722 Error *local_err = NULL;
1723 bool ro;
1723
1724 assert(bs->file == NULL);
1725 assert(options != NULL && bs->options != options);
1726
1727 opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
1728 if (!qemu_opts_absorb_qdict(opts, options, errp)) {
1729 ret = -EINVAL;
1730 goto fail_opts;

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

1767 goto fail_opts;
1768 }
1769
1770 trace_bdrv_open_common(bs, filename ?: "", bs->open_flags,
1771 drv->format_name);
1772
1773 bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
1774
1724
1725 assert(bs->file == NULL);
1726 assert(options != NULL && bs->options != options);
1727
1728 opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
1729 if (!qemu_opts_absorb_qdict(opts, options, errp)) {
1730 ret = -EINVAL;
1731 goto fail_opts;

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

1768 goto fail_opts;
1769 }
1770
1771 trace_bdrv_open_common(bs, filename ?: "", bs->open_flags,
1772 drv->format_name);
1773
1774 bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
1775
1775 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
1776 if (!bs->read_only && bdrv_is_whitelisted(drv, true)) {
1776 ro = bdrv_is_read_only(bs);
1777
1778 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, ro)) {
1779 if (!ro && bdrv_is_whitelisted(drv, true)) {
1777 ret = bdrv_apply_auto_read_only(bs, NULL, NULL);
1778 } else {
1779 ret = -ENOTSUP;
1780 }
1781 if (ret < 0) {
1782 error_setg(errp,
1780 ret = bdrv_apply_auto_read_only(bs, NULL, NULL);
1781 } else {
1782 ret = -ENOTSUP;
1783 }
1784 if (ret < 0) {
1785 error_setg(errp,
1783 !bs->read_only && bdrv_is_whitelisted(drv, true)
1786 !ro && bdrv_is_whitelisted(drv, true)
1784 ? "Driver '%s' can only be used for read-only devices"
1785 : "Driver '%s' is not whitelisted",
1786 drv->format_name);
1787 goto fail_opts;
1788 }
1789 }
1790
1791 /* bdrv_new() and bdrv_close() make it so */
1792 assert(qatomic_read(&bs->copy_on_read) == 0);
1793
1794 if (bs->open_flags & BDRV_O_COPY_ON_READ) {
1787 ? "Driver '%s' can only be used for read-only devices"
1788 : "Driver '%s' is not whitelisted",
1789 drv->format_name);
1790 goto fail_opts;
1791 }
1792 }
1793
1794 /* bdrv_new() and bdrv_close() make it so */
1795 assert(qatomic_read(&bs->copy_on_read) == 0);
1796
1797 if (bs->open_flags & BDRV_O_COPY_ON_READ) {
1795 if (!bs->read_only) {
1798 if (!ro) {
1796 bdrv_enable_copy_on_read(bs);
1797 } else {
1798 error_setg(errp, "Can't use copy-on-read on read-only device");
1799 ret = -EINVAL;
1800 goto fail_opts;
1801 }
1802 }
1803

--- 5773 unchanged lines hidden ---
1799 bdrv_enable_copy_on_read(bs);
1800 } else {
1801 error_setg(errp, "Can't use copy-on-read on read-only device");
1802 ret = -EINVAL;
1803 goto fail_opts;
1804 }
1805 }
1806

--- 5773 unchanged lines hidden ---