2009-07-28 18:46:53 +04:00
/*
Copyright Red Hat , Inc . 2006
This program is free software ; you can redistribute it and / or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation ; either version 2 , or ( at your option ) any
later version .
This program is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; see the file COPYING . If not , write to the
Free Software Foundation , Inc . , 675 Mass Ave , Cambridge ,
MA 0213 9 , USA .
*/
/*
* Author : Lon Hohberger < lhh at redhat . com >
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <signal.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/wait.h>
# include <sys/ioctl.h>
# include <arpa/inet.h>
# include <net/if.h>
# include <netinet/in.h>
# include <sys/time.h>
# include <errno.h>
# include <pthread.h>
# include <libgen.h>
2016-11-11 18:00:50 +03:00
# include <syslog.h>
2009-07-28 18:46:53 +04:00
/* Local includes */
# include "xvm.h"
# include "options.h"
# include "debug.h"
# include <client.h>
int
main ( int argc , char * * argv )
{
fence_virt_args_t args ;
2010-01-09 22:20:59 +03:00
const char * my_options ;
2010-01-13 17:26:32 +03:00
int ret = 0 ;
2009-07-28 18:46:53 +04:00
args_init ( & args ) ;
if ( ! strcmp ( basename ( argv [ 0 ] ) , " fence_xvm " ) ) {
2012-06-08 02:10:49 +04:00
my_options = " di:a:p:r:C:c:k:M:H:uo:t:?hVw: " ;
2009-07-28 18:46:53 +04:00
args . mode = MODE_MULTICAST ;
} else {
2017-07-28 17:25:28 +03:00
my_options = " dD:P:A:p:M:H:o:t:?hVT:S::C:c:k:w: " ;
2009-07-28 18:46:53 +04:00
args . mode = MODE_SERIAL ;
}
if ( argc = = 1 ) {
args_get_stdin ( my_options , & args ) ;
} else {
args_get_getopt ( argc , argv , my_options , & args ) ;
}
if ( args . flags & F_HELP ) {
args_usage ( argv [ 0 ] , my_options , 0 ) ;
printf ( " With no command line argument, arguments are "
" read from standard input. \n " ) ;
printf ( " Arguments read from standard input take "
" the form of: \n \n " ) ;
printf ( " arg1=value1 \n " ) ;
printf ( " arg2=value2 \n \n " ) ;
args_usage ( argv [ 0 ] , my_options , 1 ) ;
exit ( 0 ) ;
}
if ( args . flags & F_VERSION ) {
printf ( " %s %s \n " , basename ( argv [ 0 ] ) , XVM_VERSION ) ;
# ifdef FENCE_RELEASE_NAME
printf ( " fence release %s \n " , FENCE_RELEASE_NAME ) ;
# endif
exit ( 0 ) ;
}
2016-11-11 18:00:50 +03:00
openlog ( basename ( argv [ 0 ] ) , LOG_NDELAY | LOG_PID , LOG_DAEMON ) ;
2009-07-28 18:46:53 +04:00
args_finalize ( & args ) ;
dset ( args . debug ) ;
if ( args . debug > 0 )
args_print ( & args ) ;
/* Additional validation here */
2009-12-07 20:55:48 +03:00
if ( ! args . domain & & ( args . op ! = FENCE_DEVSTATUS & &
2010-01-14 23:26:53 +03:00
args . op ! = FENCE_HOSTLIST & &
args . op ! = FENCE_METADATA ) ) {
2009-07-28 18:46:53 +04:00
printf ( " No domain specified! \n " ) ;
2016-11-11 18:00:50 +03:00
syslog ( LOG_NOTICE , " No domain specified " ) ;
2009-07-28 18:46:53 +04:00
args . flags | = F_ERR ;
}
2017-07-28 17:25:28 +03:00
if ( args . net . ipaddr )
2012-06-01 23:22:02 +04:00
args . mode = MODE_TCP ;
2017-07-28 17:25:28 +03:00
if ( args . net . cid > = 2 )
args . mode = MODE_VSOCK ;
2012-06-01 23:22:02 +04:00
2009-07-28 18:46:53 +04:00
if ( args . flags & F_ERR ) {
2018-11-09 15:10:29 +03:00
if ( args . op ! = FENCE_VALIDATEALL )
2017-05-04 06:22:34 +03:00
args_usage ( argv [ 0 ] , my_options , ( argc = = 1 ) ) ;
2009-07-28 18:46:53 +04:00
exit ( 1 ) ;
}
2017-05-04 06:22:34 +03:00
if ( args . op = = FENCE_VALIDATEALL )
exit ( 0 ) ;
2010-01-14 23:26:53 +03:00
if ( args . op = = FENCE_METADATA ) {
args_metadata ( argv [ 0 ] , my_options ) ;
2017-05-04 06:22:34 +03:00
exit ( 0 ) ;
2010-01-14 23:26:53 +03:00
}
2016-05-03 16:58:00 +03:00
if ( args . delay > 0 & &
args . op ! = FENCE_STATUS & &
args . op ! = FENCE_DEVSTATUS & &
args . op ! = FENCE_HOSTLIST )
2012-06-08 02:10:49 +04:00
sleep ( args . delay ) ;
2009-07-28 18:46:53 +04:00
switch ( args . mode ) {
case MODE_MULTICAST :
2010-01-13 17:26:32 +03:00
ret = mcast_fence_virt ( & args ) ;
break ;
2009-07-28 18:46:53 +04:00
case MODE_SERIAL :
2010-01-13 17:26:32 +03:00
ret = serial_fence_virt ( & args ) ;
break ;
2012-06-01 23:22:02 +04:00
case MODE_TCP :
ret = tcp_fence_virt ( & args ) ;
break ;
2017-07-28 17:25:28 +03:00
case MODE_VSOCK :
ret = vsock_fence_virt ( & args ) ;
break ;
2010-01-13 17:26:32 +03:00
default :
2016-11-11 18:00:50 +03:00
ret = 1 ;
goto out ;
2010-01-13 17:26:32 +03:00
}
switch ( ret ) {
2010-01-15 16:06:34 +03:00
case RESP_OFF :
2013-11-03 21:44:49 +04:00
if ( args . op = = FENCE_STATUS )
printf ( " Status: OFF \n " ) ;
2016-11-11 18:00:50 +03:00
else if ( args . domain )
syslog ( LOG_NOTICE , " Domain \" %s \" is OFF " , args . domain ) ;
2013-11-03 21:44:49 +04:00
break ;
2010-01-13 17:26:32 +03:00
case 0 :
2013-11-03 21:44:49 +04:00
if ( args . op = = FENCE_STATUS )
printf ( " Status: ON \n " ) ;
2016-11-11 18:00:50 +03:00
else if ( args . domain )
syslog ( LOG_NOTICE , " Domain \" %s \" is ON " , args . domain ) ;
2010-01-13 17:26:32 +03:00
break ;
case RESP_FAIL :
2016-11-11 18:00:50 +03:00
if ( args . domain ) {
syslog ( LOG_NOTICE , " Fence operation failed for domain \" %s \" " ,
args . domain ) ;
} else
syslog ( LOG_NOTICE , " Fence operation failed " ) ;
2010-01-13 17:26:32 +03:00
printf ( " Operation failed \n " ) ;
break ;
case RESP_PERM :
2016-11-11 18:00:50 +03:00
if ( args . domain ) {
syslog ( LOG_NOTICE ,
" Permission denied for Fence operation for domain \" %s \" " ,
args . domain ) ;
} else
syslog ( LOG_NOTICE , " Permission denied for fence operation " ) ;
2010-01-13 17:26:32 +03:00
printf ( " Permission denied \n " ) ;
break ;
2009-07-28 18:46:53 +04:00
default :
2016-11-11 18:00:50 +03:00
if ( args . domain ) {
syslog ( LOG_NOTICE , " Unknown response (%d) for domain \" %s \" " ,
ret , args . domain ) ;
} else
syslog ( LOG_NOTICE , " Unknown response (%d) " , ret ) ;
2010-01-13 17:26:32 +03:00
printf ( " Unknown response (%d) \n " , ret ) ;
2009-07-28 18:46:53 +04:00
break ;
}
2016-11-11 18:00:50 +03:00
out :
closelog ( ) ;
2017-05-04 06:22:34 +03:00
exit ( ret ) ;
2009-07-28 18:46:53 +04:00
}