qemu: Replace deprecated option of qemu-img

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.
This commit is contained in:
Osier Yang 2011-03-10 10:05:14 +08:00
parent 340ab27dd2
commit e997c268ef

View File

@ -634,6 +634,7 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
int ret = -1; int ret = -1;
char *size = NULL; char *size = NULL;
char *create_tool; char *create_tool;
int imgformat = -1;
const char *type = virStorageFileFormatTypeToString(vol->target.format); const char *type = virStorageFileFormatTypeToString(vol->target.format);
const char *backingType = vol->backingStore.path ? const char *backingType = vol->backingStore.path ?
@ -738,6 +739,10 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
return -1; return -1;
} }
imgformat = virStorageBackendQEMUImgBackingFormat(create_tool);
if (imgformat < 0)
goto cleanup;
if (inputvol) { if (inputvol) {
const char *imgargv[] = { const char *imgargv[] = {
create_tool, create_tool,
@ -747,8 +752,19 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
inputPath, inputPath,
vol->target.path, vol->target.path,
NULL, 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); ret = virStorageBackendCreateExecCommand(pool, vol, imgargv);
} else if (vol->backingStore.path) { } else if (vol->backingStore.path) {
const char *imgargv[] = { const char *imgargv[] = {
@ -763,11 +779,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
NULL, NULL,
NULL NULL
}; };
int imgformat = virStorageBackendQEMUImgBackingFormat(create_tool);
char *optflag = NULL;
if (imgformat < 0)
goto cleanup;
char *optflag = NULL;
switch (imgformat) { switch (imgformat) {
case QEMU_IMG_BACKING_FORMAT_FLAG: case QEMU_IMG_BACKING_FORMAT_FLAG:
imgargv[6] = "-F"; imgargv[6] = "-F";
@ -783,13 +796,21 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
virReportOOMError(); virReportOOMError();
goto cleanup; 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[6] = "-o";
imgargv[7] = optflag; imgargv[7] = optflag;
imgargv[8] = vol->target.path; imgargv[8] = vol->target.path;
imgargv[9] = size; imgargv[9] = size;
if (vol->target.encryption != NULL)
imgargv[10] = "-e";
break;
default: default:
VIR_INFO("Unable to set backing store format for %s with %s", VIR_INFO("Unable to set backing store format for %s with %s",
@ -811,10 +832,18 @@ virStorageBackendCreateQemuImg(virConnectPtr conn,
vol->target.path, vol->target.path,
size, size,
NULL, NULL,
NULL,
NULL NULL
}; };
if (vol->target.encryption != NULL)
if (vol->target.encryption != NULL) {
if (imgformat == QEMU_IMG_BACKING_FORMAT_FLAG) {
imgargv[6] = "-o";
imgargv[7] = "encryption=on";
} else {
imgargv[6] = "-e"; imgargv[6] = "-e";
}
}
ret = virStorageBackendCreateExecCommand(pool, vol, imgargv); ret = virStorageBackendCreateExecCommand(pool, vol, imgargv);
} }