[DRBD-cvs] r1461 - in trunk: scripts user
drbd-user@lists.linbit.com
drbd-user@lists.linbit.com
Wed, 28 Jul 2004 11:56:38 +0200 (CEST)
Author: phil
Date: 2004-07-28 11:56:38 +0200 (Wed, 28 Jul 2004)
New Revision: 1461
Modified:
trunk/scripts/drbd.conf
trunk/user/drbdadm.h
trunk/user/drbdadm_main.c
Log:
Made drbdadm to actually run the "incon-degr-cmd"...
Modified: trunk/scripts/drbd.conf
===================================================================
--- trunk/scripts/drbd.conf 2004-07-28 08:13:16 UTC (rev 1460)
+++ trunk/scripts/drbd.conf 2004-07-28 09:56:38 UTC (rev 1461)
@@ -120,7 +120,7 @@
# what should be done in case the cluster starts up in
# degraded mode, but knows it has inconsistent data.
- incon-degr-cmd "halt -f";
+ incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
startup {
# Wait for connection timeout.
@@ -241,7 +241,7 @@
#
resource "r1" {
protocol C;
- incon-degr-cmd "halt -f";
+ incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
startup {
wfc-timeout 0; ## Infinite!
degr-wfc-timeout 120; ## 2 minutes.
@@ -278,7 +278,8 @@
resource r2 {
protocol C;
- incon-degr-cmd "halt -f";
+ incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
+
startup { wfc-timeout 0; degr-wfc-timeout 120; }
disk { on-io-error detach; }
net { timeout 60; connect-int 10; ping-int 10;
@@ -296,7 +297,7 @@
resource r3 {
protocol C;
- incon-degr-cmd "halt -f";
+ incon-degr-cmd "echo '!DRBD! pri on incon-degr' | wall ; sleep 60 ; halt -f";
startup { wfc-timeout 0; degr-wfc-timeout 120; }
disk { on-io-error detach; }
syncer {
Modified: trunk/user/drbdadm.h
===================================================================
--- trunk/user/drbdadm.h 2004-07-28 08:13:16 UTC (rev 1460)
+++ trunk/user/drbdadm.h 2004-07-28 09:56:38 UTC (rev 1461)
@@ -11,9 +11,16 @@
#define E_exec_error 20
#define E_thinko 42 /* :) */
-#define SF_MaySleep 2
-#define SF_ReturnPid 4
+enum {
+ SLEEPS_FINITE = 1,
+ SLEEPS_SHORT = 2+1,
+ SLEEPS_LONG = 4+1,
+ SLEEPS_VERY_LONG = 8+1,
+ RETURN_PID = 2,
+ SLEEPS_FOREVER = 4,
+};
+
/* for check_uniq(): Check for uniqueness of certain values...
* comment out if you want to NOT choke on the first conflict */
#define EXIT_ON_CONFLICT
@@ -65,7 +72,7 @@
extern int adm_connect(struct d_resource* ,char* );
extern int adm_resize(struct d_resource* ,char* );
extern int adm_syncer(struct d_resource* ,char* );
-extern int m_system(int,char** );
+extern int m_system(char**,int );
extern struct d_option* find_opt(struct d_option*,char*);
extern void validate_resource(struct d_resource *);
extern int check_uniq(const char* what, const char *fmt, ...);
Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c 2004-07-28 08:13:16 UTC (rev 1460)
+++ trunk/user/drbdadm_main.c 2004-07-28 09:56:38 UTC (rev 1461)
@@ -68,19 +68,16 @@
int res_name_required;
};
-struct cmd_timeout {
- const char* cmd;
- int timeout;
-};
-
extern int yyparse();
extern FILE* yyin;
int adm_attach(struct d_resource* ,char* );
int adm_connect(struct d_resource* ,char* );
-int adm_generic(struct d_resource* ,char* );
+int adm_generic_s(struct d_resource* ,char* );
+int adm_generic_l(struct d_resource* ,char* );
int adm_resize(struct d_resource* ,char* );
int adm_syncer(struct d_resource* ,char* );
+static int adm_primary(struct d_resource* ,char* );
static int adm_up(struct d_resource* ,char* );
extern int adm_adjust(struct d_resource* ,char* );
static int adm_dump(struct d_resource* ,char* );
@@ -117,20 +114,20 @@
struct adm_cmd cmds[] = {
{ "attach", adm_attach, 0 ,1,1 },
- { "detach", adm_generic, "detach" ,1,1 },
+ { "detach", adm_generic_s,"detach" ,1,1 },
{ "connect", adm_connect, 0 ,1,1 },
- { "disconnect", adm_generic, "disconnect" ,1,1 },
+ { "disconnect", adm_generic_s,"disconnect" ,1,1 },
{ "up", adm_up, 0 ,1,1 },
- { "down", adm_generic, "down" ,1,1 },
- { "primary", adm_generic, "primary" ,1,1 },
- { "secondary", adm_generic, "secondary" ,1,1 },
- { "invalidate", adm_generic, "invalidate" ,1,1 },
- { "invalidate_remote", adm_generic, "invalidate_remote",1,1 },
+ { "down", adm_generic_s,"down" ,1,1 },
+ { "primary", adm_primary, 0 ,1,1 },
+ { "secondary", adm_generic_s,"secondary" ,1,1 },
+ { "invalidate", adm_generic_l,"invalidate" ,1,1 },
+ { "invalidate_remote", adm_generic_l,"invalidate_remote",1,1 },
{ "resize", adm_resize, 0 ,1,1 },
{ "syncer", adm_syncer, 0 ,1,1 },
{ "adjust", adm_adjust, 0 ,1,1 },
{ "wait_connect", adm_wait_c, 0 ,1,1 },
- { "state", adm_generic, "state" ,1,1 },
+ { "state", adm_generic_s,"state" ,1,1 },
{ "dump", adm_dump, 0 ,1,1 },
{ "wait_con_int", adm_wait_ci, 0 ,1,0 },
{ "sh-resources", sh_resources,0 ,0,0 },
@@ -141,12 +138,6 @@
{ "sh-md-idx", sh_md_idx, 0 ,0,1 }
};
-struct cmd_timeout timeouts[] = {
- // All other commands have a timeout of 5 seconds.
- { "disk", 60 },
- { "invalidate", 60 },
- { "invalidate_remote", 60 }
-};
#define ARRY_SIZE(A) (sizeof(A)/sizeof(A[0]))
@@ -360,7 +351,7 @@
alarm_raised=1;
}
-pid_t m_system(int flags,char** argv)
+pid_t m_system(char** argv,int flags)
{
pid_t pid;
int status,rv=-1;
@@ -392,19 +383,19 @@
exit(E_exec_error);
}
- if( !(flags&SF_MaySleep) ) {
- int i,timeout=5;
+ if( flags & SLEEPS_FINITE ) {
+ int timeout;
sigaction(SIGALRM,&sa,&so);
alarm_raised=0;
- for(i=0;i<ARRY_SIZE(timeouts);i++) {
- if(!strcmp(timeouts[i].cmd,argv[2])) {
- timeout = timeouts[i].timeout;
- }
+ switch(flags) {
+ case SLEEPS_SHORT: timeout = 5; break;
+ case SLEEPS_LONG: timeout = 60; break;
+ case SLEEPS_VERY_LONG: timeout = 600; break;
}
alarm(timeout);
}
- if( (flags&SF_ReturnPid) ) {
+ if( flags == RETURN_PID ) {
return pid;
}
@@ -426,18 +417,17 @@
}
}
- if( !(flags&SF_MaySleep) ) {
+ if( flags & SLEEPS_FINITE ) {
alarm(0);
sigaction(SIGALRM,&so,NULL);
- }
-
- if(!(flags&SF_MaySleep) && rv) {
- fprintf(stderr,"Command line was '");
- while(*argv) {
- fprintf(stderr,"%s",*argv++);
- if (*argv) fputc(' ',stderr);
+ if(rv) {
+ fprintf(stderr,"Command '");
+ while(*argv) {
+ fprintf(stderr,"%s",*argv++);
+ if (*argv) fputc(' ',stderr);
+ }
+ fprintf(stderr,"' terminated with exit code %d\n",rv);
}
- fprintf(stderr,"'\n");
}
return rv;
@@ -474,7 +464,7 @@
make_options(opt);
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,SLEEPS_LONG);
}
struct d_option* find_opt(struct d_option* base,char* name)
@@ -501,10 +491,10 @@
if(opt) ssprintf(argv[argc++],"--%s=%s",opt->name,opt->value);
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,SLEEPS_SHORT);
}
-int adm_generic(struct d_resource* res,char* cmd)
+static int adm_generic(struct d_resource* res,char* cmd,int flags)
{
char* argv[20];
int argc=0,i;
@@ -517,9 +507,32 @@
}
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,flags);
}
+int adm_generic_s(struct d_resource* res,char* cmd)
+{
+ return adm_generic(res,cmd,SLEEPS_SHORT);
+}
+
+int adm_generic_l(struct d_resource* res,char* cmd)
+{
+ return adm_generic(res,cmd,SLEEPS_LONG);
+}
+
+int adm_primary(struct d_resource* res,char* unused)
+{
+ int rv;
+ char *argv[] = { "/bin/bash", "-c", res->ind_cmd , NULL };
+
+ rv = adm_generic_s(res,"primary");
+
+ if(rv==21) {
+ rv = m_system(argv,SLEEPS_VERY_LONG);
+ }
+ return rv;
+}
+
int adm_connect(struct d_resource* res,char* unused)
{
char* argv[20];
@@ -537,7 +550,7 @@
make_options(opt);
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,SLEEPS_SHORT);
}
int adm_syncer(struct d_resource* res,char* unused)
@@ -553,7 +566,7 @@
make_options(opt);
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,SLEEPS_SHORT);
}
static int adm_up(struct d_resource* res,char* unused)
@@ -576,7 +589,7 @@
argv[argc++]=flag;
argv[argc++]=0;
- return m_system(0,argv);
+ return m_system(argv,SLEEPS_SHORT);
}
@@ -593,7 +606,7 @@
make_options(opt);
argv[argc++]=0;
- rv = m_system(SF_MaySleep,argv);
+ rv = m_system(argv,SLEEPS_FOREVER);
if(rv == 5) { // Timer expired
rv = on_primary(res,"--inc-timeout-expired");
@@ -752,7 +765,7 @@
make_options(opt);
argv[argc++]=0;
- pids[i++]=m_system(SF_MaySleep|SF_ReturnPid, argv);
+ pids[i++]=m_system(argv,RETURN_PID);
}
wtime = global_options.dialog_refresh ?
@@ -884,7 +897,7 @@
"fi >/dev/null",
my_ip);
if (ex < 0) { perror("asprintf"); exit(E_thinko); }
- ex = m_system(0,argv);
+ ex = m_system(argv,SLEEPS_SHORT);
free(argv[2]); argv[2] = NULL;
if (ex != 0) {
@@ -918,7 +931,7 @@
"fi >/dev/null",
my_ip,his_ip);
if (ex < 0) { perror("asprintf"); exit(E_thinko); }
- ex = m_system(0,argv);
+ ex = m_system(argv,SLEEPS_SHORT);
free(argv[2]); argv[2] = NULL;
if (ex != 0) {
ENTRY e, *ep;
@@ -1185,7 +1198,7 @@
exit(E_usage);
found:
if( (rv=cmd->function(res,cmd->arg)) ) {
- fprintf(stderr,"drbdsetup exited with code %d\n",rv);
+ fprintf(stderr,"drbdadm aborting\n");
exit(E_exec_error);
}
}