# Notes
#
#      ashift=12:           2^12 = 4KiB sectors, for certain NVMe drives use 13 (8KiB)
#      autotrim=on:         TRIM for SSDs
#      encryption=on:       Defaults to aes-256-gcm (since 0.8.4)
#      pbkdf2iters=1400000: PBKDF2-SHA1 iterations recommendation by OWASP, default is only 350000
#      dnodesize=auto:      Is supposed to be used on systems running SAMBA with xattr=sa
#      compression=on:      Defaults to lz4
#      normalization=formD: Decomposed Unicode normalization, implies utf8only=on, so UTF-8 filenames only
#      longname=on:         Allows filenames up to 1023 bytes, default is off meaning 255 bytes (supported since 2.3.0)
#      primarycache:        Defines what is cached in ARC,   defaults to all (alternative settings: none, metadata)
#      secondarycache:      Defines what is cached in L2ARC, defaults to all (alternative settings: none, metadata)
#      direct:              Unset, defaulting to standard (since 2.3.0)
#  !!! recordsize:          Unset, defaulting to 128KiB (important performance related setting!)
#
#      Sources:
#      https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
#      https://openzfs.github.io/openzfs-docs/Getting%20Started/Debian/Debian%20Trixie%20Root%20on%20ZFS.html#step-2-disk-formatting
#      https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#compression
#      https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#direct
#      https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#dnodesize
#      https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#longname
#      https://openzfs.github.io/openzfs-docs/man/master/7/zfsprops.7.html#pbkdf2iters
#


# RAIDZ2 pool creation
#
#      -o (lowercase) is a _pool_ setting, -O (uppercase) is a _root dataset_ setting
#
zpool create \
    -o ashift=12 \
    -o autotrim=on \
    -O encryption=on -O keylocation=prompt -O keyformat=passphrase \
    -O pbkdf2iters=1400000 \
    -O acltype=posixacl -O xattr=sa -O dnodesize=auto \
    -O compression=on \
    -O normalization=formD \
    -O relatime=on \
    -O longname=on \
    -O canmount=off \
    -O mountpoint=/mnt/$${POOL_NAME} ${POOL_NAME} \
    raidz2 \
    ${DISK1..N} 


# Dataset creation (benchmarking)
#
#      To evaluate which recordsize is most suitable for a certain task we want to hit the raw disk as much as possible.
#      Modern OpenZFS versions already allow for direct IO (direct=standard by default), which mostly bypasses ARC/L2ARC.
#      In addition we tell ZFS to not hold actual file data in cache, only metadata.
#
zfs create \
    -o canmount=off \
    -o casesensitivity=insensitive \
    -o primarycache=metadata \
    -o secondarycache=metadata \
    ${POOL_NAME}/recordsize-test
zfs create -o recordsize=4K   ${POOL_NAME}/recordsize-test/4K
zfs create -o recordsize=8K   ${POOL_NAME}/recordsize-test/8K
zfs create -o recordsize=16K  ${POOL_NAME}/recordsize-test/16K
zfs create -o recordsize=32K  ${POOL_NAME}/recordsize-test/32K
zfs create -o recordsize=64K  ${POOL_NAME}/recordsize-test/64K
zfs create -o recordsize=128K ${POOL_NAME}/recordsize-test/128K
zfs create -o recordsize=256K ${POOL_NAME}/recordsize-test/256K
zfs create -o recordsize=512K ${POOL_NAME}/recordsize-test/512K
zfs create -o recordsize=1M   ${POOL_NAME}/recordsize-test/1M
zfs create -o recordsize=2M   ${POOL_NAME}/recordsize-test/2M
zfs create -o recordsize=4M   ${POOL_NAME}/recordsize-test/4M


# Dataset creation (media, file server)
#
#      casesensitivity=insensitive: Can speed up SAMBA sorting due to SAMBA being case-insensitive as well
#      recordsize=XXX               Bigger recordsize can yield higher compression rations (if data is suitable; video files aren't)      
#
TODO


# Dataset creation (databases)
#
#      Common database solutions use 4K (SQLite), 8K (PostgreSQL) or 16KB (MariaDB InnoDB) page sizes.
#      Adjusting recordsize to these workloads reduces write amplification and improves random IO.
#      Databases usually implement some form of caching themselves, so consider disabling ARC/L2ARC file caching.
#
TODO
