Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cloning files on BTRFS read-only snapshots doesn't work #195

Closed
saintger opened this issue Oct 27, 2016 · 6 comments
Closed

cloning files on BTRFS read-only snapshots doesn't work #195

saintger opened this issue Oct 27, 2016 · 6 comments

Comments

@saintger
Copy link

Trying to deduplicate/clone files which are on BTRFS read-only snapshots, return an error:

ERROR: btrfs clone: failed to open dest file.

If it helps, duperemove has a special flag ("-A") to manage this situation:
https://github.com/markfasheh/duperemove/blob/master/filerec.c#L405-L434

@sahib
Copy link
Owner

sahib commented Oct 29, 2016

I guess you used a command like this?

$ rmlint -c sh:link subvol/

And tried to execute rmlint.sh afterwards?

$ ./rmlint.sh

If so, what would your expected behaviour be?
If not, which commands did you use exactly?

I see that the error message is not very nice, but, as I understand you, you're suggesting that
this message is silenced and becomes a no-op in case of readonly subvolumes?
(Sorry, hadn't time to look into duperemove yet)

@saintger
Copy link
Author

saintger commented Nov 1, 2016

Indeed I used this command line:

rmlint --config=sh:handler=clone subvolume subvolume_read_only

The rmlint "clone" command, should be able to operate on read-only snapshots and not giving an error, but perhaps with an option/flag to make sure that the user knows what he is doing (but cloning is quite safe, from what I understand).
Duperemove managed to deduplicate read-only snapshots without any problem.

@SeeSpotRun
Copy link
Collaborator

Thanks @saintger for finding this.

It doesn't seem well documented anywhere but here's what I found by trial-and-error and reference to markfasheh/duperemove@fe67b7c:

  • Read-only snapshots can only be opened read-only (makes sense)
  • To clone identical files in btrfs, the target must generally be opened for writing (makes sense)
  • However, the BTRFS_IOC_FILE_EXTENT_SAME ioctl will also work with a read-only target if called with elevated priveleges (sounds scary but is reasonable when you think it through).

Branch https://github.com/SeeSpotRun/rmlint/tree/btrfs-clone-readonly should be able to deduplicate read-only snapshots.
Usage for deduping a single file (source and dest must have same data; requires elevated priveleges):

$ sudo rmlint --btrfs-clone -r <source> <dest>

Usage via rmlint.sh:

$ rmlint --config=sh:handler=clone subvolume subvolume_read_only
$ ./rmlint.sh -r   # note: will ask for sudo password

@saintger
Copy link
Author

@SeeSpotRun Thanks it seems to work perfectly !

@sahib
Copy link
Owner

sahib commented Nov 10, 2016

I merged @SeeSpotRun's changes into the master branch.
This issue can probably be closed now, feel free to re-open if there are other problems.

@sahib sahib closed this as completed Nov 10, 2016
@SeeSpotRun
Copy link
Collaborator

Have updated docs to include --btrfs-clone [-r](probably breaks translations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants