[systemd-devel] advice for zfs-mount-generator

Andrei Borzenkov arvidjaar at gmail.com
Tue Jun 28 17:37:57 UTC 2016


28.06.2016 06:49, Jörg Thalheim пишет:
> Hi,
> 
> when using zfs in combination with systemd, users run into the following problem:
> 
> - zfs manages mountpoints on its own and systemd is not aware of those.

systemd is aware of all mount points that are listed in
/proc/self/mountinfo. Do zfs mounts appear there?

> - this leads to problems, when mountpoints for other filesystems are mounted
>   on directories in a zfs dataset or files are created in a directory before zfs could
>   mount its dataset there. 

Did it ever work? I.e. was it ever possible (Solaris, *BSD) to intermix
zfs and legacy mount points? What happens if you try to set zfs mount
point to /legacy/zfs/mpoint where /legacy/zfs itself is mounted in
/etc/(v)fstab?

> - the default behaviour in zfs case is to refuse to mount a filesystem on top of a non-empty directory.
> 
> In case zfs is loaded via initrd (to allow to use zfs as bootfs) during early boot, writing a generator should be easy:
> 
> ```
> $ zfs get all -H | grep mountpoint
> zroot/home      mountpoint      /home  local
> zroot/journal   mountpoint      /var/lib/journal  local
> zroot/postgres  mountpoint      /var/lib/postgres  local
> zroot/root      mountpoint      /     local
> zroot/root/nix  mountpoint      /nix  local
> zroot/root/tmp  mountpoint      /tmp  local
> ```
> 
> It should be also noted that those filesystems will be not mounted using mount(2),
> but the command interface `zfs mount` except mountpoint is set the `legacy`
> 
> However currently some zfs services exists which import zfs pools after the generator run:
> 
> ```/usr/lib/systemd/system/zfs-import-scan.service
> [Unit]
> Description=Import ZFS pools by device scanning
> DefaultDependencies=no
> Requires=systemd-udev-settle.service
> After=systemd-udev-settle.service
> After=cryptsetup.target
> Before=dracut-mount.service
> ConditionPathExists=!/etc/zfs/zpool.cache
> 
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStartPre=/sbin/modprobe zfs
> ExecStart=/usr/bin/zpool import -aN -o cachefile=none
> 
> [Install]
> WantedBy=zfs-mount.service
> WantedBy=zfs.target
> ```
> 
> ```/usr/lib/systemd/system/zfs-mount.service
> [Unit]
> Description=Mount ZFS filesystems
> DefaultDependencies=no
> After=systemd-udev-settle.service
> After=zfs-import-cache.service
> After=zfs-import-scan.service
> After=systemd-remount-fs.service
> Before=local-fs.target
>

I strongly suspect that any zfs filesystem must be mounted before any
legacy filesystem, in which case just make it

Before=local-fs-pre.target

> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStart=/usr/bin/zfs mount -a
> 
> [Install]
> WantedBy=zfs-share.service
> WantedBy=zfs.target
> ```
> 
> As generators will run before unit I run into a Chicken or the egg problem.

I am not sure I understand how generators are relevant here.

> I would appreciate, if you have suggestions how to make this scheme compatible 
> with the way systemd handle mounts.
> 
> Thanks Jörg Thalheim.
> 
> 
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 



More information about the systemd-devel mailing list