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