2 * Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * Authors: Justin T. Gibbs (Spectra Logic Corporation)
36 * \file vdev_iterator.h
38 * VdevIterator class definition.
40 * Header requirements:
44 #ifndef _VDEV_ITERATOR_H_
45 #define _VDEV_ITERATOR_H_
47 /*=========================== Forward Declarations ===========================*/
49 typedef struct zpool_handle zpool_handle_t;
52 typedef struct nvlist nvlist_t;
56 /*============================= Class Definitions ============================*/
57 /*------------------------------- VdevIterator -------------------------------*/
58 typedef bool VdevCallback_t(Vdev &vdev, void *cbArg);
61 * \brief VdevIterator provides mechanisms for traversing and searching
62 * the leaf vdevs contained in a ZFS pool configuration.
68 * \brief Instantiate a VdevIterator for the given ZFS pool.
70 * \param pool The ZFS pool to traverse/search.
72 VdevIterator(zpool_handle_t *pool);
75 * \brief Instantiate a VdevIterator for the given ZFS pool.
77 * \param poolConfig The configuration data for the ZFS pool
80 VdevIterator(nvlist_t *poolConfig);
83 * \brief Reset this iterator's cursor so that Next() will
84 * report the first member of the pool.
89 * \brief Report the leaf vdev at this iterator's cursor and increment
90 * the cursor to the next leaf pool member.
95 * \brief Traverse the entire pool configuration starting its
96 * first member, returning a vdev object with the given
99 * \param vdevGUID The vdev GUID of the vdev object to find.
101 * \return A Vdev object for the matching vdev if found. Otherwise
104 * Upon return, the VdevIterator's cursor points to the vdev just
105 * past the returned vdev or end() if no matching vdev is found.
107 nvlist_t *Find(DevdCtl::Guid vdevGUID);
110 * \brief Perform the specified operation on each leaf member of
111 * a pool's vdev membership.
113 * \param cb Callback function to execute for each member.
114 * \param cbArg Argument to pass to cb.
116 void Each(VdevCallback_t *cb, void *cbArg);
119 nvlist_t *m_poolConfig;
120 std::list<nvlist_t *> m_vdevQueue;
123 #endif /* _VDEV_ITERATOR_H_ */