block.c (b8afb520e479e693c227aa39c2fb7670743e104f) block.c (636ea3708c253e9d2ddac6bd7d96854ba95fb7f5)
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

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

783 */
784 if (bs->is_temporary) {
785 open_flags |= BDRV_O_RDWR;
786 }
787
788 return open_flags;
789}
790
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

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

783 */
784 if (bs->is_temporary) {
785 open_flags |= BDRV_O_RDWR;
786 }
787
788 return open_flags;
789}
790
791static int bdrv_assign_node_name(BlockDriverState *bs,
792 const char *node_name,
793 Error **errp)
791static void bdrv_assign_node_name(BlockDriverState *bs,
792 const char *node_name,
793 Error **errp)
794{
795 if (!node_name) {
794{
795 if (!node_name) {
796 return 0;
796 return;
797 }
798
799 /* empty string node name is invalid */
800 if (node_name[0] == '\0') {
801 error_setg(errp, "Empty node name");
797 }
798
799 /* empty string node name is invalid */
800 if (node_name[0] == '\0') {
801 error_setg(errp, "Empty node name");
802 return -EINVAL;
802 return;
803 }
804
805 /* takes care of avoiding namespaces collisions */
806 if (bdrv_find(node_name)) {
807 error_setg(errp, "node-name=%s is conflicting with a device id",
808 node_name);
803 }
804
805 /* takes care of avoiding namespaces collisions */
806 if (bdrv_find(node_name)) {
807 error_setg(errp, "node-name=%s is conflicting with a device id",
808 node_name);
809 return -EINVAL;
809 return;
810 }
811
812 /* takes care of avoiding duplicates node names */
813 if (bdrv_find_node(node_name)) {
814 error_setg(errp, "Duplicate node name");
810 }
811
812 /* takes care of avoiding duplicates node names */
813 if (bdrv_find_node(node_name)) {
814 error_setg(errp, "Duplicate node name");
815 return -EINVAL;
815 return;
816 }
817
818 /* copy node name into the bs and insert it into the graph list */
819 pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
820 QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
816 }
817
818 /* copy node name into the bs and insert it into the graph list */
819 pstrcpy(bs->node_name, sizeof(bs->node_name), node_name);
820 QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list);
821
822 return 0;
823}
824
825/*
826 * Common part for opening disk images and files
827 *
828 * Removes all processed options from *options.
829 */
830static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,

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

849 error_setg(errp, "The '%s' block driver requires a file name",
850 drv->format_name);
851 return -EINVAL;
852 }
853
854 trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
855
856 node_name = qdict_get_try_str(options, "node-name");
821}
822
823/*
824 * Common part for opening disk images and files
825 *
826 * Removes all processed options from *options.
827 */
828static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,

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

847 error_setg(errp, "The '%s' block driver requires a file name",
848 drv->format_name);
849 return -EINVAL;
850 }
851
852 trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
853
854 node_name = qdict_get_try_str(options, "node-name");
857 ret = bdrv_assign_node_name(bs, node_name, errp);
858 if (ret < 0) {
859 return ret;
855 bdrv_assign_node_name(bs, node_name, &local_err);
856 if (error_is_set(&local_err)) {
857 error_propagate(errp, local_err);
858 return -EINVAL;
860 }
861 qdict_del(options, "node-name");
862
863 /* bdrv_open() with directly using a protocol as drv. This layer is already
864 * opened, so assign it to bs (while file becomes a closed BlockDriverState)
865 * and return immediately. */
866 if (file != NULL && drv->bdrv_file_open) {
867 bdrv_swap(file, bs);

--- 4650 unchanged lines hidden ---
859 }
860 qdict_del(options, "node-name");
861
862 /* bdrv_open() with directly using a protocol as drv. This layer is already
863 * opened, so assign it to bs (while file becomes a closed BlockDriverState)
864 * and return immediately. */
865 if (file != NULL && drv->bdrv_file_open) {
866 bdrv_swap(file, bs);

--- 4650 unchanged lines hidden ---