From 26b0d2e1a1606da10c4dc4e109d7b9f2d92aab6a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 29 May 2014 09:41:29 +0530 Subject: [PATCH] Avoid stat/fstat in statvfs/fstatvfs (BZ #15132) Delay the use of stat/fstat until stat data is required. When the kernel returns ST_VALID, stat data is not used by __internal_statvfs. --- ChangeLog | 16 ++++++++++++++++ NEWS | 20 ++++++++++---------- sysdeps/unix/sysv/linux/fstatvfs.c | 4 ++-- sysdeps/unix/sysv/linux/fstatvfs64.c | 10 +++------- sysdeps/unix/sysv/linux/internal_statvfs.c | 15 ++++++++------- sysdeps/unix/sysv/linux/statvfs.c | 6 ++---- sysdeps/unix/sysv/linux/statvfs64.c | 10 +++------- 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ffe903d6e..a93d36717a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-05-29 Eric Wong + + [BZ #15132] + * sysdeps/unix/sysv/linux/internal_statvfs.c (__statvfs_getflags): + Call fstat64 or stat64 internally, depending on arguments passed. + Replace stat buffer argument with file descriptor argument. + (INTERNAL_STATVFS): Update arguments to match __statvfs_getflags. + * sysdeps/unix/sysv/linux/fstatvfs.c (fstatvfs): + Pass fd to __internal_statvfs instead of calling fstat64. + * sysdeps/unix/sysv/linux/fstatvfs64.c (__fstatvfs64): + Pass fd to __internal_statvfs64 instead of calling fstat64. + * sysdeps/unix/sysv/linux/statvfs.c (statvfs): + Pass -1 to __internal_statvfs instead of calling stat64. + * sysdeps/unix/sysv/linux/statvfs64.c (__statvfs64): + Pass -1 to __internal_statvfs64 instead of calling stat64. + 2014-05-28 Roland McGrath * sysdeps/unix/sysv/linux/sh/clone.S: Deconditionalize the code diff --git a/NEWS b/NEWS index 6a0c222cbd..52d5714d44 100644 --- a/NEWS +++ b/NEWS @@ -9,16 +9,16 @@ Version 2.20 * The following bugs are resolved with this release: - 6804, 9894, 12994, 13347, 13651, 14308, 14770, 15119, 15347, 15514, 15804, - 15894, 16002, 16064, 16198, 16284, 16348, 16349, 16357, 16362, 16447, - 16516, 16532, 16545, 16564, 16574, 16599, 16600, 16609, 16610, 16611, - 16613, 16619, 16623, 16629, 16632, 16634, 16639, 16642, 16648, 16649, - 16670, 16674, 16677, 16680, 16683, 16689, 16695, 16701, 16706, 16707, - 16712, 16713, 16714, 16724, 16731, 16739, 16740, 16743, 16754, 16758, - 16759, 16760, 16770, 16786, 16789, 16791, 16796, 16799, 16800, 16815, - 16823, 16824, 16831, 16838, 16849, 16854, 16876, 16877, 16878, 16885, - 16888, 16890, 16912, 16915, 16916, 16917, 16922, 16927, 16928, 16932, - 16943, 16958, 16966, 16967, 16965, 16977, 16978, 16984, 16990. + 6804, 9894, 12994, 13347, 13651, 14308, 14770, 15119, 15132, 15347, 15514, + 15804, 15894, 16002, 16064, 16198, 16284, 16348, 16349, 16357, 16362, + 16447, 16516, 16532, 16545, 16564, 16574, 16599, 16600, 16609, 16610, + 16611, 16613, 16619, 16623, 16629, 16632, 16634, 16639, 16642, 16648, + 16649, 16670, 16674, 16677, 16680, 16683, 16689, 16695, 16701, 16706, + 16707, 16712, 16713, 16714, 16724, 16731, 16739, 16740, 16743, 16754, + 16758, 16759, 16760, 16770, 16786, 16789, 16791, 16796, 16799, 16800, + 16815, 16823, 16824, 16831, 16838, 16849, 16854, 16876, 16877, 16878, + 16885, 16888, 16890, 16912, 16915, 16916, 16917, 16922, 16927, 16928, + 16932, 16943, 16958, 16966, 16967, 16965, 16977, 16978, 16984, 16990. * The minimum Linux kernel version that this version of the GNU C Library can be used with is 2.6.32. diff --git a/sysdeps/unix/sysv/linux/fstatvfs.c b/sysdeps/unix/sysv/linux/fstatvfs.c index da1f27e721..689ab7ad10 100644 --- a/sysdeps/unix/sysv/linux/fstatvfs.c +++ b/sysdeps/unix/sysv/linux/fstatvfs.c @@ -22,7 +22,7 @@ #include extern void __internal_statvfs (const char *name, struct statvfs *buf, - struct statfs *fsbuf, struct stat64 *st); + struct statfs *fsbuf, int fd); int @@ -36,7 +36,7 @@ fstatvfs (int fd, struct statvfs *buf) return -1; /* Convert the result. */ - __internal_statvfs (NULL, buf, &fsbuf, fstat64 (fd, &st) == -1 ? NULL : &st); + __internal_statvfs (NULL, buf, &fsbuf, fd); /* We signal success if the statfs call succeeded. */ return 0; diff --git a/sysdeps/unix/sysv/linux/fstatvfs64.c b/sysdeps/unix/sysv/linux/fstatvfs64.c index dd10c1ffec..006b0591ba 100644 --- a/sysdeps/unix/sysv/linux/fstatvfs64.c +++ b/sysdeps/unix/sysv/linux/fstatvfs64.c @@ -25,7 +25,7 @@ extern void __internal_statvfs64 (const char *name, struct statvfs64 *buf, - struct statfs64 *fsbuf, struct stat64 *st); + struct statfs64 *fsbuf, int fd); /* Return information about the filesystem on which FD resides. */ @@ -60,12 +60,8 @@ __fstatvfs64 (int fd, struct statvfs64 *buf) #endif if (res == 0) - { - /* Convert the result. */ - struct stat64 st; - __internal_statvfs64 (NULL, buf, &fsbuf, - fstat64 (fd, &st) == -1 ? NULL : &st); - } + /* Convert the result. */ + __internal_statvfs64 (NULL, buf, &fsbuf, fd); return res; } diff --git a/sysdeps/unix/sysv/linux/internal_statvfs.c b/sysdeps/unix/sysv/linux/internal_statvfs.c index 2424c138ac..d71ed0cd72 100644 --- a/sysdeps/unix/sysv/linux/internal_statvfs.c +++ b/sysdeps/unix/sysv/linux/internal_statvfs.c @@ -43,9 +43,11 @@ # ifndef __ASSUME_STATFS_F_FLAGS int -__statvfs_getflags (const char *name, int fstype, struct stat64 *st) +__statvfs_getflags (const char *name, int fstype, int fd) { - if (st == NULL) + struct stat64 st; + + if ((fd < 0 ? stat64 (name, &st) : fstat64 (fd, &st)) < 0) return 0; const char *fsname = NULL; @@ -159,7 +161,7 @@ __statvfs_getflags (const char *name, int fstype, struct stat64 *st) /* Find out about the device the current entry is for. */ struct stat64 fsst; if (stat64 (mntbuf.mnt_dir, &fsst) >= 0 - && st->st_dev == fsst.st_dev) + && st.st_dev == fsst.st_dev) { /* Bingo, we found the entry for the device FD is on. Now interpret the option string. */ @@ -222,14 +224,13 @@ __statvfs_getflags (const char *name, int fstype, struct stat64 *st) } # endif #else -extern int __statvfs_getflags (const char *name, int fstype, - struct stat64 *st); +extern int __statvfs_getflags (const char *name, int fstype, int fd); #endif void INTERNAL_STATVFS (const char *name, struct STATVFS *buf, - struct STATFS *fsbuf, struct stat64 *st) + struct STATFS *fsbuf, int fd) { /* Now fill in the fields we have information for. */ buf->f_bsize = fsbuf->f_bsize; @@ -272,7 +273,7 @@ INTERNAL_STATVFS (const char *name, struct STATVFS *buf, the /etc/mtab file and search for the entry which matches the given file. The way we can test for matching filesystem is using the device number. */ - buf->f_flag = __statvfs_getflags (name, fsbuf->f_type, st); + buf->f_flag = __statvfs_getflags (name, fsbuf->f_type, fd); else #endif buf->f_flag = fsbuf->f_flags ^ ST_VALID; diff --git a/sysdeps/unix/sysv/linux/statvfs.c b/sysdeps/unix/sysv/linux/statvfs.c index 8a3df97c76..14279613b0 100644 --- a/sysdeps/unix/sysv/linux/statvfs.c +++ b/sysdeps/unix/sysv/linux/statvfs.c @@ -22,22 +22,20 @@ #include extern void __internal_statvfs (const char *name, struct statvfs *buf, - struct statfs *fsbuf, struct stat64 *st); + struct statfs *fsbuf, int fd); int statvfs (const char *file, struct statvfs *buf) { struct statfs fsbuf; - struct stat64 st; /* Get as much information as possible from the system. */ if (__statfs (file, &fsbuf) < 0) return -1; /* Convert the result. */ - __internal_statvfs (file, buf, &fsbuf, - stat64 (file, &st) == -1 ? NULL : &st); + __internal_statvfs (file, buf, &fsbuf, -1); /* We signal success if the statfs call succeeded. */ return 0; diff --git a/sysdeps/unix/sysv/linux/statvfs64.c b/sysdeps/unix/sysv/linux/statvfs64.c index e33e923a05..0ec8524a44 100644 --- a/sysdeps/unix/sysv/linux/statvfs64.c +++ b/sysdeps/unix/sysv/linux/statvfs64.c @@ -26,7 +26,7 @@ extern void __internal_statvfs64 (const char *name, struct statvfs64 *buf, - struct statfs64 *fsbuf, struct stat64 *st); + struct statfs64 *fsbuf, int fd); /* Return information about the filesystem on which FILE resides. */ @@ -61,12 +61,8 @@ __statvfs64 (const char *file, struct statvfs64 *buf) #endif if (res == 0) - { - /* Convert the result. */ - struct stat64 st; - __internal_statvfs64 (file, buf, &fsbuf, - stat64 (file, &st) == -1 ? NULL : &st); - } + /* Convert the result. */ + __internal_statvfs64 (file, buf, &fsbuf, -1); return res; } -- 2.43.5