block.c (33f2663bd58696ab836731830f9fb6a878a5b944) block.c (70082db4efab1bc91467a9207c6e3f554a8e6bac)
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

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

2463 BlockReopenQueue *reopen_queue,
2464 uint64_t perm, uint64_t shared,
2465 uint64_t *nperm, uint64_t *nshared)
2466{
2467 *nperm = perm & DEFAULT_PERM_PASSTHROUGH;
2468 *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED;
2469}
2470
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

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

2463 BlockReopenQueue *reopen_queue,
2464 uint64_t perm, uint64_t shared,
2465 uint64_t *nperm, uint64_t *nshared)
2466{
2467 *nperm = perm & DEFAULT_PERM_PASSTHROUGH;
2468 *nshared = (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHANGED;
2469}
2470
2471static void bdrv_default_perms_for_cow(BlockDriverState *bs, BdrvChild *c,
2472 const BdrvChildClass *child_class,
2473 BdrvChildRole role,
2474 BlockReopenQueue *reopen_queue,
2475 uint64_t perm, uint64_t shared,
2476 uint64_t *nperm, uint64_t *nshared)
2477{
2478 assert(child_class == &child_backing ||
2479 (child_class == &child_of_bds && (role & BDRV_CHILD_COW)));
2480
2481 /*
2482 * We want consistent read from backing files if the parent needs it.
2483 * No other operations are performed on backing files.
2484 */
2485 perm &= BLK_PERM_CONSISTENT_READ;
2486
2487 /*
2488 * If the parent can deal with changing data, we're okay with a
2489 * writable and resizable backing file.
2490 * TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too?
2491 */
2492 if (shared & BLK_PERM_WRITE) {
2493 shared = BLK_PERM_WRITE | BLK_PERM_RESIZE;
2494 } else {
2495 shared = 0;
2496 }
2497
2498 shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD |
2499 BLK_PERM_WRITE_UNCHANGED;
2500
2501 if (bs->open_flags & BDRV_O_INACTIVE) {
2502 shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
2503 }
2504
2505 *nperm = perm;
2506 *nshared = shared;
2507}
2508
2471void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
2472 const BdrvChildClass *child_class,
2473 BdrvChildRole role,
2474 BlockReopenQueue *reopen_queue,
2475 uint64_t perm, uint64_t shared,
2476 uint64_t *nperm, uint64_t *nshared)
2477{
2478 bool backing = (child_class == &child_backing);

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

2500
2501 if (bs->open_flags & BDRV_O_INACTIVE) {
2502 shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
2503 }
2504
2505 *nperm = perm;
2506 *nshared = shared;
2507 } else {
2509void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c,
2510 const BdrvChildClass *child_class,
2511 BdrvChildRole role,
2512 BlockReopenQueue *reopen_queue,
2513 uint64_t perm, uint64_t shared,
2514 uint64_t *nperm, uint64_t *nshared)
2515{
2516 bool backing = (child_class == &child_backing);

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

2538
2539 if (bs->open_flags & BDRV_O_INACTIVE) {
2540 shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
2541 }
2542
2543 *nperm = perm;
2544 *nshared = shared;
2545 } else {
2508 /* We want consistent read from backing files if the parent needs it.
2509 * No other operations are performed on backing files. */
2510 perm &= BLK_PERM_CONSISTENT_READ;
2511
2512 /* If the parent can deal with changing data, we're okay with a
2513 * writable and resizable backing file. */
2514 /* TODO Require !(perm & BLK_PERM_CONSISTENT_READ), too? */
2515 if (shared & BLK_PERM_WRITE) {
2516 shared = BLK_PERM_WRITE | BLK_PERM_RESIZE;
2517 } else {
2518 shared = 0;
2519 }
2520
2521 shared |= BLK_PERM_CONSISTENT_READ | BLK_PERM_GRAPH_MOD |
2522 BLK_PERM_WRITE_UNCHANGED;
2523
2524 if (bs->open_flags & BDRV_O_INACTIVE) {
2525 shared |= BLK_PERM_WRITE | BLK_PERM_RESIZE;
2526 }
2527
2528 *nperm = perm;
2529 *nshared = shared;
2546 bdrv_default_perms_for_cow(bs, c, child_class, role, reopen_queue,
2547 perm, shared, nperm, nshared);
2530 }
2531}
2532
2533uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
2534{
2535 static const uint64_t permissions[] = {
2536 [BLOCK_PERMISSION_CONSISTENT_READ] = BLK_PERM_CONSISTENT_READ,
2537 [BLOCK_PERMISSION_WRITE] = BLK_PERM_WRITE,

--- 4393 unchanged lines hidden ---
2548 }
2549}
2550
2551uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
2552{
2553 static const uint64_t permissions[] = {
2554 [BLOCK_PERMISSION_CONSISTENT_READ] = BLK_PERM_CONSISTENT_READ,
2555 [BLOCK_PERMISSION_WRITE] = BLK_PERM_WRITE,

--- 4393 unchanged lines hidden ---