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