Failed to hardlink when --action=duplicate

Support for Ubuntu and other Desktop Linux distributions
Post Reply
queimadus
Posts: 5
Joined: 19 May 2019, 21:35

Failed to hardlink when --action=duplicate

Post by queimadus » 19 May 2019, 21:53

I think I may have found a bug when the action is set to duplicate and the underlying OS doesn't fully support for the first approach.

After digging through the code, I saw that when the action is set to "duplicate" it will try to "clone", if that fails fallback to "duplicate" and if that fails, fallback to "copy".

The "clone" option makes use of "cp --reflink" which apparently my OS does not support (Inappropriate ioctl for device). That alone logs an error but instead of fallbacking to "duplicate" it goes straight to a "copy". (I know duplicate works because that's how I fixed my setup, and it now correctly hardlinks files)

I didn't get much into why it skipped the second fallback, I think when the "cp --reflink" fails, it still creates an empty target file which may interfere with the duplicate fallback.

PS: Running "Linux vero 3.14.29-143-osmc #1 SMP osmc-ccachefix aarch64" while using the amc script

User avatar
rednoah
The Source
Posts: 16605
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Failed to hardlink when --action=duplicate

Post by rednoah » 20 May 2019, 08:06

Here's how it works:
1. Try clone / reflink
2. Try hardlink
3. Try copy

If clone doesn't work, then it will hardlink. If hardlink doesn't work, it will copy.

:idea: Debug logging will give you more information: viewtopic.php?f=3&t=3913

queimadus wrote:
19 May 2019, 21:53
I think when the "cp --reflink" fails, it still creates an empty target file which may interfere with the
Please confirm that cp --reflink indeed creates an empty target file. That would be pretty stupid cp behaviour. But if that's indeed the case, then I'll remove the clone attempt altogether.
:idea: Please read the FAQ and How to Request Help.

queimadus
Posts: 5
Joined: 19 May 2019, 21:35

Re: Failed to hardlink when --action=duplicate

Post by queimadus » 20 May 2019, 11:32

Seems like it does.

Code: Select all

[ [email protected] /tmp/test ]$ ls                                                                                                                                                                                                                                          
[ [email protected] /tmp/test ]$ echo hello > foo                                                                                                                                                                                                                            
[ [email protected] /tmp/test ]$ cp --reflink foo bar                                                                                                                                                                                                                        
cp: failed to clone 'bar' from 'foo': Inappropriate ioctl for device
[ [email protected] /tmp/test ]$ ls                                                                                                                                                                                                                                          
bar  foo
[ [email protected] /tmp/test ]$ cat bar                                                                                                                                                                                                                                     
[ [email protected] /tmp/test ]$ cat foo                                                                                                                                                                                                                                     
hello

User avatar
rednoah
The Source
Posts: 16605
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Failed to hardlink when --action=duplicate

Post by rednoah » 20 May 2019, 11:35

Noted. Will remove clone attempt from the duplicate action.
:idea: Please read the FAQ and How to Request Help.

User avatar
rednoah
The Source
Posts: 16605
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Failed to hardlink when --action=duplicate

Post by rednoah » 09 Aug 2019, 11:20

I've updated the code to:

Code: Select all

1. Try hardlink
2. Try clonefile (via cp -c) / reflink (cp --reflink=auto)
3. Try physical copy
:idea: To make sure we don't create empty files, 2. Try clonefile / reflink now uses cp --reflink=auto, so on Linux the cp call will implicitly take care of copying files if necessary.

:idea: @since r6569
:idea: Please read the FAQ and How to Request Help.

Post Reply