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
Woul you test with 4.22.3? https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287985
I didn't realize samba420-4.20.7_7 was released when I made this bug report. I retested with that version and the issue still persists. I am in the process of testing the above referenced 4.22.3 patches.
Does 4.19 work?
(In reply to Michael Osipov from comment #3) I still experience the issue with 4.16 and 4.19.
(In reply to Andrej Ebert from comment #1) I tested with the patches and I still get the same error. However I am not sure all dependencies were updated or if I executed the build process correctly for the updated patches. This is what I did up to and including testing in net/samba420: 1. make DISABLE_VULNERABILITIES=yes BATCH=yes install //on commit d72e68a22b9ebe1380a180ffdcf92ffec9e46ad7 to make sure it would build correctly in first place 2. service samba_server onerestart 3. reproduced issue 4. git apply am 4.22.3_patch //ran this at port tree root 5. make DISABLE_VULNERABILITIES=yes BATCH=yes install //didn't output anything 6. make clean //showed it was cleaning all dependencies 7. make DISABLE_VULNERABILITIES=yes BATCH=yes install //errored b/c already installed 8. make deinstall 9. make DISABLE_VULNERABILITIES=yes BATCH=yes install //took significantly less time than the initial build 10. service samba_server onerestart 11. reproduced issue
I wasn't building in net/samba422, please stand by...
(In reply to Andrej Ebert from comment #1) I tested with 4.22.3 and updated dependencies, but I still experience the issue.
(In reply to hunt from comment #7) That's a shame, would be too easy, I guess. Despite this being FreeBSD-specific, I don't think it's a downstream problem. You should take it upstream (https://bugzilla.samba.org/), with log level = 10 logs, maybe they'll have an idea. Of course you could upload the logs here too, maybe we'll see something.
(In reply to Andrej Ebert from comment #8) I have doubts this is an upstream issue as I don't experience this issue connected to a 4.21.6 or 4.20.8 samba share hosted on linux. When I have time I'll submit logs here and to the samba mailing list for the 4.22.3 release.
Created attachment 262219 [details] smbd log level 10 one sparse file copy Here are log level 10 logs of copying 1 1G sparse file with cp --sparse=always.
Created attachment 262220 [details] smbd log level 10 one sparse file copy linux 4.20.8 Sparse file copy linux 4.20.8 instance.
So I think I found the problem: [2025/07/16 07:45:20.268817, 2, pid=33508, effective(901, 1003), real(0, 0), class=smb2] ../../source3/smbd/smb2_ioctl_filesys.c:485(fsctl_zero_data) zero-data fallocate(0x3) failed: Function not implemented Then I went down a rabbit hole about fallocate(Linux-specific) and posix_fallocate. Support for it was removed a while ago in ZFS: https://lists.freebsd.org/pipermail/freebsd-fs/2017-November/025508.html Samba apparently uses posix_fallocate, but maybe doesn't handle the EINVAL from ZFS gracefully? Acording to https://reviews.llvm.org/D115957 posix_fallocate is counterproductive on ZFS _and_ UFS on FreeBSD. I'm trying to patch the port to build with -DHAVE_POSIX_FALLOCATE=0, to see how it will behave in your setup, but no sucess so far.
(In reply to Andrej Ebert from comment #12) My huge respect for going down the rabbit hole.
Created attachment 262242 [details] Disable posix_fallocate for FreeBSD Please try the attached patch, it disables posix_fallocate for FreeBSD, it would be interesting how samba behaves in your setup.
(In reply to hunt from comment #9) Please try the attached patch disabling posix_fallocate. And it definitely is an upstream issue, just FreeBSD-specific. Samba should fallback to just writing blocks if something doesn't work with posix_fallocate, but doesn't do that. Aside from this, preallocating space for sparse files just doesn't make sense on ZFS(this is what fallocate does), and apparently is horribly slow on UFS.
Created attachment 262258 [details] log after patch I still reproduced the issue. I am not sure if I applied the patch correctly. In net/samba4.22 I ran make deinstall, copied the patch to the files directory, and ran make DISABLE_VULNERABILITIES=yes BATCH=yes install and then ran service samba_server onerestart.
(In reply to hunt from comment #16) I think you missed a "make clean" and installed the previuosly built files, since I still see a "HAVE_POSIX_FALLOCATE" in the log. Something like this: 1. Copy the patch to the "files" folder under net/samba422 2. in net/samba422 run "make clean" (or just delete the "work" dir) 3. run make deinstall reinstall clean (you shouldn't need DISABLE_VULNERABILITIES=yes and BATCH=yes, but it doesn't hurt)
(In reply to Andrej Ebert from comment #17) I did run make clean the first time, but I missed putting that in the message. On a new attempt I made sure the patch was in the files directory, ran make clean again, and made sure the work dir was gone and ran make deinstall reinstall clean DISABLE_VULNERABILITIES=yes BATCH=yes and. I still get the error deallocating error. I did see during the configure step it just outputted the following for posix_fallocate: Checking for posix_fallocate-capable libc : ok Checking for posix_fallocate : ok
(In reply to hunt from comment #18) and I also onestopped samba_server after the install from make was completed before starting it again to test.
(In reply to hunt from comment #19) Could you check the following: smbd -b | grep HAVE_POSIX There shouldn't be HAVE_POSIX_FALLOCATE in the output. This is how it looks on my system with the patch: root@freebsd-poudriere /usr/local/poudriere/ports/HEAD/net/samba422/files # 10:59smbd -b | grep HAVE_POSIX HAVE_POSIX_ACLS HAVE_POSIX_FADVISE HAVE_POSIX_MEMALIGN HAVE_POSIX_OPENPT Maybe I messed up the patch somehow...
(In reply to Andrej Ebert from comment #20) I am seeing HAVE_POSIX_FALLOCATE in my smbd -b so it seems I'm not doing the correct steps to build with the patch. Can you provide the steps you are using to rebuild with the patch?
(In reply to hunt from comment #21) Sorry, didn't have time for samba for a while... Let's start clean: 0. stop samba: either service samba_server stop or service samba_server onestop 1. Remove your ports tree and checkout a clean one (net/gitup is a nice utility) 2. Download the 4.22.3 diff as raw unified diff: https://bugs.freebsd.org/bugzilla/attachment.cgi?id=262046&action=diff&collapsed=&headers=1&format=raw 3. cd <path to your ports tree> 4. git apply <path to the downloaded diff> 5. download the posix_fallocate patch as raw unified diff: https://bugs.freebsd.org/bugzilla/attachment.cgi?id=262242&action=diff&collapsed=&headers=1&format=raw 6. mv the downloaded patch to <path to your ports tree>/net/samba422/files/patch-lib_replace_wscript 7. cd <path to your ports tree>/net/samba422 8. make clean deinstall reinstall 9. smbd -b | grep HAVE_POSIX 10. start samba: either service samba_server start or service samba_server onestart 10. you shouldn't have HAVE_POSIX_FALLOCATE in the output 11. if that is the case, test again with your use case
Created attachment 262677 [details] log after instructions Thank you. I followed those instructions and verified HAVE_POSIX_FALLOCATE wasn't in the build option output, new samba_server instance started, smbd -V is 4.22.3 but I still get cp: error deallocating 'test/test1G': Input/output error. I still see zero-data fallocate(0x3) failed: Function not implemented in the log.
Bummer... You could take it upstream linking to this bug or just don't use sparse files (which apparently don't make sense on ZFS and not much on ZFS). I think samba should handle the non-presence of fallocate or posix_fallocate more gracefully, and the EINVAL from zfs, but that's over my head.