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 zpool_list.h
35 *
36 * ZpoolList class definition.  ZpoolList is a standard container
37 * allowing filtering and iteration of imported ZFS pool information.
38 *
39 * Header requirements:
40 *
41 *    #include <list>
42 *    #include <string>
43 */
44#ifndef	_ZPOOL_LIST_H_
45#define	_ZPOOL_LIST_H_
46
47/*============================ Namespace Control =============================*/
48using std::string;
49
50/*=========================== Forward Declarations ===========================*/
51struct zpool_handle;
52typedef struct zpool_handle zpool_handle_t;
53
54struct nvlist;
55typedef struct nvlist nvlist_t;
56
57class Vdev;
58
59/*============================= Class Definitions ============================*/
60/*--------------------------------- ZpoolList --------------------------------*/
61class ZpoolList;
62typedef bool PoolFilter_t(zpool_handle_t *pool, nvlist_t *poolConfig,
63			  void *filterArg);
64
65/**
66 * \brief Container of imported ZFS pool data.
67 *
68 * ZpoolList is a convenience class that converts libzfs's ZFS
69 * pool methods into a standard list container.
70 */
71class ZpoolList : public std::list<zpool_handle_t *>
72{
73public:
74	/**
75	 * \brief Utility ZpoolList construction filter that causes all
76	 *        pools known to the system to be included in the
77	 *        instantiated ZpoolList.
78	 */
79	static PoolFilter_t ZpoolAll;
80
81	/**
82	 * \brief Utility ZpoolList construction filter that causes only
83	 *        a pool known to the system and having the specified GUID
84	 *        to be included in the instantiated ZpoolList.
85	 */
86	static PoolFilter_t ZpoolByGUID;
87
88	/**
89	 * \brief Utility ZpoolList construction filter that causes only
90	 *        pools known to the system and having the specified name
91	 *        to be included in the instantiated ZpoolList.
92	 */
93	static PoolFilter_t ZpoolByName;
94
95	/**
96	 * \brief ZpoolList constructor
97	 *
98	 * \param filter     The filter function to use when constructing
99	 *                   the ZpoolList.  This may be one of the static
100	 *                   utility filters defined for ZpoolList or a
101	 *                   user defined function.
102	 * \param filterArg  A single argument to pass into the filter function
103	 *                   when it is invoked on each candidate pool.
104	 */
105	ZpoolList(PoolFilter_t *filter = ZpoolAll, void *filterArg = NULL);
106	~ZpoolList();
107
108private:
109	/**
110	 * \brief Helper routine used to populate the internal
111	 *        data store of ZFS pool objects using libzfs's
112	 *        zpool_iter() function.
113	 *
114	 * \param pool  The ZFS pool object to filter.
115	 * \param data  User argument passed through zpool_iter().
116	 */
117	static int LoadIterator(zpool_handle_t *pool, void *data);
118
119	/**
120	 * \brief The filter with which this ZpoolList was constructed.
121	 */
122	PoolFilter_t *m_filter;
123
124	/**
125	 * \brief The filter argument with which this ZpoolList was
126	 *        constructed.
127	 */
128	void	     *m_filterArg;
129};
130
131#endif	/* _ZPOOL_ITERATOR_H_ */
132