From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: Re: [PATCH 5/6] libxl: introduce libxl__alloc_vdev Date: Tue, 27 Mar 2012 18:19:25 +0100 Message-ID: <20337.63133.683848.208682@mariner.uk.xensource.com> References: <1332856772-30292-5-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1332856772-30292-5-git-send-email-stefano.stabellini@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , Ian Campbell List-Id: xen-devel@lists.xenproject.org Stefano Stabellini writes ("[PATCH 5/6] libxl: introduce libxl__alloc_vdev"): > Introduce libxl__alloc_vdev: find a spare virtual block device in the > domain passed as argument. ... > +static int libxl__vdev_to_index(libxl__gc *gc, char *vdev) > +{ > + if (vdev == NULL) > + return 0; > + if (strlen(vdev) > 4 || strlen(vdev) < 4) > + return 0; > + /* assume xvdz is the last one available */ This is a broken half-reimplementation of libxl__device_disk_dev_number. > + free(disks); > + return libxl__index_to_vdev(gc, max_idx); And you don't need this function because you can use the disk number directly (converted to a string of decimal digits) as the vdev. Of course you can't then using the resulting vdev as a pathname in /dev/ but that's nonportable anyway; different guest OSs (and here we are playing the role of the guest) may have different conventions. You need a separate function to convert vdev numbers (as returned from _disk_dev_number) to pathnames in /dev. > + for (i = 0; i < num; i++) { > + idx = libxl__vdev_to_index(gc, disks[i].vdev); Furthermore, for the purpose for which you're using this, you should not start at zero (xvda). You should start at at least 26 (xvdA) and possibly later. That way you are less likely to clash with other statically-allocated vbds. Ian.