block.c (17c8a2197888bac8ec0256b16919b721c76c5e62) block.c (82dc8b411040fa8a7418a012ff39b8d06f68e639)
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

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

900};
901
902/*
903 * Common part for opening disk images and files
904 *
905 * Removes all processed options from *options.
906 */
907static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
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

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

900};
901
902/*
903 * Common part for opening disk images and files
904 *
905 * Removes all processed options from *options.
906 */
907static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
908 QDict *options, int flags, Error **errp)
908 QDict *options, Error **errp)
909{
910 int ret, open_flags;
911 const char *filename;
912 const char *driver_name = NULL;
913 const char *node_name = NULL;
914 QemuOpts *opts;
915 BlockDriver *drv;
916 Error *local_err = NULL;

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

938
939 if (drv->bdrv_needs_filename && !filename) {
940 error_setg(errp, "The '%s' block driver requires a file name",
941 drv->format_name);
942 ret = -EINVAL;
943 goto fail_opts;
944 }
945
909{
910 int ret, open_flags;
911 const char *filename;
912 const char *driver_name = NULL;
913 const char *node_name = NULL;
914 QemuOpts *opts;
915 BlockDriver *drv;
916 Error *local_err = NULL;

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

938
939 if (drv->bdrv_needs_filename && !filename) {
940 error_setg(errp, "The '%s' block driver requires a file name",
941 drv->format_name);
942 ret = -EINVAL;
943 goto fail_opts;
944 }
945
946 trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
946 trace_bdrv_open_common(bs, filename ?: "", bs->open_flags,
947 drv->format_name);
947
948 node_name = qemu_opt_get(opts, "node-name");
949 bdrv_assign_node_name(bs, node_name, &local_err);
950 if (local_err) {
951 error_propagate(errp, local_err);
952 ret = -EINVAL;
953 goto fail_opts;
954 }
955
956 bs->request_alignment = 512;
957 bs->zero_beyond_eof = true;
948
949 node_name = qemu_opt_get(opts, "node-name");
950 bdrv_assign_node_name(bs, node_name, &local_err);
951 if (local_err) {
952 error_propagate(errp, local_err);
953 ret = -EINVAL;
954 goto fail_opts;
955 }
956
957 bs->request_alignment = 512;
958 bs->zero_beyond_eof = true;
958 open_flags = bdrv_open_flags(bs, flags);
959 bs->read_only = !(open_flags & BDRV_O_RDWR);
959 bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
960
961 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
962 error_setg(errp,
963 !bs->read_only && bdrv_is_whitelisted(drv, true)
964 ? "Driver '%s' can only be used for read-only devices"
965 : "Driver '%s' is not whitelisted",
966 drv->format_name);
967 ret = -ENOTSUP;
968 goto fail_opts;
969 }
970
971 assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
960
961 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
962 error_setg(errp,
963 !bs->read_only && bdrv_is_whitelisted(drv, true)
964 ? "Driver '%s' can only be used for read-only devices"
965 : "Driver '%s' is not whitelisted",
966 drv->format_name);
967 ret = -ENOTSUP;
968 goto fail_opts;
969 }
970
971 assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
972 if (flags & BDRV_O_COPY_ON_READ) {
972 if (bs->open_flags & BDRV_O_COPY_ON_READ) {
973 if (!bs->read_only) {
974 bdrv_enable_copy_on_read(bs);
975 } else {
976 error_setg(errp, "Can't use copy-on-read on read-only device");
977 ret = -EINVAL;
978 goto fail_opts;
979 }
980 }

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

989 bs->drv = drv;
990 bs->opaque = g_malloc0(drv->instance_size);
991
992 /* Apply cache mode options */
993 update_flags_from_options(&bs->open_flags, opts);
994 bdrv_set_enable_write_cache(bs, bs->open_flags & BDRV_O_CACHE_WB);
995
996 /* Open the image, either directly or using a protocol */
973 if (!bs->read_only) {
974 bdrv_enable_copy_on_read(bs);
975 } else {
976 error_setg(errp, "Can't use copy-on-read on read-only device");
977 ret = -EINVAL;
978 goto fail_opts;
979 }
980 }

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

989 bs->drv = drv;
990 bs->opaque = g_malloc0(drv->instance_size);
991
992 /* Apply cache mode options */
993 update_flags_from_options(&bs->open_flags, opts);
994 bdrv_set_enable_write_cache(bs, bs->open_flags & BDRV_O_CACHE_WB);
995
996 /* Open the image, either directly or using a protocol */
997 open_flags = bdrv_open_flags(bs, bs->open_flags);
997 if (drv->bdrv_file_open) {
998 assert(file == NULL);
999 assert(!drv->bdrv_needs_filename || filename != NULL);
1000 ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
1001 } else {
1002 if (file == NULL) {
1003 error_setg(errp, "Can't use '%s' as a block driver for the "
1004 "protocol level", drv->format_name);

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

1651
1652 /* BDRV_O_PROTOCOL must be set iff a protocol BDS is about to be created */
1653 assert(!!(flags & BDRV_O_PROTOCOL) == !!drv->bdrv_file_open);
1654 /* file must be NULL if a protocol BDS is about to be created
1655 * (the inverse results in an error message from bdrv_open_common()) */
1656 assert(!(flags & BDRV_O_PROTOCOL) || !file);
1657
1658 /* Open the image */
998 if (drv->bdrv_file_open) {
999 assert(file == NULL);
1000 assert(!drv->bdrv_needs_filename || filename != NULL);
1001 ret = drv->bdrv_file_open(bs, options, open_flags, &local_err);
1002 } else {
1003 if (file == NULL) {
1004 error_setg(errp, "Can't use '%s' as a block driver for the "
1005 "protocol level", drv->format_name);

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

1652
1653 /* BDRV_O_PROTOCOL must be set iff a protocol BDS is about to be created */
1654 assert(!!(flags & BDRV_O_PROTOCOL) == !!drv->bdrv_file_open);
1655 /* file must be NULL if a protocol BDS is about to be created
1656 * (the inverse results in an error message from bdrv_open_common()) */
1657 assert(!(flags & BDRV_O_PROTOCOL) || !file);
1658
1659 /* Open the image */
1659 ret = bdrv_open_common(bs, file, options, flags, &local_err);
1660 ret = bdrv_open_common(bs, file, options, &local_err);
1660 if (ret < 0) {
1661 goto fail;
1662 }
1663
1664 if (file && (bs->file != file)) {
1665 bdrv_unref_child(bs, file);
1666 file = NULL;
1667 }

--- 2653 unchanged lines hidden ---
1661 if (ret < 0) {
1662 goto fail;
1663 }
1664
1665 if (file && (bs->file != file)) {
1666 bdrv_unref_child(bs, file);
1667 file = NULL;
1668 }

--- 2653 unchanged lines hidden ---