]>
sourceware.org Git - lvm2.git/blob - libdaemon/server/daemon-server.h
aa2f1f39f605044a8e191452164ea6fc6e87a6d7
2 * Copyright (C) 2011-2012 Red Hat, Inc.
4 * This file is part of LVM2.
6 * This copyrighted material is made available to anyone wishing to use,
7 * modify, copy, or redistribute it subject to the terms and conditions
8 * of the GNU Lesser General Public License v.2.1.
10 * You should have received a copy of the GNU Lesser General Public License
11 * along with this program; if not, write to the Free Software Foundation,
12 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 #ifndef _LVM_DAEMON_SERVER_H
16 #define _LVM_DAEMON_SERVER_H
18 #include "libdaemon/client/daemon-client.h"
21 int socket_fd
; /* the fd we use to talk to the client */
24 void *private; /* this holds per-client state */
28 struct dm_config_tree
*cft
;
34 struct dm_config_tree
*cft
;
41 * is_idle: daemon implementation sets it to true when no background task
43 * max_timeouts: how many seconds do daemon allow to be idle before it shutdowns
44 * ptimeout: internal variable passed to select(). has to be reset to 1 second
48 volatile unsigned is_idle
;
49 unsigned max_timeouts
;
50 struct timespec
*ptimeout
;
56 * Craft a simple reply, without the need to construct a config_tree. See
57 * daemon_send_simple in daemon-client.h for the description of the parameters.
59 response
daemon_reply_simple(const char *id
, ...);
61 static inline int daemon_request_int(request r
, const char *path
, int def
) {
64 return dm_config_find_int(r
.cft
->root
, path
, def
);
67 static inline const char *daemon_request_str(request r
, const char *path
, const char *def
) {
70 return dm_config_find_str(r
.cft
->root
, path
, def
);
74 * The callback. Called once per request issued, in the respective client's
75 * thread. It is presented by a parsed request (in the form of a config tree).
76 * The output is a new config tree that is serialised and sent back to the
77 * client. The client blocks until the request processing is done and reply is
80 typedef response (*handle_request
)(struct daemon_state s
, client_handle h
, request r
);
83 uint32_t log_config
[32];
84 void *backend_state
[32];
90 typedef struct daemon_state
{
92 * The maximal stack size for individual daemon threads. This is
93 * essential for daemons that need to be locked into memory, since
94 * pthread's default is 10M per thread.
96 int thread_stack_size
;
98 /* Flags & attributes affecting the behaviour of the daemon. */
100 unsigned foreground
:1;
103 const char *socket_path
;
104 const char *protocol
;
105 int protocol_version
;
107 handle_request handler
;
108 int (*daemon_init
)(struct daemon_state
*st
);
109 int (*daemon_fini
)(struct daemon_state
*st
);
110 int (*daemon_main
)(struct daemon_state
*st
);
112 /* Global runtime info maintained by the framework. */
116 struct thread_state
*threads
;
118 /* support for shutdown on idle */
121 void *private; /* the global daemon state */
124 typedef struct thread_state
{
126 client_handle client
;
127 struct thread_state
*next
;
132 * Start serving the requests. This does all the daemonisation, socket setup
133 * work and so on. This function takes over the process, and upon failure, it
134 * will terminate execution. It may be called at most once.
136 void daemon_start(daemon_state s
);
139 * Take over from an already running daemon. This function handles connecting
140 * to the running daemon and telling it we are going to take over. The takeover
141 * request may be customised by passing in a non-NULL request.
143 * The takeover sequence: the old daemon stops accepting new clients, then it
144 * waits until all current client connections are closed. When that happens, it
145 * serializes its current state and sends that as a reply, which is then
146 * returned by this function (therefore, this function won't return until the
147 * previous instance has shut down).
149 * The daemon, after calling daemon_takeover is expected to set up its
150 * daemon_state using the reply from this function and call daemon_start as
153 daemon_reply
daemon_takeover(daemon_info i
, daemon_request r
);
155 /* Call this to request a clean shutdown of the daemon. Async safe. */
156 void daemon_stop(void);
158 enum { DAEMON_LOG_OUTLET_SYSLOG
= 1,
159 DAEMON_LOG_OUTLET_STDERR
= 2,
160 DAEMON_LOG_OUTLET_SOCKET
= 4 };
162 /* Log a message of a given type. */
163 void daemon_log(log_state
*s
, int type
, const char *message
);
165 /* Log a config (sub)tree, using a given message type, each line prefixed with "prefix". */
166 void daemon_log_cft(log_state
*s
, int type
, const char *prefix
,
167 const struct dm_config_node
*n
);
169 /* Log a multi-line block, prefixing each line with "prefix". */
170 void daemon_log_multi(log_state
*s
, int type
, const char *prefix
, const char *message
);
172 /* Log a formatted message as "type". See also daemon-log.h. */
173 void daemon_logf(log_state
*s
, int type
, const char *format
, ...)
174 __attribute__ ((format(printf
, 3, 4)));
177 * Configure log_state to send messages of type "type" to the log outlet
178 * "outlet", iff "enable" is true.
180 void daemon_log_enable(log_state
*s
, int outlet
, int type
, int enable
);
183 * Set up logging on a given outlet using a list of message types (comma
184 * separated) to log using that outlet. The list is expected to look like this,
185 * "all,wire,debug". Returns 0 upon encountering an unknown message type.
187 int daemon_log_parse(log_state
*s
, int outlet
, const char *types
, int enable
);
This page took 0.054869 seconds and 6 git commands to generate.