[vhffs-dev] [1604] added a new feature to vhffsfssync, --prevent-loop option on the slave enables a loop protection that prevent the slave to connect to localhost , useful when you have two servers using heartbeat and there might be cases where the slave might connect to the master on localhost . |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [1604] added a new feature to vhffsfssync, --prevent-loop option on the slave enables a loop protection that prevent the slave to connect to localhost , useful when you have two servers using heartbeat and there might be cases where the slave might connect to the master on localhost .
- From: subversion@xxxxxxxxxxxxx
- Date: Sun, 09 May 2010 08:39:56 +0200
Revision: 1604
Author: gradator
Date: 2010-05-09 08:39:56 +0200 (Sun, 09 May 2010)
Log Message:
-----------
added a new feature to vhffsfssync, --prevent-loop option on the slave enables a loop protection that prevent the slave to connect to localhost, useful when you have two servers using heartbeat and there might be cases where the slave might connect to the master on localhost.
Modified Paths:
--------------
trunk/vhffs-fssync/vhffsfssync_master.c
trunk/vhffs-fssync/vhffsfssync_slave.c
Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c 2010-05-09 05:29:22 UTC (rev 1603)
+++ trunk/vhffs-fssync/vhffsfssync_master.c 2010-05-09 06:39:56 UTC (rev 1604)
@@ -1480,7 +1480,7 @@
free(vhffsfssync_cookie.filename);
}
- // new mtime (and also atime, chmod and chown, but we are not using them)
+ // new mtime, mode, owner, group (and also other stuff like atime, but we are not using them)
if( event->mask & IN_ATTRIB ) {
struct stat st;
#if DEBUG_INOTIFY
@@ -1942,7 +1942,7 @@
#if DEBUG_NET
printf("Welcome %s ! (using fd %d)\n", inet_ntoa(conn->sockaddr.sin_addr), conn->fd);
#endif
- vhffsfssync_net_send_event(conn, g_strdup_printf("hello%c", '\0') , VHFFSFSSYNC_NET_PRIO_HIGHEST);
+ vhffsfssync_net_send_event(conn, g_strdup_printf("hello%c%llu%c", '\0', (long long int)ntohl(conn->sockaddr.sin_addr.s_addr), '\0') , VHFFSFSSYNC_NET_PRIO_HIGHEST);
}
}
Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c 2010-05-09 05:29:22 UTC (rev 1603)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c 2010-05-09 06:39:56 UTC (rev 1604)
@@ -99,6 +99,8 @@
double vhffsfssync_time();
static void usage_exit(int ret_code, char *progname);
int vhffsfssync_preserve;
+int vhffsfssync_preventloop;
+long long int vhffsfssync_host;
/* ------------------------------------------------------------ */
@@ -703,9 +705,20 @@
fprintf(stderr, "The slave timestamp is not synchronous with the master timestamp\n");
ret = -1;
}
+ else {
+ vhffsfssync_net_send_event(conn, g_strdup_printf("fulltree%c", '\0') );
+ }
}
else if(!strcmp(args[0], "hello")) {
- // nice to meet you
+ long long int seenhost = atoll(args[1]);
+
+ if(vhffsfssync_preventloop && vhffsfssync_host == seenhost) {
+ fprintf(stderr, "The slave is connecting on the same host (loopback) and loop protection is enabled\n");
+ ret = -1;
+ }
+ else {
+ vhffsfssync_net_send_event(conn, g_strdup_printf("time%c", '\0') );
+ }
}
else {
fprintf(stderr, "Received unhandled event: %s\n", args[0]);
@@ -827,9 +840,12 @@
fprintf(stderr, "The slave timestamp is not synchronous with the master timestamp\n");
ret = -1;
}
+ else {
+ vhffsfssync_net_send_event(conn, g_strdup_printf("fulltree%c", '\0') );
+ }
}
else if(!strcmp(args[0], "hello")) {
- // nice to meet you
+ vhffsfssync_net_send_event(conn, g_strdup_printf("time%c", '\0') );
}
else {
fprintf(stderr, "Received unhandled event: %s\n", args[0]);
@@ -943,6 +959,7 @@
" -f, --foreground\tDo not daemonise the client, display errors on the console\n"
" -r, --limit-rate=kB/s\tLimit I/O bandwidth; kBytes per second\n"
" -p, --preserve\tPreserve owners, groups and permissions\n"
+ " --prevent-loop\tAbort if the host seen by the master is the host we are connecting to (loopback)\n"
" -h, --help\t\tDisplay this help and exit\n"
" -v, --version\t\tOutput version information and exit\n",
progname);
@@ -963,6 +980,7 @@
int limitrate = 0;
vhffsfssync_preserve = 0;
+ vhffsfssync_preventloop = 0;
#ifdef CHECK
foreground = 1;
#endif
@@ -971,6 +989,7 @@
{ "foreground", no_argument, NULL, 'f' },
{ "limit-rate", required_argument, NULL, 'r' },
{ "preserve", no_argument, NULL, 'p' },
+ { "prevent-loop", no_argument, NULL, 1000 },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'v' },
{ 0, 0, 0, 0 }
@@ -995,6 +1014,10 @@
vhffsfssync_preserve = 1;
break;
+ case 1000:
+ vhffsfssync_preventloop = 1;
+ break;
+
case 'h':
usage_exit(0, argv[0]);
@@ -1128,9 +1151,8 @@
}
/* connected */
+ vhffsfssync_host = (long long int)ntohl(conn->sockaddr.sin_addr.s_addr);
vhffsfssync_net_send_event(conn, g_strdup_printf("hello%c", '\0') );
- vhffsfssync_net_send_event(conn, g_strdup_printf("time%c", '\0') );
- vhffsfssync_net_send_event(conn, g_strdup_printf("fulltree%c", '\0') );
/* -- the real main loop starts here -- */
while(1) {