git: b969a40cdf17 - stable/13 - zfsd: listen for sysevent.fs.zfs instead of misc.fs.zfs

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Wed, 06 Sep 2023 21:49:20 UTC
The branch stable/13 has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=b969a40cdf17c0242740748ec66433b7bd84f503

commit b969a40cdf17c0242740748ec66433b7bd84f503
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2023-04-03 21:45:55 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2023-09-06 21:48:55 +0000

    zfsd: listen for sysevent.fs.zfs instead of misc.fs.zfs
    
    At some point the names of these devd events changed.  Probably it
    happened when importing OpenZFS.  Before that, FreeBSD's sysevent_alloc
    method didn't create a "class" nvpair in the event, which led to
    log_sysevent using the event's ev_subclass field as its type.
    
    Sponsored by:   Axcient
    Differential Revision: https://reviews.freebsd.org/D39437
    
    (cherry picked from commit 92642bba4db4bf1719758ac7233468bc09a0bd59)
    
    Fix zfsd unittests after 92642bba4db
    
    At the time we ensured that the more important functional tests were
    working, but neglected to update the unit tests.
    
    Sponsored by:   Axcient
    
    (cherry picked from commit 2a0c0aea42092f89c2a5345991e6e3ce4cbef99a)
---
 cddl/usr.sbin/zfsd/case_file.cc           |  6 +++---
 cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc |  6 +++---
 cddl/usr.sbin/zfsd/zfsd.cc                |  2 +-
 cddl/usr.sbin/zfsd/zfsd_event.cc          | 10 +++++-----
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/cddl/usr.sbin/zfsd/case_file.cc b/cddl/usr.sbin/zfsd/case_file.cc
index e04dc4e6928d..ad3bb0ffc538 100644
--- a/cddl/usr.sbin/zfsd/case_file.cc
+++ b/cddl/usr.sbin/zfsd/case_file.cc
@@ -357,7 +357,7 @@ CaseFile::ReEvaluate(const ZfsEvent &event)
 {
 	bool consumed(false);
 
-	if (event.Value("type") == "misc.fs.zfs.vdev_remove") {
+	if (event.Value("type") == "sysevent.fs.zfs.vdev_remove") {
 		/*
 		 * The Vdev we represent has been removed from the
 		 * configuration.  This case is no longer of value.
@@ -365,12 +365,12 @@ CaseFile::ReEvaluate(const ZfsEvent &event)
 		Close();
 
 		return (/*consumed*/true);
-	} else if (event.Value("type") == "misc.fs.zfs.pool_destroy") {
+	} else if (event.Value("type") == "sysevent.fs.zfs.pool_destroy") {
 		/* This Pool has been destroyed.  Discard the case */
 		Close();
 
 		return (/*consumed*/true);
-	} else if (event.Value("type") == "misc.fs.zfs.config_sync") {
+	} else if (event.Value("type") == "sysevent.fs.zfs.config_sync") {
 		RefreshVdevState();
 		if (VdevState() < VDEV_STATE_HEALTHY)
 			consumed = ActivateSpare();
diff --git a/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc b/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc
index 496be07aece9..f3fea2ca83f4 100644
--- a/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc
+++ b/cddl/usr.sbin/zfsd/tests/zfsd_unittest.cc
@@ -397,7 +397,7 @@ TEST_F(ZfsEventTest, ProcessPoolEventGetsCalled)
 {
 	string evString("!system=ZFS "
 			"subsystem=ZFS "
-			"type=misc.fs.zfs.vdev_remove "
+			"type=sysevent.fs.zfs.vdev_remove "
 			"pool_name=foo "
 			"pool_guid=9756779504028057996 "
 			"vdev_guid=1631193447431603339 "
@@ -512,7 +512,7 @@ TEST_F(CaseFileTest, PoolDestroy)
 			"pool_guid=456 "
 			"subsystem=ZFS "
 			"timestamp=1348867914 "
-			"type=misc.fs.zfs.pool_destroy ");
+			"type=sysevent.fs.zfs.pool_destroy ");
 	m_event = Event::CreateEvent(*m_eventFactory, evString);
 	ZfsEvent *zfs_event = static_cast<ZfsEvent*>(m_event);
 	EXPECT_CALL(*m_caseFile, Close());
@@ -682,7 +682,7 @@ string ReEvaluateByGuidTest::s_evString(
 	"pool_name=foo "
 	"subsystem=ZFS "
 	"timestamp=1360620391 "
-	"type=misc.fs.zfs.config_sync");
+	"type=sysevent.fs.zfs.config_sync");
 
 
 /*
diff --git a/cddl/usr.sbin/zfsd/zfsd.cc b/cddl/usr.sbin/zfsd/zfsd.cc
index 4d9e82008148..210cc4b85a44 100644
--- a/cddl/usr.sbin/zfsd/zfsd.cc
+++ b/cddl/usr.sbin/zfsd/zfsd.cc
@@ -245,7 +245,7 @@ ZfsDaemon::BuildCaseFiles()
 
 		
 		snprintf(evString, 160, "!system=ZFS subsystem=ZFS "
-		    "type=misc.fs.zfs.config_sync sub_type=synthesized "
+		    "type=sysevent.fs.zfs.config_sync sub_type=synthesized "
 		    "pool_name=%s pool_guid=%" PRIu64 "\n", poolname, poolGUID);
 		event = Event::CreateEvent(GetFactory(), string(evString));
 		if (event != NULL) {
diff --git a/cddl/usr.sbin/zfsd/zfsd_event.cc b/cddl/usr.sbin/zfsd/zfsd_event.cc
index c333f57f9a18..5cb17192d8e5 100644
--- a/cddl/usr.sbin/zfsd/zfsd_event.cc
+++ b/cddl/usr.sbin/zfsd/zfsd_event.cc
@@ -279,7 +279,7 @@ ZfsEvent::Process() const
 	}
 
 	/* On config syncs, replay any queued events first. */
-	if (Value("type").find("misc.fs.zfs.config_sync") == 0) {
+	if (Value("type").find("sysevent.fs.zfs.config_sync") == 0) {
 		/*
 		 * Even if saved events are unconsumed the second time
 		 * around, drop them.  Any events that still can't be
@@ -290,7 +290,7 @@ ZfsEvent::Process() const
 		CaseFile::ReEvaluateByGuid(PoolGUID(), *this);
 	}
 
-	if (Value("type").find("misc.fs.zfs.") == 0) {
+	if (Value("type").find("sysevent.fs.zfs.") == 0) {
 		/* Configuration changes, resilver events, etc. */
 		ProcessPoolEvent();
 		return (false);
@@ -403,7 +403,7 @@ ZfsEvent::ProcessPoolEvent() const
 	bool degradedDevice(false);
 
 	/* The pool is destroyed.  Discard any open cases */
-	if (Value("type") == "misc.fs.zfs.pool_destroy") {
+	if (Value("type") == "sysevent.fs.zfs.pool_destroy") {
 		Log(LOG_INFO);
 		CaseFile::ReEvaluateByGuid(PoolGUID(), *this);
 		return;
@@ -418,7 +418,7 @@ ZfsEvent::ProcessPoolEvent() const
 		Log(LOG_INFO);
 		caseFile->ReEvaluate(*this);
 	}
-	else if (Value("type") == "misc.fs.zfs.resilver_finish")
+	else if (Value("type") == "sysevent.fs.zfs.resilver_finish")
 	{
 		/*
 		 * It's possible to get a resilver_finish event with no
@@ -429,7 +429,7 @@ ZfsEvent::ProcessPoolEvent() const
 		CleanupSpares();
 	}
 
-	if (Value("type") == "misc.fs.zfs.vdev_remove"
+	if (Value("type") == "sysevent.fs.zfs.vdev_remove"
 	 && degradedDevice == false) {
 
 		/* See if any other cases can make use of this device. */