Path: blob/main/cddl/usr.sbin/zfsd/zfsd_exception.cc
106712 views
/*-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 zfsd_exception34*35* Implementation of the ZfsdException class.36*/37#include <sys/cdefs.h>38#include <sys/byteorder.h>39#include <sys/fs/zfs.h>4041#include <syslog.h>4243#include <string>44#include <list>45#include <sstream>4647#include <devdctl/exception.h>48#include <devdctl/guid.h>4950#include <libzfs.h>5152#include "vdev.h"53#include "zfsd_exception.h"54/*============================ Namespace Control =============================*/55using std::endl;56using std::string;57using std::stringstream;5859/*=========================== Class Implementations ==========================*/60/*------------------------------- ZfsdException ------------------------------*/61ZfsdException::ZfsdException(const char *fmt, ...)62: DevdCtl::Exception(),63m_poolConfig(NULL),64m_vdevConfig(NULL)65{66va_list ap;6768va_start(ap, fmt);69FormatLog(fmt, ap);70va_end(ap);71}7273ZfsdException::ZfsdException(zpool_handle_t *pool, const char *fmt, ...)74: DevdCtl::Exception(),75m_poolConfig(zpool_get_config(pool, NULL)),76m_vdevConfig(NULL)77{78va_list ap;7980va_start(ap, fmt);81FormatLog(fmt, ap);82va_end(ap);83}8485ZfsdException::ZfsdException(nvlist_t *poolConfig, const char *fmt, ...)86: DevdCtl::Exception(),87m_poolConfig(poolConfig),88m_vdevConfig(NULL)89{90va_list ap;9192va_start(ap, fmt);93FormatLog(fmt, ap);94va_end(ap);95}9697void98ZfsdException::Log() const99{100stringstream output;101102if (m_poolConfig != NULL) {103104output << "Pool ";105106const char *poolName;107if (nvlist_lookup_string(m_poolConfig, ZPOOL_CONFIG_POOL_NAME,108&poolName) == 0)109output << poolName;110else111output << "Unknown";112output << ": ";113}114115if (m_vdevConfig != NULL) {116117if (m_poolConfig != NULL) {118Vdev vdev(m_poolConfig, m_vdevConfig);119120output << "Vdev " << vdev.GUID() << ": ";121} else {122Vdev vdev(m_vdevConfig);123124output << "Pool " << vdev.PoolGUID() << ": ";125output << "Vdev " << vdev.GUID() << ": ";126}127}128129output << m_log << endl;130syslog(LOG_ERR, "%s", output.str().c_str());131}132133134135