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

Re: [libvirt] PATCH: Make VirtualBox domain IDs start from 1 instead of 0



On Tuesday 21 April 2009 12:15:37 Daniel P. Berrange wrote:
> The VirtualBox driver currently returns domain IDs starting from 0. The
> domain ID 0 is reserved for a special scenario. It refers to a guest which
> is also the host OS. ie its the guest in which libvirt is running. This
> guest will only exist in virtualization technology where there is a
> separate hypervisor / host OS, eg Xen or MicroSoft Hyper-V.  Thus, it
> should be avoided for drivers like QEMU or VirtualBox.

oops, didn't knew this.

>
> Index: src/vbox/vbox_tmpl.c
> ===================================================================
> RCS file: /data/cvs/libvirt/src/vbox/vbox_tmpl.c,v
> retrieving revision 1.1
> diff -u -p -r1.1 vbox_tmpl.c
> --- src/vbox/vbox_tmpl.c	17 Apr 2009 16:09:07 -0000	1.1
> +++ src/vbox/vbox_tmpl.c	21 Apr 2009 10:11:48 -0000
> @@ -434,7 +434,7 @@ static int vboxListDomains(virConnectPtr
>                      if ((state == MachineState_Running) ||
>                          (state == MachineState_Paused) ) {
>                          ret++;
> -                        ids[j++] = i;
> +                        ids[j++] = i + 1;
>                      }
>                  }
>              }
> @@ -535,6 +535,15 @@ static virDomainPtr vboxDomainLookupByID
>      PRUint32 state;
>      int i;
>
> +    /* Internal vbox IDs start from 0, the public libvirt ID
> +     * starts from 1, so refuse id==0, and adjust the rest*/
> +    if (id == 0) {
> +        vboxError(conn, VIR_ERR_NO_DOMAIN,
> +		  _("no domain with matching id %d"), id);
> +        return NULL;
> +    }
> +    id = id - 1;
> +
>      if(data->vboxObj) {
>          rc = data->vboxObj->vtbl->GetMachines(data->vboxObj, &machineCnt,
> &machines); if (NS_FAILED(rc)) {
> @@ -568,7 +577,7 @@ static virDomainPtr vboxDomainLookupByID
>
>                          dom = virGetDomain(conn, machineName, iidl);
>                          if (dom)
> -                            dom->id = id;
> +                            dom->id = id + 1;
>
>                          /* Cleanup all the XPCOM allocated stuff here */
>                          g_pVBoxFuncs->pfnComUnallocMem(iid);
> @@ -645,7 +654,7 @@ static virDomainPtr vboxDomainLookupByUU
>                      if (dom)
>                          if ((state == MachineState_Running) ||
>                              (state == MachineState_Paused) )
> -                            dom->id = i;
> +                            dom->id = i + 1;
>                  }
>
>                  if (iid) {
> @@ -725,7 +734,7 @@ static virDomainPtr vboxDomainLookupByNa
>                      if (dom)
>                          if ((state == MachineState_Running) ||
>                              (state == MachineState_Paused) )
> -                            dom->id = i;
> +                            dom->id = i + 1;
>                  }
>
>                  if (machineName) {
> @@ -2311,7 +2320,7 @@ static int vboxDomainCreate(virDomainPtr
>                                  ret = -1;
>                              } else {
>                                  /* all ok set the domid */
> -                                dom->id = i;
> +                                dom->id = i + 1;
>                                  ret = 0;
>                              }
>                          }

ACK++

Regards,
Pritesh


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