[libvirt] [PATCH 2/2] lxc: move wireless PHYs to a network namespace

Michal Privoznik mprivozn at redhat.com
Thu Apr 16 15:23:04 UTC 2015


On 14.04.2015 18:21, Lubomir Rintel wrote:
> The 802.11 interfaces can not be moved by themselves, their Phy has to move too.
> 
> If there are other interfaces, they have to move too -- hopefully it's not too
> confusing. This is a less-invasive alternative to defining a new hostdev type
> for PHYs.
> ---
>  src/util/virnetdev.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index ee60f09..df48763 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -584,6 +584,8 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
>  {
>      int rc;
>      char *pid = NULL;
> +    char *phy_path = NULL;
> +
>      const char *argv[] = {
>          "ip", "link", "set", ifname, "netns", NULL, NULL
>      };
> @@ -591,6 +593,35 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
>      if (virAsprintf(&pid, "%lld", (long long) pidInNs) == -1)
>          return -1;
>  
> +    /* The 802.11 wireless devices only move together with their PHY. */
> +    if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") >= 0) {
> +        int len;
> +        char *phy = NULL;
> +
> +        len = virFileReadAllQuiet(phy_path, 1024, &phy);
> +        VIR_FREE(phy_path);
> +
> +        /* Remove a line break. */
> +        if (len > 0)
> +            phy[len - 1] = '\0';
> +
> +        if (len >= 0) {
> +            const char *iwargv[] = {
> +                "iw", "phy", phy, "set", "netns", NULL, NULL
> +            };
> +
> +            iwargv[5] = pid;
> +            rc = virRun(iwargv, NULL);
> +
> +            VIR_FREE(phy);
> +
> +            if (rc == 0) {
> +                VIR_FREE(pid);
> +                return rc;
> +            }
> +        }
> +    }
> +
>      argv[5] = pid;
>      rc = virRun(argv, NULL);
>  
> 

I understand what you mean, but the code style could be better. I'll
polish and resend the patch in your name.

Michal




More information about the libvir-list mailing list