Skip to content

nspawn: convert var-lib-machines.mount to an automount#6095

Merged
poettering merged 2 commits intosystemd:masterfrom
fsateler:machines-mount
Jun 22, 2017
Merged

nspawn: convert var-lib-machines.mount to an automount#6095
poettering merged 2 commits intosystemd:masterfrom
fsateler:machines-mount

Conversation

@fsateler
Copy link
Member

@fsateler fsateler commented Jun 7, 2017

/var can be on a remote filesystem, thus hooking it to local-fs.target is not correct.
Lets convert it to an automount, and have the automount be pulled in by machines.target.
This way, it should be available whenever nspawn machines are enabled.

Fixes #1175

While doing this I noticed that the mount unit was being installed even when machined is disabled. I changed that.

@fsateler
Copy link
Member Author

CI fails because packaging needs adjusting (var-lib-machines.mount is no longer enabled)

Copy link
Member

@poettering poettering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i figure conceptually we can do this, but this must be conditioned differently as both machined and nspawn use the dir...

if ENABLE_MACHINED
MACHINES_TARGET_WANTS += \
var-lib-machines.automount
endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't look right. nspawn uses the dir too (in fact, it's the dir's primary user if you so will), hence this should be pulled in if nspawn is enabled too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nspawn uses the directory, but it does not manipulate it and does not care how it is mounted. Since #6079 , systemd-nspawn@ has a RequiresMountsFor=/var/lib/machines, which should take care of nspawn.

OTOH, it is machined that creates and manages /var/lib/machines.raw, so if machined is not built, neither should the mount unit, and configuring /var/lib/machines is completely up to the admin.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change this as per my reasoning above. Please indicate if you still want this changed.

Makefile.am Outdated

dist_systemunit_DATA += \
units/var-lib-machines.mount \
units/var-lib-machines.automount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is simply wrong, nspawn uses this too, see other comment.

In fact [email protected] should probably get an explicit RequiresMountsFor= for the container dir it operates on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other comment, nspawn is a mere user and as such having the mount units when nobody will create the underlying loop device is not useful.

@poettering poettering added the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Jun 16, 2017
@poettering
Copy link
Member

/var can be on a remote filesystem, thus hooking it to local-fs.target is not correct.

(Well, it's more difficult than this. /var is pulled in explicitly from basic.target, hence still part of the early boot even if located on NFS)

@poettering
Copy link
Member

So, one thing I don't really like about this is that it somewhat interferes with the user's config if he decides to make /var/lib/machines a mount point of his own (which is a very OK thing to do). So far, by placing an entry in /etc/fstab that overrode the mount unit we ship and all was good. However, this now gets weirdly affected by the automount, as the user's mount unit will now be accompanied by our .automount unit, which however is conditioned out in the usual case... And that's just weird...

Dunno if this is a problem IRL, but I am not sure I like it too much...

I wonder if it wouldn't be nicer to solve this differently: don't bother with an automount unit at all, but instead make it a normal mount unit, and then:

  1. Add RequiresMountsFor=/var/lib/machines to systemd-machined.service
  2. dito to machines.target and possibly remote-fs.target
  3. Add RequiresMountsFor=/var/lib/machines/%i to [email protected]

That way the unit is pulled in late boot only, but we get all the necessary deps in place without any automount unit. Does this make sense?

@fsateler
Copy link
Member Author

So, one thing I don't really like about this is that it somewhat interferes with the user's config if he decides to make /var/lib/machines a mount point of his own (which is a very OK thing to do). So far, by placing an entry in /etc/fstab that overrode the mount unit we ship and all was good. However, this now gets weirdly affected by the automount, as the user's mount unit will now be accompanied by our .automount unit, which however is conditioned out in the usual case... And that's just weird...

Indeed. That's an unfortunate side effect of automounts being a separate unit from the main mount. Alternatively we could have a generator but it sounds overkill.

I wonder if it wouldn't be nicer to solve this differently: don't bother with an automount unit at all, but instead make it a normal mount unit, and then:

  • Add RequiresMountsFor=/var/lib/machines to systemd-machined.service

This makes sense either way, I'll add it.

  • dito to machines.target and possibly remote-fs.target

remote-fs.target sounds a bit unrelated. I initially proposed in #1175 to have the automount hooked up in sysinit.target. If we go automount-less, we could also hook it up there, but without ordering dependencies. This way it would always be brought up, but it could be done late if necessary.

I'm not sure what would adding it to machines.target would accomplish.

This is already done since #6079

That way the unit is pulled in late boot only, but we get all the necessary deps in place without any automount unit. Does this make sense?

I think it does. The only question would be where to pull it in.

@poettering
Copy link
Member

remote-fs.target sounds a bit unrelated.

It does if you think of it as "this is where remote mounts are pulled in". But if you think about it as "this is the latest where mounts are pulled in" then it starts making sense.

That said, I don't think adding this dep actually really makes sense, as mounts marked "auto" are either pulled in by local-fs.target or remote-fs.target anyway, hence there's no need to pull them in explicitly by remote-fs.target a second time. Hence ignore this bit.

I initially proposed in #1175 to have the automount hooked up in sysinit.target. If we go automount-less, we could also hook it up there, but without ordering dependencies. This way it would always be brought up, but it could be done late if necessary.

I'm not sure what would adding it to machines.target would accomplish.

So, we document that people can access /var/lib/machines directly too, and drop their stuff there, i.e. that nspawn and machined are happy to use it, but that it isn't private property of either, but anyone is welcome to drop stuff there. Hence I think it would make a certain amount of sense to say that if you start machines.target — which I think should mean something like "please start up the VM/container virtualization subsystem and related stuff now" would also ensure the dir is then available, even if you don't actually have any nspawn instances enabled in it.

fsateler added 2 commits June 21, 2017 16:19
…target

/var can be on a remote filesystem, thus hooking it to local-fs.target is not correct.

Also, only install the mount unit when machined is enabled, because
machined is the one managing the underlying device, and thus makes no
sense without machined.

Fixes systemd#1175
Since any part of the path could be remote mounted, make sure they are
before starting machined
@fsateler
Copy link
Member Author

Updated as per #6095 (comment) .

I decided to use the regular add-wants machinery instead of using RequiresMountsFor between the targets and the mount unit, because I figured there is no reason that /var/lib/machines should be special cased in those targets, and instead the mount unit hooks into the targets.

@poettering poettering removed the reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks label Jun 22, 2017
@poettering poettering merged commit f778b8f into systemd:master Jun 22, 2017
@poettering
Copy link
Member

@fsateler @mbiebl @martinpitt any chance you can fix the packaging to adapt to this PR which I just merged so that the CI works again? Thank you!

@martinpitt
Copy link
Contributor

@poettering: I adjusted the packaging to not care any more into which target(s) it gets installed. I verified that it doesn't break the downstream build, and it should work for upstream now. Unfortunately I can't test it any more on this PR as it's already closed - but e. g. PR #6715 ought to fail still, and I'll retry it to verify.

Next time, it'd be great if we could do the downstream adjustments before merging, so that we can use the PR that introduces the change to verify.

ddstreet pushed a commit to ddstreet/systemd that referenced this pull request Jul 4, 2019
Imported using git-ubuntu import.

Changelog parent: 4d48d62

New changelog entries:
  [ Martin Pitt ]
  * Adjust var-lib-machines.mount target.
    Upstream PR systemd#6095 changed the location to
    {remote-fs,machines}.target.wants, so just install all available ones.
  [ Dimitri John Ledkov ]
  * Fix out-of-bounds write in systemd-resolved.
    CVE-2017-9445 (Closes: #866147, LP: #1695546)
  [ Michael Biebl ]
  * Be truly quiet in systemctl -q is-enabled (Closes: #866579)
  * Improve RLIMIT_NOFILE handling.
    Use /proc/sys/fs/nr_open to find the current limit of open files
    compiled into the kernel instead of using a hard-coded value of 65536
    for RLIMIT_NOFILE. (Closes: #865449)
  [ Nicolas Braud-Santoni ]
  * debian/extra/rules: Use updated U2F ruleset.
    This ruleset comes from Yubico's libu2f-host. (Closes: #824532)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants