Bug 1476120 - glibc headers don't include linux/falloc.h, and therefore doesn't include fallocate() flags
glibc headers don't include linux/falloc.h, and therefore doesn't include fal...
Status: NEW
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: glibc (Show other bugs)
7.4
All Unspecified
unspecified Severity medium
: rc
: ---
Assigned To: glibc team
qe-baseos-tools
: TestBlocker
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-07-28 01:46 EDT by David Gibson
Modified: 2017-08-09 04:17 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description David Gibson 2017-07-28 01:46:47 EDT
Description of problem:

RHEL7's kernel supports the fallocate() call and its various flags, such as FALLOC_FL_PUNCH_HOLE.  Likewise the man page for fallocate(2) lists this option and says <fcntl.h> should give you the necessary definitions.

However, while FALLOC_FL_PUNCH_HOLE (and other fallocate() flags) is included in /usr/include/linux/falloc.h (supplied by the kernel), that file is not included, directly or indirectly by /usr/include/fcntl.h

Version-Release number of selected component (if applicable):

glibc-2.17-196.el7.ppc64le
kernel-3.10.0-693.el7.ppc64le

How reproducible:

100%

Steps to Reproduce:
1. Create fallocate.c:

#define _GNU_SOURCE

#include <fcntl.h>

int test(int fd)
{
	return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
			 0, 1024 * 1024);
}

2. Compile source file above with:

    $ gcc -Wall -c fallocate.c

Actual results:

$ gcc -c fallocate.c 
fallocate.c: In function ‘test’:
fallocate.c:7:23: error: ‘FALLOC_FL_PUNCH_HOLE’ undeclared (first use in this function)
  return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                       ^
fallocate.c:7:23: note: each undeclared identifier is reported only once for each function it appears in
fallocate.c:7:46: error: ‘FALLOC_FL_KEEP_SIZE’ undeclared (first use in this function)
  return fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                                              ^

Expected results:

File compiles successfully.

Additional info:

This works correctly in Fedora 26 (and therefore, presumably, in upstream glibc).  In Fedora, fcntl.h indirectly includes linux/falloc.h via bits/fcntl-linux.h.
Comment 2 David Gibson 2017-07-28 01:47:57 EDT
The fallocate() flags are used by one of the testcases in libhugetlbfs which is used for testing hugepages on various systems.
Comment 4 Florian Weimer 2017-07-28 02:52:51 EDT
Relevant upstream commit:

commit 257dabc059447934a90be6fce4b5d2a5f4b63dfd
Author: Joseph Myers <joseph@codesourcery.com>
Date:   Wed Dec 14 18:23:15 2016 +0000

    Include <linux/falloc.h> in bits/fcntl-linux.h.
    
    This patch makes bits/fcntl-linux.h include <linux/falloc.h> to define
    the FALLOC_* flags under __USE_GNU (linux/falloc.h defines only those
    bits, nothing else).

Note You need to log in before you can comment on or make changes to this bug.