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