public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* FIDEDUPERANGE and compression
@ 2022-02-19  3:14 ov 2k
  2022-02-21  6:37 ` Zygo Blaxell
  0 siblings, 1 reply; 6+ messages in thread
From: ov 2k @ 2022-02-19  3:14 UTC (permalink / raw)
  To: linux-btrfs

[-- Attachment #1: Type: text/plain, Size: 757 bytes --]

FIDEDUPERANGE does not seem to behave as expected with compressible
data on a btrfs volume with compression enabled, at least with small
adjacent FIDEDUPERANGE requests.  I've attached a basic test case.  It
writes two short identical files and calls FIDEDUPERANGE three times,
on the thirds of the file, in order.  filefrag -v reports that the
destination file has three extents that each reference the first third
of the source file.

To be clear, the data in the destination file remains correct.
However, the second and third FIDEDUPERANGE calls do not seem to cause
the destination file to reference the expected source extents.  I'm
not actually certain whether this is a bug in FIDEDUPERANGE or
FS_IOC_FIEMAP or something deeper within btrfs itself.

[-- Attachment #2: test.c --]
[-- Type: text/x-c-code, Size: 990 bytes --]

#include <linux/fs.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/statvfs.h>
#include <unistd.h>

int main(int argc, char **argv) {
	FILE *src;
	FILE *dest;
	struct statvfs vfsstats;
	unsigned long bsize;
	size_t size;
	struct file_dedupe_range *fdr;

	src = fopen("src", "w+");
	dest = fopen("dest", "w+");

	fstatvfs(fileno(src), &vfsstats);
	bsize = vfsstats.f_bsize;
	for(size_t i = 0; i < bsize * 2; i++) {
		fprintf(src, "%s", "foo");
		fprintf(dest, "%s", "foo");
	}

	fflush(src);
	fsync(fileno(src));
	fflush(dest);
	fsync(fileno(dest));

	size = sizeof (struct file_dedupe_range);
	size += sizeof (struct file_dedupe_range_info);
	fdr = calloc(1, size);
	fdr->src_length = 2 * bsize;
	fdr->dest_count = 1;
	fdr->info[0].dest_fd = fileno(dest);

	for(size_t i = 0; i < 3; i++) {
		ioctl(fileno(src), FIDEDUPERANGE, fdr);
		fdr->src_offset += 2 * bsize;
		fdr->info[0].dest_offset += 2 * bsize;
	}

	fflush(dest);
	fsync(fileno(dest));

	return 0;
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-12  2:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-19  3:14 FIDEDUPERANGE and compression ov 2k
2022-02-21  6:37 ` Zygo Blaxell
2022-02-21 22:31   ` ov2k
2022-03-06  4:44     ` Zygo Blaxell
2022-03-09 20:04       ` ov2k
2022-03-12  2:47         ` Zygo Blaxell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox