Imported Upstream version 2.02.79
[platform/upstream/device-mapper.git] / daemons / clvmd / clvmd.h
1 /*
2  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
3  * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
4  *
5  * This file is part of LVM2.
6  *
7  * This copyrighted material is made available to anyone wishing to use,
8  * modify, copy, or redistribute it subject to the terms and conditions
9  * of the GNU General Public License v.2.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  */
15
16 #ifndef _CLVMD_H
17 #define _CLVMD_H
18
19 #define CLVMD_MAJOR_VERSION 0
20 #define CLVMD_MINOR_VERSION 2
21 #define CLVMD_PATCH_VERSION 1
22
23 /* Default time (in seconds) we will wait for all remote commands to execute
24    before declaring them dead */
25 #define DEFAULT_CMD_TIMEOUT 60
26
27 /* One of these for each reply we get from command execution on a node */
28 struct node_reply {
29         char node[MAX_CLUSTER_MEMBER_NAME_LEN];
30         char *replymsg;
31         int status;
32         struct node_reply *next;
33 };
34
35 typedef enum {DEBUG_OFF, DEBUG_STDERR, DEBUG_SYSLOG} debug_t;
36
37 /*
38  * These exist for the use of local sockets only when we are
39  * collecting responses from all cluster nodes
40  */
41 struct localsock_bits {
42         struct node_reply *replies;
43         int num_replies;
44         int expected_replies;
45         time_t sent_time;       /* So we can check for timeouts */
46         int in_progress;        /* Only execute one cmd at a time per client */
47         int sent_out;           /* Flag to indicate that a command was sent
48                                    to remote nodes */
49         void *private;          /* Private area for command processor use */
50         void *cmd;              /* Whole command as passed down local socket */
51         int cmd_len;            /* Length of above */
52         int pipe;               /* Pipe to send PRE completion status down */
53         int finished;           /* Flag to tell subthread to exit */
54         int all_success;        /* Set to 0 if any node (or the pre_command)
55                                    failed */
56         struct local_client *pipe_client;
57         pthread_t threadid;
58         enum { PRE_COMMAND, POST_COMMAND, QUIT } state;
59         pthread_mutex_t mutex;  /* Main thread and worker synchronisation */
60         pthread_cond_t cond;
61
62         pthread_mutex_t reply_mutex;    /* Protect reply structure */
63 };
64
65 /* Entries for PIPE clients */
66 struct pipe_bits {
67         struct local_client *client;    /* Actual (localsock) client */
68         pthread_t threadid;             /* Our own copy of the thread id */
69 };
70
71 /* Entries for Network socket clients */
72 struct netsock_bits {
73         void *private;
74         int flags;
75 };
76
77 typedef int (*fd_callback_t) (struct local_client * fd, char *buf, int len,
78                               const char *csid,
79                               struct local_client ** new_client);
80
81 /* One of these for each fd we are listening on */
82 struct local_client {
83         int fd;
84         enum { CLUSTER_MAIN_SOCK, CLUSTER_DATA_SOCK, LOCAL_RENDEZVOUS,
85                     LOCAL_SOCK, THREAD_PIPE, CLUSTER_INTERNAL } type;
86         struct local_client *next;
87         unsigned short xid;
88         fd_callback_t callback;
89         uint8_t removeme;
90
91         union {
92                 struct localsock_bits localsock;
93                 struct pipe_bits pipe;
94                 struct netsock_bits net;
95         } bits;
96 };
97
98 #define DEBUGLOG(fmt, args...) debuglog(fmt, ## args);
99
100 #ifndef max
101 #define max(a,b) ((a)>(b)?(a):(b))
102 #endif
103
104 /* The real command processor is in clvmd-command.c */
105 extern int do_command(struct local_client *client, struct clvm_header *msg,
106                       int msglen, char **buf, int buflen, int *retlen);
107
108 /* Pre and post command routines are called only on the local node */
109 extern int do_pre_command(struct local_client *client);
110 extern int do_post_command(struct local_client *client);
111 extern void cmd_client_cleanup(struct local_client *client);
112 extern int add_client(struct local_client *new_client);
113
114 extern void clvmd_cluster_init_completed(void);
115 extern void process_message(struct local_client *client, const char *buf,
116                             int len, const char *csid);
117 extern void debuglog(const char *fmt, ... )
118   __attribute__ ((format(printf, 1, 2)));
119
120 int sync_lock(const char *resource, int mode, int flags, int *lockid);
121 int sync_unlock(const char *resource, int lockid);
122
123 #endif