From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Ed Maste <emaste@freebsd.org>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Anthony Liguori <aliguori@amazon.com>
Subject: Re: [Qemu-devel] [PATCH] tap-bsd: use user-specified tap device if it already exists
Date: Tue, 27 Oct 2015 10:25:14 +0100 [thread overview]
Message-ID: <562F42FA.5040805@citrix.com> (raw)
In-Reply-To: <1445615635-90549-1-git-send-email-emaste@freebsd.org>
Ccing the maintainers.
El 23/10/15 a les 17.53, Ed Maste ha escrit:
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
> Signed-off-by: Ed Maste <emaste@freebsd.org>
> ---
> As an aside this was reviewed on FreeBSD's Phabricator here:
> https://reviews.freebsd.org/D3969
>
> Resend with Signed-off-by.
>
> net/tap-bsd.c | 38 +++++++++++++++++++++++++++++++++-----
> 1 file changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> index 7028d9b..0103a97 100644
> --- a/net/tap-bsd.c
> +++ b/net/tap-bsd.c
> @@ -109,8 +109,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
>
> #define PATH_NET_TAP "/dev/tap"
>
> -int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
> - int vnet_hdr_required, int mq_required, Error **errp)
> +static int tap_open_clone(char *ifname, int ifname_size, Error **errp)
> {
> int fd, s, ret;
> struct ifreq ifr;
> @@ -126,7 +125,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
> ret = ioctl(fd, TAPGIFNAME, (void *)&ifr);
> if (ret < 0) {
> error_setg_errno(errp, errno, "could not get tap interface name");
> - goto error;
> + close(fd);
> + return -1;
> }
>
> if (ifname[0] != '\0') {
> @@ -135,19 +135,47 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
> if (s < 0) {
> error_setg_errno(errp, errno,
> "could not open socket to set interface name");
> - goto error;
> + close(fd);
> + return -1;
> }
> ifr.ifr_data = ifname;
> ret = ioctl(s, SIOCSIFNAME, (void *)&ifr);
> close(s);
> if (ret < 0) {
> error_setg(errp, "could not set tap interface name");
> - goto error;
> + close(fd);
> + return -1;
> }
> } else {
> pstrcpy(ifname, ifname_size, ifr.ifr_name);
> }
>
> + return fd;
> +}
> +
> +int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
> + int vnet_hdr_required, int mq_required, Error **errp)
> +{
> + int fd = -1;
> +
> + /* If the specified tap device already exists just use it. */
> + if (ifname[0] != '\0') {
> + char dname[100];
> + snprintf(dname, sizeof dname, "/dev/%s", ifname);
> + TFR(fd = open(dname, O_RDWR));
> + if (fd < 0 && errno != ENOENT) {
> + error_setg_errno(errp, errno, "could not open %s", dname);
> + return -1;
> + }
> + }
> +
> + if (fd < 0) {
> + /* Tap device not specified or does not exist. */
> + if ((fd = tap_open_clone(ifname, ifname_size, errp)) < 0) {
> + return -1;
> + }
> + }
> +
> if (*vnet_hdr) {
> /* BSD doesn't have IFF_VNET_HDR */
> *vnet_hdr = 0;
>
next prev parent reply other threads:[~2015-10-27 9:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-23 14:39 [Qemu-devel] [PATCH] tap-bsd: use user-specified tap device if it already exists Ed Maste
2015-10-23 15:49 ` Roger Pau Monné
2015-10-23 15:53 ` Ed Maste
2015-10-27 9:25 ` Roger Pau Monné [this message]
2015-11-06 8:53 ` Michael Tokarev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=562F42FA.5040805@citrix.com \
--to=roger.pau@citrix.com \
--cc=aliguori@amazon.com \
--cc=emaste@freebsd.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).