17a0c41d5SAlan Somers /*- 27a0c41d5SAlan Somers * Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation 37a0c41d5SAlan Somers * All rights reserved. 47a0c41d5SAlan Somers * 57a0c41d5SAlan Somers * Redistribution and use in source and binary forms, with or without 67a0c41d5SAlan Somers * modification, are permitted provided that the following conditions 77a0c41d5SAlan Somers * are met: 87a0c41d5SAlan Somers * 1. Redistributions of source code must retain the above copyright 97a0c41d5SAlan Somers * notice, this list of conditions, and the following disclaimer, 107a0c41d5SAlan Somers * without modification. 117a0c41d5SAlan Somers * 2. Redistributions in binary form must reproduce at minimum a disclaimer 127a0c41d5SAlan Somers * substantially similar to the "NO WARRANTY" disclaimer below 137a0c41d5SAlan Somers * ("Disclaimer") and any redistribution must be conditioned upon 147a0c41d5SAlan Somers * including a substantially similar Disclaimer requirement for further 157a0c41d5SAlan Somers * binary redistribution. 167a0c41d5SAlan Somers * 177a0c41d5SAlan Somers * NO WARRANTY 187a0c41d5SAlan Somers * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 197a0c41d5SAlan Somers * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 207a0c41d5SAlan Somers * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 217a0c41d5SAlan Somers * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 227a0c41d5SAlan Somers * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 237a0c41d5SAlan Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 247a0c41d5SAlan Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 257a0c41d5SAlan Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 267a0c41d5SAlan Somers * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 277a0c41d5SAlan Somers * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 287a0c41d5SAlan Somers * POSSIBILITY OF SUCH DAMAGES. 297a0c41d5SAlan Somers * 307a0c41d5SAlan Somers * Authors: Justin T. Gibbs (Spectra Logic Corporation) 317a0c41d5SAlan Somers */ 327a0c41d5SAlan Somers 337a0c41d5SAlan Somers /** 347a0c41d5SAlan Somers * \file zpool_list.h 357a0c41d5SAlan Somers * 367a0c41d5SAlan Somers * ZpoolList class definition. ZpoolList is a standard container 377a0c41d5SAlan Somers * allowing filtering and iteration of imported ZFS pool information. 387a0c41d5SAlan Somers * 397a0c41d5SAlan Somers * Header requirements: 407a0c41d5SAlan Somers * 417a0c41d5SAlan Somers * #include <list> 427a0c41d5SAlan Somers * #include <string> 437a0c41d5SAlan Somers */ 447a0c41d5SAlan Somers #ifndef _ZPOOL_LIST_H_ 457a0c41d5SAlan Somers #define _ZPOOL_LIST_H_ 467a0c41d5SAlan Somers 477a0c41d5SAlan Somers /*============================ Namespace Control =============================*/ 487a0c41d5SAlan Somers using std::string; 497a0c41d5SAlan Somers 507a0c41d5SAlan Somers /*=========================== Forward Declarations ===========================*/ 517a0c41d5SAlan Somers struct zpool_handle; 527a0c41d5SAlan Somers typedef struct zpool_handle zpool_handle_t; 537a0c41d5SAlan Somers 547a0c41d5SAlan Somers struct nvlist; 557a0c41d5SAlan Somers typedef struct nvlist nvlist_t; 567a0c41d5SAlan Somers 577a0c41d5SAlan Somers class Vdev; 587a0c41d5SAlan Somers 597a0c41d5SAlan Somers /*============================= Class Definitions ============================*/ 607a0c41d5SAlan Somers /*--------------------------------- ZpoolList --------------------------------*/ 617a0c41d5SAlan Somers class ZpoolList; 627a0c41d5SAlan Somers typedef bool PoolFilter_t(zpool_handle_t *pool, nvlist_t *poolConfig, 637a0c41d5SAlan Somers void *filterArg); 647a0c41d5SAlan Somers 657a0c41d5SAlan Somers /** 667a0c41d5SAlan Somers * \brief Container of imported ZFS pool data. 677a0c41d5SAlan Somers * 687a0c41d5SAlan Somers * ZpoolList is a convenience class that converts libzfs's ZFS 697a0c41d5SAlan Somers * pool methods into a standard list container. 707a0c41d5SAlan Somers */ 717a0c41d5SAlan Somers class ZpoolList : public std::list<zpool_handle_t *> 727a0c41d5SAlan Somers { 737a0c41d5SAlan Somers public: 747a0c41d5SAlan Somers /** 757a0c41d5SAlan Somers * \brief Utility ZpoolList construction filter that causes all 767a0c41d5SAlan Somers * pools known to the system to be included in the 777a0c41d5SAlan Somers * instantiated ZpoolList. 787a0c41d5SAlan Somers */ 797a0c41d5SAlan Somers static PoolFilter_t ZpoolAll; 807a0c41d5SAlan Somers 817a0c41d5SAlan Somers /** 827a0c41d5SAlan Somers * \brief Utility ZpoolList construction filter that causes only 837a0c41d5SAlan Somers * a pool known to the system and having the specified GUID 847a0c41d5SAlan Somers * to be included in the instantiated ZpoolList. 857a0c41d5SAlan Somers */ 867a0c41d5SAlan Somers static PoolFilter_t ZpoolByGUID; 877a0c41d5SAlan Somers 887a0c41d5SAlan Somers /** 897a0c41d5SAlan Somers * \brief Utility ZpoolList construction filter that causes only 907a0c41d5SAlan Somers * pools known to the system and having the specified name 917a0c41d5SAlan Somers * to be included in the instantiated ZpoolList. 927a0c41d5SAlan Somers */ 937a0c41d5SAlan Somers static PoolFilter_t ZpoolByName; 947a0c41d5SAlan Somers 957a0c41d5SAlan Somers /** 96*f6a119cfSElyes Haouas * \brief ZpoolList constructor 977a0c41d5SAlan Somers * 987a0c41d5SAlan Somers * \param filter The filter function to use when constructing 997a0c41d5SAlan Somers * the ZpoolList. This may be one of the static 1007a0c41d5SAlan Somers * utility filters defined for ZpoolList or a 1017a0c41d5SAlan Somers * user defined function. 1027a0c41d5SAlan Somers * \param filterArg A single argument to pass into the filter function 1037a0c41d5SAlan Somers * when it is invoked on each candidate pool. 1047a0c41d5SAlan Somers */ 1057a0c41d5SAlan Somers ZpoolList(PoolFilter_t *filter = ZpoolAll, void *filterArg = NULL); 1067a0c41d5SAlan Somers ~ZpoolList(); 1077a0c41d5SAlan Somers 1087a0c41d5SAlan Somers private: 1097a0c41d5SAlan Somers /** 1107a0c41d5SAlan Somers * \brief Helper routine used to populate the internal 1117a0c41d5SAlan Somers * data store of ZFS pool objects using libzfs's 1127a0c41d5SAlan Somers * zpool_iter() function. 1137a0c41d5SAlan Somers * 1147a0c41d5SAlan Somers * \param pool The ZFS pool object to filter. 1157a0c41d5SAlan Somers * \param data User argument passed through zpool_iter(). 1167a0c41d5SAlan Somers */ 1177a0c41d5SAlan Somers static int LoadIterator(zpool_handle_t *pool, void *data); 1187a0c41d5SAlan Somers 1197a0c41d5SAlan Somers /** 1207a0c41d5SAlan Somers * \brief The filter with which this ZpoolList was constructed. 1217a0c41d5SAlan Somers */ 1227a0c41d5SAlan Somers PoolFilter_t *m_filter; 1237a0c41d5SAlan Somers 1247a0c41d5SAlan Somers /** 1257a0c41d5SAlan Somers * \brief The filter argument with which this ZpoolList was 1267a0c41d5SAlan Somers * constructed. 1277a0c41d5SAlan Somers */ 1287a0c41d5SAlan Somers void *m_filterArg; 1297a0c41d5SAlan Somers }; 1307a0c41d5SAlan Somers 1317a0c41d5SAlan Somers #endif /* _ZPOOL_ITERATOR_H_ */ 132