]> www.infradead.org Git - users/jedix/linux-maple.git/commit
ext4: fix off-by-one on max nr_pages in ext4_find_unwritten_pgoff()
authorEryu Guan <eguan@redhat.com>
Wed, 24 May 2017 22:02:20 +0000 (18:02 -0400)
committerBrian Maly <brian.maly@oracle.com>
Wed, 13 Dec 2017 16:34:46 +0000 (11:34 -0500)
commit035a08ce5cb9309ca06bef4068808caae4dc35d1
treecf8576bb05862adb7deac07835534620ac2b5ff8
parent688b978c413ab49585d188c3c41bd178e7ecc302
ext4: fix off-by-one on max nr_pages in ext4_find_unwritten_pgoff()

Orabug: 27255674

ext4_find_unwritten_pgoff() is used to search for offset of hole or
data in page range [index, end] (both inclusive), and the max number
of pages to search should be at least one, if end == index.
Otherwise the only page is missed and no hole or data is found,
which is not correct.

When block size is smaller than page size, this can be demonstrated
by preallocating a file with size smaller than page size and writing
data to the last block. E.g. run this xfs_io command on a 1k block
size ext4 on x86_64 host.

  # xfs_io -fc "falloc 0 3k" -c "pwrite 2k 1k" \
       -c "seek -d 0" /mnt/ext4/testfile
  wrote 1024/1024 bytes at offset 2048
  1 KiB, 1 ops; 0.0000 sec (42.459 MiB/sec and 43478.2609 ops/sec)
  Whence  Result
  DATA    EOF

Data at offset 2k was missed, and lseek(2) returned ENXIO.

This is unconvered by generic/285 subtest 07 and 08 on ppc64 host,
where pagesize is 64k. Because a recent change to generic/285
reduced the preallocated file size to smaller than 64k.

Signed-off-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>
(cherry picked from commit 624327f8794704c5066b11a52f9da6a09dce7f9a)
Signed-off-by: Brian Maly <brian.maly@oracle.com>
Reviewed-by: Kirtikar Kashyap <kirtikar.kashyap@oracle.com>
fs/ext4/file.c