[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v6 2/9] block: Change bdrv_get_encrypted_filename()
From: |
Max Reitz |
Subject: |
[Qemu-block] [PATCH v6 2/9] block: Change bdrv_get_encrypted_filename() |
Date: |
Fri, 13 Jan 2017 21:52:30 +0100 |
Instead of returning a pointer to the filename, g_strdup() it. This will
become necessary once we do not have BlockDriverState.filename anymore.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
---
include/block/block.h | 2 +-
block.c | 17 ++++++++++-------
monitor.c | 5 ++++-
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/include/block/block.h b/include/block/block.h
index 7bcbd05338..3425e9fa79 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -432,7 +432,7 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
int64_t *cluster_offset,
unsigned int *cluster_bytes);
-const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
+char *bdrv_get_encrypted_filename(BlockDriverState *bs);
void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
char *bdrv_get_full_backing_filename(BlockDriverState *bs, Error **errp);
diff --git a/block.c b/block.c
index c63fc1b2da..95015251d5 100644
--- a/block.c
+++ b/block.c
@@ -2858,10 +2858,12 @@ void bdrv_add_key(BlockDriverState *bs, const char
*key, Error **errp)
}
} else {
if (bdrv_key_required(bs)) {
+ char *enc_filename = bdrv_get_encrypted_filename(bs);
error_set(errp, ERROR_CLASS_DEVICE_ENCRYPTED,
"'%s' (%s) is encrypted",
bdrv_get_device_or_node_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename ?: "");
+ g_free(enc_filename);
}
}
}
@@ -3111,14 +3113,15 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState
*bs)
return false;
}
-const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
+char *bdrv_get_encrypted_filename(BlockDriverState *bs)
{
- if (bs->backing && bs->backing->bs->encrypted)
- return bs->backing_file;
- else if (bs->encrypted)
- return bs->filename;
- else
+ if (bs->backing && bs->backing->bs->encrypted) {
+ return g_strdup(bs->backing_file);
+ } else if (bs->encrypted) {
+ return g_strdup(bs->filename);
+ } else {
return NULL;
+ }
}
void bdrv_get_backing_filename(BlockDriverState *bs,
diff --git a/monitor.c b/monitor.c
index 0841d436b0..bb3000a2df 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4056,10 +4056,13 @@ int monitor_read_bdrv_key_start(Monitor *mon,
BlockDriverState *bs,
BlockCompletionFunc *completion_cb,
void *opaque)
{
+ char *enc_filename;
int err;
+ enc_filename = bdrv_get_encrypted_filename(bs);
monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs),
- bdrv_get_encrypted_filename(bs));
+ enc_filename ?: "");
+ g_free(enc_filename);
mon->password_completion_cb = completion_cb;
mon->password_opaque = opaque;
--
2.11.0
- [Qemu-block] [PATCH v6 0/9] block: Drop BDS.filename, Max Reitz, 2017/01/13
- [Qemu-block] [PATCH v6 1/9] block: Always set *file in get_block_status, Max Reitz, 2017/01/13
- [Qemu-block] [PATCH v6 2/9] block: Change bdrv_get_encrypted_filename(),
Max Reitz <=
- [Qemu-block] [PATCH v6 3/9] block: Avoid BlockDriverState.filename, Max Reitz, 2017/01/13
- [Qemu-block] [PATCH v6 4/9] block: Do not blindly copy filename from file, Max Reitz, 2017/01/13
- [Qemu-block] [PATCH v6 5/9] block: Add bdrv_filename(), Max Reitz, 2017/01/13
- [Qemu-block] [PATCH v6 9/9] iotests: Test changed Quorum filename, Max Reitz, 2017/01/16
- [Qemu-block] [PATCH v6 8/9] block: Complete move to pull filename updates, Max Reitz, 2017/01/16
- [Qemu-block] [PATCH v6 7/9] block: Drop BlockDriverState.filename, Max Reitz, 2017/01/16
- [Qemu-block] [PATCH v6 6/9] qemu-img: Use bdrv_filename() for map, Max Reitz, 2017/01/16