2 * Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * Authors: Justin T. Gibbs (Spectra Logic Corporation)
38 * Implementation of the ZpoolList class.
40 #include <sys/cdefs.h>
41 #include <sys/fs/zfs.h>
51 #include <devdctl/guid.h>
52 #include <devdctl/event.h>
53 #include <devdctl/event_factory.h>
54 #include <devdctl/exception.h>
55 #include <devdctl/consumer.h>
58 #include "vdev_iterator.h"
59 #include "zpool_list.h"
62 /*============================ Namespace Control =============================*/
65 /*=========================== Class Implementations ==========================*/
66 /*--------------------------------- ZpoolList --------------------------------*/
68 ZpoolList::ZpoolAll(zpool_handle_t *pool, nvlist_t *poolConfig, void *cbArg)
74 ZpoolList::ZpoolByGUID(zpool_handle_t *pool, nvlist_t *poolConfig,
77 Guid *desiredPoolGUID(static_cast<Guid *>(cbArg));
80 /* We are only intested in the pool that matches our pool GUID. */
81 return (nvlist_lookup_uint64(poolConfig, ZPOOL_CONFIG_POOL_GUID,
83 && poolGUID == (uint64_t)*desiredPoolGUID);
87 ZpoolList::ZpoolByName(zpool_handle_t *pool, nvlist_t *poolConfig, void *cbArg)
89 const string &desiredPoolName(*static_cast<const string *>(cbArg));
91 /* We are only intested in the pool that matches our pool GUID. */
92 return (desiredPoolName == zpool_get_name(pool));
96 ZpoolList::LoadIterator(zpool_handle_t *pool, void *data)
98 ZpoolList *zpl(reinterpret_cast<ZpoolList *>(data));
99 nvlist_t *poolConfig(zpool_get_config(pool, NULL));
101 if (zpl->m_filter(pool, poolConfig, zpl->m_filterArg))
102 zpl->push_back(pool);
108 ZpoolList::ZpoolList(PoolFilter_t *filter, void * filterArg)
110 m_filterArg(filterArg)
112 zpool_iter(g_zfsHandle, LoadIterator, this);
115 ZpoolList::~ZpoolList()
117 for (iterator it(begin()); it != end(); it++)