Hi. I just reproduced a problem I was chasing on FreeBSD also on OpenSolaris from around 2008.01. Simply doing something like this: write 9k of random data into ''foo'' file truncate ''foo'' file to 7k truncate ''foo'' file to 11k read data between 7k-9k There should be all zeros between 7k-9k, but there is previous data. It worked fine on an older ZFS versions (I''m sure it works on version 6). Simple test program: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <err.h> static char buf0[9 * 1024], buf1[2 * 1024]; int main(int argc, char *argv[]) { int fd, i; if (argc != 2) errx(1, "usage: trunctest <filename>"); fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd == -1) err(1, "open(%s)", argv[1]); memset(buf0, ''x'', sizeof(buf0)); if (write(fd, buf0, sizeof(buf0)) != sizeof(buf0)) err(1, "write()"); if (ftruncate(fd, 7 * 1024) == -1) err(1, "ftruncate(%d)", 7 * 1024); if (ftruncate(fd, 11 * 1024) == -1) err(1, "ftruncate(%d)", 11 * 1024); if (pread(fd, buf1, sizeof(buf1), 7 * 1024) != sizeof(buf1)) err(1, "pread()"); for (i = 0; i < sizeof(buf1); i++) { if (buf1[i] != ''\0'') errx(2, "unexpected data at %jd!", (intmax_t)(7 * 1024 + i)); } exit(0); } -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080722/002a0bdc/attachment.bin>
On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote:> Hi. > > I just reproduced a problem I was chasing on FreeBSD also on > OpenSolaris from around 2008.01. > > Simply doing something like this: > > write 9k of random data into ''foo'' file > truncate ''foo'' file to 7k > truncate ''foo'' file to 11k > read data between 7k-9k > > There should be all zeros between 7k-9k, but there is previous data. > It worked fine on an older ZFS versions (I''m sure it works on version 6). > > Simple test program:[...] There was a missing #include: #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <err.h> static char buf0[9 * 1024], buf1[2 * 1024]; int main(int argc, char *argv[]) { int fd, i; if (argc != 2) errx(1, "usage: trunctest <filename>"); fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd == -1) err(1, "open(%s)", argv[1]); memset(buf0, ''x'', sizeof(buf0)); if (write(fd, buf0, sizeof(buf0)) != sizeof(buf0)) err(1, "write()"); if (ftruncate(fd, 7 * 1024) == -1) err(1, "ftruncate(%d)", 7 * 1024); if (ftruncate(fd, 11 * 1024) == -1) err(1, "ftruncate(%d)", 11 * 1024); if (pread(fd, buf1, sizeof(buf1), 7 * 1024) != sizeof(buf1)) err(1, "pread()"); for (i = 0; i < sizeof(buf1); i++) { if (buf1[i] != ''\0'') errx(2, "unexpected data at %jd!", (intmax_t)(7 * 1024 + i)); } exit(0); } -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080722/80aa0207/attachment.bin>
Pawel Jakub Dawidek wrote:> On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote: >> Hi. >> >> I just reproduced a problem I was chasing on FreeBSD also on >> OpenSolaris from around 2008.01. >> >> Simply doing something like this: >> >> write 9k of random data into ''foo'' file >> truncate ''foo'' file to 7k >> truncate ''foo'' file to 11k >> read data between 7k-9k >> >> There should be all zeros between 7k-9k, but there is previous data. >> It worked fine on an older ZFS versions (I''m sure it works on version 6). >> >> Simple test program: > [...] >Thanks for reporting this. I''ve opened bug: 6728399 ftruncate(2) broken on ZFS -Mark
On Tue, Jul 22, 2008 at 08:56:31AM -0600, Mark Shellenbaum wrote:> Pawel Jakub Dawidek wrote: > >On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote: > >>Hi. > >> > >>I just reproduced a problem I was chasing on FreeBSD also on > >>OpenSolaris from around 2008.01. > >> > >>Simply doing something like this: > >> > >> write 9k of random data into ''foo'' file > >> truncate ''foo'' file to 7k > >> truncate ''foo'' file to 11k > >> read data between 7k-9k > >> > >>There should be all zeros between 7k-9k, but there is previous data. > >>It worked fine on an older ZFS versions (I''m sure it works on version 6). > >> > >>Simple test program: > >[...] > > > > Thanks for reporting this. > > I''ve opened bug: > > 6728399 ftruncate(2) broken on ZFSActually it''s not only ftruncate(2), but also truncate(2). I even tried to export&import between each step and I still saw corruption. -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080722/9a347d57/attachment.bin>
On Tue, Jul 22, 2008 at 05:06:21PM +0200, Pawel Jakub Dawidek wrote:> On Tue, Jul 22, 2008 at 08:56:31AM -0600, Mark Shellenbaum wrote: > > Pawel Jakub Dawidek wrote: > > >On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote: > > >>Hi. > > >> > > >>I just reproduced a problem I was chasing on FreeBSD also on > > >>OpenSolaris from around 2008.01. > > >> > > >>Simply doing something like this: > > >> > > >> write 9k of random data into ''foo'' file > > >> truncate ''foo'' file to 7k > > >> truncate ''foo'' file to 11k > > >> read data between 7k-9k > > >> > > >>There should be all zeros between 7k-9k, but there is previous data. > > >>It worked fine on an older ZFS versions (I''m sure it works on version 6). > > >> > > >>Simple test program: > > >[...] > > > > > > > Thanks for reporting this. > > > > I''ve opened bug: > > > > 6728399 ftruncate(2) broken on ZFS > > Actually it''s not only ftruncate(2), but also truncate(2). I even tried > to export&import between each step and I still saw corruption.One more note, might be important. We checked this on FreeBSD/ZFS/amd64 and we don''t see corruption, although I see corruption on FreeBSD/ZFS/i386 and OpenSolaris/ZFS/i386. -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080722/ff456c7d/attachment.bin>
On Tue, Jul 22, 2008 at 08:56:31AM -0600, Mark Shellenbaum wrote:> Pawel Jakub Dawidek wrote: > >On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote: > >>Hi. > >> > >>I just reproduced a problem I was chasing on FreeBSD also on > >>OpenSolaris from around 2008.01. > >> > >>Simply doing something like this: > >> > >> write 9k of random data into ''foo'' file > >> truncate ''foo'' file to 7k > >> truncate ''foo'' file to 11k > >> read data between 7k-9k > >> > >>There should be all zeros between 7k-9k, but there is previous data. > >>It worked fine on an older ZFS versions (I''m sure it works on version 6). > >> > >>Simple test program: > >[...] > > > > Thanks for reporting this. > > I''ve opened bug: > > 6728399 ftruncate(2) broken on ZFSI went a bit further trying to find out what''s going on. This is the change responsible for the problem: 20c04e18c58cfb135a135c0126c7d69f6078e1b5. In the dnode_free_range() function you can find this condition: [...] } else if (off > blkid) { /* Freeing past end-of-data */ goto out; [...] Unfortunately blkid is uninitialized at this point, so it can''t be right. I tried to change it to ''blksz'', but it panics further. I hope this helps. This is one of the last issues that holds back integration of the most recent ZFS into FreeBSD tree, so we would be very grateful if you guys could look into this. Thanks in advance! -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080816/6c85c5c5/attachment.bin>
This fix for this bug is currently in test and will be pushed shortly. -Mark Pawel Jakub Dawidek wrote:> On Tue, Jul 22, 2008 at 08:56:31AM -0600, Mark Shellenbaum wrote: >> Pawel Jakub Dawidek wrote: >>> On Tue, Jul 22, 2008 at 04:28:45PM +0200, Pawel Jakub Dawidek wrote: >>>> Hi. >>>> >>>> I just reproduced a problem I was chasing on FreeBSD also on >>>> OpenSolaris from around 2008.01. >>>> >>>> Simply doing something like this: >>>> >>>> write 9k of random data into ''foo'' file >>>> truncate ''foo'' file to 7k >>>> truncate ''foo'' file to 11k >>>> read data between 7k-9k >>>> >>>> There should be all zeros between 7k-9k, but there is previous data. >>>> It worked fine on an older ZFS versions (I''m sure it works on version 6). >>>> >>>> Simple test program: >>> [...] >>> >> Thanks for reporting this. >> >> I''ve opened bug: >> >> 6728399 ftruncate(2) broken on ZFS > > I went a bit further trying to find out what''s going on. This is the > change responsible for the problem: 20c04e18c58cfb135a135c0126c7d69f6078e1b5. > > In the dnode_free_range() function you can find this condition: > > [...] > } else if (off > blkid) { > /* Freeing past end-of-data */ > goto out; > [...] > > Unfortunately blkid is uninitialized at this point, so it can''t be > right. I tried to change it to ''blksz'', but it panics further. > > I hope this helps. This is one of the last issues that holds back > integration of the most recent ZFS into FreeBSD tree, so we would be > very grateful if you guys could look into this. > > Thanks in advance! >
On Sat, Aug 16, 2008 at 08:33:53AM -0600, Mark Maybee wrote:> This fix for this bug is currently in test and will be pushed shortly.Good to hear that, thanks! -- Pawel Jakub Dawidek http://www.wheel.pl pjd at FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 187 bytes Desc: not available URL: <http://mail.opensolaris.org/pipermail/zfs-code/attachments/20080816/c0e2d99e/attachment.bin>