]>
Commit | Line | Data |
---|---|---|
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 PR |
15 | #include "daemon-client.h" |
16 | ||
17 | #ifndef _LVM_DAEMON_COMMON_SERVER_H | |
18 | #define _LVM_DAEMON_COMMON_SERVER_H | |
56517bad PR |
19 | |
20 | typedef struct { | |
21 | int socket_fd; /* the fd we use to talk to the client */ | |
22 | pthread_t thread_id; | |
23 | char *read_buf; | |
24 | void *private; /* this holds per-client state */ | |
25 | } client_handle; | |
26 | ||
27 | typedef struct { | |
dc85d3fb PR |
28 | struct config_tree *cft; |
29 | } request; | |
30 | ||
31 | typedef struct { | |
32 | int error; | |
33 | struct config_tree *cft; | |
34 | } response; | |
35 | ||
36 | struct daemon_state; | |
37 | ||
38 | /* | |
39 | * The callback. Called once per request issued, in the respective client's | |
40 | * thread. It is presented by a parsed request (in the form of a config tree). | |
41 | * The output is a new config tree that is serialised and sent back to the | |
42 | * client. The client blocks until the request processing is done and reply is | |
43 | * sent. | |
44 | */ | |
45 | typedef response (*handle_request)(struct daemon_state s, client_handle h, request r); | |
46 | ||
47 | typedef struct daemon_state { | |
d7448a72 PR |
48 | /* |
49 | * The maximal stack size for individual daemon threads. This is | |
50 | * essential for daemons that need to be locked into memory, since | |
51 | * pthread's default is 10M per thread. | |
52 | */ | |
53 | int thread_stack_size; | |
54 | ||
55 | /* Flags & attributes affecting the behaviour of the daemon. */ | |
56 | unsigned avoid_oom:1; | |
57 | unsigned foreground:1; | |
58 | const char *name; | |
59 | const char *pidfile; | |
73ffd6e7 | 60 | const char *socket_path; |
dc85d3fb PR |
61 | int log_level; |
62 | handle_request handler; | |
63 | int (*setup_post)(struct daemon_state *st); | |
73ffd6e7 PR |
64 | |
65 | /* Global runtime info maintained by the framework. */ | |
66 | int socket_fd; | |
d7448a72 | 67 | |
56517bad PR |
68 | void *private; /* the global daemon state */ |
69 | } daemon_state; | |
70 | ||
56517bad PR |
71 | /* |
72 | * Start serving the requests. This does all the daemonisation, socket setup | |
d7448a72 PR |
73 | * work and so on. This function takes over the process, and upon failure, it |
74 | * will terminate execution. It may be called at most once. | |
56517bad | 75 | */ |
dc85d3fb | 76 | void daemon_start(daemon_state s); |
56517bad PR |
77 | |
78 | /* | |
79 | * Take over from an already running daemon. This function handles connecting | |
80 | * to the running daemon and telling it we are going to take over. The takeover | |
81 | * request may be customised by passing in a non-NULL request. | |
82 | * | |
83 | * The takeover sequence: the old daemon stops accepting new clients, then it | |
84 | * waits until all current client connections are closed. When that happens, it | |
85 | * serializes its current state and sends that as a reply, which is then | |
86 | * returned by this function (therefore, this function won't return until the | |
87 | * previous instance has shut down). | |
88 | * | |
89 | * The daemon, after calling daemon_takeover is expected to set up its | |
90 | * daemon_state using the reply from this function and call daemon_start as | |
91 | * usual. | |
92 | */ | |
93 | daemon_reply daemon_takeover(daemon_info i, daemon_request r); | |
94 | ||
95 | /* Call this to request a clean shutdown of the daemon. Async safe. */ | |
96 | void daemon_stop(); | |
97 | ||
98 | #endif |