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_iterator.h 35 * 36 * VdevIterator class definition. 37 * 38 * Header requirements: 39 * 40 * #include <list> 41 */ 42 #ifndef _VDEV_ITERATOR_H_ 43 #define _VDEV_ITERATOR_H_ 44 45 /*=========================== Forward Declarations ===========================*/ 46 struct zpool_handle; 47 typedef struct zpool_handle zpool_handle_t; 48 49 struct nvlist; 50 typedef struct nvlist nvlist_t; 51 52 class Vdev; 53 54 /*============================= Class Definitions ============================*/ 55 /*------------------------------- VdevIterator -------------------------------*/ 56 typedef bool VdevCallback_t(Vdev &vdev, void *cbArg); 57 58 /** 59 * \brief VdevIterator provides mechanisms for traversing and searching 60 * the leaf vdevs contained in a ZFS pool configuration. 61 */ 62 class VdevIterator 63 { 64 public: 65 /** 66 * \brief Instantiate a VdevIterator for the given ZFS pool. 67 * 68 * \param pool The ZFS pool to traverse/search. 69 */ 70 VdevIterator(zpool_handle_t *pool); 71 72 /** 73 * \brief Instantiate a VdevIterator for the given ZFS pool. 74 * 75 * \param poolConfig The configuration data for the ZFS pool 76 * to traverse/search. 77 */ 78 VdevIterator(nvlist_t *poolConfig); 79 80 /** 81 * \brief Reset this iterator's cursor so that Next() will 82 * report the first member of the pool. 83 */ 84 void Reset(); 85 86 /** 87 * \brief Report the leaf vdev at this iterator's cursor and increment 88 * the cursor to the next leaf pool member. 89 */ 90 nvlist_t *Next(); 91 92 /** 93 * \brief Traverse the entire pool configuration starting its 94 * first member, returning a vdev object with the given 95 * vdev GUID if found. 96 * 97 * \param vdevGUID The vdev GUID of the vdev object to find. 98 * 99 * \return A Vdev object for the matching vdev if found. Otherwise 100 * NULL. 101 * 102 * Upon return, the VdevIterator's cursor points to the vdev just 103 * past the returned vdev or end() if no matching vdev is found. 104 */ 105 nvlist_t *Find(DevdCtl::Guid vdevGUID); 106 107 /** 108 * \brief Perform the specified operation on each leaf member of 109 * a pool's vdev membership. 110 * 111 * \param cb Callback function to execute for each member. 112 * \param cbArg Argument to pass to cb. 113 */ 114 void Each(VdevCallback_t *cb, void *cbArg); 115 116 private: 117 nvlist_t *m_poolConfig; 118 std::list<nvlist_t *> m_vdevQueue; 119 }; 120 121 #endif /* _VDEV_ITERATOR_H_ */ 122