[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v2 03/12] qemu: Make qemuMonitorAddHostNetwork to pass multiple FDs



On 05/13/2013 01:23 PM, Michal Privoznik wrote:
> Currently, only one tapfd and one vhostfd could be passed.
> However, multiqueue network requires several FDs to be passed to
> qemu so we must adapt out monitor handling functions to cope with
> that.
> ---
>  src/qemu/qemu_hotplug.c |  7 +++++--
>  src/qemu/qemu_monitor.c | 39 +++++++++++++++++++++++----------------
>  src/qemu/qemu_monitor.h |  4 ++--
>  3 files changed, 30 insertions(+), 20 deletions(-)
>
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index d037c9d..b04f3bb 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -813,8 +813,11 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
>      qemuDomainObjEnterMonitor(driver, vm);
>      if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV) &&
>          virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
> -        if (qemuMonitorAddNetdev(priv->mon, netstr, tapfd, tapfd_name,
> -                                 vhostfd, vhostfd_name) < 0) {
> +        if (qemuMonitorAddNetdev(priv->mon, netstr,
> +                                 &tapfd, &tapfd_name,
> +                                 tapfd_name ? 1 : 0,
> +                                 &vhostfd, &vhostfd_name,
> +                                 vhostfd_name ? 1 : 0) < 0) {


That looks a bit obtuse, but of course it's all going to be corrected in
another patch or two...


>              qemuDomainObjExitMonitor(driver, vm);
>              virDomainAuditNet(vm, NULL, net, "attach", false);
>              goto cleanup;
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 4deb2d6..c3f35b5 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -2527,14 +2527,16 @@ int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
>  
>  int qemuMonitorAddNetdev(qemuMonitorPtr mon,
>                           const char *netdevstr,
> -                         int tapfd, const char *tapfd_name,
> -                         int vhostfd, const char *vhostfd_name)
> +                         int *tapfd, char **tapfdName, int tapfdSize,
> +                         int *vhostfd, char **vhostfdName, int vhostfdSize)
>  {
>      int ret = -1;
> -    VIR_DEBUG("mon=%p netdevstr=%s tapfd=%d tapfd_name=%s "
> -              "vhostfd=%d vhostfd_name=%s",
> -              mon, netdevstr, tapfd, NULLSTR(tapfd_name),
> -              vhostfd, NULLSTR(vhostfd_name));
> +    int i = 0, j = 0;
> +
> +    VIR_DEBUG("mon=%p netdevstr=%s tapfd=%p tapfdName=%p tapfdSize=%d"
> +              "vhostfd=%p vhostfdName=%p vhostfdSize=%d",
> +              mon, netdevstr, tapfd, tapfdName, tapfdSize,
> +              vhostfd, vhostfdName, tapfdSize);

The unfortunate thing here is that the debug log no longer displays the
actual fd, even in the common case of there being a single queue. On the
other hand, I've *never* gotten any use out of any of the "top of the
function" debug log messages anyway :-)


>  
>      if (!mon) {
>          virReportError(VIR_ERR_INVALID_ARG, "%s",
> @@ -2542,12 +2544,13 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
>          return -1;
>      }
>  
> -    if (tapfd >= 0 && qemuMonitorSendFileHandle(mon, tapfd_name, tapfd) < 0)
> -        return -1;
> -    if (vhostfd >= 0 &&
> -        qemuMonitorSendFileHandle(mon, vhostfd_name, vhostfd) < 0) {
> -        vhostfd = -1;
> -        goto cleanup;
> +    for (i = 0; i < tapfdSize; i++) {
> +        if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
> +            goto cleanup;
> +    }
> +    for (j = 0; j < vhostfdSize; j++) {
> +        if (qemuMonitorSendFileHandle(mon, vhostfdName[j], vhostfd[j]) < 0)
> +            goto cleanup;
>      }
>  
>      if (mon->json)
> @@ -2557,10 +2560,14 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
>  
>  cleanup:
>      if (ret < 0) {
> -        if (tapfd >= 0 && qemuMonitorCloseFileHandle(mon, tapfd_name) < 0)
> -            VIR_WARN("failed to close device handle '%s'", tapfd_name);
> -        if (vhostfd >= 0 && qemuMonitorCloseFileHandle(mon, vhostfd_name) < 0)
> -            VIR_WARN("failed to close device handle '%s'", vhostfd_name);
> +        while (i--) {
> +            if (qemuMonitorCloseFileHandle(mon, tapfdName[i]) < 0)
> +                VIR_WARN("failed to close device handle '%s'", tapfdName[i]);
> +        }
> +        while (j--) {
> +            if (qemuMonitorCloseFileHandle(mon, vhostfdName[j]) < 0)
> +                VIR_WARN("failed to close device handle '%s'", vhostfdName[j]);
> +        }
>      }
>  
>      return ret;
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index f39f009..580e42b 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -506,8 +506,8 @@ int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
>  
>  int qemuMonitorAddNetdev(qemuMonitorPtr mon,
>                           const char *netdevstr,
> -                         int tapfd, const char *tapfd_name,
> -                         int vhostfd, const char *vhostfd_name);
> +                         int *tapfd, char **tapfdName, int tapfdSize,
> +                         int *vhostfd, char **vhostfdName, int vhostfdSize);
>  
>  int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
>                              const char *alias);


ACK.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]