Index: head/cddl/usr.sbin/zfsd/zfsd.cc =================================================================== --- head/cddl/usr.sbin/zfsd/zfsd.cc (revision 329283) +++ head/cddl/usr.sbin/zfsd/zfsd.cc (revision 329284) @@ -1,448 +1,447 @@ /*- * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * Authors: Justin T. Gibbs (Spectra Logic Corporation) */ /** * \file zfsd.cc * * The ZFS daemon consumes kernel devdctl(4) event data via devd(8)'s * unix domain socket in order to react to system changes that impact * the function of ZFS storage pools. The goal of this daemon is to * provide similar functionality to the Solaris ZFS Diagnostic Engine * (zfs-diagnosis), the Solaris ZFS fault handler (zfs-retire), and * the Solaris ZFS vdev insertion agent (zfs-mod sysevent handler). */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "callout.h" #include "vdev_iterator.h" #include "zfsd_event.h" #include "case_file.h" #include "vdev.h" #include "vdev_iterator.h" #include "zfsd.h" #include "zfsd_exception.h" #include "zpool_list.h" __FBSDID("$FreeBSD$"); /*================================== Macros ==================================*/ #define NUM_ELEMENTS(x) (sizeof(x) / sizeof(*x)) /*============================ Namespace Control =============================*/ using DevdCtl::Event; using DevdCtl::EventFactory; using DevdCtl::EventList; /*================================ Global Data ===============================*/ int g_debug = 0; libzfs_handle_t *g_zfsHandle; /*--------------------------------- ZfsDaemon --------------------------------*/ //- ZfsDaemon Static Private Data ---------------------------------------------- ZfsDaemon *ZfsDaemon::s_theZfsDaemon; bool ZfsDaemon::s_logCaseFiles; bool ZfsDaemon::s_terminateEventLoop; char ZfsDaemon::s_pidFilePath[] = "/var/run/zfsd.pid"; pidfh *ZfsDaemon::s_pidFH; 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 } }; //- ZfsDaemon Static Public Methods -------------------------------------------- ZfsDaemon & ZfsDaemon::Get() { return (*s_theZfsDaemon); } void ZfsDaemon::WakeEventLoop() { write(s_signalPipeFD[1], "+", 1); } void ZfsDaemon::RequestSystemRescan() { s_systemRescanRequested = true; ZfsDaemon::WakeEventLoop(); } void ZfsDaemon::Run() { ZfsDaemon daemon; while (s_terminateEventLoop == false) { try { daemon.DisconnectFromDevd(); if (daemon.ConnectToDevd() == false) { sleep(30); continue; } daemon.DetectMissedEvents(); daemon.EventLoop(); } catch (const DevdCtl::Exception &exp) { exp.Log(); } } daemon.DisconnectFromDevd(); } //- ZfsDaemon Private Methods -------------------------------------------------- ZfsDaemon::ZfsDaemon() : Consumer(/*defBuilder*/NULL, s_registryEntries, NUM_ELEMENTS(s_registryEntries)) { if (s_theZfsDaemon != NULL) errx(1, "Multiple ZfsDaemon instances created. Exiting"); s_theZfsDaemon = this; if (pipe(s_signalPipeFD) != 0) errx(1, "Unable to allocate signal pipe. Exiting"); if (fcntl(s_signalPipeFD[0], F_SETFL, O_NONBLOCK) == -1) errx(1, "Unable to set pipe as non-blocking. Exiting"); if (fcntl(s_signalPipeFD[1], F_SETFL, O_NONBLOCK) == -1) errx(1, "Unable to set pipe as non-blocking. Exiting"); signal(SIGHUP, ZfsDaemon::RescanSignalHandler); signal(SIGINFO, ZfsDaemon::InfoSignalHandler); signal(SIGINT, ZfsDaemon::QuitSignalHandler); signal(SIGTERM, ZfsDaemon::QuitSignalHandler); signal(SIGUSR1, ZfsDaemon::RescanSignalHandler); g_zfsHandle = libzfs_init(); if (g_zfsHandle == NULL) errx(1, "Unable to initialize ZFS library. Exiting"); Callout::Init(); InitializeSyslog(); OpenPIDFile(); if (g_debug == 0) daemon(0, 0); UpdatePIDFile(); } ZfsDaemon::~ZfsDaemon() { PurgeCaseFiles(); ClosePIDFile(); } void ZfsDaemon::PurgeCaseFiles() { CaseFile::PurgeAll(); } bool ZfsDaemon::VdevAddCaseFile(Vdev &vdev, void *cbArg) { if (vdev.State() != VDEV_STATE_HEALTHY) CaseFile::Create(vdev); return (/*break early*/false); } void ZfsDaemon::BuildCaseFiles() { ZpoolList zpl; ZpoolList::iterator pool; /* Add CaseFiles for vdevs with issues. */ for (pool = zpl.begin(); pool != zpl.end(); pool++) VdevIterator(*pool).Each(VdevAddCaseFile, NULL); /* De-serialize any saved cases. */ CaseFile::DeSerialize(); /* Simulate config_sync events to force CaseFile reevaluation */ for (pool = zpl.begin(); pool != zpl.end(); pool++) { char evString[160]; Event *event; nvlist_t *config; uint64_t poolGUID; const char *poolname; poolname = zpool_get_name(*pool); config = zpool_get_config(*pool, NULL); if (config == NULL) { syslog(LOG_ERR, "ZFSDaemon::BuildCaseFiles: Could not " "find pool config for pool %s", poolname); continue; } if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &poolGUID) != 0) { syslog(LOG_ERR, "ZFSDaemon::BuildCaseFiles: Could not " "find pool guid for pool %s", poolname); continue; } snprintf(evString, 160, "!system=ZFS subsystem=ZFS " "type=misc.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) { event->Process(); delete event; } } } void ZfsDaemon::RescanSystem() { struct gmesh mesh; struct gclass *mp; struct ggeom *gp; struct gprovider *pp; int result; /* * The devdctl system doesn't replay events for new consumers * of the interface. Emit manufactured DEVFS arrival events * for any devices that already before we started or during * periods where we've lost our connection to devd. */ result = geom_gettree(&mesh); if (result != 0) { syslog(LOG_ERR, "ZfsDaemon::RescanSystem: " "geom_gettree faild with error %d\n", result); return; } const string evStart("!system=DEVFS subsystem=CDEV type=CREATE " "sub_type=synthesized cdev="); LIST_FOREACH(mp, &mesh.lg_class, lg_class) { LIST_FOREACH(gp, &mp->lg_geom, lg_geom) { LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { Event *event; string evString(evStart + pp->lg_name + "\n"); event = Event::CreateEvent(GetFactory(), evString); if (event != NULL) { if (event->Process()) SaveEvent(*event); delete event; } } } } geom_deletetree(&mesh); } void ZfsDaemon::DetectMissedEvents() { do { PurgeCaseFiles(); /* * Discard any events waiting for us. We don't know * if they still apply to the current state of the * system. */ FlushEvents(); BuildCaseFiles(); /* * If the system state has changed during our * interrogation, start over. */ } while (s_terminateEventLoop == false && EventsPending()); RescanSystem(); } void ZfsDaemon::EventLoop() { while (s_terminateEventLoop == false) { struct pollfd fds[2]; int result; if (s_logCaseFiles == true) { EventList::iterator event(m_unconsumedEvents.begin()); s_logCaseFiles = false; CaseFile::LogAll(); while (event != m_unconsumedEvents.end()) (*event++)->Log(LOG_INFO); } Callout::ExpireCallouts(); /* Wait for data. */ fds[0].fd = m_devdSockFD; fds[0].events = POLLIN; fds[0].revents = 0; fds[1].fd = s_signalPipeFD[0]; fds[1].events = POLLIN; fds[1].revents = 0; result = poll(fds, NUM_ELEMENTS(fds), /*timeout*/INFTIM); if (result == -1) { if (errno == EINTR) continue; else err(1, "Polling for devd events failed"); } else if (result == 0) { errx(1, "Unexpected result of 0 from poll. Exiting"); } if ((fds[0].revents & POLLIN) != 0) ProcessEvents(); if ((fds[1].revents & POLLIN) != 0) { static char discardBuf[128]; /* * This pipe exists just to close the signal * race. Its contents are of no interest to * us, but we must ensure that future signals * have space in the pipe to write. */ while (read(s_signalPipeFD[0], discardBuf, sizeof(discardBuf)) > 0) ; } if (s_systemRescanRequested == true) { s_systemRescanRequested = false; syslog(LOG_INFO, "System Rescan request processed."); RescanSystem(); } if ((fds[0].revents & POLLERR) != 0) { syslog(LOG_INFO, "POLLERROR detected on devd socket."); break; } if ((fds[0].revents & POLLHUP) != 0) { syslog(LOG_INFO, "POLLHUP detected on devd socket."); break; } } } //- ZfsDaemon staic Private Methods -------------------------------------------- void ZfsDaemon::InfoSignalHandler(int) { s_logCaseFiles = true; ZfsDaemon::WakeEventLoop(); } void ZfsDaemon::RescanSignalHandler(int) { RequestSystemRescan(); } void ZfsDaemon::QuitSignalHandler(int) { s_terminateEventLoop = true; ZfsDaemon::WakeEventLoop(); } void ZfsDaemon::OpenPIDFile() { pid_t otherPID; s_pidFH = pidfile_open(s_pidFilePath, 0600, &otherPID); if (s_pidFH == NULL) { if (errno == EEXIST) errx(1, "already running as PID %d. Exiting", otherPID); warn("cannot open PID file"); } } void ZfsDaemon::UpdatePIDFile() { if (s_pidFH != NULL) pidfile_write(s_pidFH); } void ZfsDaemon::ClosePIDFile() { if (s_pidFH != NULL) pidfile_remove(s_pidFH); } void ZfsDaemon::InitializeSyslog() { openlog("zfsd", LOG_NDELAY, LOG_DAEMON); } Index: head/cddl/usr.sbin/zfsd/zfsd_event.cc =================================================================== --- head/cddl/usr.sbin/zfsd/zfsd_event.cc (revision 329283) +++ head/cddl/usr.sbin/zfsd/zfsd_event.cc (revision 329284) @@ -1,548 +1,473 @@ /*- * Copyright (c) 2011, 2012, 2013, 2014, 2016 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * Authors: Justin T. Gibbs (Spectra Logic Corporation) */ /** * \file zfsd_event.cc */ #include #include #include #include #include #include /* * Undefine flush, defined by cpufunc.h on sparc64, because it conflicts with * C++ flush methods */ #undef flush #include #include #include #include #include #include #include #include #include #include "callout.h" #include "vdev_iterator.h" #include "zfsd_event.h" #include "case_file.h" #include "vdev.h" #include "zfsd.h" #include "zfsd_exception.h" #include "zpool_list.h" __FBSDID("$FreeBSD$"); /*============================ Namespace Control =============================*/ using DevdCtl::Event; using DevdCtl::Guid; using DevdCtl::NVPairMap; 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 DevfsEvent(type, nvPairs, eventString)); + return (new GeomEvent(type, nvPairs, eventString)); } -//- DevfsEvent Static Protected Methods ---------------------------------------- -nvlist_t * -DevfsEvent::ReadLabel(int devFd, bool &inUse, bool °raded) -{ - 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) -{ - 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); -} - -//- 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. */ 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)); + 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()) { - /* + } 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); } } - 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) + : DevdCtl::GeomEvent(type, nvpairs, eventString) { } -DevfsEvent::DevfsEvent(const DevfsEvent &src) - : DevdCtl::DevfsEvent::DevfsEvent(src) +GeomEvent::GeomEvent(const GeomEvent &src) + : DevdCtl::GeomEvent::GeomEvent(src) { } -/*-------------------------------- GeomEvent --------------------------------*/ - -//- GeomEvent Static Public Methods ------------------------------------------- -Event * -GeomEvent::Builder(Event::Type type, - NVPairMap &nvPairs, - const string &eventString) +nvlist_t * +GeomEvent::ReadLabel(int devFd, bool &inUse, bool °raded) { - return (new GeomEvent(type, nvPairs, eventString)); -} + pool_state_t poolState; + char *poolName; + boolean_t b_inuse; + int nlabels; -//- 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); + inUse = false; + degraded = false; + poolName = NULL; + if (zpool_in_use(g_zfsHandle, devFd, &poolState, + &poolName, &b_inuse) == 0) { + nvlist_t *devLabel = NULL; - /* Log the event since it is of interest. */ - Log(LOG_INFO); + inUse = b_inuse == B_TRUE; + if (poolName != NULL) + free(poolName); - string devPath; - if (!DevPath(devPath)) - return (false); + 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 physPath; - bool havePhysPath(PhysicalPath(physPath)); + 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 + ": "); - 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); + 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); } /*--------------------------------- ZfsEvent ---------------------------------*/ //- ZfsEvent Static Public Methods --------------------------------------------- DevdCtl::Event * ZfsEvent::Builder(Event::Type type, NVPairMap &nvpairs, const string &eventString) { return (new ZfsEvent(type, nvpairs, eventString)); } //- ZfsEvent Virtual Public Methods -------------------------------------------- Event * ZfsEvent::DeepCopy() const { return (new ZfsEvent(*this)); } bool ZfsEvent::Process() const { string logstr(""); if (!Contains("class") && !Contains("type")) { syslog(LOG_ERR, "ZfsEvent::Process: Missing class or type data."); return (false); } /* On config syncs, replay any queued events first. */ if (Value("type").find("misc.fs.zfs.config_sync") == 0) { /* * Even if saved events are unconsumed the second time * around, drop them. Any events that still can't be * consumed are probably referring to vdevs or pools that * no longer exist. */ ZfsDaemon::Get().ReplayUnconsumedEvents(/*discard*/true); CaseFile::ReEvaluateByGuid(PoolGUID(), *this); } if (Value("type").find("misc.fs.zfs.") == 0) { /* Configuration changes, resilver events, etc. */ ProcessPoolEvent(); return (false); } if (!Contains("pool_guid") || !Contains("vdev_guid")) { /* Only currently interested in Vdev related events. */ return (false); } CaseFile *caseFile(CaseFile::Find(PoolGUID(), VdevGUID())); if (caseFile != NULL) { Log(LOG_INFO); syslog(LOG_INFO, "Evaluating existing case file\n"); caseFile->ReEvaluate(*this); return (false); } /* Skip events that can't be handled. */ Guid poolGUID(PoolGUID()); /* If there are no replicas for a pool, then it's not manageable. */ if (Value("class").find("fs.zfs.vdev.no_replicas") == 0) { stringstream msg; msg << "No replicas available for pool " << poolGUID; msg << ", ignoring"; Log(LOG_INFO); syslog(LOG_INFO, "%s", msg.str().c_str()); return (false); } /* * Create a case file for this vdev, and have it * evaluate the event. */ ZpoolList zpl(ZpoolList::ZpoolByGUID, &poolGUID); if (zpl.empty()) { stringstream msg; int priority = LOG_INFO; msg << "ZfsEvent::Process: Event for unknown pool "; msg << poolGUID << " "; msg << "queued"; Log(LOG_INFO); syslog(priority, "%s", msg.str().c_str()); return (true); } nvlist_t *vdevConfig = VdevIterator(zpl.front()).Find(VdevGUID()); if (vdevConfig == NULL) { stringstream msg; int priority = LOG_INFO; msg << "ZfsEvent::Process: Event for unknown vdev "; msg << VdevGUID() << " "; msg << "queued"; Log(LOG_INFO); syslog(priority, "%s", msg.str().c_str()); return (true); } Vdev vdev(zpl.front(), vdevConfig); caseFile = &CaseFile::Create(vdev); if (caseFile->ReEvaluate(*this) == false) { stringstream msg; int priority = LOG_INFO; msg << "ZfsEvent::Process: Unconsumed event for vdev("; msg << zpool_get_name(zpl.front()) << ","; msg << vdev.GUID() << ") "; msg << "queued"; Log(LOG_INFO); syslog(priority, "%s", msg.str().c_str()); return (true); } return (false); } //- ZfsEvent Protected Methods ------------------------------------------------- ZfsEvent::ZfsEvent(Event::Type type, NVPairMap &nvpairs, const string &eventString) : DevdCtl::ZfsEvent(type, nvpairs, eventString) { } ZfsEvent::ZfsEvent(const ZfsEvent &src) : DevdCtl::ZfsEvent(src) { } /* * Sometimes the kernel won't detach a spare when it is no longer needed. This * can happen for example if a drive is removed, then either the pool is * exported or the machine is powered off, then the drive is reinserted, then * the machine is powered on or the pool is imported. ZFSD must detach these * spares itself. */ void ZfsEvent::CleanupSpares() const { Guid poolGUID(PoolGUID()); ZpoolList zpl(ZpoolList::ZpoolByGUID, &poolGUID); if (!zpl.empty()) { zpool_handle_t* hdl; hdl = zpl.front(); VdevIterator(hdl).Each(TryDetach, (void*)hdl); } } void ZfsEvent::ProcessPoolEvent() const { bool degradedDevice(false); /* The pool is destroyed. Discard any open cases */ if (Value("type") == "misc.fs.zfs.pool_destroy") { Log(LOG_INFO); CaseFile::ReEvaluateByGuid(PoolGUID(), *this); return; } CaseFile *caseFile(CaseFile::Find(PoolGUID(), VdevGUID())); if (caseFile != NULL) { if (caseFile->VdevState() != VDEV_STATE_UNKNOWN && caseFile->VdevState() < VDEV_STATE_HEALTHY) degradedDevice = true; Log(LOG_INFO); caseFile->ReEvaluate(*this); } else if (Value("type") == "misc.fs.zfs.resilver_finish") { /* * It's possible to get a resilver_finish event with no * corresponding casefile. For example, if a damaged pool were * exported, repaired, then reimported. */ Log(LOG_INFO); CleanupSpares(); } if (Value("type") == "misc.fs.zfs.vdev_remove" && degradedDevice == false) { /* See if any other cases can make use of this device. */ Log(LOG_INFO); ZfsDaemon::RequestSystemRescan(); } } bool ZfsEvent::TryDetach(Vdev &vdev, void *cbArg) { /* * Outline: * if this device is a spare, and its parent includes one healthy, * non-spare child, then detach this device. */ zpool_handle_t *hdl(static_cast(cbArg)); if (vdev.IsSpare()) { std::list siblings; std::list::iterator siblings_it; boolean_t cleanup = B_FALSE; Vdev parent = vdev.Parent(); siblings = parent.Children(); /* Determine whether the parent should be cleaned up */ for (siblings_it = siblings.begin(); siblings_it != siblings.end(); siblings_it++) { Vdev sibling = *siblings_it; if (!sibling.IsSpare() && sibling.State() == VDEV_STATE_HEALTHY) { cleanup = B_TRUE; break; } } if (cleanup) { syslog(LOG_INFO, "Detaching spare vdev %s from pool %s", vdev.Path().c_str(), zpool_get_name(hdl)); zpool_vdev_detach(hdl, vdev.Path().c_str()); } } /* Always return false, because there may be other spares to detach */ return (false); } Index: head/cddl/usr.sbin/zfsd/zfsd_event.h =================================================================== --- head/cddl/usr.sbin/zfsd/zfsd_event.h (revision 329283) +++ head/cddl/usr.sbin/zfsd/zfsd_event.h (revision 329284) @@ -1,168 +1,144 @@ /*- * Copyright (c) 2011, 2012, 2013, 2014, 2016 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * Authors: Justin T. Gibbs (Spectra Logic Corporation) * * $FreeBSD$ */ /** * \file dev_ctl_event.h * * \brief Class hierarchy used to express events received via * the devdctl API. * * Header requirements: * #include * #include * #include * * #include * #include */ #ifndef _ZFSD_EVENT_H_ #define _ZFSD_EVENT_H_ /*============================ Namespace Control =============================*/ using std::string; /*=========================== Forward Declarations ===========================*/ struct zpool_handle; 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 °raded); - - /** - * 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 { public: /** Specialized DevdCtlEvent object factory for ZFS 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: /** DeepCopy Constructor. */ ZfsEvent(const ZfsEvent &src); /** Constructor */ ZfsEvent(Type, DevdCtl::NVPairMap &, const string &); /** * Detach any spares that are no longer needed, but were not * automatically detached by the kernel */ virtual void CleanupSpares() const; virtual void ProcessPoolEvent() const; static VdevCallback_t TryDetach; }; class GeomEvent : public DevdCtl::GeomEvent { public: static BuildMethod Builder; virtual DevdCtl::Event *DeepCopy() const; virtual bool Process() const; protected: /** DeepCopy Constructor. */ GeomEvent(const GeomEvent &src); /** 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 °raded); + }; #endif /*_ZFSD_EVENT_H_ */ Index: head/lib/libdevdctl/event.cc =================================================================== --- head/lib/libdevdctl/event.cc (revision 329283) +++ head/lib/libdevdctl/event.cc (revision 329284) @@ -1,602 +1,605 @@ /*- * Copyright (c) 2011, 2012, 2013, 2016 Spectra Logic Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * Authors: Justin T. Gibbs (Spectra Logic Corporation) */ /** * \file event.cc * * Implementation of the class hierarchy used to express events * received via the devdctl API. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "guid.h" #include "event.h" #include "event_factory.h" #include "exception.h" __FBSDID("$FreeBSD$"); /*================================== Macros ==================================*/ #define NUM_ELEMENTS(x) (sizeof(x) / sizeof(*x)) /*============================ Namespace Control =============================*/ using std::cout; using std::endl; using std::string; using std::stringstream; namespace DevdCtl { /*=========================== Class Implementations ==========================*/ /*----------------------------------- Event ----------------------------------*/ //- Event Static Protected Data ------------------------------------------------ const string Event::s_theEmptyString; Event::EventTypeRecord Event::s_typeTable[] = { { Event::NOTIFY, "Notify" }, { Event::NOMATCH, "No Driver Match" }, { Event::ATTACH, "Attach" }, { Event::DETACH, "Detach" } }; //- Event Static Public Methods ------------------------------------------------ Event * Event::Builder(Event::Type type, NVPairMap &nvPairs, const string &eventString) { return (new Event(type, nvPairs, eventString)); } Event * Event::CreateEvent(const EventFactory &factory, const string &eventString) { NVPairMap &nvpairs(*new NVPairMap); Type type(static_cast(eventString[0])); try { ParseEventString(type, eventString, nvpairs); } catch (const ParseException &exp) { if (exp.GetType() == ParseException::INVALID_FORMAT) exp.Log(); return (NULL); } /* * Allow entries in our table for events with no system specified. * These entries should specify the string "none". */ NVPairMap::iterator system_item(nvpairs.find("system")); if (system_item == nvpairs.end()) nvpairs["system"] = "none"; return (factory.Build(type, nvpairs, eventString)); } bool Event::DevName(std::string &name) const { return (false); } /* TODO: simplify this function with C++-11 methods */ bool Event::IsDiskDev() const { const int numDrivers = 2; static const char *diskDevNames[numDrivers] = { "da", "ada" }; const char **dName; string devName; if (! DevName(devName)) return false; size_t find_start = devName.rfind('/'); if (find_start == string::npos) { find_start = 0; } else { /* Just after the last '/'. */ find_start++; } for (dName = &diskDevNames[0]; dName <= &diskDevNames[numDrivers - 1]; dName++) { size_t loc(devName.find(*dName, find_start)); if (loc == find_start) { size_t prefixLen(strlen(*dName)); if (devName.length() - find_start >= prefixLen && isdigit(devName[find_start + prefixLen])) return (true); } } return (false); } const char * Event::TypeToString(Event::Type type) { EventTypeRecord *rec(s_typeTable); EventTypeRecord *lastRec(s_typeTable + NUM_ELEMENTS(s_typeTable) - 1); for (; rec <= lastRec; rec++) { if (rec->m_type == type) return (rec->m_typeName); } return ("Unknown"); } //- Event Public Methods ------------------------------------------------------- const string & Event::Value(const string &varName) const { NVPairMap::const_iterator item(m_nvPairs.find(varName)); if (item == m_nvPairs.end()) return (s_theEmptyString); return (item->second); } bool Event::Contains(const string &varName) const { return (m_nvPairs.find(varName) != m_nvPairs.end()); } string Event::ToString() const { stringstream result; NVPairMap::const_iterator devName(m_nvPairs.find("device-name")); if (devName != m_nvPairs.end()) result << devName->second << ": "; NVPairMap::const_iterator systemName(m_nvPairs.find("system")); if (systemName != m_nvPairs.end() && systemName->second != "none") result << systemName->second << ": "; result << TypeToString(GetType()) << ' '; for (NVPairMap::const_iterator curVar = m_nvPairs.begin(); curVar != m_nvPairs.end(); curVar++) { if (curVar == devName || curVar == systemName) continue; result << ' ' << curVar->first << "=" << curVar->second; } result << endl; return (result.str()); } void Event::Print() const { cout << ToString() << std::flush; } void Event::Log(int priority) const { syslog(priority, "%s", ToString().c_str()); } //- Event Virtual Public Methods ----------------------------------------------- Event::~Event() { delete &m_nvPairs; } Event * Event::DeepCopy() const { return (new Event(*this)); } bool Event::Process() const { return (false); } timeval Event::GetTimestamp() const { timeval tv_timestamp; struct tm tm_timestamp; if (!Contains("timestamp")) { throw Exception("Event contains no timestamp: %s", m_eventString.c_str()); } strptime(Value(string("timestamp")).c_str(), "%s", &tm_timestamp); tv_timestamp.tv_sec = mktime(&tm_timestamp); tv_timestamp.tv_usec = 0; return (tv_timestamp); } bool Event::DevPath(std::string &path) const { string devName; if (!DevName(devName)) return (false); string devPath(_PATH_DEV + devName); int devFd(open(devPath.c_str(), O_RDONLY)); if (devFd == -1) return (false); /* Normalize the device name in case the DEVFS event is for a link. */ devName = fdevname(devFd); path = _PATH_DEV + devName; close(devFd); return (true); } bool Event::PhysicalPath(std::string &path) const { string devPath; if (!DevPath(devPath)) return (false); int devFd(open(devPath.c_str(), O_RDONLY)); if (devFd == -1) return (false); char physPath[MAXPATHLEN]; physPath[0] = '\0'; bool result(ioctl(devFd, DIOCGPHYSPATH, physPath) == 0); close(devFd); if (result) path = physPath; return (result); } //- Event Protected Methods ---------------------------------------------------- Event::Event(Type type, NVPairMap &map, const string &eventString) : m_type(type), m_nvPairs(map), m_eventString(eventString) { } Event::Event(const Event &src) : m_type(src.m_type), m_nvPairs(*new NVPairMap(src.m_nvPairs)), m_eventString(src.m_eventString) { } void Event::ParseEventString(Event::Type type, const string &eventString, NVPairMap& nvpairs) { size_t start; size_t end; switch (type) { case ATTACH: case DETACH: /* * \ * at \ * on * * Handle all data that doesn't conform to the * "name=value" format, and let the generic parser * below handle the rest. * * Type is a single char. Skip it. */ start = 1; end = eventString.find_first_of(" \t\n", start); if (end == string::npos) throw ParseException(ParseException::INVALID_FORMAT, eventString, start); nvpairs["device-name"] = eventString.substr(start, end - start); start = eventString.find(" on ", end); if (end == string::npos) throw ParseException(ParseException::INVALID_FORMAT, eventString, start); start += 4; end = eventString.find_first_of(" \t\n", start); nvpairs["parent"] = eventString.substr(start, end); break; case NOTIFY: break; case NOMATCH: throw ParseException(ParseException::DISCARDED_EVENT_TYPE, eventString); default: throw ParseException(ParseException::UNKNOWN_EVENT_TYPE, eventString); } /* Process common "key=value" format. */ for (start = 1; start < eventString.length(); start = end + 1) { /* Find the '=' in the middle of the key/value pair. */ end = eventString.find('=', start); if (end == string::npos) break; /* * Find the start of the key by backing up until * we hit whitespace or '!' (event type "notice"). * Due to the devdctl format, all key/value pair must * start with one of these two characters. */ start = eventString.find_last_of("! \t\n", end); if (start == string::npos) throw ParseException(ParseException::INVALID_FORMAT, eventString, end); start++; string key(eventString.substr(start, end - start)); /* * Walk forward from the '=' until either we exhaust * the buffer or we hit whitespace. */ start = end + 1; if (start >= eventString.length()) throw ParseException(ParseException::INVALID_FORMAT, eventString, end); end = eventString.find_first_of(" \t\n", start); if (end == string::npos) end = eventString.length() - 1; string value(eventString.substr(start, end - start)); nvpairs[key] = value; } } void Event::TimestampEventString(std::string &eventString) { if (eventString.size() > 0) { /* * Add a timestamp as the final field of the event if it is * not already present. */ if (eventString.find("timestamp=") == string::npos) { const size_t bufsize = 32; // Long enough for a 64-bit int timeval now; char timebuf[bufsize]; size_t eventEnd(eventString.find_last_not_of('\n') + 1); if (gettimeofday(&now, NULL) != 0) err(1, "gettimeofday"); snprintf(timebuf, bufsize, " timestamp=%" PRId64, (int64_t) now.tv_sec); eventString.insert(eventEnd, timebuf); } } } /*-------------------------------- DevfsEvent --------------------------------*/ //- DevfsEvent Static Public Methods ------------------------------------------- Event * DevfsEvent::Builder(Event::Type type, NVPairMap &nvPairs, const string &eventString) { return (new DevfsEvent(type, nvPairs, eventString)); } //- DevfsEvent Static Protected Methods ---------------------------------------- bool DevfsEvent::IsWholeDev(const string &devName) { string::const_iterator i(devName.begin()); size_t start = devName.rfind('/'); if (start == string::npos) { start = 0; } else { /* Just after the last '/'. */ start++; } i += start; /* alpha prefix followed only by digits. */ for (; i < devName.end() && !isdigit(*i); i++) ; if (i == devName.end()) return (false); for (; i < devName.end() && isdigit(*i); i++) ; return (i == devName.end()); } //- DevfsEvent Virtual Public Methods ------------------------------------------ Event * DevfsEvent::DeepCopy() const { return (new DevfsEvent(*this)); } bool DevfsEvent::Process() const { return (true); } //- DevfsEvent Public Methods -------------------------------------------------- bool DevfsEvent::IsWholeDev() const { string devName; return (DevName(devName) && IsDiskDev() && IsWholeDev(devName)); } bool DevfsEvent::DevName(std::string &name) const { if (Value("subsystem") != "CDEV") return (false); name = Value("cdev"); return (!name.empty()); } //- DevfsEvent Protected Methods ----------------------------------------------- DevfsEvent::DevfsEvent(Event::Type type, NVPairMap &nvpairs, const string &eventString) : Event(type, nvpairs, eventString) { } DevfsEvent::DevfsEvent(const DevfsEvent &src) : Event(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::DevName(std::string &name) const { - name = Value("devname"); + if (Value("subsystem") == "disk") + name = Value("devname"); + else + name = Value("cdev"); return (!name.empty()); } //- GeomEvent Protected Methods ------------------------------------------------ GeomEvent::GeomEvent(Event::Type type, NVPairMap &nvpairs, const string &eventString) : Event(type, nvpairs, eventString), m_devname(Value("devname")) { } GeomEvent::GeomEvent(const GeomEvent &src) : Event(src), m_devname(src.m_devname) { } /*--------------------------------- ZfsEvent ---------------------------------*/ //- ZfsEvent Static Public Methods --------------------------------------------- Event * ZfsEvent::Builder(Event::Type type, NVPairMap &nvpairs, const string &eventString) { return (new ZfsEvent(type, nvpairs, eventString)); } //- ZfsEvent Virtual Public Methods -------------------------------------------- Event * ZfsEvent::DeepCopy() const { return (new ZfsEvent(*this)); } bool ZfsEvent::DevName(std::string &name) const { return (false); } //- ZfsEvent Protected Methods ------------------------------------------------- ZfsEvent::ZfsEvent(Event::Type type, NVPairMap &nvpairs, const string &eventString) : Event(type, nvpairs, eventString), m_poolGUID(Guid(Value("pool_guid"))), m_vdevGUID(Guid(Value("vdev_guid"))) { } ZfsEvent::ZfsEvent(const ZfsEvent &src) : Event(src), m_poolGUID(src.m_poolGUID), m_vdevGUID(src.m_vdevGUID) { } } // namespace DevdCtl