[PATCH 1/5] util: fix tap device name auto-generation for FreeBSD
Michal Privoznik
mprivozn at redhat.com
Wed Dec 16 21:27:10 UTC 2020
On 12/16/20 2:27 AM, Laine Stump wrote:
> The Linux implementation of virNetDevCreate() no longer requires a
> template ifname (e.g. "vnet%d") when it is called, but just generates
> a new name if ifname is empty. The FreeBSD implementation requires
> that the caller actually fill in a template ifname, and will fail if
> ifname is empty. Since we want to eliminate all the special code in
> callers that is setting the template name, we need to make the
> behavior of the FreeBSD virNetDevCreate() match the behavior of the
> Linux virNetDevCreate().
>
> The simplest way to do this is to use the new virNetDevGenerateName()
> function - if ifname is empty it generates a new name with the proper
> prefix, and if it's not empty, it leaves it alone.
>
> Signed-off-by: Laine Stump <laine at redhat.com>
> ---
> src/util/virnetdevtap.c | 35 ++++++-----------------------------
> 1 file changed, 6 insertions(+), 29 deletions(-)
>
> diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
> index 88ad321627..cca2f614fe 100644
> --- a/src/util/virnetdevtap.c
> +++ b/src/util/virnetdevtap.c
> @@ -308,7 +308,6 @@ int virNetDevTapCreate(char **ifname,
> int s;
> struct ifreq ifr;
> int ret = -1;
> - char *newifname = NULL;
>
> if (tapfdSize > 1) {
> virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> @@ -316,6 +315,12 @@ int virNetDevTapCreate(char **ifname,
> goto cleanup;
> }
>
> + /* auto-generate an unused name for the new device (this
> + * is NOP if a name has been provided)
> + */
> + if (virNetDevGenerateName(ifname, VIR_NET_DEV_GEN_NAME_VNET) < 0)
> + return -1;
> +
This line ^^ contains some trailing spaces.
> /* As FreeBSD determines interface type by name,
> * we have to create 'tap' interface first and
> * then rename it to 'vnet'
Michal
More information about the libvir-list
mailing list