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 zfsd_exception.h
35 *
36 * Definition of the ZfsdException class hierarchy.  All exceptions
37 * explicitly thrown by Zfsd are defined here.
38 *
39 * Header requirements:
40 *     #include <string>
41 *
42 *     #include <devdctl/exception.h>
43 */
44#ifndef	_ZFSD_EXCEPTION_H_
45#define	_ZFSD_EXCEPTION_H_
46
47/*=========================== Forward Declarations ===========================*/
48struct zpool_handle;
49typedef struct zpool_handle zpool_handle_t;
50
51struct nvlist;
52typedef struct nvlist nvlist_t;
53
54/*============================= Class Definitions ============================*/
55/*------------------------------- ZfsdException ------------------------------*/
56/**
57 * \brief Class allowing unified reporting/logging of exceptional events.
58 */
59class ZfsdException : public DevdCtl::Exception
60{
61public:
62	/**
63	 * \brief ZfsdException constructor allowing arbitrary string
64	 *        data to be reported.
65	 *
66	 * \param fmt  Printf-like string format specifier.
67	 */
68	ZfsdException(const char *fmt, ...);
69
70	/**
71	 * \brief ZfsdException constructor allowing arbitrary string
72	 *        data to be reported and associated with the configuration
73	 *        data for a ZFS pool.
74	 *
75	 * \param pool  Pool handle describing the pool to which this
76	 *              exception is associated.
77	 * \param fmt   Printf-like string format specifier.
78	 *
79	 * Instantiation with this method is used to report global
80	 * pool errors.
81	 */
82	ZfsdException(zpool_handle_t *pool, const char *, ...);
83
84	/**
85	 * \brief ZfsdException constructor allowing arbitrary string
86	 *        data to be reported and associated with the configuration
87	 *        data for a ZFS pool.
88	 *
89	 * \param poolConfig  Pool configuration describing the pool to
90	 *                    which this exception is associated.
91	 * \param fmt         Printf-like string format specifier.
92	 *
93	 * Instantiation with this method is used to report global
94	 * pool errors.
95	 */
96	ZfsdException(nvlist_t *poolConfig, const char *, ...);
97
98	/**
99	 * \brief Emit exception data to syslog(3).
100	 */
101	virtual void Log() const;
102private:
103	nvlist_t     *m_poolConfig;
104	nvlist_t     *m_vdevConfig;
105};
106
107#endif /* _ZFSD_EXCEPTION_H_ */
108