block.c (8aecf1d1bd250a7346165de154f5ccc150ad1aa7) block.c (54a32bfec140e03ebb19863db944b1c81e4df25e)
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

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

241}
242
243/* Returns whether the image file can be written to right now */
244bool bdrv_is_writable(BlockDriverState *bs)
245{
246 return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE);
247}
248
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

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

241}
242
243/* Returns whether the image file can be written to right now */
244bool bdrv_is_writable(BlockDriverState *bs)
245{
246 return !bdrv_is_read_only(bs) && !(bs->open_flags & BDRV_O_INACTIVE);
247}
248
249int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
249int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
250 bool ignore_allow_rdw, Error **errp)
250{
251 /* Do not set read_only if copy_on_read is enabled */
252 if (bs->copy_on_read && read_only) {
253 error_setg(errp, "Can't set node '%s' to r/o with copy-on-read enabled",
254 bdrv_get_device_or_node_name(bs));
255 return -EINVAL;
256 }
257
258 /* Do not clear read_only if it is prohibited */
251{
252 /* Do not set read_only if copy_on_read is enabled */
253 if (bs->copy_on_read && read_only) {
254 error_setg(errp, "Can't set node '%s' to r/o with copy-on-read enabled",
255 bdrv_get_device_or_node_name(bs));
256 return -EINVAL;
257 }
258
259 /* Do not clear read_only if it is prohibited */
259 if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR)) {
260 if (!read_only && !(bs->open_flags & BDRV_O_ALLOW_RDWR) &&
261 !ignore_allow_rdw)
262 {
260 error_setg(errp, "Node '%s' is read only",
261 bdrv_get_device_or_node_name(bs));
262 return -EPERM;
263 }
264
265 return 0;
266}
267
268int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
269{
270 int ret = 0;
271
263 error_setg(errp, "Node '%s' is read only",
264 bdrv_get_device_or_node_name(bs));
265 return -EPERM;
266 }
267
268 return 0;
269}
270
271int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp)
272{
273 int ret = 0;
274
272 ret = bdrv_can_set_read_only(bs, read_only, errp);
275 ret = bdrv_can_set_read_only(bs, read_only, false, errp);
273 if (ret < 0) {
274 return ret;
275 }
276
277 bs->read_only = read_only;
278 return 0;
279}
280

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

2902 if (value) {
2903 qdict_put_str(reopen_state->options, "driver", value);
2904 }
2905
2906 /* If we are to stay read-only, do not allow permission change
2907 * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is
2908 * not set, or if the BDS still has copy_on_read enabled */
2909 read_only = !(reopen_state->flags & BDRV_O_RDWR);
276 if (ret < 0) {
277 return ret;
278 }
279
280 bs->read_only = read_only;
281 return 0;
282}
283

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

2905 if (value) {
2906 qdict_put_str(reopen_state->options, "driver", value);
2907 }
2908
2909 /* If we are to stay read-only, do not allow permission change
2910 * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is
2911 * not set, or if the BDS still has copy_on_read enabled */
2912 read_only = !(reopen_state->flags & BDRV_O_RDWR);
2910 ret = bdrv_can_set_read_only(reopen_state->bs, read_only, &local_err);
2913 ret = bdrv_can_set_read_only(reopen_state->bs, read_only, true, &local_err);
2911 if (local_err) {
2912 error_propagate(errp, local_err);
2913 goto error;
2914 }
2915
2916
2917 ret = bdrv_flush(reopen_state->bs);
2918 if (ret) {

--- 2023 unchanged lines hidden ---
2914 if (local_err) {
2915 error_propagate(errp, local_err);
2916 goto error;
2917 }
2918
2919
2920 ret = bdrv_flush(reopen_state->bs);
2921 if (ret) {

--- 2023 unchanged lines hidden ---