block.c (f54120ff1aa030d96ee64aefef9898e9e80b3a71) | block.c (462f5bcf69d3cae4a93ad55bee59516c15236a55) |
---|---|
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 --- 995 unchanged lines hidden (view full) --- 1004 bs->drv = NULL; 1005 return ret; 1006} 1007 1008/* 1009 * Fills in default options for opening images and converts the legacy 1010 * filename/flags pair to option QDict entries. 1011 */ | 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 --- 995 unchanged lines hidden (view full) --- 1004 bs->drv = NULL; 1005 return ret; 1006} 1007 1008/* 1009 * Fills in default options for opening images and converts the legacy 1010 * filename/flags pair to option QDict entries. 1011 */ |
1012static int bdrv_fill_options(QDict **options, const char *filename, | 1012static int bdrv_fill_options(QDict **options, const char *filename, int flags, |
1013 Error **errp) 1014{ 1015 const char *drvname; | 1013 Error **errp) 1014{ 1015 const char *drvname; |
1016 bool protocol = flags & BDRV_O_PROTOCOL; |
|
1016 bool parse_filename = false; 1017 Error *local_err = NULL; 1018 BlockDriver *drv; 1019 | 1017 bool parse_filename = false; 1018 Error *local_err = NULL; 1019 BlockDriver *drv; 1020 |
1021 if (!protocol) { 1022 return 0; 1023 } 1024 |
|
1020 /* Fetch the file name from the options QDict if necessary */ 1021 if (filename) { 1022 if (!qdict_haskey(*options, "filename")) { 1023 qdict_put(*options, "filename", qstring_from_str(filename)); 1024 parse_filename = true; 1025 } else { 1026 error_setg(errp, "Can't specify 'file' and 'filename' options at " 1027 "the same time"); --- 48 unchanged lines hidden (view full) --- 1076 * 1077 * options is an indirect pointer to a QDict of options to pass to the block 1078 * drivers, or pointer to NULL for an empty set of options. If this function 1079 * takes ownership of the QDict reference, it will set *options to NULL; 1080 * otherwise, it will contain unused/unrecognized options after this function 1081 * returns. Then, the caller is responsible for freeing it. If it intends to 1082 * reuse the QDict, QINCREF() should be called beforehand. 1083 */ | 1025 /* Fetch the file name from the options QDict if necessary */ 1026 if (filename) { 1027 if (!qdict_haskey(*options, "filename")) { 1028 qdict_put(*options, "filename", qstring_from_str(filename)); 1029 parse_filename = true; 1030 } else { 1031 error_setg(errp, "Can't specify 'file' and 'filename' options at " 1032 "the same time"); --- 48 unchanged lines hidden (view full) --- 1081 * 1082 * options is an indirect pointer to a QDict of options to pass to the block 1083 * drivers, or pointer to NULL for an empty set of options. If this function 1084 * takes ownership of the QDict reference, it will set *options to NULL; 1085 * otherwise, it will contain unused/unrecognized options after this function 1086 * returns. Then, the caller is responsible for freeing it. If it intends to 1087 * reuse the QDict, QINCREF() should be called beforehand. 1088 */ |
1084static int bdrv_file_open(BlockDriverState *bs, const char *filename, 1085 QDict **options, int flags, Error **errp) | 1089static int bdrv_file_open(BlockDriverState *bs, QDict **options, int flags, 1090 Error **errp) |
1086{ 1087 BlockDriver *drv; | 1091{ 1092 BlockDriver *drv; |
1093 const char *filename; |
|
1088 const char *drvname; 1089 Error *local_err = NULL; 1090 int ret; 1091 | 1094 const char *drvname; 1095 Error *local_err = NULL; 1096 int ret; 1097 |
1092 ret = bdrv_fill_options(options, filename, &local_err); 1093 if (local_err) { 1094 error_propagate(errp, local_err); 1095 goto fail; 1096 } 1097 | |
1098 filename = qdict_get_try_str(*options, "filename"); 1099 drvname = qdict_get_str(*options, "driver"); 1100 1101 drv = bdrv_find_format(drvname); 1102 assert(drv); 1103 qdict_del(*options, "driver"); 1104 1105 /* Open the file */ --- 325 unchanged lines hidden (view full) --- 1431 1432 /* Options given in the filename have lower priority than options 1433 * specified directly */ 1434 qdict_join(options, json_options, false); 1435 QDECREF(json_options); 1436 filename = NULL; 1437 } 1438 | 1098 filename = qdict_get_try_str(*options, "filename"); 1099 drvname = qdict_get_str(*options, "driver"); 1100 1101 drv = bdrv_find_format(drvname); 1102 assert(drv); 1103 qdict_del(*options, "driver"); 1104 1105 /* Open the file */ --- 325 unchanged lines hidden (view full) --- 1431 1432 /* Options given in the filename have lower priority than options 1433 * specified directly */ 1434 qdict_join(options, json_options, false); 1435 QDECREF(json_options); 1436 filename = NULL; 1437 } 1438 |
1439 ret = bdrv_fill_options(&options, filename, flags, &local_err); 1440 if (local_err) { 1441 goto fail; 1442 } 1443 |
|
1439 bs->options = options; 1440 options = qdict_clone_shallow(options); 1441 1442 if (flags & BDRV_O_PROTOCOL) { 1443 assert(!drv); | 1444 bs->options = options; 1445 options = qdict_clone_shallow(options); 1446 1447 if (flags & BDRV_O_PROTOCOL) { 1448 assert(!drv); |
1444 ret = bdrv_file_open(bs, filename, &options, flags & ~BDRV_O_PROTOCOL, | 1449 ret = bdrv_file_open(bs, &options, flags & ~BDRV_O_PROTOCOL, |
1445 &local_err); 1446 if (!ret) { 1447 drv = bs->drv; 1448 goto done; 1449 } else if (bs->drv) { 1450 goto close_and_fail; 1451 } else { 1452 goto fail; --- 4350 unchanged lines hidden --- | 1450 &local_err); 1451 if (!ret) { 1452 drv = bs->drv; 1453 goto done; 1454 } else if (bs->drv) { 1455 goto close_and_fail; 1456 } else { 1457 goto fail; --- 4350 unchanged lines hidden --- |