[Samba] dfree does not work on a btrfs subvolume with qgroups (Samba 4.13.13, Debian 11)
Kristaps Esterliņš
kristaps.esterlins at gmail.com
Mon Sep 19 09:28:19 UTC 2022
Good Day!
Since my initial response has not been answered. I managed to solve the
issue as follows:
Create a separate script which retrieves the `btrfs qgroup` used and free
size and then writes to a separate file. The separate file is then executed
by the script which is defined in smb.conf.
The script is either executed in cron every n minutes or as a systemd unit.
That was I overcame the permission execution issue (btrfs qgroup needs root
permissions). The only drawback is that if the directory has many
write/delete operations the free space will only be updated after the
script has been executed.
# /etc/samba/smb.conf
*...*
* dfree command = /usr/local/samba/bin/dfree dfree cache time = 0*
*...*
# ls -l /usr/local/samba/bin/
*-rwxr-xr-x 1 user user 46 Sep 19 11:47 dfree-rwxr-xr-x 1 user user 373
Apr 27 14:56 dfree.sh-rw-r--r-- 1 root root 27 Sep 19 12:20 dfree.txt*
*$ cat dfree*
*#!/bin/shcat /usr/local/samba/bin/dfree.txt*
*$ cat dfree.sh*
*#!/bin/shCUR_PATH=/srv/samba/dirTOTAL=`/usr/bin/btrfs qgroup show -rF
--raw $CUR_PATH --sync | /usr/bin/tail -1 | /usr/bin/awk '{print
$(NF-0)/1024}'`USED=`/usr/bin/btrfs qgroup show -rF --raw $CUR_PATH --sync
| /usr/bin/tail -1 | /usr/bin/awk '{print
$(NF-2)/1024}'`AVAIL=$(($TOTAL-$USED)) > /dev/null*
*echo $TOTAL $AVAIL 1024 > /usr/local/samba/bin/dfree.txt*
*$ cat dfree.txt*
*1562378240 1328810900 1024*
*# crontab*
*/2 * * * * /bin/bash /usr/local/samba/bin/dfree.sh >/dev/null 2>&1
On Tue, 29 Mar 2022 at 16:59, Kristaps Esterliņš <
kristaps.esterlins at gmail.com> wrote:
> Good Day!
>
> I am bumping this question again, maybe somebody can give me a hint why
> sys_disk_free does not return correct value:
>
> OS - Debian 11.3
> Samba - 4.13.13
>
> 2 x 8Tb HDDs with btrfs filesystem and subvolume dedicated to samba
> share. The subvolume is 1.43T large but samba share returns the whole
> (7.3T) space available which is not true.
>
>
> # cat /etc/debian_version
> 11.3
> # dpkg -l | grep -i samba
> ii libnss-winbind:amd64 2:4.13.13+dfsg-1~deb11u3
> amd64 Samba nameservice integration plugins
> ii libwbclient0:amd64 2:4.13.13+dfsg-1~deb11u3
> amd64 Samba winbind client library
> ii python3-samba 2:4.13.13+dfsg-1~deb11u3
> amd64 Python 3 bindings for Samba
> ii samba 2:4.13.13+dfsg-1~deb11u3
> amd64 SMB/CIFS file, print, and login server for Unix
> ii samba-common 2:4.13.13+dfsg-1~deb11u3
> all common files used by both the Samba server and client
> ii samba-common-bin 2:4.13.13+dfsg-1~deb11u3
> amd64 Samba common files used by both the server and the client
> ii samba-libs:amd64 2:4.13.13+dfsg-1~deb11u3
> amd64 Samba core libraries
> ii samba-vfs-modules:amd64 2:4.13.13+dfsg-1~deb11u3
> amd64 Samba Virtual FileSystem plugins
>
>
> # btrfs qgroup show -reF /srv/samba/sales
>
>
> *qgroupid rfer excl max_rfer max_excl--------
> ---- ---- -------- --------0/696 117.74GiB
> 117.74GiB 1.43TiB non*e
>
> Samba is a member of an existing Active Directory (Windows Server 2019)
> server.
>
> # /etc/samba/smb.conf
>
>
> # https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Domain_Member
> [global]
> #
> https://wiki.samba.org/index.php/Configure_Samba_to_Bind_to_Specific_Interfaces
>
> bind interfaces only = yes
> interfaces = lo br0
>
> # 29.03.2022 -
> https://wiki.samba.org/index.php/Configure_Samba_to_Work_Better_with_Mac_OS_X
>
> min protocol = SMB2
> ea support = yes
>
> # Active Directory
> workgroup = AD1
> security = ADS
> realm = AD1.domain.LV
>
> # Samba Log File
> log file = /var/log/samba/%m.log
> max log size = 32768
> log level = 1
>
> # Active Directory
> winbind refresh tickets = Yes
> # https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs
> vfs objects = acl_xattr
> map acl inherit = Yes
> store dos attributes = Yes
>
> dedicated keytab file = /etc/krb5.keytab
> kerberos method = secrets and keytab
>
> load printers = no
> printing = bsd
> printcap name = /dev/null
> disable spoolss = yes
>
> # Default ID mapping configuration for local BUILTIN accounts
> # and groups on a domain member. The default (*) domain:
> # - must not overlap with any domain ID mapping configuration!
> # - must use a read-write-enabled back end, such as tdb.
> idmap config * : backend = tdb
> idmap config * : range = 3000-7999
>
> # - You must set a DOMAIN backend configuration
> # idmap config for the AD1 domain
>
> idmap config AD1 : backend = rid
> idmap config AD1 : range = 10000-999999
>
> # ! Setting the default back end is mandatory.
>
> # ! For every domain, set these parameters individually.
> # ! The ID ranges of the * default domain and all other domains
> configured in the smb.conf file must not overlap.
>
> # Template settings for login shell and home directory
> template shell = /bin/bash
> template homedir = /home/%U
>
> username map = /usr/local/samba/etc/user.map
>
> # https://lists.samba.org/archive/samba/2021-November/238643.html
> min domain uid = 0
>
> #
> https://wiki.samba.org/index.php/Troubleshooting_Samba_Domain_Members#getent_not_Finding_Domain_Users_and_Groups
>
> winbind enum users = yes
> winbind enum groups = yes
>
> # Default Share - "Sales"
> [Sales]
> path = /srv/samba/sales
> read only = no
> # https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs
>
> acl_xattr:ignore system acls = yes
>
> # 15.02.2022 - Log activity on the "Sales" share
> #
> https://wiki.samba.org/index.php/Server-Side_Copy#Btrfs_Enhanced_Server-Side_Copy_Offload
>
> vfs objects = full_audit btrfs
> full_audit:prefix = %u|%I|%m|%S
> full_audit:success = mkdirat renameat unlinkat pwrite pread
> full_audit:failure = none
>
> dfree command = /usr/local/samba/bin/dfree
> dfree cache time = 0
>
> # journalctl -t smbd_audit
>
> *Mar 29 15:49:43 office smbd_audit[76824]: [2022/03/29 15:49:43.487977,
> 0] ../../source3/smbd/dfree.c:133(sys_disk_free)Mar 29 15:49:43 office
> smbd_audit[76824]: sys_disk_free: file_lines_load() failed for command
> '/usr/local/samba/bin/dfree .'. Error was : No child processes*
>
> # ls -al /usr/local/samba/bin/dfree
>
> *-rwxrwxrwx 1 root root 371 Feb 17 09:49 /usr/local/samba/bin/dfree*
>
> # /bin/bash /usr/local/samba/bin/dfree
> *1530920960 1407461720 1024*
>
> *# strace *
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *write(13, " sys_disk_free: file_lines_load"..., 117) = 117sendto(43,
> "<27>Mar 29 16:34:20 smbd_audit: "..., 149, MSG_NOSIGNAL, NULL, 0) =
> 149statfs(".", {f_type=BTRFS_SUPER_MAGIC, f_bsize=4096,
> f_blocks=1953506385, f_bfree=1558219039, f_bavail=1558158146, f_files=0,
> f_ffree=0, f_fsid={val=[69581704, 4285057198]}, f_namelen=255,
> f_frsize=4096, f_flags=ST_VALID|ST_RELATIME}) = 0stat(".",
> {st_mode=S_IFDIR|0771, st_size=2012, ...}) = 0getcwd("/srv/samba/sales",
> 4096) = 17stat("/srv/samba/sales", {st_mode=S_IFDIR|0771,
> st_size=2012, ...}) = 0stat("/srv/samba", {st_mode=S_IFDIR|0755,
> st_size=30, ...}) = 0stat("/srv", {st_mode=S_IFDIR|0755, st_size=36, ...})
> = 0openat(AT_FDCWD, "/etc/mtab", O_RDONLY|O_CLOEXEC) = 46fstat(46,
> {st_mode=S_IFREG|0444, st_size=0, ...}) = 0read(46, "sysfs /sys sysfs
> rw,nosuid,nodev"..., 1024) = 1024read(46, "e_ino=14902 0 0\nmqueue
> /dev/mque"..., 1024) = 829stat("/srv/samba", {st_mode=S_IFDIR|0755,
> st_size=30, ...}) = 0close(46) = 0geteuid()
> = 11124quotactl(QCMD(Q_GETQUOTA, USRQUOTA),
> "/dev/sdc1", 11124, 0x7ffe61cab2d0) = -1 ENODEV (No such device)*
>
> Thanks!
>
>
> On Thu, 17 Feb 2022 at 10:11, Kristaps Esterliņš <
> kristaps.esterlins at gmail.com> wrote:
>
>> Good Day!
>>
>> Configuration:
>>
>> Debian 11
>> Samba 4.13.13
>>
>> I have 2 x 8 Tb HDDs with btrfs filesystem with subvolume dedicated to a
>> samba share and I have created a disk quota:
>>
>> # btrfs qgroup show -reF /srv/samba/sales
>>
>>
>> *qgroupid rfer excl max_rfer max_excl--------
>> ---- ---- -------- --------0/696 117.74GiB
>> 117.74GiB 1.43TiB none*
>>
>> # mount /srv/samba
>>
>>
>> */dev/sdc1 on /srv/samba type btrfs
>> (rw,relatime,space_cache,subvolid=696,subvol=/samba)*
>>
>> # /etc/sama/smb.conf
>>
>> ...
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *# Default Share - "Sales"[Sales] path = /srv/samba/sales read only =
>> no #
>> https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs
>> <https://wiki.samba.org/index.php/Setting_up_a_Share_Using_Windows_ACLs>
>> acl_xattr:ignore system acls = yes # 15.02.2022 - Log activity on the
>> "Sales" share #
>> https://wiki.samba.org/index.php/Server-Side_Copy#Btrfs_Enhanced_Server-Side_Copy_Offload
>> <https://wiki.samba.org/index.php/Server-Side_Copy#Btrfs_Enhanced_Server-Side_Copy_Offload>
>> vfs objects = full_audit btrfs full_audit:prefix = %u|%I|%m|%S
>> full_audit:success = mkdirat renameat unlinkat pwrite pread
>> full_audit:failure = none dfree command = /usr/local/samba/bin/dfree
>> dfree cache time = 0*
>>
>> # /usr/local/samba/bin/dfree
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *#!/bin/shCUR_PATH=/srv/samba/salesTOTAL=$((`/usr/bin/btrfs qgroup show
>> -rF --raw $CUR_PATH --sync | /usr/bin/tail -1 | /usr/bin/awk '{print
>> $(NF-0)/1024}'`)) > /dev/nullUSED=$((`/usr/bin/btrfs qgroup show -rF --raw
>> $CUR_PATH --sync | /usr/bin/tail -1 | /usr/bin/awk '{print
>> $(NF-2)/1024}'`)) > /dev/nullAVAIL=$(($TOTAL-$USED)) > /dev/nullecho $TOTAL
>> $AVAIL 1024*
>>
>> office:/usr/local/samba/bin# ls -al
>> total 4
>> drwxrwxrwx 1 root root 10 Feb 17 09:50 .
>> drwxr-xr-x 1 root root 12 Feb 15 11:51 ..
>> -rwxrwxrwx 1 root root 371 Feb 17 09:49 dfree
>>
>> office:/usr/local/samba/bin# ./dfree
>>
>> *1530920960 1407461464 1024*
>>
>> # journalctl
>> ...
>>
>> Feb 17 09:29:12 office smbd_audit[59818]: [2022/02/17 09:29:12.668171,
>> 0] ../../source3/smbd/dfree.c:133(sys_disk_free)
>> Feb 17 09:29:12 office smbd_audit[59818]: sys_disk_free:
>> file_lines_load() failed for command '/usr/local/samba/bin/dfree .'. Error
>> was : No child processes
>>
>> Please see the strace file - https://pastebin.com/raw/rnDy44T6
>> <https://pastebin.com/raw/4kWZsnqm>
>>
>> Thanks!
>>
>
More information about the samba
mailing list