From: Markus Armbruster <armbru@redhat.com>
To: Bin Meng <bmeng@tinylab.org>
Cc: qemu-devel@nongnu.org,
"Richard Henderson" <richard.henderson@linaro.org>,
"Zhangjin Wu" <falcon@tinylab.org>,
"Claudio Imbrenda" <imbrenda@linux.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Thomas Huth" <thuth@redhat.com>
Subject: Re: [PATCH v4 5/6] util/async-teardown: Use qemu_close_range() to close fds
Date: Fri, 07 Jul 2023 16:40:55 +0200 [thread overview]
Message-ID: <875y6vg4y0.fsf@pond.sub.org> (raw)
In-Reply-To: <20230628152726.110295-6-bmeng@tinylab.org> (Bin Meng's message of "Wed, 28 Jun 2023 23:27:25 +0800")
Bin Meng <bmeng@tinylab.org> writes:
> From: Zhangjin Wu <falcon@tinylab.org>
>
> Based on the old close_all_open_fd() of util/async-teardown.c, a new
> generic qemu_close_range() has been added in osdep.c.
>
> Now, let's switch over to use the generic qemu_close_range().
>
> Signed-off-by: Zhangjin Wu <falcon@tinylab.org>
> Signed-off-by: Bin Meng <bmeng@tinylab.org>
>
> ---
>
> Changes in v4:
> - call sysconf directly instead of using a variable
>
> Changes in v3:
> - limit the last_fd of qemu_close_range() to sysconf(_SC_OPEN_MAX)
>
> Changes in v2:
> - new patch: "util/async-teardown: Use qemu_close_range() to close fds"
>
> util/async-teardown.c | 41 +----------------------------------------
> 1 file changed, 1 insertion(+), 40 deletions(-)
>
> diff --git a/util/async-teardown.c b/util/async-teardown.c
> index 7e0177a8da..a038a255ff 100644
> --- a/util/async-teardown.c
> +++ b/util/async-teardown.c
> @@ -29,44 +29,6 @@
>
> static pid_t the_ppid;
>
> -/*
> - * Close all open file descriptors.
> - */
> -static void close_all_open_fd(void)
> -{
> - struct dirent *de;
> - int fd, dfd;
> - DIR *dir;
> -
> -#ifdef CONFIG_CLOSE_RANGE
> - int r = close_range(0, ~0U, 0);
> - if (!r) {
> - /* Success, no need to try other ways. */
> - return;
> - }
> -#endif
> -
> - dir = opendir("/proc/self/fd");
> - if (!dir) {
> - /* If /proc is not mounted, close fds one by one. */
> - int open_max = sysconf(_SC_OPEN_MAX), i;
> - for (i = 0; i < open_max; i++) {
> - close(i);
> - }
> - return;
> - }
> - /* Avoid closing the directory. */
> - dfd = dirfd(dir);
> -
> - for (de = readdir(dir); de; de = readdir(dir)) {
> - fd = atoi(de->d_name);
> - if (fd != dfd) {
> - close(fd);
> - }
> - }
> - closedir(dir);
> -}
> -
> static void hup_handler(int signal)
> {
> /* Check every second if this process has been reparented. */
> @@ -92,9 +54,8 @@ static int async_teardown_fn(void *arg)
> /*
> * Close all file descriptors that might have been inherited from the
> * main qemu process when doing clone, needed to make libvirt happy.
> - * Not using close_range for increased compatibility with older kernels.
> */
> - close_all_open_fd();
> + qemu_close_range(0, sysconf(_SC_OPEN_MAX) - 1);
Why do you change the upper bound from ~0U to sysconf(_SC_OPEN_MAX) - 1?
>
> /* Set up a handler for SIGHUP and unblock SIGHUP. */
> sigaction(SIGHUP, &sa, NULL);
next prev parent reply other threads:[~2023-07-07 14:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 15:27 [PATCH v4 0/6] net/tap: Fix QEMU frozen issue when the maximum number of file descriptors is very large Bin Meng
2023-06-28 15:27 ` [PATCH v4 1/6] tests/tcg/cris: Fix the coding style Bin Meng
2023-06-28 15:27 ` [PATCH v4 2/6] tests/tcg/cris: Correct the off-by-one error Bin Meng
2023-06-28 15:27 ` [PATCH v4 3/6] util/async-teardown: Fall back to close fds one by one Bin Meng
2023-06-28 15:27 ` [PATCH v4 4/6] util/osdep: Introduce qemu_close_range() Bin Meng
2023-07-07 14:40 ` Markus Armbruster
2023-06-28 15:27 ` [PATCH v4 5/6] util/async-teardown: Use qemu_close_range() to close fds Bin Meng
2023-07-07 14:40 ` Markus Armbruster [this message]
2023-06-28 15:27 ` [PATCH v4 6/6] net: tap: " Bin Meng
2023-06-30 4:52 ` Jason Wang
2023-06-29 8:33 ` [PATCH v4 0/6] net/tap: Fix QEMU frozen issue when the maximum number of file descriptors is very large Michael Tokarev
2023-06-29 9:05 ` Daniel P. Berrangé
2023-07-09 15:47 ` Bin Meng
2023-07-10 3:05 ` Jason Wang
2023-07-10 6:07 ` Markus Armbruster
2023-07-11 2:40 ` Jason Wang
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=875y6vg4y0.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=bmeng@tinylab.org \
--cc=falcon@tinylab.org \
--cc=imbrenda@linux.ibm.com \
--cc=mst@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.