xref: /freebsd/cddl/usr.sbin/zfsd/zpool_list.h (revision f6a119cf8d23d53093d3c094708fb3352fdd43a5)
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  * $FreeBSD$
337a0c41d5SAlan Somers  */
347a0c41d5SAlan Somers 
357a0c41d5SAlan Somers /**
367a0c41d5SAlan Somers  * \file zpool_list.h
377a0c41d5SAlan Somers  *
387a0c41d5SAlan Somers  * ZpoolList class definition.  ZpoolList is a standard container
397a0c41d5SAlan Somers  * allowing filtering and iteration of imported ZFS pool information.
407a0c41d5SAlan Somers  *
417a0c41d5SAlan Somers  * Header requirements:
427a0c41d5SAlan Somers  *
437a0c41d5SAlan Somers  *    #include <list>
447a0c41d5SAlan Somers  *    #include <string>
457a0c41d5SAlan Somers  */
467a0c41d5SAlan Somers #ifndef	_ZPOOL_LIST_H_
477a0c41d5SAlan Somers #define	_ZPOOL_LIST_H_
487a0c41d5SAlan Somers 
497a0c41d5SAlan Somers /*============================ Namespace Control =============================*/
507a0c41d5SAlan Somers using std::string;
517a0c41d5SAlan Somers 
527a0c41d5SAlan Somers /*=========================== Forward Declarations ===========================*/
537a0c41d5SAlan Somers struct zpool_handle;
547a0c41d5SAlan Somers typedef struct zpool_handle zpool_handle_t;
557a0c41d5SAlan Somers 
567a0c41d5SAlan Somers struct nvlist;
577a0c41d5SAlan Somers typedef struct nvlist nvlist_t;
587a0c41d5SAlan Somers 
597a0c41d5SAlan Somers class Vdev;
607a0c41d5SAlan Somers 
617a0c41d5SAlan Somers /*============================= Class Definitions ============================*/
627a0c41d5SAlan Somers /*--------------------------------- ZpoolList --------------------------------*/
637a0c41d5SAlan Somers class ZpoolList;
647a0c41d5SAlan Somers typedef bool PoolFilter_t(zpool_handle_t *pool, nvlist_t *poolConfig,
657a0c41d5SAlan Somers 			  void *filterArg);
667a0c41d5SAlan Somers 
677a0c41d5SAlan Somers /**
687a0c41d5SAlan Somers  * \brief Container of imported ZFS pool data.
697a0c41d5SAlan Somers  *
707a0c41d5SAlan Somers  * ZpoolList is a convenience class that converts libzfs's ZFS
717a0c41d5SAlan Somers  * pool methods into a standard list container.
727a0c41d5SAlan Somers  */
737a0c41d5SAlan Somers class ZpoolList : public std::list<zpool_handle_t *>
747a0c41d5SAlan Somers {
757a0c41d5SAlan Somers public:
767a0c41d5SAlan Somers 	/**
777a0c41d5SAlan Somers 	 * \brief Utility ZpoolList construction filter that causes all
787a0c41d5SAlan Somers 	 *        pools known to the system to be included in the
797a0c41d5SAlan Somers 	 *        instantiated ZpoolList.
807a0c41d5SAlan Somers 	 */
817a0c41d5SAlan Somers 	static PoolFilter_t ZpoolAll;
827a0c41d5SAlan Somers 
837a0c41d5SAlan Somers 	/**
847a0c41d5SAlan Somers 	 * \brief Utility ZpoolList construction filter that causes only
857a0c41d5SAlan Somers 	 *        a pool known to the system and having the specified GUID
867a0c41d5SAlan Somers 	 *        to be included in the instantiated ZpoolList.
877a0c41d5SAlan Somers 	 */
887a0c41d5SAlan Somers 	static PoolFilter_t ZpoolByGUID;
897a0c41d5SAlan Somers 
907a0c41d5SAlan Somers 	/**
917a0c41d5SAlan Somers 	 * \brief Utility ZpoolList construction filter that causes only
927a0c41d5SAlan Somers 	 *        pools known to the system and having the specified name
937a0c41d5SAlan Somers 	 *        to be included in the instantiated ZpoolList.
947a0c41d5SAlan Somers 	 */
957a0c41d5SAlan Somers 	static PoolFilter_t ZpoolByName;
967a0c41d5SAlan Somers 
977a0c41d5SAlan Somers 	/**
98*f6a119cfSElyes Haouas 	 * \brief ZpoolList constructor
997a0c41d5SAlan Somers 	 *
1007a0c41d5SAlan Somers 	 * \param filter     The filter function to use when constructing
1017a0c41d5SAlan Somers 	 *                   the ZpoolList.  This may be one of the static
1027a0c41d5SAlan Somers 	 *                   utility filters defined for ZpoolList or a
1037a0c41d5SAlan Somers 	 *                   user defined function.
1047a0c41d5SAlan Somers 	 * \param filterArg  A single argument to pass into the filter function
1057a0c41d5SAlan Somers 	 *                   when it is invoked on each candidate pool.
1067a0c41d5SAlan Somers 	 */
1077a0c41d5SAlan Somers 	ZpoolList(PoolFilter_t *filter = ZpoolAll, void *filterArg = NULL);
1087a0c41d5SAlan Somers 	~ZpoolList();
1097a0c41d5SAlan Somers 
1107a0c41d5SAlan Somers private:
1117a0c41d5SAlan Somers 	/**
1127a0c41d5SAlan Somers 	 * \brief Helper routine used to populate the internal
1137a0c41d5SAlan Somers 	 *        data store of ZFS pool objects using libzfs's
1147a0c41d5SAlan Somers 	 *        zpool_iter() function.
1157a0c41d5SAlan Somers 	 *
1167a0c41d5SAlan Somers 	 * \param pool  The ZFS pool object to filter.
1177a0c41d5SAlan Somers 	 * \param data  User argument passed through zpool_iter().
1187a0c41d5SAlan Somers 	 */
1197a0c41d5SAlan Somers 	static int LoadIterator(zpool_handle_t *pool, void *data);
1207a0c41d5SAlan Somers 
1217a0c41d5SAlan Somers 	/**
1227a0c41d5SAlan Somers 	 * \brief The filter with which this ZpoolList was constructed.
1237a0c41d5SAlan Somers 	 */
1247a0c41d5SAlan Somers 	PoolFilter_t *m_filter;
1257a0c41d5SAlan Somers 
1267a0c41d5SAlan Somers 	/**
1277a0c41d5SAlan Somers 	 * \brief The filter argument with which this ZpoolList was
1287a0c41d5SAlan Somers 	 *        constructed.
1297a0c41d5SAlan Somers 	 */
1307a0c41d5SAlan Somers 	void	     *m_filterArg;
1317a0c41d5SAlan Somers };
1327a0c41d5SAlan Somers 
1337a0c41d5SAlan Somers #endif	/* _ZPOOL_ITERATOR_H_ */
134