xref: /freebsd/cddl/usr.sbin/zfsd/zfsd_event.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
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 /*--------------------------------- ZfsEvent ---------------------------------*/
64 class ZfsEvent : public DevdCtl::ZfsEvent
65 {
66 public:
67 	/** Specialized DevdCtlEvent object factory for ZFS events. */
68 	static BuildMethod Builder;
69 
70 	virtual DevdCtl::Event *DeepCopy() const;
71 
72 	/**
73 	 * Interpret and perform any actions necessary to
74 	 * consume the event.
75 	 * \return True if this event should be queued for later reevaluation
76 	 */
77 	virtual bool Process()		  const;
78 
79 protected:
80 	/** DeepCopy Constructor. */
81 	ZfsEvent(const ZfsEvent &src);
82 
83 	/** Constructor */
84 	ZfsEvent(Type, DevdCtl::NVPairMap &, const string &);
85 
86 	/**
87 	 * Detach any spares that are no longer needed, but were not
88 	 * automatically detached by the kernel
89 	 */
90 	virtual void CleanupSpares()	  const;
91 	virtual void ProcessPoolEvent()	  const;
92 	static VdevCallback_t TryDetach;
93 };
94 
95 class GeomEvent : public DevdCtl::GeomEvent
96 {
97 public:
98 	static BuildMethod Builder;
99 
100 	virtual DevdCtl::Event *DeepCopy() const;
101 
102 	virtual bool Process()		  const;
103 
104 protected:
105 	/** DeepCopy Constructor. */
106 	GeomEvent(const GeomEvent &src);
107 
108 	/** Constructor */
109 	GeomEvent(Type, DevdCtl::NVPairMap &, const string &);
110 
111 	/**
112 	 * Attempt to match the ZFS labeled device at devPath with an active
113 	 * CaseFile for a missing vdev.  If a CaseFile is found, attempt
114 	 * to re-integrate the device with its pool.
115 	 *
116 	 * \param devPath    The devfs path to the potential leaf vdev.
117 	 * \param physPath   The physical path string reported by the device
118 	 *                   at devPath.
119 	 * \param devConfig  The ZFS label information found on the device
120 	 *                   at devPath.
121 	 *
122 	 * \return  true if the event that caused the online action can
123 	 *          be considered consumed.
124 	 */
125 	static bool	    OnlineByLabel(const string &devPath,
126 					  const string& physPath,
127 					  nvlist_t *devConfig);
128 
129 	/**
130 	 * \brief Read and return label information for a device.
131 	 *
132 	 * \param devFd     The device from which to read ZFS label information.
133 	 * \param inUse     The device is part of an active or potentially
134 	 *                  active configuration.
135 	 * \param degraded  The device label indicates the vdev is not healthy.
136 	 *
137 	 * \return  If label information is available, an nvlist describing
138 	 *          the vdev configuraiton found on the device specified by
139 	 *          devFd.  Otherwise NULL.
140 	 */
141 	static nvlist_t    *ReadLabel(int devFd, bool &inUse, bool &degraded);
142 
143 };
144 #endif /*_ZFSD_EVENT_H_ */
145