aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorAurelien Jarno <aurelien@aurel32.net>2010-07-30 21:12:24 +0200
committerAurelien Jarno <aurelien@aurel32.net>2010-07-30 21:12:24 +0200
commitcdc6f542007a6aee0b18a5d616d031c750691e7a (patch)
treec14a02f6cdb227350b9f173fb36b78358cca5421 /block.c
parent18e9ea8a3f36b0a3845e1ac6d8acd180063bed8f (diff)
parent199630b62ec7cc5efd6f860ff545b449c7b5cdb8 (diff)
downloadqemu-cdc6f542007a6aee0b18a5d616d031c750691e7a.zip
qemu-cdc6f542007a6aee0b18a5d616d031c750691e7a.tar.gz
qemu-cdc6f542007a6aee0b18a5d616d031c750691e7a.tar.bz2
Merge branch 'for-anthony' of git://repo.or.cz/qemu/kevin
* 'for-anthony' of git://repo.or.cz/qemu/kevin: Fix -snapshot deleting images on disk change block: Use error codes from lower levels for error message block: default to 0 minimal / optiomal I/O size move 'unsafe' to end of caching modes in help virtio-blk: Create exit function to unregister savevm block migration: propagate return value when bdrv_write() returns < 0 ide/atapi: add support for GET EVENT STATUS NOTIFICATION
Diffstat (limited to 'block.c')
-rw-r--r--block.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/block.c b/block.c
index f837876..452ae94 100644
--- a/block.c
+++ b/block.c
@@ -330,7 +330,7 @@ BlockDriver *bdrv_find_protocol(const char *filename)
return NULL;
}
-static BlockDriver *find_image_format(const char *filename)
+static int find_image_format(const char *filename, BlockDriver **pdrv)
{
int ret, score, score_max;
BlockDriver *drv1, *drv;
@@ -338,19 +338,27 @@ static BlockDriver *find_image_format(const char *filename)
BlockDriverState *bs;
ret = bdrv_file_open(&bs, filename, 0);
- if (ret < 0)
- return NULL;
+ if (ret < 0) {
+ *pdrv = NULL;
+ return ret;
+ }
/* Return the raw BlockDriver * to scsi-generic devices or empty drives */
if (bs->sg || !bdrv_is_inserted(bs)) {
bdrv_delete(bs);
- return bdrv_find_format("raw");
+ drv = bdrv_find_format("raw");
+ if (!drv) {
+ ret = -ENOENT;
+ }
+ *pdrv = drv;
+ return ret;
}
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
bdrv_delete(bs);
if (ret < 0) {
- return NULL;
+ *pdrv = NULL;
+ return ret;
}
score_max = 0;
@@ -364,7 +372,11 @@ static BlockDriver *find_image_format(const char *filename)
}
}
}
- return drv;
+ if (!drv) {
+ ret = -ENOENT;
+ }
+ *pdrv = drv;
+ return ret;
}
/**
@@ -571,12 +583,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
/* Find the right image format driver */
if (!drv) {
- drv = find_image_format(filename);
+ ret = find_image_format(filename, &drv);
probed = 1;
}
if (!drv) {
- ret = -ENOENT;
goto unlink_and_fail;
}
@@ -1800,6 +1811,11 @@ int bdrv_can_snapshot(BlockDriverState *bs)
return 1;
}
+int bdrv_is_snapshot(BlockDriverState *bs)
+{
+ return !!(bs->open_flags & BDRV_O_SNAPSHOT);
+}
+
BlockDriverState *bdrv_snapshots(void)
{
BlockDriverState *bs;