[libvirt] [PATCH 2/4] vhost-user support: qemu command-line

Michal Privoznik mprivozn at redhat.com
Thu Jul 10 16:01:47 UTC 2014


On 02.07.2014 15:20, Michele Paolino wrote:
> Build the qemu-command line for vhost-user.
>
> Signed-off-by: Michele Paolino <m.paolino at virtualopensystems.com>
> ---
>   src/qemu/qemu_command.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 58 insertions(+)

This is the patch where .args and qemuxml2argvtest.c modifications would 
have been done if you go with my suggestion in 1/4.

>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index ab8cec5..c1cf001 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -6930,6 +6930,61 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr cfg,
>   }
>
>   static int
> +qemuBuildVhostuserCommandLine(virCommandPtr cmd,
> +                              virDomainDefPtr def,
> +                              virDomainNetDefPtr net,
> +                              virQEMUCapsPtr qemuCaps)
> +{
> +    virBuffer chardev_buf = VIR_BUFFER_INITIALIZER;
> +    virBuffer netdev_buf = VIR_BUFFER_INITIALIZER;
> +
> +    char* nic = NULL;
> +
> +    if (!qemuDomainSupportsNetdev(def, qemuCaps, net)) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       "%s", _("Netdev support unavailable"));
> +        goto error;
> +    }
> +
> +    if ((net->data.vhostuser)->type == 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" : "");
> +    }
> +
> +    virBufferAsprintf(&netdev_buf, "type=vhost-user,id=host%s,chardev=char%s",
> +                      net->info.alias, net->info.alias);
> +
> +    if (virBufferError(&chardev_buf) || virBufferError(&netdev_buf)) {
> +        virReportOOMError();
> +        goto error;
> +    }
> +
> +    virCommandAddArgList(cmd, "-chardev", virBufferContentAndReset(&chardev_buf),
> +                         NULL);
> +    virCommandAddArgList(cmd, "-netdev", virBufferContentAndReset(&netdev_buf),
> +                         NULL);

For some reason we tend to store the return value of 
virBufferContentAndReset() into a local variable which is then passed to 
virCommandAddArgList(). Maybe for better debugging options.

> +
> +    if (!(nic = qemuBuildNicDevStr(def, net, -1, 0, 0, qemuCaps))) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       "%s", _("Error generating NIC -device string"));
> +        goto error;
> +    }
> +
> +    virCommandAddArgList(cmd, "-device", nic, NULL);
> +    VIR_FREE(nic);
> +
> +    return 0;
> +
> + error:
> +    virBufferFreeAndReset(&chardev_buf);
> +    virBufferFreeAndReset(&netdev_buf);
> +    VIR_FREE(nic);
> +
> +    return -1;
> +}
> +
> +static int
>   qemuBuildInterfaceCommandLine(virCommandPtr cmd,
>                                 virQEMUDriverPtr driver,
>                                 virConnectPtr conn,
> @@ -6952,6 +7007,9 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
>       int actualType = virDomainNetGetActualType(net);
>       size_t i;
>
> +    if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER)
> +        return qemuBuildVhostuserCommandLine(cmd, def, net, qemuCaps);
> +
>       if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
>           /* NET_TYPE_HOSTDEV devices are really hostdev devices, so
>            * their commandlines are constructed with other hostdevs.
>

Michal




More information about the libvir-list mailing list