]> sourceware.org Git - lvm2.git/blame - daemons/common/daemon-server.h
Move the core of the lib/config/config.c functionality into libdevmapper,
[lvm2.git] / daemons / common / daemon-server.h
CommitLineData
56517bad
PR
1/*
2 * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
3 *
4 * This file is part of LVM2.
5 *
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.
9 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 */
14
dc85d3fb 15#include "daemon-client.h"
92658f56 16#include "config.h" // XXX will be in libdevmapper.h later
dc85d3fb
PR
17
18#ifndef _LVM_DAEMON_COMMON_SERVER_H
19#define _LVM_DAEMON_COMMON_SERVER_H
56517bad
PR
20
21typedef struct {
22 int socket_fd; /* the fd we use to talk to the client */
23 pthread_t thread_id;
24 char *read_buf;
25 void *private; /* this holds per-client state */
26} client_handle;
27
28typedef struct {
55e30071 29 struct config_tree *cft;
92658f56 30 char *buffer;
dc85d3fb
PR
31} request;
32
33typedef struct {
34 int error;
55e30071 35 struct config_tree *cft;
92658f56 36 char *buffer;
dc85d3fb
PR
37} response;
38
39struct daemon_state;
40
aaca7f11
PR
41/*
42 * Craft a simple reply, without the need to construct a config_tree. See
43 * daemon_send_simple in daemon-client.h for the description of the parameters.
44 */
45response daemon_reply_simple(char *id, ...);
46
94bb67ab 47static inline int daemon_request_int(request r, const char *path, int def) {
372e9b3d
PR
48 if (!r.cft)
49 return def;
94bb67ab
PR
50 return find_config_int(r.cft->root, path, def);
51}
52
53static inline const char *daemon_request_str(request r, const char *path, const char *def) {
372e9b3d
PR
54 if (!r.cft)
55 return def;
94bb67ab
PR
56 return find_config_str(r.cft->root, path, def);
57}
58
dc85d3fb
PR
59/*
60 * The callback. Called once per request issued, in the respective client's
61 * thread. It is presented by a parsed request (in the form of a config tree).
62 * The output is a new config tree that is serialised and sent back to the
63 * client. The client blocks until the request processing is done and reply is
64 * sent.
65 */
66typedef response (*handle_request)(struct daemon_state s, client_handle h, request r);
67
68typedef struct daemon_state {
d7448a72
PR
69 /*
70 * The maximal stack size for individual daemon threads. This is
71 * essential for daemons that need to be locked into memory, since
72 * pthread's default is 10M per thread.
73 */
74 int thread_stack_size;
75
76 /* Flags & attributes affecting the behaviour of the daemon. */
77 unsigned avoid_oom:1;
78 unsigned foreground:1;
79 const char *name;
80 const char *pidfile;
73ffd6e7 81 const char *socket_path;
dc85d3fb
PR
82 int log_level;
83 handle_request handler;
372e9b3d
PR
84 int (*daemon_init)(struct daemon_state *st);
85 int (*daemon_fini)(struct daemon_state *st);
73ffd6e7
PR
86
87 /* Global runtime info maintained by the framework. */
88 int socket_fd;
d7448a72 89
56517bad
PR
90 void *private; /* the global daemon state */
91} daemon_state;
92
56517bad
PR
93/*
94 * Start serving the requests. This does all the daemonisation, socket setup
d7448a72
PR
95 * work and so on. This function takes over the process, and upon failure, it
96 * will terminate execution. It may be called at most once.
56517bad 97 */
dc85d3fb 98void daemon_start(daemon_state s);
56517bad
PR
99
100/*
101 * Take over from an already running daemon. This function handles connecting
102 * to the running daemon and telling it we are going to take over. The takeover
103 * request may be customised by passing in a non-NULL request.
104 *
105 * The takeover sequence: the old daemon stops accepting new clients, then it
106 * waits until all current client connections are closed. When that happens, it
107 * serializes its current state and sends that as a reply, which is then
108 * returned by this function (therefore, this function won't return until the
109 * previous instance has shut down).
110 *
111 * The daemon, after calling daemon_takeover is expected to set up its
112 * daemon_state using the reply from this function and call daemon_start as
113 * usual.
114 */
115daemon_reply daemon_takeover(daemon_info i, daemon_request r);
116
117/* Call this to request a clean shutdown of the daemon. Async safe. */
118void daemon_stop();
119
120#endif
This page took 0.038623 seconds and 5 git commands to generate.