Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

siebenmann opened this issue May 25, 2015 · 9 comments

Comments

@siebenmann
Copy link
Contributor

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
Copy link
Contributor

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

@siebenmann
Copy link
Contributor Author

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
Copy link
Contributor

tycho commented May 26, 2015

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
Copy link
Contributor

@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 added a commit to behlendorf/zfs that referenced this issue May 26, 2015
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 <[email protected]>
Issue openzfs#3440
@behlendorf
Copy link
Contributor

@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
Copy link
Contributor

tycho commented May 26, 2015

@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
Copy link
Contributor

tycho commented May 26, 2015

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
Copy link
Contributor

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
Copy link
Contributor

tycho commented May 26, 2015

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

behlendorf added a commit that referenced this issue May 27, 2015
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 <[email protected]>
Signed-off-by: Steven Noonan <[email protected]>
Signed-off-by: Chris Siebenmann <[email protected]>
Closes #3440
kernelOfTruth pushed a commit to kernelOfTruth/zfs that referenced this issue Jun 8, 2015
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 <[email protected]>
Signed-off-by: Steven Noonan <[email protected]>
Signed-off-by: Chris Siebenmann <[email protected]>
Closes openzfs#3440
MorpheusTeam pushed a commit to Xyratex/lustre-stable that referenced this issue Aug 10, 2015
Updates ZFS and SPL to latest maintence version.  Includes the
following:

Bug Fixes:
* Fix panic due to corrupt nvlist when running utilities
(openzfs/zfs#3335)
* Fix hard lockup due to infinite loop in zfs_zget()
(openzfs/zfs#3349)
* Fix panic on unmount due to iput taskq (openzfs/zfs#3281)
* Improve metadata shrinker performance on pre-3.1 kernels
(openzfs/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 (openzfs/zfs#3402)
* Fix module loading in zfs import systemd service
(openzfs/zfs#3440)
* Fix intermittent libzfs_init() failure to open /dev/zfs
(openzfs/zfs#2556)

Signed-off-by: Nathaniel Clark <[email protected]>
Change-Id: I053087317ff9e5bedc1671bb46062e96bfe6f074
Reviewed-on: http://review.whamcloud.com/15481
Reviewed-by: Alex Zhuravlev <[email protected]>
Tested-by: Jenkins
Reviewed-by: Isaac Huang <[email protected]>
Tested-by: Maloo <[email protected]>
Reviewed-by: Oleg Drokin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants