[Libvirt-cim] [PATCH] This patch adds support for IPv6 in KVMRedirectionSAP provider

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Oct 28 22:19:18 UTC 2009


> +static CMPIStatus get_vnc_sessions(const CMPIBroker *broker,
> +                                   const CMPIObjectPath *ref,
> +                                   virConnectPtr conn,
> +                                   struct vnc_ports ports,
> +                                   struct inst_list *list)
> +{
> +        CMPIStatus s = {CMPI_RC_OK, NULL};
> +        CMPIInstance *inst;
> +        const char *path[2] = {PROC_TCP4, PROC_TCP6};
> +        FILE *tcp_info;
> +        int i, j;
> +        int error = 0;
> 
> -                inst = get_console_sap(broker, ref, conn, ports.list[i], &s);
> -                if ((s.rc != CMPI_RC_OK) || (inst == NULL))
> -                        goto out;
> +        for (j = 0; j < 2; j++) {
> +                tcp_info = fopen(path[j], "r");
> +                if (tcp_info == NULL) {
> +                        cu_statusf(broker, &s,
> +                                   CMPI_RC_ERR_FAILED,
> +                                   "Failed to open %s: %m", tcp_info);
> +                        goto error;
> +                }
> 
> -                inst_list_add(list, inst);
> +                s = read_tcp_file(broker,
> +                                  ref,
> +                                  conn,
> +                                  ports,
> +                                  list,
> +                                  tcp_info);
> +
> +                if (s.rc != CMPI_RC_OK)
> +                        goto error;
> +
> +                /* Handle any guests that were missed.  These guest don't have active 
> +                   or enabled sessions. */
> +                for (i = 0; i < ports.max; i++) { 
> +                        if (ports.list[i]->remote_port != -1)
> +                                continue;
> +
> +                        inst = get_console_sap(broker, ref, conn, ports.list[i], &s);
> +                        if ((s.rc != CMPI_RC_OK) || (inst == NULL))
> +                                goto error;
> +
> +                        inst_list_add(list, inst);
> +                }

This for loop doesn't need to be part of the greater for loop. 
Otherwise, you will generate two instances for the same guest:

# wbemcli ein http://localhost:5988/root/virt:KVM_KVMRedirectionSAP -nl
localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="5903:0",SystemCreationClassName="KVM_ComputerSystem",SystemName="f10_test"
localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="-1:-1",SystemCreationClassName="KVM_ComputerSystem",SystemName="xtest2"
localhost:5988/root/virt:KVM_KVMRedirectionSAP.CreationClassName="KVM_KVMRedirectionSAP",Name="-1:-1",SystemCreationClassName="KVM_ComputerSystem",SystemName="xtest2"

This loop creates an instance for guests that are in define state.  For 
these guests, the remote port is -1 because the hypervisor doesn't start 
a VNC server for the guest until the guest is running.

> +
> + error:

Moving the above loop outside of the outer for loop will remove the need 
  for this error tag.  And should remove the need for the error variable.

> +                if (tcp_info != NULL)
> +                        fclose(tcp_info);
> +
> +                if ((j == 0) && (s.rc != CMPI_RC_OK)) {
> +                        error = 1;
> +                        s.rc = CMPI_RC_OK;
> +                }
>          }
> 
> - out:
> -        fclose(tcp_info);
> +        if ((s.rc != CMPI_RC_OK) && (error == 0))
> +                s.rc = CMPI_RC_OK; 
> +
>          return s;
>  }
> 
> 
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim


-- 
Kaitlin Rupert
IBM Linux Technology Center
kaitlin at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list