fallocate behavior when crossing end-of-file
Hello.
I found the following bug in BtrFS:
1. Create and open an empty file
2. fallocate (fd, 0, 1)
Desired: something (probably, one block) is allocated/reserved for the file. File length is set to 1 byte.
Actual: A block is allocated. File length is set to 1 block (4096 bytes). The rest of the file is filled with zeros.
last_byte = min(extent_map_end(em), alloc_end);
last_byte = (last_byte + mask) & ~mask;
if (em->block_start == EXTENT_MAP_HOLE) {
ret = prealloc_file_range(trans, inode, cur_offset,
last_byte, locked_end + 1,
alloc_hint, mode);That part seems strange to me. You make an effort for block size to divide last_byte. But last_byte should be max(i_size_read(inode), offset+len)
- without any rounding.
Michael Raskin
Quoted 2 lines · Raskin Michael
Hello.
Hello.
Quoted 8 lines
I found the following bug in BtrFS:
1. Create and open an empty file
2. fallocate (fd, 0, 1)Desired: something (probably, one block) is allocated/reserved for the file. File length is set to 1 byte.
Where is it documented?
IMHO we should only guarantee that writes
to [0, 1] won't fail because of lack of disk space. Other things (including file size) are up to implementation.
Quoted 22 lines
Actual: A block is allocated. File length is set to 1 block (4096 bytes). The rest of the file is filled with zeros.
last_byte = min(extent_map_end(em), alloc_end); last_byte = (last_byte + mask) & ~mask; if (em->block_start == EXTENT_MAP_HOLE) { ret = prealloc_file_range(trans, inode, cur_offset, last_byte, locked_end + 1, alloc_hint, mode);That part seems strange to me. You make an effort for block size to divide
last_byte. Butlast_byteshould bemax(i_size_read(inode), offset+len)
- without any rounding.Michael Raskin
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 15 lines · Edward Shishkin
Quoted 2 lines · Raskin Michael
Hello.
Hello.
Quoted 8 lines
I found the following bug in BtrFS:
1. Create and open an empty file
2. fallocate (fd, 0, 1)Desired: something (probably, one block) is allocated/reserved for the file. File length is set to 1 byte.
Quoted 6 lines
Where is it documented?
IMHO we should only guarantee that writes
to [0, 1] won't fail because of lack of disk space. Other things (including file size) are up to implementation.
This one looks like a pretty simple bug in the fallocate call. It is rounding up the size to a block boundary.
-chris
Quoted 27 lines
Quoted 15 lines
Actual: A block is allocated. File length is set to 1 block (4096 bytes). The rest of the file is filled with zeros.
last_byte = min(extent_map_end(em), alloc_end); last_byte = (last_byte + mask) & ~mask; if (em->block_start == EXTENT_MAP_HOLE) { ret = prealloc_file_range(trans, inode, cur_offset, last_byte, locked_end + 1, alloc_hint, mode);That part seems strange to me. You make an effort for block size to divide
last_byte. Butlast_byteshould bemax(i_size_read(inode), offset+len)
- without any rounding.Quoted 7 lines
Michael Raskin
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 8 lines · Edward Shishkin
Quoted 2 lines
Desired: something (probably, one block) is allocated/reserved for the file. File length is set to 1 byte.
Where is it documented?
IMHO we should only guarantee that writes
to [0, 1] won't fail because of lack of disk space. Other things (including file size) are up to implementation.
POSIX, SUS.
http://www.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
<<<
If the offset+ len is beyond the current file size, then posix_fallocate() shall adjust the file size to offset+ len. Otherwise, the file size shall not be changed.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Michael Raskin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iQEcBAEBAgAGBQJKAajDAAoJEE6tnN0aWvw3umYH/Rhcs2m4UosPLOsSylVAiFiB rRJbeYWX5xaw9wTCV7RW3BkAEM2gJ5De10j4x7g81L7GZQZNz3Pwu6WN+kQOrBnG gSeCg7u5OpvJUrX6HxeJEeUOCg9VDzuTNyEWY3pUEo7L00MLuYqTQimg2pua3oAv Ib7bUWVfRguxgQVO7pnw//CV6L+KBY7OP2za+c2x+Ec+KN0QsgAlYATxNP9+hI4o VJL7nIGoAs5rZXkLuDJpQYgI2sl6yzZy1Jq0Q3+UnjDDLlU945yMQm4LGTEMMHJX i/Ci58y+SNhiDFrPrW1nRCZXE0RiEk01hGTtVVI2yfZJz/dabZAtSgEbyp0k0/c= =6Fmf
-----END PGP SIGNATURE-----
Quoted 16 lines · Michael Raskin
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1Quoted 10 lines · Edward Shishkin
Quoted 3 lines
Desired: something (probably, one block) is allocated/reserved for the file. File length is set to 1 byte.
Where is it documented?
IMHO we should only guarantee that writes
to [0, 1] won't fail because of lack of disk space. Other things (including file size) are up to implementation.
Quoted 9 lines
POSIX, SUS.
http://www.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
<<<
If the offset+ len is beyond the current file size, thenposix_fallocate()shall adjust the file size to offset+ len. Otherwise, the file size shall not be changed.
fallocate (2) is something different from posix_fallocate:
"...This default behavior closely resembles the behavior of the posix_fallocate(3) library function, and is intended as a method of optimally implementing that function."
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 11 lines · Edward Shishkin
Quoted 5 lines
<<<
If the offset+ len is beyond the current file size, thenposix_fallocate()shall adjust the file size to offset+ len. Otherwise, the file size shall not be changed.fallocate (2) is something different from
posix_fallocate:"...This default behavior closely resembles the behavior of the
posix_fallocate(3)library function, and is intended as a method of optimally implementing that function."
If you overincrement file size counter, the only way for glibc to correctly implement is to ftruncate after fallocate . It doesn't look like an optimal implementation of posix_fallocate (2 system calls). It also doesn't look like something glibc would do. It currently doesn't.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iQEcBAEBAgAGBQJKAfwBAAoJEE6tnN0aWvw3NQAH/2XFOZE/9MBAxySxOyNY9Gft ttotQ4+g7SuKX47tQzskcWde3qbofEYzrsF/ADebjczEwbiKcZaJwlLzqL1X6siC IWzBS8hIWbbKkyF2erQJP3QZEJq/IwRCK6bOj8EJckGJ6q6tLCIasXGs+GOAjhrB 1NWjDfprXP5M4s1xvG9KRH4Lo38Bz4/5w7ZGqGuXOy+M21ZHim+o9Tbkp7LaV9KP OHqxgXV6tpHHv+Ai16cR1cJzY8XAIZ6EsL4lfpw7nZGlgRC+snccNdyoN3MltFOG fbqIxrcPb8jL+3sAY+F1EK9oOKrCjQhY8VKxksy++M8+uP7OmgRiRkPyNewbYlw= =fY9t
-----END PGP SIGNATURE-----