/*-1* Copyright (c) 2011, 2012, 2013, 2014 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.h34*35* Class definitions and supporting data strutures for the ZFS fault36* management daemon.37*38* Header requirements:39*40* #include <sys/fs/zfs.h>41*42* #include <libzfs.h>43*44* #include <list>45* #include <map>46* #include <string>47*48* #include <devdctl/guid.h>49* #include <devdctl/event.h>50* #include <devdctl/event_factory.h>51* #include <devdctl/consumer.h>52*53* #include "vdev_iterator.h"54*/55#ifndef _ZFSD_H_56#define _ZFSD_H_5758/*=========================== Forward Declarations ===========================*/59struct pidfh;6061struct zpool_handle;62typedef struct zpool_handle zpool_handle_t;6364struct zfs_handle;65typedef struct libzfs_handle libzfs_handle_t;6667struct nvlist;68typedef struct nvlist nvlist_t;6970typedef int LeafIterFunc(zpool_handle_t *, nvlist_t *, void *);7172/*================================ Global Data ===============================*/73extern int g_debug;74extern libzfs_handle_t *g_zfsHandle;7576/*============================= Class Definitions ============================*/77/*--------------------------------- ZfsDaemon --------------------------------*/78/**79* Static singleton orchestrating the operations of the ZFS daemon program.80*/81class ZfsDaemon : public DevdCtl::Consumer82{83public:84/** Return the ZfsDaemon singleton. */85static ZfsDaemon &Get();8687/**88* Used by signal handlers to ensure, in a race free way, that89* the event loop will perform at least one more full loop90* before sleeping again.91*/92static void WakeEventLoop();9394/**95* Schedules a rescan of devices in the system for potential96* candidates to replace a missing vdev. The scan is performed97* during the next run of the event loop.98*/99static void RequestSystemRescan();100101/** Daemonize and perform all functions of the ZFS daemon. */102static void Run();103104private:105ZfsDaemon();106~ZfsDaemon();107108static VdevCallback_t VdevAddCaseFile;109110/** Purge our cache of outstanding ZFS issues in the system. */111void PurgeCaseFiles();112113/** Build a cache of outstanding ZFS issues in the system. */114void BuildCaseFiles();115116/**117* Iterate over all known issues and attempt to solve them118* given resources currently available in the system.119*/120void RescanSystem();121122/**123* Interrogate the system looking for previously unknown124* faults that occurred either before ZFSD was started,125* or during a period of lost communication with Devd.126*/127void DetectMissedEvents();128129/**130* Wait for and process event source activity.131*/132void EventLoop();133134/**135* Signal handler for which our response is to136* log the current state of the daemon.137*138* \param sigNum The signal caught.139*/140static void InfoSignalHandler(int sigNum);141142/**143* Signal handler for which our response is to144* request a case rescan.145*146* \param sigNum The signal caught.147*/148static void RescanSignalHandler(int sigNum);149150/**151* Signal handler for which our response is to152* gracefully terminate.153*154* \param sigNum The signal caught.155*/156static void QuitSignalHandler(int sigNum);157158/**159* Open and lock our PID file.160*/161static void OpenPIDFile();162163/**164* Update our PID file with our PID.165*/166static void UpdatePIDFile();167168/**169* Close and release the lock on our PID file.170*/171static void ClosePIDFile();172173/**174* Perform syslog configuration.175*/176static void InitializeSyslog();177178static ZfsDaemon *s_theZfsDaemon;179180/**181* Set to true when our program is signaled to182* gracefully exit.183*/184static bool s_logCaseFiles;185186/**187* Set to true when our program is signaled to188* gracefully exit.189*/190static bool s_terminateEventLoop;191192/**193* The canonical path and file name of zfsd's PID file.194*/195static char s_pidFilePath[];196197/**198* Control structure for PIDFILE(3) API.199*/200static pidfh *s_pidFH;201202/**203* Pipe file descriptors used to close races with our204* signal handlers.205*/206static int s_signalPipeFD[2];207208/**209* Flag controlling a rescan from ZFSD's event loop of all210* GEOM providers in the system to find candidates for solving211* cases.212*/213static bool s_systemRescanRequested;214215/**216* Flag controlling whether events can be queued. This boolean217* is set during event replay to ensure that events for pools or218* devices no longer in the system are not retained forever.219*/220static bool s_consumingEvents;221222static DevdCtl::EventFactory::Record s_registryEntries[];223};224225#endif /* _ZFSD_H_ */226227228