block.c (a4615ab31cade201641cbb17a81dcac1b3bea624) block.c (69b736e76567ecbc9b9e55570bc0afc840614a98)
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

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

1693static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q,
1694 uint64_t perm, uint64_t shared,
1695 GSList *ignore_children, Error **errp);
1696static void bdrv_child_abort_perm_update(BdrvChild *c);
1697static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
1698
1699typedef struct BlockReopenQueueEntry {
1700 bool prepared;
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

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

1693static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q,
1694 uint64_t perm, uint64_t shared,
1695 GSList *ignore_children, Error **errp);
1696static void bdrv_child_abort_perm_update(BdrvChild *c);
1697static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
1698
1699typedef struct BlockReopenQueueEntry {
1700 bool prepared;
1701 bool perms_checked;
1701 BDRVReopenState state;
1702 QSIMPLEQ_ENTRY(BlockReopenQueueEntry) entry;
1703} BlockReopenQueueEntry;
1704
1705/*
1706 * Return the flags that @bs will have after the reopens in @q have
1707 * successfully completed. If @q is NULL (or @bs is not contained in @q),
1708 * return the current flags.

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

3161 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
3162 assert(bs_entry->state.bs->quiesce_counter > 0);
3163 if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) {
3164 goto cleanup;
3165 }
3166 bs_entry->prepared = true;
3167 }
3168
1702 BDRVReopenState state;
1703 QSIMPLEQ_ENTRY(BlockReopenQueueEntry) entry;
1704} BlockReopenQueueEntry;
1705
1706/*
1707 * Return the flags that @bs will have after the reopens in @q have
1708 * successfully completed. If @q is NULL (or @bs is not contained in @q),
1709 * return the current flags.

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

3162 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
3163 assert(bs_entry->state.bs->quiesce_counter > 0);
3164 if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, errp)) {
3165 goto cleanup;
3166 }
3167 bs_entry->prepared = true;
3168 }
3169
3170 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
3171 BDRVReopenState *state = &bs_entry->state;
3172 ret = bdrv_check_perm(state->bs, bs_queue, state->perm,
3173 state->shared_perm, NULL, errp);
3174 if (ret < 0) {
3175 goto cleanup_perm;
3176 }
3177 bs_entry->perms_checked = true;
3178 }
3179
3169 /* If we reach this point, we have success and just need to apply the
3170 * changes
3171 */
3172 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
3173 bdrv_reopen_commit(&bs_entry->state);
3174 }
3175
3176 ret = 0;
3180 /* If we reach this point, we have success and just need to apply the
3181 * changes
3182 */
3183 QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) {
3184 bdrv_reopen_commit(&bs_entry->state);
3185 }
3186
3187 ret = 0;
3188cleanup_perm:
3189 QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
3190 BDRVReopenState *state = &bs_entry->state;
3177
3191
3192 if (!bs_entry->perms_checked) {
3193 continue;
3194 }
3195
3196 if (ret == 0) {
3197 bdrv_set_perm(state->bs, state->perm, state->shared_perm);
3198 } else {
3199 bdrv_abort_perm_update(state->bs);
3200 }
3201 }
3178cleanup:
3179 QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
3180 if (ret) {
3181 if (bs_entry->prepared) {
3182 bdrv_reopen_abort(&bs_entry->state);
3183 }
3184 qobject_unref(bs_entry->state.explicit_options);
3185 qobject_unref(bs_entry->state.options);

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

3423 if (!qobject_is_equal(new, old)) {
3424 error_setg(errp, "Cannot change the option '%s'", entry->key);
3425 ret = -EINVAL;
3426 goto error;
3427 }
3428 } while ((entry = qdict_next(reopen_state->options, entry)));
3429 }
3430
3202cleanup:
3203 QSIMPLEQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) {
3204 if (ret) {
3205 if (bs_entry->prepared) {
3206 bdrv_reopen_abort(&bs_entry->state);
3207 }
3208 qobject_unref(bs_entry->state.explicit_options);
3209 qobject_unref(bs_entry->state.options);

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

3447 if (!qobject_is_equal(new, old)) {
3448 error_setg(errp, "Cannot change the option '%s'", entry->key);
3449 ret = -EINVAL;
3450 goto error;
3451 }
3452 } while ((entry = qdict_next(reopen_state->options, entry)));
3453 }
3454
3431 ret = bdrv_check_perm(reopen_state->bs, queue, reopen_state->perm,
3432 reopen_state->shared_perm, NULL, errp);
3433 if (ret < 0) {
3434 goto error;
3435 }
3436
3437 ret = 0;
3438
3439 /* Restore the original reopen_state->options QDict */
3440 qobject_unref(reopen_state->options);
3441 reopen_state->options = qobject_ref(orig_reopen_opts);
3442
3443error:
3444 if (ret < 0 && drv_prepared) {

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

3495 * Child options were already removed in bdrv_reopen_queue_child() */
3496 QLIST_FOREACH(child, &bs->children, next) {
3497 qdict_del(bs->explicit_options, child->name);
3498 qdict_del(bs->options, child->name);
3499 }
3500
3501 bdrv_refresh_limits(bs, NULL);
3502
3455 ret = 0;
3456
3457 /* Restore the original reopen_state->options QDict */
3458 qobject_unref(reopen_state->options);
3459 reopen_state->options = qobject_ref(orig_reopen_opts);
3460
3461error:
3462 if (ret < 0 && drv_prepared) {

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

3513 * Child options were already removed in bdrv_reopen_queue_child() */
3514 QLIST_FOREACH(child, &bs->children, next) {
3515 qdict_del(bs->explicit_options, child->name);
3516 qdict_del(bs->options, child->name);
3517 }
3518
3519 bdrv_refresh_limits(bs, NULL);
3520
3503 bdrv_set_perm(reopen_state->bs, reopen_state->perm,
3504 reopen_state->shared_perm);
3505
3506 new_can_write =
3507 !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE);
3508 if (!old_can_write && new_can_write && drv->bdrv_reopen_bitmaps_rw) {
3509 Error *local_err = NULL;
3510 if (drv->bdrv_reopen_bitmaps_rw(bs, &local_err) < 0) {
3511 /* This is not fatal, bitmaps just left read-only, so all following
3512 * writes will fail. User can remove read-only bitmaps to unblock
3513 * writes.

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

3529
3530 assert(reopen_state != NULL);
3531 drv = reopen_state->bs->drv;
3532 assert(drv != NULL);
3533
3534 if (drv->bdrv_reopen_abort) {
3535 drv->bdrv_reopen_abort(reopen_state);
3536 }
3521 new_can_write =
3522 !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE);
3523 if (!old_can_write && new_can_write && drv->bdrv_reopen_bitmaps_rw) {
3524 Error *local_err = NULL;
3525 if (drv->bdrv_reopen_bitmaps_rw(bs, &local_err) < 0) {
3526 /* This is not fatal, bitmaps just left read-only, so all following
3527 * writes will fail. User can remove read-only bitmaps to unblock
3528 * writes.

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

3544
3545 assert(reopen_state != NULL);
3546 drv = reopen_state->bs->drv;
3547 assert(drv != NULL);
3548
3549 if (drv->bdrv_reopen_abort) {
3550 drv->bdrv_reopen_abort(reopen_state);
3551 }
3537
3538 bdrv_abort_perm_update(reopen_state->bs);
3539}
3540
3541
3542static void bdrv_close(BlockDriverState *bs)
3543{
3544 BdrvAioNotifier *ban, *ban_next;
3545 BdrvChild *child, *next;
3546

--- 2332 unchanged lines hidden ---
3552}
3553
3554
3555static void bdrv_close(BlockDriverState *bs)
3556{
3557 BdrvAioNotifier *ban, *ban_next;
3558 BdrvChild *child, *next;
3559

--- 2332 unchanged lines hidden ---