/*-1* Copyright (c) 2011, 2012, 2013 Spectra Logic Corporation2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions, and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* substantially similar to the "NO WARRANTY" disclaimer below12* ("Disclaimer") and any redistribution must be conditioned upon13* including a substantially similar Disclaimer requirement for further14* binary redistribution.15*16* NO WARRANTY17* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR20* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL22* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS23* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)24* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,25* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING26* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE27* POSSIBILITY OF SUCH DAMAGES.28*29* Authors: Justin T. Gibbs (Spectra Logic Corporation)30*/3132/**33* \file zpool_list.cc34*35* Implementation of the ZpoolList class.36*/37#include <sys/cdefs.h>38#include <sys/byteorder.h>39#include <sys/fs/zfs.h>4041#include <stdint.h>4243#include <libzfs.h>4445#include <list>46#include <map>47#include <string>4849#include <devdctl/guid.h>50#include <devdctl/event.h>51#include <devdctl/event_factory.h>52#include <devdctl/exception.h>53#include <devdctl/consumer.h>5455#include "vdev.h"56#include "vdev_iterator.h"57#include "zpool_list.h"58#include "zfsd.h"5960/*============================ Namespace Control =============================*/61using DevdCtl::Guid;6263/*=========================== Class Implementations ==========================*/64/*--------------------------------- ZpoolList --------------------------------*/65bool66ZpoolList::ZpoolAll(zpool_handle_t *pool, nvlist_t *poolConfig, void *cbArg)67{68return (true);69}7071bool72ZpoolList::ZpoolByGUID(zpool_handle_t *pool, nvlist_t *poolConfig,73void *cbArg)74{75Guid *desiredPoolGUID(static_cast<Guid *>(cbArg));76uint64_t poolGUID;7778/* We are only intested in the pool that matches our pool GUID. */79return (nvlist_lookup_uint64(poolConfig, ZPOOL_CONFIG_POOL_GUID,80&poolGUID) == 081&& poolGUID == (uint64_t)*desiredPoolGUID);82}8384bool85ZpoolList::ZpoolByName(zpool_handle_t *pool, nvlist_t *poolConfig, void *cbArg)86{87const string &desiredPoolName(*static_cast<const string *>(cbArg));8889/* We are only intested in the pool that matches our pool GUID. */90return (desiredPoolName == zpool_get_name(pool));91}9293int94ZpoolList::LoadIterator(zpool_handle_t *pool, void *data)95{96ZpoolList *zpl(reinterpret_cast<ZpoolList *>(data));97nvlist_t *poolConfig(zpool_get_config(pool, NULL));9899if (zpl->m_filter(pool, poolConfig, zpl->m_filterArg))100zpl->push_back(pool);101else102zpool_close(pool);103return (0);104}105106ZpoolList::ZpoolList(PoolFilter_t *filter, void * filterArg)107: m_filter(filter),108m_filterArg(filterArg)109{110zpool_iter(g_zfsHandle, LoadIterator, this);111}112113ZpoolList::~ZpoolList()114{115for (iterator it(begin()); it != end(); it++)116zpool_close(*it);117118clear();119}120121122