block.c (dd4118c792a8c2a104fe90274e8a41e0db1ebc56) block.c (b441dc71c0b7e8f488a6ebc2aa781b08a3a05038)
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

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

2238 }
2239
2240 if (new_bs) {
2241 bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm);
2242 bdrv_set_perm(new_bs, perm, shared_perm);
2243 }
2244}
2245
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

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

2238 }
2239
2240 if (new_bs) {
2241 bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm);
2242 bdrv_set_perm(new_bs, perm, shared_perm);
2243 }
2244}
2245
2246/*
2247 * This function steals the reference to child_bs from the caller.
2248 * That reference is later dropped by bdrv_root_unref_child().
2249 *
2250 * On failure NULL is returned, errp is set and the reference to
2251 * child_bs is also dropped.
2252 */
2246BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
2247 const char *child_name,
2248 const BdrvChildRole *child_role,
2249 uint64_t perm, uint64_t shared_perm,
2250 void *opaque, Error **errp)
2251{
2252 BdrvChild *child;
2253 int ret;
2254
2255 ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp);
2256 if (ret < 0) {
2257 bdrv_abort_perm_update(child_bs);
2253BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs,
2254 const char *child_name,
2255 const BdrvChildRole *child_role,
2256 uint64_t perm, uint64_t shared_perm,
2257 void *opaque, Error **errp)
2258{
2259 BdrvChild *child;
2260 int ret;
2261
2262 ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp);
2263 if (ret < 0) {
2264 bdrv_abort_perm_update(child_bs);
2265 bdrv_unref(child_bs);
2258 return NULL;
2259 }
2260
2261 child = g_new(BdrvChild, 1);
2262 *child = (BdrvChild) {
2263 .bs = NULL,
2264 .name = g_strdup(child_name),
2265 .role = child_role,
2266 .perm = perm,
2267 .shared_perm = shared_perm,
2268 .opaque = opaque,
2269 };
2270
2271 /* This performs the matching bdrv_set_perm() for the above check. */
2272 bdrv_replace_child(child, child_bs);
2273
2274 return child;
2275}
2276
2266 return NULL;
2267 }
2268
2269 child = g_new(BdrvChild, 1);
2270 *child = (BdrvChild) {
2271 .bs = NULL,
2272 .name = g_strdup(child_name),
2273 .role = child_role,
2274 .perm = perm,
2275 .shared_perm = shared_perm,
2276 .opaque = opaque,
2277 };
2278
2279 /* This performs the matching bdrv_set_perm() for the above check. */
2280 bdrv_replace_child(child, child_bs);
2281
2282 return child;
2283}
2284
2285/*
2286 * This function transfers the reference to child_bs from the caller
2287 * to parent_bs. That reference is later dropped by parent_bs on
2288 * bdrv_close() or if someone calls bdrv_unref_child().
2289 *
2290 * On failure NULL is returned, errp is set and the reference to
2291 * child_bs is also dropped.
2292 */
2277BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
2278 BlockDriverState *child_bs,
2279 const char *child_name,
2280 const BdrvChildRole *child_role,
2281 Error **errp)
2282{
2283 BdrvChild *child;
2284 uint64_t perm, shared_perm;

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

2396 goto out;
2397 }
2398
2399 bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing,
2400 errp);
2401 /* If backing_hd was already part of bs's backing chain, and
2402 * inherits_from pointed recursively to bs then let's update it to
2403 * point directly to bs (else it will become NULL). */
2293BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
2294 BlockDriverState *child_bs,
2295 const char *child_name,
2296 const BdrvChildRole *child_role,
2297 Error **errp)
2298{
2299 BdrvChild *child;
2300 uint64_t perm, shared_perm;

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

2412 goto out;
2413 }
2414
2415 bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_backing,
2416 errp);
2417 /* If backing_hd was already part of bs's backing chain, and
2418 * inherits_from pointed recursively to bs then let's update it to
2419 * point directly to bs (else it will become NULL). */
2404 if (update_inherits_from) {
2420 if (bs->backing && update_inherits_from) {
2405 backing_hd->inherits_from = bs;
2406 }
2421 backing_hd->inherits_from = bs;
2422 }
2407 if (!bs->backing) {
2408 bdrv_unref(backing_hd);
2409 }
2410
2411out:
2412 bdrv_refresh_limits(bs, NULL);
2413}
2414
2415/*
2416 * Opens the backing file for a BlockDriverState if not yet open
2417 *

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

2589 * The BlockdevRef will be removed from the options QDict.
2590 */
2591BdrvChild *bdrv_open_child(const char *filename,
2592 QDict *options, const char *bdref_key,
2593 BlockDriverState *parent,
2594 const BdrvChildRole *child_role,
2595 bool allow_none, Error **errp)
2596{
2423
2424out:
2425 bdrv_refresh_limits(bs, NULL);
2426}
2427
2428/*
2429 * Opens the backing file for a BlockDriverState if not yet open
2430 *

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

2602 * The BlockdevRef will be removed from the options QDict.
2603 */
2604BdrvChild *bdrv_open_child(const char *filename,
2605 QDict *options, const char *bdref_key,
2606 BlockDriverState *parent,
2607 const BdrvChildRole *child_role,
2608 bool allow_none, Error **errp)
2609{
2597 BdrvChild *c;
2598 BlockDriverState *bs;
2599
2600 bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role,
2601 allow_none, errp);
2602 if (bs == NULL) {
2603 return NULL;
2604 }
2605
2610 BlockDriverState *bs;
2611
2612 bs = bdrv_open_child_bs(filename, options, bdref_key, parent, child_role,
2613 allow_none, errp);
2614 if (bs == NULL) {
2615 return NULL;
2616 }
2617
2606 c = bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
2607 if (!c) {
2608 bdrv_unref(bs);
2609 return NULL;
2610 }
2611
2612 return c;
2618 return bdrv_attach_child(parent, bs, bdref_key, child_role, errp);
2613}
2614
2615/* TODO Future callers may need to specify parent/child_role in order for
2616 * option inheritance to work. Existing callers use it for the root node. */
2617BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
2618{
2619 BlockDriverState *bs = NULL;
2620 Error *local_err = NULL;

--- 3742 unchanged lines hidden ---
2619}
2620
2621/* TODO Future callers may need to specify parent/child_role in order for
2622 * option inheritance to work. Existing callers use it for the root node. */
2623BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp)
2624{
2625 BlockDriverState *bs = NULL;
2626 Error *local_err = NULL;

--- 3742 unchanged lines hidden ---