linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Weinberger <christian.weinberger@t-online.de>
To: linux-btrfs@vger.kernel.org
Subject: [BUG] Reflinking fails for files >2GB on 32-bit platform
Date: Wed, 16 Oct 2013 09:51:11 +0200	[thread overview]
Message-ID: <525E456F.1070601@weinberger.in> (raw)

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



                 reply	other threads:[~2013-10-16  8:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=525E456F.1070601@weinberger.in \
    --to=christian.weinberger@t-online.de \
    --cc=linux-btrfs@vger.kernel.org \
    /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).