block.c (30c6672aa4b4bc9bdba3a7e46c49bba191660143) block.c (df5817926790f6e84d1936eab523556f96fa577a)
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

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

1097 if (!drv->bdrv_needs_filename) {
1098 qdict_del(*options, "filename");
1099 }
1100 }
1101
1102 return 0;
1103}
1104
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

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

1097 if (!drv->bdrv_needs_filename) {
1098 qdict_del(*options, "filename");
1099 }
1100 }
1101
1102 return 0;
1103}
1104
1105static void bdrv_attach_child(BlockDriverState *parent_bs,
1106 BlockDriverState *child_bs,
1107 const BdrvChildRole *child_role)
1108{
1109 BdrvChild *child = g_new(BdrvChild, 1);
1110 *child = (BdrvChild) {
1111 .bs = child_bs,
1112 .role = child_role,
1113 };
1114
1115 QLIST_INSERT_HEAD(&parent_bs->children, child, next);
1116}
1117
1105void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
1106{
1107
1108 if (bs->backing_hd) {
1109 assert(bs->backing_blocker);
1110 bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);
1111 } else if (backing_hd) {
1112 error_setg(&bs->backing_blocker,

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

1197 bdrv_unref(backing_hd);
1198 backing_hd = NULL;
1199 bs->open_flags |= BDRV_O_NO_BACKING;
1200 error_setg(errp, "Could not open backing file: %s",
1201 error_get_pretty(local_err));
1202 error_free(local_err);
1203 goto free_exit;
1204 }
1118void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd)
1119{
1120
1121 if (bs->backing_hd) {
1122 assert(bs->backing_blocker);
1123 bdrv_op_unblock_all(bs->backing_hd, bs->backing_blocker);
1124 } else if (backing_hd) {
1125 error_setg(&bs->backing_blocker,

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

1210 bdrv_unref(backing_hd);
1211 backing_hd = NULL;
1212 bs->open_flags |= BDRV_O_NO_BACKING;
1213 error_setg(errp, "Could not open backing file: %s",
1214 error_get_pretty(local_err));
1215 error_free(local_err);
1216 goto free_exit;
1217 }
1218
1219 bdrv_attach_child(bs, backing_hd, &child_backing);
1205 bdrv_set_backing_hd(bs, backing_hd);
1206
1207free_exit:
1208 g_free(backing_filename);
1209 return ret;
1210}
1211
1212/*

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

1232{
1233 QDict *image_options;
1234 int ret;
1235 char *bdref_key_dot;
1236 const char *reference;
1237
1238 assert(pbs);
1239 assert(*pbs == NULL);
1220 bdrv_set_backing_hd(bs, backing_hd);
1221
1222free_exit:
1223 g_free(backing_filename);
1224 return ret;
1225}
1226
1227/*

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

1247{
1248 QDict *image_options;
1249 int ret;
1250 char *bdref_key_dot;
1251 const char *reference;
1252
1253 assert(pbs);
1254 assert(*pbs == NULL);
1255 assert(child_role != NULL);
1240
1241 bdref_key_dot = g_strdup_printf("%s.", bdref_key);
1242 qdict_extract_subqdict(options, &image_options, bdref_key_dot);
1243 g_free(bdref_key_dot);
1244
1245 reference = qdict_get_try_str(options, bdref_key);
1246 if (!filename && !reference && !qdict_size(image_options)) {
1247 if (allow_none) {

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

1252 ret = -EINVAL;
1253 }
1254 QDECREF(image_options);
1255 goto done;
1256 }
1257
1258 ret = bdrv_open_inherit(pbs, filename, reference, image_options, 0,
1259 parent, child_role, NULL, errp);
1256
1257 bdref_key_dot = g_strdup_printf("%s.", bdref_key);
1258 qdict_extract_subqdict(options, &image_options, bdref_key_dot);
1259 g_free(bdref_key_dot);
1260
1261 reference = qdict_get_try_str(options, bdref_key);
1262 if (!filename && !reference && !qdict_size(image_options)) {
1263 if (allow_none) {

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

1268 ret = -EINVAL;
1269 }
1270 QDECREF(image_options);
1271 goto done;
1272 }
1273
1274 ret = bdrv_open_inherit(pbs, filename, reference, image_options, 0,
1275 parent, child_role, NULL, errp);
1276 if (ret < 0) {
1277 goto done;
1278 }
1260
1279
1280 bdrv_attach_child(parent, *pbs, child_role);
1281
1261done:
1262 qdict_del(options, bdref_key);
1263 return ret;
1264}
1265
1266int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
1267{
1268 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */

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

1323
1324 bdrv_append(bs_snapshot, bs);
1325
1326out:
1327 g_free(tmp_filename);
1328 return ret;
1329}
1330
1282done:
1283 qdict_del(options, bdref_key);
1284 return ret;
1285}
1286
1287int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp)
1288{
1289 /* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */

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

1344
1345 bdrv_append(bs_snapshot, bs);
1346
1347out:
1348 g_free(tmp_filename);
1349 return ret;
1350}
1351
1331static void bdrv_attach_child(BlockDriverState *parent_bs,
1332 BlockDriverState *child_bs,
1333 const BdrvChildRole *child_role)
1334{
1335 BdrvChild *child = g_new(BdrvChild, 1);
1336 *child = (BdrvChild) {
1337 .bs = child_bs,
1338 .role = child_role,
1339 };
1340
1341 QLIST_INSERT_HEAD(&parent_bs->children, child, next);
1342}
1343
1344/*
1345 * Opens a disk image (raw, qcow2, vmdk, ...)
1346 *
1347 * options is a QDict of options to pass to the block drivers, or NULL for an
1348 * empty set of options. The reference to the QDict belongs to the block layer
1349 * after the call (even on failure), so if the caller intends to reuse the
1350 * dictionary, it needs to use QINCREF() before calling bdrv_open.
1351 *

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

1388 return -EINVAL;
1389 }
1390
1391 bs = bdrv_lookup_bs(reference, reference, errp);
1392 if (!bs) {
1393 return -ENODEV;
1394 }
1395 bdrv_ref(bs);
1352/*
1353 * Opens a disk image (raw, qcow2, vmdk, ...)
1354 *
1355 * options is a QDict of options to pass to the block drivers, or NULL for an
1356 * empty set of options. The reference to the QDict belongs to the block layer
1357 * after the call (even on failure), so if the caller intends to reuse the
1358 * dictionary, it needs to use QINCREF() before calling bdrv_open.
1359 *

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

1396 return -EINVAL;
1397 }
1398
1399 bs = bdrv_lookup_bs(reference, reference, errp);
1400 if (!bs) {
1401 return -ENODEV;
1402 }
1403 bdrv_ref(bs);
1396 if (child_role) {
1397 bdrv_attach_child(parent, bs, child_role);
1398 }
1399 *pbs = bs;
1400 return 0;
1401 }
1402
1403 if (*pbs) {
1404 bs = *pbs;
1405 } else {
1406 bs = bdrv_new();

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

1535 && !runstate_check(RUN_STATE_INMIGRATE)
1536 && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */
1537 error_setg(errp,
1538 "Guest must be stopped for opening of encrypted image");
1539 ret = -EBUSY;
1540 goto close_and_fail;
1541 }
1542
1404 *pbs = bs;
1405 return 0;
1406 }
1407
1408 if (*pbs) {
1409 bs = *pbs;
1410 } else {
1411 bs = bdrv_new();

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

1540 && !runstate_check(RUN_STATE_INMIGRATE)
1541 && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */
1542 error_setg(errp,
1543 "Guest must be stopped for opening of encrypted image");
1544 ret = -EBUSY;
1545 goto close_and_fail;
1546 }
1547
1543 if (child_role) {
1544 bdrv_attach_child(parent, bs, child_role);
1545 }
1546
1547 QDECREF(options);
1548 *pbs = bs;
1549 return 0;
1550
1551fail:
1552 if (file != NULL) {
1553 bdrv_unref(file);
1554 }

--- 2643 unchanged lines hidden ---
1548 QDECREF(options);
1549 *pbs = bs;
1550 return 0;
1551
1552fail:
1553 if (file != NULL) {
1554 bdrv_unref(file);
1555 }

--- 2643 unchanged lines hidden ---