qemu: monitor: Rename and improve qemuMonitorGetPtyPaths

To unify future additions that require information from "query-chardev"
rename qemuMonitorGetPtyPaths and friends to qemuMonitorGetChardevInfo
and move the allocation of the returned hash into the top level
function.
This commit is contained in:
Peter Krempa 2014-11-13 16:17:21 +01:00
parent c5942a9faa
commit e9a4506963
8 changed files with 66 additions and 52 deletions

View File

@ -2968,24 +2968,39 @@ qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
}
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths)
int
qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr *retinfo)
{
int ret;
VIR_DEBUG("mon=%p",
mon);
virHashTablePtr info = NULL;
VIR_DEBUG("mon=%p retinfo=%p", mon, retinfo);
if (!mon) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("monitor must not be NULL"));
return -1;
goto error;
}
if (!(info = virHashCreate(10, virHashValueFree)))
goto error;
if (mon->json)
ret = qemuMonitorJSONGetPtyPaths(mon, paths);
ret = qemuMonitorJSONGetChardevInfo(mon, info);
else
ret = qemuMonitorTextGetPtyPaths(mon, paths);
return ret;
ret = qemuMonitorTextGetChardevInfo(mon, info);
if (ret < 0)
goto error;
*retinfo = info;
return 0;
error:
virHashFree(info);
*retinfo = NULL;
return -1;
}

View File

@ -639,8 +639,8 @@ int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
int qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
virNetDevRxFilterPtr *filter);
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths);
int qemuMonitorGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr *retinfo);
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
const char *bus,

View File

@ -3396,8 +3396,9 @@ qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, const char *alias,
* ]}
*
*/
static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
virHashTablePtr paths)
static int
qemuMonitorJSONExtractChardevInfo(virJSONValuePtr reply,
virHashTablePtr info)
{
virJSONValuePtr data;
int ret = -1;
@ -3442,7 +3443,7 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
if (VIR_STRDUP(path, type + strlen("pty:")) < 0)
goto cleanup;
if (virHashAddEntry(paths, id, path) < 0) {
if (virHashAddEntry(info, id, path) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("failed to save chardev path '%s'"), path);
VIR_FREE(path);
@ -3457,8 +3458,10 @@ static int qemuMonitorJSONExtractPtyPaths(virJSONValuePtr reply,
return ret;
}
int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths)
int
qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr info)
{
int ret;
@ -3475,7 +3478,7 @@ int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
ret = qemuMonitorJSONCheckError(cmd, reply);
if (ret == 0)
ret = qemuMonitorJSONExtractPtyPaths(reply, paths);
ret = qemuMonitorJSONExtractChardevInfo(reply, info);
virJSONValueFree(cmd);
virJSONValueFree(reply);

View File

@ -214,8 +214,8 @@ int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
int qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, const char *alias,
virNetDevRxFilterPtr *filter);
int qemuMonitorJSONGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths);
int qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr info);
int qemuMonitorJSONAttachPCIDiskController(qemuMonitorPtr mon,
const char *bus,

View File

@ -2170,8 +2170,8 @@ int qemuMonitorTextRemoveNetdev(qemuMonitorPtr mon,
* '/dev/pty/7'. The hash will contain only a single value.
*/
int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths)
int qemuMonitorTextGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr info)
{
char *reply = NULL;
int ret = -1;
@ -2222,7 +2222,7 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
if (VIR_STRDUP(path, needle + strlen(NEEDLE)) < 0)
goto cleanup;
if (virHashAddEntry(paths, id, path) < 0) {
if (virHashAddEntry(info, id, path) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED,
_("failed to save chardev path '%s'"),
path);

View File

@ -179,8 +179,8 @@ int qemuMonitorTextAddNetdev(qemuMonitorPtr mon,
int qemuMonitorTextRemoveNetdev(qemuMonitorPtr mon,
const char *alias);
int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon,
virHashTablePtr paths);
int qemuMonitorTextGetChardevInfo(qemuMonitorPtr mon,
virHashTablePtr info);
int qemuMonitorTextAttachPCIDiskController(qemuMonitorPtr mon,
const char *bus,

View File

@ -1865,7 +1865,7 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
virDomainChrDefPtr *devices,
int count,
virHashTablePtr paths)
virHashTablePtr info)
{
size_t i;
@ -1886,7 +1886,7 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
return -1;
}
path = (const char *) virHashLookup(paths, id);
path = (const char *) virHashLookup(info, id);
if (path == NULL) {
if (chr->source.data.file.path == NULL) {
/* neither the log output nor 'info chardev' had a
@ -1915,23 +1915,23 @@ qemuProcessLookupPTYs(virDomainDefPtr def,
static int
qemuProcessFindCharDevicePTYsMonitor(virDomainObjPtr vm,
virQEMUCapsPtr qemuCaps,
virHashTablePtr paths)
virHashTablePtr info)
{
size_t i = 0;
if (qemuProcessLookupPTYs(vm->def, qemuCaps,
vm->def->serials, vm->def->nserials,
paths) < 0)
info) < 0)
return -1;
if (qemuProcessLookupPTYs(vm->def, qemuCaps,
vm->def->parallels, vm->def->nparallels,
paths) < 0)
info) < 0)
return -1;
if (qemuProcessLookupPTYs(vm->def, qemuCaps,
vm->def->channels, vm->def->nchannels,
paths) < 0)
info) < 0)
return -1;
/* For historical reasons, console[0] can be just an alias
* for serial[0]. That's why we need to update it as well. */
@ -1951,7 +1951,7 @@ qemuProcessFindCharDevicePTYsMonitor(virDomainObjPtr vm,
if (qemuProcessLookupPTYs(vm->def, qemuCaps,
vm->def->consoles + i, vm->def->nconsoles - i,
paths) < 0)
info) < 0)
return -1;
return 0;
@ -2035,7 +2035,7 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
size_t buf_size = 4096; /* Plenty of space to get startup greeting */
int logfd = -1;
int ret = -1;
virHashTablePtr paths = NULL;
virHashTablePtr info = NULL;
qemuDomainObjPrivatePtr priv;
if (pos != -1 &&
@ -2060,22 +2060,18 @@ qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
* reliable if it's available.
* Note that the monitor itself can be on a pty, so we still need to try the
* log output method. */
paths = virHashCreate(0, virHashValueFree);
if (paths == NULL)
goto cleanup;
priv = vm->privateData;
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
goto cleanup;
ret = qemuMonitorGetPtyPaths(priv->mon, paths);
ret = qemuMonitorGetChardevInfo(priv->mon, &info);
qemuDomainObjExitMonitor(driver, vm);
VIR_DEBUG("qemuMonitorGetPtyPaths returned %i", ret);
VIR_DEBUG("qemuMonitorGetChardevInfo returned %i", ret);
if (ret == 0)
ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, paths);
ret = qemuProcessFindCharDevicePTYsMonitor(vm, qemuCaps, info);
cleanup:
virHashFree(paths);
virHashFree(info);
if (pos != -1 && kill(vm->pid, 0) == -1 && errno == ESRCH) {
int len;

View File

@ -1765,24 +1765,24 @@ testHashEqualString(const void *value1, const void *value2)
}
static int
testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *data)
{
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1;
virHashTablePtr paths = NULL, expectedPaths = NULL;
virHashTablePtr info = NULL, expectedInfo = NULL;
if (!test)
return -1;
if (!(paths = virHashCreate(32, (virHashDataFree) free)) ||
!(expectedPaths = virHashCreate(32, NULL)))
if (!(info = virHashCreate(32, (virHashDataFree) free)) ||
!(expectedInfo = virHashCreate(32, NULL)))
goto cleanup;
if (virHashAddEntry(expectedPaths, "charserial1", (void *) "/dev/pts/21") < 0 ||
virHashAddEntry(expectedPaths, "charserial0", (void *) "/dev/pts/20") < 0) {
if (virHashAddEntry(expectedInfo, "charserial1", (void *) "/dev/pts/21") < 0 ||
virHashAddEntry(expectedInfo, "charserial0", (void *) "/dev/pts/20") < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"Unable to create expectedPaths hash table");
"Unable to create expectedInfo hash table");
goto cleanup;
}
@ -1806,11 +1806,11 @@ testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
"}") < 0)
goto cleanup;
if (qemuMonitorJSONGetPtyPaths(qemuMonitorTestGetMonitor(test),
paths) < 0)
if (qemuMonitorJSONGetChardevInfo(qemuMonitorTestGetMonitor(test),
info) < 0)
goto cleanup;
if (!virHashEqual(paths, expectedPaths, testHashEqualString)) {
if (!virHashEqual(info, expectedInfo, testHashEqualString)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
"Hashtable is different to the expected one");
goto cleanup;
@ -1818,8 +1818,8 @@ testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
ret = 0;
cleanup:
virHashFree(paths);
virHashFree(expectedPaths);
virHashFree(info);
virHashFree(expectedInfo);
qemuMonitorTestFree(test);
return ret;
}
@ -2387,7 +2387,7 @@ mymain(void)
DO_TEST(qemuMonitorJSONGetMigrationCacheSize);
DO_TEST(qemuMonitorJSONGetMigrationStatus);
DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus);
DO_TEST(qemuMonitorJSONGetPtyPaths);
DO_TEST(qemuMonitorJSONGetChardevInfo);
DO_TEST(qemuMonitorJSONSetBlockIoThrottle);
DO_TEST(qemuMonitorJSONGetTargetArch);
DO_TEST(qemuMonitorJSONGetMigrationCapability);