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