Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
For bugs related to Red Hat Enterprise Linux 5 product line. The current stable release is 5.10. For Red Hat Enterprise Linux 6 and above, please visit Red Hat JIRA https://issues.redhat.com/secure/CreateIssue!default.jspa?pid=12332745 to report new issues.

Bug 248405

Summary: the open(2) man page lists an incorrect requirement on O_DIRECT buffer alignment
Product: Red Hat Enterprise Linux 5 Reporter: Jeff Moyer <jmoyer>
Component: man-pagesAssignee: Ivana Varekova <varekova>
Status: CLOSED ERRATA QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: 5.0Keywords: Reopened
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: RHBA-2008-0587 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2008-07-16 13:37:44 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:
Attachments:
Description Flags
reproducer program none

Description Jeff Moyer 2007-07-16 17:40:15 UTC
Description of problem:
O_DIRECT I/O must be allowed to buffers aligned on a 512-byte boundary, and must
allow an I/O size that is a multiple of 512 bytes.  This works properly on every
other architecture.

Version-Release number of selected component (if applicable):
2.6.18-32.el5

How reproducible:
100%

Steps to Reproduce:
Run the attached reproducer.

Comment 1 Jeff Moyer 2007-07-16 17:40:15 UTC
Created attachment 159344 [details]
reproducer program

Comment 2 Jan Glauber 2007-07-23 12:43:18 UTC
On s390 the I/O size is not 512 bytes but 4096 bytes! Therefore this testcase
does produce an error (due to the check in fs/direct_io.c: __blockdev_direct_IO()).

Reading 512 bytes with direct-IO is therefore not supported on s390... rejecting.

Comment 3 Jeff Moyer 2007-07-23 13:58:27 UTC
Jan,

I discussed this with Zach Brown, and he said that this is an ABI that the
kernel provides to userspace.  Alignment on 512 byte boundaries must be
supported, so this is a bug.  Surely you can read in 4k and zero out the
remainder of the block?  It's not optimal, but should only be required for the
first/last partial blocks.

Comment 4 Jan Glauber 2007-07-24 11:47:04 UTC
Jeffrey,

it is not correct that the direct-IO blocksize is always 512 bytes. It happens
to be 512 bytes on other architectures but on s390 the dasd device blocksize
always was 4K. Direct-IO must work with the blocksize of the device!

Apparently the man page for open is wrong:

Under Linux 2.4 transfer sizes, and the alignment of user buffer and file offset
must all be multiples of the logical block size of the file system. Under Linux
2.6 alignment to 512-byte boundaries suffices.


Comment 5 Zach Brown 2007-07-24 17:15:51 UTC
I asked around, and the man page does seem to be wrong.

The change from 2.4 wasn't to force 512B as a standard minimum alignment, but to
let the app operate at disk sector alignment instead of fs block alignment.  I
was confused and mislead Jeff.

So apps using O_DIRECT are, supposedly, expected to figure out the sector size
of the underlying block device and align accordingly.  The code seems to match
this, working with bdev_hardsect_size() when a block device for the inode is
available.

Comment 6 Jeff Moyer 2007-07-24 17:20:30 UTC
Thanks for the update, Zach.  Sorry to waste your time, Jan!

Comment 7 Jan Glauber 2007-07-25 09:21:25 UTC
We should update the man page, but I don't know how this could be done, maybe you
open a bugzilla against the man page :)

Comment 8 Jeff Moyer 2007-07-25 17:02:13 UTC
(In reply to comment #7)
> We should update the man page, but I don't know how this could be done, maybe you
> open a bugzilla against the man page :)

Actually, I don't see that verbiage in the read(2) or write(2) man pages on my
RHEL 5 system.  At which man page are you looking?

Comment 9 Jan Glauber 2007-07-27 19:41:18 UTC
its the open man page, man 2 open, look for O_DIRECT (format broke by paste):

O_DIRECT
Try to minimize cache effects of the I/O to and from this
file. In  general  this  will degrade performance, but it is useful
in special situations, such  as  when  applications  do  their
own caching.   File I/O is done directly to/from user space
buffers. The I/O is synchronous, i.e., at the completion of a read(2)
or write(2),  data  is  guaranteed to have been transferred.
Under Linux 2.4 transfer sizes, and the alignment of user  buffer
and file  offset  must all be multiples of the logical block size
of the file system. Under Linux 2.6 alignment  to  512-byte
bound-aries suffices.

The last sentence is wrong. For 2.6 the alignment must fit the block size
of the device.

Comment 16 errata-xmlrpc 2008-07-16 13:37:44 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2008-0587.html