/*-1* Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Justin T. Gibbs (Spectra Logic Corporation)30*/3132/**33* \file vdev.h34*35* Definition of the Vdev class.36*37* Header requirements:38*39* #include <string>40* #include <list>41*42* #include <devdctl/guid.h>43*/44#ifndef _VDEV_H_45#define _VDEV_H_4647/*=========================== Forward Declarations ===========================*/48struct zpool_handle;49typedef struct zpool_handle zpool_handle_t;5051struct nvlist;52typedef struct nvlist nvlist_t;5354/*============================= Class Definitions ============================*/55/*----------------------------------- Vdev -----------------------------------*/56/**57* \brief Wrapper class for a vdev's name/value configuration list58* simplifying access to commonly used vdev attributes.59*/60class Vdev61{62public:63/**64* \brief Instantiate a vdev object for a vdev that is a member65* of an imported pool.66*67* \param pool The pool object containing the vdev with68* configuration data provided in vdevConfig.69* \param vdevConfig Vdev configuration data.70*71* This method should be used whenever dealing with vdev's72* enumerated via the ZpoolList class. The in-core configuration73* data for a vdev does not contain all of the items found in74* the on-disk label. This requires the vdev class to augment75* the data in vdevConfig with data found in the pool object.76*/77Vdev(zpool_handle_t *pool, nvlist_t *vdevConfig);7879/**80* \brief Instantiate a vdev object for a vdev that is a member81* of a pool configuration.82*83* \param poolConfig The pool configuration containing the vdev84* configuration data provided in vdevConfig.85* \param vdevConfig Vdev configuration data.86*87* This method should be used whenever dealing with vdev's88* enumerated via the ZpoolList class. The in-core configuration89* data for a vdev does not contain all of the items found in90* the on-disk label. This requires the vdev class to augment91* the data in vdevConfig with data found in the pool object.92*/93Vdev(nvlist_t *poolConfig, nvlist_t *vdevConfig);9495/**96* \brief Instantiate a vdev object from a ZFS label stored on97* the device.98*99* \param vdevConfig The name/value list retrieved by reading100* the label information on a leaf vdev.101*/102Vdev(nvlist_t *vdevConfig);103104/**105* \brief No-op copy constructor for nonexistent vdevs.106*/107Vdev();108109/**110* \brief No-op virtual destructor, since this class has virtual111* functions.112*/113virtual ~Vdev();114bool DoesNotExist() const;115116/**117* \brief Return a list of the vdev's children.118*/119std::list<Vdev> Children();120121virtual DevdCtl::Guid GUID() const;122bool IsSpare() const;123virtual DevdCtl::Guid PoolGUID() const;124virtual vdev_state State() const;125std::string Path() const;126virtual std::string PhysicalPath() const;127std::string GUIDString() const;128nvlist_t *PoolConfig() const;129nvlist_t *Config() const;130Vdev Parent();131Vdev RootVdev();132virtual std::string Name(zpool_handle_t *, bool verbose) const;133bool IsSpare();134bool IsAvailableSpare() const;135bool IsActiveSpare() const;136bool IsResilvering() const;137138private:139void VdevLookupGuid();140bool VdevLookupPoolGuid();141DevdCtl::Guid m_poolGUID;142DevdCtl::Guid m_vdevGUID;143nvlist_t *m_poolConfig;144nvlist_t *m_config;145};146147//- Special objects -----------------------------------------------------------148extern Vdev NonexistentVdev;149150//- Vdev Inline Public Methods ------------------------------------------------151inline Vdev::~Vdev()152{153}154155inline DevdCtl::Guid156Vdev::PoolGUID() const157{158return (m_poolGUID);159}160161inline DevdCtl::Guid162Vdev::GUID() const163{164return (m_vdevGUID);165}166167inline nvlist_t *168Vdev::PoolConfig() const169{170return (m_poolConfig);171}172173inline nvlist_t *174Vdev::Config() const175{176return (m_config);177}178179inline bool180Vdev::DoesNotExist() const181{182return (m_config == NULL);183}184185#endif /* _VDEV_H_ */186187188