Resolves: #1511951 - df: do not call stat() on file system unless it is necessary

This commit is contained in:
Kamil Dudka 2017-11-10 18:42:59 +01:00
parent 80f5fc5d4d
commit 24c35e9787
2 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,82 @@
From 9c4641f42bbecf63ec0a0e05caacbccd5332b831 Mon Sep 17 00:00:00 2001
From: Philipp Thomas <pth@suse.de>
Date: Sun, 26 Mar 2017 22:34:00 -0700
Subject: [PATCH 1/2] df: avoid querying excluded file systems
* src/df.c (filter_mount_list): Avoid stat() on
explicitly excluded file systems, which is especially
significant in cases like `-x nfs` which may hang.
* NEWS: Mention the bug fix.
Upstream-commit: 7c228bc55ed3fd6d56a6ad135438066de2f54a30
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/df.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/df.c b/src/df.c
index 5b9e8fd..e0ebed7 100644
--- a/src/df.c
+++ b/src/df.c
@@ -682,9 +682,11 @@ filter_mount_list (bool devices_only)
On Linux we probably have me_dev populated from /proc/self/mountinfo,
however we still stat() in case another device was mounted later. */
if ((me->me_remote && show_local_fs)
+ || (!selected_fstype (me->me_type) || excluded_fstype (me->me_type))
|| -1 == stat (me->me_mountdir, &buf))
{
- /* If remote, and showing just local, add ME for filtering later.
+ /* If remote, and showing just local, or FS type is excluded,
+ add ME for filtering later.
If stat failed; add ME to be able to complain about it later. */
buf.st_dev = me->me_dev;
}
--
2.13.6
From 605ec5a50d341fb2d3eea6ad68316e229c7b8382 Mon Sep 17 00:00:00 2001
From: Josef Cejka <jcejka@suse.com>
Date: Tue, 1 Aug 2017 01:50:34 +0200
Subject: [PATCH 2/2] df: avoid stat() for dummy file systems with -l
When systemd is configured to automount a remote file system - see
'man systemd.automount(5)', then the mount point is initially
mounted by systemd with the file system type "autofs".
When the resource is used later on, then the wanted file system is
mounted over that mount point on demand.
'df -l' triggered systemd to mount the file system because it called
stat() on the mount point.
Instead of single-casing "autofs" targets, we can avoid stat()ing
all dummy file systems (which includes "autofs"), because those are
skipped later on in get_dev() anyway.
*src/df.c (filter_mount_list): Also skip dummy file systems unless
the -a option or a specific target are given.
* NEWS: Mention the fix.
Co-authored-by: Bernhard Voelker <mail@bernhard-voelker.de>
Fixes http://bugzilla.suse.com/show_bug.cgi?id=1043059
Upstream-commit: a19ff5d8179a7de38109fc78278229fd96f3941a
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
src/df.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/df.c b/src/df.c
index e0ebed7..11b5a22 100644
--- a/src/df.c
+++ b/src/df.c
@@ -682,6 +682,7 @@ filter_mount_list (bool devices_only)
On Linux we probably have me_dev populated from /proc/self/mountinfo,
however we still stat() in case another device was mounted later. */
if ((me->me_remote && show_local_fs)
+ || (me->me_dummy && !show_all_fs && !show_listed_fs)
|| (!selected_fstype (me->me_type) || excluded_fstype (me->me_type))
|| -1 == stat (me->me_mountdir, &buf))
{
--
2.13.6

View File

@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils
Version: 8.27
Release: 6%{?dist}
Release: 7%{?dist}
License: GPLv3+
Group: System Environment/Base
Url: https://www.gnu.org/software/coreutils/
@ -31,6 +31,9 @@ Patch4: coreutils-8.27-runcon-doc.patch
# ptx: fix a possible crash caused by integer overflow (#1482445)
Patch5: coreutils-8.27-ptx-int-overflow.patch
# df: do not call stat() on file system unless it is necessary (#1511951)
Patch6: coreutils-8.27-df-stat.patch
# disable the test-lock gnulib test prone to deadlock
Patch100: coreutils-8.26-test-lock.patch
@ -313,6 +316,9 @@ fi
%license COPYING
%changelog
* Fri Nov 10 2017 Kamil Dudka <kdudka@redhat.com> - 8.27-7
- df: do not call stat() on file system unless it is necessary (#1511951)
* Fri Aug 18 2017 Kamil Dudka <kdudka@redhat.com> - 8.27-6
- ptx: fix a possible crash caused by integer overflow (#1482445)
- doc: mention `setpriv --no-new-privs` feature in runcon info (#1360903)