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
This commit is contained in:
Alan Somers 2018-02-14 23:52:39 +00:00
parent 27f6bdd04f
commit a07d59d1da
4 changed files with 123 additions and 220 deletions

View File

@ -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 }
};

View File

@ -76,20 +76,95 @@ 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)
GeomEvent::Builder(Event::Type type,
NVPairMap &nvPairs,
const string &eventString)
{
return (new GeomEvent(type, nvPairs, eventString));
}
//- GeomEvent Virtual Public Methods ------------------------------------------
Event *
GeomEvent::DeepCopy() const
{
return (new GeomEvent(*this));
}
bool
GeomEvent::Process() const
{
/*
* 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") != "GEOM::physpath" && Value("type") != "CREATE")
return (false);
/* Log the event since it is of interest. */
Log(LOG_INFO);
string devPath;
if (!DevPath(devPath))
return (false);
int devFd(open(devPath.c_str(), O_RDONLY));
if (devFd == -1)
return (false);
bool inUse;
bool degraded;
nvlist_t *devLabel(ReadLabel(devFd, inUse, degraded));
string physPath;
bool havePhysPath(PhysicalPath(physPath));
string devName;
DevName(devName);
close(devFd);
if (inUse && devLabel != NULL) {
OnlineByLabel(devPath, physPath, devLabel);
} else if (degraded) {
syslog(LOG_INFO, "%s is marked degraded. Ignoring "
"as a replace by physical path candidate.\n",
devName.c_str());
} else 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);
}
}
return (false);
}
//- GeomEvent Protected Methods -----------------------------------------------
GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
const string &eventString)
: DevdCtl::GeomEvent(type, nvpairs, eventString)
{
}
GeomEvent::GeomEvent(const GeomEvent &src)
: DevdCtl::GeomEvent::GeomEvent(src)
{
return (new DevfsEvent(type, nvPairs, eventString));
}
//- DevfsEvent Static Protected Methods ----------------------------------------
nvlist_t *
DevfsEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
GeomEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
{
pool_state_t poolState;
char *poolName;
@ -128,7 +203,7 @@ DevfsEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
} catch (ZfsdException &exp) {
string devName = fdevname(devFd);
string devPath = _PATH_DEV + devName;
string context("DevfsEvent::ReadLabel: "
string context("GeomEvent::ReadLabel: "
+ devPath + ": ");
exp.GetString().insert(0, context);
@ -140,7 +215,7 @@ DevfsEvent::ReadLabel(int devFd, bool &inUse, bool &degraded)
}
bool
DevfsEvent::OnlineByLabel(const string &devPath, const string& physPath,
GeomEvent::OnlineByLabel(const string &devPath, const string& physPath,
nvlist_t *devConfig)
{
try {
@ -158,7 +233,7 @@ DevfsEvent::OnlineByLabel(const string &devPath, const string& physPath,
return (caseFile->ReEvaluate(devPath, physPath, &vdev));
} catch (ZfsdException &exp) {
string context("DevfsEvent::OnlineByLabel: " + devPath + ": ");
string context("GeomEvent::OnlineByLabel: " + devPath + ": ");
exp.GetString().insert(0, context);
exp.Log();
@ -166,156 +241,6 @@ DevfsEvent::OnlineByLabel(const string &devPath, const string& physPath,
return (false);
}
//- DevfsEvent Virtual Public Methods ------------------------------------------
Event *
DevfsEvent::DeepCopy() const
{
return (new DevfsEvent(*this));
}
bool
DevfsEvent::Process() const
{
/*
* We are only concerned with newly discovered
* devices that can be ZFS vdevs.
*/
if (Value("type") != "CREATE" || !IsDiskDev())
return (false);
/* Log the event since it is of interest. */
Log(LOG_INFO);
string devPath;
if (!DevPath(devPath))
return (false);
int devFd(open(devPath.c_str(), O_RDONLY));
if (devFd == -1)
return (false);
bool inUse;
bool degraded;
nvlist_t *devLabel(ReadLabel(devFd, inUse, degraded));
string physPath;
bool havePhysPath(PhysicalPath(physPath));
string devName;
DevName(devName);
close(devFd);
if (inUse && devLabel != NULL) {
OnlineByLabel(devPath, physPath, devLabel);
} else if (degraded) {
syslog(LOG_INFO, "%s is marked degraded. Ignoring "
"as a replace by physical path candidate.\n",
devName.c_str());
} else if (havePhysPath && IsWholeDev()) {
/*
* 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);
}
}
if (devLabel != NULL)
nvlist_free(devLabel);
return (false);
}
//- DevfsEvent Protected Methods -----------------------------------------------
DevfsEvent::DevfsEvent(Event::Type type, NVPairMap &nvpairs,
const string &eventString)
: DevdCtl::DevfsEvent(type, nvpairs, eventString)
{
}
DevfsEvent::DevfsEvent(const DevfsEvent &src)
: DevdCtl::DevfsEvent::DevfsEvent(src)
{
}
/*-------------------------------- GeomEvent --------------------------------*/
//- GeomEvent Static Public Methods -------------------------------------------
Event *
GeomEvent::Builder(Event::Type type,
NVPairMap &nvPairs,
const string &eventString)
{
return (new GeomEvent(type, nvPairs, eventString));
}
//- GeomEvent Virtual Public Methods ------------------------------------------
Event *
GeomEvent::DeepCopy() const
{
return (new GeomEvent(*this));
}
bool
GeomEvent::Process() const
{
/*
* 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);
/* Log the event since it is of interest. */
Log(LOG_INFO);
string devPath;
if (!DevPath(devPath))
return (false);
string physPath;
bool havePhysPath(PhysicalPath(physPath));
string devName;
DevName(devName);
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);
}
}
return (false);
}
//- GeomEvent Protected Methods -----------------------------------------------
GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs,
const string &eventString)
: DevdCtl::GeomEvent(type, nvpairs, eventString)
{
}
GeomEvent::GeomEvent(const GeomEvent &src)
: DevdCtl::GeomEvent::GeomEvent(src)
{
}
/*--------------------------------- ZfsEvent ---------------------------------*/
//- ZfsEvent Static Public Methods ---------------------------------------------

View File

@ -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 @@ class GeomEvent : public DevdCtl::GeomEvent
/** 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_ */

View File

@ -542,7 +542,10 @@ GeomEvent::DeepCopy() const
bool
GeomEvent::DevName(std::string &name) const
{
name = Value("devname");
if (Value("subsystem") == "disk")
name = Value("devname");
else
name = Value("cdev");
return (!name.empty());
}