[Bug 288014] errors when copying sparse files to samba share

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 05 Jul 2025 00:30:59 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=288014

            Bug ID: 288014
           Summary: errors when copying sparse files to samba share
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: ports-bugs@FreeBSD.org
          Reporter: wrangletime@gmail.com

I am having issues with sparse/sparse adjacent files (created with qemu-img
create .../truncate) copied to or manipulated on samba server. This issue is
focusing on copy errors as I am working on isolating other issues.

FreeBSD server - freebsd-version -k & freebsd-version -u:
14.3-RELEASE
14.3-RELEASE-p1

samba420-4.20.7_6 is installed

client - debian 12 kernel 6.1.0-37-amd64

Steps to reproduce:
On Freebsd machine
1. pkg install samba420 from latest repo and not quarterly
2. pw useradd username -s /usr/sbin/nologin -w no
3. pw groupadd group
4. pw groupmod -n group -m username
5. smbpasswd -a user
6. modify /usr/local/etc/smb4.conf to be content at bottom of report
7. chown share path (/path/foo) to be username:group that is forced in the smb
config
8. service samba onerestart

On linux machine with GNU coreutils do the following:
1. mount -t cifs -o defaults,username=username,pass=<pass> //freebsd_ip/share
localdir
2. truncate foo --size=1G 
3. sudo cp -av --sparse=always foo localdir
4. cp gets error "error deallocating '<destination>': Input/output error"
Transferred file size is the same, hard to tell if file was manipulated since
truncate 0s output
5. sudo qemu-img create -o preallocation=full -f qcow2 dest.qcow2 1G (same
thing happens with falloc) 
6. sudo cp -av --sparse=always dest.qcow2 sambashare 
7. cp gets error "error deallocating '<destination>': Input/output error"
file gets truncated to 196K

This was tested when samba share path backing store was zfs or ufs2.

I don't get this error on a samba share hosted on Fedora 41 with an identical
samba configuration (storage is ext4). It was mounted on the same client I
mounted the FreeBSD share. Package version is samba-4.21.6-1.fc41.rpm.

For qemu-img preallocation option, I get no error when preallocation is set to
off or metadata. I'm not sure why falloc or full get errors, but, metadata
doesn't. The man page says this about the option which leads me to believe
falloc and full are making sparse files since similar error behavior to
truncate:
"preallocation
                 Preallocation mode (allowed values: off, metadata, falloc, 
full).
                 An  image  with  preallocated metadata is initially larger but
can
                 improve performance when the image needs to grow. falloc and 
full
                 preallocations  are  like the same options of raw format, but
sets
                 up metadata also."
and here is the snippet from the option for raw
"preallocation
                 Preallocation mode (allowed values: off,  falloc,  full).  
falloc
                 mode  preallocates  space  for image by calling
posix_fallocate().
                 full mode preallocates space for image by writing data to
underly‐
                 ing storage.  This data may or may not be zero, depending  on 
the
                 storage location." 


smb4.conf
[global]
        workgroup = SAMBA
        security = user

        client min protocol = SMB3
        smb encrypt = mandatory
        server signing = mandatory

        passdb backend = tdbsam

        socket options = TCP_NODELAY
        map to guest = Bad User
        smb3 unix extensions = yes

[share]
        path = /path/foo
        writeable = yes
        browseable = no
        public = no
        valid users = username
        create mask = 0770
        directory mask = 0770
        force group = group

-- 
You are receiving this mail because:
You are the assignee for the bug.