[BUG] Reflinking fails for files >2GB on 32-bit platform

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux