block: clean up bdrv_open2 structure a bit
Check the whitelist as early as possible instead of continuing the setup, and move all the error handling code to the end of the function. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
392ecf543d
commit
6987307ca3
31
block.c
31
block.c
@ -428,10 +428,16 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
|||||||
drv = find_image_format(filename);
|
drv = find_image_format(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!drv) {
|
if (!drv) {
|
||||||
ret = -ENOENT;
|
ret = -ENOENT;
|
||||||
goto unlink_and_fail;
|
goto unlink_and_fail;
|
||||||
}
|
}
|
||||||
|
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
|
||||||
|
ret = -ENOTSUP;
|
||||||
|
goto unlink_and_fail;
|
||||||
|
}
|
||||||
|
|
||||||
bs->drv = drv;
|
bs->drv = drv;
|
||||||
bs->opaque = qemu_mallocz(drv->instance_size);
|
bs->opaque = qemu_mallocz(drv->instance_size);
|
||||||
|
|
||||||
@ -453,20 +459,12 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
|||||||
} else {
|
} else {
|
||||||
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
|
open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
|
||||||
}
|
}
|
||||||
if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv)) {
|
|
||||||
ret = -ENOTSUP;
|
ret = drv->bdrv_open(bs, filename, open_flags);
|
||||||
} else {
|
|
||||||
ret = drv->bdrv_open(bs, filename, open_flags);
|
|
||||||
}
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
qemu_free(bs->opaque);
|
goto free_and_fail;
|
||||||
bs->opaque = NULL;
|
|
||||||
bs->drv = NULL;
|
|
||||||
unlink_and_fail:
|
|
||||||
if (bs->is_temporary)
|
|
||||||
unlink(filename);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drv->bdrv_getlength) {
|
if (drv->bdrv_getlength) {
|
||||||
bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
bs->total_sectors = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
|
||||||
}
|
}
|
||||||
@ -499,6 +497,15 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int flags,
|
|||||||
bs->change_cb(bs->change_opaque);
|
bs->change_cb(bs->change_opaque);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
free_and_fail:
|
||||||
|
qemu_free(bs->opaque);
|
||||||
|
bs->opaque = NULL;
|
||||||
|
bs->drv = NULL;
|
||||||
|
unlink_and_fail:
|
||||||
|
if (bs->is_temporary)
|
||||||
|
unlink(filename);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bdrv_close(BlockDriverState *bs)
|
void bdrv_close(BlockDriverState *bs)
|
||||||
|
Loading…
Reference in New Issue
Block a user