aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorNaphtali Sprei <nsprei@redhat.com>2010-01-17 16:48:13 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-01-20 08:25:22 -0600
commitf5edb014ed221db6942225ec675aafe2675632dd (patch)
tree8c4d10e0d64b55c4320e1837749fc03cbf80941e /block.c
parentb196b1532f2981e9c811c96214a44ee9e7d12af3 (diff)
Clean-up a little bit the RW related bits of BDRV_O_FLAGS. BDRV_O_RDONLY gone (and so is BDRV_O_ACCESS). Default value for bdrv_flags (0/zero) is READ-ONLY. Need to explicitly request READ-WRITE.
Instead of using the field 'readonly' of the BlockDriverState struct for passing the request, pass the request in the flags parameter to the function. Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'block.c')
-rw-r--r--block.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/block.c b/block.c
index 115e5913eb..8def3c4801 100644
--- a/block.c
+++ b/block.c
@@ -310,7 +310,7 @@ static BlockDriver *find_image_format(const char *filename)
if (drv && strcmp(drv->format_name, "vvfat") == 0)
return drv;
- ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
+ ret = bdrv_file_open(&bs, filename, 0);
if (ret < 0)
return NULL;
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
@@ -356,7 +356,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags)
int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
BlockDriver *drv)
{
- int ret, open_flags, try_rw;
+ int ret, open_flags;
char tmp_filename[PATH_MAX];
char backing_filename[PATH_MAX];
@@ -446,19 +446,23 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
/* Note: for compatibility, we open disk image files as RDWR, and
RDONLY as fallback */
- try_rw = !bs->read_only || bs->is_temporary;
- if (!(flags & BDRV_O_FILE))
- open_flags = (try_rw ? BDRV_O_RDWR : 0) |
- (flags & (BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO));
- else
+ bs->read_only = (flags & BDRV_O_RDWR) == 0;
+ if (!(flags & BDRV_O_FILE)) {
+ open_flags = (flags & (BDRV_O_RDWR | BDRV_O_CACHE_MASK|BDRV_O_NATIVE_AIO));
+ if (bs->is_temporary) { /* snapshot should be writeable */
+ open_flags |= BDRV_O_RDWR;
+ }
+ } else {
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
- if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv))
+ }
+ if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
ret = -ENOTSUP;
- else
+ } else {
ret = drv->bdrv_open(bs, filename, open_flags);
- if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
- ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
- bs->read_only = 1;
+ if ((ret == -EACCES || ret == -EPERM) && !(flags & BDRV_O_FILE)) {
+ ret = drv->bdrv_open(bs, filename, open_flags & ~BDRV_O_RDWR);
+ bs->read_only = 1;
+ }
}
if (ret < 0) {
qemu_free(bs->opaque);
@@ -481,14 +485,13 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
/* if there is a backing file, use it */
BlockDriver *back_drv = NULL;
bs->backing_hd = bdrv_new("");
- /* pass on read_only property to the backing_hd */
- bs->backing_hd->read_only = bs->read_only;
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
if (bs->backing_format[0] != '\0')
back_drv = bdrv_find_format(bs->backing_format);
ret = bdrv_open2(bs->backing_hd, backing_filename, open_flags,
back_drv);
+ bs->backing_hd->read_only = (open_flags & BDRV_O_RDWR) == 0;
if (ret < 0) {
bdrv_close(bs);
return ret;