xen: Move xenFormatSxprChr to xen_common

That's the only file using the helper function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-07-03 09:15:37 +02:00
parent 145b625915
commit 640a4f132c
4 changed files with 79 additions and 81 deletions

View File

@ -3,7 +3,6 @@
#
# xenconfig/xen_sxpr.h
xenFormatSxprChr;
xenGetDomIdFromSxpr;
xenGetDomIdFromSxprString;
xenParseSxpr;

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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);