Bug 921708

Summary: Improve handling of cp --reflink=always when not supported by destination FS
Product: [Fedora] Fedora Reporter: Yann Droneaud <yann>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: admiller, kdudka, kzak, ovasik, p, twaugh
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: All   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-05-12 12:00:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
strace output of cp --reflink=always source dest none

Description Yann Droneaud 2013-03-14 18:08:45 UTC
Created attachment 710155 [details]
strace output of cp --reflink=always source dest

Description of problem:

$ stat source
  File: `source'
  Size: 172253    	Blocks: 344        IO Block: 4096   regular file
Device: fd02h/64770d	Inode: 1704360     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1002/ydroneaud)   Gid: ( 1002/ydroneaud)
Access: 2013-03-14 19:05:12.642541940 +0100
Modify: 2013-03-14 19:04:46.787541606 +0100
Change: 2013-03-14 19:04:46.787541606 +0100
 Birth: -

$ cp --reflink=always source dest
cp: failed to clone `dest' from `source': Inappropriate ioctl for device

$ stat dest
  File: `dest'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd02h/64770d	Inode: 1707547     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1002/ydroneaud)   Gid: ( 1002/ydroneaud)
Access: 2013-03-14 19:07:06.493543407 +0100
Modify: 2013-03-14 19:07:06.493543407 +0100
Change: 2013-03-14 19:07:06.493543407 +0100
 Birth: -


Expected results:

As reflink are not supported on Ext4 filesystem, cp --reflink=always is expected to fail, but it must not create the file, and it must not leave an empty file.

Comment 1 Yann Droneaud 2013-03-14 18:10:51 UTC
Comment on attachment 710155 [details]
strace output of cp --reflink=always source dest

MIME Type text/x-log => test/plain

Comment 2 Ondrej Vasik 2013-03-15 09:14:49 UTC
Thanks for the report and suggestion, but this is a bit tricky thing. It is quite common that cp behaves this way in the case of many failures requested by the user. As actual copy process consists from many steps, many such failures end up with an empty destination file. In many cases you don't know if you fail before the attempt, so there is no perfect solution. 

In this case, I can imagine a check if the reflink is supported by the destination filesystem (or generally by the system, as reflink always fail with ENOTSUP, when __linux__ is not defined). Then cp may exit with error earlier, before actually rewriting the destination file. Still, this is something for upstream discussion.

Comment 3 Pádraig Brady 2013-03-23 00:08:46 UTC
Some upstream notes on this:
http://lists.gnu.org/archive/html/coreutils/2013-03/msg00056.html

Comment 4 Kamil Dudka 2016-05-12 12:00:26 UTC
Based on the above response of coreutils upstream, closing WONTFIX.

Please reiterate the discussion on the upstream mailing-list if necessary.