Custom Samba Sizing

After reorganizing my ZFS datasets a bit, I suddenly noted I couldn't copy any file larger than a few MB. A bit of investigation later and I figured why it was so.

My ZFS data sets were as follows:

# zfs list
NAME USED AVAIL REFER MOUNTPOINT
Data 2.06T 965G 96K none
Data/Users 181G 965G 96K none
Data/Users/User1 44.3G 19.7G 2.23G /Data/Users/User1
Data/Users/User2 14.7G 49.3G 264K /Data/Users/User2
Data/Users/User3 224K 64.0G 96K /Data/Users/User3

And my Samba share was pointing to /Data/Users/.

Guess what? Path /Data/Users was not pointing to any dataset as my parent dataset for Data/Users was not mounted. Instead it pointed to memory disk md0 which had just a few MB free. Samba doesn't check full path for disk size but only its root share.

The easiest way to workaround this would be to simply mount parent dataset. But why go for easy?

A bit more complicated solution is getting Samba to use custom script to determine free space. We can then use this script to return available disk space for our parent dataset instead of built-in samba calculation.

To do this, we first create script /myScripts/sambaDiskFree:

#!/bin/sh
DATASET=`pwd | cut -c2-`
zfs list -H -p -o available,used $DATASET | awk '{print $1+$2 " " $1}'

This script will check current directory, map its name to dataset (in my case it is as easy as stripping first slash character) and return two numbers. First is total disk space, followed by available diskspace - both in bytes.

Once script is saved and marked as executable (chmod +x), we just need to reference it in Services > CIFS/SMB > Settings under Additional parameters:

dfree command = /myScripts/sambaDiskFree

This will tell Samba to use our script for disk space determinations.

Leave a Reply

Your email address will not be published. Required fields are marked *