2 * Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * Authors: Justin T. Gibbs (Spectra Logic Corporation)
38 * Definition of the Vdev class.
40 * Header requirements:
45 * #include <devdctl/guid.h>
50 /*=========================== Forward Declarations ===========================*/
52 typedef struct zpool_handle zpool_handle_t;
55 typedef struct nvlist nvlist_t;
57 /*============================= Class Definitions ============================*/
58 /*----------------------------------- Vdev -----------------------------------*/
60 * \brief Wrapper class for a vdev's name/value configuration list
61 * simplifying access to commonly used vdev attributes.
67 * \brief Instantiate a vdev object for a vdev that is a member
68 * of an imported pool.
70 * \param pool The pool object containing the vdev with
71 * configuration data provided in vdevConfig.
72 * \param vdevConfig Vdev configuration data.
74 * This method should be used whenever dealing with vdev's
75 * enumerated via the ZpoolList class. The in-core configuration
76 * data for a vdev does not contain all of the items found in
77 * the on-disk label. This requires the vdev class to augment
78 * the data in vdevConfig with data found in the pool object.
80 Vdev(zpool_handle_t *pool, nvlist_t *vdevConfig);
83 * \brief Instantiate a vdev object for a vdev that is a member
84 * of a pool configuration.
86 * \param poolConfig The pool configuration containing the vdev
87 * configuration data provided in vdevConfig.
88 * \param vdevConfig Vdev configuration data.
90 * This method should be used whenever dealing with vdev's
91 * enumerated via the ZpoolList class. The in-core configuration
92 * data for a vdev does not contain all of the items found in
93 * the on-disk label. This requires the vdev class to augment
94 * the data in vdevConfig with data found in the pool object.
96 Vdev(nvlist_t *poolConfig, nvlist_t *vdevConfig);
99 * \brief Instantiate a vdev object from a ZFS label stored on
102 * \param vdevConfig The name/value list retrieved by reading
103 * the label information on a leaf vdev.
105 Vdev(nvlist_t *vdevConfig);
108 * \brief No-op copy constructor for nonexistent vdevs.
113 * \brief No-op virtual destructor, since this class has virtual
117 bool DoesNotExist() const;
120 * \brief Return a list of the vdev's children.
122 std::list<Vdev> Children();
124 virtual DevdCtl::Guid GUID() const;
125 bool IsSpare() const;
126 virtual DevdCtl::Guid PoolGUID() const;
127 virtual vdev_state State() const;
128 std::string Path() const;
129 virtual std::string PhysicalPath() const;
130 std::string GUIDString() const;
131 nvlist_t *PoolConfig() const;
132 nvlist_t *Config() const;
135 std::string Name(zpool_handle_t *, bool verbose) const;
137 bool IsAvailableSpare() const;
138 bool IsActiveSpare() const;
139 bool IsResilvering() const;
142 void VdevLookupGuid();
143 bool VdevLookupPoolGuid();
144 DevdCtl::Guid m_poolGUID;
145 DevdCtl::Guid m_vdevGUID;
146 nvlist_t *m_poolConfig;
150 //- Special objects -----------------------------------------------------------
151 extern Vdev NonexistentVdev;
153 //- Vdev Inline Public Methods ------------------------------------------------
159 Vdev::PoolGUID() const
171 Vdev::PoolConfig() const
173 return (m_poolConfig);
183 Vdev::DoesNotExist() const
185 return (m_config == NULL);
188 #endif /* _VDEV_H_ */