/*-1* Copyright (c) 2011, 2012, 2013, 2014, 2016 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Justin T. Gibbs (Spectra Logic Corporation)30*/3132/**33* \file dev_ctl_event.h34*35* \brief Class hierarchy used to express events received via36* the devdctl API.37*38* Header requirements:39* #include <string>40* #include <list>41* #include <map>42*43* #include <devdctl/guid.h>44* #include <devdctl/event.h>45*/4647#ifndef _ZFSD_EVENT_H_48#define _ZFSD_EVENT_H_4950/*============================ Namespace Control =============================*/51using std::string;5253/*=========================== Forward Declarations ===========================*/54struct zpool_handle;55typedef struct zpool_handle zpool_handle_t;5657struct nvlist;58typedef struct nvlist nvlist_t;5960/*--------------------------------- ZfsEvent ---------------------------------*/61class ZfsEvent : public DevdCtl::ZfsEvent62{63public:64/** Specialized DevdCtlEvent object factory for ZFS events. */65static BuildMethod Builder;6667virtual DevdCtl::Event *DeepCopy() const;6869/**70* Interpret and perform any actions necessary to71* consume the event.72* \return True if this event should be queued for later reevaluation73*/74virtual bool Process() const;7576protected:77/** DeepCopy Constructor. */78ZfsEvent(const ZfsEvent &src);7980/** Constructor */81ZfsEvent(Type, DevdCtl::NVPairMap &, const string &);8283/**84* Detach any spares that are no longer needed, but were not85* automatically detached by the kernel86*/87virtual void CleanupSpares() const;88virtual void ProcessPoolEvent() const;89static VdevCallback_t TryDetach;90};9192class GeomEvent : public DevdCtl::GeomEvent93{94public:95static BuildMethod Builder;9697virtual DevdCtl::Event *DeepCopy() const;9899virtual bool Process() const;100101protected:102/** DeepCopy Constructor. */103GeomEvent(const GeomEvent &src);104105/** Constructor */106GeomEvent(Type, DevdCtl::NVPairMap &, const string &);107108/**109* Attempt to match the ZFS labeled device at devPath with an active110* CaseFile for a missing vdev. If a CaseFile is found, attempt111* to re-integrate the device with its pool.112*113* \param devPath The devfs path to the potential leaf vdev.114* \param physPath The physical path string reported by the device115* at devPath.116* \param devConfig The ZFS label information found on the device117* at devPath.118*119* \return true if the event that caused the online action can120* be considered consumed.121*/122static bool OnlineByLabel(const string &devPath,123const string& physPath,124nvlist_t *devConfig);125126/**127* \brief Read and return label information for a device.128*129* \param devFd The device from which to read ZFS label information.130* \param inUse The device is part of an active or potentially131* active configuration.132* \param degraded The device label indicates the vdev is not healthy.133*134* \return If label information is available, an nvlist describing135* the vdev configuraiton found on the device specified by136* devFd. Otherwise NULL.137*/138static nvlist_t *ReadLabel(int devFd, bool &inUse, bool °raded);139140};141#endif /*_ZFSD_EVENT_H_ */142143144