Skip to content

systemd-mount-generator breaks with default mountpoints due to mount canonicalizing the source argument when calling mount.zfs #11448

Closed
@chenxiaolong

Description

@chenxiaolong

System information

Type Version/Name
Distribution Name Fedora
Distribution Version 33
Linux Kernel 5.9.16-200.fc33.x86_64
Architecture x86_64
ZFS Version 2.0.1-1
SPL Version 2.0.1-1
util-linux Version 2.36-3.fc33.x86_64

Describe the problem you're observing

With systemd .mount units, the mount command gets run in CWD /, which causes mount to turn the source argument into an absolute path before calling mount.zfs. This is problematic with the default mountpoint scheme where the dataset name is the mountpoint. When mount is called with pool/dataset as the source, mount.zfs gets called with /pool/dataset.

This can be worked around when mounting manually by:

  • Passing --no-canonicalize to mount
  • Running mount from anywhere else besides /

Unfortunately, I don't think systemd .mount units support either of those options. Would it be feasible to try and detect this somehow in mount.zfs or maybe there's a better workaround available?

Describe how to reproduce the problem

  1. Enable systemd-mount-generator:
touch /etc/zfs/zfs-list.cache/pool
  1. Create a test dataset and unmount it:
zfs create pool/test
zfs unmount pool/test
  1. Reload systemd and try to mount the volume:
systemctl daemon-reload
systemctl start pool-test.mount
  1. The mount fails with:
filesystem '/pool/test' cannot be mounted, unable to open the dataset

The mount canonicalization behavior can also be reproduced by:

$ zfs create pool/test
$ zfs unmount pool/test
$ cd /
$ mount pool/test /pool/test -t zfs -o defaults,atime,relatime,dev,exec,rw,suid,nomand,zfsutil
filesystem '/pool/test' cannot be mounted, unable to open the dataset
$ cd /tmp
$ mount pool/test /pool/test -t zfs -o defaults,atime,relatime,dev,exec,rw,suid,nomand,zfsutil
# ^^ Works outside of /
$ umount /pool/test
$ mount pool/test /pool/test -t zfs -o defaults,atime,relatime,dev,exec,rw,suid,nomand,zfsutil --no-canonicalize
# ^^ Also works with --no-canonicalize

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: Triage NeededNew issue which needs to be triagedType: DefectIncorrect behavior (e.g. crash, hang)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions