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$ 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(); 111305286Sdim 112305286Sdim /** 113305286Sdim * \brief No-op virtual destructor, since this class has virtual 114305286Sdim * functions. 115305286Sdim */ 116305286Sdim virtual ~Vdev(); 117300906Sasomers bool DoesNotExist() const; 118300906Sasomers 119300906Sasomers /** 120300906Sasomers * \brief Return a list of the vdev's children. 121300906Sasomers */ 122300906Sasomers std::list<Vdev> Children(); 123300906Sasomers 124300906Sasomers virtual DevdCtl::Guid GUID() const; 125300906Sasomers bool IsSpare() const; 126300906Sasomers virtual DevdCtl::Guid PoolGUID() const; 127300906Sasomers virtual vdev_state State() const; 128300906Sasomers std::string Path() const; 129300906Sasomers virtual std::string PhysicalPath() const; 130300906Sasomers std::string GUIDString() const; 131300906Sasomers nvlist_t *PoolConfig() const; 132300906Sasomers nvlist_t *Config() const; 133300906Sasomers Vdev Parent(); 134300906Sasomers Vdev RootVdev(); 135300906Sasomers std::string Name(zpool_handle_t *, bool verbose) const; 136300906Sasomers bool IsSpare(); 137300906Sasomers bool IsAvailableSpare() const; 138300906Sasomers bool IsActiveSpare() const; 139300906Sasomers bool IsResilvering() const; 140300906Sasomers 141300906Sasomersprivate: 142300906Sasomers void VdevLookupGuid(); 143300906Sasomers bool VdevLookupPoolGuid(); 144300906Sasomers DevdCtl::Guid m_poolGUID; 145300906Sasomers DevdCtl::Guid m_vdevGUID; 146300906Sasomers nvlist_t *m_poolConfig; 147300906Sasomers nvlist_t *m_config; 148300906Sasomers}; 149300906Sasomers 150300906Sasomers//- Special objects ----------------------------------------------------------- 151300906Sasomersextern Vdev NonexistentVdev; 152300906Sasomers 153300906Sasomers//- Vdev Inline Public Methods ------------------------------------------------ 154305286Sdiminline Vdev::~Vdev() 155305286Sdim{ 156305286Sdim} 157305286Sdim 158300906Sasomersinline DevdCtl::Guid 159300906SasomersVdev::PoolGUID() const 160300906Sasomers{ 161300906Sasomers return (m_poolGUID); 162300906Sasomers} 163300906Sasomers 164300906Sasomersinline DevdCtl::Guid 165300906SasomersVdev::GUID() const 166300906Sasomers{ 167300906Sasomers return (m_vdevGUID); 168300906Sasomers} 169300906Sasomers 170300906Sasomersinline nvlist_t * 171300906SasomersVdev::PoolConfig() const 172300906Sasomers{ 173300906Sasomers return (m_poolConfig); 174300906Sasomers} 175300906Sasomers 176300906Sasomersinline nvlist_t * 177300906SasomersVdev::Config() const 178300906Sasomers{ 179300906Sasomers return (m_config); 180300906Sasomers} 181300906Sasomers 182300906Sasomersinline bool 183300906SasomersVdev::DoesNotExist() const 184300906Sasomers{ 185300906Sasomers return (m_config == NULL); 186300906Sasomers} 187300906Sasomers 188300906Sasomers#endif /* _VDEV_H_ */ 189