aboutsummaryrefslogtreecommitdiff
path: root/cddl/usr.sbin
diff options
context:
space:
mode:
authorAlan Somers <asomers@FreeBSD.org>2018-02-14 23:52:39 +0000
committerAlan Somers <asomers@FreeBSD.org>2018-02-14 23:52:39 +0000
commita07d59d1daafdaae0d1b1ad1f977f9eda92dc83b (patch)
tree48a11c58cadb77016854faba935c88f85787a347 /cddl/usr.sbin
parent27f6bdd04fe9f0fe8ce4ce1700948337b912d298 (diff)
downloadsrc-a07d59d1daafdaae0d1b1ad1f977f9eda92dc83b.tar.gz
src-a07d59d1daafdaae0d1b1ad1f977f9eda92dc83b.zip
zfsd: Allow zfsd to work on any type of GEOM provider
cddl/usr.sbin/zfsd/zfsd_event.cc Remove the check for da and ada devices. This way zfsd can work on md, geli, glabel, gstripe, etc devices. geli in particular is useful combined with ZFS. gnop is also useful for simulating drive pulls in the ZFSD test suite. Also, eliminate the DevfsEvent class entirely. Move its responsibilities into GeomEvent. We can get everything we need to know just from listening to GEOM events. lib/libdevdctl/event.cc Fix GeomEvent::DevName for CREATE events. Oddly, the relevant field is named "cdev" for CREATE events but "devname" for disk events. MFC after: 3 weeks Relnotes: Yes (probably worth mentioning the geli part) Sponsored by: Spectra Logic Corp
Notes
Notes: svn path=/head/; revision=329284
Diffstat (limited to 'cddl/usr.sbin')
-rw-r--r--cddl/usr.sbin/zfsd/zfsd.cc1
-rw-r--r--cddl/usr.sbin/zfsd/zfsd_event.cc247
-rw-r--r--cddl/usr.sbin/zfsd/zfsd_event.h90
3 files changed, 119 insertions, 219 deletions
diff --git a/cddl/usr.sbin/zfsd/zfsd.cc b/cddl/usr.sbin/zfsd/zfsd.cc
index 648455f1fefe..2f17b474e493 100644
--- a/cddl/usr.sbin/zfsd/zfsd.cc
+++ b/cddl/usr.sbin/zfsd/zfsd.cc
@@ -98,7 +98,6 @@ int ZfsDaemon::s_signalPipeFD[2];
bool ZfsDaemon::s_systemRescanRequested(false);
EventFactory::Record ZfsDaemon::s_registryEntries[] =
{
- { Event::NOTIFY, "DEVFS", &DevfsEvent::Builder },
{ Event::NOTIFY, "GEOM", &GeomEvent::Builder },
{ Event::NOTIFY, "ZFS", &ZfsEvent::Builder }
};
diff --git a/cddl/usr.sbin/zfsd/zfsd_event.cc b/cddl/usr.sbin/zfsd/zfsd_event.cc
index 5594b35a88a8..50da07631d5a 100644
--- a/cddl/usr.sbin/zfsd/zfsd_event.cc
+++ b/cddl/usr.sbin/zfsd/zfsd_event.cc
@@ -76,111 +76,32 @@ using std::stringstream;
/*=========================== Class Implementations ==========================*/
-/*-------------------------------- DevfsEvent --------------------------------*/
+/*-------------------------------- GeomEvent --------------------------------*/
-//- DevfsEvent Static Public Methods -------------------------------------------
+//- GeomEvent Static Public Methods -------------------------------------------
Event *
-DevfsEvent::Builder(Event::Type type,
- NVPairMap &nvPairs,
- const string &eventString)
-{
- return (new DevfsEvent(type, nvPairs, eventString));
-}
-
-//- DevfsEvent Static Protected Methods ----------------------------------------
-nvlist_t *
-DevfsEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
-{
- pool_state_t poolState;
- char *poolName;
- boolean_t b_inuse;
- int nlabels;
-
- inUse = false;
- degraded = false;
- poolName = NULL;
- if (zpool_in_use(g_zfsHandle, devFd, &poolState,
- &poolName, &b_inuse) == 0) {
- nvlist_t *devLabel = NULL;
-
- inUse = b_inuse == B_TRUE;
- if (poolName != NULL)
- free(poolName);
-
- nlabels = zpool_read_all_labels(devFd, &devLabel);
- /*
- * If we find a disk with fewer than the maximum number of
- * labels, it might be the whole disk of a partitioned disk
- * where ZFS resides on a partition. In that case, we should do
- * nothing and wait for the partition to appear. Or, the disk
- * might be damaged. In that case, zfsd should do nothing and
- * wait for the sysadmin to decide.
- */
- if (nlabels != VDEV_LABELS || devLabel == NULL) {
- nvlist_free(devLabel);
- return (NULL);
- }
-
- try {
- Vdev vdev(devLabel);
- degraded = vdev.State() != VDEV_STATE_HEALTHY;
- return (devLabel);
- } catch (ZfsdException &exp) {
- string devName = fdevname(devFd);
- string devPath = _PATH_DEV + devName;
- string context("DevfsEvent::ReadLabel: "
- + devPath + ": ");
-
- exp.GetString().insert(0, context);
- exp.Log();
- nvlist_free(devLabel);
- }
- }
- return (NULL);
-}
-
-bool
-DevfsEvent::OnlineByLabel(const string &devPath, const string& physPath,
- nvlist_t *devConfig)
+GeomEvent::Builder(Event::Type type,
+ NVPairMap &nvPairs,
+ const string &eventString)
{
- try {
- /*
- * A device with ZFS label information has been
- * inserted. If it matches a device for which we
- * have a case, see if we can solve that case.
- */
- syslog(LOG_INFO, "Interrogating VDEV label for %s\n",
- devPath.c_str());
- Vdev vdev(devConfig);
- CaseFile *caseFile(CaseFile::Find(vdev.PoolGUID(),
- vdev.GUID()));
- if (caseFile != NULL)
- return (caseFile->ReEvaluate(devPath, physPath, &vdev));
-
- } catch (ZfsdException &exp) {
- string context("DevfsEvent::OnlineByLabel: " + devPath + ": ");
-
- exp.GetString().insert(0, context);
- exp.Log();
- }
- return (false);
+ return (new GeomEvent(type, nvPairs, eventString));
}
-//- DevfsEvent Virtual Public Methods ------------------------------------------
+//- GeomEvent Virtual Public Methods ------------------------------------------
Event *
-DevfsEvent::DeepCopy() const
+GeomEvent::DeepCopy() const
{
- return (new DevfsEvent(*this));
+ return (new GeomEvent(*this));
}
-
+
bool
-DevfsEvent::Process() const
+GeomEvent::Process() const
{
/*
- * We are only concerned with newly discovered
- * devices that can be ZFS vdevs.
+ * We are only concerned with create arrivals and physical path changes,
+ * because those can be used to satisfy online and autoreplace operations
*/
- if (Value("type") != "CREATE" || !IsDiskDev())
+ if (Value("type") != "GEOM::physpath" && Value("type") != "CREATE")
return (false);
/* Log the event since it is of interest. */
@@ -199,7 +120,7 @@ DevfsEvent::Process() const
nvlist_t *devLabel(ReadLabel(devFd, inUse, degraded));
string physPath;
- bool havePhysPath(PhysicalPath(physPath));
+ bool havePhysPath(PhysicalPath(physPath));
string devName;
DevName(devName);
@@ -211,8 +132,8 @@ DevfsEvent::Process() const
syslog(LOG_INFO, "%s is marked degraded. Ignoring "
"as a replace by physical path candidate.\n",
devName.c_str());
- } else if (havePhysPath && IsWholeDev()) {
- /*
+ } else if (havePhysPath) {
+ /*
* TODO: attempt to resolve events using every casefile
* that matches this physpath
*/
@@ -227,93 +148,97 @@ DevfsEvent::Process() const
caseFile->ReEvaluate(devPath, physPath, /*vdev*/NULL);
}
}
- if (devLabel != NULL)
- nvlist_free(devLabel);
return (false);
}
-//- DevfsEvent Protected Methods -----------------------------------------------
-DevfsEvent::DevfsEvent(Event::Type type, NVPairMap &nvpairs,
+//- GeomEvent Protected Methods -----------------------------------------------
+GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
const string &eventString)
- : DevdCtl::DevfsEvent(type, nvpairs, eventString)
-{
-}
-
-DevfsEvent::DevfsEvent(const DevfsEvent &src)
- : DevdCtl::DevfsEvent::DevfsEvent(src)
+ : DevdCtl::GeomEvent(type, nvpairs, eventString)
{
}
-/*-------------------------------- GeomEvent --------------------------------*/
-
-//- GeomEvent Static Public Methods -------------------------------------------
-Event *
-GeomEvent::Builder(Event::Type type,
- NVPairMap &nvPairs,
- const string &eventString)
+GeomEvent::GeomEvent(const GeomEvent &src)
+ : DevdCtl::GeomEvent::GeomEvent(src)
{
- return (new GeomEvent(type, nvPairs, eventString));
}
-//- GeomEvent Virtual Public Methods ------------------------------------------
-Event *
-GeomEvent::DeepCopy() const
-{
- return (new GeomEvent(*this));
-}
-
-bool
-GeomEvent::Process() const
+nvlist_t *
+GeomEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
{
- /*
- * We are only concerned with physical path changes, because those can
- * be used to satisfy autoreplace operations
- */
- if (Value("type") != "GEOM::physpath" || !IsDiskDev())
- return (false);
+ pool_state_t poolState;
+ char *poolName;
+ boolean_t b_inuse;
+ int nlabels;
- /* Log the event since it is of interest. */
- Log(LOG_INFO);
+ inUse = false;
+ degraded = false;
+ poolName = NULL;
+ if (zpool_in_use(g_zfsHandle, devFd, &poolState,
+ &poolName, &b_inuse) == 0) {
+ nvlist_t *devLabel = NULL;
- string devPath;
- if (!DevPath(devPath))
- return (false);
+ inUse = b_inuse == B_TRUE;
+ if (poolName != NULL)
+ free(poolName);
- string physPath;
- bool havePhysPath(PhysicalPath(physPath));
+ nlabels = zpool_read_all_labels(devFd, &devLabel);
+ /*
+ * If we find a disk with fewer than the maximum number of
+ * labels, it might be the whole disk of a partitioned disk
+ * where ZFS resides on a partition. In that case, we should do
+ * nothing and wait for the partition to appear. Or, the disk
+ * might be damaged. In that case, zfsd should do nothing and
+ * wait for the sysadmin to decide.
+ */
+ if (nlabels != VDEV_LABELS || devLabel == NULL) {
+ nvlist_free(devLabel);
+ return (NULL);
+ }
- string devName;
- DevName(devName);
+ try {
+ Vdev vdev(devLabel);
+ degraded = vdev.State() != VDEV_STATE_HEALTHY;
+ return (devLabel);
+ } catch (ZfsdException &exp) {
+ string devName = fdevname(devFd);
+ string devPath = _PATH_DEV + devName;
+ string context("GeomEvent::ReadLabel: "
+ + devPath + ": ");
- if (havePhysPath) {
- /*
- * TODO: attempt to resolve events using every casefile
- * that matches this physpath
- */
- CaseFile *caseFile(CaseFile::Find(physPath));
- if (caseFile != NULL) {
- syslog(LOG_INFO,
- "Found CaseFile(%s:%s:%s) - ReEvaluating\n",
- caseFile->PoolGUIDString().c_str(),
- caseFile->VdevGUIDString().c_str(),
- zpool_state_to_name(caseFile->VdevState(),
- VDEV_AUX_NONE));
- caseFile->ReEvaluate(devPath, physPath, /*vdev*/NULL);
+ exp.GetString().insert(0, context);
+ exp.Log();
+ nvlist_free(devLabel);
}
}
- return (false);
+ return (NULL);
}
-//- GeomEvent Protected Methods -----------------------------------------------
-GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
- const string &eventString)
- : DevdCtl::GeomEvent(type, nvpairs, eventString)
+bool
+GeomEvent::OnlineByLabel(const string &devPath, const string& physPath,
+ nvlist_t *devConfig)
{
-}
+ try {
+ /*
+ * A device with ZFS label information has been
+ * inserted. If it matches a device for which we
+ * have a case, see if we can solve that case.
+ */
+ syslog(LOG_INFO, "Interrogating VDEV label for %s\n",
+ devPath.c_str());
+ Vdev vdev(devConfig);
+ CaseFile *caseFile(CaseFile::Find(vdev.PoolGUID(),
+ vdev.GUID()));
+ if (caseFile != NULL)
+ return (caseFile->ReEvaluate(devPath, physPath, &vdev));
-GeomEvent::GeomEvent(const GeomEvent &src)
- : DevdCtl::GeomEvent::GeomEvent(src)
-{
+ } catch (ZfsdException &exp) {
+ string context("GeomEvent::OnlineByLabel: " + devPath + ": ");
+
+ exp.GetString().insert(0, context);
+ exp.Log();
+ }
+ return (false);
}
diff --git a/cddl/usr.sbin/zfsd/zfsd_event.h b/cddl/usr.sbin/zfsd/zfsd_event.h
index c4ba422ee15a..fd3f9f7c5200 100644
--- a/cddl/usr.sbin/zfsd/zfsd_event.h
+++ b/cddl/usr.sbin/zfsd/zfsd_event.h
@@ -60,63 +60,6 @@ typedef struct zpool_handle zpool_handle_t;
struct nvlist;
typedef struct nvlist nvlist_t;
-/*============================= Class Definitions ============================*/
-/*-------------------------------- DevfsEvent --------------------------------*/
-class DevfsEvent : public DevdCtl::DevfsEvent
-{
-public:
- /** Specialized DevdCtlEvent object factory for Devfs events. */
- static BuildMethod Builder;
-
- virtual DevdCtl::Event *DeepCopy() const;
-
- /**
- * Interpret and perform any actions necessary to
- * consume the event.
- * \return True if this event should be queued for later reevaluation
- */
- virtual bool Process() const;
-
-protected:
- /**
- * \brief Read and return label information for a device.
- *
- * \param devFd The device from which to read ZFS label information.
- * \param inUse The device is part of an active or potentially
- * active configuration.
- * \param degraded The device label indicates the vdev is not healthy.
- *
- * \return If label information is available, an nvlist describing
- * the vdev configuraiton found on the device specified by
- * devFd. Otherwise NULL.
- */
- static nvlist_t *ReadLabel(int devFd, bool &inUse, bool &degraded);
-
- /**
- * Attempt to match the ZFS labeled device at devPath with an active
- * CaseFile for a missing vdev. If a CaseFile is found, attempt
- * to re-integrate the device with its pool.
- *
- * \param devPath The devfs path to the potential leaf vdev.
- * \param physPath The physical path string reported by the device
- * at devPath.
- * \param devConfig The ZFS label information found on the device
- * at devPath.
- *
- * \return true if the event that caused the online action can
- * be considered consumed.
- */
- static bool OnlineByLabel(const string &devPath,
- const string& physPath,
- nvlist_t *devConfig);
-
- /** DeepCopy Constructor. */
- DevfsEvent(const DevfsEvent &src);
-
- /** Constructor */
- DevfsEvent(Type, DevdCtl::NVPairMap &, const string &);
-};
-
/*--------------------------------- ZfsEvent ---------------------------------*/
class ZfsEvent : public DevdCtl::ZfsEvent
{
@@ -164,5 +107,38 @@ protected:
/** Constructor */
GeomEvent(Type, DevdCtl::NVPairMap &, const string &);
+
+ /**
+ * Attempt to match the ZFS labeled device at devPath with an active
+ * CaseFile for a missing vdev. If a CaseFile is found, attempt
+ * to re-integrate the device with its pool.
+ *
+ * \param devPath The devfs path to the potential leaf vdev.
+ * \param physPath The physical path string reported by the device
+ * at devPath.
+ * \param devConfig The ZFS label information found on the device
+ * at devPath.
+ *
+ * \return true if the event that caused the online action can
+ * be considered consumed.
+ */
+ static bool OnlineByLabel(const string &devPath,
+ const string& physPath,
+ nvlist_t *devConfig);
+
+ /**
+ * \brief Read and return label information for a device.
+ *
+ * \param devFd The device from which to read ZFS label information.
+ * \param inUse The device is part of an active or potentially
+ * active configuration.
+ * \param degraded The device label indicates the vdev is not healthy.
+ *
+ * \return If label information is available, an nvlist describing
+ * the vdev configuraiton found on the device specified by
+ * devFd. Otherwise NULL.
+ */
+ static nvlist_t *ReadLabel(int devFd, bool &inUse, bool &degraded);
+
};
#endif /*_ZFSD_EVENT_H_ */