As far as I can tell, only 'mv -Z' uses the recursive code in the
restorecon function. It calls restorecon_private, which opens a file
descriptor and performs an fstat/stat call. Therefore, the fts stat is
not necessary. I noticed this while looking to make some other changes
here.
-- 8< --
Before:
$ rm -rf a b; mkdir -p a; touch a/{1..1000};
$ strace -c -e trace='/stat' ./src/mv-prev -Z a b
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
55.18 0.003251 3 1017 3 newfstatat
44.60 0.002628 2 1019 fstat
0.22 0.000013 6 2 statfs
------ ----------- ----------- --------- --------- ----------------
100.00 0.005892 2 2038 3 total
After:
$ rm -rf a b; mkdir -p a; touch a/{1..1000};
$ strace -c -e trace='/stat' ./src/mv -Z a b
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
98.18 0.003071 3 1019 fstat
1.34 0.000042 2 17 3 newfstatat
0.48 0.000015 7 2 statfs
------ ----------- ----------- --------- --------- ----------------
100.00 0.003128 3 1038 3 total
* src/selinux.c (restorecon): Use FTS_NOSTAT.
* NEWS: Mention the bug fix.
---
NEWS | 4 ++++
src/selinux.c | 3 ++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 3441f1bf2..58850e489 100644
--- a/NEWS
+++ b/NEWS
@@ -185,6 +185,10 @@ GNU coreutils NEWS -*-
outline -*-
just-moved FIFO.
[bug introduced with SELinux support in coreutils-8.22]
+ 'mv -Z' no longer performs an extra fstatat call for each directory entry
+ located under a moved directory.
+ [bug introduced with SELinux support in coreutils-8.22]
+
'mv --exchange A B' now emits a more meaningful error message when file B
does
not exist. Previously, it would print the error message as if errno were set
to -1, e.g., "Unknown error -1" on glibc.
diff --git a/src/selinux.c b/src/selinux.c
index e5f5e14bb..d56a7a246 100644
--- a/src/selinux.c
+++ b/src/selinux.c
@@ -308,7 +308,8 @@ restorecon (struct selabel_handle *selabel_handle,
}
char const *ftspath[2] = { path, NULL };
- FTS *fts = xfts_open ((char *const *) ftspath, FTS_PHYSICAL, NULL);
+ FTS *fts = xfts_open ((char *const *) ftspath, FTS_PHYSICAL | FTS_NOSTAT,
+ NULL);
int err = 0;
for (FTSENT *ent; (ent = fts_read (fts)); )
--
2.56.1