Mount zfs dataset in LXC

I am running LXC with unprivileged containers on a ZFS backend.
I’d now like to split the container’s rootfs from the application data using two separate zfs datasets.
For example ‘rpool/LXC/containers/test’ for the container rootfs (already working) and ‘rpool/LXC/data/test’ for the data volume. This allows me to easily upgrade the container by destroying & recreating it based on a newer template, and just re-mounting the data volume.

For now the best I’ve found would be to mount the ‘rpool/LXC/containers/test’ dataset on the host and then have a bind mount in the LXC container through a lxc.mount.entry. What I’d prefer is to directly mount the dataset in the container - however something like ‘lxc.mount.entry = zfs:rpool/LXC/data/test’ does not work.

Any ideas ?

(On a related note, this is similiar to what LXD can do through ‘lxc storage’ but I’m stuck with LXC on this system)

lxc.mount.entry = rpool/LXC/containers/test data/test zfs rw,zfsutil,mntpoint=/data/test 0 0

That may work.

Where do I need to put it?
In profile?

That question was about LXC, not LXD. There is no such thing as profiles in LXC.

Understood.
I have a LXD.
Than what’s about doing the same in LXD profile?

For LXD if you want to separate the rootfs files from the application files, you can create a custom volume and then attach that to the instance.

E.g.

lxc init images:ubuntu/focal myapp -s zfspool
lxc storage volume create zfspool myappdata
lxc storage volume attach zfspool myappdata myapp appdata /mnt/appdata
lxc start myapp
lxc exec myapp -- ls -la /mnt/appdata # Will show contents of the custom volume

I mounted datasets, configured in profiles the passtrough of mountpoints via type: disk, than created sub-container, and done the same for it. It seemed to work, but after reboot, I can’t find my data.
Dataset1 was mounted at host to /mnt1. /mnt1 was passed to container via profile as, also, /mnt1 and then passed to a sub-container as (also) /mnt1. So the data ought to be found either in host’s /mnt1, where Dataset1 is mounted or in ${CONTAINER_DATASET_MOUNTPOINT}/rootfs/mnt1 or in ${SUB_CONTAINER_DATASET_MOUNTPOINT}/rootfs/mnt1, if /mnt1 was not really pased to sub-container. But after reboot Dataset1 and ${CONTAINER_DATASET_MOUNTPOINT}/rootfs/mnt1 and ${SUB_CONTAINER_DATASET_MOUNTPOINT}/rootfs/mnt1 are empty. Seems all data was writen in tmpfs instead of zfs.
(Data was not critical, and there is a backup.)
So, as I see passing mounted zfs dataset through container to sub-container via:

my_dataset:
  path: /container_mnt
  source: /hosts_mnt
  type: disk

and then via:

my_dataset:
  path: /sub_container_mnt
  source: /container_mnt
  type: disk

leads to data loose…

Can you recreate the setup and then show the output of findmnt in each of host, container and nested container.