diff options
author | Theodore Ts'o <tytso@mit.edu> | 2021-07-24 12:55:28 -0400 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2021-07-25 21:39:58 -0700 |
commit | c04264e47fd1c14c37ef4618c07d71ea75a2b87e (patch) | |
tree | 15bf73e9bcb996cc0d4d3f7cfa1d2eaaeb2d63d6 | |
parent | 956ab461229cc9c070009e623cae03ea2c988321 (diff) | |
download | e2fsprogs-c04264e47fd1c14c37ef4618c07d71ea75a2b87e.tar.gz |
libext2fs: avoid unnecessary stat(2) calls on mountpoints
If the device name in the mtab or /proc/mounts file does not match
with the device passed into ext2fs_check_if_mounted() or
ext2fs_check_mount_point(), skip the stat(2) call on the mountpoint,
since we never use the results of the stat(2) in that case. Not only
does this provide a slight performance win, but it the stat calls on
the mountpoints could potentially trigger some SELinux denials that
could stress some sysadmins out.
Google-Bug-Id: 193137337
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit ddee43e8e847b25148d694bb5dbec633729e975b)
Bug: 193137337
Change-Id: I2f8ae579b892e959113a03c6615e8a2736ab41bc
-rw-r--r-- | lib/ext2fs/ismounted.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/ext2fs/ismounted.c b/lib/ext2fs/ismounted.c index 46d330d9..c9e6a9d0 100644 --- a/lib/ext2fs/ismounted.c +++ b/lib/ext2fs/ismounted.c @@ -128,14 +128,14 @@ static errcode_t check_mntent_file(const char *mtab_file, const char *file, while ((mnt = getmntent (f)) != NULL) { if (mnt->mnt_fsname[0] != '/') continue; - if (stat(mnt->mnt_dir, &st_buf) != 0) - continue; if (strcmp(file, mnt->mnt_fsname) == 0) { + if (stat(mnt->mnt_dir, &st_buf) != 0) + continue; if (file_rdev && (file_rdev != st_buf.st_dev)) { #ifdef DEBUG printf("Bogus entry in %s! " - "(%s does not exist)\n", - mtab_file, mnt->mnt_dir); + "(%s is not mounted on %s)\n", + mtab_file, file, mnt->mnt_dir); #endif /* DEBUG */ continue; } |