xref: /freebsd/cddl/usr.sbin/zfsd/zfsd_event.h (revision 273c26a3c3bea87a241d6879abd4f991db180bf0)
1 /*-
2  * Copyright (c) 2011, 2012, 2013, 2014, 2016 Spectra Logic Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    substantially similar to the "NO WARRANTY" disclaimer below
13  *    ("Disclaimer") and any redistribution must be conditioned upon
14  *    including a substantially similar Disclaimer requirement for further
15  *    binary redistribution.
16  *
17  * NO WARRANTY
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGES.
29  *
30  * Authors: Justin T. Gibbs     (Spectra Logic Corporation)
31  *
32  * $FreeBSD$
33  */
34 
35 /**
36  * \file dev_ctl_event.h
37  *
38  * \brief Class hierarchy used to express events received via
39  *        the devdctl API.
40  *
41  * Header requirements:
42  *    #include <string>
43  *    #include <list>
44  *    #include <map>
45  *
46  *    #include <devdctl/guid.h>
47  *    #include <devdctl/event.h>
48  */
49 
50 #ifndef _ZFSD_EVENT_H_
51 #define	_ZFSD_EVENT_H_
52 
53 /*============================ Namespace Control =============================*/
54 using std::string;
55 
56 /*=========================== Forward Declarations ===========================*/
57 struct zpool_handle;
58 typedef struct zpool_handle zpool_handle_t;
59 
60 struct nvlist;
61 typedef struct nvlist nvlist_t;
62 
63 /*============================= Class Definitions ============================*/
64 /*-------------------------------- DevfsEvent --------------------------------*/
65 class DevfsEvent : public DevdCtl::DevfsEvent
66 {
67 public:
68 	/** Specialized DevdCtlEvent object factory for Devfs events. */
69 	static BuildMethod Builder;
70 
71 	virtual DevdCtl::Event *DeepCopy() const;
72 
73 	/**
74 	 * Interpret and perform any actions necessary to
75 	 * consume the event.
76 	 * \return True if this event should be queued for later reevaluation
77 	 */
78 	virtual bool Process()		  const;
79 
80 protected:
81 	/**
82 	 * \brief Read and return label information for a device.
83 	 *
84 	 * \param devFd     The device from which to read ZFS label information.
85 	 * \param inUse     The device is part of an active or potentially
86 	 *                  active configuration.
87 	 * \param degraded  The device label indicates the vdev is not healthy.
88 	 *
89 	 * \return  If label information is available, an nvlist describing
90 	 *          the vdev configuraiton found on the device specified by
91 	 *          devFd.  Otherwise NULL.
92 	 */
93 	static nvlist_t    *ReadLabel(int devFd, bool &inUse, bool &degraded);
94 
95 	/**
96 	 * Attempt to match the ZFS labeled device at devPath with an active
97 	 * CaseFile for a missing vdev.  If a CaseFile is found, attempt
98 	 * to re-integrate the device with its pool.
99 	 *
100 	 * \param devPath    The devfs path to the potential leaf vdev.
101 	 * \param physPath   The physical path string reported by the device
102 	 *                   at devPath.
103 	 * \param devConfig  The ZFS label information found on the device
104 	 *                   at devPath.
105 	 *
106 	 * \return  true if the event that caused the online action can
107 	 *          be considered consumed.
108 	 */
109 	static bool	    OnlineByLabel(const string &devPath,
110 					  const string& physPath,
111 					  nvlist_t *devConfig);
112 
113 	/** DeepCopy Constructor. */
114 	DevfsEvent(const DevfsEvent &src);
115 
116 	/** Constructor */
117 	DevfsEvent(Type, DevdCtl::NVPairMap &, const string &);
118 };
119 
120 /*--------------------------------- ZfsEvent ---------------------------------*/
121 class ZfsEvent : public DevdCtl::ZfsEvent
122 {
123 public:
124 	/** Specialized DevdCtlEvent object factory for ZFS events. */
125 	static BuildMethod Builder;
126 
127 	virtual DevdCtl::Event *DeepCopy() const;
128 
129 	/**
130 	 * Interpret and perform any actions necessary to
131 	 * consume the event.
132 	 * \return True if this event should be queued for later reevaluation
133 	 */
134 	virtual bool Process()		  const;
135 
136 protected:
137 	/** DeepCopy Constructor. */
138 	ZfsEvent(const ZfsEvent &src);
139 
140 	/** Constructor */
141 	ZfsEvent(Type, DevdCtl::NVPairMap &, const string &);
142 
143 	/**
144 	 * Detach any spares that are no longer needed, but were not
145 	 * automatically detached by the kernel
146 	 */
147 	virtual void CleanupSpares()	  const;
148 	virtual void ProcessPoolEvent()	  const;
149 	static VdevCallback_t TryDetach;
150 };
151 
152 class GeomEvent : public DevdCtl::GeomEvent
153 {
154 public:
155 	static BuildMethod Builder;
156 
157 	virtual DevdCtl::Event *DeepCopy() const;
158 
159 	virtual bool Process()		  const;
160 
161 protected:
162 	/** DeepCopy Constructor. */
163 	GeomEvent(const GeomEvent &src);
164 
165 	/** Constructor */
166 	GeomEvent(Type, DevdCtl::NVPairMap &, const string &);
167 };
168 #endif /*_ZFSD_EVENT_H_ */
169