Path: blob/main/cddl/usr.sbin/zfsd/vdev_iterator.h
103554 views
/*-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_iterator.h34*35* VdevIterator class definition.36*37* Header requirements:38*39* #include <list>40*/41#ifndef _VDEV_ITERATOR_H_42#define _VDEV_ITERATOR_H_4344/*=========================== Forward Declarations ===========================*/45struct zpool_handle;46typedef struct zpool_handle zpool_handle_t;4748struct nvlist;49typedef struct nvlist nvlist_t;5051class Vdev;5253/*============================= Class Definitions ============================*/54/*------------------------------- VdevIterator -------------------------------*/55typedef bool VdevCallback_t(Vdev &vdev, void *cbArg);5657/**58* \brief VdevIterator provides mechanisms for traversing and searching59* the leaf vdevs contained in a ZFS pool configuration.60*/61class VdevIterator62{63public:64/**65* \brief Instantiate a VdevIterator for the given ZFS pool.66*67* \param pool The ZFS pool to traverse/search.68*/69VdevIterator(zpool_handle_t *pool);7071/**72* \brief Instantiate a VdevIterator for the given ZFS pool.73*74* \param poolConfig The configuration data for the ZFS pool75* to traverse/search.76*/77VdevIterator(nvlist_t *poolConfig);7879/**80* \brief Reset this iterator's cursor so that Next() will81* report the first member of the pool.82*/83void Reset();8485/**86* \brief Report the leaf vdev at this iterator's cursor and increment87* the cursor to the next leaf pool member.88*/89nvlist_t *Next();9091/**92* \brief Traverse the entire pool configuration starting its93* first member, returning a vdev object with the given94* vdev GUID if found.95*96* \param vdevGUID The vdev GUID of the vdev object to find.97*98* \return A Vdev object for the matching vdev if found. Otherwise99* NULL.100*101* Upon return, the VdevIterator's cursor points to the vdev just102* past the returned vdev or end() if no matching vdev is found.103*/104nvlist_t *Find(DevdCtl::Guid vdevGUID);105106/**107* \brief Perform the specified operation on each leaf member of108* a pool's vdev membership.109*110* \param cb Callback function to execute for each member.111* \param cbArg Argument to pass to cb.112*/113void Each(VdevCallback_t *cb, void *cbArg);114115private:116nvlist_t *m_poolConfig;117std::list<nvlist_t *> m_vdevQueue;118};119120#endif /* _VDEV_ITERATOR_H_ */121122123