From: Omar Sandoval <osandov@osandov.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org, kernel-team@fb.com,
David Sterba <dsterba@suse.com>, Jun Wu <quark@fb.com>
Subject: Re: [PATCH v2] Btrfs: fix error handling in btrfs_truncate()
Date: Tue, 22 May 2018 10:37:14 -0700 [thread overview]
Message-ID: <20180522173714.GB9536@vader> (raw)
In-Reply-To: <20180522171748.GY6649@twin.jikos.cz>
On Tue, May 22, 2018 at 07:17:48PM +0200, David Sterba wrote:
> On Tue, May 22, 2018 at 09:47:58AM -0700, Omar Sandoval wrote:
> > From: Omar Sandoval <osandov@fb.com>
> >
> > Jun Wu at Facebook reported that an internal service was seeing a return
> > value of 1 from ftruncate() on Btrfs in some cases.
>
> Do you have a reproducer? To estimate how likely is to hit the problem
> in practice.
This reproduces it every time when mounted with compress-force=zstd:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
int main() {
int i;
for (i = 0; i < 2; i++) {
char buf[256] = { 0 };
int fd, ret;
char *p;
fd = open("test", O_CREAT | O_WRONLY | O_TRUNC, 0666);
if (fd == -1) {
perror("open");
return EXIT_FAILURE;
}
if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
perror("write");
close(fd);
return EXIT_FAILURE;
}
close(fd);
fd = open("test", O_RDONLY, 0666);
if (fd == -1) {
perror("open");
return EXIT_FAILURE;
}
p = mmap(NULL, 256, PROT_READ, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
perror("mmap");
close(fd);
return EXIT_FAILURE;
}
if (p[0] != 0)
return 1;
close(fd);
fd = open("test", O_WRONLY, 0666);
if (fd == -1) {
perror("open");
return EXIT_FAILURE;
}
ret = ftruncate(fd, 128);
if (ret) {
printf("ftruncate() returned %d\n", ret);
close(fd);
return EXIT_FAILURE;
}
close(fd);
}
return EXIT_SUCCESS;
}
This happens any time NEED_TRUNCATE_BLOCK is returned. The file has to
be inline and compressed, and there's some other condition that I
haven't figured out yet which the mmap() is there for.
next prev parent reply other threads:[~2018-05-22 17:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 16:47 [PATCH v2] Btrfs: fix error handling in btrfs_truncate() Omar Sandoval
2018-05-22 17:17 ` David Sterba
2018-05-22 17:37 ` Omar Sandoval [this message]
2018-05-22 17:41 ` Omar Sandoval
2018-05-22 17:48 ` Omar Sandoval
2018-05-24 11:06 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180522173714.GB9536@vader \
--to=osandov@osandov.com \
--cc=dsterba@suse.com \
--cc=dsterba@suse.cz \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quark@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox