提交 640a4f13 编写于 作者: P Peter Krempa

xen: Move xenFormatSxprChr to xen_common

That's the only file using the helper function.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 145b6259
......@@ -3,7 +3,6 @@
#
# xenconfig/xen_sxpr.h
xenFormatSxprChr;
xenGetDomIdFromSxpr;
xenGetDomIdFromSxprString;
xenParseSxpr;
......
......@@ -1260,6 +1260,85 @@ xenParseConfigCommon(virConfPtr conf,
}
/**
* xenFormatSxprChr:
* @def: the domain config
* @buf: a buffer for the result S-expression
*
* Convert the character device part of the domain config into a S-expression
* in buf.
*
* Returns 0 in case of success, -1 in case of error
*/
static int
xenFormatSxprChr(virDomainChrDefPtr def,
virBufferPtr buf)
{
const char *type = virDomainChrTypeToString(def->source->type);
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("unexpected chr device type"));
return -1;
}
switch (def->source->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
case VIR_DOMAIN_CHR_TYPE_STDIO:
case VIR_DOMAIN_CHR_TYPE_VC:
case VIR_DOMAIN_CHR_TYPE_PTY:
virBufferAdd(buf, type, -1);
break;
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
virBufferAsprintf(buf, "%s:", type);
virBufferEscapeSexpr(buf, "%s", def->source->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
virBufferEscapeSexpr(buf, "%s", def->source->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_TCP:
virBufferAsprintf(buf, "%s:%s:%s%s",
(def->source->data.tcp.protocol
== VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
"tcp" : "telnet"),
NULLSTR_EMPTY(def->source->data.tcp.host),
NULLSTR_EMPTY(def->source->data.tcp.service),
(def->source->data.tcp.listen ?
",server,nowait" : ""));
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
virBufferAsprintf(buf, "%s:%s:%s@%s:%s", type,
NULLSTR_EMPTY(def->source->data.udp.connectHost),
NULLSTR_EMPTY(def->source->data.udp.connectService),
NULLSTR_EMPTY(def->source->data.udp.bindHost),
NULLSTR_EMPTY(def->source->data.udp.bindService));
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
virBufferAsprintf(buf, "%s:", type);
virBufferEscapeSexpr(buf, "%s", def->source->data.nix.path);
if (def->source->data.nix.listen)
virBufferAddLit(buf, ",server,nowait");
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported chr device type '%s'"), type);
return -1;
}
if (virBufferCheckError(buf) < 0)
return -1;
return 0;
}
static int
xenFormatSerial(virConfValuePtr list, virDomainChrDefPtr serial)
{
......
......@@ -1491,81 +1491,3 @@ xenParseSxprString(const char *sexpr,
return def;
}
/**
* xenFormatSxprChr:
* @def: the domain config
* @buf: a buffer for the result S-expression
*
* Convert the character device part of the domain config into a S-expression
* in buf.
*
* Returns 0 in case of success, -1 in case of error
*/
int
xenFormatSxprChr(virDomainChrDefPtr def,
virBufferPtr buf)
{
const char *type = virDomainChrTypeToString(def->source->type);
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("unexpected chr device type"));
return -1;
}
switch (def->source->type) {
case VIR_DOMAIN_CHR_TYPE_NULL:
case VIR_DOMAIN_CHR_TYPE_STDIO:
case VIR_DOMAIN_CHR_TYPE_VC:
case VIR_DOMAIN_CHR_TYPE_PTY:
virBufferAdd(buf, type, -1);
break;
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
virBufferAsprintf(buf, "%s:", type);
virBufferEscapeSexpr(buf, "%s", def->source->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_DEV:
virBufferEscapeSexpr(buf, "%s", def->source->data.file.path);
break;
case VIR_DOMAIN_CHR_TYPE_TCP:
virBufferAsprintf(buf, "%s:%s:%s%s",
(def->source->data.tcp.protocol
== VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW ?
"tcp" : "telnet"),
NULLSTR_EMPTY(def->source->data.tcp.host),
NULLSTR_EMPTY(def->source->data.tcp.service),
(def->source->data.tcp.listen ?
",server,nowait" : ""));
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
virBufferAsprintf(buf, "%s:%s:%s@%s:%s", type,
NULLSTR_EMPTY(def->source->data.udp.connectHost),
NULLSTR_EMPTY(def->source->data.udp.connectService),
NULLSTR_EMPTY(def->source->data.udp.bindHost),
NULLSTR_EMPTY(def->source->data.udp.bindService));
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
virBufferAsprintf(buf, "%s:", type);
virBufferEscapeSexpr(buf, "%s", def->source->data.nix.path);
if (def->source->data.nix.listen)
virBufferAddLit(buf, ",server,nowait");
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported chr device type '%s'"), type);
return -1;
}
if (virBufferCheckError(buf) < 0)
return -1;
return 0;
}
......@@ -49,5 +49,3 @@ int xenParseSxprSound(virDomainDefPtr def, const char *str);
virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty);
int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec);
int xenFormatSxprChr(virDomainChrDefPtr def, virBufferPtr buf);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册