Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/cddl/usr.sbin/zfsd/vdev.h
103499 views
1
/*-
2
* Copyright (c) 2011, 2012, 2013 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 vdev.h
35
*
36
* Definition of the Vdev class.
37
*
38
* Header requirements:
39
*
40
* #include <string>
41
* #include <list>
42
*
43
* #include <devdctl/guid.h>
44
*/
45
#ifndef _VDEV_H_
46
#define _VDEV_H_
47
48
/*=========================== Forward Declarations ===========================*/
49
struct zpool_handle;
50
typedef struct zpool_handle zpool_handle_t;
51
52
struct nvlist;
53
typedef struct nvlist nvlist_t;
54
55
/*============================= Class Definitions ============================*/
56
/*----------------------------------- Vdev -----------------------------------*/
57
/**
58
* \brief Wrapper class for a vdev's name/value configuration list
59
* simplifying access to commonly used vdev attributes.
60
*/
61
class Vdev
62
{
63
public:
64
/**
65
* \brief Instantiate a vdev object for a vdev that is a member
66
* of an imported pool.
67
*
68
* \param pool The pool object containing the vdev with
69
* configuration data provided in vdevConfig.
70
* \param vdevConfig Vdev configuration data.
71
*
72
* This method should be used whenever dealing with vdev's
73
* enumerated via the ZpoolList class. The in-core configuration
74
* data for a vdev does not contain all of the items found in
75
* the on-disk label. This requires the vdev class to augment
76
* the data in vdevConfig with data found in the pool object.
77
*/
78
Vdev(zpool_handle_t *pool, nvlist_t *vdevConfig);
79
80
/**
81
* \brief Instantiate a vdev object for a vdev that is a member
82
* of a pool configuration.
83
*
84
* \param poolConfig The pool configuration containing the vdev
85
* configuration data provided in vdevConfig.
86
* \param vdevConfig Vdev configuration data.
87
*
88
* This method should be used whenever dealing with vdev's
89
* enumerated via the ZpoolList class. The in-core configuration
90
* data for a vdev does not contain all of the items found in
91
* the on-disk label. This requires the vdev class to augment
92
* the data in vdevConfig with data found in the pool object.
93
*/
94
Vdev(nvlist_t *poolConfig, nvlist_t *vdevConfig);
95
96
/**
97
* \brief Instantiate a vdev object from a ZFS label stored on
98
* the device.
99
*
100
* \param vdevConfig The name/value list retrieved by reading
101
* the label information on a leaf vdev.
102
*/
103
Vdev(nvlist_t *vdevConfig);
104
105
/**
106
* \brief No-op copy constructor for nonexistent vdevs.
107
*/
108
Vdev();
109
110
/**
111
* \brief No-op virtual destructor, since this class has virtual
112
* functions.
113
*/
114
virtual ~Vdev();
115
bool DoesNotExist() const;
116
117
/**
118
* \brief Return a list of the vdev's children.
119
*/
120
std::list<Vdev> Children();
121
122
virtual DevdCtl::Guid GUID() const;
123
bool IsSpare() const;
124
virtual DevdCtl::Guid PoolGUID() const;
125
virtual vdev_state State() const;
126
std::string Path() const;
127
virtual std::string PhysicalPath() const;
128
std::string GUIDString() const;
129
nvlist_t *PoolConfig() const;
130
nvlist_t *Config() const;
131
Vdev Parent();
132
Vdev RootVdev();
133
virtual std::string Name(zpool_handle_t *, bool verbose) const;
134
bool IsSpare();
135
bool IsAvailableSpare() const;
136
bool IsActiveSpare() const;
137
bool IsResilvering() const;
138
139
private:
140
void VdevLookupGuid();
141
bool VdevLookupPoolGuid();
142
DevdCtl::Guid m_poolGUID;
143
DevdCtl::Guid m_vdevGUID;
144
nvlist_t *m_poolConfig;
145
nvlist_t *m_config;
146
};
147
148
//- Special objects -----------------------------------------------------------
149
extern Vdev NonexistentVdev;
150
151
//- Vdev Inline Public Methods ------------------------------------------------
152
inline Vdev::~Vdev()
153
{
154
}
155
156
inline DevdCtl::Guid
157
Vdev::PoolGUID() const
158
{
159
return (m_poolGUID);
160
}
161
162
inline DevdCtl::Guid
163
Vdev::GUID() const
164
{
165
return (m_vdevGUID);
166
}
167
168
inline nvlist_t *
169
Vdev::PoolConfig() const
170
{
171
return (m_poolConfig);
172
}
173
174
inline nvlist_t *
175
Vdev::Config() const
176
{
177
return (m_config);
178
}
179
180
inline bool
181
Vdev::DoesNotExist() const
182
{
183
return (m_config == NULL);
184
}
185
186
#endif /* _VDEV_H_ */
187
188