block.c (dcf3f9b268a5c04bd94d721b81774092d7170cc4) block.c (1d42f48c3a468fbf53660970d7372d0f0f9d0529)
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

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

3999 * backing BlockDriverState (or NULL).
4000 *
4001 * Return 0 on success, otherwise return < 0 and set @errp.
4002 */
4003static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state,
4004 Error **errp)
4005{
4006 BlockDriverState *bs = reopen_state->bs;
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

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

3999 * backing BlockDriverState (or NULL).
4000 *
4001 * Return 0 on success, otherwise return < 0 and set @errp.
4002 */
4003static int bdrv_reopen_parse_backing(BDRVReopenState *reopen_state,
4004 Error **errp)
4005{
4006 BlockDriverState *bs = reopen_state->bs;
4007 BlockDriverState *overlay_bs, *new_backing_bs;
4007 BlockDriverState *overlay_bs, *below_bs, *new_backing_bs;
4008 QObject *value;
4009 const char *str;
4010
4011 value = qdict_get(reopen_state->options, "backing");
4012 if (value == NULL) {
4013 return 0;
4014 }
4015

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

4039 */
4040 if (new_backing_bs) {
4041 if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)) {
4042 return -EINVAL;
4043 }
4044 }
4045
4046 /*
4008 QObject *value;
4009 const char *str;
4010
4011 value = qdict_get(reopen_state->options, "backing");
4012 if (value == NULL) {
4013 return 0;
4014 }
4015

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

4039 */
4040 if (new_backing_bs) {
4041 if (!bdrv_reopen_can_attach(bs, bs->backing, new_backing_bs, errp)) {
4042 return -EINVAL;
4043 }
4044 }
4045
4046 /*
4047 * Ensure that @bs can really handle backing files, because we are
4048 * about to give it one (or swap the existing one)
4049 */
4050 if (bs->drv->is_filter) {
4051 /* Filters always have a file or a backing child */
4052 if (!bs->backing) {
4053 error_setg(errp, "'%s' is a %s filter node that does not support a "
4054 "backing child", bs->node_name, bs->drv->format_name);
4055 return -EINVAL;
4056 }
4057 } else if (!bs->drv->supports_backing) {
4058 error_setg(errp, "Driver '%s' of node '%s' does not support backing "
4059 "files", bs->drv->format_name, bs->node_name);
4060 return -EINVAL;
4061 }
4062
4063 /*
4047 * Find the "actual" backing file by skipping all links that point
4048 * to an implicit node, if any (e.g. a commit filter node).
4064 * Find the "actual" backing file by skipping all links that point
4065 * to an implicit node, if any (e.g. a commit filter node).
4066 * We cannot use any of the bdrv_skip_*() functions here because
4067 * those return the first explicit node, while we are looking for
4068 * its overlay here.
4049 */
4050 overlay_bs = bs;
4069 */
4070 overlay_bs = bs;
4051 while (backing_bs(overlay_bs) && backing_bs(overlay_bs)->implicit) {
4052 overlay_bs = backing_bs(overlay_bs);
4071 for (below_bs = bdrv_filter_or_cow_bs(overlay_bs);
4072 below_bs && below_bs->implicit;
4073 below_bs = bdrv_filter_or_cow_bs(overlay_bs))
4074 {
4075 overlay_bs = below_bs;
4053 }
4054
4055 /* If we want to replace the backing file we need some extra checks */
4076 }
4077
4078 /* If we want to replace the backing file we need some extra checks */
4056 if (new_backing_bs != backing_bs(overlay_bs)) {
4079 if (new_backing_bs != bdrv_filter_or_cow_bs(overlay_bs)) {
4057 /* Check for implicit nodes between bs and its backing file */
4058 if (bs != overlay_bs) {
4059 error_setg(errp, "Cannot change backing link if '%s' has "
4060 "an implicit backing file", bs->node_name);
4061 return -EPERM;
4062 }
4080 /* Check for implicit nodes between bs and its backing file */
4081 if (bs != overlay_bs) {
4082 error_setg(errp, "Cannot change backing link if '%s' has "
4083 "an implicit backing file", bs->node_name);
4084 return -EPERM;
4085 }
4063 /* Check if the backing link that we want to replace is frozen */
4064 if (bdrv_is_backing_chain_frozen(overlay_bs, backing_bs(overlay_bs),
4065 errp)) {
4086 /*
4087 * Check if the backing link that we want to replace is frozen.
4088 * Note that
4089 * bdrv_filter_or_cow_child(overlay_bs) == overlay_bs->backing,
4090 * because we know that overlay_bs == bs, and that @bs
4091 * either is a filter that uses ->backing or a COW format BDS
4092 * with bs->drv->supports_backing == true.
4093 */
4094 if (bdrv_is_backing_chain_frozen(overlay_bs,
4095 child_bs(overlay_bs->backing), errp))
4096 {
4066 return -EPERM;
4067 }
4068 reopen_state->replace_backing_bs = true;
4069 if (new_backing_bs) {
4070 bdrv_ref(new_backing_bs);
4071 reopen_state->new_backing_bs = new_backing_bs;
4072 }
4073 }

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

4206 drv_prepared = true;
4207
4208 /*
4209 * We must provide the 'backing' option if the BDS has a backing
4210 * file or if the image file has a backing file name as part of
4211 * its metadata. Otherwise the 'backing' option can be omitted.
4212 */
4213 if (drv->supports_backing && reopen_state->backing_missing &&
4097 return -EPERM;
4098 }
4099 reopen_state->replace_backing_bs = true;
4100 if (new_backing_bs) {
4101 bdrv_ref(new_backing_bs);
4102 reopen_state->new_backing_bs = new_backing_bs;
4103 }
4104 }

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

4237 drv_prepared = true;
4238
4239 /*
4240 * We must provide the 'backing' option if the BDS has a backing
4241 * file or if the image file has a backing file name as part of
4242 * its metadata. Otherwise the 'backing' option can be omitted.
4243 */
4244 if (drv->supports_backing && reopen_state->backing_missing &&
4214 (backing_bs(reopen_state->bs) || reopen_state->bs->backing_file[0])) {
4245 (reopen_state->bs->backing || reopen_state->bs->backing_file[0])) {
4215 error_setg(errp, "backing is missing for '%s'",
4216 reopen_state->bs->node_name);
4217 ret = -EINVAL;
4218 goto error;
4219 }
4220
4221 /*
4222 * Allow changing the 'backing' option. The new value can be

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

4347 }
4348
4349 /*
4350 * Change the backing file if a new one was specified. We do this
4351 * after updating bs->options, so bdrv_refresh_filename() (called
4352 * from bdrv_set_backing_hd()) has the new values.
4353 */
4354 if (reopen_state->replace_backing_bs) {
4246 error_setg(errp, "backing is missing for '%s'",
4247 reopen_state->bs->node_name);
4248 ret = -EINVAL;
4249 goto error;
4250 }
4251
4252 /*
4253 * Allow changing the 'backing' option. The new value can be

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

4378 }
4379
4380 /*
4381 * Change the backing file if a new one was specified. We do this
4382 * after updating bs->options, so bdrv_refresh_filename() (called
4383 * from bdrv_set_backing_hd()) has the new values.
4384 */
4385 if (reopen_state->replace_backing_bs) {
4355 BlockDriverState *old_backing_bs = backing_bs(bs);
4386 BlockDriverState *old_backing_bs = child_bs(bs->backing);
4356 assert(!old_backing_bs || !old_backing_bs->implicit);
4357 /* Abort the permission update on the backing bs we're detaching */
4358 if (old_backing_bs) {
4359 bdrv_abort_perm_update(old_backing_bs);
4360 }
4361 bdrv_set_backing_hd(bs, reopen_state->new_backing_bs, &error_abort);
4362 }
4363

--- 2793 unchanged lines hidden ---
4387 assert(!old_backing_bs || !old_backing_bs->implicit);
4388 /* Abort the permission update on the backing bs we're detaching */
4389 if (old_backing_bs) {
4390 bdrv_abort_perm_update(old_backing_bs);
4391 }
4392 bdrv_set_backing_hd(bs, reopen_state->new_backing_bs, &error_abort);
4393 }
4394

--- 2793 unchanged lines hidden ---