From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: Paul Holzinger <pholzing@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 3/3] tap: Remove unnecessary global tun_ns_fd
Date: Wed, 2 Aug 2023 13:15:42 +1000 [thread overview]
Message-ID: <20230802031542.2726758-4-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20230802031542.2726758-1-david@gibson.dropbear.id.au>
tap_ns_tun(), which runs in an ephemeral thread puts the fd it opens into
the global variable tun_ns_fd to communicate it back to the main thread
in tap_sock_tun_init().
However, the only thing tap_sock_tun_init() does with it is copies it to
c->fd_tap and everything else uses it from there. tap_ns_tun() already
has access to the context structure, so we might as well store the value
directly in there rather than having a global as an intermediate.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tap.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/tap.c b/tap.c
index a5d357a..e034f94 100644
--- a/tap.c
+++ b/tap.c
@@ -1165,8 +1165,6 @@ static void tap_sock_unix_new(struct ctx *c)
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev);
}
-static int tun_ns_fd = -1;
-
/**
* tap_ns_tun() - Get tuntap fd in namespace
* @c: Execution context
@@ -1182,7 +1180,7 @@ static int tap_ns_tun(void *arg)
struct ctx *c = (struct ctx *)arg;
int fd, rc;
- tun_ns_fd = -1;
+ c->fd_tap = -1;
memcpy(ifr.ifr_name, c->pasta_ifn, IFNAMSIZ);
ns_enter(c);
@@ -1197,7 +1195,7 @@ static int tap_ns_tun(void *arg)
if (!(c->pasta_ifi = if_nametoindex(c->pasta_ifn)))
die("Tap device opened but no network interface found");
- tun_ns_fd = fd;
+ c->fd_tap = fd;
return 0;
}
@@ -1211,13 +1209,11 @@ static void tap_sock_tun_init(struct ctx *c)
struct epoll_event ev = { 0 };
NS_CALL(tap_ns_tun, c);
- if (tun_ns_fd == -1)
+ if (c->fd_tap == -1)
die("Failed to set up tap device in namespace");
pasta_ns_conf(c);
- c->fd_tap = tun_ns_fd;
-
ev.data.fd = c->fd_tap;
ev.events = EPOLLIN | EPOLLRDHUP;
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev);
--
@@ -1165,8 +1165,6 @@ static void tap_sock_unix_new(struct ctx *c)
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev);
}
-static int tun_ns_fd = -1;
-
/**
* tap_ns_tun() - Get tuntap fd in namespace
* @c: Execution context
@@ -1182,7 +1180,7 @@ static int tap_ns_tun(void *arg)
struct ctx *c = (struct ctx *)arg;
int fd, rc;
- tun_ns_fd = -1;
+ c->fd_tap = -1;
memcpy(ifr.ifr_name, c->pasta_ifn, IFNAMSIZ);
ns_enter(c);
@@ -1197,7 +1195,7 @@ static int tap_ns_tun(void *arg)
if (!(c->pasta_ifi = if_nametoindex(c->pasta_ifn)))
die("Tap device opened but no network interface found");
- tun_ns_fd = fd;
+ c->fd_tap = fd;
return 0;
}
@@ -1211,13 +1209,11 @@ static void tap_sock_tun_init(struct ctx *c)
struct epoll_event ev = { 0 };
NS_CALL(tap_ns_tun, c);
- if (tun_ns_fd == -1)
+ if (c->fd_tap == -1)
die("Failed to set up tap device in namespace");
pasta_ns_conf(c);
- c->fd_tap = tun_ns_fd;
-
ev.data.fd = c->fd_tap;
ev.events = EPOLLIN | EPOLLRDHUP;
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap, &ev);
--
2.41.0
next prev parent reply other threads:[~2023-08-02 3:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-02 3:15 [PATCH 0/3] Better report errors failing to open namespace tap device David Gibson
2023-08-02 3:15 ` [PATCH 1/3] util: Make ns_enter() a void function and report setns() errors David Gibson
2023-08-02 3:15 ` [PATCH 2/3] tap: More detailed error reporting in tap_ns_tun() David Gibson
2023-08-02 3:15 ` David Gibson [this message]
2023-08-04 7:04 ` [PATCH 0/3] Better report errors failing to open namespace tap device Stefano Brivio
2023-08-04 8:35 ` David Gibson
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=20230802031542.2726758-4-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=pholzing@redhat.com \
--cc=sbrivio@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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).