/*-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 zpool_list.h34*35* ZpoolList class definition. ZpoolList is a standard container36* allowing filtering and iteration of imported ZFS pool information.37*38* Header requirements:39*40* #include <list>41* #include <string>42*/43#ifndef _ZPOOL_LIST_H_44#define _ZPOOL_LIST_H_4546/*============================ Namespace Control =============================*/47using std::string;4849/*=========================== Forward Declarations ===========================*/50struct zpool_handle;51typedef struct zpool_handle zpool_handle_t;5253struct nvlist;54typedef struct nvlist nvlist_t;5556class Vdev;5758/*============================= Class Definitions ============================*/59/*--------------------------------- ZpoolList --------------------------------*/60class ZpoolList;61typedef bool PoolFilter_t(zpool_handle_t *pool, nvlist_t *poolConfig,62void *filterArg);6364/**65* \brief Container of imported ZFS pool data.66*67* ZpoolList is a convenience class that converts libzfs's ZFS68* pool methods into a standard list container.69*/70class ZpoolList : public std::list<zpool_handle_t *>71{72public:73/**74* \brief Utility ZpoolList construction filter that causes all75* pools known to the system to be included in the76* instantiated ZpoolList.77*/78static PoolFilter_t ZpoolAll;7980/**81* \brief Utility ZpoolList construction filter that causes only82* a pool known to the system and having the specified GUID83* to be included in the instantiated ZpoolList.84*/85static PoolFilter_t ZpoolByGUID;8687/**88* \brief Utility ZpoolList construction filter that causes only89* pools known to the system and having the specified name90* to be included in the instantiated ZpoolList.91*/92static PoolFilter_t ZpoolByName;9394/**95* \brief ZpoolList constructor96*97* \param filter The filter function to use when constructing98* the ZpoolList. This may be one of the static99* utility filters defined for ZpoolList or a100* user defined function.101* \param filterArg A single argument to pass into the filter function102* when it is invoked on each candidate pool.103*/104ZpoolList(PoolFilter_t *filter = ZpoolAll, void *filterArg = NULL);105~ZpoolList();106107private:108/**109* \brief Helper routine used to populate the internal110* data store of ZFS pool objects using libzfs's111* zpool_iter() function.112*113* \param pool The ZFS pool object to filter.114* \param data User argument passed through zpool_iter().115*/116static int LoadIterator(zpool_handle_t *pool, void *data);117118/**119* \brief The filter with which this ZpoolList was constructed.120*/121PoolFilter_t *m_filter;122123/**124* \brief The filter argument with which this ZpoolList was125* constructed.126*/127void *m_filterArg;128};129130#endif /* _ZPOOL_ITERATOR_H_ */131132133