提交 423b4f66 编写于 作者: P Peter Krempa

qemu: block: Allow skipping non-target related data when formating disk JSON

When formatting new qcow2 images we need to provide the backing store
string which should not contain any authentication or irrelevant data.

Add a flag for qemuBlockStorageSourceGetBackendProps which allows to
skip the irrelevant data.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 aa7d7313
...@@ -624,7 +624,8 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src) ...@@ -624,7 +624,8 @@ qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src, qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
bool legacy) bool legacy,
bool onlytarget)
{ {
VIR_AUTOPTR(virJSONValue) servers = NULL; VIR_AUTOPTR(virJSONValue) servers = NULL;
VIR_AUTOPTR(virJSONValue) props = NULL; VIR_AUTOPTR(virJSONValue) props = NULL;
...@@ -645,7 +646,8 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src, ...@@ -645,7 +646,8 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
"a:server", &servers, NULL) < 0) "a:server", &servers, NULL) < 0)
return NULL; return NULL;
if (src->debug && if (!onlytarget &&
src->debug &&
virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0) virJSONValueObjectAdd(props, "u:debug", src->debugLevel, NULL) < 0)
return NULL; return NULL;
...@@ -654,10 +656,12 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src, ...@@ -654,10 +656,12 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src,
bool onlytarget)
{ {
const char *protocol = virStorageNetProtocolTypeToString(src->protocol); const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
VIR_AUTOPTR(virJSONValue) server = NULL; VIR_AUTOPTR(virJSONValue) server = NULL;
const char *tlsAlias = src->tlsAlias;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
if (src->nhosts != 1) { if (src->nhosts != 1) {
...@@ -669,6 +673,9 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) ...@@ -669,6 +673,9 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src)
if (!(server = qemuBlockStorageSourceBuildJSONInetSocketAddress(&src->hosts[0]))) if (!(server = qemuBlockStorageSourceBuildJSONInetSocketAddress(&src->hosts[0])))
return NULL; return NULL;
if (onlytarget)
tlsAlias = NULL;
/* VxHS disk specification example: /* VxHS disk specification example:
* { driver:"vxhs", * { driver:"vxhs",
* tls-creds:"objvirtio-disk0_tls0", * tls-creds:"objvirtio-disk0_tls0",
...@@ -677,7 +684,7 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) ...@@ -677,7 +684,7 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src)
*/ */
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", protocol, "s:driver", protocol,
"S:tls-creds", src->tlsAlias, "S:tls-creds", tlsAlias,
"s:vdisk-id", src->path, "s:vdisk-id", src->path,
"a:server", &server, NULL)); "a:server", &server, NULL));
...@@ -686,7 +693,8 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src) ...@@ -686,7 +693,8 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src) qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
bool onlytarget)
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
const char *passwordalias = NULL; const char *passwordalias = NULL;
...@@ -716,7 +724,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src) ...@@ -716,7 +724,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src)
if (!(uristr = virURIFormat(uri))) if (!(uristr = virURIFormat(uri)))
return NULL; return NULL;
if (src->auth) { if (!onlytarget && src->auth) {
username = src->auth->username; username = src->auth->username;
passwordalias = srcPriv->secinfo->s.aes.alias; passwordalias = srcPriv->secinfo->s.aes.alias;
} }
...@@ -733,7 +741,8 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src) ...@@ -733,7 +741,8 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src) qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src,
bool onlytarget)
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
const char *protocol = virStorageNetProtocolTypeToString(src->protocol); const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
...@@ -781,7 +790,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src) ...@@ -781,7 +790,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
return NULL; return NULL;
} }
if (src->auth) { if (!onlytarget && src->auth) {
username = src->auth->username; username = src->auth->username;
objalias = srcPriv->secinfo->s.aes.alias; objalias = srcPriv->secinfo->s.aes.alias;
} }
...@@ -801,9 +810,11 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src) ...@@ -801,9 +810,11 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src) qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src,
bool onlytarget)
{ {
VIR_AUTOPTR(virJSONValue) serverprops = NULL; VIR_AUTOPTR(virJSONValue) serverprops = NULL;
const char *tlsAlias = src->tlsAlias;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
if (src->nhosts != 1) { if (src->nhosts != 1) {
...@@ -817,11 +828,14 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src) ...@@ -817,11 +828,14 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src)
if (!serverprops) if (!serverprops)
return NULL; return NULL;
if (onlytarget)
tlsAlias = NULL;
if (virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "nbd", "s:driver", "nbd",
"a:server", &serverprops, "a:server", &serverprops,
"S:export", src->path, "S:export", src->path,
"S:tls-creds", src->tlsAlias, "S:tls-creds", tlsAlias,
NULL) < 0) NULL) < 0)
return NULL; return NULL;
...@@ -830,7 +844,8 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src) ...@@ -830,7 +844,8 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src) qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src,
bool onlytarget)
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
VIR_AUTOPTR(virJSONValue) servers = NULL; VIR_AUTOPTR(virJSONValue) servers = NULL;
...@@ -844,7 +859,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src) ...@@ -844,7 +859,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src)
!(servers = qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(src))) !(servers = qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(src)))
return NULL; return NULL;
if (src->auth) { if (!onlytarget && src->auth) {
username = srcPriv->secinfo->s.aes.username; username = srcPriv->secinfo->s.aes.username;
keysecret = srcPriv->secinfo->s.aes.alias; keysecret = srcPriv->secinfo->s.aes.alias;
/* the auth modes are modelled after our old command line generator */ /* the auth modes are modelled after our old command line generator */
...@@ -943,16 +958,14 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src) ...@@ -943,16 +958,14 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src) qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src,
bool onlytarget)
{ {
const char *driver = "file"; const char *driver = "file";
const char *iomode = NULL; const char *iomode = NULL;
const char *prManagerAlias = NULL; const char *prManagerAlias = NULL;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
if (src->iomode != VIR_DOMAIN_DISK_IO_DEFAULT)
iomode = virDomainDiskIoTypeToString(src->iomode);
if (virStorageSourceIsBlockLocal(src)) { if (virStorageSourceIsBlockLocal(src)) {
if (src->hostcdrom) if (src->hostcdrom)
driver = "host_cdrom"; driver = "host_cdrom";
...@@ -960,9 +973,14 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src) ...@@ -960,9 +973,14 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src)
driver = "host_device"; driver = "host_device";
} }
if (!onlytarget) {
if (src->pr) if (src->pr)
prManagerAlias = src->pr->mgralias; prManagerAlias = src->pr->mgralias;
if (src->iomode != VIR_DOMAIN_DISK_IO_DEFAULT)
iomode = virDomainDiskIoTypeToString(src->iomode);
}
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", driver, "s:driver", driver,
"s:filename", src->path, "s:filename", src->path,
...@@ -974,21 +992,26 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src) ...@@ -974,21 +992,26 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src)
static virJSONValuePtr static virJSONValuePtr
qemuBlockStorageSourceGetVvfatProps(virStorageSourcePtr src) qemuBlockStorageSourceGetVvfatProps(virStorageSourcePtr src,
bool onlytarget)
{ {
virJSONValuePtr ret = NULL; VIR_AUTOPTR(virJSONValue) ret = NULL;
/* libvirt currently does not handle the following attributes: /* libvirt currently does not handle the following attributes:
* '*fat-type': 'int' * '*fat-type': 'int'
* '*label': 'str' * '*label': 'str'
*/ */
ignore_value(virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "vvfat", "s:driver", "vvfat",
"s:dir", src->path, "s:dir", src->path,
"b:floppy", src->floppyimg, "b:floppy", src->floppyimg, NULL) < 0)
"b:rw", !src->readonly, NULL)); return NULL;
return ret; if (!onlytarget &&
virJSONValueObjectAdd(ret, "b:rw", !src->readonly, NULL) < 0)
return NULL;
VIR_RETURN_PTR(ret);
} }
...@@ -1024,13 +1047,15 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src, ...@@ -1024,13 +1047,15 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src,
* qemuBlockStorageSourceGetBackendProps: * qemuBlockStorageSourceGetBackendProps:
* @src: disk source * @src: disk source
* @legacy: use legacy formatting of attributes (for -drive / old qemus) * @legacy: use legacy formatting of attributes (for -drive / old qemus)
* @onlytarget: omit any data which does not identify the image itself
* *
* Creates a JSON object describing the underlying storage or protocol of a * Creates a JSON object describing the underlying storage or protocol of a
* storage source. Returns NULL on error and reports an appropriate error message. * storage source. Returns NULL on error and reports an appropriate error message.
*/ */
virJSONValuePtr virJSONValuePtr
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
bool legacy) bool legacy,
bool onlytarget)
{ {
int actualType = virStorageSourceGetActualType(src); int actualType = virStorageSourceGetActualType(src);
VIR_AUTOPTR(virJSONValue) fileprops = NULL; VIR_AUTOPTR(virJSONValue) fileprops = NULL;
...@@ -1038,14 +1063,14 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1038,14 +1063,14 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
switch ((virStorageType)actualType) { switch ((virStorageType)actualType) {
case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_FILE:
if (!(fileprops = qemuBlockStorageSourceGetFileProps(src))) if (!(fileprops = qemuBlockStorageSourceGetFileProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_DIR:
/* qemu handles directories by exposing them as a device with emulated /* qemu handles directories by exposing them as a device with emulated
* FAT filesystem */ * FAT filesystem */
if (!(fileprops = qemuBlockStorageSourceGetVvfatProps(src))) if (!(fileprops = qemuBlockStorageSourceGetVvfatProps(src, onlytarget)))
return NULL; return NULL;
break; break;
...@@ -1057,12 +1082,12 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1057,12 +1082,12 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
case VIR_STORAGE_TYPE_NETWORK: case VIR_STORAGE_TYPE_NETWORK:
switch ((virStorageNetProtocol) src->protocol) { switch ((virStorageNetProtocol) src->protocol) {
case VIR_STORAGE_NET_PROTOCOL_GLUSTER: case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, legacy))) if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, legacy, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_VXHS: case VIR_STORAGE_NET_PROTOCOL_VXHS:
if (!(fileprops = qemuBlockStorageSourceGetVxHSProps(src))) if (!(fileprops = qemuBlockStorageSourceGetVxHSProps(src, onlytarget)))
return NULL; return NULL;
break; break;
...@@ -1071,22 +1096,22 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1071,22 +1096,22 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
case VIR_STORAGE_NET_PROTOCOL_FTP: case VIR_STORAGE_NET_PROTOCOL_FTP:
case VIR_STORAGE_NET_PROTOCOL_FTPS: case VIR_STORAGE_NET_PROTOCOL_FTPS:
case VIR_STORAGE_NET_PROTOCOL_TFTP: case VIR_STORAGE_NET_PROTOCOL_TFTP:
if (!(fileprops = qemuBlockStorageSourceGetCURLProps(src))) if (!(fileprops = qemuBlockStorageSourceGetCURLProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_ISCSI: case VIR_STORAGE_NET_PROTOCOL_ISCSI:
if (!(fileprops = qemuBlockStorageSourceGetISCSIProps(src))) if (!(fileprops = qemuBlockStorageSourceGetISCSIProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_NBD:
if (!(fileprops = qemuBlockStorageSourceGetNBDProps(src))) if (!(fileprops = qemuBlockStorageSourceGetNBDProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_RBD: case VIR_STORAGE_NET_PROTOCOL_RBD:
if (!(fileprops = qemuBlockStorageSourceGetRBDProps(src))) if (!(fileprops = qemuBlockStorageSourceGetRBDProps(src, onlytarget)))
return NULL; return NULL;
break; break;
...@@ -1107,6 +1132,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1107,6 +1132,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
break; break;
} }
if (!onlytarget) {
if (qemuBlockNodeNameValidate(src->nodestorage) < 0 || if (qemuBlockNodeNameValidate(src->nodestorage) < 0 ||
virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage, NULL) < 0) virJSONValueObjectAdd(fileprops, "S:node-name", src->nodestorage, NULL) < 0)
return NULL; return NULL;
...@@ -1121,6 +1147,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1121,6 +1147,7 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
NULL) < 0) NULL) < 0)
return NULL; return NULL;
} }
}
VIR_RETURN_PTR(fileprops); VIR_RETURN_PTR(fileprops);
} }
...@@ -1440,7 +1467,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src) ...@@ -1440,7 +1467,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
return NULL; return NULL;
if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src)) || if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src)) ||
!(data->storageProps = qemuBlockStorageSourceGetBackendProps(src, false))) !(data->storageProps = qemuBlockStorageSourceGetBackendProps(src, false, false)))
return NULL; return NULL;
data->storageNodeName = src->nodestorage; data->storageNodeName = src->nodestorage;
......
...@@ -58,7 +58,8 @@ qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src); ...@@ -58,7 +58,8 @@ qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src);
virJSONValuePtr virJSONValuePtr
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
bool legacy); bool legacy,
bool onlytarget);
virURIPtr virURIPtr
qemuBlockStorageSourceGetURI(virStorageSourcePtr src); qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
......
...@@ -1602,7 +1602,7 @@ qemuDiskSourceGetProps(virStorageSourcePtr src) ...@@ -1602,7 +1602,7 @@ qemuDiskSourceGetProps(virStorageSourcePtr src)
virJSONValuePtr props; virJSONValuePtr props;
virJSONValuePtr ret; virJSONValuePtr ret;
if (!(props = qemuBlockStorageSourceGetBackendProps(src, true))) if (!(props = qemuBlockStorageSourceGetBackendProps(src, true, false)))
return NULL; return NULL;
if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0) { if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0) {
......
...@@ -67,7 +67,7 @@ testBackingXMLjsonXML(const void *args) ...@@ -67,7 +67,7 @@ testBackingXMLjsonXML(const void *args)
return -1; return -1;
} }
if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc, true))) { if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc, true, false))) {
fprintf(stderr, "failed to format disk source json\n"); fprintf(stderr, "failed to format disk source json\n");
return -1; return -1;
} }
...@@ -213,7 +213,7 @@ testQemuDiskXMLToProps(const void *opaque) ...@@ -213,7 +213,7 @@ testQemuDiskXMLToProps(const void *opaque)
goto cleanup; goto cleanup;
if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n)) || if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n)) ||
!(storageProps = qemuBlockStorageSourceGetBackendProps(n, false))) { !(storageProps = qemuBlockStorageSourceGetBackendProps(n, false, false))) {
if (!data->fail) { if (!data->fail) {
VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n"); VIR_TEST_VERBOSE("failed to generate qemu blockdev props\n");
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册