linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] Reflinking fails for files >2GB on 32-bit platform
@ 2013-10-16  7:51 Christian Weinberger
  0 siblings, 0 replies; only message in thread
From: Christian Weinberger @ 2013-10-16  7:51 UTC (permalink / raw)
  To: linux-btrfs

I want to make you aware of a possible bug in the reflink handling of btrfs:

When I reflink a file larger 2GB (on the same subvol), the reflinking
fails. But it works fine for files smaller 2GB in size.

I was able to track this down to btrfs with great support of Martin
Raiber who created a small demo code:
Source: https://urbackup.atlassian.net/secure/attachment/10201/reflink.cpp
Compile: g++ reflink.cpp -o reflink
Usage: reflink source-file destination-file

Works if source-file is smaller 2GB and errors otherwise.

Environment:
Debian Wheezy 7.2 i386 --> 32 bit
Kernel: 3.10.11-1~bpo70+1 (most recent from wheezy backports rep)

Anything missing? I´m happy to provide additional input!

====snip===demo program source=======

#include <iostream>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>

bool os_create_reflink(const char* linkname, const char* fname)
{
  int src_desc=open(fname, O_RDONLY);
  if( src_desc<0)
  return false;

  int dst_desc=open(linkname, O_WRONLY | O_CREAT | O_EXCL, S_IRWXU | S_IRWXG);
  if( dst_desc<0 )
  {
  close(src_desc);
  return false;
  }

  #define BTRFS_IOCTL_MAGIC 0x94
  #define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int)

  int rc=ioctl(dst_desc, BTRFS_IOC_CLONE, src_desc);

  close(src_desc);
  close(dst_desc);

  return rc==0;
}

int main(int argc, char* argv[])
{
  if(argc<3)
  {
    std::cout << "not enough arguments: reflink [source file] [dest file]" << std::endl;
    return 1;
  }
  
  if(!os_create_reflink(argv[2], argv[1]))
  {
     perror("reflink");
     return 2;
  }
  
  return 0;
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-10-16  8:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-16  7:51 [BUG] Reflinking fails for files >2GB on 32-bit platform Christian Weinberger

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).