[libvirt] [PATCH v2] qemu: Replace deprecated option of qemu-img
Daniel P. Berrange
berrange at redhat.com
Wed Mar 9 16:44:31 UTC 2011
On Wed, Mar 09, 2011 at 10:12:53PM +0800, Osier Yang wrote:
> qemu-img silently disable "-e", so we can't use it for volume
> encryption anymore, change it into "-o encryption=on" if qemu
> supports "-o" option.
> ---
> src/storage/storage_backend.c | 47 +++++++++++++++++++++++++++++++++-------
> 1 files changed, 38 insertions(+), 9 deletions(-)
>
> diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
> index 2eede74..ec122a9 100644
> --- a/src/storage/storage_backend.c
> +++ b/src/storage/storage_backend.c
> @@ -637,6 +637,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> int ret = -1;
> char *size = NULL;
> char *create_tool;
> + int imgformat = -1;
>
> const char *type = virStorageFileFormatTypeToString(vol->target.format);
> const char *backingType = vol->backingStore.path ?
> @@ -741,6 +742,10 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> return -1;
> }
>
> + imgformat = virStorageBackendQEMUImgBackingFormat(create_tool);
> + if (imgformat < 0)
> + goto cleanup;
> +
> if (inputvol) {
> const char *imgargv[] = {
> create_tool,
> @@ -750,8 +755,19 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> inputPath,
> vol->target.path,
> NULL,
> + NULL,
> + NULL
> };
>
> + if (vol->target.encryption != NULL) {
> + if (imgformat == QEMU_IMG_BACKING_FORMAT_FLAG) {
> + imgargv[8] = "-o";
> + imgargv[9] = "encryption=on";
> + } else {
> + imgargv[8] = "-e";
> + }
> + }
> +
> ret = virStorageBackendCreateExecCommand(pool, vol, imgargv);
> } else if (vol->backingStore.path) {
> const char *imgargv[] = {
> @@ -766,11 +782,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> NULL,
> NULL
> };
> - int imgformat = virStorageBackendQEMUImgBackingFormat(create_tool);
> - char *optflag = NULL;
> - if (imgformat < 0)
> - goto cleanup;
>
> + char *optflag = NULL;
> switch (imgformat) {
> case QEMU_IMG_BACKING_FORMAT_FLAG:
> imgargv[6] = "-F";
> @@ -786,13 +799,21 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> virReportOOMError();
> goto cleanup;
> }
> +
> + if (vol->target.encryption != NULL) {
> + char *tmp = NULL;
> + if (virAsprintf(&tmp, "%s,%s", optflag, "encryption=on") < 0) {
> + virReportOOMError();
> + goto cleanup;
> + }
> + VIR_FREE(optflag);
> + optflag = tmp;
> + }
> +
> imgargv[6] = "-o";
> imgargv[7] = optflag;
> imgargv[8] = vol->target.path;
> imgargv[9] = size;
> - if (vol->target.encryption != NULL)
> - imgargv[10] = "-e";
> - break;
>
> default:
> VIR_INFO("Unable to set backing store format for %s with %s",
> @@ -814,10 +835,18 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
> vol->target.path,
> size,
> NULL,
> + NULL,
> NULL
> };
> - if (vol->target.encryption != NULL)
> - imgargv[6] = "-e";
> +
> + if (vol->target.encryption != NULL) {
> + if (imgformat == QEMU_IMG_BACKING_FORMAT_FLAG) {
> + imgargv[6] = "-o";
> + imgargv[7] = "encryption=on";
> + } else {
> + imgargv[6] = "-e";
> + }
> + }
>
> ret = virStorageBackendCreateExecCommand(pool, vol, imgargv);
> }
ACK, looks better now
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list