[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v3 08/38] block: JSON filenames and relative backing
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL v3 08/38] block: JSON filenames and relative backing files |
Date: |
Tue, 13 Jan 2015 13:47:46 +0000 |
From: Max Reitz <address@hidden>
When using a relative backing file name, qemu needs to know the
directory of the top image file. For JSON filenames, such a directory
cannot be easily determined (e.g. how do you determine the directory of
a qcow2 BDS directly on top of a quorum BDS?). Therefore, do not allow
relative filenames for the backing file of BDSs only having a JSON
filename.
Furthermore, BDS::exact_filename should be used whenever possible. If
BDS::filename is not equal to BDS::exact_filename, the former will
always be a JSON object.
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 28 ++++++++++++++++++++++------
block/qapi.c | 7 ++++++-
include/block/block.h | 5 +++--
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/block.c b/block.c
index 86f2faa..cf0867c 100644
--- a/block.c
+++ b/block.c
@@ -305,19 +305,28 @@ void path_combine(char *dest, int dest_size,
void bdrv_get_full_backing_filename_from_filename(const char *backed,
const char *backing,
- char *dest, size_t sz)
+ char *dest, size_t sz,
+ Error **errp)
{
- if (backing[0] == '\0' || path_has_protocol(backing)) {
+ if (backing[0] == '\0' || path_has_protocol(backing) ||
+ path_is_absolute(backing))
+ {
pstrcpy(dest, sz, backing);
+ } else if (backed[0] == '\0' || strstart(backed, "json:", NULL)) {
+ error_setg(errp, "Cannot use relative backing file names for '%s'",
+ backed);
} else {
path_combine(dest, sz, backed, backing);
}
}
-void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t
sz)
+void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t
sz,
+ Error **errp)
{
- bdrv_get_full_backing_filename_from_filename(bs->filename,
bs->backing_file,
- dest, sz);
+ char *backed = bs->exact_filename[0] ? bs->exact_filename : bs->filename;
+
+ bdrv_get_full_backing_filename_from_filename(backed, bs->backing_file,
+ dest, sz, errp);
}
void bdrv_register(BlockDriver *bdrv)
@@ -1225,7 +1234,14 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict
*options, Error **errp)
QDECREF(options);
goto free_exit;
} else {
- bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX);
+ bdrv_get_full_backing_filename(bs, backing_filename, PATH_MAX,
+ &local_err);
+ if (local_err) {
+ ret = -EINVAL;
+ error_propagate(errp, local_err);
+ QDECREF(options);
+ goto free_exit;
+ }
}
if (!bs->drv || !bs->drv->supports_backing) {
diff --git a/block/qapi.c b/block/qapi.c
index fa68ba7..a6fd6f7 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -214,7 +214,12 @@ void bdrv_query_image_info(BlockDriverState *bs,
info->backing_filename = g_strdup(backing_filename);
info->has_backing_filename = true;
bdrv_get_full_backing_filename(bs, backing_filename2,
- sizeof(backing_filename2));
+ sizeof(backing_filename2), &err);
+ if (err) {
+ error_propagate(errp, err);
+ qapi_free_ImageInfo(info);
+ return;
+ }
if (strcmp(backing_filename, backing_filename2) != 0) {
info->full_backing_filename =
diff --git a/include/block/block.h b/include/block/block.h
index eac9bb0..9efaa80 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -396,10 +396,11 @@ const char *bdrv_get_encrypted_filename(BlockDriverState
*bs);
void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
void bdrv_get_full_backing_filename(BlockDriverState *bs,
- char *dest, size_t sz);
+ char *dest, size_t sz, Error **errp);
void bdrv_get_full_backing_filename_from_filename(const char *backed,
const char *backing,
- char *dest, size_t sz);
+ char *dest, size_t sz,
+ Error **errp);
int bdrv_is_snapshot(BlockDriverState *bs);
int path_has_protocol(const char *path);
--
2.1.0
- [Qemu-devel] [PULL v3 00/38] Block patches, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 02/38] qemu-iotests: Speed up make check-block, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 01/38] qemu-iotests: Remove 091 from quick group, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 05/38] block: replace g_new0 with g_new for bottom half allocation., Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 03/38] block: mark AioContext as recursive, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 06/38] checkpatch: Brace handling on multi-line condition, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 04/38] block: do not allocate an iovec per read of a growable/zero_after_eof BDS, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 07/38] block: Get full backing filename from string, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 09/38] block: Relative backing file for image creation, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 10/38] block/vmdk: Relative backing file for creation, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 08/38] block: JSON filenames and relative backing files,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL v3 13/38] block: fix spoiling all dirty bitmaps by mirror and migration, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 11/38] iotests: Add test for relative backing file names, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 14/38] qapi: Comment version info in TransactionAction, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 12/38] qapi: Fix document for BlockStats.node-name, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 15/38] qmp: Add command 'blockdev-backup', Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 16/38] block: Add blockdev-backup to transaction, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 17/38] qemu-iotests: Test blockdev-backup in 055, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 18/38] iotests: Filter out "I/O thread spun..." warning, Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 21/38] .gitignore: Ignore generated "common.env", Stefan Hajnoczi, 2015/01/13
- [Qemu-devel] [PULL v3 19/38] migration/block: fix pending() return value, Stefan Hajnoczi, 2015/01/13