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

Add events to zed and minor tweaks. #12416

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

lundman
Copy link
Contributor

@lundman lundman commented Jul 22, 2021

Collected all zed changes into one PR.

Motivation and Context

Description

This PR comes in 3 parts;

  1. Add events for macOS, mounting snapshots, creating zvol symlinks
  2. Work around different pthread setname. macOS can only set name from child thread.
  3. Compile fixes for Werror, add includes etc.

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

@lundman lundman mentioned this pull request Jul 22, 2021
13 tasks
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jul 26, 2021
@tonyhutter
Copy link
Contributor

@lundman I'm back from vacation - I'll take a look at this.

module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
@tonyhutter
Copy link
Contributor

Would you mind squashing these commits? There seems to be some churn between them.

@lundman
Copy link
Contributor Author

lundman commented Aug 4, 2021

Would you mind squashing these commits? There seems to be some churn between them.

Not at all, one-commit next push.

module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
@lundman
Copy link
Contributor Author

lundman commented Aug 25, 2021

I'm also wondering if for the pthread names, instead of #ifdefs everywhere, perhaps we could define 2 macros:
zfs_pthread_setname(1 arg)
zfs_pthread_setname_tid(2 args)

use both args in zed source files, but one macro is empty, depending on platform?

@tonyhutter
Copy link
Contributor

I personally like the more verbose #ifdefs, because it's apparent that you're doing something special for OSX for the pthread names. If you use the macros, it could lead the casual reader getting confused:

        pthread_setname_tid(g_agents_tid, "agents");
	< spawn thread>
	        pthread_setname("agents");

"dude... why is it setting the thread name twice?"

include/sys/fm/fs/zfs.h Outdated Show resolved Hide resolved
@tonyhutter
Copy link
Contributor

Once the last two outstanding comments get fixed, I think this will be good to go.

@lundman
Copy link
Contributor Author

lundman commented Sep 1, 2021

I believe I have updated for both comments, let me know if you want further tweaking.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

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

I really don't have a good solution to the pthread_setname_np() issue since it's used so differently. It seems like we might need to live with the #ifdefs.

It seems to me it would be useful to post these new events on all platforms. That would allow users to create their own zedlets to do interesting things with them. Even if we still for example on Linux rely on udev to create the links and not the ZED. Plus it means we won't be merging any dead code with this PR, which would be good.

cmd/zed/agents/zfs_retire.c Outdated Show resolved Hide resolved
cmd/zed/zed_conf.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
module/zfs/zfs_fm.c Outdated Show resolved Hide resolved
@lundman lundman force-pushed the macOS_pr27 branch 4 times, most recently from 4515062 to c5f227a Compare September 3, 2021 00:52
For kernel to send snapshot mount/unmount events to zed.

For kernel to send symlink creates/removes on zvol plumbing.
(/dev/run/dsk/zvol/$pool/$zvol -> /dev/diskX)

If zed misses the ENODEV, all errors after are EINVAL. Treat any error
as kernel module failure.

Signed-off-by: Jorgen Lundman <[email protected]>
Copy link
Contributor

@tonyhutter tonyhutter left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this @lundman

@lundman
Copy link
Contributor Author

lundman commented Sep 7, 2021

I'm just happy we are allowed to use zed - otherwise we'd have to write our own ;)

@behlendorf
Copy link
Contributor

Just a matter of figuring out where in fbsd/linux to place the calls.

For Linux you'll want to place the call in the error == 0 block at the end of zvol_os_create_minor(). It looks like a pretty similar story for FreeBSD with zvol_create_minor_impl(). Though looking it this again two more questions come to mind.

  1. Do we really want the kernel to provide a normal and raw symlink path in the event? I may be biased because of how udev works, but it seems like we'd want to leave this policy decision in user space and let the zedlet construct the right path from the zvol name.
  2. There's also the zvol_rename_minor() functionality which has basically this same problem. Was the intent to generate this same event for renames? We also had a hook for deleting the symlink in another PR, right?

The zedlets would need something like #if linux // do nothing #else if macOS // "zfs mount"

Yes, that's pretty much what I had in mind. Although now I'm second guessing myself since I'm not sure we really have a solid use case for it yet on other platforms. For the moments let's leave it as you had it originally and not call zfs_ereport_snapshot_post() from anywhere yet.

@lundman
Copy link
Contributor Author

lundman commented Sep 8, 2021

Do we really want the kernel to provide a normal and raw symlink path in the event? I may be biased because of how udev works, but it seems like we'd want to leave this policy decision in user space and let the zedlet construct the right path from the zvol name.

I think your device names makes sense on linux, I don't actually know what udev produces? At least on illumos, you know the zvol is /dev/zvol/dsk/$pool/$volume right, is that what you mean? On macOS, you don't know what it will be called. So I have to pass the /dev/disk15 (or whatever it might be), so we can make the (user friendly) named-symlink /var/run/zfs/zvol/dsk/$pool/$volume to point to it. It's hard to stick /dev/disk15 into say /etc/fstab if the device gets called /dev/disk14 next boot.

The zedlet only get pool/volume and /dev/disk15. Then it generated the symlink name;
https://github.com/openzfsonosx/openzfs/blob/development/cmd/zed/zed.d/zvol.create.sh
However, there is the raw disk /dev/rdisk15. macOS doesn't need it, and can probably guess/generate it. I left it in just in-case some future OS has something unrelated. But maybe that is a bit premature.

Yes, that's pretty much what I had in mind. Although now I'm second guessing myself

Leaving it as it is.

@behlendorf
Copy link
Contributor

Thanks for linking the zedlet that helped clear things up. I see what you're saying, that makes sense. Just thinking out loud, but would having the device major:minor numbers be helpful as well?

I don't actually know what udev produces?

That's actually sounds pretty similar to how it currently works on Linux. In the udev event we actually only get the /dev/disk15 (or whatever) path and not the pool/dataset name so we need to invoke a small helper utility called zvol_id which does an ioctl() on the new block device to look it up. At least with a zed event you'll get the device name and pool/dataset name which is nice, so that's an improvement.

@lundman
Copy link
Contributor Author

lundman commented Sep 8, 2021

Passing along major,minor could be useful for some platforms, sort of the future guessing I was trying to do with raw-device name.

Any changes desired for this PR?

@behlendorf
Copy link
Contributor

@lundman I think I've derailed things enough for the time being. Since we've got the needed reviews let me just go ahead and get this merged so you can build on it. Thanks for your patience!

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Sep 9, 2021
@behlendorf behlendorf merged commit 5a54a4e into openzfs:master Sep 9, 2021
rincebrain pushed a commit to rincebrain/zfs that referenced this pull request Sep 22, 2021
For kernel to send snapshot mount/unmount events to zed.

For kernel to send symlink creates/removes on zvol plumbing.
(/dev/run/dsk/zvol/$pool/$zvol -> /dev/diskX)

If zed misses the ENODEV, all errors after are EINVAL. Treat any error
as kernel module failure.

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Jorgen Lundman <[email protected]>
Closes openzfs#12416
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Feb 10, 2022
For kernel to send snapshot mount/unmount events to zed.

For kernel to send symlink creates/removes on zvol plumbing.
(/dev/run/dsk/zvol/$pool/$zvol -> /dev/diskX)

If zed misses the ENODEV, all errors after are EINVAL. Treat any error
as kernel module failure.

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Jorgen Lundman <[email protected]>
Closes openzfs#12416
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants