php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60666 scandir doesn''t return entries on GlusterFS (redHat's) file system
Submitted: 2012-01-05 22:13 UTC Modified: 2021-09-26 04:22 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:2 of 3 (66.7%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: hunter at yessoftware dot com Assigned: cmb (profile)
Status: No Feedback Package: Directory function related
PHP Version: 5.3.8 OS: CentOS 5.7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
17 + 37 = ?
Subscribe to this entry?

 
 [2012-01-05 22:13 UTC] hunter at yessoftware dot com
Description:
------------
When I'm trying to scandir or opendir/readdir on GlusterFS Distributed volumes (mounted to some folder) I got something but not I'm expecting to obtainan: empty array even without . and .. entries, only . entry, 2-3 entries instead of >100 and so on.

Other ways (bash ls or perl opendir) works correctly.

for example:
distributed GlusterFS volume mounted to /sites/blog folder.
scandir("/sites/blog");

array(0) {
}
distributed GlusterFS volume mounted to /sites/other folder:
scandir("/sites/other");
array(1) {
  [0]=>
  string(1) "."
}
scandir("/sites/other/old");
array(3) {
  [0]=>
  string(1) "."
  [1]=>
  string(11) "1.2.0.2540"
  [2]=>
  string(11) "1.5.0.2559"
}




Test script:
---------------
<?php
clearstatcache();
var_dump(scandir('/sites/blogs'));
var_dump(scandir('/sites/other'));
var_dump(scandir('/sites/other/ms'));
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-07 12:36 UTC] hunter at yessoftware dot com
PHP strace:
10458 open("/sites/cache", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
10458 fcntl64(3, F_SETFD, FD_CLOEXEC)   = 0
10458 getdents(3, 0x9d0640c, 32768)     = -1 EINVAL (Invalid argument)
10458 close(3)                          = 0
10458 write(1, "0\r\n", 3)              = 3
10458 open("/nonglustered/dir", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
10458 fcntl64(3, F_SETFD, FD_CLOEXEC)   = 0
10458 getdents(3, 0x9d0640c, 32768)     = 120
10458 getdents(3, 0x9d0640c, 32768)     = 0
10458 close(3)                          = 0
10458 write(1, "3\r\n", 3)              = 3
10458 close(0)                          = 0

Perl strace
open("/sites/other", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fcntl64(3, F_SETFD, FD_CLOEXEC)         = 0
brk(0x8608000)                          = 0x8608000
getdents64(3, /* 24 entries */, 32768)  = 1352
write(1, "12548855754ef9fb85723261.9149936"..., 38) = 38

So goal is to use getdents64 instead of getdents.

The original Linux getdents() system call did not handle large file systems and large file offsets. Consequently, Linux 2.4 added getdents64(), with wider types for the d_ino and d_off fields employed in the linux_dirent structure.
 [2012-01-10 13:18 UTC] hunter at yessoftware dot com
I solved it by rebuilding php with 
export CPPFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
./configure
 [2019-11-08 11:16 UTC] 7eggert at gmx dot de
I experienced the same or something similar with mergerfs. While scandir() or readdir report not even "." and "..", but () and false. stracing the apache process with the PHP7.3.10 of openSUSE Tumbleweed, shows the call to getdents64.
Using glob() does return a nonempty array.
 [2021-09-14 13:46 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-09-14 13:46 UTC] cmb@php.net
Is this still an issue with any of the actively supported PHP
versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-09-26 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC