[libvirt] [PATCH v2 1/2] Move virBhyveTapGetRealDeviceName to virnetdevtap

Ján Tomko jtomko at redhat.com
Wed Mar 26 12:28:10 UTC 2014


On 03/23/2014 07:17 AM, Roman Bogorodskiy wrote:
> To ease mocking for bhyve unit tests move virBhyveTapGetRealDeviceName()
> out of bhyve_command.c to virnetdevtap and rename it to
> virNetDevTapGetRealDeviceName().
> ---
>  src/bhyve/bhyve_command.c | 70 +----------------------------------------
>  src/libvirt_private.syms  |  1 +
>  src/util/virnetdevtap.c   | 79 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virnetdevtap.h   |  3 ++
>  4 files changed, 84 insertions(+), 69 deletions(-)
> 
>  
> @@ -72,6 +79,78 @@ virNetDevTapGetName(int tapfd ATTRIBUTE_UNUSED, char **ifname ATTRIBUTE_UNUSED)
>  #endif
>  }
>  
> +/**
> + * virNetDevTapGetRealDeviceName:
> + * @ifname: the interface name
> + *
> + * Lookup real interface name (i.e. name of the device entry in /dev),
> + * because e.g. on FreeBSD if we rename tap device to vnetN its device
> + * entry still remains unchanged (/dev/tapX), but bhyve needs a name
> + * that matches /dev entry.
> + *
> + * Returns the proper interface name or NULL if no corresponding interface
> + * found.
> + */
> +char*
> +virNetDevTapGetRealDeviceName(char *ifname)
> +{
> +    char *ret = NULL;
> +    struct dirent *dp;
> +    char *devpath = NULL;
> +    int fd;
> +
> +    DIR *dirp = opendir("/dev");
> +    if (dirp == NULL) {
> +        virReportSystemError(errno,
> +                             _("Failed to opendir path '%s'"),
> +                             "/dev");
> +        return NULL;
> +    }
> +
> +    while ((dp = readdir(dirp)) != NULL) {
> +        if (STRPREFIX(dp->d_name, "tap")) {
> +            struct ifreq ifr;
> +            if (virAsprintf(&devpath, "/dev/%s", dp->d_name) < 0) {
> +                goto cleanup;
> +            }
> +            if ((fd = open(devpath, O_RDWR)) < 0) {
> +                virReportSystemError(errno, _("Unable to open '%s'"), devpath);
> +                goto cleanup;
> +            }
> +
> +            if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {

This fails to build on Linux. The whole function should be #ifdef'd and return
-1 on non-FreeBSD.

> +                virReportSystemError(errno, "%s",
> +                                     _("Unable to query tap interface name"));
> +                goto cleanup;
> +            }
> +

Jan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140326/dc3282b6/attachment-0001.sig>


More information about the libvir-list mailing list