[libvirt] [PATCH 4/9] qemuBuildVhostuserCommandLine: Reuse qemuBuildChrChardevStr
John Ferlan
jferlan at redhat.com
Thu Sep 22 22:52:07 UTC 2016
On 08/16/2016 11:41 AM, Michal Privoznik wrote:
> There's no need to reinvent the wheel here. We already have a
> function to format virDomainChrSourceDefPtr. It's called
> qemuBuildChrChardevStr(). Use that instead of some dummy
> virBufferAsprintf().
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
> src/qemu/qemu_command.c | 16 +++++++++-------
> 1 file changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index c419ecf..59fcb4c 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -7848,7 +7848,7 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
> virQEMUCapsPtr qemuCaps,
> unsigned int bootindex)
> {
> - virBuffer chardev_buf = VIR_BUFFER_INITIALIZER;
> + char *chardev = NULL;
> virBuffer netdev_buf = VIR_BUFFER_INITIALIZER;
> unsigned int queues = net->driver.virtio.queues;
> char *nic = NULL;
> @@ -7861,9 +7861,10 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
>
> switch ((virDomainChrType) net->data.vhostuser->type) {
> case VIR_DOMAIN_CHR_TYPE_UNIX:
> - virBufferAsprintf(&chardev_buf, "socket,id=char%s,path=%s%s",
> - net->info.alias, net->data.vhostuser->data.nix.path,
> - net->data.vhostuser->data.nix.listen ? ",server" : "");
> + if (!(chardev = qemuBuildChrChardevStr(NULL, NULL, NULL, def,
logManager == NULL?
cmd == NULL?
cfg == NULL?
if (dev->logfile) code will surely have problems (as will the TLS code)
While true your narrow usage could avoid the TLS code that's going to
dereference cfg without doing the obligatory "cfg &&", I'm still not
clear how it would avoid the dev->logfile code.
Shouldn't this support that logManager anyway? If not, then perhaps it
needs to be more explicit. IOW: Extra checks.
John
> + net->data.vhostuser,
> + net->info.alias, qemuCaps, false)))
> + goto error;
> break;
>
> case VIR_DOMAIN_CHR_TYPE_NULL:
> @@ -7881,7 +7882,7 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
> case VIR_DOMAIN_CHR_TYPE_LAST:
> virReportError(VIR_ERR_INTERNAL_ERROR,
> _("vhost-user type '%s' not supported"),
> - virDomainChrTypeToString(net->data.vhostuser->type));
> + virDomainChrTypeToString(net->data.vhostuser->type));
> goto error;
> }
>
> @@ -7899,7 +7900,8 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
> }
>
> virCommandAddArg(cmd, "-chardev");
> - virCommandAddArgBuffer(cmd, &chardev_buf);
> + virCommandAddArg(cmd, chardev);
> + VIR_FREE(chardev);
>
> virCommandAddArg(cmd, "-netdev");
> virCommandAddArgBuffer(cmd, &netdev_buf);
> @@ -7917,7 +7919,7 @@ qemuBuildVhostuserCommandLine(virCommandPtr cmd,
> return 0;
>
> error:
> - virBufferFreeAndReset(&chardev_buf);
> + VIR_FREE(chardev);
> virBufferFreeAndReset(&netdev_buf);
> VIR_FREE(nic);
>
>
More information about the libvir-list
mailing list