Re: [PATCH v2 1/2] Move virBhyveTapGetRealDeviceName to virnetdevtap

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

 



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


Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]