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
33/**
34 * \file dev_ctl_event.h
35 *
36 * \brief Class hierarchy used to express events received via
37 *        the devdctl API.
38 *
39 * Header requirements:
40 *    #include <string>
41 *    #include <list>
42 *    #include <map>
43 *
44 *    #include <devdctl/guid.h>
45 *    #include <devdctl/event.h>
46 */
47
48#ifndef _ZFSD_EVENT_H_
49#define	_ZFSD_EVENT_H_
50
51/*============================ Namespace Control =============================*/
52using std::string;
53
54/*=========================== Forward Declarations ===========================*/
55struct zpool_handle;
56typedef struct zpool_handle zpool_handle_t;
57
58struct nvlist;
59typedef struct nvlist nvlist_t;
60
61/*--------------------------------- ZfsEvent ---------------------------------*/
62class ZfsEvent : public DevdCtl::ZfsEvent
63{
64public:
65	/** Specialized DevdCtlEvent object factory for ZFS events. */
66	static BuildMethod Builder;
67
68	virtual DevdCtl::Event *DeepCopy() const;
69
70	/**
71	 * Interpret and perform any actions necessary to
72	 * consume the event.
73	 * \return True if this event should be queued for later reevaluation
74	 */
75	virtual bool Process()		  const;
76
77protected:
78	/** DeepCopy Constructor. */
79	ZfsEvent(const ZfsEvent &src);
80
81	/** Constructor */
82	ZfsEvent(Type, DevdCtl::NVPairMap &, const string &);
83
84	/**
85	 * Detach any spares that are no longer needed, but were not
86	 * automatically detached by the kernel
87	 */
88	virtual void CleanupSpares()	  const;
89	virtual void ProcessPoolEvent()	  const;
90	static VdevCallback_t TryDetach;
91};
92
93class GeomEvent : public DevdCtl::GeomEvent
94{
95public:
96	static BuildMethod Builder;
97
98	virtual DevdCtl::Event *DeepCopy() const;
99
100	virtual bool Process()		  const;
101
102protected:
103	/** DeepCopy Constructor. */
104	GeomEvent(const GeomEvent &src);
105
106	/** Constructor */
107	GeomEvent(Type, DevdCtl::NVPairMap &, const string &);
108
109	/**
110	 * Attempt to match the ZFS labeled device at devPath with an active
111	 * CaseFile for a missing vdev.  If a CaseFile is found, attempt
112	 * to re-integrate the device with its pool.
113	 *
114	 * \param devPath    The devfs path to the potential leaf vdev.
115	 * \param physPath   The physical path string reported by the device
116	 *                   at devPath.
117	 * \param devConfig  The ZFS label information found on the device
118	 *                   at devPath.
119	 *
120	 * \return  true if the event that caused the online action can
121	 *          be considered consumed.
122	 */
123	static bool	    OnlineByLabel(const string &devPath,
124					  const string& physPath,
125					  nvlist_t *devConfig);
126
127	/**
128	 * \brief Read and return label information for a device.
129	 *
130	 * \param devFd     The device from which to read ZFS label information.
131	 * \param inUse     The device is part of an active or potentially
132	 *                  active configuration.
133	 * \param degraded  The device label indicates the vdev is not healthy.
134	 *
135	 * \return  If label information is available, an nvlist describing
136	 *          the vdev configuraiton found on the device specified by
137	 *          devFd.  Otherwise NULL.
138	 */
139	static nvlist_t    *ReadLabel(int devFd, bool &inUse, bool &degraded);
140
141};
142#endif /*_ZFSD_EVENT_H_ */
143