mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemu: monitor: Remove legacy 'device_add' infrastrcture
Remove the old-style 'device_add' helpers which parse the commandline arguments to JSON since we now coverted all usage to use JSON directly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3b4cc1d5a6
commit
cb1721767b
@ -2858,40 +2858,6 @@ qemuMonitorDelDevice(qemuMonitor *mon,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorAddDeviceWithFd(qemuMonitor *mon,
|
||||
const char *devicestr,
|
||||
int fd,
|
||||
const char *fdname)
|
||||
{
|
||||
int ret;
|
||||
|
||||
VIR_DEBUG("device=%s fd=%d fdname=%s", devicestr, fd, NULLSTR(fdname));
|
||||
|
||||
QEMU_CHECK_MONITOR(mon);
|
||||
|
||||
if (fd >= 0 && qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
|
||||
return -1;
|
||||
|
||||
ret = qemuMonitorJSONAddDevice(mon, devicestr);
|
||||
|
||||
if (ret < 0 && fd >= 0) {
|
||||
if (qemuMonitorCloseFileHandle(mon, fdname) < 0)
|
||||
VIR_WARN("failed to close device handle '%s'", fdname);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorAddDevice(qemuMonitor *mon,
|
||||
const char *devicestr)
|
||||
{
|
||||
return qemuMonitorAddDeviceWithFd(mon, devicestr, -1, NULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuMonitorAddDeviceProps:
|
||||
* @mon: monitor object
|
||||
|
@ -1030,13 +1030,6 @@ int qemuMonitorAttachPCIDiskController(qemuMonitor *mon,
|
||||
|
||||
int qemuMonitorAddDeviceProps(qemuMonitor *mon,
|
||||
virJSONValue **props);
|
||||
int qemuMonitorAddDevice(qemuMonitor *mon,
|
||||
const char *devicestr);
|
||||
|
||||
int qemuMonitorAddDeviceWithFd(qemuMonitor *mon,
|
||||
const char *devicestr,
|
||||
int fd,
|
||||
const char *fdname);
|
||||
|
||||
int qemuMonitorDelDevice(qemuMonitor *mon,
|
||||
const char *devalias);
|
||||
|
@ -579,144 +579,6 @@ qemuMonitorJSONMakeCommand(const char *cmdname,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
qemuMonitorJSONParseKeywordsFree(int nkeywords,
|
||||
char **keywords,
|
||||
char **values)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < nkeywords; i++) {
|
||||
g_free(keywords[i]);
|
||||
g_free(values[i]);
|
||||
}
|
||||
g_free(keywords);
|
||||
g_free(values);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Takes a string containing a set of key=value,key=value,key...
|
||||
* parameters and splits them up, returning two arrays with
|
||||
* the individual keys and values.
|
||||
* The "=value" part is optional and if a key with no value is found,
|
||||
* NULL will be placed into corresponding place in retvalues.
|
||||
*/
|
||||
static int
|
||||
qemuMonitorJSONParseKeywords(const char *str,
|
||||
char ***retkeywords,
|
||||
char ***retvalues,
|
||||
int *retnkeywords)
|
||||
{
|
||||
int keywordCount = 0;
|
||||
int keywordAlloc = 0;
|
||||
char **keywords = NULL;
|
||||
char **values = NULL;
|
||||
const char *start = str;
|
||||
const char *end;
|
||||
|
||||
*retkeywords = NULL;
|
||||
*retvalues = NULL;
|
||||
*retnkeywords = 0;
|
||||
end = start + strlen(str);
|
||||
|
||||
while (start) {
|
||||
const char *separator;
|
||||
const char *endmark;
|
||||
char *keyword;
|
||||
char *value = NULL;
|
||||
|
||||
endmark = start;
|
||||
do {
|
||||
/* QEMU accepts ',,' as an escape for a literal comma;
|
||||
* skip past those here while searching for the end of the
|
||||
* value, then strip them down below */
|
||||
endmark = strchr(endmark, ',');
|
||||
} while (endmark && endmark[1] == ',' && (endmark += 2));
|
||||
if (!endmark)
|
||||
endmark = end;
|
||||
if (!(separator = strchr(start, '=')))
|
||||
separator = end;
|
||||
|
||||
if (separator >= endmark)
|
||||
separator = endmark;
|
||||
|
||||
keyword = g_strndup(start, separator - start);
|
||||
|
||||
if (separator < endmark) {
|
||||
separator++;
|
||||
value = g_strndup(separator, endmark - separator);
|
||||
if (strchr(value, ',')) {
|
||||
char *p = strchr(value, ',') + 1;
|
||||
char *q = p + 1;
|
||||
while (*q) {
|
||||
if (*q == ',')
|
||||
q++;
|
||||
*p++ = *q++;
|
||||
}
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (keywordAlloc == keywordCount) {
|
||||
VIR_REALLOC_N(keywords, keywordAlloc + 10);
|
||||
VIR_REALLOC_N(values, keywordAlloc + 10);
|
||||
keywordAlloc += 10;
|
||||
}
|
||||
|
||||
keywords[keywordCount] = keyword;
|
||||
values[keywordCount] = value;
|
||||
keywordCount++;
|
||||
|
||||
start = endmark < end ? endmark + 1 : NULL;
|
||||
}
|
||||
|
||||
*retkeywords = keywords;
|
||||
*retvalues = values;
|
||||
*retnkeywords = keywordCount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static virJSONValue *
|
||||
qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
|
||||
{
|
||||
virJSONValue *ret = virJSONValueNewObject();
|
||||
char **keywords = NULL;
|
||||
char **values = NULL;
|
||||
int nkeywords = 0;
|
||||
size_t i;
|
||||
|
||||
if (qemuMonitorJSONParseKeywords(str, &keywords, &values, &nkeywords) < 0)
|
||||
goto error;
|
||||
|
||||
for (i = 0; i < nkeywords; i++) {
|
||||
if (values[i] == NULL) {
|
||||
if (i != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("unexpected empty keyword in %s"), str);
|
||||
goto error;
|
||||
} else {
|
||||
/* This 3rd arg isn't a typo - the way the parser works is
|
||||
* that the value ended up in the keyword field */
|
||||
if (virJSONValueObjectAppendString(ret, firstkeyword, keywords[i]) < 0)
|
||||
goto error;
|
||||
}
|
||||
} else {
|
||||
if (virJSONValueObjectAppendString(ret, keywords[i], values[i]) < 0)
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
qemuMonitorJSONParseKeywordsFree(nkeywords, keywords, values);
|
||||
return ret;
|
||||
|
||||
error:
|
||||
qemuMonitorJSONParseKeywordsFree(nkeywords, keywords, values);
|
||||
virJSONValueFree(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *data)
|
||||
{
|
||||
bool guest = false;
|
||||
@ -4576,19 +4438,6 @@ qemuMonitorJSONAddDeviceProps(qemuMonitor *mon,
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorJSONAddDevice(qemuMonitor *mon,
|
||||
const char *devicestr)
|
||||
{
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
|
||||
if (!(props = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver")))
|
||||
return -1;
|
||||
|
||||
return qemuMonitorJSONAddDeviceProps(mon, &props);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
qemuMonitorJSONAddObject(qemuMonitor *mon,
|
||||
virJSONValue **props)
|
||||
|
@ -237,8 +237,6 @@ int qemuMonitorJSONAttachPCIDiskController(qemuMonitor *mon,
|
||||
|
||||
int qemuMonitorJSONAddDeviceProps(qemuMonitor *mon,
|
||||
virJSONValue **props);
|
||||
int qemuMonitorJSONAddDevice(qemuMonitor *mon,
|
||||
const char *devicestr);
|
||||
|
||||
int qemuMonitorJSONDelDevice(qemuMonitor *mon,
|
||||
const char *devalias);
|
||||
|
@ -1184,7 +1184,6 @@ GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
|
||||
"localhost", 12345, 12346, "certsubjectval")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONAddDevice, "some_dummy_devicestr")
|
||||
GEN_TEST_FUNC(qemuMonitorJSONDriveMirror, "vdb", "/foo/bar", "formatstr", 1024, 1234, 31234, true, true)
|
||||
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMirror, "jobname", true, "vdb", "targetnode", 1024, 1234, 31234, true)
|
||||
GEN_TEST_FUNC(qemuMonitorJSONBlockStream, "vdb", "jobname", true, "/foo/bar1", "backingnode", "backingfilename", 1024)
|
||||
@ -3024,7 +3023,6 @@ mymain(void)
|
||||
DO_TEST_GEN(qemuMonitorJSONGraphicsRelocate);
|
||||
DO_TEST_GEN(qemuMonitorJSONRemoveNetdev);
|
||||
DO_TEST_GEN(qemuMonitorJSONDelDevice);
|
||||
DO_TEST_GEN(qemuMonitorJSONAddDevice);
|
||||
DO_TEST_GEN(qemuMonitorJSONDriveMirror);
|
||||
DO_TEST_GEN(qemuMonitorJSONBlockdevMirror);
|
||||
DO_TEST_GEN(qemuMonitorJSONBlockStream);
|
||||
|
Loading…
x
Reference in New Issue
Block a user