CTDB with GlusterFS.

Ralph Boehme rb at sernet.de
Fri Nov 13 17:24:48 UTC 2015


On Fri, Nov 13, 2015 at 10:28:05AM +0100, Ralph Boehme wrote:
> On Thu, Nov 12, 2015 at 01:51:40PM +1100, Martin Schwenke wrote:
> > On Wed, 11 Nov 2015 07:26:03 +0100, Ralph Boehme <rb at sernet.de> wrote:
> > 
> > > On Wed, Nov 11, 2015 at 05:12:31PM +1100, Martin Schwenke wrote:
> > > > This would allow you to test the fcntl(2) locking without having all of
> > > > CTDB in the way.
> > > > 
> > > > If you're not a C programmer (though I think this could probably be
> > > > done with Python too) then please yell and I'll whip something up for
> > > > you to test with...  :-)  
> > > 
> > > fwiw, I have this WIP patch for ping_pong in a working branch.
> > 
> > I think we discussed this some time ago and some of us thought there
> > were better ways.  I think one reply was probably that it didn't
> > belong in ping_pong.   Also, Michael pointed out another way using
> > existing ping_pong functionality.
> > 
> > However, I think your patch creates a very obvious way of testing
> > byte-range locks and we should think about how it can be cleaned
> > up and pushed.
> > 
> > You probably need to clean up the repetitive usage checking...  :-)
> 
> I'll cleanup and resubmit later on today.

updated patch attached.

I could split the modification of lock_range() into a seperate commit
if you prefer.

Thoughts?

-Ralph

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de,mailto:kontakt@sernet.de
-------------- next part --------------
From 68e7f6570f835a68abfad66a5ff75c7832435c07 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Sun, 10 May 2015 01:39:16 +0200
Subject: [PATCH] ping_pong: add -l option

Add a new option -l to check whether POSIX byte range locks are
working. Usage:

node1$ touch /path/to/cluster-fs/FILE

node1$ ./bin/ping_pong -l /path/to/cluster-fs/FILE
Holding lock, press any key to continue...
You should run the same command on another node now.

node2$ ./bin/ping_pong -l /path/to/cluster-fs/FILE

Output can either be:

  Holding lock, press any key to continue...

This means POSIX byte range locks are *not* working.

If you see this instead:

  file already locked, calling check_lock to tell us who has it locked...:
  check_lock failed: lock held: pid='27375', type='1', start='0', len='0'
  Working POSIX byte range locks

Congrats, you have a cluster fs with functional byte range locks!

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 ctdb/utils/ping_pong/ping_pong.c | 65 ++++++++++++++++++++++++++++++----------
 1 file changed, 50 insertions(+), 15 deletions(-)

diff --git a/ctdb/utils/ping_pong/ping_pong.c b/ctdb/utils/ping_pong/ping_pong.c
index fdb575d..be43a1d 100644
--- a/ctdb/utils/ping_pong/ping_pong.c
+++ b/ctdb/utils/ping_pong/ping_pong.c
@@ -39,10 +39,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <stdbool.h>
 
 static struct timeval tp1,tp2;
 
-static int do_reads, do_writes, use_mmap, do_check;
+static int do_reads, do_writes, use_mmap, do_check, do_brl_test;
 
 static void start_timer(void)
 {
@@ -57,7 +58,7 @@ static double end_timer(void)
 }
 
 /* lock a byte range in a open file */
-static int lock_range(int fd, int offset, int len)
+static int lock_range(int fd, int offset, int len, bool wait)
 {
 	struct flock lock;
 
@@ -67,7 +68,7 @@ static int lock_range(int fd, int offset, int len)
 	lock.l_len = len;
 	lock.l_pid = 0;
 	
-	return fcntl(fd,F_SETLKW,&lock);
+	return fcntl(fd, wait ? F_SETLKW : F_SETLK, &lock);
 }
 
 /* check whether we could place a lock */
@@ -147,11 +148,11 @@ static void ping_pong(int fd, int num_locks)
 
 	start_timer();
 
-	lock_range(fd, 0, 1);
+	lock_range(fd, 0, 1, true);
 	i = 0;
 
 	while (1) {
-		if (lock_range(fd, (i+1) % num_locks, 1) != 0) {
+		if (lock_range(fd, (i+1) % num_locks, 1, true) != 0) {
 			printf("lock at %d failed! - %s\n",
 			       (i+1) % num_locks, strerror(errno));
 		}
@@ -198,13 +199,25 @@ static void ping_pong(int fd, int num_locks)
 	}
 }
 
+static void usage(void)
+{
+	printf("ping_pong -rwmc <file> <num_locks>\n");
+	printf("ping_pong -l <file>\n\n");
+	printf("Options\n");
+	printf(" -r    do reads\n");
+	printf(" -w    do writes\n");
+	printf(" -m    use mmap\n");
+	printf(" -c    check locks\n");
+	printf(" -l    test for working byte range locks\n");
+}
+
 int main(int argc, char *argv[])
 {
 	char *fname;
 	int fd, num_locks;
 	int c;
 
-	while ((c = getopt(argc, argv, "rwmc")) != -1) {
+	while ((c = getopt(argc, argv, "rwmcl")) != -1) {
 		switch (c){
 		case 'w':
 			do_writes = 1;
@@ -218,6 +231,9 @@ int main(int argc, char *argv[])
 		case 'c':
 			do_check = 1;
 			break;
+		case 'l':
+			do_brl_test = 1;
+			break;
 		default:
 			fprintf(stderr, "Unknown option '%c'\n", c);
 			exit(1);
@@ -227,25 +243,44 @@ int main(int argc, char *argv[])
 	argv += optind;
 	argc -= optind;
 
-	if (argc < 2) {
-		printf("ping_pong [options] <file> <num_locks>\n");
-		printf("           -r    do reads\n");
-		printf("           -w    do writes\n");
-		printf("           -m    use mmap\n");
-		printf("           -c    check locks\n");
+	if (argc < 1) {
+		usage();
 		exit(1);
 	}
 
 	fname = argv[0];
+
+	fd = open(fname, O_CREAT|O_RDWR, 0600);
+	if (fd == -1) {
+		exit(1);
+	}
+
+	if (do_brl_test) {
+		if (lock_range(fd, 0, 0, false) != 0) {
+			printf("file already locked, calling check_lock to tell us who has it locked:\n");
+			(void)check_lock(fd, 0, 0);
+			printf("Working POSIX byte range locks\n");
+			exit(0);
+		}
+
+		printf("Holding lock, press any key to continue...\n");
+		printf("You should run the same command on another node now.\n");
+		getchar();
+		printf("Good bye.\n");
+		exit(0);
+	}
+
+	if (argc < 2) {
+		usage();
+		exit(1);
+	}
+
 	num_locks = atoi(argv[1]);
 	if (num_locks <= 0) {
 		printf("num_locks should be > 0\n");
 		exit(1);
 	}
 
-	fd = open(fname, O_CREAT|O_RDWR, 0600);
-	if (fd == -1) exit(1);
-
 	ping_pong(fd, num_locks);
 
 	return 0;
-- 
2.5.0



More information about the samba-technical mailing list