1300906Sasomers/*- 2300906Sasomers * Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation 3300906Sasomers * All rights reserved. 4300906Sasomers * 5300906Sasomers * Redistribution and use in source and binary forms, with or without 6300906Sasomers * modification, are permitted provided that the following conditions 7300906Sasomers * are met: 8300906Sasomers * 1. Redistributions of source code must retain the above copyright 9300906Sasomers * notice, this list of conditions, and the following disclaimer, 10300906Sasomers * without modification. 11300906Sasomers * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12300906Sasomers * substantially similar to the "NO WARRANTY" disclaimer below 13300906Sasomers * ("Disclaimer") and any redistribution must be conditioned upon 14300906Sasomers * including a substantially similar Disclaimer requirement for further 15300906Sasomers * binary redistribution. 16300906Sasomers * 17300906Sasomers * NO WARRANTY 18300906Sasomers * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19300906Sasomers * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20300906Sasomers * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 21300906Sasomers * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22300906Sasomers * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23300906Sasomers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24300906Sasomers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25300906Sasomers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26300906Sasomers * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 27300906Sasomers * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28300906Sasomers * POSSIBILITY OF SUCH DAMAGES. 29300906Sasomers * 30300906Sasomers * Authors: Justin T. Gibbs (Spectra Logic Corporation) 31300906Sasomers * 32300906Sasomers * $FreeBSD: releng/11.0/cddl/usr.sbin/zfsd/vdev.h 300906 2016-05-28 17:43:40Z asomers $ 33300906Sasomers */ 34300906Sasomers 35300906Sasomers/** 36300906Sasomers * \file vdev.h 37300906Sasomers * 38300906Sasomers * Definition of the Vdev class. 39300906Sasomers * 40300906Sasomers * Header requirements: 41300906Sasomers * 42300906Sasomers * #include <string> 43300906Sasomers * #include <list> 44300906Sasomers * 45300906Sasomers * #include <devdctl/guid.h> 46300906Sasomers */ 47300906Sasomers#ifndef _VDEV_H_ 48300906Sasomers#define _VDEV_H_ 49300906Sasomers 50300906Sasomers/*=========================== Forward Declarations ===========================*/ 51300906Sasomersstruct zpool_handle; 52300906Sasomerstypedef struct zpool_handle zpool_handle_t; 53300906Sasomers 54300906Sasomersstruct nvlist; 55300906Sasomerstypedef struct nvlist nvlist_t; 56300906Sasomers 57300906Sasomers/*============================= Class Definitions ============================*/ 58300906Sasomers/*----------------------------------- Vdev -----------------------------------*/ 59300906Sasomers/** 60300906Sasomers * \brief Wrapper class for a vdev's name/value configuration list 61300906Sasomers * simplifying access to commonly used vdev attributes. 62300906Sasomers */ 63300906Sasomersclass Vdev 64300906Sasomers{ 65300906Sasomerspublic: 66300906Sasomers /** 67300906Sasomers * \brief Instantiate a vdev object for a vdev that is a member 68300906Sasomers * of an imported pool. 69300906Sasomers * 70300906Sasomers * \param pool The pool object containing the vdev with 71300906Sasomers * configuration data provided in vdevConfig. 72300906Sasomers * \param vdevConfig Vdev configuration data. 73300906Sasomers * 74300906Sasomers * This method should be used whenever dealing with vdev's 75300906Sasomers * enumerated via the ZpoolList class. The in-core configuration 76300906Sasomers * data for a vdev does not contain all of the items found in 77300906Sasomers * the on-disk label. This requires the vdev class to augment 78300906Sasomers * the data in vdevConfig with data found in the pool object. 79300906Sasomers */ 80300906Sasomers Vdev(zpool_handle_t *pool, nvlist_t *vdevConfig); 81300906Sasomers 82300906Sasomers /** 83300906Sasomers * \brief Instantiate a vdev object for a vdev that is a member 84300906Sasomers * of a pool configuration. 85300906Sasomers * 86300906Sasomers * \param poolConfig The pool configuration containing the vdev 87300906Sasomers * configuration data provided in vdevConfig. 88300906Sasomers * \param vdevConfig Vdev configuration data. 89300906Sasomers * 90300906Sasomers * This method should be used whenever dealing with vdev's 91300906Sasomers * enumerated via the ZpoolList class. The in-core configuration 92300906Sasomers * data for a vdev does not contain all of the items found in 93300906Sasomers * the on-disk label. This requires the vdev class to augment 94300906Sasomers * the data in vdevConfig with data found in the pool object. 95300906Sasomers */ 96300906Sasomers Vdev(nvlist_t *poolConfig, nvlist_t *vdevConfig); 97300906Sasomers 98300906Sasomers /** 99300906Sasomers * \brief Instantiate a vdev object from a ZFS label stored on 100300906Sasomers * the device. 101300906Sasomers * 102300906Sasomers * \param vdevConfig The name/value list retrieved by reading 103300906Sasomers * the label information on a leaf vdev. 104300906Sasomers */ 105300906Sasomers Vdev(nvlist_t *vdevConfig); 106300906Sasomers 107300906Sasomers /** 108300906Sasomers * \brief No-op copy constructor for nonexistent vdevs. 109300906Sasomers */ 110300906Sasomers Vdev(); 111300906Sasomers bool DoesNotExist() const; 112300906Sasomers 113300906Sasomers /** 114300906Sasomers * \brief Return a list of the vdev's children. 115300906Sasomers */ 116300906Sasomers std::list<Vdev> Children(); 117300906Sasomers 118300906Sasomers virtual DevdCtl::Guid GUID() const; 119300906Sasomers bool IsSpare() const; 120300906Sasomers virtual DevdCtl::Guid PoolGUID() const; 121300906Sasomers virtual vdev_state State() const; 122300906Sasomers std::string Path() const; 123300906Sasomers virtual std::string PhysicalPath() const; 124300906Sasomers std::string GUIDString() const; 125300906Sasomers nvlist_t *PoolConfig() const; 126300906Sasomers nvlist_t *Config() const; 127300906Sasomers Vdev Parent(); 128300906Sasomers Vdev RootVdev(); 129300906Sasomers std::string Name(zpool_handle_t *, bool verbose) const; 130300906Sasomers bool IsSpare(); 131300906Sasomers bool IsAvailableSpare() const; 132300906Sasomers bool IsActiveSpare() const; 133300906Sasomers bool IsResilvering() const; 134300906Sasomers 135300906Sasomersprivate: 136300906Sasomers void VdevLookupGuid(); 137300906Sasomers bool VdevLookupPoolGuid(); 138300906Sasomers DevdCtl::Guid m_poolGUID; 139300906Sasomers DevdCtl::Guid m_vdevGUID; 140300906Sasomers nvlist_t *m_poolConfig; 141300906Sasomers nvlist_t *m_config; 142300906Sasomers}; 143300906Sasomers 144300906Sasomers//- Special objects ----------------------------------------------------------- 145300906Sasomersextern Vdev NonexistentVdev; 146300906Sasomers 147300906Sasomers//- Vdev Inline Public Methods ------------------------------------------------ 148300906Sasomersinline DevdCtl::Guid 149300906SasomersVdev::PoolGUID() const 150300906Sasomers{ 151300906Sasomers return (m_poolGUID); 152300906Sasomers} 153300906Sasomers 154300906Sasomersinline DevdCtl::Guid 155300906SasomersVdev::GUID() const 156300906Sasomers{ 157300906Sasomers return (m_vdevGUID); 158300906Sasomers} 159300906Sasomers 160300906Sasomersinline nvlist_t * 161300906SasomersVdev::PoolConfig() const 162300906Sasomers{ 163300906Sasomers return (m_poolConfig); 164300906Sasomers} 165300906Sasomers 166300906Sasomersinline nvlist_t * 167300906SasomersVdev::Config() const 168300906Sasomers{ 169300906Sasomers return (m_config); 170300906Sasomers} 171300906Sasomers 172300906Sasomersinline bool 173300906SasomersVdev::DoesNotExist() const 174300906Sasomers{ 175300906Sasomers return (m_config == NULL); 176300906Sasomers} 177300906Sasomers 178300906Sasomers#endif /* _VDEV_H_ */ 179