提交 8e0b1f8a 编写于 作者: P Peter Krempa

qemu: block: Extract formatting of 'driver' attribute from child formatters

To allow reusing the formatters in the code for creating JSON properties
for 'blockdev-create' we need to create everything except the 'driver'
attribute.

Use the new helper virJSONValueObjectPrependString to put the driver at
the same place so that we don't change any output.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 12a330b5
...@@ -640,7 +640,6 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src, ...@@ -640,7 +640,6 @@ qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src,
* {type:"unix", socket:"/tmp/glusterd.socket"}, ...]} * {type:"unix", socket:"/tmp/glusterd.socket"}, ...]}
*/ */
if (virJSONValueObjectCreate(&props, if (virJSONValueObjectCreate(&props,
"s:driver", "gluster",
"s:volume", src->volume, "s:volume", src->volume,
"s:path", src->path, "s:path", src->path,
"a:server", &servers, NULL) < 0) "a:server", &servers, NULL) < 0)
...@@ -659,7 +658,6 @@ static virJSONValuePtr ...@@ -659,7 +658,6 @@ static virJSONValuePtr
qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src, qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src,
bool onlytarget) bool onlytarget)
{ {
const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
VIR_AUTOPTR(virJSONValue) server = NULL; VIR_AUTOPTR(virJSONValue) server = NULL;
const char *tlsAlias = src->tlsAlias; const char *tlsAlias = src->tlsAlias;
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
...@@ -683,7 +681,6 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src, ...@@ -683,7 +681,6 @@ qemuBlockStorageSourceGetVxHSProps(virStorageSourcePtr src,
* server:{type:"tcp", host:"1.2.3.4", port:9999}} * server:{type:"tcp", host:"1.2.3.4", port:9999}}
*/ */
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", protocol,
"S:tls-creds", tlsAlias, "S:tls-creds", tlsAlias,
"s:vdisk-id", src->path, "s:vdisk-id", src->path,
"a:server", &server, NULL)); "a:server", &server, NULL));
...@@ -702,7 +699,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src, ...@@ -702,7 +699,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
VIR_AUTOPTR(virURI) uri = NULL; VIR_AUTOPTR(virURI) uri = NULL;
VIR_AUTOFREE(char *) uristr = NULL; VIR_AUTOFREE(char *) uristr = NULL;
const char *driver;
/** /**
* Common options: * Common options:
...@@ -716,7 +712,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src, ...@@ -716,7 +712,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
* sslverify * sslverify
*/ */
driver = virStorageNetProtocolTypeToString(src->protocol);
if (!(uri = qemuBlockStorageSourceGetURI(src))) if (!(uri = qemuBlockStorageSourceGetURI(src)))
return NULL; return NULL;
...@@ -730,7 +725,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src, ...@@ -730,7 +725,6 @@ qemuBlockStorageSourceGetCURLProps(virStorageSourcePtr src,
} }
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", driver,
"s:url", uristr, "s:url", uristr,
"S:username", username, "S:username", username,
"S:password-secret", passwordalias, "S:password-secret", passwordalias,
...@@ -745,7 +739,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src, ...@@ -745,7 +739,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src,
bool onlytarget) bool onlytarget)
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
VIR_AUTOFREE(char *) target = NULL; VIR_AUTOFREE(char *) target = NULL;
char *lunStr = NULL; char *lunStr = NULL;
char *username = NULL; char *username = NULL;
...@@ -796,7 +789,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src, ...@@ -796,7 +789,6 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src,
} }
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", protocol,
"s:portal", portal, "s:portal", portal,
"s:target", target, "s:target", target,
"u:lun", lun, "u:lun", lun,
...@@ -832,7 +824,6 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src, ...@@ -832,7 +824,6 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src,
tlsAlias = NULL; tlsAlias = NULL;
if (virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "nbd",
"a:server", &serverprops, "a:server", &serverprops,
"S:export", src->path, "S:export", src->path,
"S:tls-creds", tlsAlias, "S:tls-creds", tlsAlias,
...@@ -880,7 +871,6 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src, ...@@ -880,7 +871,6 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src,
} }
if (virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "rbd",
"s:pool", src->volume, "s:pool", src->volume,
"s:image", src->path, "s:image", src->path,
"S:snapshot", src->snapshot, "S:snapshot", src->snapshot,
...@@ -915,7 +905,6 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSourcePtr src) ...@@ -915,7 +905,6 @@ qemuBlockStorageSourceGetSheepdogProps(virStorageSourcePtr src)
/* libvirt does not support the 'snap-id' and 'tag' properties */ /* libvirt does not support the 'snap-id' and 'tag' properties */
if (virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "sheepdog",
"a:server", &serverprops, "a:server", &serverprops,
"s:vdi", src->path, "s:vdi", src->path,
NULL) < 0) NULL) < 0)
...@@ -946,7 +935,6 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src) ...@@ -946,7 +935,6 @@ qemuBlockStorageSourceGetSshProps(virStorageSourcePtr src)
username = src->auth->username; username = src->auth->username;
if (virJSONValueObjectCreate(&ret, if (virJSONValueObjectCreate(&ret,
"s:driver", "ssh",
"s:path", src->path, "s:path", src->path,
"a:server", &serverprops, "a:server", &serverprops,
"S:user", username, "S:user", username,
...@@ -961,18 +949,10 @@ static virJSONValuePtr ...@@ -961,18 +949,10 @@ static virJSONValuePtr
qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src, qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src,
bool onlytarget) bool onlytarget)
{ {
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 (virStorageSourceIsBlockLocal(src)) {
if (src->hostcdrom)
driver = "host_cdrom";
else
driver = "host_device";
}
if (!onlytarget) { if (!onlytarget) {
if (src->pr) if (src->pr)
prManagerAlias = src->pr->mgralias; prManagerAlias = src->pr->mgralias;
...@@ -982,7 +962,6 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src, ...@@ -982,7 +962,6 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src,
} }
ignore_value(virJSONValueObjectCreate(&ret, ignore_value(virJSONValueObjectCreate(&ret,
"s:driver", driver,
"s:filename", src->path, "s:filename", src->path,
"S:aio", iomode, "S:aio", iomode,
"S:pr-manager", prManagerAlias, "S:pr-manager", prManagerAlias,
...@@ -1059,10 +1038,20 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1059,10 +1038,20 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
{ {
int actualType = virStorageSourceGetActualType(src); int actualType = virStorageSourceGetActualType(src);
VIR_AUTOPTR(virJSONValue) fileprops = NULL; VIR_AUTOPTR(virJSONValue) fileprops = NULL;
const char *driver = NULL;
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 (virStorageSourceIsBlockLocal(src)) {
if (src->hostcdrom)
driver = "host_cdrom";
else
driver = "host_device";
} else {
driver = "file";
}
if (!(fileprops = qemuBlockStorageSourceGetFileProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetFileProps(src, onlytarget)))
return NULL; return NULL;
break; break;
...@@ -1082,11 +1071,13 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1082,11 +1071,13 @@ 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:
driver = "gluster";
if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, legacy, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetGlusterProps(src, legacy, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_VXHS: case VIR_STORAGE_NET_PROTOCOL_VXHS:
driver = "vxhs";
if (!(fileprops = qemuBlockStorageSourceGetVxHSProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetVxHSProps(src, onlytarget)))
return NULL; return NULL;
break; break;
...@@ -1096,31 +1087,37 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1096,31 +1087,37 @@ 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:
driver = virStorageNetProtocolTypeToString(src->protocol);
if (!(fileprops = qemuBlockStorageSourceGetCURLProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetCURLProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_ISCSI: case VIR_STORAGE_NET_PROTOCOL_ISCSI:
driver = "iscsi";
if (!(fileprops = qemuBlockStorageSourceGetISCSIProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetISCSIProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_NBD:
driver = "nbd";
if (!(fileprops = qemuBlockStorageSourceGetNBDProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetNBDProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_RBD: case VIR_STORAGE_NET_PROTOCOL_RBD:
driver = "rbd";
if (!(fileprops = qemuBlockStorageSourceGetRBDProps(src, onlytarget))) if (!(fileprops = qemuBlockStorageSourceGetRBDProps(src, onlytarget)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
driver = "sheepdog";
if (!(fileprops = qemuBlockStorageSourceGetSheepdogProps(src))) if (!(fileprops = qemuBlockStorageSourceGetSheepdogProps(src)))
return NULL; return NULL;
break; break;
case VIR_STORAGE_NET_PROTOCOL_SSH: case VIR_STORAGE_NET_PROTOCOL_SSH:
driver = "ssh";
if (!(fileprops = qemuBlockStorageSourceGetSshProps(src))) if (!(fileprops = qemuBlockStorageSourceGetSshProps(src)))
return NULL; return NULL;
break; break;
...@@ -1132,6 +1129,9 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src, ...@@ -1132,6 +1129,9 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
break; break;
} }
if (driver && virJSONValueObjectPrependString(fileprops, "driver", driver) < 0)
return NULL;
if (!onlytarget) { 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册