xenconfig: Move guts of xenFormatSxprSound into xenFormatSound

Use new coding style to merge the only use of xenFormatSxprSound into
the caller.

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:04:01 +02:00
parent 7480ae5794
commit 145b625915
4 changed files with 22 additions and 50 deletions

View File

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

View File

@ -2006,25 +2006,34 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
static int static int
xenFormatSound(virConfPtr conf, virDomainDefPtr def) xenFormatSound(virConfPtr conf, virDomainDefPtr def)
{ {
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (def->sounds) { const char * model;
virBuffer buf = VIR_BUFFER_INITIALIZER; VIR_AUTOFREE(char *) str = NULL;
char *str = NULL; size_t i;
int ret = xenFormatSxprSound(def, &buf);
str = virBufferContentAndReset(&buf); if (def->os.type != VIR_DOMAIN_OSTYPE_HVM ||
if (ret == 0) !def->sounds)
ret = xenConfigSetString(conf, "soundhw", str); return 0;
VIR_FREE(str); for (i = 0; i < def->nsounds; i++) {
if (ret < 0) if (!(model = virDomainSoundModelTypeToString(def->sounds[i]->model))) {
return -1; virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sound model %d"),
def->sounds[i]->model);
return -1;
} }
if (i)
virBufferAddChar(&buf, ',');
virBufferEscapeSexpr(&buf, "%s", model);
} }
return 0; if (virBufferCheckError(&buf) < 0)
} return -1;
str = virBufferContentAndReset(&buf);
return xenConfigSetString(conf, "soundhw", str);
}
static int static int

View File

@ -1569,38 +1569,3 @@ xenFormatSxprChr(virDomainChrDefPtr def,
return 0; return 0;
} }
/**
* xenFormatSxprSound:
* @def: the domain config
* @buf: a buffer for the result S-expression
*
* Convert all sound device parts of the domain config into S-expression in buf.
*
* Returns 0 if successful or -1 if failed.
*/
int
xenFormatSxprSound(virDomainDefPtr def,
virBufferPtr buf)
{
const char *str;
size_t i;
for (i = 0; i < def->nsounds; i++) {
if (!(str = virDomainSoundModelTypeToString(def->sounds[i]->model))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sound model %d"),
def->sounds[i]->model);
return -1;
}
if (i)
virBufferAddChar(buf, ',');
virBufferEscapeSexpr(buf, "%s", str);
}
if (virBufferCheckError(buf) < 0)
return -1;
return 0;
}

View File

@ -51,4 +51,3 @@ virDomainChrDefPtr xenParseSxprChar(const char *value, const char *tty);
int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec); int xenParseSxprVifRate(const char *rate, unsigned long long *kbytes_per_sec);
int xenFormatSxprChr(virDomainChrDefPtr def, virBufferPtr buf); int xenFormatSxprChr(virDomainChrDefPtr def, virBufferPtr buf);
int xenFormatSxprSound(virDomainDefPtr def, virBufferPtr buf);