Bug 430768

Summary: opendir / __alloc_dir tries to malloc st_blksize; may fail
Product: [Fedora] Fedora Reporter: Eric Sandeen <esandeen>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: drepper
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-04-10 10:04:59 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Eric Sandeen 2008-01-29 18:20:56 UTC
A filesytem may report its preferred IO size (not fundamental block size) in
st_blksize, and this might be fairly large:

[root@magnesium tmp]# stat mnt
  File: `mnt'
  Size: 27        	Blocks: 0          IO Block: 536870912 directory
Device: 700h/1792d	Inode: 128         Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2008-01-29 11:40:37.091973914 -0600
Modify: 2008-01-29 11:40:50.078976949 -0600
Change: 2008-01-29 11:40:50.078976949 -0600

It appears that opendir / __alloc_dir will attempt to use that size, without
fallback:

[root@magnesium tmp]# strace -otrace ./test
[root@magnesium tmp]# grep -3 53687 trace
open("mnt", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|0x80000) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=27, ...}) = 0
fcntl64(3, F_GETFD)                     = 0x1 (flags FD_CLOEXEC)
mmap2(NULL, 536875008, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x97f86000
munmap(0x97f86000, 536875008)           = 0
close(3)                                = 0
exit_group(0)                           = ?

Since st_blksize is "preferred" and the alternative is an opendir failure,
should this fall back to smaller sizes on ENOMEM?

Thanks,
-Eric

Comment 1 Jakub Jelinek 2008-02-04 09:17:09 UTC
And so will many other apps do.  Using such huge preferred IO size is not very wise.

Comment 2 Eric Sandeen 2008-02-04 14:06:57 UTC
Agreed, and perhaps even if reporting large IO sizes for files, the fs should
report something smaller for directories.

But in any case, do you think that glibc (and other apps...) should fall back to
smaller sizes if allocation fails?

Comment 3 Ulrich Drepper 2008-03-30 08:52:49 UTC
I've checked in upstream a patch to try a possibly smaller allocation if the
size provided by st_blksize couldn't be fulfilled.

Comment 4 Jakub Jelinek 2008-04-10 10:04:59 UTC
Should be in glibc-2.7.90-14