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

Re: [libvirt] [PATCH] vbox: Use virIndexToDiskName() in vboxGenerateMediumName()



On Fri, Dec 04, 2009 at 03:31:06PM +0100, Matthias Bolte wrote:
> ---
>  src/vbox/vbox_tmpl.c |   48 +++++++++---------------------------------------
>  1 files changed, 9 insertions(+), 39 deletions(-)
> 
> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
> index 10cc1ed..33f5334 100644
> --- a/src/vbox/vbox_tmpl.c
> +++ b/src/vbox/vbox_tmpl.c
> @@ -426,15 +426,14 @@ static void vboxUtf8toIID(virConnectPtr conn, char *uuidstr, vboxIID **iid) {
>   * @param       aMaxSlotPerPort Input array of max slot per device port
>   *
>   */
> -static char *vboxGenerateMediumName(virConnectPtr conn,
> -                                    PRUint32  storageBus,
> +static char *vboxGenerateMediumName(PRUint32  storageBus,
>                                      PRInt32   deviceInst,
>                                      PRInt32   devicePort,
>                                      PRInt32   deviceSlot,
>                                      PRUint32 *aMaxPortPerInst,
>                                      PRUint32 *aMaxSlotPerPort) {
> +    const char *prefix = NULL;
>      char *name  = NULL;
> -    int   len   = 0;
>      int   total = 0;
>      PRUint32 maxPortPerInst = 0;
>      PRUint32 maxSlotPerPort = 0;
> @@ -453,48 +452,20 @@ static char *vboxGenerateMediumName(virConnectPtr conn,
>              + (devicePort * maxSlotPerPort)
>              + deviceSlot;
>  
> -    if ((total >= 0) && (total < 26))
> -        len = 4;
> -    else if ((total >= 26) && (total < 26*26 + 26))
> -        len = 5;
> -    else if ((total >= 26*26 + 26) && (total < 26*26*26 + 26*26 + 26))
> -        len = 6;
> -    else
> -        return NULL;
> -
> -    if (VIR_ALLOC_N(name, len) < 0) {
> -        virReportOOMError(conn);
> -        return NULL;
> -    }
> -
> -    /* TODO: use virIndexToDiskName() here when available */
>      if (storageBus == StorageBus_IDE) {
> -        name[0] = 'h';
> -        name[1] = 'd';
> +        prefix = "hd";
>      } else if (   (storageBus == StorageBus_SATA)
>                 || (storageBus == StorageBus_SCSI)) {
> -        name[0] = 's';
> -        name[1] = 'd';
> +        prefix = "sd";
>      } else if (storageBus == StorageBus_Floppy) {
> -        name[0] = 'f';
> -        name[1] = 'd';
> +        prefix = "fd";
>      }
>  
> -    if (len == 4) {
> -        name[2] = (char)(97 + total);
> -    } else if (len == 5) {
> -        name[2] = (char)(96 + (total / 26));
> -        name[3] = (char)(97 + (total % 26));
> -    } else if (len == 6) {
> -        name[2] = (char)(96 + (total / 26*26));
> -        name[3] = (char)(96 + ((total % (26*26)) / 26));
> -        name[4] = (char)(97 + ((total % (26*26)) % 26));
> -    }
> +    name = virIndexToDiskName(total, prefix);
>  
> -    name[len - 1] = '\0';
> -    DEBUG("name=%s, len=%d, total=%d, storageBus=%u, deviceInst=%d, "
> +    DEBUG("name=%s, total=%d, storageBus=%u, deviceInst=%d, "
>            "devicePort=%d deviceSlot=%d, maxPortPerInst=%u maxSlotPerPort=%u",
> -          name, len, total, storageBus, deviceInst, devicePort,
> +          NULLSTR(name), total, storageBus, deviceInst, devicePort,
>            deviceSlot, maxPortPerInst, maxSlotPerPort);
>      return name;
>  }
> @@ -2496,8 +2467,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
>  
>                  imediumattach->vtbl->GetPort(imediumattach, &devicePort);
>                  imediumattach->vtbl->GetDevice(imediumattach, &deviceSlot);
> -                def->disks[diskCount]->dst = vboxGenerateMediumName(dom->conn,
> -                                                                    storageBus,
> +                def->disks[diskCount]->dst = vboxGenerateMediumName(storageBus,
>                                                                      deviceInst,
>                                                                      devicePort,
>                                                                      deviceSlot,

  ACK, now that we have the common routine ... let's use it !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


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