Shares, Quotas, Datasets and how they work together

Cedus

Cadet
Joined
Nov 20, 2020
Messages
4
Hi everyone!

After hours of searching and reading old posts I'm more confused than ever. Previously I used Netapp. There I created a volume in an aggregate of disks and shared it via nfs. Now to add quotas: set a per-group rule so that users of group pupils get a hard limit of 20GB and users of group teachers get 100GB. Users of group root/wheel/staff are unlimited. Apply and ready!
Now with TrueNAS 13.0-U3.1 I created a pool and shared it via nfs. Now to add quotas... but suddenly there are datasets and I don't get the concept. How do I set the quotas according to my previous NAS with this? I studied the Docs Hub and started to create a generic dataset with a quota of 20GB, but I cannot set a group nor user.
Should I create three datasets (20/100/unlimited) and do I need to create rules to distribute them to my user(group)s? If a dataset is a file system within a TrueNAS pool, do I need to export the three datasets as three nfs-shares? Also there is no "Parent path" (as seen on the screenshots in Docs Hub) in my system, so it looks to me that the dataset is for the entire pool. If someone can give me a clue (and a simple explanation how the three in the title work together) please...

regards
 

Attachments

  • New_Dataset_on_my_system.JPG
    New_Dataset_on_my_system.JPG
    23.3 KB · Views: 137
  • Generic_Dataset_on_Docs_Hub.JPG
    Generic_Dataset_on_Docs_Hub.JPG
    47.2 KB · Views: 135

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
The original concept for ZFS Quotas and Reservations were to allow datasets to act similar to disk partitions & RAID volumes. This means that instead of sharing free space between ZFS datasets, you can make some guarantees of where the free space is available.

Later, Sun Microsystems added "userquota@USER" & "groupquota@GROUP", (and something for projects...). I don't know much about them, but I guessing that these are closer to what you were looking for.
 

Cedus

Cadet
Joined
Nov 20, 2020
Messages
4
Thanks for the hint. I can finally answer my own question: to use quotas, you need to create a pool (here pool0) and then create a generic dataset within with all the default options. Don't change anything, just remember the name (mine was home). Now you can apply userquotas via shell to this dataset, because using the GUI would get tiresome for a few thousand users. So I created a script, which reassembles the functionality of my previous NAS:
Code:
#!/bin/bash
#######################################################
# This script sets a per user quota as defined in 'limit' on the 'targetpath'   #
# using the zfs command for all existing accounts from 'uidnr' to 'uidlimit' #
#######################################################
set -euo pipefail

uidnr=10000
uidlimit=19999
# USE none AS limit TO REMOVE QUOTA
limit=10G
targetpath="pool0/home"

until [ $uidnr -gt $uidlimit ]
do
    # check if user exists (requires Active Directory or LDAP setup)
    if getent passwd $uidnr >/dev/null
    then
        echo "Setting quota for useruid " $uidnr
        /usr/local/sbin/zfs set userquota@$uidnr=$limit $targetpath   
    else
        echo $uidnr "does not exist - no quota set"
    fi
    ((uidnr=uidnr+1))
done

exit 0


cheers :smile:
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
There's webui / API support for user quotas.

Additionally if access is purely over SMB protocol you can specify a base user quota by setting the auxiliary parameter zfs_core:base_user_quota = 1G on your share.

This will automatically apply a 1G quota on the dataset for the user when it first connects to the share.

Is where it receives CI coverage.
 

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
Glad I could clarify things.

You might need to investigate setting the user quotas from the command line API. Perhaps @anodos can verify, but some items changed from the command line are not preserved properly. Unless done from either the GUI or command line API.

I don't know about user quotas being in ZFS or both ZFS and API.
 

anodos

Sambassador
iXsystems
Joined
Mar 6, 2014
Messages
9,554
Glad I could clarify things.

You might need to investigate setting the user quotas from the command line API. Perhaps @anodos can verify, but some items changed from the command line are not preserved properly. Unless done from either the GUI or command line API.

I don't know about user quotas being in ZFS or both ZFS and API.
They're stored in ZFS and so webui, samba, etc all have same source of truth. This particular script isn't really a problem.

You can write scripts to do these things of course (with caveat that not all changes persist), but my experience is that code in general is a liability. If you use built-in features then you're offloading the liability to us. If you have your own bundle of scripts to do things then this is something you have to maintain (and if this is at work, then your employer eventually has to maintain). This costs time / money in the long run.
 

Cedus

Cadet
Joined
Nov 20, 2020
Messages
4
Thanks to both of you for your additions. As stated in my first post, I only use NFS so I never tried @anodis auxiliary parameter, which I also stumbled upon on previous searches. And it sets a default base quota for every user whereas I can copy my script and adapt the uid-variables to create "default quotas" for different users (pupils & teachers) - it's nearly like a new zfs-parameter base_user_quota_for_uidrange ;-) The results are furthermore perfectly displayed in the GUI.
 
Top