Bug 10883 - Samba server does not update ctime (SMB or SMB3 last change time) on hardlinks
Summary: Samba server does not update ctime (SMB or SMB3 last change time) on hardlinks
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: 4.2.0rc2
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-17 21:57 UTC by Steve French
Modified: 2024-04-28 21:08 UTC (History)
1 user (show)

See Also:


Attachments
wireshark trace showing samba not updating change time on hardlinks but showing windows is updating change time (16.22 KB, application/x-pcapng)
2014-10-17 22:02 UTC, Steve French
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve French 2014-10-17 21:57:44 UTC
Samba does not update ctime (last Change time) on either CIFS or SMB3 when creating a hard link while Windows servers do (and obviously Linux local file systems too).  It works with POSIX Extensions but not with CIFS or SMB3 to Samba. Following is output from a simple demonstration (/mnt is a cifs mount to Samba, /mnt1 is a cifs mount to Windows 8.1).

root@ubuntu:~/cifs-2.6# touch /mnt/file1
root@ubuntu:~/cifs-2.6# touch /mnt1/file1
root@ubuntu:~/cifs-2.6# stat /mnt/file1 ; ln /mnt/file1 /mnt/file2
  File: ‘/mnt/file1’
  Size: 0         	Blocks: 0          IO Block: 16384  regular empty file
Device: 1dh/29d	Inode: 395051      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-10-17 16:33:59.538897300 -0500
Modify: 2014-10-17 16:33:59.538897300 -0500
Change: 2014-10-17 16:33:59.538897300 -0500
 Birth: -
root@ubuntu:~/cifs-2.6# stat /mnt/file2
  File: ‘/mnt/file2’
  Size: 0         	Blocks: 0          IO Block: 16384  regular empty file
Device: 1dh/29d	Inode: 395051      Links: 2
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-10-17 16:33:59.538897300 -0500
Modify: 2014-10-17 16:33:59.538897300 -0500
Change: 2014-10-17 16:33:59.538897300 -0500
 Birth: -

/* NOTE ctime HAS NOT CHANGED LIKE IT SHOULD */

/* Now repeat experiment to Windows 8.1 */

root@ubuntu:~/cifs-2.6# stat /mnt1/file1 ; ln /mnt1/file1 /mnt1/file2
  File: ‘/mnt1/file1’
  Size: 0         	Blocks: 0          IO Block: 16384  regular empty file
Device: 1eh/30d	Inode: 2251799813699648  Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-10-17 16:34:02.982897300 -0500
Modify: 2014-10-17 16:34:02.982897300 -0500
Change: 2014-10-17 16:34:02.982897300 -0500
 Birth: -
root@ubuntu:~/cifs-2.6# stat /mnt1/file2
  File: ‘/mnt1/file2’
  Size: 0         	Blocks: 0          IO Block: 16384  regular empty file
Device: 1eh/30d	Inode: 2251799813699648  Links: 2
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-10-17 16:34:02.982897300 -0500
Modify: 2014-10-17 16:34:02.982897300 -0500
Change: 2014-10-17 16:38:28.726949400 -0500  /* NOTE ctime HAS CHANGED */
 Birth: -
Comment 1 Steve French 2014-10-17 22:02:28 UTC
Created attachment 10355 [details]
wireshark trace showing samba not updating change time on hardlinks but showing windows is updating change time

127.0.0.1 target is samba server (4.1 server, but also fails to 4.2-rc2)
(note 


192.168.93.159 target is Windows 8.1 server

Compare frame 45 (bad change time) to frame 83 (change time updated)
Comment 2 Steve French 2014-10-17 22:03:41 UTC
Note that this was discovered with xfstests generic/236 running on SMB3 Linux mount
Comment 3 Anubhav Rakshit 2015-07-08 09:37:19 UTC
Looks like this is XFS specific. Hardlink creation and updation of ctime works fine with ext4 for me.

====
anubhav@citadel:~$ stat notes.txt
  File: `notes.txt'
  Size: 11456           Blocks: 24         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 9706103     Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/ anubhav)   Gid: ( 1000/ anubhav)
Access: 2015-06-18 17:08:18.655020928 +0530
Modify: 2014-06-25 20:09:58.594835586 +0530
Change: 2014-06-25 20:09:58.648784072 +0530

smb: \> hardlink notes.txt notes1.txt

anubhav@citadel:~$ stat notes1.txt
  File: `notes1.txt'
  Size: 11456           Blocks: 24         IO Block: 4096   regular file
Device: 801h/2049d      Inode: 9706103     Links: 2
Access: (0644/-rw-r--r--)  Uid: ( 1000/ anubhav)   Gid: ( 1000/ anubhav)
Access: 2015-06-18 17:08:18.655020928 +0530
Modify: 2014-06-25 20:09:58.594835586 +0530
Change: 2015-07-08 14:59:03.383769118 +0530

anubhav@citadel:~$ sudo blkid /dev/sda1 
/dev/sda1: UUID="16a10327-c4ba-4a36-866d-d67a775fcb57" TYPE="ext4"

anubhav@citadel:~$ /usr/local/samba/sbin/smbd -V
Version 4.3.0pre1-GIT-e3373e9
====
Comment 4 Steve French 2024-04-28 19:32:48 UTC
It also fails on ext4 (at least with current Samba Version 4.21.0pre1-GIT-73e3ffb8418 and Samba 4.18 as well)

Just tried it to ext4 mount as well (see below, remove vs. local - local reports the ctime correctly, ie updated after hardlink, but Samba remotes it wrong)

root@smfrench-ThinkPad-P52:/shares/test# stat /mnt1/smallfile
  File: /mnt1/smallfile
  Size: 10        	Blocks: 8          IO Block: 1048576 regular file
Device: 0,72	Inode: 1831427     Links: 2
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2024-04-28 14:25:57.615181400 -0500
Modify: 2024-04-28 14:25:57.615181400 -0500
Change: 2024-04-28 14:25:57.615181400 -0500
 Birth: 2024-04-28 14:25:57.602181400 -0500
root@smfrench-ThinkPad-P52:/shares/test# stat /boot/tmpshare/smallfile 
  File: /boot/tmpshare/smallfile
  Size: 10        	Blocks: 8          IO Block: 4096   regular file
Device: 259,3	Inode: 1831427     Links: 2
Access: (0766/-rwxrw-rw-)  Uid: (65534/  nobody)   Gid: (65534/ nogroup)
Access: 2024-04-28 14:25:57.602181433 -0500
Modify: 2024-04-28 14:25:57.615181400 -0500
Change: 2024-04-28 14:27:14.942326150 -0500
 Birth: 2024-04-28 14:25:57.602181433 -0500

I also verified it is broken for Samba over XFS and btrfs.

The reproduction scenario is trivial:
1) mount to Samba from Linux
2) do "ln /mnt1/target /mnt1/sysmlinktotarget"
3) stat /mnt1/target   and you will see ctime was not updated when hardlink created (but this works fine to Windows, ksmbd and other servers).  ctime reported locally on the Samba server does show ctime updated
Comment 5 Steve French 2024-04-28 19:36:34 UTC
The only way I can see to get this to work is to mount with "posix" on the Linux client - and then the server reports ctime correctly.   Note that Windows updates ctime when new hardlink created, so Samba server should be as well, with or without posix extensions.
Comment 6 Michael Tokarev 2024-04-28 21:08:35 UTC
This does not look like samba issue at all.  More, it is filesystem-specific, - some filesystems change ctime when creating hardlink, some don't.  Samba definitely should not do anything extra besides link(2).