systemd service zfs-import-cache.service no longer works correctly #3440

Closed
siebenmann opened this Issue May 25, 2015 · 9 comments

3 participants

@siebenmann

As of commit 87abfcb, the ExecStart specified in zfs-import-cache.service is:

ExecStart=/sbin/modprobe zfs && @sbindir@/zpool import -c @sysconfdir@/zfs/zpool.cache -aN

However, systemd ExecStart is not a shell command line; it is a command (or several commands separated by ';'). As a result, the entire ExecStart is handed to modprobe as command line arguments and modprobe errors out (its specific complaint is that it doesn't have a -N argument). Even if modprobe ignored the surplus arguments, this would not run 'zpool import'. I think that the simple way to make this work is to put the modprobe command in an ExecStartPre= statement.

@behlendorf
ZFS on Linux member

I was afraid of that. If you could propose a clean fix that would be great.

@siebenmann

What seems to work for me is splitting the ExecStart into:

ExecStartPre=/sbin/modprobe zfs
ExecStart=@sbindir@/zpool import -c @sysconfdir@/zfs/zpool.cache -aN

Based on my system and on my reading of systemd.service, this should work right; if the ExecStartPre modprobe fails, the ExecStart is not run and the unit is considered failed (the intent of the existing '&&', or so I assume). It's possible that the modprobe should be started with a '-' so that even if it fails the 'zpool import' will be tried just in the hopes that it will work.

(My sysadmin bias is that ZFS should try relatively hard to bring pools up, because failure to bring pools up is basically a fatal boot failure. But for the first fix I would just split to ExecStartPre/ExecStart without the '-'.)

A similar fix is needed to zfs-import-scan.service.in.

@tycho

I just ran into this. The solution I used was this:

http://git.uplinklabs.net/snoonan/projects/archlinux/ec2/ec2-packages.git/plain/zfs-git/0001-zfs-import-.service-ExecStart-doesn-t-support.patch

Feel free to pull that patch into the zfs repo if it looks alright.

@behlendorf
ZFS on Linux member

@tycho thanks for the patch. One question, why did you opt to use ExecStart instead of ExecStartPre for the modprobe? I'm no systemd expert so I'm curious, the documentation doesn't seem to make it clear why you'd choose one over the other.

http://www.freedesktop.org/software/systemd/man/systemd.service.html

@behlendorf behlendorf added a commit to behlendorf/zfs that referenced this issue May 26, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #3440
30b0af5
@behlendorf
ZFS on Linux member

@siebenmann @tycho I opened a pull request, #3444, with your proposed fix if I could get you guys to review and sign off on it we can get this fixed in master.

@tycho

@behlendorf In this case, I believe ExecStart/ExecStartPre will be functionally the same. I'll pose the question on the systemd-devel mailing list.

http://lists.freedesktop.org/archives/systemd-devel/2015-May/032268.html

@tycho

There's a reply on the mailing list.

http://lists.freedesktop.org/archives/systemd-devel/2015-May/032269.html

Copying here for posterity.

From: Christian Seiler christian at iwakd.de 
Date: Tue May 26 14:26:11 PDT 2015
Subject: [systemd-devel] Re: ExecStart vs ExecStartPre

On 05/26/2015 11:12 PM, Steven Noonan wrote:
> Hi there,
> 
> I'm wondering what the functional difference is between doing:
> 
> ExecStartPre=/bin/foo
> ExecStart=/bin/bar
> 
> and
> 
> ExecStart=/bin/foo
> ExecStart=/bin/bar
> 
> From my read of the systemd.service man page, they appear to have the
> same behavior in the common use case.

Three differences come directly to mind:

 - If you have unit of type that is NOT oneshot (simple, forking,
   etc.), you can have only a single ExecStart= line, not multiple
   ones. The main service process must be started in ExecStart=
   and not ExecStartPre=.

 - Even in Type=oneshot units you must have at least one ExecStart=
   line (but can in any case have an arbitrary amount of ExecStartPre=
   lines, even zero).

 - If you set PermissionsStartOnly= or RootDirectoryStartOnly=, then
   certain settings will be applied to ExecStart= but not to
   ExecStartPre= (see manpage for details).

(There are probably more.)

Generally speaking, I follow the following guidelines when writing
units:

 - Type=oneshot: I typically use only ExecStart= and only use
   ExecStartPre= if I have to use *StartOnly=true (see above).

 - other types: ExecStart= to start the service proper, ExecStartPre=
   for preparatory things (like generating a default config if none
   is already present or something along those lines)

But it really depends on your use case and as always YMMV.

Hope that helps!

Christian
@behlendorf
ZFS on Linux member

Interesting, well you learn something every day. It seems to me our use case would fall under this sort of general rule. I'm inclined to go with ExecStartPre= if you're both OK with that.

 - other types: ExecStart= to start the service proper, ExecStartPre=
   for preparatory things (like generating a default config if none
   is already present or something along those lines)
@tycho

Yep. Already signed off on your version in the pull request. 😄

@behlendorf behlendorf added a commit that closed this issue May 26, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes #3440
544f718
@behlendorf behlendorf added a commit that referenced this issue May 27, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes #3440
4c05965
@kernelOfTruth kernelOfTruth added a commit to kernelOfTruth/zfs that referenced this issue Jun 8, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes #3440
6b57a91
@diametric diametric added a commit that referenced this issue Jun 23, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes #3440
1ae2bc2
@diametric diametric added a commit that referenced this issue Jun 23, 2015
@behlendorf behlendorf Use ExecStartPre to load zfs modules
Commit 87abfcb broke the systemd import service by treating the
ExecStart line as if it were a shell command that could be executed.
This isn't the way systemd works and the correct way to handle this
case is with ExecStartPre.  This patch updates the zfs import service
files accordingly,

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
Signed-off-by: Chris Siebenmann <cks.git01@cs.toronto.edu>
Closes #3440
8d333b7
@MorpheusTeam MorpheusTeam pushed a commit to Xyratex/lustre-stable that referenced this issue Aug 10, 2015
@utopiabound utopiabound LU-6791 build: Update ZFS/SPL version to 0.6.4.2
Updates ZFS and SPL to latest maintence version.  Includes the
following:

Bug Fixes:
* Fix panic due to corrupt nvlist when running utilities
(zfsonlinux/zfs#3335)
* Fix hard lockup due to infinite loop in zfs_zget()
(zfsonlinux/zfs#3349)
* Fix panic on unmount due to iput taskq (zfsonlinux/zfs#3281)
* Improve metadata shrinker performance on pre-3.1 kernels
(zfsonlinux/zfs#3501)
* Linux 4.1 compat: use read_iter() / write_iter()
* Linux 3.12 compat: NUMA-aware per-superblock shrinker
* Fix spurious hung task watchdog stack traces (zfsonlinux/zfs#3402)
* Fix module loading in zfs import systemd service
(zfsonlinux/zfs#3440)
* Fix intermittent libzfs_init() failure to open /dev/zfs
(zfsonlinux/zfs#2556)

Signed-off-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Change-Id: I053087317ff9e5bedc1671bb46062e96bfe6f074
Reviewed-on: http://review.whamcloud.com/15481
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Tested-by: Jenkins
Reviewed-by: Isaac Huang <he.huang@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
6923382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment