linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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:48:38 -0700	[thread overview]
Message-ID: <20180522174838.GD9536@vader> (raw)
In-Reply-To: <20180522174111.GC9536@vader>

On Tue, May 22, 2018 at 10:41:11AM -0700, Omar Sandoval wrote:
> On Tue, May 22, 2018 at 10:37:14AM -0700, Omar Sandoval wrote:
> > 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.

Okay last one, I promise, we just need the extent items to be on disk:

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {
	char buf[256] = { 0 };
	int ret;
	int fd;

	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;
	}

	if (fsync(fd) == -1) {
		perror("fsync");
		close(fd);
		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;
}

Basically, any time we truncate a compressed, inline file, as long as
its extents are already on disk, we get the erroneous return value.

  reply	other threads:[~2018-05-22 17:48 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
2018-05-22 17:41     ` Omar Sandoval
2018-05-22 17:48       ` Omar Sandoval [this message]
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=20180522174838.GD9536@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;
as well as URLs for NNTP newsgroup(s).